Implement TBN_RESTORE notification.
[wine/wine64.git] / dlls / comctl32 / toolbar.c
blob048dae39de549a0d0391b80f3f476e06c50e437a
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_SAVE
55 * - Button wrapping (under construction).
56 * - Fix TB_SETROWS.
57 * - iListGap custom draw support.
59 * Testing:
60 * - Run tests using Waite Group Windows95 API Bible Volume 2.
61 * The second cdrom contains executables addstr.exe, btncount.exe,
62 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
63 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
64 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
65 * setparnt.exe, setrows.exe, toolwnd.exe.
66 * - Microsofts controlspy examples.
67 * - Charles Petzold's 'Programming Windows': gadgets.exe
70 #include <stdarg.h>
71 #include <string.h>
73 #include "windef.h"
74 #include "winbase.h"
75 #include "winreg.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_TRANSPARENT;
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);
872 else
873 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
875 if(lpText)
876 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE);
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;
4389 /* helper for TOOLBAR_SaveRestoreW */
4390 static BOOL
4391 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4393 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4394 debugstr_w(lpSave->pszValueName));
4396 return FALSE;
4400 /* helper for TOOLBAR_Restore */
4401 static void
4402 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4404 INT i;
4405 TTTOOLINFOW ti;
4407 ZeroMemory(&ti, sizeof(ti));
4408 ti.cbSize = sizeof(ti);
4409 ti.hwnd = infoPtr->hwndSelf;
4411 for (i = 0; i < infoPtr->nNumButtons; i++)
4413 if ((infoPtr->hwndToolTip) &&
4414 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4416 ti.uId = infoPtr->buttons[i].idCommand;
4417 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4421 Free(infoPtr->buttons);
4422 infoPtr->buttons = NULL;
4423 infoPtr->nNumButtons = 0;
4427 /* helper for TOOLBAR_SaveRestoreW */
4428 static BOOL
4429 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4431 LONG res;
4432 HKEY hkey = NULL;
4433 BOOL ret = FALSE;
4434 DWORD dwType;
4435 DWORD dwSize = 0;
4436 NMTBRESTORE nmtbr;
4438 /* restore toolbar information */
4439 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4440 debugstr_w(lpSave->pszValueName));
4442 memset(&nmtbr, 0, sizeof(nmtbr));
4444 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4445 KEY_QUERY_VALUE, &hkey);
4446 if (!res)
4447 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4448 NULL, &dwSize);
4449 if (!res && dwType != REG_BINARY)
4450 res = ERROR_FILE_NOT_FOUND;
4451 if (!res)
4453 nmtbr.pData = HeapAlloc(GetProcessHeap(), 0, dwSize);
4454 nmtbr.cbData = (UINT)dwSize;
4455 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4457 if (!res)
4458 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4459 (LPBYTE)nmtbr.pData, &dwSize);
4460 if (!res)
4462 nmtbr.pCurrent = nmtbr.pData;
4463 nmtbr.iItem = -1;
4464 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4465 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4467 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4469 INT i;
4471 /* remove all existing buttons as this function is designed to
4472 * restore the toolbar to a previously saved state */
4473 TOOLBAR_DeleteAllButtons(infoPtr);
4475 for (i = 0; i < nmtbr.cButtons; i++)
4477 nmtbr.iItem = i;
4478 nmtbr.tbButton.iBitmap = -1;
4479 nmtbr.tbButton.fsState = 0;
4480 nmtbr.tbButton.fsStyle = 0;
4481 nmtbr.tbButton.idCommand = 0;
4482 if (*nmtbr.pCurrent == (DWORD)-1)
4484 /* separator */
4485 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4486 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4488 else if (*nmtbr.pCurrent == (DWORD)-2)
4489 /* hidden button */
4490 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4491 else
4492 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4494 nmtbr.pCurrent++;
4496 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4498 /* can't contain real string as we don't know whether
4499 * the client put an ANSI or Unicode string in there */
4500 if (HIWORD(nmtbr.tbButton.iString))
4501 nmtbr.tbButton.iString = 0;
4503 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4504 (LPARAM)&nmtbr.tbButton);
4507 /* do legacy notifications */
4508 if (infoPtr->iVersion < 5)
4510 /* FIXME: send TBN_BEGINADJUST */
4511 FIXME("send TBN_GETBUTTONINFO for each button\n");
4512 /* FIXME: send TBN_ENDADJUST */
4515 /* remove all uninitialised buttons
4516 * note: loop backwards to avoid having to fixup i on a
4517 * delete */
4518 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4519 if (infoPtr->buttons[i].iBitmap == -1)
4520 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4522 /* only indicate success if at least one button survived */
4523 if (infoPtr->nNumButtons > 0) ret = TRUE;
4526 HeapFree(GetProcessHeap(), 0, nmtbr.pData);
4527 RegCloseKey(hkey);
4529 return ret;
4533 static LRESULT
4534 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4536 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4538 if (lpSave == NULL) return 0;
4540 if (wParam)
4541 return TOOLBAR_Save(infoPtr, lpSave);
4542 else
4543 return TOOLBAR_Restore(infoPtr, lpSave);
4547 static LRESULT
4548 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4550 TBSAVEPARAMSW SaveW;
4551 int len;
4553 if (lpSave == NULL) return 0;
4555 SaveW.hkr = lpSave->hkr;
4557 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4558 SaveW.pszSubKey = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
4559 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, (LPWSTR)SaveW.pszSubKey, len);
4561 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4562 SaveW.pszValueName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
4563 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, (LPWSTR)SaveW.pszValueName, len);
4565 return TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4569 static LRESULT
4570 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4573 BOOL bOldAnchor = infoPtr->bAnchor;
4575 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4577 infoPtr->bAnchor = (BOOL)wParam;
4579 /* Native does not remove the hot effect from an already hot button */
4581 return (LRESULT)bOldAnchor;
4585 static LRESULT
4586 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4589 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4591 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4593 if (wParam != 0)
4594 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4596 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4597 return FALSE;
4599 if (infoPtr->nNumButtons > 0)
4600 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4601 infoPtr->nNumButtons,
4602 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4603 LOWORD(lParam), HIWORD(lParam));
4605 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4606 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4609 if ((himlDef == infoPtr->himlInt) &&
4610 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4612 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4613 infoPtr->nBitmapHeight);
4616 return TRUE;
4620 static LRESULT
4621 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4624 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4625 TBUTTON_INFO *btnPtr;
4626 INT nIndex;
4627 RECT oldBtnRect;
4629 if (lptbbi == NULL)
4630 return FALSE;
4631 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4632 return FALSE;
4634 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4635 lptbbi->dwMask & 0x80000000);
4636 if (nIndex == -1)
4637 return FALSE;
4639 btnPtr = &infoPtr->buttons[nIndex];
4640 if (lptbbi->dwMask & TBIF_COMMAND)
4641 btnPtr->idCommand = lptbbi->idCommand;
4642 if (lptbbi->dwMask & TBIF_IMAGE)
4643 btnPtr->iBitmap = lptbbi->iImage;
4644 if (lptbbi->dwMask & TBIF_LPARAM)
4645 btnPtr->dwData = lptbbi->lParam;
4646 if (lptbbi->dwMask & TBIF_SIZE)
4647 btnPtr->cx = lptbbi->cx;
4648 if (lptbbi->dwMask & TBIF_STATE)
4649 btnPtr->fsState = lptbbi->fsState;
4650 if (lptbbi->dwMask & TBIF_STYLE)
4651 btnPtr->fsStyle = lptbbi->fsStyle;
4653 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4654 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4655 /* iString is index, zero it to make Str_SetPtr succeed */
4656 btnPtr->iString=0;
4658 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4661 /* save the button rect to see if we need to redraw the whole toolbar */
4662 oldBtnRect = btnPtr->rect;
4663 TOOLBAR_CalcToolbar(hwnd);
4665 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4666 InvalidateRect(hwnd, NULL, TRUE);
4667 else
4668 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4670 return TRUE;
4674 static LRESULT
4675 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4677 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4678 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4679 TBUTTON_INFO *btnPtr;
4680 INT nIndex;
4681 RECT oldBtnRect;
4683 if (lptbbi == NULL)
4684 return FALSE;
4685 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4686 return FALSE;
4688 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4689 lptbbi->dwMask & 0x80000000);
4690 if (nIndex == -1)
4691 return FALSE;
4693 btnPtr = &infoPtr->buttons[nIndex];
4694 if (lptbbi->dwMask & TBIF_COMMAND)
4695 btnPtr->idCommand = lptbbi->idCommand;
4696 if (lptbbi->dwMask & TBIF_IMAGE)
4697 btnPtr->iBitmap = lptbbi->iImage;
4698 if (lptbbi->dwMask & TBIF_LPARAM)
4699 btnPtr->dwData = lptbbi->lParam;
4700 if (lptbbi->dwMask & TBIF_SIZE)
4701 btnPtr->cx = lptbbi->cx;
4702 if (lptbbi->dwMask & TBIF_STATE)
4703 btnPtr->fsState = lptbbi->fsState;
4704 if (lptbbi->dwMask & TBIF_STYLE)
4705 btnPtr->fsStyle = lptbbi->fsStyle;
4707 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4708 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4709 /* iString is index, zero it to make Str_SetPtr succeed */
4710 btnPtr->iString=0;
4711 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4714 /* save the button rect to see if we need to redraw the whole toolbar */
4715 oldBtnRect = btnPtr->rect;
4716 TOOLBAR_CalcToolbar(hwnd);
4718 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4719 InvalidateRect(hwnd, NULL, TRUE);
4720 else
4721 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4723 return TRUE;
4727 static LRESULT
4728 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4731 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4733 if ((cx < 0) || (cy < 0))
4735 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4736 return FALSE;
4739 /* The documentation claims you can only change the button size before
4740 * any button has been added. But this is wrong.
4741 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4742 * it to the toolbar, and it checks that the return value is nonzero - mjm
4743 * Further testing shows that we must actually perform the change too.
4746 * The documentation also does not mention that if 0 is supplied for
4747 * either size, the system changes it to the default of 24 wide and
4748 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4750 infoPtr->nButtonWidth = (cx) ? cx : 24;
4751 infoPtr->nButtonHeight = (cy) ? cy : 22;
4752 return TRUE;
4756 static LRESULT
4757 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4759 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4761 if (infoPtr == NULL) {
4762 TRACE("Toolbar not initialized yet?????\n");
4763 return FALSE;
4766 /* if setting to current values, ignore */
4767 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4768 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4769 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4770 infoPtr->cxMin, infoPtr->cxMax);
4771 return TRUE;
4774 /* save new values */
4775 infoPtr->cxMin = (INT)LOWORD(lParam);
4776 infoPtr->cxMax = (INT)HIWORD(lParam);
4778 /* if both values are 0 then we are done */
4779 if (lParam == 0) {
4780 TRACE("setting both min and max to 0, norecalc\n");
4781 return TRUE;
4784 /* otherwise we need to recalc the toolbar and in some cases
4785 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4786 which doesn't actually draw - GA). */
4787 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4788 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4790 TOOLBAR_CalcToolbar (hwnd);
4792 InvalidateRect (hwnd, NULL, TRUE);
4794 return TRUE;
4798 static LRESULT
4799 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4801 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4802 INT nIndex = (INT)wParam;
4804 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4805 return FALSE;
4807 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4809 if (infoPtr->hwndToolTip) {
4811 FIXME("change tool tip!\n");
4815 return TRUE;
4819 static LRESULT
4820 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4823 HIMAGELIST himl = (HIMAGELIST)lParam;
4824 HIMAGELIST himlTemp;
4825 INT id = 0;
4827 if (infoPtr->iVersion >= 5)
4828 id = wParam;
4830 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4831 &infoPtr->cimlDis, himl, id);
4833 /* FIXME: redraw ? */
4835 return (LRESULT)himlTemp;
4839 static LRESULT
4840 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4842 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4843 DWORD dwTemp;
4845 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4847 dwTemp = infoPtr->dwDTFlags;
4848 infoPtr->dwDTFlags =
4849 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4851 return (LRESULT)dwTemp;
4854 /* This function differs a bit from what MSDN says it does:
4855 * 1. lParam contains extended style flags to OR with current style
4856 * (MSDN isn't clear on the OR bit)
4857 * 2. wParam appears to contain extended style flags to be reset
4858 * (MSDN says that this parameter is reserved)
4860 static LRESULT
4861 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4864 DWORD dwTemp;
4866 dwTemp = infoPtr->dwExStyle;
4867 infoPtr->dwExStyle &= ~wParam;
4868 infoPtr->dwExStyle |= (DWORD)lParam;
4870 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4872 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4873 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4874 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4876 TOOLBAR_CalcToolbar (hwnd);
4878 TOOLBAR_AutoSize(hwnd);
4880 InvalidateRect(hwnd, NULL, TRUE);
4882 return (LRESULT)dwTemp;
4886 static LRESULT
4887 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4890 HIMAGELIST himlTemp;
4891 HIMAGELIST himl = (HIMAGELIST)lParam;
4892 INT id = 0;
4894 if (infoPtr->iVersion >= 5)
4895 id = wParam;
4897 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4899 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4900 &infoPtr->cimlHot, himl, id);
4902 /* FIXME: redraw ? */
4904 return (LRESULT)himlTemp;
4908 /* Makes previous hot button no longer hot, makes the specified
4909 * button hot and sends appropriate notifications. dwReason is one or
4910 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4911 * NOTE 1: this function does not validate nHit
4912 * NOTE 2: the name of this function is completely made up and
4913 * not based on any documentation from Microsoft. */
4914 static void
4915 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4917 if (infoPtr->nHotItem != nHit)
4919 NMTBHOTITEM nmhotitem;
4920 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4921 LRESULT no_highlight;
4923 /* Remove the effect of an old hot button if the button was
4924 drawn with the hot button effect */
4925 if(infoPtr->nHotItem >= 0)
4927 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4928 oldBtnPtr->bHot = FALSE;
4931 infoPtr->nHotItem = nHit;
4933 /* It's not a separator or in nowhere. It's a hot button. */
4934 if (nHit >= 0)
4935 btnPtr = &infoPtr->buttons[nHit];
4937 nmhotitem.dwFlags = dwReason;
4938 if (oldBtnPtr)
4939 nmhotitem.idOld = oldBtnPtr->idCommand;
4940 else
4941 nmhotitem.dwFlags |= HICF_ENTERING;
4942 if (btnPtr)
4943 nmhotitem.idNew = btnPtr->idCommand;
4944 else
4945 nmhotitem.dwFlags |= HICF_LEAVING;
4947 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4949 /* now invalidate the old and new buttons so they will be painted */
4950 if (oldBtnPtr)
4951 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4952 if (btnPtr && !no_highlight)
4954 btnPtr->bHot = TRUE;
4955 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4960 static LRESULT
4961 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4963 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4964 INT nOldHotItem = infoPtr->nHotItem;
4966 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4968 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4969 wParam = -1;
4971 /* NOTE: an application can still remove the hot item even if anchor
4972 * highlighting is enabled */
4974 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4975 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4977 if (nOldHotItem < 0)
4978 return -1;
4980 return (LRESULT)nOldHotItem;
4984 static LRESULT
4985 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4988 HIMAGELIST himlTemp;
4989 HIMAGELIST himl = (HIMAGELIST)lParam;
4990 INT i, id = 0;
4992 if (infoPtr->iVersion >= 5)
4993 id = wParam;
4995 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4996 &infoPtr->cimlDef, himl, id);
4998 infoPtr->nNumBitmaps = 0;
4999 for (i = 0; i < infoPtr->cimlDef; i++)
5000 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5002 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5003 &infoPtr->nBitmapHeight);
5004 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
5005 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
5006 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5008 InvalidateRect(hwnd, NULL, TRUE);
5010 return (LRESULT)himlTemp;
5014 static LRESULT
5015 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5017 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5019 infoPtr->nIndent = (INT)wParam;
5021 TRACE("\n");
5023 /* process only on indent changing */
5024 if(infoPtr->nIndent != (INT)wParam)
5026 infoPtr->nIndent = (INT)wParam;
5027 TOOLBAR_CalcToolbar (hwnd);
5028 InvalidateRect(hwnd, NULL, FALSE);
5031 return TRUE;
5035 static LRESULT
5036 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5038 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5039 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5041 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5043 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5045 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5046 return 0;
5049 if ((lptbim->iButton == -1) ||
5050 ((lptbim->iButton < infoPtr->nNumButtons) &&
5051 (lptbim->iButton >= 0)))
5053 infoPtr->tbim = *lptbim;
5054 /* FIXME: don't need to update entire toolbar */
5055 InvalidateRect(hwnd, NULL, TRUE);
5057 else
5058 ERR("Invalid button index %d\n", lptbim->iButton);
5060 return 0;
5064 static LRESULT
5065 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5069 infoPtr->clrInsertMark = (COLORREF)lParam;
5071 /* FIXME: don't need to update entire toolbar */
5072 InvalidateRect(hwnd, NULL, TRUE);
5074 return 0;
5078 static LRESULT
5079 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5083 if (infoPtr == NULL)
5084 return FALSE;
5086 infoPtr->nMaxTextRows = (INT)wParam;
5088 TOOLBAR_CalcToolbar(hwnd);
5089 return TRUE;
5093 /* MSDN gives slightly wrong info on padding.
5094 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5095 * 2. It is not used to create a blank area between the edge of the button
5096 * and the text or image if TBSTYLE_LIST is set. It is used to control
5097 * the gap between the image and text.
5098 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5099 * to control the bottom and right borders [with the border being
5100 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5101 * is shared evenly on both sides of the button.
5103 static LRESULT
5104 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5107 DWORD oldPad;
5109 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5110 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
5111 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
5112 TRACE("cx=%ld, cy=%ld\n",
5113 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5114 return (LRESULT) oldPad;
5118 static LRESULT
5119 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5121 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5122 HWND hwndOldNotify;
5124 TRACE("\n");
5126 if (infoPtr == NULL)
5127 return 0;
5128 hwndOldNotify = infoPtr->hwndNotify;
5129 infoPtr->hwndNotify = (HWND)wParam;
5131 return (LRESULT)hwndOldNotify;
5135 static LRESULT
5136 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5139 LPRECT lprc = (LPRECT)lParam;
5141 TRACE("\n");
5143 if (LOWORD(wParam) > 1) {
5144 FIXME("multiple rows not supported!\n");
5147 if(infoPtr->nRows != LOWORD(wParam))
5149 infoPtr->nRows = LOWORD(wParam);
5151 /* recalculate toolbar */
5152 TOOLBAR_CalcToolbar (hwnd);
5154 /* repaint toolbar */
5155 InvalidateRect(hwnd, NULL, TRUE);
5158 /* return bounding rectangle */
5159 if (lprc) {
5160 lprc->left = infoPtr->rcBound.left;
5161 lprc->right = infoPtr->rcBound.right;
5162 lprc->top = infoPtr->rcBound.top;
5163 lprc->bottom = infoPtr->rcBound.bottom;
5166 return 0;
5170 static LRESULT
5171 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5174 TBUTTON_INFO *btnPtr;
5175 INT nIndex;
5177 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5178 if (nIndex == -1)
5179 return FALSE;
5181 btnPtr = &infoPtr->buttons[nIndex];
5183 /* if hidden state has changed the invalidate entire window and recalc */
5184 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5185 btnPtr->fsState = LOWORD(lParam);
5186 TOOLBAR_CalcToolbar (hwnd);
5187 InvalidateRect(hwnd, 0, TRUE);
5188 return TRUE;
5191 /* process state changing if current state doesn't match new state */
5192 if(btnPtr->fsState != LOWORD(lParam))
5194 btnPtr->fsState = LOWORD(lParam);
5195 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5198 return TRUE;
5202 static LRESULT
5203 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5205 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5207 return TRUE;
5211 inline static LRESULT
5212 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5216 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5218 if (infoPtr == NULL)
5219 return 0;
5220 infoPtr->hwndToolTip = (HWND)wParam;
5221 return 0;
5225 static LRESULT
5226 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5229 BOOL bTemp;
5231 TRACE("%s hwnd=%p\n",
5232 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5234 bTemp = infoPtr->bUnicode;
5235 infoPtr->bUnicode = (BOOL)wParam;
5237 return bTemp;
5241 static LRESULT
5242 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5244 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5246 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5247 comctl32_color.clrBtnHighlight :
5248 infoPtr->clrBtnHighlight;
5249 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5250 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5251 return 1;
5255 static LRESULT
5256 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5260 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5261 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5262 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5264 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5265 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5266 InvalidateRect(hwnd, NULL, TRUE);
5267 return 0;
5271 static LRESULT
5272 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5275 INT iOldVersion = infoPtr->iVersion;
5277 infoPtr->iVersion = iVersion;
5279 if (infoPtr->iVersion >= 5)
5280 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5282 return iOldVersion;
5286 static LRESULT
5287 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5290 WORD iString = HIWORD(wParam);
5291 WORD buffersize = LOWORD(wParam);
5292 LPSTR str = (LPSTR)lParam;
5293 LRESULT ret = -1;
5295 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5297 if (iString < infoPtr->nNumStrings)
5299 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5301 TRACE("returning %s\n", debugstr_a(str));
5303 else
5304 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5306 return ret;
5310 static LRESULT
5311 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5314 WORD iString = HIWORD(wParam);
5315 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5316 LPWSTR str = (LPWSTR)lParam;
5317 LRESULT ret = -1;
5319 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5321 if (iString < infoPtr->nNumStrings)
5323 len = min(len, strlenW(infoPtr->strings[iString]));
5324 ret = (len+1)*sizeof(WCHAR);
5325 memcpy(str, infoPtr->strings[iString], ret);
5326 str[len] = '\0';
5328 TRACE("returning %s\n", debugstr_w(str));
5330 else
5331 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5333 return ret;
5336 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5337 * is the maximum size of the toolbar? */
5338 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5340 SIZE * pSize = (SIZE*)lParam;
5341 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5342 return 0;
5346 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5347 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5348 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5349 * sends). */
5350 static LRESULT
5351 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5354 INT nOldHotItem = infoPtr->nHotItem;
5356 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5357 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5359 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5360 wParam = -1;
5362 /* NOTE: an application can still remove the hot item even if anchor
5363 * highlighting is enabled */
5365 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5367 GetFocus();
5369 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5372 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5373 * which controls the amount of spacing between the image and the text
5374 * of buttons for TBSTYLE_LIST toolbars. */
5375 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5379 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5381 if (lParam != 0)
5382 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5384 infoPtr->iListGap = (INT)wParam;
5386 InvalidateRect(hwnd, NULL, TRUE);
5388 return 0;
5391 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5392 * of image lists associated with the various states. */
5393 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5397 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5399 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5402 static LRESULT
5403 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5405 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5406 LPSIZE lpsize = (LPSIZE)lParam;
5408 if (lpsize == NULL)
5409 return FALSE;
5412 * Testing shows the following:
5413 * wParam = 0 adjust cx value
5414 * = 1 set cy value to max size.
5415 * lParam pointer to SIZE structure
5418 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5419 wParam, lParam, lpsize->cx, lpsize->cy);
5421 switch(wParam) {
5422 case 0:
5423 if (lpsize->cx == -1) {
5424 /* **** this is wrong, native measures each button and sets it */
5425 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5427 else if(HIWORD(lpsize->cx)) {
5428 RECT rc;
5429 HWND hwndParent = GetParent(hwnd);
5431 GetWindowRect(hwnd, &rc);
5432 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5433 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5434 rc.left, rc.top, rc.right, rc.bottom);
5435 lpsize->cx = max(rc.right-rc.left,
5436 infoPtr->rcBound.right - infoPtr->rcBound.left);
5438 else {
5439 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5441 break;
5442 case 1:
5443 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5444 /* lpsize->cy = infoPtr->nHeight; */
5445 break;
5446 default:
5447 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5448 wParam);
5449 return 0;
5451 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5452 lpsize->cx, lpsize->cy);
5453 return 1;
5456 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5458 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5460 InvalidateRect(hwnd, NULL, TRUE);
5461 return 1;
5465 static LRESULT
5466 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5469 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5470 LOGFONTA logFont;
5472 TRACE("hwnd = %p\n", hwnd);
5474 /* initialize info structure */
5475 infoPtr->nButtonHeight = 22;
5476 infoPtr->nButtonWidth = 24;
5477 infoPtr->nBitmapHeight = 15;
5478 infoPtr->nBitmapWidth = 16;
5480 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5481 infoPtr->nMaxTextRows = 1;
5482 infoPtr->cxMin = -1;
5483 infoPtr->cxMax = -1;
5484 infoPtr->nNumBitmaps = 0;
5485 infoPtr->nNumStrings = 0;
5487 infoPtr->bCaptured = FALSE;
5488 infoPtr->nButtonDown = -1;
5489 infoPtr->nButtonDrag = -1;
5490 infoPtr->nOldHit = -1;
5491 infoPtr->nHotItem = -1;
5492 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5493 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5494 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5495 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5496 infoPtr->bDragOutSent = FALSE;
5497 infoPtr->iVersion = 0;
5498 infoPtr->hwndSelf = hwnd;
5499 infoPtr->bDoRedraw = TRUE;
5500 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5501 infoPtr->clrBtnShadow = CLR_DEFAULT;
5502 /* not sure where the +1 comes from, but this comes to the same value
5503 * as native so this is probably correct */
5504 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5505 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5506 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5507 infoPtr->dwStyle = dwStyle;
5508 infoPtr->tbim.iButton = -1;
5509 GetClientRect(hwnd, &infoPtr->client_rect);
5510 infoPtr->bUnicode = infoPtr->hwndNotify &&
5511 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5513 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5514 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5516 if (dwStyle & TBSTYLE_TOOLTIPS) {
5517 /* Create tooltip control */
5518 infoPtr->hwndToolTip =
5519 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5520 CW_USEDEFAULT, CW_USEDEFAULT,
5521 CW_USEDEFAULT, CW_USEDEFAULT,
5522 hwnd, 0, 0, 0);
5524 /* Send NM_TOOLTIPSCREATED notification */
5525 if (infoPtr->hwndToolTip) {
5526 NMTOOLTIPSCREATED nmttc;
5528 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5530 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5531 NM_TOOLTIPSCREATED);
5535 TOOLBAR_CheckStyle (hwnd, dwStyle);
5537 TOOLBAR_CalcToolbar(hwnd);
5539 return 0;
5543 static LRESULT
5544 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5548 /* delete tooltip control */
5549 if (infoPtr->hwndToolTip)
5550 DestroyWindow (infoPtr->hwndToolTip);
5552 /* delete temporary buffer for tooltip text */
5553 if (infoPtr->pszTooltipText)
5554 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5556 /* delete button data */
5557 if (infoPtr->buttons)
5558 Free (infoPtr->buttons);
5560 /* delete strings */
5561 if (infoPtr->strings) {
5562 INT i;
5563 for (i = 0; i < infoPtr->nNumStrings; i++)
5564 if (infoPtr->strings[i])
5565 Free (infoPtr->strings[i]);
5567 Free (infoPtr->strings);
5570 /* destroy internal image list */
5571 if (infoPtr->himlInt)
5572 ImageList_Destroy (infoPtr->himlInt);
5574 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5575 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5576 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5578 /* delete default font */
5579 if (infoPtr->hFont)
5580 DeleteObject (infoPtr->hDefaultFont);
5582 /* free toolbar info data */
5583 Free (infoPtr);
5584 SetWindowLongPtrW (hwnd, 0, 0);
5586 return 0;
5590 static LRESULT
5591 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5594 NMTBCUSTOMDRAW tbcd;
5595 INT ret = FALSE;
5596 DWORD ntfret;
5598 /* the app has told us not to redraw the toolbar */
5599 if (!infoPtr->bDoRedraw)
5600 return FALSE;
5602 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5603 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5604 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5605 tbcd.nmcd.hdc = (HDC)wParam;
5606 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5607 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5609 /* FIXME: in general the return flags *can* be or'ed together */
5610 switch (infoPtr->dwBaseCustDraw)
5612 case CDRF_DODEFAULT:
5613 break;
5614 case CDRF_SKIPDEFAULT:
5615 return TRUE;
5616 default:
5617 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5618 hwnd, ntfret);
5622 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5623 * to my parent for processing.
5625 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5626 POINT pt, ptorig;
5627 HDC hdc = (HDC)wParam;
5628 HWND parent;
5630 pt.x = 0;
5631 pt.y = 0;
5632 parent = GetParent(hwnd);
5633 MapWindowPoints(hwnd, parent, &pt, 1);
5634 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5635 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5636 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5638 if (!ret)
5639 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5641 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5642 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5643 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5644 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5645 tbcd.nmcd.hdc = (HDC)wParam;
5646 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5647 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5648 switch (infoPtr->dwBaseCustDraw)
5650 case CDRF_DODEFAULT:
5651 break;
5652 case CDRF_SKIPDEFAULT:
5653 return TRUE;
5654 default:
5655 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5656 hwnd, ntfret);
5659 return ret;
5663 static LRESULT
5664 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5668 return (LRESULT)infoPtr->hFont;
5672 static LRESULT
5673 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5675 POINT pt;
5676 INT nHit;
5678 pt.x = (INT)LOWORD(lParam);
5679 pt.y = (INT)HIWORD(lParam);
5680 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5682 if (nHit >= 0)
5683 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5684 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5685 TOOLBAR_Customize (hwnd);
5687 return 0;
5691 static LRESULT
5692 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5695 TBUTTON_INFO *btnPtr;
5696 POINT pt;
5697 INT nHit;
5698 NMTOOLBARA nmtb;
5699 NMMOUSE nmmouse;
5700 BOOL bDragKeyPressed;
5702 TRACE("\n");
5704 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5705 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5706 else
5707 bDragKeyPressed = (wParam & MK_SHIFT);
5709 if (infoPtr->hwndToolTip)
5710 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5711 WM_LBUTTONDOWN, wParam, lParam);
5713 pt.x = (INT)LOWORD(lParam);
5714 pt.y = (INT)HIWORD(lParam);
5715 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5717 btnPtr = &infoPtr->buttons[nHit];
5719 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5721 infoPtr->nButtonDrag = nHit;
5722 SetCapture (hwnd);
5724 /* If drag cursor has not been loaded, load it.
5725 * Note: it doesn't need to be freed */
5726 if (!hCursorDrag)
5727 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5728 SetCursor(hCursorDrag);
5730 else if (nHit >= 0)
5732 RECT arrowRect;
5733 infoPtr->nOldHit = nHit;
5735 CopyRect(&arrowRect, &btnPtr->rect);
5736 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5738 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5739 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5740 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5741 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5742 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5743 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5745 LRESULT res;
5747 /* draw in pressed state */
5748 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5749 btnPtr->fsState |= TBSTATE_PRESSED;
5750 else
5751 btnPtr->bDropDownPressed = TRUE;
5752 RedrawWindow(hwnd,&btnPtr->rect,0,
5753 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5755 memset(&nmtb, 0, sizeof(nmtb));
5756 nmtb.iItem = btnPtr->idCommand;
5757 nmtb.rcButton = btnPtr->rect;
5758 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5759 TBN_DROPDOWN);
5760 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5762 if (res != TBDDRET_TREATPRESSED)
5764 MSG msg;
5766 /* redraw button in unpressed state */
5767 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5768 btnPtr->fsState &= ~TBSTATE_PRESSED;
5769 else
5770 btnPtr->bDropDownPressed = FALSE;
5771 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5773 /* find and set hot item
5774 * NOTE: native doesn't do this, but that is a bug */
5775 GetCursorPos(&pt);
5776 ScreenToClient(hwnd, &pt);
5777 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5778 if (!infoPtr->bAnchor || (nHit >= 0))
5779 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5781 /* remove any left mouse button down or double-click messages
5782 * so that we can get a toggle effect on the button */
5783 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5784 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5787 return 0;
5789 /* otherwise drop through and process as pushed */
5791 infoPtr->bCaptured = TRUE;
5792 infoPtr->nButtonDown = nHit;
5793 infoPtr->bDragOutSent = FALSE;
5795 btnPtr->fsState |= TBSTATE_PRESSED;
5797 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5799 if (btnPtr->fsState & TBSTATE_ENABLED)
5800 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5801 UpdateWindow(hwnd);
5802 SetCapture (hwnd);
5805 if (nHit >=0)
5807 memset(&nmtb, 0, sizeof(nmtb));
5808 nmtb.iItem = btnPtr->idCommand;
5809 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5812 nmmouse.dwHitInfo = nHit;
5814 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5815 if (nHit < 0)
5816 nmmouse.dwItemSpec = -1;
5817 else
5819 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5820 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5823 ClientToScreen(hwnd, &pt);
5824 nmmouse.pt = pt;
5826 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_LDOWN))
5827 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5829 return 0;
5832 static LRESULT
5833 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5836 TBUTTON_INFO *btnPtr;
5837 POINT pt;
5838 INT nHit;
5839 INT nOldIndex = -1;
5840 BOOL bSendMessage = TRUE;
5841 NMHDR hdr;
5842 NMMOUSE nmmouse;
5843 NMTOOLBARA nmtb;
5845 if (infoPtr->hwndToolTip)
5846 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5847 WM_LBUTTONUP, wParam, lParam);
5849 pt.x = (INT)LOWORD(lParam);
5850 pt.y = (INT)HIWORD(lParam);
5851 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5853 if (!infoPtr->bAnchor || (nHit >= 0))
5854 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5856 if (infoPtr->nButtonDrag >= 0) {
5857 RECT rcClient;
5858 NMHDR hdr;
5860 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5861 ReleaseCapture();
5862 /* reset cursor */
5863 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5865 GetClientRect(hwnd, &rcClient);
5866 if (PtInRect(&rcClient, pt))
5868 INT nButton = -1;
5869 if (nHit >= 0)
5870 nButton = nHit;
5871 else if (nHit < -1)
5872 nButton = -nHit;
5873 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5874 nButton = -nHit;
5876 if (nButton == infoPtr->nButtonDrag)
5878 /* if the button is moved sightly left and we have a
5879 * separator there then remove it */
5880 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5882 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5883 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5885 else /* else insert a separator before the dragged button */
5887 TBBUTTON tbb;
5888 memset(&tbb, 0, sizeof(tbb));
5889 tbb.fsStyle = BTNS_SEP;
5890 tbb.iString = -1;
5891 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5894 else
5896 if (nButton == -1)
5898 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5899 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5900 else
5901 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5903 else
5904 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5907 else
5909 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5910 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5913 /* button under cursor changed so need to re-set hot item */
5914 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5915 infoPtr->nButtonDrag = -1;
5917 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5919 else if (infoPtr->nButtonDown >= 0) {
5920 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5921 btnPtr->fsState &= ~TBSTATE_PRESSED;
5923 if (btnPtr->fsStyle & BTNS_CHECK) {
5924 if (btnPtr->fsStyle & BTNS_GROUP) {
5925 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5926 nHit);
5927 if (nOldIndex == nHit)
5928 bSendMessage = FALSE;
5929 if ((nOldIndex != nHit) &&
5930 (nOldIndex != -1))
5931 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5932 btnPtr->fsState |= TBSTATE_CHECKED;
5934 else {
5935 if (btnPtr->fsState & TBSTATE_CHECKED)
5936 btnPtr->fsState &= ~TBSTATE_CHECKED;
5937 else
5938 btnPtr->fsState |= TBSTATE_CHECKED;
5942 if (nOldIndex != -1)
5943 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5946 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5947 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5948 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5950 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5951 ReleaseCapture ();
5952 infoPtr->nButtonDown = -1;
5954 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5955 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5956 NM_RELEASEDCAPTURE);
5958 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5959 * TBN_BEGINDRAG
5961 memset(&nmtb, 0, sizeof(nmtb));
5962 nmtb.iItem = btnPtr->idCommand;
5963 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5964 TBN_ENDDRAG);
5966 if (btnPtr->fsState & TBSTATE_ENABLED)
5968 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5969 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5973 /* !!! Undocumented - toolbar at 4.71 level and above sends
5974 * NM_CLICK with the NMMOUSE structure. */
5975 nmmouse.dwHitInfo = nHit;
5977 if (nmmouse.dwHitInfo < 0)
5978 nmmouse.dwItemSpec = -1;
5979 else
5981 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5982 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5985 ClientToScreen(hwnd, &pt);
5986 nmmouse.pt = pt;
5988 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5989 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5991 return 0;
5994 static LRESULT
5995 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5998 INT nHit;
5999 NMMOUSE nmmouse;
6000 POINT pt;
6002 pt.x = LOWORD(lParam);
6003 pt.y = HIWORD(lParam);
6005 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6006 nmmouse.dwHitInfo = nHit;
6008 if (nHit < 0) {
6009 nmmouse.dwItemSpec = -1;
6010 } else {
6011 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6012 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6015 ClientToScreen(hwnd, &pt);
6016 nmmouse.pt = pt;
6018 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6019 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6021 return 0;
6024 static LRESULT
6025 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6027 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6028 NMHDR nmhdr;
6030 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6031 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6033 return 0;
6036 static LRESULT
6037 TOOLBAR_CaptureChanged(HWND hwnd)
6039 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6040 TBUTTON_INFO *btnPtr;
6042 infoPtr->bCaptured = FALSE;
6044 if (infoPtr->nButtonDown >= 0)
6046 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6047 btnPtr->fsState &= ~TBSTATE_PRESSED;
6049 infoPtr->nOldHit = -1;
6051 if (btnPtr->fsState & TBSTATE_ENABLED)
6052 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6054 return 0;
6057 static LRESULT
6058 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6060 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6061 TBUTTON_INFO *hotBtnPtr;
6063 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6065 /* don't remove hot effects when in anchor highlighting mode or when a
6066 * drop-down button is pressed */
6067 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6068 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6070 if (infoPtr->nOldHit < 0)
6071 return TRUE;
6073 /* If the last button we were over is depressed then make it not */
6074 /* depressed and redraw it */
6075 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6077 TBUTTON_INFO *btnPtr;
6078 RECT rc1;
6080 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6082 btnPtr->fsState &= ~TBSTATE_PRESSED;
6084 rc1 = hotBtnPtr->rect;
6085 InflateRect (&rc1, 1, 1);
6086 InvalidateRect (hwnd, &rc1, TRUE);
6089 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6091 NMTOOLBARW nmt;
6092 ZeroMemory(&nmt, sizeof(nmt));
6093 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6094 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6095 infoPtr->bDragOutSent = TRUE;
6098 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6100 return TRUE;
6103 static LRESULT
6104 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6107 POINT pt;
6108 TRACKMOUSEEVENT trackinfo;
6109 INT nHit;
6110 TBUTTON_INFO *btnPtr;
6112 /* fill in the TRACKMOUSEEVENT struct */
6113 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6114 trackinfo.dwFlags = TME_QUERY;
6115 trackinfo.hwndTrack = hwnd;
6116 trackinfo.dwHoverTime = HOVER_DEFAULT;
6118 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6119 _TrackMouseEvent(&trackinfo);
6121 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6122 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6123 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6125 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6126 /* and can properly deactivate the hot toolbar button */
6127 _TrackMouseEvent(&trackinfo);
6130 if (infoPtr->hwndToolTip)
6131 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6132 WM_MOUSEMOVE, wParam, lParam);
6134 pt.x = (INT)LOWORD(lParam);
6135 pt.y = (INT)HIWORD(lParam);
6137 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6139 if (!infoPtr->bAnchor || (nHit >= 0))
6140 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6142 if (infoPtr->nOldHit != nHit)
6144 if (infoPtr->bCaptured)
6146 if (!infoPtr->bDragOutSent)
6148 NMTOOLBARW nmt;
6149 ZeroMemory(&nmt, sizeof(nmt));
6150 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6151 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6152 infoPtr->bDragOutSent = TRUE;
6155 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6156 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6157 btnPtr->fsState &= ~TBSTATE_PRESSED;
6158 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6160 else if (nHit == infoPtr->nButtonDown) {
6161 btnPtr->fsState |= TBSTATE_PRESSED;
6162 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6164 infoPtr->nOldHit = nHit;
6168 return 0;
6172 inline static LRESULT
6173 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6175 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6176 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6177 /* else */
6178 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6182 inline static LRESULT
6183 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6185 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6186 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6188 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6192 static LRESULT
6193 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6195 TOOLBAR_INFO *infoPtr;
6196 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6197 DWORD styleadd = 0;
6199 /* allocate memory for info structure */
6200 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6201 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6203 /* paranoid!! */
6204 infoPtr->dwStructSize = sizeof(TBBUTTON);
6205 infoPtr->nRows = 1;
6207 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6208 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6209 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6210 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6213 /* native control does:
6214 * Get a lot of colors and brushes
6215 * WM_NOTIFYFORMAT
6216 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
6217 * CreateFontIndirectA(adr1)
6218 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6219 * hdc = GetDC(toolbar)
6220 * GetSystemMetrics(0x48)
6221 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6222 * 0, 0, 0, 0, "MARLETT")
6223 * oldfnt = SelectObject(hdc, fnt2)
6224 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
6225 * GetTextMetricsA(hdc, adr3)
6226 * SelectObject(hdc, oldfnt)
6227 * DeleteObject(fnt2)
6228 * ReleaseDC(hdc)
6229 * InvalidateRect(toolbar, 0, 1)
6230 * SetWindowLongA(toolbar, 0, addr)
6231 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
6232 * WM_STYLECHANGING
6233 * CallWinEx old new
6234 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6235 * ie 2 0x4600094c 0x4600094c 0x4600894d
6236 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6237 * rebar 0x50008844 0x40008844 0x50008845
6238 * pager 0x50000844 0x40000844 0x50008845
6239 * IC35mgr 0x5400084e **nochange**
6240 * on entry to _NCCREATE 0x5400084e
6241 * rowlist 0x5400004e **nochange**
6242 * on entry to _NCCREATE 0x5400004e
6246 /* I think the code below is a bug, but it is the way that the native
6247 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6248 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6249 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6250 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6251 * Some how, the only cases of this seem to be MFC programs.
6253 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6254 * does not occur in the WM_STYLECHANGING routine.
6255 * (Guy Albertelli 9/2001)
6258 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6259 styleadd |= TBSTYLE_TRANSPARENT;
6260 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6261 styleadd |= CCS_TOP; /* default to top */
6262 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6265 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6269 static LRESULT
6270 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6272 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6273 RECT rcWindow;
6274 HDC hdc;
6276 if (dwStyle & WS_MINIMIZE)
6277 return 0; /* Nothing to do */
6279 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6281 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6282 return 0;
6284 if (!(dwStyle & CCS_NODIVIDER))
6286 GetWindowRect (hwnd, &rcWindow);
6287 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6288 if( dwStyle & WS_BORDER )
6289 OffsetRect (&rcWindow, 1, 1);
6290 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6293 ReleaseDC( hwnd, hdc );
6295 return 0;
6299 /* handles requests from the tooltip control on what text to display */
6300 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6302 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6304 TRACE("button index = %d\n", index);
6306 if (infoPtr->pszTooltipText)
6308 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6309 infoPtr->pszTooltipText = NULL;
6312 if (index < 0)
6313 return 0;
6315 if (infoPtr->bNtfUnicode)
6317 WCHAR wszBuffer[INFOTIPSIZE+1];
6318 NMTBGETINFOTIPW tbgit;
6319 unsigned int len; /* in chars */
6321 wszBuffer[0] = '\0';
6322 wszBuffer[INFOTIPSIZE] = '\0';
6324 tbgit.pszText = wszBuffer;
6325 tbgit.cchTextMax = INFOTIPSIZE;
6326 tbgit.iItem = lpnmtdi->hdr.idFrom;
6327 tbgit.lParam = infoPtr->buttons[index].dwData;
6329 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6331 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6333 len = strlenW(tbgit.pszText);
6334 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6336 /* need to allocate temporary buffer in infoPtr as there
6337 * isn't enough space in buffer passed to us by the
6338 * tooltip control */
6339 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6340 if (infoPtr->pszTooltipText)
6342 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6343 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6344 return 0;
6347 else if (len > 0)
6349 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6350 return 0;
6353 else
6355 CHAR szBuffer[INFOTIPSIZE+1];
6356 NMTBGETINFOTIPA tbgit;
6357 unsigned int len; /* in chars */
6359 szBuffer[0] = '\0';
6360 szBuffer[INFOTIPSIZE] = '\0';
6362 tbgit.pszText = szBuffer;
6363 tbgit.cchTextMax = INFOTIPSIZE;
6364 tbgit.iItem = lpnmtdi->hdr.idFrom;
6365 tbgit.lParam = infoPtr->buttons[index].dwData;
6367 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6369 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6371 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6372 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6374 /* need to allocate temporary buffer in infoPtr as there
6375 * isn't enough space in buffer passed to us by the
6376 * tooltip control */
6377 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6378 if (infoPtr->pszTooltipText)
6380 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6381 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6382 return 0;
6385 else if (len > 0)
6387 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6388 return 0;
6392 /* if button has text, but it is not shown then automatically
6393 * use that text as tooltip */
6394 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6395 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6397 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6398 unsigned int len = pszText ? strlenW(pszText) : 0;
6400 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6402 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6404 /* need to allocate temporary buffer in infoPtr as there
6405 * isn't enough space in buffer passed to us by the
6406 * tooltip control */
6407 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6408 if (infoPtr->pszTooltipText)
6410 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6411 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6412 return 0;
6415 else if (len > 0)
6417 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6418 return 0;
6422 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6424 /* last resort: send notification on to app */
6425 /* FIXME: find out what is really used here */
6426 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6430 inline static LRESULT
6431 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6434 LPNMHDR lpnmh = (LPNMHDR)lParam;
6436 switch (lpnmh->code)
6438 case PGN_CALCSIZE:
6440 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6442 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6443 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6444 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6445 lppgc->iWidth);
6447 else {
6448 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6449 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6450 lppgc->iHeight);
6452 return 0;
6455 case PGN_SCROLL:
6457 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6459 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6460 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6461 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6462 lppgs->iScroll, lppgs->iDir);
6463 return 0;
6466 case TTN_GETDISPINFOW:
6467 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6469 case TTN_GETDISPINFOA:
6470 FIXME("TTN_GETDISPINFOA - stub\n");
6471 return 0;
6473 default:
6474 return 0;
6479 static LRESULT
6480 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6482 /* remove this routine when Toolbar is improved to pass infoPtr
6483 * around instead of hwnd.
6485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6486 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6490 static LRESULT
6491 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6493 LRESULT format;
6495 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6497 if (lParam == NF_QUERY)
6498 return NFR_UNICODE;
6500 if (lParam == NF_REQUERY) {
6501 format = SendMessageW(infoPtr->hwndNotify,
6502 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6503 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6504 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6505 format);
6506 format = NFR_ANSI;
6508 return format;
6510 return 0;
6514 static LRESULT
6515 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6517 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6518 HDC hdc;
6519 PAINTSTRUCT ps;
6521 /* fill ps.rcPaint with a default rect */
6522 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6524 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6526 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6527 ps.rcPaint.left, ps.rcPaint.top,
6528 ps.rcPaint.right, ps.rcPaint.bottom);
6530 TOOLBAR_Refresh (hwnd, hdc, &ps);
6531 if (!wParam) EndPaint (hwnd, &ps);
6533 return 0;
6537 static LRESULT
6538 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6539 /*****************************************************
6541 * Function;
6542 * Handles the WM_SETREDRAW message.
6544 * Documentation:
6545 * According to testing V4.71 of COMCTL32 returns the
6546 * *previous* status of the redraw flag (either 0 or 1)
6547 * instead of the MSDN documented value of 0 if handled.
6548 * (For laughs see the "consistency" with same function
6549 * in rebar.)
6551 *****************************************************/
6553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6554 BOOL oldredraw = infoPtr->bDoRedraw;
6556 TRACE("set to %s\n",
6557 (wParam) ? "TRUE" : "FALSE");
6558 infoPtr->bDoRedraw = (BOOL) wParam;
6559 if (wParam) {
6560 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6562 return (oldredraw) ? 1 : 0;
6566 static LRESULT
6567 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6570 DWORD dwStyle = infoPtr->dwStyle;
6571 RECT parent_rect;
6572 RECT window_rect;
6573 HWND parent;
6574 INT x, y;
6575 INT cx, cy;
6576 INT flags;
6577 UINT uPosFlags = 0;
6579 /* Resize deadlock check */
6580 if (infoPtr->bAutoSize) {
6581 infoPtr->bAutoSize = FALSE;
6582 return 0;
6585 /* FIXME: optimize to only update size if the new size doesn't */
6586 /* match the current size */
6588 flags = (INT) wParam;
6590 /* FIXME for flags =
6591 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6594 TRACE("sizing toolbar!\n");
6596 if (flags == SIZE_RESTORED) {
6597 /* width and height don't apply */
6598 parent = GetParent (hwnd);
6599 GetClientRect(parent, &parent_rect);
6600 x = parent_rect.left;
6601 y = parent_rect.top;
6603 if (dwStyle & CCS_NORESIZE) {
6604 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6607 * this sets the working width of the toolbar, and
6608 * Calc Toolbar will not adjust it, only the height
6610 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6611 cy = infoPtr->nHeight;
6612 cx = infoPtr->nWidth;
6613 TOOLBAR_CalcToolbar (hwnd);
6614 infoPtr->nWidth = cx;
6615 infoPtr->nHeight = cy;
6617 else {
6618 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6619 TOOLBAR_CalcToolbar (hwnd);
6620 cy = infoPtr->nHeight;
6621 cx = infoPtr->nWidth;
6623 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6624 GetWindowRect(hwnd, &window_rect);
6625 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6626 y = window_rect.top;
6628 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6629 GetWindowRect(hwnd, &window_rect);
6630 y = parent_rect.bottom -
6631 ( window_rect.bottom - window_rect.top);
6635 if (dwStyle & CCS_NOPARENTALIGN) {
6636 uPosFlags |= SWP_NOMOVE;
6637 cy = infoPtr->nHeight;
6638 cx = infoPtr->nWidth;
6641 if (!(dwStyle & CCS_NODIVIDER))
6642 cy += GetSystemMetrics(SM_CYEDGE);
6644 if (dwStyle & WS_BORDER)
6646 x = y = 1;
6647 cy += GetSystemMetrics(SM_CYEDGE);
6648 cx += GetSystemMetrics(SM_CYEDGE);
6651 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6653 RECT delta_width, delta_height, client, dummy;
6654 DWORD min_x, max_x, min_y, max_y;
6655 TBUTTON_INFO *btnPtr;
6656 INT i;
6658 GetClientRect(hwnd, &client);
6659 if(client.right > infoPtr->client_rect.right)
6661 min_x = infoPtr->client_rect.right;
6662 max_x = client.right;
6664 else
6666 max_x = infoPtr->client_rect.right;
6667 min_x = client.right;
6669 if(client.bottom > infoPtr->client_rect.bottom)
6671 min_y = infoPtr->client_rect.bottom;
6672 max_y = client.bottom;
6674 else
6676 max_y = infoPtr->client_rect.bottom;
6677 min_y = client.bottom;
6680 SetRect(&delta_width, min_x, 0, max_x, min_y);
6681 SetRect(&delta_height, 0, min_y, max_x, max_y);
6683 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6684 btnPtr = infoPtr->buttons;
6685 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6686 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6687 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6688 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6691 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6692 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6694 GetClientRect(hwnd, &infoPtr->client_rect);
6695 return 0;
6699 static LRESULT
6700 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6704 if (nType == GWL_STYLE) {
6705 if (lpStyle->styleNew & TBSTYLE_LIST) {
6706 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6708 else {
6709 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6711 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6712 (TBSTYLE_FLAT | TBSTYLE_LIST));
6713 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6715 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6717 infoPtr->dwStyle = lpStyle->styleNew;
6720 TOOLBAR_CalcToolbar(hwnd);
6722 TOOLBAR_AutoSize (hwnd);
6724 InvalidateRect(hwnd, NULL, TRUE);
6726 return 0;
6730 static LRESULT
6731 TOOLBAR_SysColorChange (HWND hwnd)
6733 COMCTL32_RefreshSysColors();
6735 return 0;
6740 static LRESULT WINAPI
6741 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6745 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6746 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6748 if (!infoPtr && (uMsg != WM_NCCREATE))
6749 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6751 switch (uMsg)
6753 case TB_ADDBITMAP:
6754 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6756 case TB_ADDBUTTONSA:
6757 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6759 case TB_ADDBUTTONSW:
6760 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6762 case TB_ADDSTRINGA:
6763 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6765 case TB_ADDSTRINGW:
6766 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6768 case TB_AUTOSIZE:
6769 return TOOLBAR_AutoSize (hwnd);
6771 case TB_BUTTONCOUNT:
6772 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6774 case TB_BUTTONSTRUCTSIZE:
6775 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6777 case TB_CHANGEBITMAP:
6778 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6780 case TB_CHECKBUTTON:
6781 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6783 case TB_COMMANDTOINDEX:
6784 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6786 case TB_CUSTOMIZE:
6787 return TOOLBAR_Customize (hwnd);
6789 case TB_DELETEBUTTON:
6790 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6792 case TB_ENABLEBUTTON:
6793 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6795 case TB_GETANCHORHIGHLIGHT:
6796 return TOOLBAR_GetAnchorHighlight (hwnd);
6798 case TB_GETBITMAP:
6799 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6801 case TB_GETBITMAPFLAGS:
6802 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6804 case TB_GETBUTTON:
6805 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6807 case TB_GETBUTTONINFOA:
6808 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6810 case TB_GETBUTTONINFOW:
6811 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6813 case TB_GETBUTTONSIZE:
6814 return TOOLBAR_GetButtonSize (hwnd);
6816 case TB_GETBUTTONTEXTA:
6817 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6819 case TB_GETBUTTONTEXTW:
6820 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6822 case TB_GETDISABLEDIMAGELIST:
6823 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6825 case TB_GETEXTENDEDSTYLE:
6826 return TOOLBAR_GetExtendedStyle (hwnd);
6828 case TB_GETHOTIMAGELIST:
6829 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6831 case TB_GETHOTITEM:
6832 return TOOLBAR_GetHotItem (hwnd);
6834 case TB_GETIMAGELIST:
6835 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6837 case TB_GETINSERTMARK:
6838 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6840 case TB_GETINSERTMARKCOLOR:
6841 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6843 case TB_GETITEMRECT:
6844 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6846 case TB_GETMAXSIZE:
6847 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6849 /* case TB_GETOBJECT: */ /* 4.71 */
6851 case TB_GETPADDING:
6852 return TOOLBAR_GetPadding (hwnd);
6854 case TB_GETRECT:
6855 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6857 case TB_GETROWS:
6858 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6860 case TB_GETSTATE:
6861 return TOOLBAR_GetState (hwnd, wParam, lParam);
6863 case TB_GETSTRINGA:
6864 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6866 case TB_GETSTRINGW:
6867 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6869 case TB_GETSTYLE:
6870 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6872 case TB_GETTEXTROWS:
6873 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6875 case TB_GETTOOLTIPS:
6876 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6878 case TB_GETUNICODEFORMAT:
6879 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6881 case TB_HIDEBUTTON:
6882 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6884 case TB_HITTEST:
6885 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6887 case TB_INDETERMINATE:
6888 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6890 case TB_INSERTBUTTONA:
6891 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6893 case TB_INSERTBUTTONW:
6894 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6896 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6898 case TB_ISBUTTONCHECKED:
6899 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6901 case TB_ISBUTTONENABLED:
6902 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6904 case TB_ISBUTTONHIDDEN:
6905 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6907 case TB_ISBUTTONHIGHLIGHTED:
6908 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6910 case TB_ISBUTTONINDETERMINATE:
6911 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6913 case TB_ISBUTTONPRESSED:
6914 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6916 case TB_LOADIMAGES:
6917 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6919 case TB_MAPACCELERATORA:
6920 case TB_MAPACCELERATORW:
6921 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6923 case TB_MARKBUTTON:
6924 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6926 case TB_MOVEBUTTON:
6927 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6929 case TB_PRESSBUTTON:
6930 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6932 case TB_REPLACEBITMAP:
6933 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6935 case TB_SAVERESTOREA:
6936 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6938 case TB_SAVERESTOREW:
6939 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6941 case TB_SETANCHORHIGHLIGHT:
6942 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6944 case TB_SETBITMAPSIZE:
6945 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6947 case TB_SETBUTTONINFOA:
6948 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6950 case TB_SETBUTTONINFOW:
6951 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6953 case TB_SETBUTTONSIZE:
6954 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6956 case TB_SETBUTTONWIDTH:
6957 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6959 case TB_SETCMDID:
6960 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6962 case TB_SETDISABLEDIMAGELIST:
6963 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6965 case TB_SETDRAWTEXTFLAGS:
6966 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6968 case TB_SETEXTENDEDSTYLE:
6969 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6971 case TB_SETHOTIMAGELIST:
6972 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6974 case TB_SETHOTITEM:
6975 return TOOLBAR_SetHotItem (hwnd, wParam);
6977 case TB_SETIMAGELIST:
6978 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6980 case TB_SETINDENT:
6981 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6983 case TB_SETINSERTMARK:
6984 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6986 case TB_SETINSERTMARKCOLOR:
6987 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6989 case TB_SETMAXTEXTROWS:
6990 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6992 case TB_SETPADDING:
6993 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6995 case TB_SETPARENT:
6996 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6998 case TB_SETROWS:
6999 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7001 case TB_SETSTATE:
7002 return TOOLBAR_SetState (hwnd, wParam, lParam);
7004 case TB_SETSTYLE:
7005 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7007 case TB_SETTOOLTIPS:
7008 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7010 case TB_SETUNICODEFORMAT:
7011 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7013 case TB_UNKWN45D:
7014 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7016 case TB_UNKWN45E:
7017 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7019 case TB_UNKWN460:
7020 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7022 case TB_UNKWN462:
7023 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7025 case TB_UNKWN463:
7026 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7028 case TB_UNKWN464:
7029 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7031 /* Common Control Messages */
7033 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7034 case CCM_GETCOLORSCHEME:
7035 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7037 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7038 case CCM_SETCOLORSCHEME:
7039 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7041 case CCM_GETVERSION:
7042 return TOOLBAR_GetVersion (hwnd);
7044 case CCM_SETVERSION:
7045 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7048 /* case WM_CHAR: */
7050 case WM_CREATE:
7051 return TOOLBAR_Create (hwnd, wParam, lParam);
7053 case WM_DESTROY:
7054 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7056 case WM_ERASEBKGND:
7057 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7059 case WM_GETFONT:
7060 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7062 /* case WM_KEYDOWN: */
7063 /* case WM_KILLFOCUS: */
7065 case WM_LBUTTONDBLCLK:
7066 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7068 case WM_LBUTTONDOWN:
7069 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7071 case WM_LBUTTONUP:
7072 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7074 case WM_RBUTTONUP:
7075 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7077 case WM_RBUTTONDBLCLK:
7078 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7080 case WM_MOUSEMOVE:
7081 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7083 case WM_MOUSELEAVE:
7084 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7086 case WM_CAPTURECHANGED:
7087 return TOOLBAR_CaptureChanged(hwnd);
7089 case WM_NCACTIVATE:
7090 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7092 case WM_NCCALCSIZE:
7093 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7095 case WM_NCCREATE:
7096 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7098 case WM_NCPAINT:
7099 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7101 case WM_NOTIFY:
7102 return TOOLBAR_Notify (hwnd, wParam, lParam);
7104 case WM_NOTIFYFORMAT:
7105 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
7107 case WM_PAINT:
7108 return TOOLBAR_Paint (hwnd, wParam);
7110 case WM_SETREDRAW:
7111 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7113 case WM_SIZE:
7114 return TOOLBAR_Size (hwnd, wParam, lParam);
7116 case WM_STYLECHANGED:
7117 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7119 case WM_SYSCOLORCHANGE:
7120 return TOOLBAR_SysColorChange (hwnd);
7122 /* case WM_WININICHANGE: */
7124 case WM_CHARTOITEM:
7125 case WM_COMMAND:
7126 case WM_DRAWITEM:
7127 case WM_MEASUREITEM:
7128 case WM_VKEYTOITEM:
7129 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7131 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7132 case PGM_FORWARDMOUSE:
7133 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7135 default:
7136 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7137 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7138 uMsg, wParam, lParam);
7139 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7141 return 0;
7145 VOID
7146 TOOLBAR_Register (void)
7148 WNDCLASSW wndClass;
7150 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7151 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7152 wndClass.lpfnWndProc = ToolbarWindowProc;
7153 wndClass.cbClsExtra = 0;
7154 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7155 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7156 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7157 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7159 RegisterClassW (&wndClass);
7163 VOID
7164 TOOLBAR_Unregister (void)
7166 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7169 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7171 HIMAGELIST himlold;
7172 PIMLENTRY c = NULL;
7174 /* Check if the entry already exists */
7175 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7177 /* If this is a new entry we must create it and insert into the array */
7178 if (!c)
7180 PIMLENTRY *pnies;
7182 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7183 c->id = id;
7185 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7186 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7187 pnies[*cies] = c;
7188 (*cies)++;
7190 Free(*pies);
7191 *pies = pnies;
7194 himlold = c->himl;
7195 c->himl = himl;
7197 return himlold;
7201 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7203 int i;
7205 for (i = 0; i < *cies; i++)
7206 Free((*pies)[i]);
7208 Free(*pies);
7210 *cies = 0;
7211 *pies = NULL;
7215 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7217 PIMLENTRY c = NULL;
7219 if (pies != NULL)
7221 int i;
7223 for (i = 0; i < cies; i++)
7225 if (pies[i]->id == id)
7227 c = pies[i];
7228 break;
7233 return c;
7237 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7239 HIMAGELIST himlDef = 0;
7240 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7242 if (pie)
7243 himlDef = pie->himl;
7245 return himlDef;
7249 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7251 if (infoPtr->bUnicode)
7252 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
7253 else
7255 CHAR Buffer[256];
7256 NMTOOLBARA nmtba;
7257 BOOL bRet = FALSE;
7259 nmtba.iItem = nmtb->iItem;
7260 nmtba.pszText = Buffer;
7261 nmtba.cchText = 256;
7262 ZeroMemory(nmtba.pszText, nmtba.cchText);
7264 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
7266 int ccht = strlen(nmtba.pszText);
7267 if (ccht)
7268 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7269 nmtb->pszText, nmtb->cchText);
7271 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7272 bRet = TRUE;
7275 return bRet;
7280 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7281 int iItem, PCUSTOMBUTTON btnInfo)
7283 NMTOOLBARW nmtb;
7285 /* MSDN states that iItem is the index of the button, rather than the
7286 * command ID as used by every other NMTOOLBAR notification */
7287 nmtb.iItem = iItem;
7288 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7290 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);