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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
98 BYTE bDropDownPressed;
103 INT cx; /* manually set size */
117 } IMLENTRY, *PIMLENTRY;
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
124 RECT rcBound; /* bounding rectangle */
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nHotItem; /* index of the "hot" item */
142 SIZE szPadding; /* padding values around button */
143 INT iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
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 bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
182 PTOOLBAR_INFO tbInfo;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
201 #define SEPARATOR_WIDTH 8
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
212 /* vertical padding used in list mode when image is present */
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_DOUBLEBUFFER | \
229 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
231 /* all of the CCS_ styles */
232 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
233 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
235 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
236 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
237 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
238 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
239 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
241 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
243 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
250 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
251 static void TOOLBAR_LayoutToolbar(HWND hwnd);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
254 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
255 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
258 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
260 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
262 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
266 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
268 LPWSTR lpText = NULL;
270 /* NOTE: iString == -1 is undocumented */
271 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
272 lpText = (LPWSTR)btnPtr->iString;
273 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
274 lpText = infoPtr->strings[btnPtr->iString];
280 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
282 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
283 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
284 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
288 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
290 if (TRACE_ON(toolbar)){
291 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
292 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
293 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
294 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
295 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
296 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
297 wine_dbgstr_rect(&bP->rect));
303 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
305 if (TRACE_ON(toolbar)) {
308 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
310 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
311 iP->nNumStrings, iP->dwStyle);
312 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
314 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
315 (iP->bDoRedraw) ? "TRUE" : "FALSE");
316 for(i=0; i<iP->nNumButtons; i++) {
317 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
323 /***********************************************************************
326 * This function validates that the styles set are implemented and
327 * issues FIXME's warning of possible problems. In a perfect world this
328 * function should be null.
331 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
333 if (dwStyle & TBSTYLE_REGISTERDROP)
334 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
339 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
341 if(!IsWindow(infoPtr->hwndSelf))
342 return 0; /* we have just been destroyed */
344 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
345 nmhdr->hwndFrom = infoPtr->hwndSelf;
348 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
349 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
351 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
354 /***********************************************************************
355 * TOOLBAR_GetBitmapIndex
357 * This function returns the bitmap index associated with a button.
358 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
359 * is issued to retrieve the index.
362 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
364 INT ret = btnPtr->iBitmap;
366 if (ret == I_IMAGECALLBACK)
368 /* issue TBN_GETDISPINFO */
371 memset(&nmgd, 0, sizeof(nmgd));
372 nmgd.idCommand = btnPtr->idCommand;
373 nmgd.lParam = btnPtr->dwData;
374 nmgd.dwMask = TBNF_IMAGE;
376 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
377 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
378 if (nmgd.dwMask & TBNF_DI_SETITEM)
379 btnPtr->iBitmap = nmgd.iImage;
381 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
382 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
385 if (ret != I_IMAGENONE)
386 ret = GETIBITMAP(infoPtr, ret);
393 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
396 INT id = GETHIMLID(infoPtr, index);
397 INT iBitmap = GETIBITMAP(infoPtr, index);
399 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
400 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
401 (index == I_IMAGECALLBACK))
409 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
411 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
412 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
416 /***********************************************************************
417 * TOOLBAR_GetImageListForDrawing
419 * This function validates the bitmap index (including I_IMAGECALLBACK
420 * functionality) and returns the corresponding image list.
423 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
424 IMAGE_LIST_TYPE imagelist, INT * index)
428 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
429 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
430 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
431 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
435 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
436 if ((*index == I_IMAGECALLBACK) ||
437 (*index == I_IMAGENONE)) return NULL;
438 ERR("TBN_GETDISPINFO returned invalid index %d\n",
445 case IMAGE_LIST_DEFAULT:
446 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
449 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
451 case IMAGE_LIST_DISABLED:
452 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
456 FIXME("Shouldn't reach here\n");
460 TRACE("no image list\n");
467 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
470 COLORREF oldcolor, newcolor;
472 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
473 myrect.right = myrect.left + 1;
474 myrect.top = lpRect->top + 2;
475 myrect.bottom = lpRect->bottom - 2;
477 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
478 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
479 oldcolor = SetBkColor (hdc, newcolor);
480 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
482 myrect.left = myrect.right;
483 myrect.right = myrect.left + 1;
485 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
486 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
487 SetBkColor (hdc, newcolor);
488 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
490 SetBkColor (hdc, oldcolor);
494 /***********************************************************************
495 * TOOLBAR_DrawFlatHorizontalSeparator
497 * This function draws horizontal separator for toolbars having CCS_VERT style.
498 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
499 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
500 * are horizontal as opposed to the vertical separators for not dropdown
503 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
506 TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
507 const TOOLBAR_INFO *infoPtr)
510 COLORREF oldcolor, newcolor;
512 myrect.left = lpRect->left;
513 myrect.right = lpRect->right;
514 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
515 myrect.bottom = myrect.top + 1;
517 InflateRect (&myrect, -2, 0);
519 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
521 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
522 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
523 oldcolor = SetBkColor (hdc, newcolor);
524 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
526 myrect.top = myrect.bottom;
527 myrect.bottom = myrect.top + 1;
529 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
530 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
531 SetBkColor (hdc, newcolor);
532 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
534 SetBkColor (hdc, oldcolor);
539 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
544 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
545 hOldPen = SelectObject ( hdc, hPen );
548 MoveToEx (hdc, x, y, NULL);
549 LineTo (hdc, x+5, y++); x++;
550 MoveToEx (hdc, x, y, NULL);
551 LineTo (hdc, x+3, y++); x++;
552 MoveToEx (hdc, x, y, NULL);
553 LineTo (hdc, x+1, y);
554 SelectObject( hdc, hOldPen );
555 DeleteObject( hPen );
559 * Draw the text string for this button.
560 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
561 * is non-zero, so we can simply check himlDef to see if we have
565 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
566 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
568 HDC hdc = tbcd->nmcd.hdc;
571 COLORREF clrOldBk = 0;
573 UINT state = tbcd->nmcd.uItemState;
577 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
578 wine_dbgstr_rect(rcText));
580 hOldFont = SelectObject (hdc, infoPtr->hFont);
581 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
582 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
584 else if (state & CDIS_DISABLED) {
585 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
586 OffsetRect (rcText, 1, 1);
587 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
588 SetTextColor (hdc, comctl32_color.clr3dShadow);
589 OffsetRect (rcText, -1, -1);
591 else if (state & CDIS_INDETERMINATE) {
592 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
594 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
595 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
596 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
597 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
600 clrOld = SetTextColor (hdc, tbcd->clrText);
603 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
604 SetTextColor (hdc, clrOld);
605 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
607 SetBkColor (hdc, clrOldBk);
608 SetBkMode (hdc, oldBkMode);
610 SelectObject (hdc, hOldFont);
616 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
618 HDC hdc = tbcd->nmcd.hdc;
619 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
622 INT cx = lpRect->right - lpRect->left;
623 INT cy = lpRect->bottom - lpRect->top;
624 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
625 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
626 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
627 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
628 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
629 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
630 SetBkColor(hdc, clrBkOld);
631 SetTextColor(hdc, clrTextOld);
632 SelectObject (hdc, hbr);
636 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
639 HBITMAP hbmMask, hbmImage;
640 HDC hdcMask, hdcImage;
642 ImageList_GetIconSize(himl, &cx, &cy);
644 /* Create src image */
645 hdcImage = CreateCompatibleDC(hdc);
646 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
647 SelectObject(hdcImage, hbmImage);
648 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
649 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
652 hdcMask = CreateCompatibleDC(0);
653 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
654 SelectObject(hdcMask, hbmMask);
656 /* Remove the background and all white pixels */
657 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
658 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
659 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
660 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
662 /* draw the new mask 'etched' to hdc */
663 SetBkColor(hdc, RGB(255, 255, 255));
664 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
665 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
666 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
667 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
668 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
671 DeleteObject(hbmImage);
673 DeleteObject (hbmMask);
679 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
683 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
684 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
685 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
686 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
687 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
688 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
689 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
693 /* draws the image on a toolbar button */
695 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
696 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
698 HIMAGELIST himl = NULL;
699 BOOL draw_masked = FALSE;
702 UINT draw_flags = ILD_TRANSPARENT;
704 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
706 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
709 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
713 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
714 ((tbcd->nmcd.uItemState & CDIS_HOT)
715 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
717 /* if hot, attempt to draw with hot image list, if fails,
718 use default image list */
719 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
721 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
724 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
729 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
730 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
733 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
734 (tbcd->nmcd.uItemState & CDIS_MARKED))
735 draw_flags |= ILD_BLEND50;
737 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
738 index, himl, left, top, offset);
741 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
743 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
746 /* draws a blank frame for a toolbar button */
748 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
750 HDC hdc = tbcd->nmcd.hdc;
751 RECT rc = tbcd->nmcd.rc;
752 /* if the state is disabled or indeterminate then the button
753 * cannot have an interactive look like pressed or hot */
754 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
755 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
756 BOOL pressed_look = !non_interactive_state &&
757 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
758 (tbcd->nmcd.uItemState & CDIS_CHECKED));
760 /* app don't want us to draw any edges */
761 if (dwItemCDFlag & TBCDRF_NOEDGES)
764 if (infoPtr->dwStyle & TBSTYLE_FLAT)
767 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
768 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
769 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
774 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
776 DrawEdge (hdc, &rc, EDGE_RAISED,
777 BF_SOFT | BF_RECT | BF_MIDDLE);
782 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
784 HDC hdc = tbcd->nmcd.hdc;
786 BOOL pressed = bDropDownPressed ||
787 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
789 if (infoPtr->dwStyle & TBSTYLE_FLAT)
792 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
793 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
794 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
795 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
796 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
801 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
803 DrawEdge (hdc, rcArrow, EDGE_RAISED,
804 BF_SOFT | BF_RECT | BF_MIDDLE);
808 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
810 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
812 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
813 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
816 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
819 /* draws a complete toolbar button */
821 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
824 DWORD dwStyle = infoPtr->dwStyle;
825 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
826 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
827 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
828 BOOL drawSepDropDownArrow = hasDropDownArrow &&
829 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
830 RECT rc, rcArrow, rcBitmap, rcText;
831 LPWSTR lpText = NULL;
836 DWORD dwItemCustDraw;
838 HTHEME theme = GetWindowTheme (hwnd);
841 CopyRect (&rcArrow, &rc);
843 /* separator - doesn't send NM_CUSTOMDRAW */
844 if (btnPtr->fsStyle & BTNS_SEP) {
847 DrawThemeBackground (theme, hdc,
848 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
852 /* with the FLAT style, iBitmap is the width and has already */
853 /* been taken into consideration in calculating the width */
854 /* so now we need to draw the vertical separator */
855 /* empirical tests show that iBitmap can/will be non-zero */
856 /* when drawing the vertical bar... */
857 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
858 if (dwStyle & CCS_VERT)
859 TOOLBAR_DrawFlatHorizontalSeparator (&rc, hdc, infoPtr);
861 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
863 else if (btnPtr->fsStyle != BTNS_SEP) {
864 FIXME("Draw some kind of separator: fsStyle=%x\n",
870 /* get a pointer to the text */
871 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
873 if (hasDropDownArrow)
877 if (dwStyle & TBSTYLE_FLAT)
878 right = max(rc.left, rc.right - DDARROW_WIDTH);
880 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
882 if (drawSepDropDownArrow)
885 rcArrow.left = right;
888 /* copy text & bitmap rects after adjusting for drop-down arrow
889 * so that text & bitmap is centered in the rectangle not containing
891 CopyRect(&rcText, &rc);
892 CopyRect(&rcBitmap, &rc);
894 /* Center the bitmap horizontally and vertically */
895 if (dwStyle & TBSTYLE_LIST)
898 infoPtr->nMaxTextRows > 0 &&
899 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
900 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
901 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
903 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
906 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
908 rcBitmap.top += infoPtr->szPadding.cy / 2;
910 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
911 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
912 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
913 TRACE("Text=%s\n", debugstr_w(lpText));
914 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
916 /* calculate text position */
919 rcText.left += GetSystemMetrics(SM_CXEDGE);
920 rcText.right -= GetSystemMetrics(SM_CXEDGE);
921 if (dwStyle & TBSTYLE_LIST)
923 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
927 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
928 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
930 rcText.top += infoPtr->szPadding.cy/2 + 2;
934 /* Initialize fields in all cases, because we use these later
935 * NOTE: applications can and do alter these to customize their
937 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
938 tbcd.clrText = comctl32_color.clrBtnText;
939 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
940 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
941 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
942 tbcd.clrMark = comctl32_color.clrHighlight;
943 tbcd.clrHighlightHotTrack = 0;
944 tbcd.nStringBkMode = TRANSPARENT;
945 tbcd.nHLStringBkMode = OPAQUE;
946 /* MSDN says that this is the text rectangle.
947 * But (why always a but) tracing of v5.7 of native shows
948 * that this is really a *relative* rectangle based on the
949 * the nmcd.rc. Also the left and top are always 0 ignoring
950 * any bitmap that might be present. */
951 tbcd.rcText.left = 0;
953 tbcd.rcText.right = rcText.right - rc.left;
954 tbcd.rcText.bottom = rcText.bottom - rc.top;
955 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
958 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
960 /* FIXME: what are these used for? */
964 /* Issue Item Prepaint notify */
967 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
969 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
970 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
971 tbcd.nmcd.lItemlParam = btnPtr->dwData;
972 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
973 /* reset these fields so the user can't alter the behaviour like native */
977 dwItemCustDraw = ntfret & 0xffff;
978 dwItemCDFlag = ntfret & 0xffff0000;
979 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
981 /* save the only part of the rect that the user can change */
982 rcText.right = tbcd.rcText.right + rc.left;
983 rcText.bottom = tbcd.rcText.bottom + rc.top;
986 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
987 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
988 OffsetRect(&rcText, 1, 1);
990 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
991 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
992 TOOLBAR_DrawPattern (&rc, &tbcd);
994 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
995 && (tbcd.nmcd.uItemState & CDIS_HOT))
997 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
1001 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1002 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1003 if (hasDropDownArrow)
1004 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1005 SetBkColor(hdc, oldclr);
1011 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1012 int stateId = TS_NORMAL;
1014 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1015 stateId = TS_DISABLED;
1016 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1017 stateId = TS_PRESSED;
1018 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1019 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1020 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1021 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1024 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1027 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1029 if (drawSepDropDownArrow)
1033 int stateId = TS_NORMAL;
1035 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1036 stateId = TS_DISABLED;
1037 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1038 stateId = TS_PRESSED;
1039 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1040 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1041 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1044 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1045 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1048 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1051 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1052 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1053 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1054 SetBkMode (hdc, oldBkMode);
1056 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1058 if (hasDropDownArrow && !drawSepDropDownArrow)
1060 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1065 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1067 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1068 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1071 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1074 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1076 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1077 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1084 TOOLBAR_Refresh (HWND hwnd, HDC hdc, const PAINTSTRUCT *ps)
1086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1087 TBUTTON_INFO *btnPtr;
1089 RECT rcTemp, rcClient;
1090 NMTBCUSTOMDRAW tbcd;
1092 DWORD dwBaseCustDraw;
1094 /* the app has told us not to redraw the toolbar */
1095 if (!infoPtr->bDoRedraw)
1098 /* if imagelist belongs to the app, it can be changed
1099 by the app after setting it */
1100 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1102 infoPtr->nNumBitmaps = 0;
1103 for (i = 0; i < infoPtr->cimlDef; i++)
1104 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1107 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1109 /* change the imagelist icon size if we manage the list and it is necessary */
1110 TOOLBAR_CheckImageListIconSize(infoPtr);
1112 /* Send initial notify */
1113 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1114 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1115 tbcd.nmcd.hdc = hdc;
1116 tbcd.nmcd.rc = ps->rcPaint;
1117 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1118 dwBaseCustDraw = ntfret & 0xffff;
1120 GetClientRect(hwnd, &rcClient);
1122 /* redraw necessary buttons */
1123 btnPtr = infoPtr->buttons;
1124 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1127 if (!RectVisible(hdc, &btnPtr->rect))
1129 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1131 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1132 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1136 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1137 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1139 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1142 /* draw insert mark if required */
1143 if (infoPtr->tbim.iButton != -1)
1145 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1147 rcInsertMark.top = rcButton.top;
1148 rcInsertMark.bottom = rcButton.bottom;
1149 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1150 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1152 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1153 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1156 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1158 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1159 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1160 tbcd.nmcd.hdc = hdc;
1161 tbcd.nmcd.rc = ps->rcPaint;
1162 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1166 /***********************************************************************
1167 * TOOLBAR_MeasureString
1169 * This function gets the width and height of a string in pixels. This
1170 * is done first by using GetTextExtentPoint to get the basic width
1171 * and height. The DrawText is called with DT_CALCRECT to get the exact
1172 * width. The reason is because the text may have more than one "&" (or
1173 * prefix characters as M$ likes to call them). The prefix character
1174 * indicates where the underline goes, except for the string "&&" which
1175 * is reduced to a single "&". GetTextExtentPoint does not process these
1176 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1179 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1180 HDC hdc, LPSIZE lpSize)
1187 if (infoPtr->nMaxTextRows > 0 &&
1188 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1189 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1190 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1192 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1194 if(lpText != NULL) {
1195 /* first get size of all the text */
1196 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1198 /* feed above size into the rectangle for DrawText */
1199 myrect.left = myrect.top = 0;
1200 myrect.right = lpSize->cx;
1201 myrect.bottom = lpSize->cy;
1203 /* Use DrawText to get true size as drawn (less pesky "&") */
1204 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1205 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1208 /* feed back to caller */
1209 lpSize->cx = myrect.right;
1210 lpSize->cy = myrect.bottom;
1214 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1217 /***********************************************************************
1218 * TOOLBAR_CalcStrings
1220 * This function walks through each string and measures it and returns
1221 * the largest height and width to caller.
1224 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1226 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1227 TBUTTON_INFO *btnPtr;
1236 if (infoPtr->nMaxTextRows == 0)
1240 hOldFont = SelectObject (hdc, infoPtr->hFont);
1242 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1246 GetTextMetricsW(hdc, &tm);
1247 lpSize->cy = tm.tmHeight;
1250 btnPtr = infoPtr->buttons;
1251 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1252 if(TOOLBAR_HasText(infoPtr, btnPtr))
1254 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1255 if (sz.cx > lpSize->cx)
1257 if (sz.cy > lpSize->cy)
1262 SelectObject (hdc, hOldFont);
1263 ReleaseDC (hwnd, hdc);
1265 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1268 /***********************************************************************
1269 * TOOLBAR_WrapToolbar
1271 * This function walks through the buttons and separators in the
1272 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1273 * wrapping should occur based on the width of the toolbar window.
1274 * It does *not* calculate button placement itself. That task
1275 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1276 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1277 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1279 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1280 * vertical toolbar lists.
1284 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1287 TBUTTON_INFO *btnPtr;
1292 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1293 /* no layout is necessary. Applications may use this style */
1294 /* to perform their own layout on the toolbar. */
1295 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1296 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1298 btnPtr = infoPtr->buttons;
1299 x = infoPtr->nIndent;
1301 if (GetParent(hwnd))
1303 /* this can get the parents width, to know how far we can extend
1304 * this toolbar. We cannot use its height, as there may be multiple
1305 * toolbars in a rebar control
1307 GetClientRect( GetParent(hwnd), &rc );
1308 infoPtr->nWidth = rc.right - rc.left;
1312 GetWindowRect( hwnd, &rc );
1313 infoPtr->nWidth = rc.right - rc.left;
1316 bButtonWrap = FALSE;
1318 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1319 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1322 for (i = 0; i < infoPtr->nNumButtons; i++ )
1324 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1326 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1329 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1330 /* it is the actual width of the separator. This is used for */
1331 /* custom controls in toolbars. */
1333 /* horizontal separators are treated as buttons for width */
1334 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1335 !(infoPtr->dwStyle & CCS_VERT))
1336 cx = (btnPtr[i].iBitmap > 0) ?
1337 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1339 cx = (btnPtr[i].cx) ? btnPtr[i].cx : infoPtr->nButtonWidth;
1341 /* Two or more adjacent separators form a separator group. */
1342 /* The first separator in a group should be wrapped to the */
1343 /* next row if the previous wrapping is on a button. */
1345 (btnPtr[i].fsStyle & BTNS_SEP) &&
1346 (i + 1 < infoPtr->nNumButtons ) &&
1347 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1349 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1350 btnPtr[i].fsState |= TBSTATE_WRAP;
1351 x = infoPtr->nIndent;
1353 bButtonWrap = FALSE;
1357 /* The layout makes sure the bitmap is visible, but not the button. */
1358 /* Test added to also wrap after a button that starts a row but */
1359 /* is bigger than the area. - GA 8/01 */
1360 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1361 > infoPtr->nWidth ) ||
1362 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1364 BOOL bFound = FALSE;
1366 /* If the current button is a separator and not hidden, */
1367 /* go to the next until it reaches a non separator. */
1368 /* Wrap the last separator if it is before a button. */
1369 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1370 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1371 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1372 i < infoPtr->nNumButtons )
1378 if( bFound && i < infoPtr->nNumButtons )
1381 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1382 i, btnPtr[i].fsStyle, x, cx);
1383 btnPtr[i].fsState |= TBSTATE_WRAP;
1384 x = infoPtr->nIndent;
1385 bButtonWrap = FALSE;
1388 else if ( i >= infoPtr->nNumButtons)
1391 /* If the current button is not a separator, find the last */
1392 /* separator and wrap it. */
1393 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1395 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1396 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1400 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1401 i, btnPtr[i].fsStyle, x, cx);
1402 x = infoPtr->nIndent;
1403 btnPtr[j].fsState |= TBSTATE_WRAP;
1404 bButtonWrap = FALSE;
1409 /* If no separator available for wrapping, wrap one of */
1410 /* non-hidden previous button. */
1414 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1416 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1421 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1422 i, btnPtr[i].fsStyle, x, cx);
1423 x = infoPtr->nIndent;
1424 btnPtr[j].fsState |= TBSTATE_WRAP;
1430 /* If all above failed, wrap the current button. */
1433 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1434 i, btnPtr[i].fsStyle, x, cx);
1435 btnPtr[i].fsState |= TBSTATE_WRAP;
1436 x = infoPtr->nIndent;
1437 if (btnPtr[i].fsStyle & BTNS_SEP )
1438 bButtonWrap = FALSE;
1444 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1445 i, btnPtr[i].fsStyle, x, cx);
1452 /***********************************************************************
1453 * TOOLBAR_MeasureButton
1455 * Calculates the width and height required for a button. Used in
1456 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1457 * the width of buttons that are autosized.
1459 * Note that it would have been rather elegant to use one piece of code for
1460 * both the laying out of the toolbar and for controlling where button parts
1461 * are drawn, but the native control has inconsistencies between the two that
1462 * prevent this from being effectively. These inconsistencies can be seen as
1463 * artefacts where parts of the button appear outside of the bounding button
1466 * There are several cases for the calculation of the button dimensions and
1467 * button part positioning:
1474 * +--------------------------------------------------------+ ^
1476 * | | pad.cy / 2 | centred | |
1477 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1478 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1479 * | |<------------>| | | | |
1480 * | +--------------+ +------------+ | |
1481 * |<-------------------------------------->| | |
1482 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1484 * +--------------------------------------------------------+ -
1485 * <-------------------------------------------------------->
1486 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1488 * Without Bitmap (I_IMAGENONE):
1490 * +-----------------------------------+ ^
1492 * | | centred | | LISTPAD_CY +
1493 * | +------------+ | | szText.cy
1496 * | +------------+ | |
1497 * |<----------------->| | |
1498 * | cxedge |<-----------> | |
1500 * +-----------------------------------+ -
1501 * <----------------------------------->
1502 * szText.cx + pad.cx
1506 * +--------------------------------------+ ^
1508 * | | padding.cy/2 | | DEFPAD_CY +
1509 * | +------------+ | | nBitmapHeight
1512 * | +------------+ | |
1513 * |<------------------->| | |
1514 * | cxedge + iListGap/2 |<-----------> | |
1515 * | nBitmapWidth | |
1516 * +--------------------------------------+ -
1517 * <-------------------------------------->
1518 * 2*cxedge + nBitmapWidth + iListGap
1525 * +-----------------------------------+ ^
1527 * | | pad.cy / 2 | | nBitmapHeight +
1528 * | - | | szText.cy +
1529 * | +------------+ | | DEFPAD_CY + 1
1530 * | centred | Bitmap | | |
1531 * |<----------------->| | | |
1532 * | +------------+ | |
1536 * | centred +---------------+ | |
1537 * |<--------------->| Text | | |
1538 * | +---------------+ | |
1539 * +-----------------------------------+ -
1540 * <----------------------------------->
1541 * pad.cx + max(nBitmapWidth, szText.cx)
1543 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1545 * +---------------------------------------+ ^
1547 * | | 2 + pad.cy / 2 | |
1548 * | - | | szText.cy +
1549 * | centred +-----------------+ | | pad.cy + 2
1550 * |<--------------->| Text | | |
1551 * | +-----------------+ | |
1553 * +---------------------------------------+ -
1554 * <--------------------------------------->
1555 * 2*cxedge + pad.cx + szText.cx
1558 * As for with bitmaps, but with szText.cx zero.
1560 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1561 BOOL bHasBitmap, BOOL bValidImageList)
1564 if (infoPtr->dwStyle & TBSTYLE_LIST)
1566 /* set button height from bitmap / text height... */
1567 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1570 /* ... add on the necessary padding */
1571 if (bValidImageList)
1574 sizeButton.cy += DEFPAD_CY;
1576 sizeButton.cy += LISTPAD_CY;
1579 sizeButton.cy += infoPtr->szPadding.cy;
1581 /* calculate button width */
1582 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1583 infoPtr->nBitmapWidth + infoPtr->iListGap;
1584 if (sizeString.cx > 0)
1585 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1592 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1593 if (sizeString.cy > 0)
1594 sizeButton.cy += 1 + sizeString.cy;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(sizeString.cx, infoPtr->nBitmapWidth);
1600 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1601 NONLIST_NOTEXT_OFFSET;
1602 sizeButton.cx = infoPtr->szPadding.cx +
1603 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1621 TOOLBAR_CalcToolbar (HWND hwnd)
1623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1624 SIZE sizeString, sizeButton;
1625 BOOL validImageList = FALSE;
1627 TOOLBAR_CalcStrings (hwnd, &sizeString);
1629 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1631 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1632 validImageList = TRUE;
1633 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1634 infoPtr->nButtonWidth = sizeButton.cx;
1635 infoPtr->nButtonHeight = sizeButton.cy;
1636 infoPtr->iTopMargin = default_top_margin(infoPtr);
1638 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1639 infoPtr->nButtonWidth = infoPtr->cxMin;
1640 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1641 infoPtr->nButtonWidth = infoPtr->cxMax;
1643 TOOLBAR_LayoutToolbar(hwnd);
1647 TOOLBAR_LayoutToolbar(HWND hwnd)
1649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1650 TBUTTON_INFO *btnPtr;
1652 INT i, nRows, nSepRows;
1655 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1656 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1658 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1660 x = infoPtr->nIndent;
1661 y = infoPtr->iTopMargin;
1662 cx = infoPtr->nButtonWidth;
1663 cy = infoPtr->nButtonHeight;
1665 nRows = nSepRows = 0;
1667 infoPtr->rcBound.top = y;
1668 infoPtr->rcBound.left = x;
1669 infoPtr->rcBound.bottom = y + cy;
1670 infoPtr->rcBound.right = x;
1672 btnPtr = infoPtr->buttons;
1674 TRACE("cy=%d\n", cy);
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1679 if (btnPtr->fsState & TBSTATE_HIDDEN)
1681 SetRectEmpty (&btnPtr->rect);
1685 cy = infoPtr->nButtonHeight;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr->fsStyle & BTNS_SEP) {
1691 if (infoPtr->dwStyle & CCS_VERT) {
1692 cy = (btnPtr->iBitmap > 0) ?
1693 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 cx = infoPtr->nButtonWidth;
1697 cx = (btnPtr->iBitmap > 0) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH;
1704 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1705 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1712 hOldFont = SelectObject (hdc, infoPtr->hFont);
1714 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1716 SelectObject (hdc, hOldFont);
1717 ReleaseDC (hwnd, hdc);
1719 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1725 cx = infoPtr->nButtonWidth;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr->cx && hasDropDownArrows &&
1730 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1731 cx += DDARROW_WIDTH;
1733 if (btnPtr->fsState & TBSTATE_WRAP )
1736 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1738 if (infoPtr->rcBound.left > x)
1739 infoPtr->rcBound.left = x;
1740 if (infoPtr->rcBound.right < x + cx)
1741 infoPtr->rcBound.right = x + cx;
1742 if (infoPtr->rcBound.bottom < y + cy)
1743 infoPtr->rcBound.bottom = y + cy;
1745 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr->nRow = nRows + nSepRows;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1757 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(infoPtr->dwStyle & CCS_VERT))
1765 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1766 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1770 /* nSepRows is used to calculate the extra height following */
1774 x = infoPtr->nIndent;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i != infoPtr->nNumButtons-1)
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr->nRows = nRows + nSepRows + 1;
1788 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1793 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1796 TBUTTON_INFO *btnPtr;
1799 btnPtr = infoPtr->buttons;
1800 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1801 if (btnPtr->fsState & TBSTATE_HIDDEN)
1804 if (btnPtr->fsStyle & BTNS_SEP) {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON SEPARATOR %d!\n", i);
1811 if (PtInRect (&btnPtr->rect, *lpPt)) {
1812 TRACE(" ON BUTTON %d!\n", i);
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE;
1823 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1825 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, TBBUTTON *lpTbb, BOOL fUnicode)
1827 INT nOldButtons, nNewButtons, iButton;
1828 BOOL fHasString = FALSE;
1830 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1831 iIndex = infoPtr->nNumButtons;
1833 nOldButtons = infoPtr->nNumButtons;
1834 nNewButtons = nOldButtons + nAddButtons;
1836 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1837 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1838 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1839 infoPtr->nNumButtons += nAddButtons;
1841 /* insert new buttons data */
1842 for (iButton = 0; iButton < nAddButtons; iButton++) {
1843 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1845 TOOLBAR_DumpTBButton(lpTbb, fUnicode);
1847 ZeroMemory(btnPtr, sizeof(*btnPtr));
1848 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1849 btnPtr->idCommand = lpTbb[iButton].idCommand;
1850 btnPtr->fsState = lpTbb[iButton].fsState;
1851 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1852 btnPtr->dwData = lpTbb[iButton].dwData;
1853 if(HIWORD(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1856 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1858 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1862 btnPtr->iString = lpTbb[iButton].iString;
1864 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1867 if (infoPtr->nNumStrings > 0 || fHasString)
1868 TOOLBAR_CalcToolbar(infoPtr->hwndSelf);
1870 TOOLBAR_LayoutToolbar(infoPtr->hwndSelf);
1871 TOOLBAR_AutoSize(infoPtr->hwndSelf);
1873 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1874 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1880 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1882 TBUTTON_INFO *btnPtr;
1885 if (CommandIsIndex) {
1886 TRACE("command is really index command=%d\n", idCommand);
1887 if (idCommand >= infoPtr->nNumButtons) return -1;
1890 btnPtr = infoPtr->buttons;
1891 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1892 if (btnPtr->idCommand == idCommand) {
1893 TRACE("command=%d index=%d\n", idCommand, i);
1897 TRACE("no index found for command=%d\n", idCommand);
1903 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1905 TBUTTON_INFO *btnPtr;
1908 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1911 /* check index button */
1912 btnPtr = &infoPtr->buttons[nIndex];
1913 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1914 if (btnPtr->fsState & TBSTATE_CHECKED)
1918 /* check previous buttons */
1919 nRunIndex = nIndex - 1;
1920 while (nRunIndex >= 0) {
1921 btnPtr = &infoPtr->buttons[nRunIndex];
1922 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1923 if (btnPtr->fsState & TBSTATE_CHECKED)
1931 /* check next buttons */
1932 nRunIndex = nIndex + 1;
1933 while (nRunIndex < infoPtr->nNumButtons) {
1934 btnPtr = &infoPtr->buttons[nRunIndex];
1935 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1936 if (btnPtr->fsState & TBSTATE_CHECKED)
1949 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1950 WPARAM wParam, LPARAM lParam)
1956 msg.wParam = wParam;
1957 msg.lParam = lParam;
1958 msg.time = GetMessageTime ();
1959 msg.pt.x = (short)LOWORD(GetMessagePos ());
1960 msg.pt.y = (short)HIWORD(GetMessagePos ());
1962 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1966 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1968 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1971 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1972 ti.cbSize = sizeof (TTTOOLINFOW);
1973 ti.hwnd = infoPtr->hwndSelf;
1974 ti.uId = button->idCommand;
1976 ti.lpszText = LPSTR_TEXTCALLBACKW;
1977 /* ti.lParam = random value from the stack? */
1979 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1985 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1987 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1990 ZeroMemory(&ti, sizeof(ti));
1991 ti.cbSize = sizeof(ti);
1992 ti.hwnd = infoPtr->hwndSelf;
1993 ti.uId = button->idCommand;
1995 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1999 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2001 /* Set the toolTip only for non-hidden, non-separator button */
2002 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
2006 ZeroMemory(&ti, sizeof(ti));
2007 ti.cbSize = sizeof(ti);
2008 ti.hwnd = infoPtr->hwndSelf;
2009 ti.uId = button->idCommand;
2010 ti.rect = button->rect;
2011 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2015 /* Creates the tooltip control */
2017 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2020 NMTOOLTIPSCREATED nmttc;
2022 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2023 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2024 infoPtr->hwndSelf, 0, 0, 0);
2026 if (!infoPtr->hwndToolTip)
2029 /* Send NM_TOOLTIPSCREATED notification */
2030 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2031 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2033 for (i = 0; i < infoPtr->nNumButtons; i++)
2035 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2036 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2040 /* keeps available button list box sorted by button id */
2041 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2045 PCUSTOMBUTTON btnInfo;
2046 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2048 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2050 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2052 /* position 0 is always separator */
2053 for (i = 1; i < count; i++)
2055 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2056 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2058 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2059 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2063 /* id higher than all others add to end */
2064 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2065 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2068 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2072 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2074 if (nIndexFrom == nIndexTo)
2077 /* MSDN states that iItem is the index of the button, rather than the
2078 * command ID as used by every other NMTOOLBAR notification */
2079 nmtb.iItem = nIndexFrom;
2080 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2082 PCUSTOMBUTTON btnInfo;
2084 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2085 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2087 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2089 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2090 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2091 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2092 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2095 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2097 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2099 /* last item is always separator, so -2 instead of -1 */
2100 if (nIndexTo >= (count - 2))
2101 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2103 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2105 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2106 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2108 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2112 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2116 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2118 /* MSDN states that iItem is the index of the button, rather than the
2119 * command ID as used by every other NMTOOLBAR notification */
2120 nmtb.iItem = nIndexAvail;
2121 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2123 PCUSTOMBUTTON btnInfo;
2125 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2126 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2127 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2129 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2131 if (nIndexAvail != 0) /* index == 0 indicates separator */
2133 /* remove from 'available buttons' list */
2134 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2135 if (nIndexAvail == count-1)
2136 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2138 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2142 PCUSTOMBUTTON btnNew;
2144 /* duplicate 'separator' button */
2145 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2150 /* insert into 'toolbar button' list */
2151 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2152 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2154 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2156 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2160 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2162 PCUSTOMBUTTON btnInfo;
2163 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2165 TRACE("Remove: index %d\n", index);
2167 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2169 /* send TBN_QUERYDELETE notification */
2170 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2174 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2175 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2177 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2179 /* insert into 'available button' list */
2180 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2181 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2185 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2189 /* drag list notification function for toolbar buttons list box */
2190 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2191 const DRAGLISTINFO *pDLI)
2193 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2194 switch (pDLI->uNotification)
2198 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2199 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2200 /* no dragging for last item (separator) */
2201 if (nCurrentItem >= (nCount - 1)) return FALSE;
2206 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2207 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2208 /* no dragging past last item (separator) */
2209 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2211 DrawInsert(hwnd, hwndList, nCurrentItem);
2212 /* FIXME: native uses "move button" cursor */
2213 return DL_COPYCURSOR;
2216 /* not over toolbar buttons list */
2217 if (nCurrentItem < 0)
2219 POINT ptWindow = pDLI->ptCursor;
2220 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2221 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2222 /* over available buttons list? */
2223 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2224 /* FIXME: native uses "move button" cursor */
2225 return DL_COPYCURSOR;
2227 /* clear drag arrow */
2228 DrawInsert(hwnd, hwndList, -1);
2229 return DL_STOPCURSOR;
2233 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2234 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2235 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2236 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2238 /* clear drag arrow */
2239 DrawInsert(hwnd, hwndList, -1);
2241 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2243 /* not over toolbar buttons list */
2246 POINT ptWindow = pDLI->ptCursor;
2247 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2248 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2249 /* over available buttons list? */
2250 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2251 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2256 /* Clear drag arrow */
2257 DrawInsert(hwnd, hwndList, -1);
2264 /* drag list notification function for available buttons list box */
2265 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2266 const DRAGLISTINFO *pDLI)
2268 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2269 switch (pDLI->uNotification)
2275 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2276 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2277 /* no dragging past last item (separator) */
2278 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2280 DrawInsert(hwnd, hwndList, nCurrentItem);
2281 /* FIXME: native uses "move button" cursor */
2282 return DL_COPYCURSOR;
2285 /* not over toolbar buttons list */
2286 if (nCurrentItem < 0)
2288 POINT ptWindow = pDLI->ptCursor;
2289 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2290 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2291 /* over available buttons list? */
2292 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2293 /* FIXME: native uses "move button" cursor */
2294 return DL_COPYCURSOR;
2296 /* clear drag arrow */
2297 DrawInsert(hwnd, hwndList, -1);
2298 return DL_STOPCURSOR;
2302 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2303 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2304 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2305 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2307 /* clear drag arrow */
2308 DrawInsert(hwnd, hwndList, -1);
2310 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2314 /* Clear drag arrow */
2315 DrawInsert(hwnd, hwndList, -1);
2321 extern UINT uDragListMessage;
2323 /***********************************************************************
2324 * TOOLBAR_CustomizeDialogProc
2325 * This function implements the toolbar customization dialog.
2327 static INT_PTR CALLBACK
2328 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2330 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2331 PCUSTOMBUTTON btnInfo;
2333 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2338 custInfo = (PCUSTDLG_INFO)lParam;
2339 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2346 NMTBINITCUSTOMIZE nmtbic;
2348 infoPtr = custInfo->tbInfo;
2350 /* send TBN_QUERYINSERT notification */
2351 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2353 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2356 nmtbic.hwndDialog = hwnd;
2357 /* Send TBN_INITCUSTOMIZE notification */
2358 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2361 TRACE("TBNRF_HIDEHELP requested\n");
2362 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2365 /* add items to 'toolbar buttons' list and check if removable */
2366 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2368 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2369 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2370 btnInfo->btn.fsStyle = BTNS_SEP;
2371 btnInfo->bVirtual = FALSE;
2372 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2374 /* send TBN_QUERYDELETE notification */
2375 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2377 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2378 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2381 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2383 /* insert separator button into 'available buttons' list */
2384 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2385 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2386 btnInfo->btn.fsStyle = BTNS_SEP;
2387 btnInfo->bVirtual = FALSE;
2388 btnInfo->bRemovable = TRUE;
2389 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2390 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2391 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2393 /* insert all buttons into dsa */
2396 /* send TBN_GETBUTTONINFO notification */
2399 nmtb.pszText = Buffer;
2402 /* Clear previous button's text */
2403 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2405 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2408 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2409 nmtb.tbButton.fsStyle, i,
2410 nmtb.tbButton.idCommand,
2411 nmtb.tbButton.iString,
2412 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2415 /* insert button into the apropriate list */
2416 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2419 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2420 btnInfo->bVirtual = FALSE;
2421 btnInfo->bRemovable = TRUE;
2425 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2426 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2429 btnInfo->btn = nmtb.tbButton;
2430 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2432 if (lstrlenW(nmtb.pszText))
2433 lstrcpyW(btnInfo->text, nmtb.pszText);
2434 else if (nmtb.tbButton.iString >= 0 &&
2435 nmtb.tbButton.iString < infoPtr->nNumStrings)
2437 lstrcpyW(btnInfo->text,
2438 infoPtr->strings[nmtb.tbButton.iString]);
2443 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2446 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2448 /* select first item in the 'available' list */
2449 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2451 /* append 'virtual' separator button to the 'toolbar buttons' list */
2452 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2453 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2454 btnInfo->btn.fsStyle = BTNS_SEP;
2455 btnInfo->bVirtual = TRUE;
2456 btnInfo->bRemovable = FALSE;
2457 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2458 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2459 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2461 /* select last item in the 'toolbar' list */
2462 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2463 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2465 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2466 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2468 /* set focus and disable buttons */
2469 PostMessageW (hwnd, WM_USER, 0, 0);
2474 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2475 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2476 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2477 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2481 EndDialog(hwnd, FALSE);
2485 switch (LOWORD(wParam))
2487 case IDC_TOOLBARBTN_LBOX:
2488 if (HIWORD(wParam) == LBN_SELCHANGE)
2490 PCUSTOMBUTTON btnInfo;
2495 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2496 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2498 /* send TBN_QUERYINSERT notification */
2500 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2502 /* get list box item */
2503 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2505 if (index == (count - 1))
2507 /* last item (virtual separator) */
2508 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2509 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2511 else if (index == (count - 2))
2513 /* second last item (last non-virtual item) */
2514 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2515 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2517 else if (index == 0)
2520 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2521 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2525 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2526 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2529 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2533 case IDC_MOVEUP_BTN:
2535 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2536 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2540 case IDC_MOVEDN_BTN: /* move down */
2542 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2543 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2547 case IDC_REMOVE_BTN: /* remove button */
2549 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2551 if (LB_ERR == index)
2554 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2558 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2561 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2564 case IDOK: /* Add button */
2569 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2570 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2572 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2577 EndDialog(hwnd, FALSE);
2587 /* delete items from 'toolbar buttons' listbox*/
2588 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2589 for (i = 0; i < count; i++)
2591 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2593 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2595 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2598 /* delete items from 'available buttons' listbox*/
2599 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2600 for (i = 0; i < count; i++)
2602 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2604 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2606 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2611 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2613 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2618 COLORREF oldText = 0;
2622 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2623 if (btnInfo == NULL)
2625 FIXME("btnInfo invalid!\n");
2629 /* set colors and select objects */
2630 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2631 if (btnInfo->bVirtual)
2632 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2634 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2635 hPen = CreatePen( PS_SOLID, 1,
2636 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2637 hOldPen = SelectObject (lpdis->hDC, hPen );
2638 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2640 /* fill background rectangle */
2641 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2642 lpdis->rcItem.right, lpdis->rcItem.bottom);
2644 /* calculate button and text rectangles */
2645 CopyRect (&rcButton, &lpdis->rcItem);
2646 InflateRect (&rcButton, -1, -1);
2647 CopyRect (&rcText, &rcButton);
2648 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2649 rcText.left = rcButton.right + 2;
2651 /* draw focus rectangle */
2652 if (lpdis->itemState & ODS_FOCUS)
2653 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2656 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2657 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2659 /* draw image and text */
2660 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2661 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2662 btnInfo->btn.iBitmap));
2663 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2664 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2666 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2667 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2669 /* delete objects and reset colors */
2670 SelectObject (lpdis->hDC, hOldBrush);
2671 SelectObject (lpdis->hDC, hOldPen);
2672 SetBkColor (lpdis->hDC, oldBk);
2673 SetTextColor (lpdis->hDC, oldText);
2674 DeleteObject( hPen );
2679 case WM_MEASUREITEM:
2680 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2682 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2684 lpmis->itemHeight = 15 + 8; /* default height */
2691 if (uDragListMessage && (uMsg == uDragListMessage))
2693 if (wParam == IDC_TOOLBARBTN_LBOX)
2695 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2696 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2697 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2700 else if (wParam == IDC_AVAILBTN_LBOX)
2702 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2703 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2704 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2713 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2716 INT nCountBefore = ImageList_GetImageCount(himlDef);
2722 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2723 /* Add bitmaps to the default image list */
2724 if (bitmap->hInst == NULL) /* a handle was passed */
2725 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2727 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2729 /* enlarge the bitmap if needed */
2730 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2731 if (bitmap->hInst != COMCTL32_hModule)
2732 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2734 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2735 DeleteObject(hbmLoad);
2739 nCountAfter = ImageList_GetImageCount(himlDef);
2740 nAdded = nCountAfter - nCountBefore;
2741 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2743 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2744 } else if (nAdded > (INT)bitmap->nButtons) {
2745 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2746 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2749 infoPtr->nNumBitmaps += nAdded;
2754 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2761 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2762 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2764 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2766 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2769 TRACE("Update icon size: %dx%d -> %dx%d\n",
2770 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2772 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2773 ILC_COLORDDB|ILC_MASK, 8, 2);
2774 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2775 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2776 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2777 infoPtr->himlInt = himlNew;
2779 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2780 ImageList_Destroy(himlDef);
2783 /***********************************************************************
2784 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2788 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2790 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2791 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2796 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2800 if (lpAddBmp->hInst == HINST_COMMCTRL)
2802 info.hInst = COMCTL32_hModule;
2803 switch (lpAddBmp->nID)
2805 case IDB_STD_SMALL_COLOR:
2807 info.nID = IDB_STD_SMALL;
2809 case IDB_STD_LARGE_COLOR:
2811 info.nID = IDB_STD_LARGE;
2813 case IDB_VIEW_SMALL_COLOR:
2815 info.nID = IDB_VIEW_SMALL;
2817 case IDB_VIEW_LARGE_COLOR:
2819 info.nID = IDB_VIEW_LARGE;
2821 case IDB_HIST_SMALL_COLOR:
2823 info.nID = IDB_HIST_SMALL;
2825 case IDB_HIST_LARGE_COLOR:
2827 info.nID = IDB_HIST_LARGE;
2833 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2835 /* Windows resize all the buttons to the size of a newly added standard image */
2836 if (lpAddBmp->nID & 1)
2838 /* large icons: 24x24. Will make the button 31x30 */
2839 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2843 /* small icons: 16x16. Will make the buttons 23x22 */
2844 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2847 TOOLBAR_CalcToolbar (hwnd);
2851 info.nButtons = (INT)wParam;
2852 info.hInst = lpAddBmp->hInst;
2853 info.nID = lpAddBmp->nID;
2854 TRACE("adding %d bitmaps!\n", info.nButtons);
2857 /* check if the bitmap is already loaded and compute iSumButtons */
2859 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2861 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2862 infoPtr->bitmaps[i].nID == info.nID)
2864 iSumButtons += infoPtr->bitmaps[i].nButtons;
2867 if (!infoPtr->cimlDef) {
2868 /* create new default image list */
2869 TRACE ("creating default image list!\n");
2871 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2872 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2873 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2874 infoPtr->himlInt = himlDef;
2877 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2881 WARN("No default image list available\n");
2885 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2888 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2889 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2890 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2891 infoPtr->nNumBitmapInfos++;
2892 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2894 InvalidateRect(hwnd, NULL, TRUE);
2900 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2903 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2904 INT nAddButtons = (UINT)wParam;
2906 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2908 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2913 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2915 #define MAX_RESOURCE_STRING_LENGTH 512
2916 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2917 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2918 INT nIndex = infoPtr->nNumStrings;
2920 if ((wParam) && (HIWORD(lParam) == 0)) {
2921 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2926 TRACE("adding string from resource!\n");
2928 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2929 szString, MAX_RESOURCE_STRING_LENGTH);
2931 TRACE("len=%d %s\n", len, debugstr_w(szString));
2932 if (len == 0 || len == 1)
2935 TRACE("Delimiter: 0x%x\n", *szString);
2936 delimiter = *szString;
2939 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2941 if (next_delim + 1 >= szString + len)
2943 /* this may happen if delimiter == '\0' or if the last char is a
2944 * delimiter (then it is ignored like the native does) */
2948 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2949 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2950 infoPtr->nNumStrings++;
2956 LPWSTR p = (LPWSTR)lParam;
2961 TRACE("adding string(s) from array!\n");
2965 TRACE("len=%d %s\n", len, debugstr_w(p));
2966 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2967 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2968 infoPtr->nNumStrings++;
2975 TOOLBAR_CalcToolbar(hwnd);
2981 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2983 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2984 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2989 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2990 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2996 TRACE("adding string(s) from array!\n");
2997 nIndex = infoPtr->nNumStrings;
3000 TRACE("len=%d \"%s\"\n", len, p);
3002 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3003 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3004 infoPtr->nNumStrings++;
3010 TOOLBAR_CalcToolbar(hwnd);
3016 TOOLBAR_AutoSize (HWND hwnd)
3018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3024 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3026 parent = GetParent (hwnd);
3028 if (!parent || !infoPtr->bDoRedraw)
3031 GetClientRect(parent, &parent_rect);
3033 x = parent_rect.left;
3034 y = parent_rect.top;
3036 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3038 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3039 cx = parent_rect.right - parent_rect.left;
3041 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3043 TOOLBAR_LayoutToolbar(hwnd);
3044 InvalidateRect( hwnd, NULL, TRUE );
3047 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3050 UINT uPosFlags = SWP_NOZORDER;
3052 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3054 GetWindowRect(hwnd, &window_rect);
3055 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3056 y = window_rect.top;
3058 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3060 GetWindowRect(hwnd, &window_rect);
3061 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3064 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3065 uPosFlags |= SWP_NOMOVE;
3067 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3068 cy += GetSystemMetrics(SM_CYEDGE);
3070 if (infoPtr->dwStyle & WS_BORDER)
3072 x = y = 1; /* FIXME: this looks wrong */
3073 cy += GetSystemMetrics(SM_CYEDGE);
3074 cx += GetSystemMetrics(SM_CXEDGE);
3077 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3085 TOOLBAR_ButtonCount (HWND hwnd)
3087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 return infoPtr->nNumButtons;
3094 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam)
3096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3098 infoPtr->dwStructSize = (DWORD)wParam;
3105 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3107 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3108 TBUTTON_INFO *btnPtr;
3111 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3113 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3117 btnPtr = &infoPtr->buttons[nIndex];
3118 btnPtr->iBitmap = LOWORD(lParam);
3120 /* we HAVE to erase the background, the new bitmap could be */
3122 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3129 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3131 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3132 TBUTTON_INFO *btnPtr;
3135 BOOL bChecked = FALSE;
3137 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3139 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3144 btnPtr = &infoPtr->buttons[nIndex];
3146 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3148 if (LOWORD(lParam) == FALSE)
3149 btnPtr->fsState &= ~TBSTATE_CHECKED;
3151 if (btnPtr->fsStyle & BTNS_GROUP) {
3153 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3154 if (nOldIndex == nIndex)
3156 if (nOldIndex != -1)
3157 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3159 btnPtr->fsState |= TBSTATE_CHECKED;
3162 if( bChecked != LOWORD(lParam) )
3164 if (nOldIndex != -1)
3165 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3166 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3169 /* FIXME: Send a WM_NOTIFY?? */
3176 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam)
3178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3180 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3185 TOOLBAR_Customize (HWND hwnd)
3187 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3188 CUSTDLG_INFO custInfo;
3194 custInfo.tbInfo = infoPtr;
3195 custInfo.tbHwnd = hwnd;
3197 /* send TBN_BEGINADJUST notification */
3198 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3200 if (!(hRes = FindResourceW (COMCTL32_hModule,
3201 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3202 (LPWSTR)RT_DIALOG)))
3205 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3208 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3209 template, hwnd, TOOLBAR_CustomizeDialogProc,
3212 /* send TBN_ENDADJUST notification */
3213 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3220 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam)
3222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3223 INT nIndex = (INT)wParam;
3225 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3227 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3230 memset(&nmtb, 0, sizeof(nmtb));
3231 nmtb.iItem = btnPtr->idCommand;
3232 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3233 nmtb.tbButton.idCommand = btnPtr->idCommand;
3234 nmtb.tbButton.fsState = btnPtr->fsState;
3235 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3236 nmtb.tbButton.dwData = btnPtr->dwData;
3237 nmtb.tbButton.iString = btnPtr->iString;
3238 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3240 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3242 if (infoPtr->nNumButtons == 1) {
3243 TRACE(" simple delete!\n");
3244 Free (infoPtr->buttons);
3245 infoPtr->buttons = NULL;
3246 infoPtr->nNumButtons = 0;
3249 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3250 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3252 infoPtr->nNumButtons--;
3253 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3255 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3256 nIndex * sizeof(TBUTTON_INFO));
3259 if (nIndex < infoPtr->nNumButtons) {
3260 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3261 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3267 TOOLBAR_LayoutToolbar(hwnd);
3269 InvalidateRect (hwnd, NULL, TRUE);
3276 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3279 TBUTTON_INFO *btnPtr;
3283 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3285 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3290 btnPtr = &infoPtr->buttons[nIndex];
3292 bState = btnPtr->fsState & TBSTATE_ENABLED;
3294 /* update the toolbar button state */
3295 if(LOWORD(lParam) == FALSE) {
3296 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3298 btnPtr->fsState |= TBSTATE_ENABLED;
3301 /* redraw the button only if the state of the button changed */
3302 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3303 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3309 static inline LRESULT
3310 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3312 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3314 return infoPtr->bAnchor;
3319 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam)
3321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3324 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3328 return infoPtr->buttons[nIndex].iBitmap;
3332 static inline LRESULT
3333 TOOLBAR_GetBitmapFlags (void)
3335 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3340 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3343 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3344 INT nIndex = (INT)wParam;
3345 TBUTTON_INFO *btnPtr;
3350 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3353 btnPtr = &infoPtr->buttons[nIndex];
3354 lpTbb->iBitmap = btnPtr->iBitmap;
3355 lpTbb->idCommand = btnPtr->idCommand;
3356 lpTbb->fsState = btnPtr->fsState;
3357 lpTbb->fsStyle = btnPtr->fsStyle;
3358 lpTbb->bReserved[0] = 0;
3359 lpTbb->bReserved[1] = 0;
3360 lpTbb->dwData = btnPtr->dwData;
3361 lpTbb->iString = btnPtr->iString;
3368 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3371 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3372 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3373 TBUTTON_INFO *btnPtr;
3376 if (lpTbInfo == NULL)
3379 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3380 * the headers and tests shows that even with comctl 6 Vista accepts only the
3381 * original TBBUTTONINFO size
3383 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3385 WARN("Invalid button size\n");
3389 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3390 lpTbInfo->dwMask & 0x80000000);
3394 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3396 if (lpTbInfo->dwMask & TBIF_COMMAND)
3397 lpTbInfo->idCommand = btnPtr->idCommand;
3398 if (lpTbInfo->dwMask & TBIF_IMAGE)
3399 lpTbInfo->iImage = btnPtr->iBitmap;
3400 if (lpTbInfo->dwMask & TBIF_LPARAM)
3401 lpTbInfo->lParam = btnPtr->dwData;
3402 if (lpTbInfo->dwMask & TBIF_SIZE)
3403 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3404 if (lpTbInfo->dwMask & TBIF_STATE)
3405 lpTbInfo->fsState = btnPtr->fsState;
3406 if (lpTbInfo->dwMask & TBIF_STYLE)
3407 lpTbInfo->fsStyle = btnPtr->fsStyle;
3408 if (lpTbInfo->dwMask & TBIF_TEXT) {
3409 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3410 can't use TOOLBAR_GetText here */
3411 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3412 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3414 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3416 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3418 lpTbInfo->pszText[0] = '\0';
3425 TOOLBAR_GetButtonSize (HWND hwnd)
3427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3429 return MAKELONG((WORD)infoPtr->nButtonWidth,
3430 (WORD)infoPtr->nButtonHeight);
3435 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3444 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3448 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3450 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3451 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3456 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3463 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3467 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3471 ret = strlenW (lpText);
3474 strcpyW ((LPWSTR)lParam, lpText);
3482 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3484 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3485 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3486 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3490 static inline LRESULT
3491 TOOLBAR_GetExtendedStyle (HWND hwnd)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3497 return infoPtr->dwExStyle;
3502 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3504 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3505 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3506 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3511 TOOLBAR_GetHotItem (HWND hwnd)
3513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3515 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3518 if (infoPtr->nHotItem < 0)
3521 return (LRESULT)infoPtr->nHotItem;
3526 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3528 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3529 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3530 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3535 TOOLBAR_GetInsertMark (HWND hwnd, LPARAM lParam)
3537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3538 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3540 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3542 *lptbim = infoPtr->tbim;
3549 TOOLBAR_GetInsertMarkColor (HWND hwnd)
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3553 TRACE("hwnd = %p\n", hwnd);
3555 return (LRESULT)infoPtr->clrInsertMark;
3560 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3563 TBUTTON_INFO *btnPtr;
3567 nIndex = (INT)wParam;
3568 btnPtr = &infoPtr->buttons[nIndex];
3569 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3571 lpRect = (LPRECT)lParam;
3574 if (btnPtr->fsState & TBSTATE_HIDDEN)
3577 lpRect->left = btnPtr->rect.left;
3578 lpRect->right = btnPtr->rect.right;
3579 lpRect->bottom = btnPtr->rect.bottom;
3580 lpRect->top = btnPtr->rect.top;
3587 TOOLBAR_GetMaxSize (HWND hwnd, LPARAM lParam)
3589 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3590 LPSIZE lpSize = (LPSIZE)lParam;
3595 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3596 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3598 TRACE("maximum size %d x %d\n",
3599 infoPtr->rcBound.right - infoPtr->rcBound.left,
3600 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3606 /* << TOOLBAR_GetObject >> */
3610 TOOLBAR_GetPadding (HWND hwnd)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3615 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3616 return (LRESULT) oldPad;
3621 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3624 TBUTTON_INFO *btnPtr;
3628 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3629 btnPtr = &infoPtr->buttons[nIndex];
3630 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3632 lpRect = (LPRECT)lParam;
3636 lpRect->left = btnPtr->rect.left;
3637 lpRect->right = btnPtr->rect.right;
3638 lpRect->bottom = btnPtr->rect.bottom;
3639 lpRect->top = btnPtr->rect.top;
3646 TOOLBAR_GetRows (HWND hwnd)
3648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3650 return infoPtr->nRows;
3655 TOOLBAR_GetState (HWND hwnd, WPARAM wParam)
3657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3660 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3664 return infoPtr->buttons[nIndex].fsState;
3669 TOOLBAR_GetStyle (HWND hwnd)
3671 return GetWindowLongW(hwnd, GWL_STYLE);
3676 TOOLBAR_GetTextRows (HWND hwnd)
3678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3680 return infoPtr->nMaxTextRows;
3685 TOOLBAR_GetToolTips (HWND hwnd)
3687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3689 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3690 TOOLBAR_TooltipCreateControl(infoPtr);
3691 return (LRESULT)infoPtr->hwndToolTip;
3696 TOOLBAR_GetUnicodeFormat (HWND hwnd)
3698 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3700 TRACE("%s hwnd=%p\n",
3701 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3703 return infoPtr->bUnicode;
3707 static inline LRESULT
3708 TOOLBAR_GetVersion (HWND hwnd)
3710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3711 return infoPtr->iVersion;
3716 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3719 TBUTTON_INFO *btnPtr;
3724 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3728 btnPtr = &infoPtr->buttons[nIndex];
3729 if (LOWORD(lParam) == FALSE)
3730 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3732 btnPtr->fsState |= TBSTATE_HIDDEN;
3734 TOOLBAR_LayoutToolbar (hwnd);
3736 InvalidateRect (hwnd, NULL, TRUE);
3742 static inline LRESULT
3743 TOOLBAR_HitTest (HWND hwnd, LPARAM lParam)
3745 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3750 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3752 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3753 TBUTTON_INFO *btnPtr;
3757 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3761 btnPtr = &infoPtr->buttons[nIndex];
3762 oldState = btnPtr->fsState;
3763 if (LOWORD(lParam) == FALSE)
3764 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3766 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3768 if(oldState != btnPtr->fsState)
3769 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3776 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3778 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3779 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3780 INT nIndex = (INT)wParam;
3786 /* EPP: this seems to be an undocumented call (from my IE4)
3787 * I assume in that case that:
3788 * - index of insertion is at the end of existing buttons
3789 * I only see this happen with nIndex == -1, but it could have a special
3790 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3792 nIndex = infoPtr->nNumButtons;
3794 } else if (nIndex < 0)
3797 TRACE("inserting button index=%d\n", nIndex);
3798 if (nIndex > infoPtr->nNumButtons) {
3799 nIndex = infoPtr->nNumButtons;
3800 TRACE("adjust index=%d\n", nIndex);
3803 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3806 /* << TOOLBAR_InsertMarkHitTest >> */
3810 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam)
3812 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3815 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3819 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3824 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam)
3826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3829 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3833 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3838 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam)
3840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3843 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3847 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3852 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam)
3854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3857 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3861 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3866 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam)
3868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3871 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3875 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3880 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam)
3882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3885 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3889 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3894 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3897 tbab.hInst = (HINSTANCE)lParam;
3900 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3902 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3907 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3910 WCHAR wAccel = (WCHAR)wParam;
3911 UINT* pIDButton = (UINT*)lParam;
3912 WCHAR wszAccel[] = {'&',wAccel,0};
3915 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3916 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3918 for (i = 0; i < infoPtr->nNumButtons; i++)
3920 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3921 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3922 !(btnPtr->fsState & TBSTATE_HIDDEN))
3924 int iLen = strlenW(wszAccel);
3925 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3932 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3937 if (!strncmpiW(lpszStr, wszAccel, iLen))
3939 *pIDButton = btnPtr->idCommand;
3951 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3953 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3956 TBUTTON_INFO *btnPtr;
3958 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3960 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3964 btnPtr = &infoPtr->buttons[nIndex];
3965 oldState = btnPtr->fsState;
3968 btnPtr->fsState |= TBSTATE_MARKED;
3970 btnPtr->fsState &= ~TBSTATE_MARKED;
3972 if(oldState != btnPtr->fsState)
3973 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3979 /* fixes up an index of a button affected by a move */
3980 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3984 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3986 else if (*pIndex == nIndex)
3987 *pIndex = nMoveIndex;
3991 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3993 else if (*pIndex == nIndex)
3994 *pIndex = nMoveIndex;
4000 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4002 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4005 INT nMoveIndex = (INT)lParam;
4006 TBUTTON_INFO button;
4008 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4010 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4011 if ((nIndex == -1) || (nMoveIndex < 0))
4014 if (nMoveIndex > infoPtr->nNumButtons - 1)
4015 nMoveIndex = infoPtr->nNumButtons - 1;
4017 button = infoPtr->buttons[nIndex];
4019 /* move button right */
4020 if (nIndex < nMoveIndex)
4022 nCount = nMoveIndex - nIndex;
4023 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4024 infoPtr->buttons[nMoveIndex] = button;
4026 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4027 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4028 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4029 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4031 else if (nIndex > nMoveIndex) /* move button left */
4033 nCount = nIndex - nMoveIndex;
4034 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4035 infoPtr->buttons[nMoveIndex] = button;
4037 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4038 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4039 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4040 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4043 TOOLBAR_LayoutToolbar(hwnd);
4044 TOOLBAR_AutoSize(hwnd);
4045 InvalidateRect(hwnd, NULL, TRUE);
4052 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4055 TBUTTON_INFO *btnPtr;
4059 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4063 btnPtr = &infoPtr->buttons[nIndex];
4064 oldState = btnPtr->fsState;
4065 if (LOWORD(lParam) == FALSE)
4066 btnPtr->fsState &= ~TBSTATE_PRESSED;
4068 btnPtr->fsState |= TBSTATE_PRESSED;
4070 if(oldState != btnPtr->fsState)
4071 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4076 /* FIXME: there might still be some confusion her between number of buttons
4077 * and number of bitmaps */
4079 TOOLBAR_ReplaceBitmap (HWND hwnd, LPARAM lParam)
4081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4082 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4084 int i = 0, nOldButtons = 0, pos = 0;
4085 int nOldBitmaps, nNewBitmaps = 0;
4086 HIMAGELIST himlDef = 0;
4088 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4089 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4090 lpReplace->nButtons);
4092 if (lpReplace->hInstOld == HINST_COMMCTRL)
4094 FIXME("changing standard bitmaps not implemented\n");
4097 else if (lpReplace->hInstOld != 0)
4098 FIXME("resources not in the current module not implemented\n");
4100 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4101 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4102 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4103 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4104 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4106 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4107 nOldButtons = tbi->nButtons;
4108 tbi->nButtons = lpReplace->nButtons;
4109 tbi->hInst = lpReplace->hInstNew;
4110 tbi->nID = lpReplace->nIDNew;
4111 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4114 pos += tbi->nButtons;
4117 if (nOldButtons == 0)
4119 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4123 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4126 if (lpReplace->hInstNew)
4127 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4129 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4131 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4132 nOldBitmaps = ImageList_GetImageCount(himlDef);
4134 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4136 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4137 ImageList_Remove(himlDef, i);
4141 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4142 nNewBitmaps = ImageList_GetImageCount(himlDef);
4143 DeleteObject(hBitmap);
4146 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4148 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4149 pos, nOldBitmaps, nNewBitmaps);
4151 InvalidateRect(hwnd, NULL, TRUE);
4156 /* helper for TOOLBAR_SaveRestoreW */
4158 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4160 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4161 debugstr_w(lpSave->pszValueName));
4167 /* helper for TOOLBAR_Restore */
4169 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4173 for (i = 0; i < infoPtr->nNumButtons; i++)
4175 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4178 Free(infoPtr->buttons);
4179 infoPtr->buttons = NULL;
4180 infoPtr->nNumButtons = 0;
4184 /* helper for TOOLBAR_SaveRestoreW */
4186 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4195 /* restore toolbar information */
4196 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4197 debugstr_w(lpSave->pszValueName));
4199 memset(&nmtbr, 0, sizeof(nmtbr));
4201 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4202 KEY_QUERY_VALUE, &hkey);
4204 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4206 if (!res && dwType != REG_BINARY)
4207 res = ERROR_FILE_NOT_FOUND;
4210 nmtbr.pData = Alloc(dwSize);
4211 nmtbr.cbData = dwSize;
4212 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4215 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4216 (LPBYTE)nmtbr.pData, &dwSize);
4219 nmtbr.pCurrent = nmtbr.pData;
4221 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4222 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4224 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4228 /* remove all existing buttons as this function is designed to
4229 * restore the toolbar to a previously saved state */
4230 TOOLBAR_DeleteAllButtons(infoPtr);
4232 for (i = 0; i < nmtbr.cButtons; i++)
4235 nmtbr.tbButton.iBitmap = -1;
4236 nmtbr.tbButton.fsState = 0;
4237 nmtbr.tbButton.fsStyle = 0;
4238 nmtbr.tbButton.idCommand = 0;
4239 if (*nmtbr.pCurrent == (DWORD)-1)
4242 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4243 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4245 else if (*nmtbr.pCurrent == (DWORD)-2)
4247 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4249 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4253 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4255 /* can't contain real string as we don't know whether
4256 * the client put an ANSI or Unicode string in there */
4257 if (HIWORD(nmtbr.tbButton.iString))
4258 nmtbr.tbButton.iString = 0;
4260 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4261 (LPARAM)&nmtbr.tbButton, TRUE);
4264 /* do legacy notifications */
4265 if (infoPtr->iVersion < 5)
4267 /* FIXME: send TBN_BEGINADJUST */
4268 FIXME("send TBN_GETBUTTONINFO for each button\n");
4269 /* FIXME: send TBN_ENDADJUST */
4272 /* remove all uninitialised buttons
4273 * note: loop backwards to avoid having to fixup i on a
4275 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4276 if (infoPtr->buttons[i].iBitmap == -1)
4277 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i);
4279 /* only indicate success if at least one button survived */
4280 if (infoPtr->nNumButtons > 0) ret = TRUE;
4291 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4295 if (lpSave == NULL) return 0;
4298 return TOOLBAR_Save(lpSave);
4300 return TOOLBAR_Restore(infoPtr, lpSave);
4305 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4307 LPWSTR pszValueName = 0, pszSubKey = 0;
4308 TBSAVEPARAMSW SaveW;
4312 if (lpSave == NULL) return 0;
4314 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4315 pszSubKey = Alloc(len * sizeof(WCHAR));
4316 if (pszSubKey) goto exit;
4317 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4319 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4320 pszValueName = Alloc(len * sizeof(WCHAR));
4321 if (!pszValueName) goto exit;
4322 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4324 SaveW.pszValueName = pszValueName;
4325 SaveW.pszSubKey = pszSubKey;
4326 SaveW.hkr = lpSave->hkr;
4327 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4330 Free (pszValueName);
4338 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4341 BOOL bOldAnchor = infoPtr->bAnchor;
4343 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4345 infoPtr->bAnchor = (BOOL)wParam;
4347 /* Native does not remove the hot effect from an already hot button */
4349 return (LRESULT)bOldAnchor;
4354 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4357 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4358 short width = (short)LOWORD(lParam);
4359 short height = (short)HIWORD(lParam);
4361 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4364 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4366 /* 0 width or height is changed to 1 */
4372 if (infoPtr->nNumButtons > 0)
4373 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4374 infoPtr->nNumButtons,
4375 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4377 if (width < -1 || height < -1)
4379 /* Windows destroys the imagelist and seems to actually use negative
4380 * values to compute button sizes */
4381 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4385 /* width or height of -1 means no change */
4387 infoPtr->nBitmapWidth = width;
4389 infoPtr->nBitmapHeight = height;
4391 if ((himlDef == infoPtr->himlInt) &&
4392 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4394 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4395 infoPtr->nBitmapHeight);
4398 TOOLBAR_CalcToolbar(hwnd);
4399 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4405 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4408 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4409 TBUTTON_INFO *btnPtr;
4415 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4418 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4419 lptbbi->dwMask & 0x80000000);
4423 btnPtr = &infoPtr->buttons[nIndex];
4424 if (lptbbi->dwMask & TBIF_COMMAND)
4425 btnPtr->idCommand = lptbbi->idCommand;
4426 if (lptbbi->dwMask & TBIF_IMAGE)
4427 btnPtr->iBitmap = lptbbi->iImage;
4428 if (lptbbi->dwMask & TBIF_LPARAM)
4429 btnPtr->dwData = lptbbi->lParam;
4430 if (lptbbi->dwMask & TBIF_SIZE)
4431 btnPtr->cx = lptbbi->cx;
4432 if (lptbbi->dwMask & TBIF_STATE)
4433 btnPtr->fsState = lptbbi->fsState;
4434 if (lptbbi->dwMask & TBIF_STYLE)
4435 btnPtr->fsStyle = lptbbi->fsStyle;
4437 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4438 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4439 /* iString is index, zero it to make Str_SetPtr succeed */
4442 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4445 /* save the button rect to see if we need to redraw the whole toolbar */
4446 oldBtnRect = btnPtr->rect;
4447 TOOLBAR_LayoutToolbar(hwnd);
4449 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4450 InvalidateRect(hwnd, NULL, TRUE);
4452 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4459 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4462 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4463 TBUTTON_INFO *btnPtr;
4469 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4472 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4473 lptbbi->dwMask & 0x80000000);
4477 btnPtr = &infoPtr->buttons[nIndex];
4478 if (lptbbi->dwMask & TBIF_COMMAND)
4479 btnPtr->idCommand = lptbbi->idCommand;
4480 if (lptbbi->dwMask & TBIF_IMAGE)
4481 btnPtr->iBitmap = lptbbi->iImage;
4482 if (lptbbi->dwMask & TBIF_LPARAM)
4483 btnPtr->dwData = lptbbi->lParam;
4484 if (lptbbi->dwMask & TBIF_SIZE)
4485 btnPtr->cx = lptbbi->cx;
4486 if (lptbbi->dwMask & TBIF_STATE)
4487 btnPtr->fsState = lptbbi->fsState;
4488 if (lptbbi->dwMask & TBIF_STYLE)
4489 btnPtr->fsStyle = lptbbi->fsStyle;
4491 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4492 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4493 /* iString is index, zero it to make Str_SetPtr succeed */
4495 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4498 /* save the button rect to see if we need to redraw the whole toolbar */
4499 oldBtnRect = btnPtr->rect;
4500 TOOLBAR_LayoutToolbar(hwnd);
4502 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4503 InvalidateRect(hwnd, NULL, TRUE);
4505 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4512 TOOLBAR_SetButtonSize (HWND hwnd, LPARAM lParam)
4514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4515 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4517 if ((cx < 0) || (cy < 0))
4519 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4523 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4525 /* The documentation claims you can only change the button size before
4526 * any button has been added. But this is wrong.
4527 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4528 * it to the toolbar, and it checks that the return value is nonzero - mjm
4529 * Further testing shows that we must actually perform the change too.
4532 * The documentation also does not mention that if 0 is supplied for
4533 * either size, the system changes it to the default of 24 wide and
4534 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4536 if (cx == 0) cx = 24;
4537 if (cy == 0) cx = 22;
4539 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4540 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4542 infoPtr->nButtonWidth = cx;
4543 infoPtr->nButtonHeight = cy;
4545 infoPtr->iTopMargin = default_top_margin(infoPtr);
4546 TOOLBAR_LayoutToolbar(hwnd);
4552 TOOLBAR_SetButtonWidth (HWND hwnd, LPARAM lParam)
4554 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4556 /* if setting to current values, ignore */
4557 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4558 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4559 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4560 infoPtr->cxMin, infoPtr->cxMax);
4564 /* save new values */
4565 infoPtr->cxMin = (short)LOWORD(lParam);
4566 infoPtr->cxMax = (short)HIWORD(lParam);
4568 /* otherwise we need to recalc the toolbar and in some cases
4569 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4570 which doesn't actually draw - GA). */
4571 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4572 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4574 TOOLBAR_CalcToolbar (hwnd);
4576 InvalidateRect (hwnd, NULL, TRUE);
4583 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4586 INT nIndex = (INT)wParam;
4588 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4591 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4593 if (infoPtr->hwndToolTip) {
4595 FIXME("change tool tip!\n");
4604 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4607 HIMAGELIST himl = (HIMAGELIST)lParam;
4608 HIMAGELIST himlTemp;
4611 if (infoPtr->iVersion >= 5)
4614 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4615 &infoPtr->cimlDis, himl, id);
4617 /* FIXME: redraw ? */
4619 return (LRESULT)himlTemp;
4624 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4629 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4631 dwTemp = infoPtr->dwDTFlags;
4632 infoPtr->dwDTFlags =
4633 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4635 return (LRESULT)dwTemp;
4638 /* This function differs a bit from what MSDN says it does:
4639 * 1. lParam contains extended style flags to OR with current style
4640 * (MSDN isn't clear on the OR bit)
4641 * 2. wParam appears to contain extended style flags to be reset
4642 * (MSDN says that this parameter is reserved)
4645 TOOLBAR_SetExtendedStyle (HWND hwnd, LPARAM lParam)
4647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4650 dwOldStyle = infoPtr->dwExStyle;
4651 infoPtr->dwExStyle = (DWORD)lParam;
4653 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4655 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4656 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4657 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4659 if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4660 TOOLBAR_CalcToolbar(hwnd);
4662 TOOLBAR_LayoutToolbar(hwnd);
4664 TOOLBAR_AutoSize(hwnd);
4665 InvalidateRect(hwnd, NULL, TRUE);
4667 return (LRESULT)dwOldStyle;
4672 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4674 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4675 HIMAGELIST himlTemp;
4676 HIMAGELIST himl = (HIMAGELIST)lParam;
4679 if (infoPtr->iVersion >= 5)
4682 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4684 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4685 &infoPtr->cimlHot, himl, id);
4687 /* FIXME: redraw ? */
4689 return (LRESULT)himlTemp;
4693 /* Makes previous hot button no longer hot, makes the specified
4694 * button hot and sends appropriate notifications. dwReason is one or
4695 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4696 * NOTE 1: this function does not validate nHit
4697 * NOTE 2: the name of this function is completely made up and
4698 * not based on any documentation from Microsoft. */
4700 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4702 if (infoPtr->nHotItem != nHit)
4704 NMTBHOTITEM nmhotitem;
4705 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4707 nmhotitem.dwFlags = dwReason;
4708 if(infoPtr->nHotItem >= 0)
4710 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4711 nmhotitem.idOld = oldBtnPtr->idCommand;
4715 nmhotitem.dwFlags |= HICF_ENTERING;
4716 nmhotitem.idOld = 0;
4721 btnPtr = &infoPtr->buttons[nHit];
4722 nmhotitem.idNew = btnPtr->idCommand;
4726 nmhotitem.dwFlags |= HICF_LEAVING;
4727 nmhotitem.idNew = 0;
4730 /* now change the hot and invalidate the old and new buttons - if the
4732 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4735 oldBtnPtr->bHot = FALSE;
4736 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4738 /* setting disabled buttons as hot fails even if the notify contains the button id */
4739 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4740 btnPtr->bHot = TRUE;
4741 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4742 infoPtr->nHotItem = nHit;
4745 infoPtr->nHotItem = -1;
4751 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4754 INT nOldHotItem = infoPtr->nHotItem;
4756 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4758 if ((INT)wParam >= infoPtr->nNumButtons)
4759 return infoPtr->nHotItem;
4761 if ((INT)wParam < 0)
4764 /* NOTE: an application can still remove the hot item even if anchor
4765 * highlighting is enabled */
4767 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4769 if (nOldHotItem < 0)
4772 return (LRESULT)nOldHotItem;
4777 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4780 HIMAGELIST himlTemp;
4781 HIMAGELIST himl = (HIMAGELIST)lParam;
4782 INT oldButtonWidth = infoPtr->nButtonWidth;
4785 if (infoPtr->iVersion >= 5)
4788 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4789 &infoPtr->cimlDef, himl, id);
4791 infoPtr->nNumBitmaps = 0;
4792 for (i = 0; i < infoPtr->cimlDef; i++)
4793 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4795 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4796 &infoPtr->nBitmapHeight))
4798 infoPtr->nBitmapWidth = 1;
4799 infoPtr->nBitmapHeight = 1;
4801 TOOLBAR_CalcToolbar(hwnd);
4802 if (infoPtr->nButtonWidth < oldButtonWidth)
4803 TOOLBAR_SetButtonSize(hwnd, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4805 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4806 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4807 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4809 InvalidateRect(hwnd, NULL, TRUE);
4811 return (LRESULT)himlTemp;
4816 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam)
4818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4820 infoPtr->nIndent = (INT)wParam;
4824 /* process only on indent changing */
4825 if(infoPtr->nIndent != (INT)wParam)
4827 infoPtr->nIndent = (INT)wParam;
4828 TOOLBAR_CalcToolbar (hwnd);
4829 InvalidateRect(hwnd, NULL, FALSE);
4837 TOOLBAR_SetInsertMark (HWND hwnd, LPARAM lParam)
4839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4840 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4842 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4844 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4846 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4850 if ((lptbim->iButton == -1) ||
4851 ((lptbim->iButton < infoPtr->nNumButtons) &&
4852 (lptbim->iButton >= 0)))
4854 infoPtr->tbim = *lptbim;
4855 /* FIXME: don't need to update entire toolbar */
4856 InvalidateRect(hwnd, NULL, TRUE);
4859 ERR("Invalid button index %d\n", lptbim->iButton);
4866 TOOLBAR_SetInsertMarkColor (HWND hwnd, LPARAM lParam)
4868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4870 infoPtr->clrInsertMark = (COLORREF)lParam;
4872 /* FIXME: don't need to update entire toolbar */
4873 InvalidateRect(hwnd, NULL, TRUE);
4880 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam)
4882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4884 infoPtr->nMaxTextRows = (INT)wParam;
4886 TOOLBAR_CalcToolbar(hwnd);
4891 /* MSDN gives slightly wrong info on padding.
4892 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4893 * 2. It is not used to create a blank area between the edge of the button
4894 * and the text or image if TBSTYLE_LIST is set. It is used to control
4895 * the gap between the image and text.
4896 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4897 * to control the bottom and right borders [with the border being
4898 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4899 * is shared evenly on both sides of the button.
4900 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4903 TOOLBAR_SetPadding (HWND hwnd, LPARAM lParam)
4905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4908 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4909 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4910 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4911 TRACE("cx=%d, cy=%d\n",
4912 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4913 return (LRESULT) oldPad;
4918 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam)
4920 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4925 hwndOldNotify = infoPtr->hwndNotify;
4926 infoPtr->hwndNotify = (HWND)wParam;
4928 return (LRESULT)hwndOldNotify;
4933 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4935 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4936 LPRECT lprc = (LPRECT)lParam;
4937 int rows = LOWORD(wParam);
4938 BOOL bLarger = HIWORD(wParam);
4942 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4944 if(infoPtr->nRows != rows)
4946 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4947 int curColumn = 0; /* Current column */
4948 int curRow = 0; /* Current row */
4949 int hidden = 0; /* Number of hidden buttons */
4950 int seps = 0; /* Number of separators */
4951 int idealWrap = 0; /* Ideal wrap point */
4956 Calculate new size and wrap points - Under windows, setrows will
4957 change the dimensions if needed to show the number of requested
4958 rows (if CCS_NORESIZE is set), or will take up the whole window
4959 (if no CCS_NORESIZE).
4961 Basic algorithm - If N buttons, and y rows requested, each row
4962 contains N/y buttons.
4964 FIXME: Handling of separators not obvious from testing results
4965 FIXME: Take width of window into account?
4968 /* Loop through the buttons one by one counting key items */
4969 for (i = 0; i < infoPtr->nNumButtons; i++ )
4971 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4972 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4974 else if (btnPtr[i].fsStyle & BTNS_SEP)
4978 /* FIXME: Separators make this quite complex */
4979 if (seps) FIXME("Separators unhandled\n");
4981 /* Round up so more per line, i.e., less rows */
4982 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4984 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4985 achieve the requested number of rows. */
4986 if (bLarger && idealWrap > 1)
4988 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4989 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4991 if (resRows < rows && moreRows > rows)
4994 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
4998 curColumn = curRow = 0;
5000 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5001 infoPtr->nNumButtons, hidden, rows);
5003 for (i = 0; i < infoPtr->nNumButtons; i++ )
5005 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5008 /* Step on, wrap if necessary or flag next to wrap */
5017 if (curColumn > (idealWrap-1)) {
5019 btnPtr[i].fsState |= TBSTATE_WRAP;
5023 TRACE("Result - %d rows\n", curRow + 1);
5025 /* recalculate toolbar */
5026 TOOLBAR_CalcToolbar (hwnd);
5028 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5029 if NORESIZE is NOT set, then the toolbar will always be resized to
5030 take up the whole window. With it set, sizing needs to be manual. */
5031 if (infoPtr->dwStyle & CCS_NORESIZE) {
5032 SetWindowPos(hwnd, NULL, 0, 0,
5033 infoPtr->rcBound.right - infoPtr->rcBound.left,
5034 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5038 /* repaint toolbar */
5039 InvalidateRect(hwnd, NULL, TRUE);
5042 /* return bounding rectangle */
5044 lprc->left = infoPtr->rcBound.left;
5045 lprc->right = infoPtr->rcBound.right;
5046 lprc->top = infoPtr->rcBound.top;
5047 lprc->bottom = infoPtr->rcBound.bottom;
5055 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5057 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5058 TBUTTON_INFO *btnPtr;
5061 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5065 btnPtr = &infoPtr->buttons[nIndex];
5067 /* if hidden state has changed the invalidate entire window and recalc */
5068 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5069 btnPtr->fsState = LOWORD(lParam);
5070 TOOLBAR_CalcToolbar (hwnd);
5071 InvalidateRect(hwnd, 0, TRUE);
5075 /* process state changing if current state doesn't match new state */
5076 if(btnPtr->fsState != LOWORD(lParam))
5078 btnPtr->fsState = LOWORD(lParam);
5079 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5087 TOOLBAR_SetStyle (HWND hwnd, LPARAM lParam)
5089 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5095 static inline LRESULT
5096 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5100 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5102 infoPtr->hwndToolTip = (HWND)wParam;
5108 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
5110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5113 TRACE("%s hwnd=%p\n",
5114 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5116 bTemp = infoPtr->bUnicode;
5117 infoPtr->bUnicode = (BOOL)wParam;
5124 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5126 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5128 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5129 comctl32_color.clrBtnHighlight :
5130 infoPtr->clrBtnHighlight;
5131 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5132 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5138 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5142 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5143 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5144 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5146 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5147 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5148 InvalidateRect(hwnd, NULL, TRUE);
5154 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5156 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5157 INT iOldVersion = infoPtr->iVersion;
5159 infoPtr->iVersion = iVersion;
5161 if (infoPtr->iVersion >= 5)
5162 TOOLBAR_SetUnicodeFormat(hwnd, TRUE);
5169 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5172 WORD iString = HIWORD(wParam);
5173 WORD buffersize = LOWORD(wParam);
5174 LPSTR str = (LPSTR)lParam;
5177 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5179 if (iString < infoPtr->nNumStrings)
5181 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5184 TRACE("returning %s\n", debugstr_a(str));
5187 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5194 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5197 WORD iString = HIWORD(wParam);
5198 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5199 LPWSTR str = (LPWSTR)lParam;
5202 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5204 if (iString < infoPtr->nNumStrings)
5206 len = min(len, strlenW(infoPtr->strings[iString]));
5207 ret = (len+1)*sizeof(WCHAR);
5210 memcpy(str, infoPtr->strings[iString], ret);
5215 TRACE("returning %s\n", debugstr_w(str));
5218 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5223 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5224 * is the maximum size of the toolbar? */
5225 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5227 SIZE * pSize = (SIZE*)lParam;
5228 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5233 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5234 * caller to specify a reason why the hot item changed (rather than just the
5235 * HICF_OTHER that TB_SETHOTITEM sends). */
5237 TOOLBAR_SetHotItem2 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5240 INT nOldHotItem = infoPtr->nHotItem;
5242 TRACE("old item=%d, new item=%d, flags=%08x\n",
5243 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5245 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5248 /* NOTE: an application can still remove the hot item even if anchor
5249 * highlighting is enabled */
5251 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5255 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5258 /* Sets the toolbar global iListGap parameter which controls the amount of
5259 * spacing between the image and the text of buttons for TBSTYLE_LIST
5261 static LRESULT TOOLBAR_SetListGap(HWND hwnd, WPARAM wParam)
5263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5265 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5267 infoPtr->iListGap = (INT)wParam;
5269 InvalidateRect(hwnd, NULL, TRUE);
5274 /* Returns the number of maximum number of image lists associated with the
5275 * various states. */
5276 static LRESULT TOOLBAR_GetImageListCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
5278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5280 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5282 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5286 TOOLBAR_GetIdealSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5288 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5289 LPSIZE lpsize = (LPSIZE)lParam;
5295 * Testing shows the following:
5296 * wParam = 0 adjust cx value
5297 * = 1 set cy value to max size.
5298 * lParam pointer to SIZE structure
5301 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5302 wParam, lParam, lpsize->cx, lpsize->cy);
5306 if (lpsize->cx == -1) {
5307 /* **** this is wrong, native measures each button and sets it */
5308 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5310 else if(HIWORD(lpsize->cx)) {
5312 HWND hwndParent = GetParent(hwnd);
5314 GetWindowRect(hwnd, &rc);
5315 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5316 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5317 lpsize->cx = max(rc.right-rc.left,
5318 infoPtr->rcBound.right - infoPtr->rcBound.left);
5321 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5325 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5328 FIXME("Unknown wParam %ld\n", wParam);
5331 TRACE("set to -> 0x%08x 0x%08x\n",
5332 lpsize->cx, lpsize->cy);
5336 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5338 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5340 InvalidateRect(hwnd, NULL, TRUE);
5346 TOOLBAR_Create (HWND hwnd, LPARAM lParam)
5348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5349 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5352 TRACE("hwnd = %p\n", hwnd);
5354 /* initialize info structure */
5355 infoPtr->nButtonWidth = 23;
5356 infoPtr->nButtonHeight = 22;
5357 infoPtr->nBitmapHeight = 16;
5358 infoPtr->nBitmapWidth = 16;
5360 infoPtr->nMaxTextRows = 1;
5361 infoPtr->cxMin = -1;
5362 infoPtr->cxMax = -1;
5363 infoPtr->nNumBitmaps = 0;
5364 infoPtr->nNumStrings = 0;
5366 infoPtr->bCaptured = FALSE;
5367 infoPtr->nButtonDown = -1;
5368 infoPtr->nButtonDrag = -1;
5369 infoPtr->nOldHit = -1;
5370 infoPtr->nHotItem = -1;
5371 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5372 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5373 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5374 infoPtr->bDragOutSent = FALSE;
5375 infoPtr->iVersion = 0;
5376 infoPtr->hwndSelf = hwnd;
5377 infoPtr->bDoRedraw = TRUE;
5378 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5379 infoPtr->clrBtnShadow = CLR_DEFAULT;
5380 infoPtr->szPadding.cx = DEFPAD_CX;
5381 infoPtr->szPadding.cy = DEFPAD_CY;
5382 infoPtr->iListGap = DEFLISTGAP;
5383 infoPtr->iTopMargin = default_top_margin(infoPtr);
5384 infoPtr->dwStyle = dwStyle;
5385 infoPtr->tbim.iButton = -1;
5386 GetClientRect(hwnd, &infoPtr->client_rect);
5387 infoPtr->bUnicode = infoPtr->hwndNotify &&
5388 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5389 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5391 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5392 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5394 OpenThemeData (hwnd, themeClass);
5396 TOOLBAR_CheckStyle (hwnd, dwStyle);
5403 TOOLBAR_Destroy (HWND hwnd)
5405 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5407 /* delete tooltip control */
5408 if (infoPtr->hwndToolTip)
5409 DestroyWindow (infoPtr->hwndToolTip);
5411 /* delete temporary buffer for tooltip text */
5412 Free (infoPtr->pszTooltipText);
5413 Free (infoPtr->bitmaps); /* bitmaps list */
5415 /* delete button data */
5416 Free (infoPtr->buttons);
5418 /* delete strings */
5419 if (infoPtr->strings) {
5421 for (i = 0; i < infoPtr->nNumStrings; i++)
5422 Free (infoPtr->strings[i]);
5424 Free (infoPtr->strings);
5427 /* destroy internal image list */
5428 if (infoPtr->himlInt)
5429 ImageList_Destroy (infoPtr->himlInt);
5431 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5432 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5433 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5435 /* delete default font */
5436 DeleteObject (infoPtr->hDefaultFont);
5438 CloseThemeData (GetWindowTheme (hwnd));
5440 /* free toolbar info data */
5442 SetWindowLongPtrW (hwnd, 0, 0);
5449 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5451 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5452 NMTBCUSTOMDRAW tbcd;
5455 HTHEME theme = GetWindowTheme (hwnd);
5456 DWORD dwEraseCustDraw = 0;
5458 /* the app has told us not to redraw the toolbar */
5459 if (!infoPtr->bDoRedraw)
5462 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5463 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5464 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5465 tbcd.nmcd.hdc = (HDC)wParam;
5466 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5467 dwEraseCustDraw = ntfret & 0xffff;
5469 /* FIXME: in general the return flags *can* be or'ed together */
5470 switch (dwEraseCustDraw)
5472 case CDRF_DODEFAULT:
5474 case CDRF_SKIPDEFAULT:
5477 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5482 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5483 * to my parent for processing.
5485 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5487 HDC hdc = (HDC)wParam;
5492 parent = GetParent(hwnd);
5493 MapWindowPoints(hwnd, parent, &pt, 1);
5494 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5495 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5496 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5499 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5501 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5502 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5503 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5504 tbcd.nmcd.hdc = (HDC)wParam;
5505 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5506 dwEraseCustDraw = ntfret & 0xffff;
5507 switch (dwEraseCustDraw)
5509 case CDRF_DODEFAULT:
5511 case CDRF_SKIPDEFAULT:
5514 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5523 TOOLBAR_GetFont (HWND hwnd)
5525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5527 return (LRESULT)infoPtr->hFont;
5532 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5535 INT nNewHotItem = infoPtr->nHotItem;
5537 for (i = 0; i < infoPtr->nNumButtons; i++)
5540 if ((nNewHotItem + iDirection < 0) ||
5541 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5543 NMTBWRAPHOTITEM nmtbwhi;
5544 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5545 nmtbwhi.iDirection = iDirection;
5546 nmtbwhi.dwReason = dwReason;
5548 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5552 nNewHotItem += iDirection;
5553 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5555 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5556 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5558 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5565 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5570 nmkey.nVKey = (UINT)wParam;
5571 nmkey.uFlags = HIWORD(lParam);
5573 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5574 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5576 switch ((UINT)wParam)
5580 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5584 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5588 if ((infoPtr->nHotItem >= 0) &&
5589 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5591 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5592 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5603 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5608 pt.x = (short)LOWORD(lParam);
5609 pt.y = (short)HIWORD(lParam);
5610 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5613 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5614 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5615 TOOLBAR_Customize (hwnd);
5622 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5624 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5625 TBUTTON_INFO *btnPtr;
5630 BOOL bDragKeyPressed;
5634 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5635 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5637 bDragKeyPressed = (wParam & MK_SHIFT);
5639 if (infoPtr->hwndToolTip)
5640 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5641 WM_LBUTTONDOWN, wParam, lParam);
5643 pt.x = (short)LOWORD(lParam);
5644 pt.y = (short)HIWORD(lParam);
5645 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5647 btnPtr = &infoPtr->buttons[nHit];
5649 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5651 infoPtr->nButtonDrag = nHit;
5654 /* If drag cursor has not been loaded, load it.
5655 * Note: it doesn't need to be freed */
5657 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5658 SetCursor(hCursorDrag);
5663 infoPtr->nOldHit = nHit;
5665 CopyRect(&arrowRect, &btnPtr->rect);
5666 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5668 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5669 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5670 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5671 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5672 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5673 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5677 /* draw in pressed state */
5678 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5679 btnPtr->fsState |= TBSTATE_PRESSED;
5681 btnPtr->bDropDownPressed = TRUE;
5682 RedrawWindow(hwnd,&btnPtr->rect,0,
5683 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5685 memset(&nmtb, 0, sizeof(nmtb));
5686 nmtb.iItem = btnPtr->idCommand;
5687 nmtb.rcButton = btnPtr->rect;
5688 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5690 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5692 if (res != TBDDRET_TREATPRESSED)
5696 /* redraw button in unpressed state */
5697 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5698 btnPtr->fsState &= ~TBSTATE_PRESSED;
5700 btnPtr->bDropDownPressed = FALSE;
5701 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5703 /* find and set hot item
5704 * NOTE: native doesn't do this, but that is a bug */
5706 ScreenToClient(hwnd, &pt);
5707 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5708 if (!infoPtr->bAnchor || (nHit >= 0))
5709 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5711 /* remove any left mouse button down or double-click messages
5712 * so that we can get a toggle effect on the button */
5713 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5714 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5719 /* otherwise drop through and process as pushed */
5721 infoPtr->bCaptured = TRUE;
5722 infoPtr->nButtonDown = nHit;
5723 infoPtr->bDragOutSent = FALSE;
5725 btnPtr->fsState |= TBSTATE_PRESSED;
5727 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5729 if (btnPtr->fsState & TBSTATE_ENABLED)
5730 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5737 memset(&nmtb, 0, sizeof(nmtb));
5738 nmtb.iItem = btnPtr->idCommand;
5739 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5742 nmmouse.dwHitInfo = nHit;
5744 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5746 nmmouse.dwItemSpec = -1;
5749 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5750 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5753 ClientToScreen(hwnd, &pt);
5756 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5757 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5763 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5766 TBUTTON_INFO *btnPtr;
5774 if (infoPtr->hwndToolTip)
5775 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5776 WM_LBUTTONUP, wParam, lParam);
5778 pt.x = (short)LOWORD(lParam);
5779 pt.y = (short)HIWORD(lParam);
5780 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5782 if (!infoPtr->bAnchor || (nHit >= 0))
5783 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5785 if (infoPtr->nButtonDrag >= 0) {
5789 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5792 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5794 GetClientRect(hwnd, &rcClient);
5795 if (PtInRect(&rcClient, pt))
5802 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5805 if (nButton == infoPtr->nButtonDrag)
5807 /* if the button is moved sightly left and we have a
5808 * separator there then remove it */
5809 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5811 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5812 TOOLBAR_DeleteButton(hwnd, nButton - 1);
5814 else /* else insert a separator before the dragged button */
5817 memset(&tbb, 0, sizeof(tbb));
5818 tbb.fsStyle = BTNS_SEP;
5820 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5827 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5828 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5830 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5833 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5838 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5839 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag);
5842 /* button under cursor changed so need to re-set hot item */
5843 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5844 infoPtr->nButtonDrag = -1;
5846 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5848 else if (infoPtr->nButtonDown >= 0) {
5849 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5850 btnPtr->fsState &= ~TBSTATE_PRESSED;
5852 if (btnPtr->fsStyle & BTNS_CHECK) {
5853 if (btnPtr->fsStyle & BTNS_GROUP) {
5854 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5856 if ((nOldIndex != nHit) &&
5858 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5859 btnPtr->fsState |= TBSTATE_CHECKED;
5862 if (btnPtr->fsState & TBSTATE_CHECKED)
5863 btnPtr->fsState &= ~TBSTATE_CHECKED;
5865 btnPtr->fsState |= TBSTATE_CHECKED;
5869 if (nOldIndex != -1)
5870 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5873 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5874 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5875 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5877 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5879 infoPtr->nButtonDown = -1;
5881 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5882 TOOLBAR_SendNotify (&hdr, infoPtr,
5883 NM_RELEASEDCAPTURE);
5885 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5888 memset(&nmtb, 0, sizeof(nmtb));
5889 nmtb.iItem = btnPtr->idCommand;
5890 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5893 if (btnPtr->fsState & TBSTATE_ENABLED)
5895 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5896 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5898 /* In case we have just been destroyed... */
5904 /* !!! Undocumented - toolbar at 4.71 level and above sends
5905 * NM_CLICK with the NMMOUSE structure. */
5906 nmmouse.dwHitInfo = nHit;
5909 nmmouse.dwItemSpec = -1;
5912 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5913 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5916 ClientToScreen(hwnd, &pt);
5919 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5920 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5926 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5933 pt.x = (short)LOWORD(lParam);
5934 pt.y = (short)HIWORD(lParam);
5936 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5937 nmmouse.dwHitInfo = nHit;
5940 nmmouse.dwItemSpec = -1;
5942 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5943 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5946 ClientToScreen(hwnd, &pt);
5949 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5950 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5956 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5958 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5961 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5962 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5968 TOOLBAR_CaptureChanged(HWND hwnd)
5970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5971 TBUTTON_INFO *btnPtr;
5973 infoPtr->bCaptured = FALSE;
5975 if (infoPtr->nButtonDown >= 0)
5977 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5978 btnPtr->fsState &= ~TBSTATE_PRESSED;
5980 infoPtr->nOldHit = -1;
5982 if (btnPtr->fsState & TBSTATE_ENABLED)
5983 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5989 TOOLBAR_MouseLeave (HWND hwnd)
5991 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5993 /* don't remove hot effects when in anchor highlighting mode or when a
5994 * drop-down button is pressed */
5995 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5997 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5998 if (!hotBtnPtr->bDropDownPressed)
5999 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6002 if (infoPtr->nOldHit < 0)
6005 /* If the last button we were over is depressed then make it not */
6006 /* depressed and redraw it */
6007 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6009 TBUTTON_INFO *btnPtr;
6012 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6014 btnPtr->fsState &= ~TBSTATE_PRESSED;
6017 InflateRect (&rc1, 1, 1);
6018 InvalidateRect (hwnd, &rc1, TRUE);
6021 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6024 ZeroMemory(&nmt, sizeof(nmt));
6025 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6026 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6027 infoPtr->bDragOutSent = TRUE;
6030 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6036 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6038 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6040 TRACKMOUSEEVENT trackinfo;
6042 TBUTTON_INFO *btnPtr;
6044 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6045 TOOLBAR_TooltipCreateControl(infoPtr);
6047 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6048 /* fill in the TRACKMOUSEEVENT struct */
6049 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6050 trackinfo.dwFlags = TME_QUERY;
6052 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6053 _TrackMouseEvent(&trackinfo);
6055 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6056 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6057 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6058 trackinfo.hwndTrack = hwnd;
6060 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6061 /* and can properly deactivate the hot toolbar button */
6062 _TrackMouseEvent(&trackinfo);
6066 if (infoPtr->hwndToolTip)
6067 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6068 WM_MOUSEMOVE, wParam, lParam);
6070 pt.x = (short)LOWORD(lParam);
6071 pt.y = (short)HIWORD(lParam);
6073 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6075 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6076 && (!infoPtr->bAnchor || (nHit >= 0)))
6077 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6079 if (infoPtr->nOldHit != nHit)
6081 if (infoPtr->bCaptured)
6083 if (!infoPtr->bDragOutSent)
6086 ZeroMemory(&nmt, sizeof(nmt));
6087 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6088 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6089 infoPtr->bDragOutSent = TRUE;
6092 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6093 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6094 btnPtr->fsState &= ~TBSTATE_PRESSED;
6095 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6097 else if (nHit == infoPtr->nButtonDown) {
6098 btnPtr->fsState |= TBSTATE_PRESSED;
6099 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6101 infoPtr->nOldHit = nHit;
6109 static inline LRESULT
6110 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6112 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6113 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6115 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6119 static inline LRESULT
6120 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6122 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6123 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6125 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6130 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6132 TOOLBAR_INFO *infoPtr;
6133 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6136 /* allocate memory for info structure */
6137 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
6138 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6141 infoPtr->dwStructSize = sizeof(TBBUTTON);
6143 infoPtr->nWidth = 0;
6145 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6146 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6147 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6148 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6151 /* native control does:
6152 * Get a lot of colors and brushes
6154 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6155 * CreateFontIndirectW(adr1)
6156 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6157 * hdc = GetDC(toolbar)
6158 * GetSystemMetrics(0x48)
6159 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6160 * 0, 0, 0, 0, "MARLETT")
6161 * oldfnt = SelectObject(hdc, fnt2)
6162 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6163 * GetTextMetricsW(hdc, adr3)
6164 * SelectObject(hdc, oldfnt)
6165 * DeleteObject(fnt2)
6167 * InvalidateRect(toolbar, 0, 1)
6168 * SetWindowLongW(toolbar, 0, addr)
6169 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6172 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6173 * ie 2 0x4600094c 0x4600094c 0x4600894d
6174 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6175 * rebar 0x50008844 0x40008844 0x50008845
6176 * pager 0x50000844 0x40000844 0x50008845
6177 * IC35mgr 0x5400084e **nochange**
6178 * on entry to _NCCREATE 0x5400084e
6179 * rowlist 0x5400004e **nochange**
6180 * on entry to _NCCREATE 0x5400004e
6184 /* I think the code below is a bug, but it is the way that the native
6185 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6186 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6187 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6188 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6189 * Somehow, the only cases of this seem to be MFC programs.
6191 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6192 * does not occur in the WM_STYLECHANGING routine.
6193 * (Guy Albertelli 9/2001)
6196 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6197 && !(cs->style & TBSTYLE_TRANSPARENT))
6198 styleadd |= TBSTYLE_TRANSPARENT;
6199 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6200 styleadd |= CCS_TOP; /* default to top */
6201 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6204 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6209 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6211 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6215 if (dwStyle & WS_MINIMIZE)
6216 return 0; /* Nothing to do */
6218 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6220 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6223 if (!(dwStyle & CCS_NODIVIDER))
6225 GetWindowRect (hwnd, &rcWindow);
6226 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6227 if( dwStyle & WS_BORDER )
6228 OffsetRect (&rcWindow, 1, 1);
6229 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6232 ReleaseDC( hwnd, hdc );
6238 /* handles requests from the tooltip control on what text to display */
6239 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6241 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6243 TRACE("button index = %d\n", index);
6245 Free (infoPtr->pszTooltipText);
6246 infoPtr->pszTooltipText = NULL;
6251 if (infoPtr->bUnicode)
6253 WCHAR wszBuffer[INFOTIPSIZE+1];
6254 NMTBGETINFOTIPW tbgit;
6255 unsigned int len; /* in chars */
6257 wszBuffer[0] = '\0';
6258 wszBuffer[INFOTIPSIZE] = '\0';
6260 tbgit.pszText = wszBuffer;
6261 tbgit.cchTextMax = INFOTIPSIZE;
6262 tbgit.iItem = lpnmtdi->hdr.idFrom;
6263 tbgit.lParam = infoPtr->buttons[index].dwData;
6265 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6267 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6269 len = strlenW(tbgit.pszText);
6270 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6272 /* need to allocate temporary buffer in infoPtr as there
6273 * isn't enough space in buffer passed to us by the
6274 * tooltip control */
6275 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6276 if (infoPtr->pszTooltipText)
6278 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6279 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6285 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6291 CHAR szBuffer[INFOTIPSIZE+1];
6292 NMTBGETINFOTIPA tbgit;
6293 unsigned int len; /* in chars */
6296 szBuffer[INFOTIPSIZE] = '\0';
6298 tbgit.pszText = szBuffer;
6299 tbgit.cchTextMax = INFOTIPSIZE;
6300 tbgit.iItem = lpnmtdi->hdr.idFrom;
6301 tbgit.lParam = infoPtr->buttons[index].dwData;
6303 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6305 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6307 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6308 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6310 /* need to allocate temporary buffer in infoPtr as there
6311 * isn't enough space in buffer passed to us by the
6312 * tooltip control */
6313 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6314 if (infoPtr->pszTooltipText)
6316 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6317 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6321 else if (tbgit.pszText[0])
6323 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6324 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6329 /* if button has text, but it is not shown then automatically
6330 * use that text as tooltip */
6331 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6332 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6334 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6335 unsigned int len = pszText ? strlenW(pszText) : 0;
6337 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6339 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6341 /* need to allocate temporary buffer in infoPtr as there
6342 * isn't enough space in buffer passed to us by the
6343 * tooltip control */
6344 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6345 if (infoPtr->pszTooltipText)
6347 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6348 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6354 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6359 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6361 /* last resort: send notification on to app */
6362 /* FIXME: find out what is really used here */
6363 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6367 static inline LRESULT
6368 TOOLBAR_Notify (HWND hwnd, LPARAM lParam)
6370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6371 LPNMHDR lpnmh = (LPNMHDR)lParam;
6373 switch (lpnmh->code)
6377 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6379 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6380 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6381 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6385 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6386 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6394 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6396 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6397 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6398 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6399 lppgs->iScroll, lppgs->iDir);
6403 case TTN_GETDISPINFOW:
6404 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6406 case TTN_GETDISPINFOA:
6407 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6417 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6421 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6423 if (lParam == NF_QUERY)
6426 if (lParam == NF_REQUERY) {
6427 format = SendMessageW(infoPtr->hwndNotify,
6428 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6429 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6430 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6441 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6447 /* fill ps.rcPaint with a default rect */
6448 ps.rcPaint = infoPtr->rcBound;
6450 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6452 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6454 TOOLBAR_Refresh (hwnd, hdc, &ps);
6455 if (!wParam) EndPaint (hwnd, &ps);
6462 TOOLBAR_SetFocus (HWND hwnd)
6464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6466 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6468 /* make first item hot */
6469 if (infoPtr->nNumButtons > 0)
6470 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6476 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6480 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6483 infoPtr->hFont = infoPtr->hDefaultFont;
6485 infoPtr->hFont = (HFONT)wParam;
6487 TOOLBAR_CalcToolbar(hwnd);
6490 InvalidateRect(hwnd, NULL, TRUE);
6495 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam)
6496 /*****************************************************
6499 * Handles the WM_SETREDRAW message.
6502 * According to testing V4.71 of COMCTL32 returns the
6503 * *previous* status of the redraw flag (either 0 or 1)
6504 * instead of the MSDN documented value of 0 if handled.
6505 * (For laughs see the "consistency" with same function
6508 *****************************************************/
6510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6511 BOOL oldredraw = infoPtr->bDoRedraw;
6513 TRACE("set to %s\n",
6514 (wParam) ? "TRUE" : "FALSE");
6515 infoPtr->bDoRedraw = (BOOL) wParam;
6517 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6519 return (oldredraw) ? 1 : 0;
6524 TOOLBAR_Size (HWND hwnd)
6526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6528 TRACE("sizing toolbar!\n");
6530 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6532 RECT delta_width, delta_height, client, dummy;
6533 DWORD min_x, max_x, min_y, max_y;
6534 TBUTTON_INFO *btnPtr;
6537 GetClientRect(hwnd, &client);
6538 if(client.right > infoPtr->client_rect.right)
6540 min_x = infoPtr->client_rect.right;
6541 max_x = client.right;
6545 max_x = infoPtr->client_rect.right;
6546 min_x = client.right;
6548 if(client.bottom > infoPtr->client_rect.bottom)
6550 min_y = infoPtr->client_rect.bottom;
6551 max_y = client.bottom;
6555 max_y = infoPtr->client_rect.bottom;
6556 min_y = client.bottom;
6559 SetRect(&delta_width, min_x, 0, max_x, min_y);
6560 SetRect(&delta_height, 0, min_y, max_x, max_y);
6562 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6563 btnPtr = infoPtr->buttons;
6564 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6565 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6566 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6567 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6569 GetClientRect(hwnd, &infoPtr->client_rect);
6570 TOOLBAR_AutoSize(hwnd);
6576 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6580 if (nType == GWL_STYLE)
6582 DWORD dwOldStyle = infoPtr->dwStyle;
6584 if (lpStyle->styleNew & TBSTYLE_LIST)
6585 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6587 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6589 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6591 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6593 infoPtr->dwStyle = lpStyle->styleNew;
6595 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6596 TOOLBAR_LayoutToolbar(hwnd);
6598 /* only resize if one of the CCS_* styles was changed */
6599 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6601 TOOLBAR_AutoSize (hwnd);
6603 InvalidateRect(hwnd, NULL, TRUE);
6612 TOOLBAR_SysColorChange ()
6614 COMCTL32_RefreshSysColors();
6620 /* update theme after a WM_THEMECHANGED message */
6621 static LRESULT theme_changed (HWND hwnd)
6623 HTHEME theme = GetWindowTheme (hwnd);
6624 CloseThemeData (theme);
6625 OpenThemeData (hwnd, themeClass);
6630 static LRESULT WINAPI
6631 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6633 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6635 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6636 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6638 if (!infoPtr && (uMsg != WM_NCCREATE))
6639 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6644 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6646 case TB_ADDBUTTONSA:
6647 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6649 case TB_ADDBUTTONSW:
6650 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6653 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6656 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6659 return TOOLBAR_AutoSize (hwnd);
6661 case TB_BUTTONCOUNT:
6662 return TOOLBAR_ButtonCount (hwnd);
6664 case TB_BUTTONSTRUCTSIZE:
6665 return TOOLBAR_ButtonStructSize (hwnd, wParam);
6667 case TB_CHANGEBITMAP:
6668 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6670 case TB_CHECKBUTTON:
6671 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6673 case TB_COMMANDTOINDEX:
6674 return TOOLBAR_CommandToIndex (hwnd, wParam);
6677 return TOOLBAR_Customize (hwnd);
6679 case TB_DELETEBUTTON:
6680 return TOOLBAR_DeleteButton (hwnd, wParam);
6682 case TB_ENABLEBUTTON:
6683 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6685 case TB_GETANCHORHIGHLIGHT:
6686 return TOOLBAR_GetAnchorHighlight (hwnd);
6689 return TOOLBAR_GetBitmap (hwnd, wParam);
6691 case TB_GETBITMAPFLAGS:
6692 return TOOLBAR_GetBitmapFlags ();
6695 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6697 case TB_GETBUTTONINFOA:
6698 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6700 case TB_GETBUTTONINFOW:
6701 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6703 case TB_GETBUTTONSIZE:
6704 return TOOLBAR_GetButtonSize (hwnd);
6706 case TB_GETBUTTONTEXTA:
6707 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6709 case TB_GETBUTTONTEXTW:
6710 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6712 case TB_GETDISABLEDIMAGELIST:
6713 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6715 case TB_GETEXTENDEDSTYLE:
6716 return TOOLBAR_GetExtendedStyle (hwnd);
6718 case TB_GETHOTIMAGELIST:
6719 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6722 return TOOLBAR_GetHotItem (hwnd);
6724 case TB_GETIMAGELIST:
6725 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6727 case TB_GETINSERTMARK:
6728 return TOOLBAR_GetInsertMark (hwnd, lParam);
6730 case TB_GETINSERTMARKCOLOR:
6731 return TOOLBAR_GetInsertMarkColor (hwnd);
6733 case TB_GETITEMRECT:
6734 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6737 return TOOLBAR_GetMaxSize (hwnd, lParam);
6739 /* case TB_GETOBJECT: */ /* 4.71 */
6742 return TOOLBAR_GetPadding (hwnd);
6745 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6748 return TOOLBAR_GetRows (hwnd);
6751 return TOOLBAR_GetState (hwnd, wParam);
6754 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6757 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6760 return TOOLBAR_GetStyle (hwnd);
6762 case TB_GETTEXTROWS:
6763 return TOOLBAR_GetTextRows (hwnd);
6765 case TB_GETTOOLTIPS:
6766 return TOOLBAR_GetToolTips (hwnd);
6768 case TB_GETUNICODEFORMAT:
6769 return TOOLBAR_GetUnicodeFormat (hwnd);
6772 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6775 return TOOLBAR_HitTest (hwnd, lParam);
6777 case TB_INDETERMINATE:
6778 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6780 case TB_INSERTBUTTONA:
6781 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6783 case TB_INSERTBUTTONW:
6784 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6786 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6788 case TB_ISBUTTONCHECKED:
6789 return TOOLBAR_IsButtonChecked (hwnd, wParam);
6791 case TB_ISBUTTONENABLED:
6792 return TOOLBAR_IsButtonEnabled (hwnd, wParam);
6794 case TB_ISBUTTONHIDDEN:
6795 return TOOLBAR_IsButtonHidden (hwnd, wParam);
6797 case TB_ISBUTTONHIGHLIGHTED:
6798 return TOOLBAR_IsButtonHighlighted (hwnd, wParam);
6800 case TB_ISBUTTONINDETERMINATE:
6801 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam);
6803 case TB_ISBUTTONPRESSED:
6804 return TOOLBAR_IsButtonPressed (hwnd, wParam);
6807 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6809 case TB_MAPACCELERATORA:
6810 case TB_MAPACCELERATORW:
6811 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6814 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6817 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6819 case TB_PRESSBUTTON:
6820 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6822 case TB_REPLACEBITMAP:
6823 return TOOLBAR_ReplaceBitmap (hwnd, lParam);
6825 case TB_SAVERESTOREA:
6826 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6828 case TB_SAVERESTOREW:
6829 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6831 case TB_SETANCHORHIGHLIGHT:
6832 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6834 case TB_SETBITMAPSIZE:
6835 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6837 case TB_SETBUTTONINFOA:
6838 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6840 case TB_SETBUTTONINFOW:
6841 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6843 case TB_SETBUTTONSIZE:
6844 return TOOLBAR_SetButtonSize (hwnd, lParam);
6846 case TB_SETBUTTONWIDTH:
6847 return TOOLBAR_SetButtonWidth (hwnd, lParam);
6850 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6852 case TB_SETDISABLEDIMAGELIST:
6853 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6855 case TB_SETDRAWTEXTFLAGS:
6856 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6858 case TB_SETEXTENDEDSTYLE:
6859 return TOOLBAR_SetExtendedStyle (hwnd, lParam);
6861 case TB_SETHOTIMAGELIST:
6862 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6865 return TOOLBAR_SetHotItem (hwnd, wParam);
6867 case TB_SETIMAGELIST:
6868 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6871 return TOOLBAR_SetIndent (hwnd, wParam);
6873 case TB_SETINSERTMARK:
6874 return TOOLBAR_SetInsertMark (hwnd, lParam);
6876 case TB_SETINSERTMARKCOLOR:
6877 return TOOLBAR_SetInsertMarkColor (hwnd, lParam);
6879 case TB_SETMAXTEXTROWS:
6880 return TOOLBAR_SetMaxTextRows (hwnd, wParam);
6883 return TOOLBAR_SetPadding (hwnd, lParam);
6886 return TOOLBAR_SetParent (hwnd, wParam);
6889 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6892 return TOOLBAR_SetState (hwnd, wParam, lParam);
6895 return TOOLBAR_SetStyle (hwnd, lParam);
6897 case TB_SETTOOLTIPS:
6898 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6900 case TB_SETUNICODEFORMAT:
6901 return TOOLBAR_SetUnicodeFormat (hwnd, wParam);
6904 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6906 case TB_SETHOTITEM2:
6907 return TOOLBAR_SetHotItem2 (hwnd, wParam, lParam);
6910 return TOOLBAR_SetListGap(hwnd, wParam);
6912 case TB_GETIMAGELISTCOUNT:
6913 return TOOLBAR_GetImageListCount(hwnd, wParam, lParam);
6915 case TB_GETIDEALSIZE:
6916 return TOOLBAR_GetIdealSize (hwnd, wParam, lParam);
6919 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6921 /* Common Control Messages */
6923 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6924 case CCM_GETCOLORSCHEME:
6925 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6927 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6928 case CCM_SETCOLORSCHEME:
6929 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6931 case CCM_GETVERSION:
6932 return TOOLBAR_GetVersion (hwnd);
6934 case CCM_SETVERSION:
6935 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6941 return TOOLBAR_Create (hwnd, lParam);
6944 return TOOLBAR_Destroy (hwnd);
6947 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6950 return TOOLBAR_GetFont (hwnd);
6953 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6955 /* case WM_KILLFOCUS: */
6957 case WM_LBUTTONDBLCLK:
6958 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6960 case WM_LBUTTONDOWN:
6961 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6964 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6967 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6969 case WM_RBUTTONDBLCLK:
6970 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6973 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6976 return TOOLBAR_MouseLeave (hwnd);
6978 case WM_CAPTURECHANGED:
6979 return TOOLBAR_CaptureChanged(hwnd);
6982 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6985 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6988 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6991 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6994 return TOOLBAR_Notify (hwnd, lParam);
6996 case WM_NOTIFYFORMAT:
6997 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6999 case WM_PRINTCLIENT:
7001 return TOOLBAR_Paint (hwnd, wParam);
7004 return TOOLBAR_SetFocus (hwnd);
7007 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7010 return TOOLBAR_SetRedraw (hwnd, wParam);
7013 return TOOLBAR_Size (hwnd);
7015 case WM_STYLECHANGED:
7016 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7018 case WM_SYSCOLORCHANGE:
7019 return TOOLBAR_SysColorChange ();
7021 case WM_THEMECHANGED:
7022 return theme_changed (hwnd);
7024 /* case WM_WININICHANGE: */
7029 case WM_MEASUREITEM:
7031 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7033 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7034 case PGM_FORWARDMOUSE:
7035 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7038 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
7039 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7040 uMsg, wParam, lParam);
7041 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7047 TOOLBAR_Register (void)
7051 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7052 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7053 wndClass.lpfnWndProc = ToolbarWindowProc;
7054 wndClass.cbClsExtra = 0;
7055 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7056 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7057 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7058 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7060 RegisterClassW (&wndClass);
7065 TOOLBAR_Unregister (void)
7067 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7070 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7075 /* Check if the entry already exists */
7076 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7078 /* If this is a new entry we must create it and insert into the array */
7083 c = Alloc(sizeof(IMLENTRY));
7086 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7087 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7102 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7106 for (i = 0; i < *cies; i++)
7116 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7124 for (i = 0; i < cies; i++)
7126 if (pies[i]->id == id)
7138 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7140 HIMAGELIST himlDef = 0;
7141 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7144 himlDef = pie->himl;
7150 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7152 if (infoPtr->bUnicode)
7153 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7160 nmtba.iItem = nmtb->iItem;
7161 nmtba.pszText = Buffer;
7162 nmtba.cchText = 256;
7163 ZeroMemory(nmtba.pszText, nmtba.cchText);
7165 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7167 int ccht = strlen(nmtba.pszText);
7169 MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
7170 nmtb->pszText, nmtb->cchText);
7172 nmtb->tbButton = nmtba.tbButton;
7181 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7185 /* MSDN states that iItem is the index of the button, rather than the
7186 * command ID as used by every other NMTOOLBAR notification */
7188 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7190 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);