- TBN_DELETINGBUTTON sends the command ID, not the index.
[wine/hacks.git] / dlls / comctl32 / toolbar.c
blob4f2c0e028f545574bdfa45c80ade5f962d8ed5f4
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * NOTES
24 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
40 * TODO:
41 * - Styles:
42 * - TBSTYLE_REGISTERDROP
43 * - TBSTYLE_EX_DOUBLEBUFFER
44 * - Messages:
45 * - TB_GETMETRICS
46 * - TB_GETOBJECT
47 * - TB_INSERTMARKHITTEST
48 * - TB_SAVERESTORE
49 * - TB_SETMETRICS
50 * - Notifications:
51 * - NM_CHAR
52 * - NM_KEYDOWN
53 * - TBN_GETOBJECT
54 * - TBN_RESTORE
55 * - TBN_SAVE
56 * - Button wrapping (under construction).
57 * - Fix TB_SETROWS.
58 * - iListGap custom draw support.
60 * Testing:
61 * - Run tests using Waite Group Windows95 API Bible Volume 2.
62 * The second cdrom contains executables addstr.exe, btncount.exe,
63 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
64 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
65 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
66 * setparnt.exe, setrows.exe, toolwnd.exe.
67 * - Microsofts controlspy examples.
68 * - Charles Petzold's 'Programming Windows': gadgets.exe
71 #include <stdarg.h>
72 #include <string.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "wingdi.h"
77 #include "winuser.h"
78 #include "wine/unicode.h"
79 #include "winnls.h"
80 #include "commctrl.h"
81 #include "comctl32.h"
82 #include "wine/debug.h"
84 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
86 static HCURSOR hCursorDrag = NULL;
88 typedef struct
90 INT iBitmap;
91 INT idCommand;
92 BYTE fsState;
93 BYTE fsStyle;
94 BYTE bHot;
95 BYTE bDropDownPressed;
96 DWORD dwData;
97 INT iString;
98 INT nRow;
99 RECT rect;
100 INT cx; /* manually set size */
101 } TBUTTON_INFO;
103 typedef struct
105 UINT nButtons;
106 HINSTANCE hInst;
107 UINT nID;
108 } TBITMAP_INFO;
110 typedef struct
112 HIMAGELIST himl;
113 INT id;
114 } IMLENTRY, *PIMLENTRY;
116 typedef struct
118 DWORD dwStructSize; /* size of TBBUTTON struct */
119 INT nHeight; /* height of the toolbar */
120 INT nWidth; /* width of the toolbar */
121 RECT client_rect;
122 RECT rcBound; /* bounding rectangle */
123 INT nButtonHeight;
124 INT nButtonWidth;
125 INT nBitmapHeight;
126 INT nBitmapWidth;
127 INT nIndent;
128 INT nRows; /* number of button rows */
129 INT nMaxTextRows; /* maximum number of text rows */
130 INT cxMin; /* minimum button width */
131 INT cxMax; /* maximum button width */
132 INT nNumButtons; /* number of buttons */
133 INT nNumBitmaps; /* number of bitmaps */
134 INT nNumStrings; /* number of strings */
135 INT nNumBitmapInfos;
136 INT nButtonDown; /* toolbar button being pressed or -1 if none */
137 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
138 INT nOldHit;
139 INT nHotItem; /* index of the "hot" item */
140 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
141 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
142 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
143 SIZE szPadding; /* padding values around button */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hDefaultFont;
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bBtnTranspnt; /* button transparency flag */
158 BOOL bAutoSize; /* auto size deadlock indicator */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
161 BOOL bDoRedraw; /* Redraw status */
162 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
163 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
164 BOOL bCaptured; /* mouse captured? */
165 DWORD dwStyle; /* regular toolbar style */
166 DWORD dwExStyle; /* extended toolbar style */
167 DWORD dwDTFlags; /* DrawText flags */
169 COLORREF clrInsertMark; /* insert mark color */
170 COLORREF clrBtnHighlight; /* color for Flat Separator */
171 COLORREF clrBtnShadow; /* color for Flag Separator */
172 INT iVersion;
173 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
174 * for TTN_GETDISPINFOW notification */
175 TBINSERTMARK tbim; /* info on insertion mark */
176 TBUTTON_INFO *buttons; /* pointer to button array */
177 LPWSTR *strings; /* pointer to string array */
178 TBITMAP_INFO *bitmaps;
179 } TOOLBAR_INFO, *PTOOLBAR_INFO;
182 /* used by customization dialog */
183 typedef struct
185 PTOOLBAR_INFO tbInfo;
186 HWND tbHwnd;
187 } CUSTDLG_INFO, *PCUSTDLG_INFO;
189 typedef struct
191 TBBUTTON btn;
192 BOOL bVirtual;
193 BOOL bRemovable;
194 WCHAR text[64];
195 } CUSTOMBUTTON, *PCUSTOMBUTTON;
197 typedef enum
199 IMAGE_LIST_DEFAULT,
200 IMAGE_LIST_HOT,
201 IMAGE_LIST_DISABLED
202 } IMAGE_LIST_TYPE;
204 #define SEPARATOR_WIDTH 8
205 #define TOP_BORDER 2
206 #define BOTTOM_BORDER 2
207 #define DDARROW_WIDTH 11
208 #define ARROW_HEIGHT 3
209 #define INSERTMARK_WIDTH 2
211 /* gap between border of button and text/image */
212 #define OFFSET_X 1
213 #define OFFSET_Y 1
214 /* how wide to treat the bitmap if it isn't present */
215 #define LIST_IMAGE_ABSENT_WIDTH 2
217 #define TOOLBAR_NOWHERE (-1)
219 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
225 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
228 /* Used to find undocumented extended styles */
229 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
230 TBSTYLE_EX_UNDOC1 | \
231 TBSTYLE_EX_MIXEDBUTTONS | \
232 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
241 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
242 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
243 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
244 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
245 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
246 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
247 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
249 static LRESULT
250 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
253 static LPWSTR
254 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
256 LPWSTR lpText = NULL;
258 /* NOTE: iString == -1 is undocumented */
259 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
260 lpText = (LPWSTR)btnPtr->iString;
261 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
262 lpText = infoPtr->strings[btnPtr->iString];
264 return lpText;
267 static void
268 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
270 if (TRACE_ON(toolbar)){
271 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
272 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
273 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
274 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
275 if (internal)
276 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
277 btn_num, bP->idCommand,
278 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
279 bP->rect.left, bP->rect.top,
280 bP->rect.right, bP->rect.bottom);
285 static void
286 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
288 if (TRACE_ON(toolbar)) {
289 INT i;
291 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
292 iP->hwndSelf, line,
293 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
294 iP->nNumStrings, iP->dwStyle);
295 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
296 iP->hwndSelf, line,
297 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
298 (iP->bDoRedraw) ? "TRUE" : "FALSE");
299 for(i=0; i<iP->nNumButtons; i++) {
300 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
306 /***********************************************************************
307 * TOOLBAR_CheckStyle
309 * This function validates that the styles set are implemented and
310 * issues FIXME's warning of possible problems. In a perfect world this
311 * function should be null.
313 static void
314 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
316 if (dwStyle & TBSTYLE_REGISTERDROP)
317 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
321 static INT
322 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
324 if(!IsWindow(infoPtr->hwndSelf))
325 return 0; /* we have just been destroyed */
327 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
328 nmhdr->hwndFrom = infoPtr->hwndSelf;
329 nmhdr->code = code;
331 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
332 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
334 if (infoPtr->bNtfUnicode)
335 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
336 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
337 else
338 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
349 static INT
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK) {
355 /* issue TBN_GETDISPINFO */
356 NMTBDISPINFOA nmgd;
358 nmgd.idCommand = btnPtr->idCommand;
359 nmgd.lParam = btnPtr->dwData;
360 nmgd.dwMask = TBNF_IMAGE;
361 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
362 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
363 TBN_GETDISPINFOA);
364 if (nmgd.dwMask & TBNF_DI_SETITEM) {
365 btnPtr->iBitmap = nmgd.iImage;
367 ret = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
375 return ret;
379 static BOOL
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
382 HIMAGELIST himl;
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
389 return TRUE;
390 else
391 return FALSE;
395 /***********************************************************************
396 * TOOLBAR_GetImageListForDrawing
398 * This function validates the bitmap index (including I_IMAGECALLBACK
399 * functionality) and returns the corresponding image list.
401 static HIMAGELIST
402 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
404 HIMAGELIST himl;
406 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
407 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
408 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
409 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
410 return NULL;
413 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
414 if ((*index == I_IMAGECALLBACK) ||
415 (*index == I_IMAGENONE)) return NULL;
416 ERR("TBN_GETDISPINFO returned invalid index %d\n",
417 *index);
418 return NULL;
421 switch(imagelist)
423 case IMAGE_LIST_DEFAULT:
424 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
425 break;
426 case IMAGE_LIST_HOT:
427 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
428 break;
429 case IMAGE_LIST_DISABLED:
430 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
431 break;
432 default:
433 himl = NULL;
434 FIXME("Shouldn't reach here\n");
437 if (!himl)
438 TRACE("no image list\n");
440 return himl;
444 /***********************************************************************
445 * TOOLBAR_TestImageExist
447 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
448 * return the image list. The I_IMAGECALLBACK functionality is implemented.
450 static BOOL
451 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
453 INT index;
455 if (!himl) return FALSE;
457 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
458 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
459 ERR("index %d is not valid, max %d\n",
460 btnPtr->iBitmap, infoPtr->nNumBitmaps);
461 return FALSE;
464 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
465 if ((index == I_IMAGECALLBACK) ||
466 (index == I_IMAGENONE)) return FALSE;
467 ERR("TBN_GETDISPINFO returned invalid index %d\n",
468 index);
469 return FALSE;
471 return TRUE;
475 static void
476 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
478 RECT myrect;
479 COLORREF oldcolor, newcolor;
481 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
482 myrect.right = myrect.left + 1;
483 myrect.top = lpRect->top + 2;
484 myrect.bottom = lpRect->bottom - 2;
486 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
487 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
488 oldcolor = SetBkColor (hdc, newcolor);
489 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
491 myrect.left = myrect.right;
492 myrect.right = myrect.left + 1;
494 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
495 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
496 SetBkColor (hdc, newcolor);
497 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
499 SetBkColor (hdc, oldcolor);
503 /***********************************************************************
504 * TOOLBAR_DrawDDFlatSeparator
506 * This function draws the separator that was flagged as BTNS_DROPDOWN.
507 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
508 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
509 * are horizontal as opposed to the vertical separators for not dropdown
510 * type.
512 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
514 static void
515 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
517 RECT myrect;
518 COLORREF oldcolor, newcolor;
520 myrect.left = lpRect->left;
521 myrect.right = lpRect->right;
522 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
523 myrect.bottom = myrect.top + 1;
525 InflateRect (&myrect, -2, 0);
527 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
528 myrect.left, myrect.top, myrect.right, myrect.bottom);
530 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
531 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
532 oldcolor = SetBkColor (hdc, newcolor);
533 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
535 myrect.top = myrect.bottom;
536 myrect.bottom = myrect.top + 1;
538 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
539 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
540 SetBkColor (hdc, newcolor);
541 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
543 SetBkColor (hdc, oldcolor);
547 static void
548 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
550 INT x, y;
551 HPEN hPen, hOldPen;
553 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
554 hOldPen = SelectObject ( hdc, hPen );
555 x = left + 2;
556 y = top;
557 MoveToEx (hdc, x, y, NULL);
558 LineTo (hdc, x+5, y++); x++;
559 MoveToEx (hdc, x, y, NULL);
560 LineTo (hdc, x+3, y++); x++;
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+1, y++);
563 SelectObject( hdc, hOldPen );
564 DeleteObject( hPen );
568 * Draw the text string for this button.
569 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
570 * is non-zero, so we can simply check himlDef to see if we have
571 * an image list
573 static void
574 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
575 NMTBCUSTOMDRAW *tbcd)
577 HDC hdc = tbcd->nmcd.hdc;
578 HFONT hOldFont = 0;
579 COLORREF clrOld = 0;
580 COLORREF clrOldBk = 0;
581 int oldBkMode = 0;
582 UINT state = tbcd->nmcd.uItemState;
584 /* draw text */
585 if (lpText) {
586 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
587 rcText->left, rcText->top, rcText->right, rcText->bottom);
589 hOldFont = SelectObject (hdc, infoPtr->hFont);
590 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
591 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
593 else if (state & CDIS_DISABLED) {
594 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
595 OffsetRect (rcText, 1, 1);
596 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
597 SetTextColor (hdc, comctl32_color.clr3dShadow);
598 OffsetRect (rcText, -1, -1);
600 else if (state & CDIS_INDETERMINATE) {
601 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
603 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
604 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
605 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
606 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
608 else {
609 clrOld = SetTextColor (hdc, tbcd->clrText);
612 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
613 SetTextColor (hdc, clrOld);
614 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
616 SetBkColor (hdc, clrOldBk);
617 SetBkMode (hdc, oldBkMode);
619 SelectObject (hdc, hOldFont);
624 static void
625 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
627 HDC hdc = tbcd->nmcd.hdc;
628 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
629 COLORREF clrTextOld;
630 COLORREF clrBkOld;
631 INT cx = lpRect->right - lpRect->left;
632 INT cy = lpRect->bottom - lpRect->top;
633 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
634 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
635 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
636 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
637 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
638 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
639 SetBkColor(hdc, clrBkOld);
640 SetTextColor(hdc, clrTextOld);
641 SelectObject (hdc, hbr);
645 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
647 INT cx, cy;
648 HBITMAP hbmMask, hbmImage;
649 HDC hdcMask, hdcImage;
651 ImageList_GetIconSize(himl, &cx, &cy);
653 /* Create src image */
654 hdcImage = CreateCompatibleDC(hdc);
655 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
656 SelectObject(hdcImage, hbmImage);
657 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
658 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
660 /* Create Mask */
661 hdcMask = CreateCompatibleDC(0);
662 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
663 SelectObject(hdcMask, hbmMask);
665 /* Remove the background and all white pixels */
666 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
667 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
668 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
669 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
671 /* draw the new mask 'etched' to hdc */
672 SetBkColor(hdc, RGB(255, 255, 255));
673 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
674 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
675 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
676 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
677 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
679 /* Cleanup */
680 DeleteObject(hbmImage);
681 DeleteDC(hdcImage);
682 DeleteObject (hbmMask);
683 DeleteDC(hdcMask);
687 static UINT
688 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
690 UINT retstate = 0;
692 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
693 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
694 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
695 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
696 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
698 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
699 return retstate;
702 /* draws the image on a toolbar button */
703 static void
704 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
706 HIMAGELIST himl = NULL;
707 BOOL draw_masked = FALSE;
708 INT index;
709 INT offset = 0;
710 UINT draw_flags = ILD_NORMAL;
712 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
715 if (!himl)
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
718 draw_masked = TRUE;
721 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
723 /* if hot, attempt to draw with hot image list, if fails,
724 use default image list */
725 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
726 if (!himl)
727 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
729 else
730 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
732 if (!himl)
733 return;
735 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
736 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
737 offset = 1;
739 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
740 (tbcd->nmcd.uItemState & CDIS_MARKED))
741 draw_flags |= ILD_BLEND50;
743 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
744 index, himl, left, top, offset);
746 if (draw_masked)
747 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
748 else
749 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
752 /* draws a blank frame for a toolbar button */
753 static void
754 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
756 HDC hdc = tbcd->nmcd.hdc;
757 RECT rc = tbcd->nmcd.rc;
758 /* if the state is disabled or indeterminate then the button
759 * cannot have an interactive look like pressed or hot */
760 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
761 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
762 BOOL pressed_look = !non_interactive_state &&
763 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
764 (tbcd->nmcd.uItemState & CDIS_CHECKED));
766 /* app don't want us to draw any edges */
767 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
768 return;
770 if (flat)
772 if (pressed_look)
773 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
774 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
775 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
777 else
779 if (pressed_look)
780 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
781 else
782 DrawEdge (hdc, &rc, EDGE_RAISED,
783 BF_SOFT | BF_RECT | BF_MIDDLE);
787 static void
788 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
790 HDC hdc = tbcd->nmcd.hdc;
791 int offset = 0;
792 BOOL pressed = bDropDownPressed ||
793 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
795 if (infoPtr->dwStyle & TBSTYLE_FLAT)
797 if (pressed)
798 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
799 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
800 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
801 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
802 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
804 else
806 if (pressed)
807 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
808 else
809 DrawEdge (hdc, rcArrow, EDGE_RAISED,
810 BF_SOFT | BF_RECT | BF_MIDDLE);
813 if (pressed)
814 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
816 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
818 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
819 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
821 else
822 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
825 /* draws a complete toolbar button */
826 static void
827 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
830 DWORD dwStyle = infoPtr->dwStyle;
831 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
832 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
833 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
834 BOOL drawSepDropDownArrow = hasDropDownArrow &&
835 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
836 RECT rc, rcArrow, rcBitmap, rcText;
837 LPWSTR lpText = NULL;
838 NMTBCUSTOMDRAW tbcd;
839 DWORD ntfret;
840 INT offset;
842 rc = btnPtr->rect;
843 CopyRect (&rcArrow, &rc);
844 CopyRect(&rcBitmap, &rc);
846 /* get a pointer to the text */
847 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
849 if (hasDropDownArrow)
851 int right;
853 if (dwStyle & TBSTYLE_FLAT)
854 right = max(rc.left, rc.right - DDARROW_WIDTH);
855 else
856 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
858 if (drawSepDropDownArrow)
859 rc.right = right;
861 rcArrow.left = right;
864 /* copy text rect after adjusting for drop-down arrow
865 * so that text is centred in the rectangle not containing
866 * the arrow */
867 CopyRect(&rcText, &rc);
869 /* Center the bitmap horizontally and vertically */
870 if (dwStyle & TBSTYLE_LIST)
871 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
872 else
873 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
875 if(lpText)
876 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
877 else
878 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
880 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
881 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
882 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
883 TRACE ("iString: %x\n", btnPtr->iString);
884 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
886 /* draw text */
887 if (lpText) {
888 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
889 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
890 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
891 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
893 if (dwStyle & TBSTYLE_LIST)
894 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
895 else
896 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
898 else
899 if (dwStyle & TBSTYLE_LIST)
900 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
902 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
903 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
904 OffsetRect(&rcText, 1, 1);
907 /* Initialize fields in all cases, because we use these later
908 * NOTE: applications can and do alter these to customize their
909 * toolbars */
910 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
911 tbcd.clrText = comctl32_color.clrBtnText;
912 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
913 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
914 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
915 tbcd.clrMark = comctl32_color.clrHighlight;
916 tbcd.clrHighlightHotTrack = 0;
917 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
918 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 /* MSDN says that this is the text rectangle.
920 * But (why always a but) tracing of v5.7 of native shows
921 * that this is really a *relative* rectangle based on the
922 * the nmcd.rc. Also the left and top are always 0 ignoring
923 * any bitmap that might be present. */
924 tbcd.rcText.left = 0;
925 tbcd.rcText.top = 0;
926 tbcd.rcText.right = rcText.right - rc.left;
927 tbcd.rcText.bottom = rcText.bottom - rc.top;
928 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
929 tbcd.nmcd.hdc = hdc;
930 tbcd.nmcd.rc = rc;
931 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
933 /* FIXME: what are these used for? */
934 tbcd.hbrLines = 0;
935 tbcd.hpenLines = 0;
937 /* Issue Item Prepaint notify */
938 infoPtr->dwItemCustDraw = 0;
939 infoPtr->dwItemCDFlag = 0;
940 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
942 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
943 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
944 tbcd.nmcd.lItemlParam = btnPtr->dwData;
945 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
946 /* reset these fields so the user can't alter the behaviour like native */
947 tbcd.nmcd.hdc = hdc;
948 tbcd.nmcd.rc = rc;
950 infoPtr->dwItemCustDraw = ntfret & 0xffff;
951 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
952 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
953 return;
954 /* save the only part of the rect that the user can change */
955 rcText.right = tbcd.rcText.right + rc.left;
956 rcText.bottom = tbcd.rcText.bottom + rc.top;
959 /* separator */
960 if (btnPtr->fsStyle & BTNS_SEP) {
961 /* with the FLAT style, iBitmap is the width and has already */
962 /* been taken into consideration in calculating the width */
963 /* so now we need to draw the vertical separator */
964 /* empirical tests show that iBitmap can/will be non-zero */
965 /* when drawing the vertical bar... */
966 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
967 if (btnPtr->fsStyle & BTNS_DROPDOWN)
968 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
969 else
970 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
972 else if (btnPtr->fsStyle != BTNS_SEP) {
973 FIXME("Draw some kind of separator: fsStyle=%x\n",
974 btnPtr->fsStyle);
976 goto FINALNOTIFY;
979 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
980 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
981 TOOLBAR_DrawPattern (&rc, &tbcd);
983 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
985 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
987 COLORREF oldclr;
989 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
990 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
991 if (hasDropDownArrow)
992 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
993 SetBkColor(hdc, oldclr);
997 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
999 if (drawSepDropDownArrow)
1000 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1002 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1003 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1005 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1007 if (hasDropDownArrow && !drawSepDropDownArrow)
1009 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1011 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1014 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1016 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1017 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1019 else
1020 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1023 FINALNOTIFY:
1024 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1026 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1027 tbcd.nmcd.hdc = hdc;
1028 tbcd.nmcd.rc = rc;
1029 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1030 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1031 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1032 tbcd.rcText = rcText;
1033 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1034 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1041 static void
1042 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1045 TBUTTON_INFO *btnPtr;
1046 INT i, oldBKmode = 0;
1047 RECT rcTemp, rcClient;
1048 NMTBCUSTOMDRAW tbcd;
1049 DWORD ntfret;
1051 /* the app has told us not to redraw the toolbar */
1052 if (!infoPtr->bDoRedraw)
1053 return;
1055 /* if imagelist belongs to the app, it can be changed
1056 by the app after setting it */
1057 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1059 infoPtr->nNumBitmaps = 0;
1060 for (i = 0; i < infoPtr->cimlDef; i++)
1061 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1064 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1066 /* Send initial notify */
1067 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1068 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1069 tbcd.nmcd.hdc = hdc;
1070 tbcd.nmcd.rc = ps->rcPaint;
1071 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1072 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1074 if (infoPtr->bBtnTranspnt)
1075 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1077 GetClientRect(hwnd, &rcClient);
1079 /* redraw necessary buttons */
1080 btnPtr = infoPtr->buttons;
1081 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1083 BOOL bDraw;
1084 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1086 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1087 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1089 else
1090 bDraw = TRUE;
1091 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1092 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1093 if (bDraw)
1094 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1097 /* draw insert mark if required */
1098 if (infoPtr->tbim.iButton != -1)
1100 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1101 RECT rcInsertMark;
1102 rcInsertMark.top = rcButton.top;
1103 rcInsertMark.bottom = rcButton.bottom;
1104 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1105 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1106 else
1107 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1108 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1111 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1112 SetBkMode (hdc, oldBKmode);
1114 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1116 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1117 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1118 tbcd.nmcd.hdc = hdc;
1119 tbcd.nmcd.rc = ps->rcPaint;
1120 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1124 /***********************************************************************
1125 * TOOLBAR_MeasureString
1127 * This function gets the width and height of a string in pixels. This
1128 * is done first by using GetTextExtentPoint to get the basic width
1129 * and height. The DrawText is called with DT_CALCRECT to get the exact
1130 * width. The reason is because the text may have more than one "&" (or
1131 * prefix characters as M$ likes to call them). The prefix character
1132 * indicates where the underline goes, except for the string "&&" which
1133 * is reduced to a single "&". GetTextExtentPoint does not process these
1134 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1136 static void
1137 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1138 HDC hdc, LPSIZE lpSize)
1140 RECT myrect;
1142 lpSize->cx = 0;
1143 lpSize->cy = 0;
1145 if (infoPtr->nMaxTextRows > 0 &&
1146 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1147 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1148 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1150 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1152 if(lpText != NULL) {
1153 /* first get size of all the text */
1154 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1156 /* feed above size into the rectangle for DrawText */
1157 myrect.left = myrect.top = 0;
1158 myrect.right = lpSize->cx;
1159 myrect.bottom = lpSize->cy;
1161 /* Use DrawText to get true size as drawn (less pesky "&") */
1162 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1163 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1164 DT_NOPREFIX : 0));
1166 /* feed back to caller */
1167 lpSize->cx = myrect.right;
1168 lpSize->cy = myrect.bottom;
1172 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1175 /***********************************************************************
1176 * TOOLBAR_CalcStrings
1178 * This function walks through each string and measures it and returns
1179 * the largest height and width to caller.
1181 static void
1182 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1185 TBUTTON_INFO *btnPtr;
1186 INT i;
1187 SIZE sz;
1188 HDC hdc;
1189 HFONT hOldFont;
1191 lpSize->cx = 0;
1192 lpSize->cy = 0;
1194 if(infoPtr->nMaxTextRows == 0)
1195 return;
1197 hdc = GetDC (hwnd);
1198 hOldFont = SelectObject (hdc, infoPtr->hFont);
1200 btnPtr = infoPtr->buttons;
1201 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1202 if(TOOLBAR_HasText(infoPtr, btnPtr))
1204 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1205 if (sz.cx > lpSize->cx)
1206 lpSize->cx = sz.cx;
1207 if (sz.cy > lpSize->cy)
1208 lpSize->cy = sz.cy;
1212 SelectObject (hdc, hOldFont);
1213 ReleaseDC (hwnd, hdc);
1215 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1218 /***********************************************************************
1219 * TOOLBAR_WrapToolbar
1221 * This function walks through the buttons and separators in the
1222 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1223 * wrapping should occur based on the width of the toolbar window.
1224 * It does *not* calculate button placement itself. That task
1225 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1226 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1227 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1229 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1230 * vertical toolbar lists.
1233 static void
1234 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1237 TBUTTON_INFO *btnPtr;
1238 INT x, cx, i, j;
1239 RECT rc;
1240 BOOL bWrap, bButtonWrap;
1242 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1243 /* no layout is necessary. Applications may use this style */
1244 /* to perform their own layout on the toolbar. */
1245 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1246 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1248 btnPtr = infoPtr->buttons;
1249 x = infoPtr->nIndent;
1251 /* this can get the parents width, to know how far we can extend
1252 * this toolbar. We cannot use its height, as there may be multiple
1253 * toolbars in a rebar control
1255 GetClientRect( GetParent(hwnd), &rc );
1256 infoPtr->nWidth = rc.right - rc.left;
1257 bButtonWrap = FALSE;
1259 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1260 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1261 infoPtr->nIndent);
1263 for (i = 0; i < infoPtr->nNumButtons; i++ )
1265 bWrap = FALSE;
1266 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1268 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1269 continue;
1271 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1272 /* it is the actual width of the separator. This is used for */
1273 /* custom controls in toolbars. */
1274 /* */
1275 /* BTNS_DROPDOWN separators are treated as buttons for */
1276 /* width. - GA 8/01 */
1277 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1278 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1279 cx = (btnPtr[i].iBitmap > 0) ?
1280 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1281 else
1282 cx = infoPtr->nButtonWidth;
1284 /* Two or more adjacent separators form a separator group. */
1285 /* The first separator in a group should be wrapped to the */
1286 /* next row if the previous wrapping is on a button. */
1287 if( bButtonWrap &&
1288 (btnPtr[i].fsStyle & BTNS_SEP) &&
1289 (i + 1 < infoPtr->nNumButtons ) &&
1290 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1292 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1293 btnPtr[i].fsState |= TBSTATE_WRAP;
1294 x = infoPtr->nIndent;
1295 i++;
1296 bButtonWrap = FALSE;
1297 continue;
1300 /* The layout makes sure the bitmap is visible, but not the button. */
1301 /* Test added to also wrap after a button that starts a row but */
1302 /* is bigger than the area. - GA 8/01 */
1303 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1304 > infoPtr->nWidth ) ||
1305 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1307 BOOL bFound = FALSE;
1309 /* If the current button is a separator and not hidden, */
1310 /* go to the next until it reaches a non separator. */
1311 /* Wrap the last separator if it is before a button. */
1312 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1313 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1314 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1315 i < infoPtr->nNumButtons )
1317 i++;
1318 bFound = TRUE;
1321 if( bFound && i < infoPtr->nNumButtons )
1323 i--;
1324 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1325 i, btnPtr[i].fsStyle, x, cx);
1326 btnPtr[i].fsState |= TBSTATE_WRAP;
1327 x = infoPtr->nIndent;
1328 bButtonWrap = FALSE;
1329 continue;
1331 else if ( i >= infoPtr->nNumButtons)
1332 break;
1334 /* If the current button is not a separator, find the last */
1335 /* separator and wrap it. */
1336 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1338 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1339 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1341 bFound = TRUE;
1342 i = j;
1343 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1344 i, btnPtr[i].fsStyle, x, cx);
1345 x = infoPtr->nIndent;
1346 btnPtr[j].fsState |= TBSTATE_WRAP;
1347 bButtonWrap = FALSE;
1348 break;
1352 /* If no separator available for wrapping, wrap one of */
1353 /* non-hidden previous button. */
1354 if (!bFound)
1356 for ( j = i - 1;
1357 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1359 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1360 continue;
1362 bFound = TRUE;
1363 i = j;
1364 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1365 i, btnPtr[i].fsStyle, x, cx);
1366 x = infoPtr->nIndent;
1367 btnPtr[j].fsState |= TBSTATE_WRAP;
1368 bButtonWrap = TRUE;
1369 break;
1373 /* If all above failed, wrap the current button. */
1374 if (!bFound)
1376 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1378 btnPtr[i].fsState |= TBSTATE_WRAP;
1379 bFound = TRUE;
1380 x = infoPtr->nIndent;
1381 if (btnPtr[i].fsStyle & BTNS_SEP )
1382 bButtonWrap = FALSE;
1383 else
1384 bButtonWrap = TRUE;
1387 else {
1388 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1389 i, btnPtr[i].fsStyle, x, cx);
1390 x += cx;
1396 /***********************************************************************
1397 * TOOLBAR_CalcToolbar
1399 * This function calculates button and separator placement. It first
1400 * calculates the button sizes, gets the toolbar window width and then
1401 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1402 * on. It assigns a new location to each item and sends this location to
1403 * the tooltip window if appropriate. Finally, it updates the rcBound
1404 * rect and calculates the new required toolbar window height.
1407 static void
1408 TOOLBAR_CalcToolbar (HWND hwnd)
1410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1411 DWORD dwStyle = infoPtr->dwStyle;
1412 TBUTTON_INFO *btnPtr;
1413 INT i, nRows, nSepRows;
1414 INT x, y, cx, cy;
1415 SIZE sizeString;
1416 BOOL bWrap;
1417 BOOL usesBitmaps = FALSE;
1418 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1420 TOOLBAR_CalcStrings (hwnd, &sizeString);
1422 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1424 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1426 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1427 usesBitmaps = TRUE;
1429 if (dwStyle & TBSTYLE_LIST)
1431 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1432 0, sizeString.cy) + infoPtr->szPadding.cy;
1433 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1434 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1435 if (sizeString.cx > 0)
1436 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1437 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1438 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1439 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1441 else {
1442 if (sizeString.cy > 0)
1444 if (usesBitmaps)
1445 infoPtr->nButtonHeight = sizeString.cy +
1446 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1447 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1448 else
1449 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1451 else
1452 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1454 if (sizeString.cx > infoPtr->nBitmapWidth)
1455 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1456 else
1457 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1460 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1461 infoPtr->nButtonWidth = infoPtr->cxMin;
1462 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1463 infoPtr->nButtonWidth = infoPtr->cxMax;
1465 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1467 x = infoPtr->nIndent;
1468 y = 0;
1470 /* from above, minimum is a button, and possible text */
1471 cx = infoPtr->nButtonWidth;
1473 /* cannot use just ButtonHeight, we may have no buttons! */
1474 if (infoPtr->nNumButtons > 0)
1475 infoPtr->nHeight = infoPtr->nButtonHeight;
1477 cy = infoPtr->nHeight;
1479 nRows = nSepRows = 0;
1481 infoPtr->rcBound.top = y;
1482 infoPtr->rcBound.left = x;
1483 infoPtr->rcBound.bottom = y + cy;
1484 infoPtr->rcBound.right = x;
1486 btnPtr = infoPtr->buttons;
1488 TRACE("cy=%d\n", cy);
1490 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1492 bWrap = FALSE;
1493 if (btnPtr->fsState & TBSTATE_HIDDEN)
1495 SetRectEmpty (&btnPtr->rect);
1496 continue;
1499 cy = infoPtr->nHeight;
1501 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1502 /* it is the actual width of the separator. This is used for */
1503 /* custom controls in toolbars. */
1504 if (btnPtr->fsStyle & BTNS_SEP) {
1505 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1506 cy = (btnPtr->iBitmap > 0) ?
1507 btnPtr->iBitmap : SEPARATOR_WIDTH;
1508 cx = infoPtr->nButtonWidth;
1510 else
1511 cx = (btnPtr->iBitmap > 0) ?
1512 btnPtr->iBitmap : SEPARATOR_WIDTH;
1514 else
1516 if (btnPtr->cx)
1517 cx = btnPtr->cx;
1518 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1519 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1521 SIZE sz;
1522 HDC hdc;
1523 HFONT hOldFont;
1525 hdc = GetDC (hwnd);
1526 hOldFont = SelectObject (hdc, infoPtr->hFont);
1528 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1530 SelectObject (hdc, hOldFont);
1531 ReleaseDC (hwnd, hdc);
1533 /* add space on for button frame, etc */
1534 cx = sz.cx + infoPtr->szPadding.cx;
1536 /* add list padding */
1537 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1538 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1540 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1542 if (dwStyle & TBSTYLE_LIST)
1543 cx += infoPtr->nBitmapWidth;
1544 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1545 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1547 else if (dwStyle & TBSTYLE_LIST)
1548 cx += LIST_IMAGE_ABSENT_WIDTH;
1550 else
1551 cx = infoPtr->nButtonWidth;
1553 /* if size has been set manually then don't add on extra space
1554 * for the drop down arrow */
1555 if (!btnPtr->cx && hasDropDownArrows &&
1556 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1557 cx += DDARROW_WIDTH;
1559 if (btnPtr->fsState & TBSTATE_WRAP )
1560 bWrap = TRUE;
1562 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1564 if (infoPtr->rcBound.left > x)
1565 infoPtr->rcBound.left = x;
1566 if (infoPtr->rcBound.right < x + cx)
1567 infoPtr->rcBound.right = x + cx;
1568 if (infoPtr->rcBound.bottom < y + cy)
1569 infoPtr->rcBound.bottom = y + cy;
1571 /* Set the toolTip only for non-hidden, non-separator button */
1572 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1574 TTTOOLINFOW ti;
1576 ZeroMemory (&ti, sizeof(ti));
1577 ti.cbSize = sizeof(ti);
1578 ti.hwnd = hwnd;
1579 ti.uId = btnPtr->idCommand;
1580 ti.rect = btnPtr->rect;
1581 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1582 0, (LPARAM)&ti);
1585 /* btnPtr->nRow is zero based. The space between the rows is */
1586 /* also considered as a row. */
1587 btnPtr->nRow = nRows + nSepRows;
1589 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1590 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1591 x, y, x+cx, y+cy);
1593 if( bWrap )
1595 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1596 y += cy;
1597 else
1599 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1600 /* it is the actual width of the separator. This is used for */
1601 /* custom controls in toolbars. */
1602 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1603 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1604 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1605 else
1606 y += cy;
1608 /* nSepRows is used to calculate the extra height follwoing */
1609 /* the last row. */
1610 nSepRows++;
1612 x = infoPtr->nIndent;
1614 /* Increment row number unless this is the last button */
1615 /* and it has Wrap set. */
1616 if (i != infoPtr->nNumButtons-1)
1617 nRows++;
1619 else
1620 x += cx;
1623 /* infoPtr->nRows is the number of rows on the toolbar */
1624 infoPtr->nRows = nRows + nSepRows + 1;
1626 #if 0
1627 /********************************************************************
1628 * The following while interesting, does not match the values *
1629 * created above for the button rectangles, nor the rcBound rect. *
1630 * We will comment it out and remove it later. *
1632 * The problem showed up as heights in the pager control that was *
1633 * wrong. *
1634 ********************************************************************/
1636 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1637 /* the last row. */
1638 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1639 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1640 nSepRows * (infoPtr->nBitmapHeight + 1) +
1641 BOTTOM_BORDER;
1642 #endif
1644 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1646 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1650 static INT
1651 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1654 TBUTTON_INFO *btnPtr;
1655 INT i;
1657 btnPtr = infoPtr->buttons;
1658 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1659 if (btnPtr->fsState & TBSTATE_HIDDEN)
1660 continue;
1662 if (btnPtr->fsStyle & BTNS_SEP) {
1663 if (PtInRect (&btnPtr->rect, *lpPt)) {
1664 TRACE(" ON SEPARATOR %d!\n", i);
1665 return -i;
1668 else {
1669 if (PtInRect (&btnPtr->rect, *lpPt)) {
1670 TRACE(" ON BUTTON %d!\n", i);
1671 return i;
1676 TRACE(" NOWHERE!\n");
1677 return TOOLBAR_NOWHERE;
1681 static INT
1682 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1684 TBUTTON_INFO *btnPtr;
1685 INT i;
1687 if (CommandIsIndex) {
1688 TRACE("command is really index command=%d\n", idCommand);
1689 if (idCommand >= infoPtr->nNumButtons) return -1;
1690 return idCommand;
1692 btnPtr = infoPtr->buttons;
1693 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1694 if (btnPtr->idCommand == idCommand) {
1695 TRACE("command=%d index=%d\n", idCommand, i);
1696 return i;
1699 TRACE("no index found for command=%d\n", idCommand);
1700 return -1;
1704 static INT
1705 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1707 TBUTTON_INFO *btnPtr;
1708 INT nRunIndex;
1710 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1711 return -1;
1713 /* check index button */
1714 btnPtr = &infoPtr->buttons[nIndex];
1715 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1716 if (btnPtr->fsState & TBSTATE_CHECKED)
1717 return nIndex;
1720 /* check previous buttons */
1721 nRunIndex = nIndex - 1;
1722 while (nRunIndex >= 0) {
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 /* check next buttons */
1734 nRunIndex = nIndex + 1;
1735 while (nRunIndex < infoPtr->nNumButtons) {
1736 btnPtr = &infoPtr->buttons[nRunIndex];
1737 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1738 if (btnPtr->fsState & TBSTATE_CHECKED)
1739 return nRunIndex;
1741 else
1742 break;
1743 nRunIndex++;
1746 return -1;
1750 static VOID
1751 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1752 WPARAM wParam, LPARAM lParam)
1754 MSG msg;
1756 msg.hwnd = hwndMsg;
1757 msg.message = uMsg;
1758 msg.wParam = wParam;
1759 msg.lParam = lParam;
1760 msg.time = GetMessageTime ();
1761 msg.pt.x = LOWORD(GetMessagePos ());
1762 msg.pt.y = HIWORD(GetMessagePos ());
1764 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1767 /* keeps available button list box sorted by button id */
1768 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1770 int i;
1771 int count;
1772 PCUSTOMBUTTON btnInfo;
1773 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1775 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1777 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1779 /* position 0 is always separator */
1780 for (i = 1; i < count; i++)
1782 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1783 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1785 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1786 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1787 return;
1790 /* id higher than all others add to end */
1791 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1792 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1795 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1797 NMTOOLBARW nmtb;
1799 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1801 if (nIndexFrom == nIndexTo)
1802 return;
1804 /* MSDN states that iItem is the index of the button, rather than the
1805 * command ID as used by every other NMTOOLBAR notification */
1806 nmtb.iItem = nIndexFrom;
1807 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1809 PCUSTOMBUTTON btnInfo;
1810 NMHDR hdr;
1811 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1812 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1814 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1816 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1817 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1818 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1819 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1821 if (nIndexTo <= 0)
1822 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1823 else
1824 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1826 /* last item is always separator, so -2 instead of -1 */
1827 if (nIndexTo >= (count - 2))
1828 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1829 else
1830 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1832 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1833 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1835 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1839 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1841 NMTOOLBARW nmtb;
1843 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1845 /* MSDN states that iItem is the index of the button, rather than the
1846 * command ID as used by every other NMTOOLBAR notification */
1847 nmtb.iItem = nIndexAvail;
1848 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1850 PCUSTOMBUTTON btnInfo;
1851 NMHDR hdr;
1852 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1853 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1854 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1856 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1858 if (nIndexAvail != 0) /* index == 0 indicates separator */
1860 /* remove from 'available buttons' list */
1861 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1862 if (nIndexAvail == count-1)
1863 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1864 else
1865 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1867 else
1869 PCUSTOMBUTTON btnNew;
1871 /* duplicate 'separator' button */
1872 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1873 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1874 btnInfo = btnNew;
1877 /* insert into 'toolbar button' list */
1878 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1879 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1881 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1883 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1887 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1889 PCUSTOMBUTTON btnInfo;
1890 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1892 TRACE("Remove: index %d\n", index);
1894 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
1896 /* send TBN_QUERYDELETE notification */
1897 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
1899 NMHDR hdr;
1901 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
1902 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
1904 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1906 /* insert into 'available button' list */
1907 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
1908 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
1909 else
1910 Free(btnInfo);
1912 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1916 /* drag list notification function for toolbar buttons list box */
1917 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1919 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1920 switch (pDLI->uNotification)
1922 case DL_BEGINDRAG:
1924 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1925 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1926 /* no dragging for last item (separator) */
1927 if (nCurrentItem >= (nCount - 1)) return FALSE;
1928 return TRUE;
1930 case DL_DRAGGING:
1932 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1933 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1934 /* no dragging past last item (separator) */
1935 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
1937 DrawInsert(hwnd, hwndList, nCurrentItem);
1938 /* FIXME: native uses "move button" cursor */
1939 return DL_COPYCURSOR;
1942 /* not over toolbar buttons list */
1943 if (nCurrentItem < 0)
1945 POINT ptWindow = pDLI->ptCursor;
1946 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1947 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1948 /* over available buttons list? */
1949 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1950 /* FIXME: native uses "move button" cursor */
1951 return DL_COPYCURSOR;
1953 /* clear drag arrow */
1954 DrawInsert(hwnd, hwndList, -1);
1955 return DL_STOPCURSOR;
1957 case DL_DROPPED:
1959 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1960 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
1961 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1962 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
1964 /* clear drag arrow */
1965 DrawInsert(hwnd, hwndList, -1);
1966 /* move item */
1967 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
1969 /* not over toolbar buttons list */
1970 if (nIndexTo < 0)
1972 POINT ptWindow = pDLI->ptCursor;
1973 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1974 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1975 /* over available buttons list? */
1976 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1977 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
1979 break;
1981 case DL_CANCELDRAG:
1982 /* Clear drag arrow */
1983 DrawInsert(hwnd, hwndList, -1);
1984 break;
1987 return 0;
1990 /* drag list notification function for available buttons list box */
1991 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1993 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1994 switch (pDLI->uNotification)
1996 case DL_BEGINDRAG:
1997 return TRUE;
1998 case DL_DRAGGING:
2000 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2001 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2002 /* no dragging past last item (separator) */
2003 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2005 DrawInsert(hwnd, hwndList, nCurrentItem);
2006 /* FIXME: native uses "move button" cursor */
2007 return DL_COPYCURSOR;
2010 /* not over toolbar buttons list */
2011 if (nCurrentItem < 0)
2013 POINT ptWindow = pDLI->ptCursor;
2014 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2015 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2016 /* over available buttons list? */
2017 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2018 /* FIXME: native uses "move button" cursor */
2019 return DL_COPYCURSOR;
2021 /* clear drag arrow */
2022 DrawInsert(hwnd, hwndList, -1);
2023 return DL_STOPCURSOR;
2025 case DL_DROPPED:
2027 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2028 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2029 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2030 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2032 /* clear drag arrow */
2033 DrawInsert(hwnd, hwndList, -1);
2034 /* add item */
2035 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2038 case DL_CANCELDRAG:
2039 /* Clear drag arrow */
2040 DrawInsert(hwnd, hwndList, -1);
2041 break;
2043 return 0;
2046 extern UINT uDragListMessage;
2048 /***********************************************************************
2049 * TOOLBAR_CustomizeDialogProc
2050 * This function implements the toolbar customization dialog.
2052 static INT_PTR CALLBACK
2053 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2055 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2056 PCUSTOMBUTTON btnInfo;
2057 NMTOOLBARA nmtb;
2058 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2060 switch (uMsg)
2062 case WM_INITDIALOG:
2063 custInfo = (PCUSTDLG_INFO)lParam;
2064 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2066 if (custInfo)
2068 WCHAR Buffer[256];
2069 int i = 0;
2070 int index;
2072 infoPtr = custInfo->tbInfo;
2074 /* send TBN_QUERYINSERT notification */
2075 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2077 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
2078 return FALSE;
2080 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2081 nmtb.iItem = (int)hwnd;
2082 /* Send TBN_INITCUSTOMIZE notification */
2083 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2084 TBNRF_HIDEHELP)
2086 TRACE("TBNRF_HIDEHELP requested\n");
2087 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2090 /* add items to 'toolbar buttons' list and check if removable */
2091 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2093 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2094 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2095 btnInfo->btn.fsStyle = BTNS_SEP;
2096 btnInfo->bVirtual = FALSE;
2097 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2099 /* send TBN_QUERYDELETE notification */
2100 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2102 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2103 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2106 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2108 /* insert separator button into 'available buttons' list */
2109 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2110 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2111 btnInfo->btn.fsStyle = BTNS_SEP;
2112 btnInfo->bVirtual = FALSE;
2113 btnInfo->bRemovable = TRUE;
2114 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2115 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2116 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2118 /* insert all buttons into dsa */
2119 for (i = 0;; i++)
2121 /* send TBN_GETBUTTONINFO notification */
2122 NMTOOLBARW nmtb;
2123 nmtb.iItem = i;
2124 nmtb.pszText = Buffer;
2125 nmtb.cchText = 256;
2127 /* Clear previous button's text */
2128 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2130 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2131 break;
2133 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2134 nmtb.tbButton.fsStyle, i,
2135 nmtb.tbButton.idCommand,
2136 nmtb.tbButton.iString,
2137 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2138 : "");
2140 /* insert button into the apropriate list */
2141 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2142 if (index == -1)
2144 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2145 btnInfo->bVirtual = FALSE;
2146 btnInfo->bRemovable = TRUE;
2148 else
2150 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2151 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2154 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2155 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2157 if (lstrlenW(nmtb.pszText))
2158 lstrcpyW(btnInfo->text, nmtb.pszText);
2159 else if (nmtb.tbButton.iString >= 0 &&
2160 nmtb.tbButton.iString < infoPtr->nNumStrings)
2162 lstrcpyW(btnInfo->text,
2163 infoPtr->strings[nmtb.tbButton.iString]);
2167 if (index == -1)
2168 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2171 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2173 /* select first item in the 'available' list */
2174 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2176 /* append 'virtual' separator button to the 'toolbar buttons' list */
2177 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2178 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2179 btnInfo->btn.fsStyle = BTNS_SEP;
2180 btnInfo->bVirtual = TRUE;
2181 btnInfo->bRemovable = FALSE;
2182 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2183 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2184 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2186 /* select last item in the 'toolbar' list */
2187 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2188 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2190 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2191 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2193 /* set focus and disable buttons */
2194 PostMessageW (hwnd, WM_USER, 0, 0);
2196 return TRUE;
2198 case WM_USER:
2199 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2200 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2201 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2202 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2203 return TRUE;
2205 case WM_CLOSE:
2206 EndDialog(hwnd, FALSE);
2207 return TRUE;
2209 case WM_COMMAND:
2210 switch (LOWORD(wParam))
2212 case IDC_TOOLBARBTN_LBOX:
2213 if (HIWORD(wParam) == LBN_SELCHANGE)
2215 PCUSTOMBUTTON btnInfo;
2216 NMTOOLBARA nmtb;
2217 int count;
2218 int index;
2220 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2221 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2223 /* send TBN_QUERYINSERT notification */
2224 nmtb.iItem = index;
2225 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2226 TBN_QUERYINSERT);
2228 /* get list box item */
2229 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2231 if (index == (count - 1))
2233 /* last item (virtual separator) */
2234 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2235 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2237 else if (index == (count - 2))
2239 /* second last item (last non-virtual item) */
2240 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2241 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2243 else if (index == 0)
2245 /* first item */
2246 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2247 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2249 else
2251 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2252 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2255 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2257 break;
2259 case IDC_MOVEUP_BTN:
2261 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2262 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2264 break;
2266 case IDC_MOVEDN_BTN: /* move down */
2268 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2269 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2271 break;
2273 case IDC_REMOVE_BTN: /* remove button */
2275 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2277 if (LB_ERR == index)
2278 break;
2280 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2282 break;
2283 case IDC_HELP_BTN:
2284 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2285 break;
2286 case IDC_RESET_BTN:
2287 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2288 break;
2290 case IDOK: /* Add button */
2292 int index;
2293 int indexto;
2295 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2296 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2298 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2300 break;
2302 case IDCANCEL:
2303 EndDialog(hwnd, FALSE);
2304 break;
2306 return TRUE;
2308 case WM_DESTROY:
2310 int count;
2311 int i;
2313 /* delete items from 'toolbar buttons' listbox*/
2314 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2315 for (i = 0; i < count; i++)
2317 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2318 Free(btnInfo);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2321 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2324 /* delete items from 'available buttons' listbox*/
2325 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2326 for (i = 0; i < count; i++)
2328 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2329 Free(btnInfo);
2330 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2332 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2334 return TRUE;
2336 case WM_DRAWITEM:
2337 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2339 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2340 RECT rcButton;
2341 RECT rcText;
2342 HPEN hPen, hOldPen;
2343 HBRUSH hOldBrush;
2344 COLORREF oldText = 0;
2345 COLORREF oldBk = 0;
2347 /* get item data */
2348 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2349 if (btnInfo == NULL)
2351 FIXME("btnInfo invalid!\n");
2352 return TRUE;
2355 /* set colors and select objects */
2356 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2357 if (btnInfo->bVirtual)
2358 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2359 else
2360 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2361 hPen = CreatePen( PS_SOLID, 1,
2362 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2363 hOldPen = SelectObject (lpdis->hDC, hPen );
2364 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2366 /* fill background rectangle */
2367 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2368 lpdis->rcItem.right, lpdis->rcItem.bottom);
2370 /* calculate button and text rectangles */
2371 CopyRect (&rcButton, &lpdis->rcItem);
2372 InflateRect (&rcButton, -1, -1);
2373 CopyRect (&rcText, &rcButton);
2374 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2375 rcText.left = rcButton.right + 2;
2377 /* draw focus rectangle */
2378 if (lpdis->itemState & ODS_FOCUS)
2379 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2381 /* draw button */
2382 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2383 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2385 /* draw image and text */
2386 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2387 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2388 btnInfo->btn.iBitmap));
2389 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2390 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2392 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2393 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2395 /* delete objects and reset colors */
2396 SelectObject (lpdis->hDC, hOldBrush);
2397 SelectObject (lpdis->hDC, hOldPen);
2398 SetBkColor (lpdis->hDC, oldBk);
2399 SetTextColor (lpdis->hDC, oldText);
2400 DeleteObject( hPen );
2401 return TRUE;
2403 return FALSE;
2405 case WM_MEASUREITEM:
2406 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2408 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2410 lpmis->itemHeight = 15 + 8; /* default height */
2412 return TRUE;
2414 return FALSE;
2416 default:
2417 if (uDragListMessage && (uMsg == uDragListMessage))
2419 if (wParam == IDC_TOOLBARBTN_LBOX)
2421 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2422 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2423 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2424 return TRUE;
2426 else if (wParam == IDC_AVAILBTN_LBOX)
2428 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2429 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2430 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2431 return TRUE;
2434 return FALSE;
2439 /***********************************************************************
2440 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2443 static LRESULT
2444 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2446 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2447 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2448 INT nIndex = 0, nButtons, nCount;
2449 HBITMAP hbmLoad;
2450 HIMAGELIST himlDef;
2452 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2453 if (!lpAddBmp)
2454 return -1;
2456 if (lpAddBmp->hInst == HINST_COMMCTRL)
2458 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2459 nButtons = 15;
2460 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2461 nButtons = 13;
2462 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2463 nButtons = 5;
2464 else
2465 return -1;
2467 TRACE ("adding %d internal bitmaps!\n", nButtons);
2469 /* Windows resize all the buttons to the size of a newly added standard image */
2470 if (lpAddBmp->nID & 1)
2472 /* large icons */
2473 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2474 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2476 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2477 MAKELPARAM((WORD)24, (WORD)24));
2478 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2479 MAKELPARAM((WORD)31, (WORD)30));
2481 else
2483 /* small icons */
2484 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2485 MAKELPARAM((WORD)16, (WORD)16));
2486 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2487 MAKELPARAM((WORD)22, (WORD)22));
2490 TOOLBAR_CalcToolbar (hwnd);
2492 else
2494 nButtons = (INT)wParam;
2495 if (nButtons <= 0)
2496 return -1;
2498 TRACE ("adding %d bitmaps!\n", nButtons);
2501 if (!infoPtr->cimlDef) {
2502 /* create new default image list */
2503 TRACE ("creating default image list!\n");
2505 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2506 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2507 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2508 infoPtr->himlInt = himlDef;
2510 else {
2511 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2514 if (!himlDef) {
2515 WARN("No default image list available\n");
2516 return -1;
2519 nCount = ImageList_GetImageCount(himlDef);
2521 /* Add bitmaps to the default image list */
2522 if (lpAddBmp->hInst == NULL)
2524 BITMAP bmp;
2525 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2526 HDC hdcImage, hdcBitmap;
2528 /* copy the bitmap before adding it so that the user's bitmap
2529 * doesn't get modified.
2531 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2533 hdcImage = CreateCompatibleDC(0);
2534 hdcBitmap = CreateCompatibleDC(0);
2536 /* create new bitmap */
2537 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2538 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2539 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2541 /* Copy the user's image */
2542 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2543 hdcBitmap, 0, 0, SRCCOPY);
2545 SelectObject (hdcImage, hOldBitmapLoad);
2546 SelectObject (hdcBitmap, hOldBitmapBitmap);
2547 DeleteDC (hdcImage);
2548 DeleteDC (hdcBitmap);
2550 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2551 DeleteObject (hbmLoad);
2553 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2555 /* Add system bitmaps */
2556 switch (lpAddBmp->nID)
2558 case IDB_STD_SMALL_COLOR:
2559 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2560 MAKEINTRESOURCEA(IDB_STD_SMALL));
2561 nIndex = ImageList_AddMasked (himlDef,
2562 hbmLoad, comctl32_color.clrBtnFace);
2563 DeleteObject (hbmLoad);
2564 break;
2566 case IDB_STD_LARGE_COLOR:
2567 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2568 MAKEINTRESOURCEA(IDB_STD_LARGE));
2569 nIndex = ImageList_AddMasked (himlDef,
2570 hbmLoad, comctl32_color.clrBtnFace);
2571 DeleteObject (hbmLoad);
2572 break;
2574 case IDB_VIEW_SMALL_COLOR:
2575 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2576 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2577 nIndex = ImageList_AddMasked (himlDef,
2578 hbmLoad, comctl32_color.clrBtnFace);
2579 DeleteObject (hbmLoad);
2580 break;
2582 case IDB_VIEW_LARGE_COLOR:
2583 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2584 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2585 nIndex = ImageList_AddMasked (himlDef,
2586 hbmLoad, comctl32_color.clrBtnFace);
2587 DeleteObject (hbmLoad);
2588 break;
2590 case IDB_HIST_SMALL_COLOR:
2591 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2592 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2593 nIndex = ImageList_AddMasked (himlDef,
2594 hbmLoad, comctl32_color.clrBtnFace);
2595 DeleteObject (hbmLoad);
2596 break;
2598 case IDB_HIST_LARGE_COLOR:
2599 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2600 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2601 nIndex = ImageList_AddMasked (himlDef,
2602 hbmLoad, comctl32_color.clrBtnFace);
2603 DeleteObject (hbmLoad);
2604 break;
2606 default:
2607 nIndex = ImageList_GetImageCount (himlDef);
2608 ERR ("invalid imagelist!\n");
2609 break;
2612 else
2614 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2615 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2616 DeleteObject (hbmLoad);
2619 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2621 if (infoPtr->nNumBitmapInfos == 0)
2623 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2625 else
2627 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2628 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2629 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2632 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2633 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2634 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2636 infoPtr->nNumBitmapInfos++;
2637 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2639 if (nIndex != -1)
2641 INT imagecount = ImageList_GetImageCount(himlDef);
2643 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2645 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",
2646 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2647 infoPtr->nNumBitmaps+nButtons,imagecount);
2649 infoPtr->nNumBitmaps = imagecount;
2651 else
2652 infoPtr->nNumBitmaps += nButtons;
2655 InvalidateRect(hwnd, NULL, TRUE);
2657 return nIndex;
2661 static LRESULT
2662 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2665 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2666 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2668 TRACE("adding %d buttons!\n", wParam);
2670 nAddButtons = (UINT)wParam;
2671 nOldButtons = infoPtr->nNumButtons;
2672 nNewButtons = nOldButtons + nAddButtons;
2674 if (infoPtr->nNumButtons == 0) {
2675 infoPtr->buttons =
2676 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2678 else {
2679 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2680 infoPtr->buttons =
2681 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2682 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2683 nOldButtons * sizeof(TBUTTON_INFO));
2684 Free (oldButtons);
2687 infoPtr->nNumButtons = nNewButtons;
2689 /* insert new button data */
2690 for (nCount = 0; nCount < nAddButtons; nCount++) {
2691 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2692 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2693 btnPtr->idCommand = lpTbb[nCount].idCommand;
2694 btnPtr->fsState = lpTbb[nCount].fsState;
2695 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2696 btnPtr->dwData = lpTbb[nCount].dwData;
2697 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2698 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2699 else
2700 btnPtr->iString = lpTbb[nCount].iString;
2701 btnPtr->bHot = FALSE;
2703 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2704 TTTOOLINFOW ti;
2706 ZeroMemory (&ti, sizeof(ti));
2707 ti.cbSize = sizeof(ti);
2708 ti.hwnd = hwnd;
2709 ti.uId = btnPtr->idCommand;
2710 ti.hinst = 0;
2711 ti.lpszText = LPSTR_TEXTCALLBACKW;
2713 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2714 0, (LPARAM)&ti);
2718 TOOLBAR_CalcToolbar (hwnd);
2720 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2722 InvalidateRect(hwnd, NULL, TRUE);
2724 return TRUE;
2728 static LRESULT
2729 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2733 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2735 TRACE("adding %d buttons!\n", wParam);
2737 nAddButtons = (UINT)wParam;
2738 nOldButtons = infoPtr->nNumButtons;
2739 nNewButtons = nOldButtons + nAddButtons;
2741 if (infoPtr->nNumButtons == 0) {
2742 infoPtr->buttons =
2743 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2745 else {
2746 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2747 infoPtr->buttons =
2748 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2749 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2750 nOldButtons * sizeof(TBUTTON_INFO));
2751 Free (oldButtons);
2754 infoPtr->nNumButtons = nNewButtons;
2756 /* insert new button data */
2757 for (nCount = 0; nCount < nAddButtons; nCount++) {
2758 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2759 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2760 btnPtr->idCommand = lpTbb[nCount].idCommand;
2761 btnPtr->fsState = lpTbb[nCount].fsState;
2762 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2763 btnPtr->dwData = lpTbb[nCount].dwData;
2764 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2765 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2766 else
2767 btnPtr->iString = lpTbb[nCount].iString;
2768 btnPtr->bHot = FALSE;
2770 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2771 TTTOOLINFOW ti;
2773 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2774 ti.cbSize = sizeof (TTTOOLINFOW);
2775 ti.hwnd = hwnd;
2776 ti.uId = btnPtr->idCommand;
2777 ti.hinst = 0;
2778 ti.lpszText = LPSTR_TEXTCALLBACKW;
2779 ti.lParam = lParam;
2781 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2782 0, (LPARAM)&ti);
2786 TOOLBAR_CalcToolbar (hwnd);
2788 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2790 InvalidateRect(hwnd, NULL, TRUE);
2792 return TRUE;
2796 static LRESULT
2797 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 INT nIndex;
2802 if ((wParam) && (HIWORD(lParam) == 0)) {
2803 char szString[256];
2804 INT len;
2805 TRACE("adding string from resource!\n");
2807 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2808 szString, 256);
2810 TRACE("len=%d \"%s\"\n", len, szString);
2811 nIndex = infoPtr->nNumStrings;
2812 if (infoPtr->nNumStrings == 0) {
2813 infoPtr->strings =
2814 Alloc (sizeof(LPWSTR));
2816 else {
2817 LPWSTR *oldStrings = infoPtr->strings;
2818 infoPtr->strings =
2819 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2820 memcpy (&infoPtr->strings[0], &oldStrings[0],
2821 sizeof(LPWSTR) * infoPtr->nNumStrings);
2822 Free (oldStrings);
2825 /*Alloc zeros out the allocated memory*/
2826 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2827 infoPtr->nNumStrings++;
2829 else {
2830 LPSTR p = (LPSTR)lParam;
2831 INT len;
2833 if (p == NULL)
2834 return -1;
2835 TRACE("adding string(s) from array!\n");
2837 nIndex = infoPtr->nNumStrings;
2838 while (*p) {
2839 len = strlen (p);
2840 TRACE("len=%d \"%s\"\n", len, p);
2842 if (infoPtr->nNumStrings == 0) {
2843 infoPtr->strings =
2844 Alloc (sizeof(LPWSTR));
2846 else {
2847 LPWSTR *oldStrings = infoPtr->strings;
2848 infoPtr->strings =
2849 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2850 memcpy (&infoPtr->strings[0], &oldStrings[0],
2851 sizeof(LPWSTR) * infoPtr->nNumStrings);
2852 Free (oldStrings);
2855 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2856 infoPtr->nNumStrings++;
2858 p += (len+1);
2862 return nIndex;
2866 static LRESULT
2867 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2869 #define MAX_RESOURCE_STRING_LENGTH 512
2870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2871 INT nIndex;
2873 if ((wParam) && (HIWORD(lParam) == 0)) {
2874 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2875 INT len;
2876 TRACE("adding string from resource!\n");
2878 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2879 szString, MAX_RESOURCE_STRING_LENGTH);
2881 TRACE("len=%d %s\n", len, debugstr_w(szString));
2882 TRACE("First char: 0x%x\n", *szString);
2883 if (szString[0] == L'|')
2885 PWSTR p = szString + 1;
2887 nIndex = infoPtr->nNumStrings;
2888 while (*p != L'|' && *p != L'\0') {
2889 PWSTR np;
2891 if (infoPtr->nNumStrings == 0) {
2892 infoPtr->strings = Alloc (sizeof(LPWSTR));
2894 else
2896 LPWSTR *oldStrings = infoPtr->strings;
2897 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2898 memcpy(&infoPtr->strings[0], &oldStrings[0],
2899 sizeof(LPWSTR) * infoPtr->nNumStrings);
2900 Free(oldStrings);
2903 np=strchrW (p, '|');
2904 if (np!=NULL) {
2905 len = np - p;
2906 np++;
2907 } else {
2908 len = strlenW(p);
2909 np = p + len;
2911 TRACE("len=%d %s\n", len, debugstr_w(p));
2912 infoPtr->strings[infoPtr->nNumStrings] =
2913 Alloc (sizeof(WCHAR)*(len+1));
2914 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2915 infoPtr->nNumStrings++;
2917 p = np;
2920 else
2922 nIndex = infoPtr->nNumStrings;
2923 if (infoPtr->nNumStrings == 0) {
2924 infoPtr->strings =
2925 Alloc (sizeof(LPWSTR));
2927 else {
2928 LPWSTR *oldStrings = infoPtr->strings;
2929 infoPtr->strings =
2930 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2931 memcpy (&infoPtr->strings[0], &oldStrings[0],
2932 sizeof(LPWSTR) * infoPtr->nNumStrings);
2933 Free (oldStrings);
2936 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2937 infoPtr->nNumStrings++;
2940 else {
2941 LPWSTR p = (LPWSTR)lParam;
2942 INT len;
2944 if (p == NULL)
2945 return -1;
2946 TRACE("adding string(s) from array!\n");
2947 nIndex = infoPtr->nNumStrings;
2948 while (*p) {
2949 len = strlenW (p);
2951 TRACE("len=%d %s\n", len, debugstr_w(p));
2952 if (infoPtr->nNumStrings == 0) {
2953 infoPtr->strings =
2954 Alloc (sizeof(LPWSTR));
2956 else {
2957 LPWSTR *oldStrings = infoPtr->strings;
2958 infoPtr->strings =
2959 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2960 memcpy (&infoPtr->strings[0], &oldStrings[0],
2961 sizeof(LPWSTR) * infoPtr->nNumStrings);
2962 Free (oldStrings);
2965 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2966 infoPtr->nNumStrings++;
2968 p += (len+1);
2972 return nIndex;
2976 static LRESULT
2977 TOOLBAR_AutoSize (HWND hwnd)
2979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2980 RECT parent_rect;
2981 RECT window_rect;
2982 HWND parent;
2983 INT x, y;
2984 INT cx, cy;
2985 UINT uPosFlags = SWP_NOZORDER;
2987 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2989 parent = GetParent (hwnd);
2990 GetClientRect(parent, &parent_rect);
2992 x = parent_rect.left;
2993 y = parent_rect.top;
2995 /* FIXME: we should be able to early out if nothing */
2996 /* has changed with nWidth != parent_rect width */
2998 if (infoPtr->dwStyle & CCS_NORESIZE) {
2999 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3000 cx = 0;
3001 cy = 0;
3002 TOOLBAR_CalcToolbar (hwnd);
3004 else {
3005 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3006 TOOLBAR_CalcToolbar (hwnd);
3007 InvalidateRect( hwnd, NULL, TRUE );
3008 cy = infoPtr->nHeight;
3009 cx = infoPtr->nWidth;
3011 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3012 GetWindowRect(hwnd, &window_rect);
3013 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3014 y = window_rect.top;
3016 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3017 GetWindowRect(hwnd, &window_rect);
3018 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3022 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3023 uPosFlags |= SWP_NOMOVE;
3025 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3026 cy += GetSystemMetrics(SM_CYEDGE);
3028 if (infoPtr->dwStyle & WS_BORDER)
3030 x = y = 1;
3031 cy += GetSystemMetrics(SM_CYEDGE);
3032 cx += GetSystemMetrics(SM_CYEDGE);
3035 infoPtr->bAutoSize = TRUE;
3036 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3037 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3038 * after the setwindowpos calls */
3039 infoPtr->bAutoSize = FALSE;
3041 return 0;
3045 static LRESULT
3046 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3050 return infoPtr->nNumButtons;
3054 static LRESULT
3055 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3057 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3059 if (infoPtr == NULL) {
3060 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
3061 ERR("infoPtr == NULL!\n");
3062 return 0;
3065 infoPtr->dwStructSize = (DWORD)wParam;
3067 return 0;
3071 static LRESULT
3072 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3075 TBUTTON_INFO *btnPtr;
3076 INT nIndex;
3078 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3080 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3081 if (nIndex == -1)
3082 return FALSE;
3084 btnPtr = &infoPtr->buttons[nIndex];
3085 btnPtr->iBitmap = LOWORD(lParam);
3087 /* we HAVE to erase the background, the new bitmap could be */
3088 /* transparent */
3089 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3091 return TRUE;
3095 static LRESULT
3096 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 TBUTTON_INFO *btnPtr;
3100 INT nIndex;
3101 INT nOldIndex = -1;
3102 BOOL bChecked = FALSE;
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3106 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3108 if (nIndex == -1)
3109 return FALSE;
3111 btnPtr = &infoPtr->buttons[nIndex];
3113 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3115 if (LOWORD(lParam) == FALSE)
3116 btnPtr->fsState &= ~TBSTATE_CHECKED;
3117 else {
3118 if (btnPtr->fsStyle & BTNS_GROUP) {
3119 nOldIndex =
3120 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3121 if (nOldIndex == nIndex)
3122 return 0;
3123 if (nOldIndex != -1)
3124 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3126 btnPtr->fsState |= TBSTATE_CHECKED;
3129 if( bChecked != LOWORD(lParam) )
3131 if (nOldIndex != -1)
3132 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3133 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3136 /* FIXME: Send a WM_NOTIFY?? */
3138 return TRUE;
3142 static LRESULT
3143 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3145 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3147 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3151 static LRESULT
3152 TOOLBAR_Customize (HWND hwnd)
3154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3155 CUSTDLG_INFO custInfo;
3156 LRESULT ret;
3157 LPCVOID template;
3158 HRSRC hRes;
3159 NMHDR nmhdr;
3161 custInfo.tbInfo = infoPtr;
3162 custInfo.tbHwnd = hwnd;
3164 /* send TBN_BEGINADJUST notification */
3165 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3166 TBN_BEGINADJUST);
3168 if (!(hRes = FindResourceW (COMCTL32_hModule,
3169 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3170 (LPWSTR)RT_DIALOG)))
3171 return FALSE;
3173 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3174 return FALSE;
3176 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3177 (LPDLGTEMPLATEW)template,
3178 hwnd,
3179 TOOLBAR_CustomizeDialogProc,
3180 (LPARAM)&custInfo);
3182 /* send TBN_ENDADJUST notification */
3183 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3184 TBN_ENDADJUST);
3186 return ret;
3190 static LRESULT
3191 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3194 INT nIndex = (INT)wParam;
3195 NMTOOLBARW nmtb;
3196 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3198 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3199 return FALSE;
3201 memset(&nmtb, 0, sizeof(nmtb));
3202 nmtb.iItem = btnPtr->idCommand;
3203 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3204 nmtb.tbButton.idCommand = btnPtr->idCommand;
3205 nmtb.tbButton.fsState = btnPtr->fsState;
3206 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3207 nmtb.tbButton.dwData = btnPtr->dwData;
3208 nmtb.tbButton.iString = btnPtr->iString;
3209 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3211 if ((infoPtr->hwndToolTip) &&
3212 !(btnPtr->fsStyle & BTNS_SEP)) {
3213 TTTOOLINFOW ti;
3215 ZeroMemory (&ti, sizeof(ti));
3216 ti.cbSize = sizeof(ti);
3217 ti.hwnd = hwnd;
3218 ti.uId = infoPtr->buttons[nIndex].idCommand;
3220 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3223 if (infoPtr->nNumButtons == 1) {
3224 TRACE(" simple delete!\n");
3225 Free (infoPtr->buttons);
3226 infoPtr->buttons = NULL;
3227 infoPtr->nNumButtons = 0;
3229 else {
3230 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3231 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3233 infoPtr->nNumButtons--;
3234 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3235 if (nIndex > 0) {
3236 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3237 nIndex * sizeof(TBUTTON_INFO));
3240 if (nIndex < infoPtr->nNumButtons) {
3241 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3242 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3245 Free (oldButtons);
3248 TOOLBAR_CalcToolbar (hwnd);
3250 InvalidateRect (hwnd, NULL, TRUE);
3252 return TRUE;
3256 static LRESULT
3257 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3260 TBUTTON_INFO *btnPtr;
3261 INT nIndex;
3262 DWORD bState;
3264 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3266 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3268 if (nIndex == -1)
3269 return FALSE;
3271 btnPtr = &infoPtr->buttons[nIndex];
3273 bState = btnPtr->fsState & TBSTATE_ENABLED;
3275 /* update the toolbar button state */
3276 if(LOWORD(lParam) == FALSE) {
3277 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3278 } else {
3279 btnPtr->fsState |= TBSTATE_ENABLED;
3282 /* redraw the button only if the state of the button changed */
3283 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3284 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3286 return TRUE;
3290 static inline LRESULT
3291 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3295 return infoPtr->bAnchor;
3299 static LRESULT
3300 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 INT nIndex;
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3306 if (nIndex == -1)
3307 return -1;
3309 return infoPtr->buttons[nIndex].iBitmap;
3313 static inline LRESULT
3314 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3320 static LRESULT
3321 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3324 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3325 INT nIndex = (INT)wParam;
3326 TBUTTON_INFO *btnPtr;
3328 if (infoPtr == NULL)
3329 return FALSE;
3331 if (lpTbb == NULL)
3332 return FALSE;
3334 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3335 return FALSE;
3337 btnPtr = &infoPtr->buttons[nIndex];
3338 lpTbb->iBitmap = btnPtr->iBitmap;
3339 lpTbb->idCommand = btnPtr->idCommand;
3340 lpTbb->fsState = btnPtr->fsState;
3341 lpTbb->fsStyle = btnPtr->fsStyle;
3342 lpTbb->bReserved[0] = 0;
3343 lpTbb->bReserved[1] = 0;
3344 lpTbb->dwData = btnPtr->dwData;
3345 lpTbb->iString = btnPtr->iString;
3347 return TRUE;
3351 static LRESULT
3352 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3355 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3356 TBUTTON_INFO *btnPtr;
3357 INT nIndex;
3359 if (infoPtr == NULL)
3360 return -1;
3361 if (lpTbInfo == NULL)
3362 return -1;
3363 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3364 return -1;
3366 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3367 lpTbInfo->dwMask & 0x80000000);
3368 if (nIndex == -1)
3369 return -1;
3371 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3373 if (lpTbInfo->dwMask & TBIF_COMMAND)
3374 lpTbInfo->idCommand = btnPtr->idCommand;
3375 if (lpTbInfo->dwMask & TBIF_IMAGE)
3376 lpTbInfo->iImage = btnPtr->iBitmap;
3377 if (lpTbInfo->dwMask & TBIF_LPARAM)
3378 lpTbInfo->lParam = btnPtr->dwData;
3379 if (lpTbInfo->dwMask & TBIF_SIZE)
3380 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3381 if (lpTbInfo->dwMask & TBIF_STATE)
3382 lpTbInfo->fsState = btnPtr->fsState;
3383 if (lpTbInfo->dwMask & TBIF_STYLE)
3384 lpTbInfo->fsStyle = btnPtr->fsStyle;
3385 if (lpTbInfo->dwMask & TBIF_TEXT) {
3386 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3387 can't use TOOLBAR_GetText here */
3388 LPWSTR lpText;
3389 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3390 lpText = (LPWSTR)btnPtr->iString;
3391 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3392 } else
3393 lpTbInfo->pszText[0] = '\0';
3395 return nIndex;
3399 static LRESULT
3400 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3402 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3403 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3404 TBUTTON_INFO *btnPtr;
3405 INT nIndex;
3407 if (infoPtr == NULL)
3408 return -1;
3409 if (lpTbInfo == NULL)
3410 return -1;
3411 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3412 return -1;
3414 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3415 lpTbInfo->dwMask & 0x80000000);
3416 if (nIndex == -1)
3417 return -1;
3419 btnPtr = &infoPtr->buttons[nIndex];
3421 if(!btnPtr)
3422 return -1;
3424 if (lpTbInfo->dwMask & TBIF_COMMAND)
3425 lpTbInfo->idCommand = btnPtr->idCommand;
3426 if (lpTbInfo->dwMask & TBIF_IMAGE)
3427 lpTbInfo->iImage = btnPtr->iBitmap;
3428 if (lpTbInfo->dwMask & TBIF_LPARAM)
3429 lpTbInfo->lParam = btnPtr->dwData;
3430 if (lpTbInfo->dwMask & TBIF_SIZE)
3431 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3432 if (lpTbInfo->dwMask & TBIF_STATE)
3433 lpTbInfo->fsState = btnPtr->fsState;
3434 if (lpTbInfo->dwMask & TBIF_STYLE)
3435 lpTbInfo->fsStyle = btnPtr->fsStyle;
3436 if (lpTbInfo->dwMask & TBIF_TEXT) {
3437 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3438 can't use TOOLBAR_GetText here */
3439 LPWSTR lpText;
3440 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3441 lpText = (LPWSTR)btnPtr->iString;
3442 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3443 } else
3444 lpTbInfo->pszText[0] = '\0';
3447 return nIndex;
3451 static LRESULT
3452 TOOLBAR_GetButtonSize (HWND hwnd)
3454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3456 if (infoPtr->nNumButtons > 0)
3457 return MAKELONG((WORD)infoPtr->nButtonWidth,
3458 (WORD)infoPtr->nButtonHeight);
3459 else
3460 return MAKELONG(8,7);
3464 static LRESULT
3465 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3468 INT nIndex;
3469 LPWSTR lpText;
3471 if (lParam == 0)
3472 return -1;
3474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3475 if (nIndex == -1)
3476 return -1;
3478 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3480 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3481 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3485 static LRESULT
3486 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3488 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3489 INT nIndex;
3490 LPWSTR lpText;
3491 LRESULT ret = 0;
3493 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3494 if (nIndex == -1)
3495 return -1;
3497 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3499 if (lpText)
3501 ret = strlenW (lpText);
3503 if (lParam)
3504 strcpyW ((LPWSTR)lParam, lpText);
3507 return ret;
3511 static LRESULT
3512 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3514 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3515 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3516 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3520 inline static LRESULT
3521 TOOLBAR_GetExtendedStyle (HWND hwnd)
3523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3525 TRACE("\n");
3527 return infoPtr->dwExStyle;
3531 static LRESULT
3532 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3534 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3535 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3536 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3540 static LRESULT
3541 TOOLBAR_GetHotItem (HWND hwnd)
3543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3545 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3546 return -1;
3548 if (infoPtr->nHotItem < 0)
3549 return -1;
3551 return (LRESULT)infoPtr->nHotItem;
3555 static LRESULT
3556 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3558 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3559 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3560 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3564 static LRESULT
3565 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3568 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3570 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3572 *lptbim = infoPtr->tbim;
3574 return 0;
3578 static LRESULT
3579 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3583 TRACE("hwnd = %p\n", hwnd);
3585 return (LRESULT)infoPtr->clrInsertMark;
3589 static LRESULT
3590 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 TBUTTON_INFO *btnPtr;
3594 LPRECT lpRect;
3595 INT nIndex;
3597 if (infoPtr == NULL)
3598 return FALSE;
3599 nIndex = (INT)wParam;
3600 btnPtr = &infoPtr->buttons[nIndex];
3601 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3602 return FALSE;
3603 lpRect = (LPRECT)lParam;
3604 if (lpRect == NULL)
3605 return FALSE;
3606 if (btnPtr->fsState & TBSTATE_HIDDEN)
3607 return FALSE;
3609 lpRect->left = btnPtr->rect.left;
3610 lpRect->right = btnPtr->rect.right;
3611 lpRect->bottom = btnPtr->rect.bottom;
3612 lpRect->top = btnPtr->rect.top;
3614 return TRUE;
3618 static LRESULT
3619 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3622 LPSIZE lpSize = (LPSIZE)lParam;
3624 if (lpSize == NULL)
3625 return FALSE;
3627 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3628 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3630 TRACE("maximum size %ld x %ld\n",
3631 infoPtr->rcBound.right - infoPtr->rcBound.left,
3632 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3634 return TRUE;
3638 /* << TOOLBAR_GetObject >> */
3641 static LRESULT
3642 TOOLBAR_GetPadding (HWND hwnd)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 DWORD oldPad;
3647 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3648 return (LRESULT) oldPad;
3652 static LRESULT
3653 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3656 TBUTTON_INFO *btnPtr;
3657 LPRECT lpRect;
3658 INT nIndex;
3660 if (infoPtr == NULL)
3661 return FALSE;
3662 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3663 btnPtr = &infoPtr->buttons[nIndex];
3664 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3665 return FALSE;
3666 lpRect = (LPRECT)lParam;
3667 if (lpRect == NULL)
3668 return FALSE;
3670 lpRect->left = btnPtr->rect.left;
3671 lpRect->right = btnPtr->rect.right;
3672 lpRect->bottom = btnPtr->rect.bottom;
3673 lpRect->top = btnPtr->rect.top;
3675 return TRUE;
3679 static LRESULT
3680 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3685 return infoPtr->nRows;
3686 else
3687 return 1;
3691 static LRESULT
3692 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3695 INT nIndex;
3697 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3698 if (nIndex == -1)
3699 return -1;
3701 return infoPtr->buttons[nIndex].fsState;
3705 static LRESULT
3706 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 return GetWindowLongW(hwnd, GWL_STYLE);
3712 static LRESULT
3713 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3717 if (infoPtr == NULL)
3718 return 0;
3720 return infoPtr->nMaxTextRows;
3724 static LRESULT
3725 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 if (infoPtr == NULL)
3730 return 0;
3731 return (LRESULT)infoPtr->hwndToolTip;
3735 static LRESULT
3736 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3740 TRACE("%s hwnd=%p\n",
3741 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3743 return infoPtr->bUnicode;
3747 inline static LRESULT
3748 TOOLBAR_GetVersion (HWND hwnd)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3751 return infoPtr->iVersion;
3755 static LRESULT
3756 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3759 TBUTTON_INFO *btnPtr;
3760 INT nIndex;
3762 TRACE("\n");
3764 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3765 if (nIndex == -1)
3766 return FALSE;
3768 btnPtr = &infoPtr->buttons[nIndex];
3769 if (LOWORD(lParam) == FALSE)
3770 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3771 else
3772 btnPtr->fsState |= TBSTATE_HIDDEN;
3774 TOOLBAR_CalcToolbar (hwnd);
3776 InvalidateRect (hwnd, NULL, TRUE);
3778 return TRUE;
3782 inline static LRESULT
3783 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3785 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3789 static LRESULT
3790 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3792 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3793 TBUTTON_INFO *btnPtr;
3794 INT nIndex;
3795 DWORD oldState;
3797 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3798 if (nIndex == -1)
3799 return FALSE;
3801 btnPtr = &infoPtr->buttons[nIndex];
3802 oldState = btnPtr->fsState;
3803 if (LOWORD(lParam) == FALSE)
3804 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3805 else
3806 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3808 if(oldState != btnPtr->fsState)
3809 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3811 return TRUE;
3815 static LRESULT
3816 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3819 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3820 INT nIndex = (INT)wParam;
3821 TBUTTON_INFO *oldButtons;
3823 if (lpTbb == NULL)
3824 return FALSE;
3826 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3828 if (nIndex == -1) {
3829 /* EPP: this seems to be an undocumented call (from my IE4)
3830 * I assume in that case that:
3831 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3832 * - index of insertion is at the end of existing buttons
3833 * I only see this happen with nIndex == -1, but it could have a special
3834 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3836 nIndex = infoPtr->nNumButtons;
3838 } else if (nIndex < 0)
3839 return FALSE;
3841 /* If the string passed is not an index, assume address of string
3842 and do our own AddString */
3843 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3844 LPSTR ptr;
3845 INT len;
3847 TRACE("string %s passed instead of index, adding string\n",
3848 debugstr_a((LPSTR)lpTbb->iString));
3849 len = strlen((LPSTR)lpTbb->iString) + 2;
3850 ptr = Alloc(len);
3851 strcpy(ptr, (LPSTR)lpTbb->iString);
3852 ptr[len - 1] = 0; /* ended by two '\0' */
3853 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3854 Free(ptr);
3857 TRACE("inserting button index=%d\n", nIndex);
3858 if (nIndex > infoPtr->nNumButtons) {
3859 nIndex = infoPtr->nNumButtons;
3860 TRACE("adjust index=%d\n", nIndex);
3863 oldButtons = infoPtr->buttons;
3864 infoPtr->nNumButtons++;
3865 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3866 /* pre insert copy */
3867 if (nIndex > 0) {
3868 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3869 nIndex * sizeof(TBUTTON_INFO));
3872 /* insert new button */
3873 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3874 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3875 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3876 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3877 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3878 /* if passed string and not index, then add string */
3879 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3880 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3882 else
3883 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3885 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3886 TTTOOLINFOW ti;
3888 ZeroMemory (&ti, sizeof(ti));
3889 ti.cbSize = sizeof (ti);
3890 ti.hwnd = hwnd;
3891 ti.uId = lpTbb->idCommand;
3892 ti.hinst = 0;
3893 ti.lpszText = LPSTR_TEXTCALLBACKW;
3895 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3896 0, (LPARAM)&ti);
3899 /* post insert copy */
3900 if (nIndex < infoPtr->nNumButtons - 1) {
3901 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3902 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3905 Free (oldButtons);
3907 TOOLBAR_CalcToolbar (hwnd);
3909 InvalidateRect (hwnd, NULL, TRUE);
3911 return TRUE;
3915 static LRESULT
3916 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3919 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3920 INT nIndex = (INT)wParam;
3921 TBUTTON_INFO *oldButtons;
3923 if (lpTbb == NULL)
3924 return FALSE;
3926 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3928 if (nIndex == -1) {
3929 /* EPP: this seems to be an undocumented call (from my IE4)
3930 * I assume in that case that:
3931 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3932 * - index of insertion is at the end of existing buttons
3933 * I only see this happen with nIndex == -1, but it could have a special
3934 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3936 nIndex = infoPtr->nNumButtons;
3938 } else if (nIndex < 0)
3939 return FALSE;
3941 /* If the string passed is not an index, assume address of string
3942 and do our own AddString */
3943 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3944 LPWSTR ptr;
3945 INT len;
3947 TRACE("string %s passed instead of index, adding string\n",
3948 debugstr_w((LPWSTR)lpTbb->iString));
3949 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3950 ptr = Alloc(len*sizeof(WCHAR));
3951 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3952 ptr[len - 1] = 0; /* ended by two '\0' */
3953 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3954 Free(ptr);
3957 TRACE("inserting button index=%d\n", nIndex);
3958 if (nIndex > infoPtr->nNumButtons) {
3959 nIndex = infoPtr->nNumButtons;
3960 TRACE("adjust index=%d\n", nIndex);
3963 oldButtons = infoPtr->buttons;
3964 infoPtr->nNumButtons++;
3965 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3966 /* pre insert copy */
3967 if (nIndex > 0) {
3968 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3969 nIndex * sizeof(TBUTTON_INFO));
3972 /* insert new button */
3973 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3974 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3975 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3976 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3977 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3978 /* if passed string and not index, then add string */
3979 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3980 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3982 else
3983 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3985 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3986 TTTOOLINFOW ti;
3988 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3989 ti.cbSize = sizeof (TTTOOLINFOW);
3990 ti.hwnd = hwnd;
3991 ti.uId = lpTbb->idCommand;
3992 ti.hinst = 0;
3993 ti.lpszText = LPSTR_TEXTCALLBACKW;
3995 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3996 0, (LPARAM)&ti);
3999 /* post insert copy */
4000 if (nIndex < infoPtr->nNumButtons - 1) {
4001 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4002 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4005 Free (oldButtons);
4007 TOOLBAR_CalcToolbar (hwnd);
4009 InvalidateRect (hwnd, NULL, TRUE);
4011 return TRUE;
4015 /* << TOOLBAR_InsertMarkHitTest >> */
4018 static LRESULT
4019 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4022 INT nIndex;
4024 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4025 if (nIndex == -1)
4026 return FALSE;
4028 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4032 static LRESULT
4033 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4036 INT nIndex;
4038 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4039 if (nIndex == -1)
4040 return FALSE;
4042 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4046 static LRESULT
4047 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4050 INT nIndex;
4052 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4053 if (nIndex == -1)
4054 return TRUE;
4056 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4060 static LRESULT
4061 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4063 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4064 INT nIndex;
4066 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4067 if (nIndex == -1)
4068 return FALSE;
4070 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4074 static LRESULT
4075 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4078 INT nIndex;
4080 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4081 if (nIndex == -1)
4082 return FALSE;
4084 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4088 static LRESULT
4089 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4092 INT nIndex;
4094 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4095 if (nIndex == -1)
4096 return FALSE;
4098 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4102 static LRESULT
4103 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4105 TBADDBITMAP tbab;
4106 tbab.hInst = (HINSTANCE)lParam;
4107 tbab.nID = (UINT_PTR)wParam;
4109 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4111 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4115 static LRESULT
4116 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4119 WCHAR wAccel = (WCHAR)wParam;
4120 UINT* pIDButton = (UINT*)lParam;
4121 WCHAR wszAccel[] = {'&',wAccel,0};
4122 int i;
4124 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4125 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4127 for (i = 0; i < infoPtr->nNumButtons; i++)
4129 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4130 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4131 !(btnPtr->fsState & TBSTATE_HIDDEN))
4133 int iLen = strlenW(wszAccel);
4134 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4136 if (!lpszStr)
4137 continue;
4139 while (*lpszStr)
4141 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4143 lpszStr += 2;
4144 continue;
4146 if (!strncmpiW(lpszStr, wszAccel, iLen))
4148 *pIDButton = btnPtr->idCommand;
4149 return TRUE;
4151 lpszStr++;
4155 return FALSE;
4159 static LRESULT
4160 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4163 INT nIndex;
4164 DWORD oldState;
4165 TBUTTON_INFO *btnPtr;
4167 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4169 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4170 if (nIndex == -1)
4171 return FALSE;
4173 btnPtr = &infoPtr->buttons[nIndex];
4174 oldState = btnPtr->fsState;
4176 if (LOWORD(lParam))
4177 btnPtr->fsState |= TBSTATE_MARKED;
4178 else
4179 btnPtr->fsState &= ~TBSTATE_MARKED;
4181 if(oldState != btnPtr->fsState)
4182 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4184 return TRUE;
4188 /* fixes up an index of a button affected by a move */
4189 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4191 if (bMoveUp)
4193 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4194 (*pIndex)--;
4195 else if (*pIndex == nIndex)
4196 *pIndex = nMoveIndex;
4198 else
4200 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4201 (*pIndex)++;
4202 else if (*pIndex == nIndex)
4203 *pIndex = nMoveIndex;
4208 static LRESULT
4209 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4212 INT nIndex;
4213 INT nCount;
4214 INT nMoveIndex = (INT)lParam;
4215 TBUTTON_INFO button;
4217 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4219 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4220 if ((nIndex == -1) || (nMoveIndex < 0))
4221 return FALSE;
4223 if (nMoveIndex > infoPtr->nNumButtons - 1)
4224 nMoveIndex = infoPtr->nNumButtons - 1;
4226 button = infoPtr->buttons[nIndex];
4228 /* move button right */
4229 if (nIndex < nMoveIndex)
4231 nCount = nMoveIndex - nIndex;
4232 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4233 infoPtr->buttons[nMoveIndex] = button;
4235 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4236 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4237 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4238 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4240 else if (nIndex > nMoveIndex) /* move button left */
4242 nCount = nIndex - nMoveIndex;
4243 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4244 infoPtr->buttons[nMoveIndex] = button;
4246 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4247 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4248 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4249 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4252 TOOLBAR_CalcToolbar(hwnd);
4253 InvalidateRect(hwnd, NULL, TRUE);
4255 return TRUE;
4259 static LRESULT
4260 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4263 TBUTTON_INFO *btnPtr;
4264 INT nIndex;
4265 DWORD oldState;
4267 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4268 if (nIndex == -1)
4269 return FALSE;
4271 btnPtr = &infoPtr->buttons[nIndex];
4272 oldState = btnPtr->fsState;
4273 if (LOWORD(lParam) == FALSE)
4274 btnPtr->fsState &= ~TBSTATE_PRESSED;
4275 else
4276 btnPtr->fsState |= TBSTATE_PRESSED;
4278 if(oldState != btnPtr->fsState)
4279 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4281 return TRUE;
4284 /* FIXME: there might still be some confusion her between number of buttons
4285 * and number of bitmaps */
4286 static LRESULT
4287 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4290 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4291 HBITMAP hBitmap;
4292 int i = 0, nOldButtons = 0, pos = 0;
4293 int nOldBitmaps, nNewBitmaps;
4294 HIMAGELIST himlDef = 0;
4296 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4297 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4298 lpReplace->nButtons);
4300 if (lpReplace->hInstOld == HINST_COMMCTRL)
4302 FIXME("changing standard bitmaps not implemented\n");
4303 return FALSE;
4305 else if (lpReplace->hInstOld != 0)
4307 FIXME("resources not in the current module not implemented\n");
4308 return FALSE;
4310 else
4312 hBitmap = (HBITMAP) lpReplace->nIDNew;
4315 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4316 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4317 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4318 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4319 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4321 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4322 nOldButtons = tbi->nButtons;
4323 tbi->nButtons = lpReplace->nButtons;
4324 tbi->hInst = lpReplace->hInstNew;
4325 tbi->nID = lpReplace->nIDNew;
4326 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4327 break;
4329 pos += tbi->nButtons;
4332 if (nOldButtons == 0)
4334 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4335 return FALSE;
4338 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4339 nOldBitmaps = ImageList_GetImageCount(himlDef);
4341 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4343 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4344 ImageList_Remove(himlDef, i);
4347 BITMAP bmp;
4348 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4349 HDC hdcImage, hdcBitmap;
4351 /* copy the bitmap before adding it so that the user's bitmap
4352 * doesn't get modified.
4354 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4356 hdcImage = CreateCompatibleDC(0);
4357 hdcBitmap = CreateCompatibleDC(0);
4359 /* create new bitmap */
4360 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4361 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4362 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4364 /* Copy the user's image */
4365 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4366 hdcBitmap, 0, 0, SRCCOPY);
4368 SelectObject (hdcImage, hOldBitmapLoad);
4369 SelectObject (hdcBitmap, hOldBitmapBitmap);
4370 DeleteDC (hdcImage);
4371 DeleteDC (hdcBitmap);
4373 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4374 nNewBitmaps = ImageList_GetImageCount(himlDef);
4375 DeleteObject (hbmLoad);
4378 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4380 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4381 pos, nOldBitmaps, nNewBitmaps);
4383 InvalidateRect(hwnd, NULL, TRUE);
4385 return TRUE;
4388 static LRESULT
4389 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4391 #if 0
4392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4393 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4395 if (lpSave == NULL) return 0;
4397 if ((BOOL)wParam) {
4398 /* save toolbar information */
4399 FIXME("save to \"%s\" \"%s\"\n",
4400 lpSave->pszSubKey, lpSave->pszValueName);
4404 else {
4405 /* restore toolbar information */
4407 FIXME("restore from \"%s\" \"%s\"\n",
4408 lpSave->pszSubKey, lpSave->pszValueName);
4412 #endif
4414 return 0;
4418 static LRESULT
4419 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4421 #if 0
4422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4423 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4425 if (lpSave == NULL)
4426 return 0;
4428 if ((BOOL)wParam) {
4429 /* save toolbar information */
4430 FIXME("save to \"%s\" \"%s\"\n",
4431 lpSave->pszSubKey, lpSave->pszValueName);
4435 else {
4436 /* restore toolbar information */
4438 FIXME("restore from \"%s\" \"%s\"\n",
4439 lpSave->pszSubKey, lpSave->pszValueName);
4443 #endif
4445 return 0;
4449 static LRESULT
4450 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4453 BOOL bOldAnchor = infoPtr->bAnchor;
4455 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4457 infoPtr->bAnchor = (BOOL)wParam;
4459 /* Native does not remove the hot effect from an already hot button */
4461 return (LRESULT)bOldAnchor;
4465 static LRESULT
4466 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4469 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4471 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4473 if (wParam != 0)
4474 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4476 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4477 return FALSE;
4479 if (infoPtr->nNumButtons > 0)
4480 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4481 infoPtr->nNumButtons,
4482 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4483 LOWORD(lParam), HIWORD(lParam));
4485 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4486 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4489 if ((himlDef == infoPtr->himlInt) &&
4490 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4492 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4493 infoPtr->nBitmapHeight);
4496 return TRUE;
4500 static LRESULT
4501 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4504 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4505 TBUTTON_INFO *btnPtr;
4506 INT nIndex;
4507 RECT oldBtnRect;
4509 if (lptbbi == NULL)
4510 return FALSE;
4511 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4512 return FALSE;
4514 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4515 lptbbi->dwMask & 0x80000000);
4516 if (nIndex == -1)
4517 return FALSE;
4519 btnPtr = &infoPtr->buttons[nIndex];
4520 if (lptbbi->dwMask & TBIF_COMMAND)
4521 btnPtr->idCommand = lptbbi->idCommand;
4522 if (lptbbi->dwMask & TBIF_IMAGE)
4523 btnPtr->iBitmap = lptbbi->iImage;
4524 if (lptbbi->dwMask & TBIF_LPARAM)
4525 btnPtr->dwData = lptbbi->lParam;
4526 if (lptbbi->dwMask & TBIF_SIZE)
4527 btnPtr->cx = lptbbi->cx;
4528 if (lptbbi->dwMask & TBIF_STATE)
4529 btnPtr->fsState = lptbbi->fsState;
4530 if (lptbbi->dwMask & TBIF_STYLE)
4531 btnPtr->fsStyle = lptbbi->fsStyle;
4533 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4534 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4535 /* iString is index, zero it to make Str_SetPtr succeed */
4536 btnPtr->iString=0;
4538 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4541 /* save the button rect to see if we need to redraw the whole toolbar */
4542 oldBtnRect = btnPtr->rect;
4543 TOOLBAR_CalcToolbar(hwnd);
4545 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4546 InvalidateRect(hwnd, NULL, TRUE);
4547 else
4548 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4550 return TRUE;
4554 static LRESULT
4555 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4558 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4559 TBUTTON_INFO *btnPtr;
4560 INT nIndex;
4561 RECT oldBtnRect;
4563 if (lptbbi == NULL)
4564 return FALSE;
4565 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4566 return FALSE;
4568 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4569 lptbbi->dwMask & 0x80000000);
4570 if (nIndex == -1)
4571 return FALSE;
4573 btnPtr = &infoPtr->buttons[nIndex];
4574 if (lptbbi->dwMask & TBIF_COMMAND)
4575 btnPtr->idCommand = lptbbi->idCommand;
4576 if (lptbbi->dwMask & TBIF_IMAGE)
4577 btnPtr->iBitmap = lptbbi->iImage;
4578 if (lptbbi->dwMask & TBIF_LPARAM)
4579 btnPtr->dwData = lptbbi->lParam;
4580 if (lptbbi->dwMask & TBIF_SIZE)
4581 btnPtr->cx = lptbbi->cx;
4582 if (lptbbi->dwMask & TBIF_STATE)
4583 btnPtr->fsState = lptbbi->fsState;
4584 if (lptbbi->dwMask & TBIF_STYLE)
4585 btnPtr->fsStyle = lptbbi->fsStyle;
4587 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4588 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4589 /* iString is index, zero it to make Str_SetPtr succeed */
4590 btnPtr->iString=0;
4591 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4594 /* save the button rect to see if we need to redraw the whole toolbar */
4595 oldBtnRect = btnPtr->rect;
4596 TOOLBAR_CalcToolbar(hwnd);
4598 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4599 InvalidateRect(hwnd, NULL, TRUE);
4600 else
4601 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4603 return TRUE;
4607 static LRESULT
4608 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4611 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4613 if ((cx < 0) || (cy < 0))
4615 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4616 return FALSE;
4619 /* The documentation claims you can only change the button size before
4620 * any button has been added. But this is wrong.
4621 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4622 * it to the toolbar, and it checks that the return value is nonzero - mjm
4623 * Further testing shows that we must actually perform the change too.
4626 * The documentation also does not mention that if 0 is supplied for
4627 * either size, the system changes it to the default of 24 wide and
4628 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4630 infoPtr->nButtonWidth = (cx) ? cx : 24;
4631 infoPtr->nButtonHeight = (cy) ? cy : 22;
4632 return TRUE;
4636 static LRESULT
4637 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4641 if (infoPtr == NULL) {
4642 TRACE("Toolbar not initialized yet?????\n");
4643 return FALSE;
4646 /* if setting to current values, ignore */
4647 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4648 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4649 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4650 infoPtr->cxMin, infoPtr->cxMax);
4651 return TRUE;
4654 /* save new values */
4655 infoPtr->cxMin = (INT)LOWORD(lParam);
4656 infoPtr->cxMax = (INT)HIWORD(lParam);
4658 /* if both values are 0 then we are done */
4659 if (lParam == 0) {
4660 TRACE("setting both min and max to 0, norecalc\n");
4661 return TRUE;
4664 /* otherwise we need to recalc the toolbar and in some cases
4665 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4666 which doesn't actually draw - GA). */
4667 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4668 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4670 TOOLBAR_CalcToolbar (hwnd);
4672 InvalidateRect (hwnd, NULL, TRUE);
4674 return TRUE;
4678 static LRESULT
4679 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4682 INT nIndex = (INT)wParam;
4684 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4685 return FALSE;
4687 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4689 if (infoPtr->hwndToolTip) {
4691 FIXME("change tool tip!\n");
4695 return TRUE;
4699 static LRESULT
4700 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4703 HIMAGELIST himl = (HIMAGELIST)lParam;
4704 HIMAGELIST himlTemp;
4705 INT id = 0;
4707 if (infoPtr->iVersion >= 5)
4708 id = wParam;
4710 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4711 &infoPtr->cimlDis, himl, id);
4713 /* FIXME: redraw ? */
4715 return (LRESULT)himlTemp;
4719 static LRESULT
4720 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4723 DWORD dwTemp;
4725 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4727 dwTemp = infoPtr->dwDTFlags;
4728 infoPtr->dwDTFlags =
4729 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4731 return (LRESULT)dwTemp;
4734 /* This function differs a bit from what MSDN says it does:
4735 * 1. lParam contains extended style flags to OR with current style
4736 * (MSDN isn't clear on the OR bit)
4737 * 2. wParam appears to contain extended style flags to be reset
4738 * (MSDN says that this parameter is reserved)
4740 static LRESULT
4741 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4744 DWORD dwTemp;
4746 dwTemp = infoPtr->dwExStyle;
4747 infoPtr->dwExStyle &= ~wParam;
4748 infoPtr->dwExStyle |= (DWORD)lParam;
4750 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4752 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4753 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4754 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4756 TOOLBAR_CalcToolbar (hwnd);
4758 TOOLBAR_AutoSize(hwnd);
4760 InvalidateRect(hwnd, NULL, TRUE);
4762 return (LRESULT)dwTemp;
4766 static LRESULT
4767 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4770 HIMAGELIST himlTemp;
4771 HIMAGELIST himl = (HIMAGELIST)lParam;
4772 INT id = 0;
4774 if (infoPtr->iVersion >= 5)
4775 id = wParam;
4777 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4779 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4780 &infoPtr->cimlHot, himl, id);
4782 /* FIXME: redraw ? */
4784 return (LRESULT)himlTemp;
4788 /* Makes previous hot button no longer hot, makes the specified
4789 * button hot and sends appropriate notifications. dwReason is one or
4790 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4791 * NOTE 1: this function does not validate nHit
4792 * NOTE 2: the name of this function is completely made up and
4793 * not based on any documentation from Microsoft. */
4794 static void
4795 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4797 if (infoPtr->nHotItem != nHit)
4799 NMTBHOTITEM nmhotitem;
4800 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4801 LRESULT no_highlight;
4803 /* Remove the effect of an old hot button if the button was
4804 drawn with the hot button effect */
4805 if(infoPtr->nHotItem >= 0)
4807 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4808 oldBtnPtr->bHot = FALSE;
4811 infoPtr->nHotItem = nHit;
4813 /* It's not a separator or in nowhere. It's a hot button. */
4814 if (nHit >= 0)
4815 btnPtr = &infoPtr->buttons[nHit];
4817 nmhotitem.dwFlags = dwReason;
4818 if (oldBtnPtr)
4819 nmhotitem.idOld = oldBtnPtr->idCommand;
4820 else
4821 nmhotitem.dwFlags |= HICF_ENTERING;
4822 if (btnPtr)
4823 nmhotitem.idNew = btnPtr->idCommand;
4824 else
4825 nmhotitem.dwFlags |= HICF_LEAVING;
4827 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4829 /* now invalidate the old and new buttons so they will be painted */
4830 if (oldBtnPtr)
4831 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4832 if (btnPtr && !no_highlight)
4834 btnPtr->bHot = TRUE;
4835 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4840 static LRESULT
4841 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4844 INT nOldHotItem = infoPtr->nHotItem;
4846 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4848 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4849 wParam = -1;
4851 /* NOTE: an application can still remove the hot item even if anchor
4852 * highlighting is enabled */
4854 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4855 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4857 if (nOldHotItem < 0)
4858 return -1;
4860 return (LRESULT)nOldHotItem;
4864 static LRESULT
4865 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4868 HIMAGELIST himlTemp;
4869 HIMAGELIST himl = (HIMAGELIST)lParam;
4870 INT i, id = 0;
4872 if (infoPtr->iVersion >= 5)
4873 id = wParam;
4875 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4876 &infoPtr->cimlDef, himl, id);
4878 infoPtr->nNumBitmaps = 0;
4879 for (i = 0; i < infoPtr->cimlDef; i++)
4880 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4882 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4883 &infoPtr->nBitmapHeight);
4884 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4885 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4886 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4888 InvalidateRect(hwnd, NULL, TRUE);
4890 return (LRESULT)himlTemp;
4894 static LRESULT
4895 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4899 infoPtr->nIndent = (INT)wParam;
4901 TRACE("\n");
4903 /* process only on indent changing */
4904 if(infoPtr->nIndent != (INT)wParam)
4906 infoPtr->nIndent = (INT)wParam;
4907 TOOLBAR_CalcToolbar (hwnd);
4908 InvalidateRect(hwnd, NULL, FALSE);
4911 return TRUE;
4915 static LRESULT
4916 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4919 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4921 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4923 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4925 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4926 return 0;
4929 if ((lptbim->iButton == -1) ||
4930 ((lptbim->iButton < infoPtr->nNumButtons) &&
4931 (lptbim->iButton >= 0)))
4933 infoPtr->tbim = *lptbim;
4934 /* FIXME: don't need to update entire toolbar */
4935 InvalidateRect(hwnd, NULL, TRUE);
4937 else
4938 ERR("Invalid button index %d\n", lptbim->iButton);
4940 return 0;
4944 static LRESULT
4945 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4949 infoPtr->clrInsertMark = (COLORREF)lParam;
4951 /* FIXME: don't need to update entire toolbar */
4952 InvalidateRect(hwnd, NULL, TRUE);
4954 return 0;
4958 static LRESULT
4959 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4963 if (infoPtr == NULL)
4964 return FALSE;
4966 infoPtr->nMaxTextRows = (INT)wParam;
4968 TOOLBAR_CalcToolbar(hwnd);
4969 return TRUE;
4973 /* MSDN gives slightly wrong info on padding.
4974 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4975 * 2. It is not used to create a blank area between the edge of the button
4976 * and the text or image if TBSTYLE_LIST is set. It is used to control
4977 * the gap between the image and text.
4978 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4979 * to control the bottom and right borders [with the border being
4980 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4981 * is shared evenly on both sides of the button.
4983 static LRESULT
4984 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4987 DWORD oldPad;
4989 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4990 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4991 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4992 TRACE("cx=%ld, cy=%ld\n",
4993 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4994 return (LRESULT) oldPad;
4998 static LRESULT
4999 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5001 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5002 HWND hwndOldNotify;
5004 TRACE("\n");
5006 if (infoPtr == NULL)
5007 return 0;
5008 hwndOldNotify = infoPtr->hwndNotify;
5009 infoPtr->hwndNotify = (HWND)wParam;
5011 return (LRESULT)hwndOldNotify;
5015 static LRESULT
5016 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5019 LPRECT lprc = (LPRECT)lParam;
5021 TRACE("\n");
5023 if (LOWORD(wParam) > 1) {
5024 FIXME("multiple rows not supported!\n");
5027 if(infoPtr->nRows != LOWORD(wParam))
5029 infoPtr->nRows = LOWORD(wParam);
5031 /* recalculate toolbar */
5032 TOOLBAR_CalcToolbar (hwnd);
5034 /* repaint toolbar */
5035 InvalidateRect(hwnd, NULL, TRUE);
5038 /* return bounding rectangle */
5039 if (lprc) {
5040 lprc->left = infoPtr->rcBound.left;
5041 lprc->right = infoPtr->rcBound.right;
5042 lprc->top = infoPtr->rcBound.top;
5043 lprc->bottom = infoPtr->rcBound.bottom;
5046 return 0;
5050 static LRESULT
5051 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5054 TBUTTON_INFO *btnPtr;
5055 INT nIndex;
5057 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5058 if (nIndex == -1)
5059 return FALSE;
5061 btnPtr = &infoPtr->buttons[nIndex];
5063 /* if hidden state has changed the invalidate entire window and recalc */
5064 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5065 btnPtr->fsState = LOWORD(lParam);
5066 TOOLBAR_CalcToolbar (hwnd);
5067 InvalidateRect(hwnd, 0, TRUE);
5068 return TRUE;
5071 /* process state changing if current state doesn't match new state */
5072 if(btnPtr->fsState != LOWORD(lParam))
5074 btnPtr->fsState = LOWORD(lParam);
5075 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5078 return TRUE;
5082 static LRESULT
5083 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5085 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5087 return TRUE;
5091 inline static LRESULT
5092 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5096 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5098 if (infoPtr == NULL)
5099 return 0;
5100 infoPtr->hwndToolTip = (HWND)wParam;
5101 return 0;
5105 static LRESULT
5106 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5109 BOOL bTemp;
5111 TRACE("%s hwnd=%p\n",
5112 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5114 bTemp = infoPtr->bUnicode;
5115 infoPtr->bUnicode = (BOOL)wParam;
5117 return bTemp;
5121 static LRESULT
5122 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5126 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5127 comctl32_color.clrBtnHighlight :
5128 infoPtr->clrBtnHighlight;
5129 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5130 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5131 return 1;
5135 static LRESULT
5136 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5141 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5142 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5144 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5145 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5146 InvalidateRect(hwnd, NULL, TRUE);
5147 return 0;
5151 static LRESULT
5152 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5155 INT iOldVersion = infoPtr->iVersion;
5157 infoPtr->iVersion = iVersion;
5159 if (infoPtr->iVersion >= 5)
5160 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5162 return iOldVersion;
5166 static LRESULT
5167 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5170 WORD iString = HIWORD(wParam);
5171 WORD buffersize = LOWORD(wParam);
5172 LPSTR str = (LPSTR)lParam;
5173 LRESULT ret = -1;
5175 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5177 if (iString < infoPtr->nNumStrings)
5179 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5181 TRACE("returning %s\n", debugstr_a(str));
5183 else
5184 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5186 return ret;
5190 static LRESULT
5191 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5194 WORD iString = HIWORD(wParam);
5195 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5196 LPWSTR str = (LPWSTR)lParam;
5197 LRESULT ret = -1;
5199 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5201 if (iString < infoPtr->nNumStrings)
5203 len = min(len, strlenW(infoPtr->strings[iString]));
5204 ret = (len+1)*sizeof(WCHAR);
5205 memcpy(str, infoPtr->strings[iString], ret);
5206 str[len] = '\0';
5208 TRACE("returning %s\n", debugstr_w(str));
5210 else
5211 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5213 return ret;
5216 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5217 * is the maximum size of the toolbar? */
5218 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5220 SIZE * pSize = (SIZE*)lParam;
5221 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5222 return 0;
5226 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5227 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5228 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5229 * sends). */
5230 static LRESULT
5231 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5234 INT nOldHotItem = infoPtr->nHotItem;
5236 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5237 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5239 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5240 wParam = -1;
5242 /* NOTE: an application can still remove the hot item even if anchor
5243 * highlighting is enabled */
5245 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5247 GetFocus();
5249 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5252 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5253 * which controls the amount of spacing between the image and the text
5254 * of buttons for TBSTYLE_LIST toolbars. */
5255 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5259 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5261 if (lParam != 0)
5262 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5264 infoPtr->iListGap = (INT)wParam;
5266 InvalidateRect(hwnd, NULL, TRUE);
5268 return 0;
5271 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5272 * of image lists associated with the various states. */
5273 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5277 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5279 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5282 static LRESULT
5283 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5286 LPSIZE lpsize = (LPSIZE)lParam;
5288 if (lpsize == NULL)
5289 return FALSE;
5292 * Testing shows the following:
5293 * wParam = 0 adjust cx value
5294 * = 1 set cy value to max size.
5295 * lParam pointer to SIZE structure
5298 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5299 wParam, lParam, lpsize->cx, lpsize->cy);
5301 switch(wParam) {
5302 case 0:
5303 if (lpsize->cx == -1) {
5304 /* **** this is wrong, native measures each button and sets it */
5305 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5307 else if(HIWORD(lpsize->cx)) {
5308 RECT rc;
5309 HWND hwndParent = GetParent(hwnd);
5311 GetWindowRect(hwnd, &rc);
5312 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5313 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5314 rc.left, rc.top, rc.right, rc.bottom);
5315 lpsize->cx = max(rc.right-rc.left,
5316 infoPtr->rcBound.right - infoPtr->rcBound.left);
5318 else {
5319 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5321 break;
5322 case 1:
5323 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5324 /* lpsize->cy = infoPtr->nHeight; */
5325 break;
5326 default:
5327 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5328 wParam);
5329 return 0;
5331 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5332 lpsize->cx, lpsize->cy);
5333 return 1;
5336 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5338 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5340 InvalidateRect(hwnd, NULL, TRUE);
5341 return 1;
5345 static LRESULT
5346 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5349 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5350 LOGFONTA logFont;
5352 TRACE("hwnd = %p\n", hwnd);
5354 /* initialize info structure */
5355 infoPtr->nButtonHeight = 22;
5356 infoPtr->nButtonWidth = 24;
5357 infoPtr->nBitmapHeight = 15;
5358 infoPtr->nBitmapWidth = 16;
5360 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5361 infoPtr->nMaxTextRows = 1;
5362 infoPtr->cxMin = -1;
5363 infoPtr->cxMax = -1;
5364 infoPtr->nNumBitmaps = 0;
5365 infoPtr->nNumStrings = 0;
5367 infoPtr->bCaptured = FALSE;
5368 infoPtr->nButtonDown = -1;
5369 infoPtr->nButtonDrag = -1;
5370 infoPtr->nOldHit = -1;
5371 infoPtr->nHotItem = -1;
5372 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5373 infoPtr->bUnicode = IsWindowUnicode (infoPtr->hwndNotify);
5374 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5375 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5376 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5377 infoPtr->bDragOutSent = FALSE;
5378 infoPtr->iVersion = 0;
5379 infoPtr->hwndSelf = hwnd;
5380 infoPtr->bDoRedraw = TRUE;
5381 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5382 infoPtr->clrBtnShadow = CLR_DEFAULT;
5383 /* not sure where the +1 comes from, but this comes to the same value
5384 * as native so this is probably correct */
5385 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5386 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5387 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5388 infoPtr->dwStyle = dwStyle;
5389 infoPtr->tbim.iButton = -1;
5390 GetClientRect(hwnd, &infoPtr->client_rect);
5391 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5393 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5394 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5396 if (dwStyle & TBSTYLE_TOOLTIPS) {
5397 /* Create tooltip control */
5398 infoPtr->hwndToolTip =
5399 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5400 CW_USEDEFAULT, CW_USEDEFAULT,
5401 CW_USEDEFAULT, CW_USEDEFAULT,
5402 hwnd, 0, 0, 0);
5404 /* Send NM_TOOLTIPSCREATED notification */
5405 if (infoPtr->hwndToolTip) {
5406 NMTOOLTIPSCREATED nmttc;
5408 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5410 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5411 NM_TOOLTIPSCREATED);
5415 TOOLBAR_CheckStyle (hwnd, dwStyle);
5417 TOOLBAR_CalcToolbar(hwnd);
5419 return 0;
5423 static LRESULT
5424 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5428 /* delete tooltip control */
5429 if (infoPtr->hwndToolTip)
5430 DestroyWindow (infoPtr->hwndToolTip);
5432 /* delete temporary buffer for tooltip text */
5433 if (infoPtr->pszTooltipText)
5434 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5436 /* delete button data */
5437 if (infoPtr->buttons)
5438 Free (infoPtr->buttons);
5440 /* delete strings */
5441 if (infoPtr->strings) {
5442 INT i;
5443 for (i = 0; i < infoPtr->nNumStrings; i++)
5444 if (infoPtr->strings[i])
5445 Free (infoPtr->strings[i]);
5447 Free (infoPtr->strings);
5450 /* destroy internal image list */
5451 if (infoPtr->himlInt)
5452 ImageList_Destroy (infoPtr->himlInt);
5454 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5455 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5456 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5458 /* delete default font */
5459 if (infoPtr->hFont)
5460 DeleteObject (infoPtr->hDefaultFont);
5462 /* free toolbar info data */
5463 Free (infoPtr);
5464 SetWindowLongPtrW (hwnd, 0, 0);
5466 return 0;
5470 static LRESULT
5471 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5474 NMTBCUSTOMDRAW tbcd;
5475 INT ret = FALSE;
5476 DWORD ntfret;
5478 /* the app has told us not to redraw the toolbar */
5479 if (!infoPtr->bDoRedraw)
5480 return FALSE;
5482 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5483 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5484 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5485 tbcd.nmcd.hdc = (HDC)wParam;
5486 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5487 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5489 /* FIXME: in general the return flags *can* be or'ed together */
5490 switch (infoPtr->dwBaseCustDraw)
5492 case CDRF_DODEFAULT:
5493 break;
5494 case CDRF_SKIPDEFAULT:
5495 return TRUE;
5496 default:
5497 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5498 hwnd, ntfret);
5502 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5503 * to my parent for processing.
5505 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5506 POINT pt, ptorig;
5507 HDC hdc = (HDC)wParam;
5508 HWND parent;
5510 pt.x = 0;
5511 pt.y = 0;
5512 parent = GetParent(hwnd);
5513 MapWindowPoints(hwnd, parent, &pt, 1);
5514 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5515 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5516 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5518 if (!ret)
5519 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5521 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5522 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5523 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5524 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5525 tbcd.nmcd.hdc = (HDC)wParam;
5526 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5527 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5528 switch (infoPtr->dwBaseCustDraw)
5530 case CDRF_DODEFAULT:
5531 break;
5532 case CDRF_SKIPDEFAULT:
5533 return TRUE;
5534 default:
5535 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5536 hwnd, ntfret);
5539 return ret;
5543 static LRESULT
5544 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5548 return (LRESULT)infoPtr->hFont;
5552 static LRESULT
5553 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5555 POINT pt;
5556 INT nHit;
5558 pt.x = (INT)LOWORD(lParam);
5559 pt.y = (INT)HIWORD(lParam);
5560 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5562 if (nHit >= 0)
5563 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5564 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5565 TOOLBAR_Customize (hwnd);
5567 return 0;
5571 static LRESULT
5572 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5575 TBUTTON_INFO *btnPtr;
5576 POINT pt;
5577 INT nHit;
5578 NMTOOLBARA nmtb;
5579 NMMOUSE nmmouse;
5580 BOOL bDragKeyPressed;
5582 TRACE("\n");
5584 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5585 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5586 else
5587 bDragKeyPressed = (wParam & MK_SHIFT);
5589 if (infoPtr->hwndToolTip)
5590 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5591 WM_LBUTTONDOWN, wParam, lParam);
5593 pt.x = (INT)LOWORD(lParam);
5594 pt.y = (INT)HIWORD(lParam);
5595 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5597 btnPtr = &infoPtr->buttons[nHit];
5599 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5601 infoPtr->nButtonDrag = nHit;
5602 SetCapture (hwnd);
5604 /* If drag cursor has not been loaded, load it.
5605 * Note: it doesn't need to be freed */
5606 if (!hCursorDrag)
5607 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5608 SetCursor(hCursorDrag);
5610 else if (nHit >= 0)
5612 RECT arrowRect;
5613 infoPtr->nOldHit = nHit;
5615 CopyRect(&arrowRect, &btnPtr->rect);
5616 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5618 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5619 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5620 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5621 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5622 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5623 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5625 LRESULT res;
5627 /* draw in pressed state */
5628 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5629 btnPtr->fsState |= TBSTATE_PRESSED;
5630 else
5631 btnPtr->bDropDownPressed = TRUE;
5632 RedrawWindow(hwnd,&btnPtr->rect,0,
5633 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5635 nmtb.iItem = btnPtr->idCommand;
5636 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5637 nmtb.cchText = 0;
5638 nmtb.pszText = 0;
5639 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5640 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5641 TBN_DROPDOWN);
5642 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5644 if (res != TBDDRET_TREATPRESSED)
5646 MSG msg;
5648 /* redraw button in unpressed state */
5649 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5650 btnPtr->fsState &= ~TBSTATE_PRESSED;
5651 else
5652 btnPtr->bDropDownPressed = FALSE;
5653 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5655 /* find and set hot item
5656 * NOTE: native doesn't do this, but that is a bug */
5657 GetCursorPos(&pt);
5658 ScreenToClient(hwnd, &pt);
5659 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5660 if (!infoPtr->bAnchor || (nHit >= 0))
5661 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5663 /* remove any left mouse button down or double-click messages
5664 * so that we can get a toggle effect on the button */
5665 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5666 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5669 return 0;
5671 /* otherwise drop through and process as pushed */
5673 infoPtr->bCaptured = TRUE;
5674 infoPtr->nButtonDown = nHit;
5675 infoPtr->bDragOutSent = FALSE;
5677 btnPtr->fsState |= TBSTATE_PRESSED;
5679 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5681 if (btnPtr->fsState & TBSTATE_ENABLED)
5682 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5683 UpdateWindow(hwnd);
5684 SetCapture (hwnd);
5687 if (nHit >=0)
5689 nmtb.iItem = btnPtr->idCommand;
5690 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5691 nmtb.tbButton.idCommand = btnPtr->idCommand;
5692 nmtb.tbButton.fsState = btnPtr->fsState;
5693 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5694 nmtb.tbButton.dwData = btnPtr->dwData;
5695 nmtb.tbButton.iString = btnPtr->iString;
5696 nmtb.cchText = 0; /* !!! not correct */
5697 nmtb.pszText = 0; /* !!! not correct */
5698 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5701 nmmouse.dwHitInfo = nHit;
5703 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5704 if (nmmouse.dwHitInfo < 0)
5705 nmmouse.dwItemSpec = -1;
5706 else
5708 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5709 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5712 ClientToScreen(hwnd, &pt);
5713 nmmouse.pt = pt;
5715 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_LDOWN))
5716 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5718 return 0;
5721 static LRESULT
5722 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5725 TBUTTON_INFO *btnPtr;
5726 POINT pt;
5727 INT nHit;
5728 INT nOldIndex = -1;
5729 BOOL bSendMessage = TRUE;
5730 NMHDR hdr;
5731 NMMOUSE nmmouse;
5732 NMTOOLBARA nmtb;
5734 if (infoPtr->hwndToolTip)
5735 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5736 WM_LBUTTONUP, wParam, lParam);
5738 pt.x = (INT)LOWORD(lParam);
5739 pt.y = (INT)HIWORD(lParam);
5740 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5742 if (!infoPtr->bAnchor || (nHit >= 0))
5743 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5745 if (infoPtr->nButtonDrag >= 0) {
5746 RECT rcClient;
5747 NMHDR hdr;
5749 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5750 ReleaseCapture();
5751 /* reset cursor */
5752 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5754 GetClientRect(hwnd, &rcClient);
5755 if (PtInRect(&rcClient, pt))
5757 INT nButton = -1;
5758 if (nHit >= 0)
5759 nButton = nHit;
5760 else if (nHit < -1)
5761 nButton = -nHit;
5762 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5763 nButton = -nHit;
5765 if (nButton == infoPtr->nButtonDrag)
5767 /* if the button is moved sightly left and we have a
5768 * separator there then remove it */
5769 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5771 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5772 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5774 else /* else insert a separator before the dragged button */
5776 TBBUTTON tbb;
5777 memset(&tbb, 0, sizeof(tbb));
5778 tbb.fsStyle = BTNS_SEP;
5779 tbb.iString = -1;
5780 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5783 else
5785 if (nButton == -1)
5787 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5788 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5789 else
5790 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5792 else
5793 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5796 else
5798 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5799 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5802 /* button under cursor changed so need to re-set hot item */
5803 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5804 infoPtr->nButtonDrag = -1;
5806 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5808 else if (infoPtr->nButtonDown >= 0) {
5809 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5810 btnPtr->fsState &= ~TBSTATE_PRESSED;
5812 if (btnPtr->fsStyle & BTNS_CHECK) {
5813 if (btnPtr->fsStyle & BTNS_GROUP) {
5814 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5815 nHit);
5816 if (nOldIndex == nHit)
5817 bSendMessage = FALSE;
5818 if ((nOldIndex != nHit) &&
5819 (nOldIndex != -1))
5820 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5821 btnPtr->fsState |= TBSTATE_CHECKED;
5823 else {
5824 if (btnPtr->fsState & TBSTATE_CHECKED)
5825 btnPtr->fsState &= ~TBSTATE_CHECKED;
5826 else
5827 btnPtr->fsState |= TBSTATE_CHECKED;
5831 if (nOldIndex != -1)
5832 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5835 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5836 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5837 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5839 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5840 ReleaseCapture ();
5841 infoPtr->nButtonDown = -1;
5843 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5844 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5845 NM_RELEASEDCAPTURE);
5847 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5848 * TBN_BEGINDRAG
5850 nmtb.iItem = btnPtr->idCommand;
5851 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5852 nmtb.tbButton.idCommand = btnPtr->idCommand;
5853 nmtb.tbButton.fsState = btnPtr->fsState;
5854 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5855 nmtb.tbButton.dwData = btnPtr->dwData;
5856 nmtb.tbButton.iString = btnPtr->iString;
5857 nmtb.cchText = 0; /* !!! not correct */
5858 nmtb.pszText = 0; /* !!! not correct */
5859 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5860 TBN_ENDDRAG);
5862 if (btnPtr->fsState & TBSTATE_ENABLED)
5864 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5865 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5869 /* !!! Undocumented - toolbar at 4.71 level and above sends
5870 * NM_CLICK with the NMMOUSE structure. */
5871 nmmouse.dwHitInfo = nHit;
5873 if (nmmouse.dwHitInfo < 0)
5874 nmmouse.dwItemSpec = -1;
5875 else
5877 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5878 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5881 ClientToScreen(hwnd, &pt);
5882 nmmouse.pt = pt;
5884 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5885 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5887 return 0;
5890 static LRESULT
5891 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5895 NMMOUSE nmmouse;
5896 POINT pt;
5898 pt.x = LOWORD(lParam);
5899 pt.y = HIWORD(lParam);
5901 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5903 if (nmmouse.dwHitInfo < 0) {
5904 nmmouse.dwItemSpec = -1;
5905 } else {
5906 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5907 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5910 ClientToScreen(hwnd, &pt);
5911 nmmouse.pt = pt;
5913 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5914 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5916 return 0;
5919 static LRESULT
5920 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5923 NMHDR nmhdr;
5925 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5926 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5928 return 0;
5931 static LRESULT
5932 TOOLBAR_CaptureChanged(HWND hwnd)
5934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5935 TBUTTON_INFO *btnPtr;
5937 infoPtr->bCaptured = FALSE;
5939 if (infoPtr->nButtonDown >= 0)
5941 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5942 btnPtr->fsState &= ~TBSTATE_PRESSED;
5944 infoPtr->nOldHit = -1;
5946 if (btnPtr->fsState & TBSTATE_ENABLED)
5947 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5949 return 0;
5952 static LRESULT
5953 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5955 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5956 TBUTTON_INFO *hotBtnPtr;
5958 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5960 /* don't remove hot effects when in anchor highlighting mode or when a
5961 * drop-down button is pressed */
5962 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
5963 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5965 if (infoPtr->nOldHit < 0)
5966 return TRUE;
5968 /* If the last button we were over is depressed then make it not */
5969 /* depressed and redraw it */
5970 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5972 TBUTTON_INFO *btnPtr;
5973 RECT rc1;
5975 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5977 btnPtr->fsState &= ~TBSTATE_PRESSED;
5979 rc1 = hotBtnPtr->rect;
5980 InflateRect (&rc1, 1, 1);
5981 InvalidateRect (hwnd, &rc1, TRUE);
5984 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5986 NMTOOLBARW nmt;
5987 ZeroMemory(&nmt, sizeof(nmt));
5988 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5989 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5990 infoPtr->bDragOutSent = TRUE;
5993 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5995 return TRUE;
5998 static LRESULT
5999 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6001 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6002 POINT pt;
6003 TRACKMOUSEEVENT trackinfo;
6004 INT nHit;
6005 TBUTTON_INFO *btnPtr;
6007 /* fill in the TRACKMOUSEEVENT struct */
6008 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6009 trackinfo.dwFlags = TME_QUERY;
6010 trackinfo.hwndTrack = hwnd;
6011 trackinfo.dwHoverTime = HOVER_DEFAULT;
6013 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6014 _TrackMouseEvent(&trackinfo);
6016 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6017 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6018 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6020 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6021 /* and can properly deactivate the hot toolbar button */
6022 _TrackMouseEvent(&trackinfo);
6025 if (infoPtr->hwndToolTip)
6026 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6027 WM_MOUSEMOVE, wParam, lParam);
6029 pt.x = (INT)LOWORD(lParam);
6030 pt.y = (INT)HIWORD(lParam);
6032 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6034 if (!infoPtr->bAnchor || (nHit >= 0))
6035 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6037 if (infoPtr->nOldHit != nHit)
6039 if (infoPtr->bCaptured)
6041 if (!infoPtr->bDragOutSent)
6043 NMTOOLBARW nmt;
6044 ZeroMemory(&nmt, sizeof(nmt));
6045 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6046 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6047 infoPtr->bDragOutSent = TRUE;
6050 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6051 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6052 btnPtr->fsState &= ~TBSTATE_PRESSED;
6053 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6055 else if (nHit == infoPtr->nButtonDown) {
6056 btnPtr->fsState |= TBSTATE_PRESSED;
6057 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6059 infoPtr->nOldHit = nHit;
6063 return 0;
6067 inline static LRESULT
6068 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6070 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6071 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6072 /* else */
6073 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6077 inline static LRESULT
6078 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6080 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6081 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6083 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6087 static LRESULT
6088 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6090 TOOLBAR_INFO *infoPtr;
6091 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6092 DWORD styleadd = 0;
6094 /* allocate memory for info structure */
6095 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6096 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6098 /* paranoid!! */
6099 infoPtr->dwStructSize = sizeof(TBBUTTON);
6100 infoPtr->nRows = 1;
6102 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6103 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6104 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6105 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6108 /* native control does:
6109 * Get a lot of colors and brushes
6110 * WM_NOTIFYFORMAT
6111 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
6112 * CreateFontIndirectA(adr1)
6113 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6114 * hdc = GetDC(toolbar)
6115 * GetSystemMetrics(0x48)
6116 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6117 * 0, 0, 0, 0, "MARLETT")
6118 * oldfnt = SelectObject(hdc, fnt2)
6119 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
6120 * GetTextMetricsA(hdc, adr3)
6121 * SelectObject(hdc, oldfnt)
6122 * DeleteObject(fnt2)
6123 * ReleaseDC(hdc)
6124 * InvalidateRect(toolbar, 0, 1)
6125 * SetWindowLongA(toolbar, 0, addr)
6126 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
6127 * WM_STYLECHANGING
6128 * CallWinEx old new
6129 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6130 * ie 2 0x4600094c 0x4600094c 0x4600894d
6131 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6132 * rebar 0x50008844 0x40008844 0x50008845
6133 * pager 0x50000844 0x40000844 0x50008845
6134 * IC35mgr 0x5400084e **nochange**
6135 * on entry to _NCCREATE 0x5400084e
6136 * rowlist 0x5400004e **nochange**
6137 * on entry to _NCCREATE 0x5400004e
6141 /* I think the code below is a bug, but it is the way that the native
6142 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6143 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6144 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6145 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6146 * Some how, the only cases of this seem to be MFC programs.
6148 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6149 * does not occur in the WM_STYLECHANGING routine.
6150 * (Guy Albertelli 9/2001)
6153 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6154 styleadd |= TBSTYLE_TRANSPARENT;
6155 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6156 styleadd |= CCS_TOP; /* default to top */
6157 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6160 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6164 static LRESULT
6165 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6167 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6168 RECT rcWindow;
6169 HDC hdc;
6171 if (dwStyle & WS_MINIMIZE)
6172 return 0; /* Nothing to do */
6174 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6176 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6177 return 0;
6179 if (!(dwStyle & CCS_NODIVIDER))
6181 GetWindowRect (hwnd, &rcWindow);
6182 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6183 if( dwStyle & WS_BORDER )
6184 OffsetRect (&rcWindow, 1, 1);
6185 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6188 ReleaseDC( hwnd, hdc );
6190 return 0;
6194 /* handles requests from the tooltip control on what text to display */
6195 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6197 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6199 TRACE("button index = %d\n", index);
6201 if (infoPtr->pszTooltipText)
6203 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6204 infoPtr->pszTooltipText = NULL;
6207 if (index < 0)
6208 return 0;
6210 if (infoPtr->bNtfUnicode)
6212 WCHAR wszBuffer[INFOTIPSIZE+1];
6213 NMTBGETINFOTIPW tbgit;
6214 unsigned int len; /* in chars */
6216 wszBuffer[0] = '\0';
6217 wszBuffer[INFOTIPSIZE] = '\0';
6219 tbgit.pszText = wszBuffer;
6220 tbgit.cchTextMax = INFOTIPSIZE;
6221 tbgit.iItem = lpnmtdi->hdr.idFrom;
6222 tbgit.lParam = infoPtr->buttons[index].dwData;
6224 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6226 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6228 len = strlenW(tbgit.pszText);
6229 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6231 /* need to allocate temporary buffer in infoPtr as there
6232 * isn't enough space in buffer passed to us by the
6233 * tooltip control */
6234 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6235 if (infoPtr->pszTooltipText)
6237 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6238 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6239 return 0;
6242 else if (len > 0)
6244 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6245 return 0;
6248 else
6250 CHAR szBuffer[INFOTIPSIZE+1];
6251 NMTBGETINFOTIPA tbgit;
6252 unsigned int len; /* in chars */
6254 szBuffer[0] = '\0';
6255 szBuffer[INFOTIPSIZE] = '\0';
6257 tbgit.pszText = szBuffer;
6258 tbgit.cchTextMax = INFOTIPSIZE;
6259 tbgit.iItem = lpnmtdi->hdr.idFrom;
6260 tbgit.lParam = infoPtr->buttons[index].dwData;
6262 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6264 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6266 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6267 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6269 /* need to allocate temporary buffer in infoPtr as there
6270 * isn't enough space in buffer passed to us by the
6271 * tooltip control */
6272 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6273 if (infoPtr->pszTooltipText)
6275 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6276 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6277 return 0;
6280 else if (len > 0)
6282 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6283 return 0;
6287 /* if button has text, but it is not shown then automatically
6288 * use that text as tooltip */
6289 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6290 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6292 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6293 unsigned int len = pszText ? strlenW(pszText) : 0;
6295 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6297 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6299 /* need to allocate temporary buffer in infoPtr as there
6300 * isn't enough space in buffer passed to us by the
6301 * tooltip control */
6302 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6303 if (infoPtr->pszTooltipText)
6305 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6306 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6307 return 0;
6310 else if (len > 0)
6312 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6313 return 0;
6317 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6319 /* last resort: send notification on to app */
6320 /* FIXME: find out what is really used here */
6321 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6325 inline static LRESULT
6326 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6329 LPNMHDR lpnmh = (LPNMHDR)lParam;
6331 switch (lpnmh->code)
6333 case PGN_CALCSIZE:
6335 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6337 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6338 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6339 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6340 lppgc->iWidth);
6342 else {
6343 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6344 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6345 lppgc->iHeight);
6347 return 0;
6350 case PGN_SCROLL:
6352 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6354 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6355 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6356 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6357 lppgs->iScroll, lppgs->iDir);
6358 return 0;
6361 case TTN_GETDISPINFOW:
6362 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6364 case TTN_GETDISPINFOA:
6365 FIXME("TTN_GETDISPINFOA - stub\n");
6366 return 0;
6368 default:
6369 return 0;
6374 static LRESULT
6375 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6377 /* remove this routine when Toolbar is improved to pass infoPtr
6378 * around instead of hwnd.
6380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6381 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6385 static LRESULT
6386 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6388 INT i;
6390 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6392 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6393 return NFR_UNICODE;
6395 if (lParam == NF_REQUERY) {
6396 i = SendMessageW(infoPtr->hwndNotify,
6397 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6398 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6399 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6401 i = NFR_ANSI;
6403 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6404 return (LRESULT)i;
6406 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6410 static LRESULT
6411 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6414 HDC hdc;
6415 PAINTSTRUCT ps;
6417 /* fill ps.rcPaint with a default rect */
6418 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6420 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6422 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6423 ps.rcPaint.left, ps.rcPaint.top,
6424 ps.rcPaint.right, ps.rcPaint.bottom);
6426 TOOLBAR_Refresh (hwnd, hdc, &ps);
6427 if (!wParam) EndPaint (hwnd, &ps);
6429 return 0;
6433 static LRESULT
6434 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6435 /*****************************************************
6437 * Function;
6438 * Handles the WM_SETREDRAW message.
6440 * Documentation:
6441 * According to testing V4.71 of COMCTL32 returns the
6442 * *previous* status of the redraw flag (either 0 or 1)
6443 * instead of the MSDN documented value of 0 if handled.
6444 * (For laughs see the "consistency" with same function
6445 * in rebar.)
6447 *****************************************************/
6449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6450 BOOL oldredraw = infoPtr->bDoRedraw;
6452 TRACE("set to %s\n",
6453 (wParam) ? "TRUE" : "FALSE");
6454 infoPtr->bDoRedraw = (BOOL) wParam;
6455 if (wParam) {
6456 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6458 return (oldredraw) ? 1 : 0;
6462 static LRESULT
6463 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6466 DWORD dwStyle = infoPtr->dwStyle;
6467 RECT parent_rect;
6468 RECT window_rect;
6469 HWND parent;
6470 INT x, y;
6471 INT cx, cy;
6472 INT flags;
6473 UINT uPosFlags = 0;
6475 /* Resize deadlock check */
6476 if (infoPtr->bAutoSize) {
6477 infoPtr->bAutoSize = FALSE;
6478 return 0;
6481 /* FIXME: optimize to only update size if the new size doesn't */
6482 /* match the current size */
6484 flags = (INT) wParam;
6486 /* FIXME for flags =
6487 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6490 TRACE("sizing toolbar!\n");
6492 if (flags == SIZE_RESTORED) {
6493 /* width and height don't apply */
6494 parent = GetParent (hwnd);
6495 GetClientRect(parent, &parent_rect);
6496 x = parent_rect.left;
6497 y = parent_rect.top;
6499 if (dwStyle & CCS_NORESIZE) {
6500 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6503 * this sets the working width of the toolbar, and
6504 * Calc Toolbar will not adjust it, only the height
6506 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6507 cy = infoPtr->nHeight;
6508 cx = infoPtr->nWidth;
6509 TOOLBAR_CalcToolbar (hwnd);
6510 infoPtr->nWidth = cx;
6511 infoPtr->nHeight = cy;
6513 else {
6514 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6515 TOOLBAR_CalcToolbar (hwnd);
6516 cy = infoPtr->nHeight;
6517 cx = infoPtr->nWidth;
6519 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6520 GetWindowRect(hwnd, &window_rect);
6521 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6522 y = window_rect.top;
6524 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6525 GetWindowRect(hwnd, &window_rect);
6526 y = parent_rect.bottom -
6527 ( window_rect.bottom - window_rect.top);
6531 if (dwStyle & CCS_NOPARENTALIGN) {
6532 uPosFlags |= SWP_NOMOVE;
6533 cy = infoPtr->nHeight;
6534 cx = infoPtr->nWidth;
6537 if (!(dwStyle & CCS_NODIVIDER))
6538 cy += GetSystemMetrics(SM_CYEDGE);
6540 if (dwStyle & WS_BORDER)
6542 x = y = 1;
6543 cy += GetSystemMetrics(SM_CYEDGE);
6544 cx += GetSystemMetrics(SM_CYEDGE);
6547 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6549 RECT delta_width, delta_height, client, dummy;
6550 DWORD min_x, max_x, min_y, max_y;
6551 TBUTTON_INFO *btnPtr;
6552 INT i;
6554 GetClientRect(hwnd, &client);
6555 if(client.right > infoPtr->client_rect.right)
6557 min_x = infoPtr->client_rect.right;
6558 max_x = client.right;
6560 else
6562 max_x = infoPtr->client_rect.right;
6563 min_x = client.right;
6565 if(client.bottom > infoPtr->client_rect.bottom)
6567 min_y = infoPtr->client_rect.bottom;
6568 max_y = client.bottom;
6570 else
6572 max_y = infoPtr->client_rect.bottom;
6573 min_y = client.bottom;
6576 SetRect(&delta_width, min_x, 0, max_x, min_y);
6577 SetRect(&delta_height, 0, min_y, max_x, max_y);
6579 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6580 btnPtr = infoPtr->buttons;
6581 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6582 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6583 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6584 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6587 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6588 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6590 GetClientRect(hwnd, &infoPtr->client_rect);
6591 return 0;
6595 static LRESULT
6596 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6600 if (nType == GWL_STYLE) {
6601 if (lpStyle->styleNew & TBSTYLE_LIST) {
6602 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6604 else {
6605 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6607 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6608 (TBSTYLE_FLAT | TBSTYLE_LIST));
6609 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6611 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6613 infoPtr->dwStyle = lpStyle->styleNew;
6616 TOOLBAR_CalcToolbar(hwnd);
6618 TOOLBAR_AutoSize (hwnd);
6620 InvalidateRect(hwnd, NULL, TRUE);
6622 return 0;
6626 static LRESULT
6627 TOOLBAR_SysColorChange (HWND hwnd)
6629 COMCTL32_RefreshSysColors();
6631 return 0;
6636 static LRESULT WINAPI
6637 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6641 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6642 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6644 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6645 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6647 switch (uMsg)
6649 case TB_ADDBITMAP:
6650 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6652 case TB_ADDBUTTONSA:
6653 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6655 case TB_ADDBUTTONSW:
6656 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6658 case TB_ADDSTRINGA:
6659 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6661 case TB_ADDSTRINGW:
6662 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6664 case TB_AUTOSIZE:
6665 return TOOLBAR_AutoSize (hwnd);
6667 case TB_BUTTONCOUNT:
6668 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6670 case TB_BUTTONSTRUCTSIZE:
6671 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6673 case TB_CHANGEBITMAP:
6674 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6676 case TB_CHECKBUTTON:
6677 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6679 case TB_COMMANDTOINDEX:
6680 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6682 case TB_CUSTOMIZE:
6683 return TOOLBAR_Customize (hwnd);
6685 case TB_DELETEBUTTON:
6686 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6688 case TB_ENABLEBUTTON:
6689 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6691 case TB_GETANCHORHIGHLIGHT:
6692 return TOOLBAR_GetAnchorHighlight (hwnd);
6694 case TB_GETBITMAP:
6695 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6697 case TB_GETBITMAPFLAGS:
6698 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6700 case TB_GETBUTTON:
6701 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6703 case TB_GETBUTTONINFOA:
6704 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6706 case TB_GETBUTTONINFOW:
6707 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6709 case TB_GETBUTTONSIZE:
6710 return TOOLBAR_GetButtonSize (hwnd);
6712 case TB_GETBUTTONTEXTA:
6713 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6715 case TB_GETBUTTONTEXTW:
6716 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6718 case TB_GETDISABLEDIMAGELIST:
6719 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6721 case TB_GETEXTENDEDSTYLE:
6722 return TOOLBAR_GetExtendedStyle (hwnd);
6724 case TB_GETHOTIMAGELIST:
6725 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6727 case TB_GETHOTITEM:
6728 return TOOLBAR_GetHotItem (hwnd);
6730 case TB_GETIMAGELIST:
6731 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6733 case TB_GETINSERTMARK:
6734 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6736 case TB_GETINSERTMARKCOLOR:
6737 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6739 case TB_GETITEMRECT:
6740 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6742 case TB_GETMAXSIZE:
6743 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6745 /* case TB_GETOBJECT: */ /* 4.71 */
6747 case TB_GETPADDING:
6748 return TOOLBAR_GetPadding (hwnd);
6750 case TB_GETRECT:
6751 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6753 case TB_GETROWS:
6754 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6756 case TB_GETSTATE:
6757 return TOOLBAR_GetState (hwnd, wParam, lParam);
6759 case TB_GETSTRINGA:
6760 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6762 case TB_GETSTRINGW:
6763 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6765 case TB_GETSTYLE:
6766 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6768 case TB_GETTEXTROWS:
6769 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6771 case TB_GETTOOLTIPS:
6772 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6774 case TB_GETUNICODEFORMAT:
6775 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6777 case TB_HIDEBUTTON:
6778 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6780 case TB_HITTEST:
6781 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6783 case TB_INDETERMINATE:
6784 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6786 case TB_INSERTBUTTONA:
6787 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6789 case TB_INSERTBUTTONW:
6790 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6792 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6794 case TB_ISBUTTONCHECKED:
6795 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6797 case TB_ISBUTTONENABLED:
6798 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6800 case TB_ISBUTTONHIDDEN:
6801 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6803 case TB_ISBUTTONHIGHLIGHTED:
6804 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6806 case TB_ISBUTTONINDETERMINATE:
6807 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6809 case TB_ISBUTTONPRESSED:
6810 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6812 case TB_LOADIMAGES:
6813 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6815 case TB_MAPACCELERATORA:
6816 case TB_MAPACCELERATORW:
6817 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6819 case TB_MARKBUTTON:
6820 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6822 case TB_MOVEBUTTON:
6823 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6825 case TB_PRESSBUTTON:
6826 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6828 case TB_REPLACEBITMAP:
6829 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6831 case TB_SAVERESTOREA:
6832 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6834 case TB_SAVERESTOREW:
6835 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6837 case TB_SETANCHORHIGHLIGHT:
6838 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6840 case TB_SETBITMAPSIZE:
6841 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6843 case TB_SETBUTTONINFOA:
6844 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6846 case TB_SETBUTTONINFOW:
6847 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6849 case TB_SETBUTTONSIZE:
6850 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6852 case TB_SETBUTTONWIDTH:
6853 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6855 case TB_SETCMDID:
6856 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6858 case TB_SETDISABLEDIMAGELIST:
6859 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6861 case TB_SETDRAWTEXTFLAGS:
6862 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6864 case TB_SETEXTENDEDSTYLE:
6865 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6867 case TB_SETHOTIMAGELIST:
6868 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6870 case TB_SETHOTITEM:
6871 return TOOLBAR_SetHotItem (hwnd, wParam);
6873 case TB_SETIMAGELIST:
6874 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6876 case TB_SETINDENT:
6877 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6879 case TB_SETINSERTMARK:
6880 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6882 case TB_SETINSERTMARKCOLOR:
6883 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6885 case TB_SETMAXTEXTROWS:
6886 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6888 case TB_SETPADDING:
6889 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6891 case TB_SETPARENT:
6892 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6894 case TB_SETROWS:
6895 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6897 case TB_SETSTATE:
6898 return TOOLBAR_SetState (hwnd, wParam, lParam);
6900 case TB_SETSTYLE:
6901 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6903 case TB_SETTOOLTIPS:
6904 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6906 case TB_SETUNICODEFORMAT:
6907 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6909 case TB_UNKWN45D:
6910 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6912 case TB_UNKWN45E:
6913 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6915 case TB_UNKWN460:
6916 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6918 case TB_UNKWN462:
6919 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6921 case TB_UNKWN463:
6922 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6924 case TB_UNKWN464:
6925 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6927 /* Common Control Messages */
6929 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6930 case CCM_GETCOLORSCHEME:
6931 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6933 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6934 case CCM_SETCOLORSCHEME:
6935 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6937 case CCM_GETVERSION:
6938 return TOOLBAR_GetVersion (hwnd);
6940 case CCM_SETVERSION:
6941 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6944 /* case WM_CHAR: */
6946 case WM_CREATE:
6947 return TOOLBAR_Create (hwnd, wParam, lParam);
6949 case WM_DESTROY:
6950 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6952 case WM_ERASEBKGND:
6953 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6955 case WM_GETFONT:
6956 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6958 /* case WM_KEYDOWN: */
6959 /* case WM_KILLFOCUS: */
6961 case WM_LBUTTONDBLCLK:
6962 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6964 case WM_LBUTTONDOWN:
6965 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6967 case WM_LBUTTONUP:
6968 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6970 case WM_RBUTTONUP:
6971 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6973 case WM_RBUTTONDBLCLK:
6974 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6976 case WM_MOUSEMOVE:
6977 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6979 case WM_MOUSELEAVE:
6980 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6982 case WM_CAPTURECHANGED:
6983 return TOOLBAR_CaptureChanged(hwnd);
6985 case WM_NCACTIVATE:
6986 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6988 case WM_NCCALCSIZE:
6989 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6991 case WM_NCCREATE:
6992 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6994 case WM_NCPAINT:
6995 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6997 case WM_NOTIFY:
6998 return TOOLBAR_Notify (hwnd, wParam, lParam);
7000 case WM_NOTIFYFORMAT:
7001 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
7003 case WM_PAINT:
7004 return TOOLBAR_Paint (hwnd, wParam);
7006 case WM_SETREDRAW:
7007 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7009 case WM_SIZE:
7010 return TOOLBAR_Size (hwnd, wParam, lParam);
7012 case WM_STYLECHANGED:
7013 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7015 case WM_SYSCOLORCHANGE:
7016 return TOOLBAR_SysColorChange (hwnd);
7018 /* case WM_WININICHANGE: */
7020 case WM_CHARTOITEM:
7021 case WM_COMMAND:
7022 case WM_DRAWITEM:
7023 case WM_MEASUREITEM:
7024 case WM_VKEYTOITEM:
7025 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7027 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7028 case PGM_FORWARDMOUSE:
7029 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7031 default:
7032 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7033 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7034 uMsg, wParam, lParam);
7035 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7037 return 0;
7041 VOID
7042 TOOLBAR_Register (void)
7044 WNDCLASSW wndClass;
7046 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7047 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7048 wndClass.lpfnWndProc = ToolbarWindowProc;
7049 wndClass.cbClsExtra = 0;
7050 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7051 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7052 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7053 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7055 RegisterClassW (&wndClass);
7059 VOID
7060 TOOLBAR_Unregister (void)
7062 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7065 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7067 HIMAGELIST himlold;
7068 PIMLENTRY c = NULL;
7070 /* Check if the entry already exists */
7071 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7073 /* If this is a new entry we must create it and insert into the array */
7074 if (!c)
7076 PIMLENTRY *pnies;
7078 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7079 c->id = id;
7081 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7082 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7083 pnies[*cies] = c;
7084 (*cies)++;
7086 Free(*pies);
7087 *pies = pnies;
7090 himlold = c->himl;
7091 c->himl = himl;
7093 return himlold;
7097 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7099 int i;
7101 for (i = 0; i < *cies; i++)
7102 Free((*pies)[i]);
7104 Free(*pies);
7106 *cies = 0;
7107 *pies = NULL;
7111 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7113 PIMLENTRY c = NULL;
7115 if (pies != NULL)
7117 int i;
7119 for (i = 0; i < cies; i++)
7121 if (pies[i]->id == id)
7123 c = pies[i];
7124 break;
7129 return c;
7133 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7135 HIMAGELIST himlDef = 0;
7136 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7138 if (pie)
7139 himlDef = pie->himl;
7141 return himlDef;
7145 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7147 if (infoPtr->bUnicode)
7148 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
7149 else
7151 CHAR Buffer[256];
7152 NMTOOLBARA nmtba;
7153 BOOL bRet = FALSE;
7155 nmtba.iItem = nmtb->iItem;
7156 nmtba.pszText = Buffer;
7157 nmtba.cchText = 256;
7158 ZeroMemory(nmtba.pszText, nmtba.cchText);
7160 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
7162 int ccht = strlen(nmtba.pszText);
7163 if (ccht)
7164 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7165 nmtb->pszText, nmtb->cchText);
7167 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7168 bRet = TRUE;
7171 return bRet;
7176 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7177 int iItem, PCUSTOMBUTTON btnInfo)
7179 NMTOOLBARW nmtb;
7181 /* MSDN states that iItem is the index of the button, rather than the
7182 * command ID as used by every other NMTOOLBAR notification */
7183 nmtb.iItem = iItem;
7184 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7186 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);