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 if (btnPtr[i].cx > 0)
1331 /* horizontal separators are treated as buttons for width */
1332 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1333 !(infoPtr->dwStyle & CCS_VERT))
1334 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1336 cx = infoPtr->nButtonWidth;
1338 /* Two or more adjacent separators form a separator group. */
1339 /* The first separator in a group should be wrapped to the */
1340 /* next row if the previous wrapping is on a button. */
1342 (btnPtr[i].fsStyle & BTNS_SEP) &&
1343 (i + 1 < infoPtr->nNumButtons ) &&
1344 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1346 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1347 btnPtr[i].fsState |= TBSTATE_WRAP;
1348 x = infoPtr->nIndent;
1350 bButtonWrap = FALSE;
1354 /* The layout makes sure the bitmap is visible, but not the button. */
1355 /* Test added to also wrap after a button that starts a row but */
1356 /* is bigger than the area. - GA 8/01 */
1357 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1358 > infoPtr->nWidth ) ||
1359 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1361 BOOL bFound = FALSE;
1363 /* If the current button is a separator and not hidden, */
1364 /* go to the next until it reaches a non separator. */
1365 /* Wrap the last separator if it is before a button. */
1366 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1367 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1368 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1369 i < infoPtr->nNumButtons )
1375 if( bFound && i < infoPtr->nNumButtons )
1378 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1379 i, btnPtr[i].fsStyle, x, cx);
1380 btnPtr[i].fsState |= TBSTATE_WRAP;
1381 x = infoPtr->nIndent;
1382 bButtonWrap = FALSE;
1385 else if ( i >= infoPtr->nNumButtons)
1388 /* If the current button is not a separator, find the last */
1389 /* separator and wrap it. */
1390 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1392 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1393 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1397 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1398 i, btnPtr[i].fsStyle, x, cx);
1399 x = infoPtr->nIndent;
1400 btnPtr[j].fsState |= TBSTATE_WRAP;
1401 bButtonWrap = FALSE;
1406 /* If no separator available for wrapping, wrap one of */
1407 /* non-hidden previous button. */
1411 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1413 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1418 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1419 i, btnPtr[i].fsStyle, x, cx);
1420 x = infoPtr->nIndent;
1421 btnPtr[j].fsState |= TBSTATE_WRAP;
1427 /* If all above failed, wrap the current button. */
1430 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1431 i, btnPtr[i].fsStyle, x, cx);
1432 btnPtr[i].fsState |= TBSTATE_WRAP;
1433 x = infoPtr->nIndent;
1434 if (btnPtr[i].fsStyle & BTNS_SEP )
1435 bButtonWrap = FALSE;
1441 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1442 i, btnPtr[i].fsStyle, x, cx);
1449 /***********************************************************************
1450 * TOOLBAR_MeasureButton
1452 * Calculates the width and height required for a button. Used in
1453 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1454 * the width of buttons that are autosized.
1456 * Note that it would have been rather elegant to use one piece of code for
1457 * both the laying out of the toolbar and for controlling where button parts
1458 * are drawn, but the native control has inconsistencies between the two that
1459 * prevent this from being effectively. These inconsistencies can be seen as
1460 * artefacts where parts of the button appear outside of the bounding button
1463 * There are several cases for the calculation of the button dimensions and
1464 * button part positioning:
1471 * +--------------------------------------------------------+ ^
1473 * | | pad.cy / 2 | centred | |
1474 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1475 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1476 * | |<------------>| | | | |
1477 * | +--------------+ +------------+ | |
1478 * |<-------------------------------------->| | |
1479 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1481 * +--------------------------------------------------------+ -
1482 * <-------------------------------------------------------->
1483 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1485 * Without Bitmap (I_IMAGENONE):
1487 * +-----------------------------------+ ^
1489 * | | centred | | LISTPAD_CY +
1490 * | +------------+ | | szText.cy
1493 * | +------------+ | |
1494 * |<----------------->| | |
1495 * | cxedge |<-----------> | |
1497 * +-----------------------------------+ -
1498 * <----------------------------------->
1499 * szText.cx + pad.cx
1503 * +--------------------------------------+ ^
1505 * | | padding.cy/2 | | DEFPAD_CY +
1506 * | +------------+ | | nBitmapHeight
1509 * | +------------+ | |
1510 * |<------------------->| | |
1511 * | cxedge + iListGap/2 |<-----------> | |
1512 * | nBitmapWidth | |
1513 * +--------------------------------------+ -
1514 * <-------------------------------------->
1515 * 2*cxedge + nBitmapWidth + iListGap
1522 * +-----------------------------------+ ^
1524 * | | pad.cy / 2 | | nBitmapHeight +
1525 * | - | | szText.cy +
1526 * | +------------+ | | DEFPAD_CY + 1
1527 * | centred | Bitmap | | |
1528 * |<----------------->| | | |
1529 * | +------------+ | |
1533 * | centred +---------------+ | |
1534 * |<--------------->| Text | | |
1535 * | +---------------+ | |
1536 * +-----------------------------------+ -
1537 * <----------------------------------->
1538 * pad.cx + max(nBitmapWidth, szText.cx)
1540 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1542 * +---------------------------------------+ ^
1544 * | | 2 + pad.cy / 2 | |
1545 * | - | | szText.cy +
1546 * | centred +-----------------+ | | pad.cy + 2
1547 * |<--------------->| Text | | |
1548 * | +-----------------+ | |
1550 * +---------------------------------------+ -
1551 * <--------------------------------------->
1552 * 2*cxedge + pad.cx + szText.cx
1555 * As for with bitmaps, but with szText.cx zero.
1557 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1558 BOOL bHasBitmap, BOOL bValidImageList)
1561 if (infoPtr->dwStyle & TBSTYLE_LIST)
1563 /* set button height from bitmap / text height... */
1564 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1567 /* ... add on the necessary padding */
1568 if (bValidImageList)
1571 sizeButton.cy += DEFPAD_CY;
1573 sizeButton.cy += LISTPAD_CY;
1576 sizeButton.cy += infoPtr->szPadding.cy;
1578 /* calculate button width */
1579 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1580 infoPtr->nBitmapWidth + infoPtr->iListGap;
1581 if (sizeString.cx > 0)
1582 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1589 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1590 if (sizeString.cy > 0)
1591 sizeButton.cy += 1 + sizeString.cy;
1592 sizeButton.cx = infoPtr->szPadding.cx +
1593 max(sizeString.cx, infoPtr->nBitmapWidth);
1597 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1598 NONLIST_NOTEXT_OFFSET;
1599 sizeButton.cx = infoPtr->szPadding.cx +
1600 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1607 /***********************************************************************
1608 * TOOLBAR_CalcToolbar
1610 * This function calculates button and separator placement. It first
1611 * calculates the button sizes, gets the toolbar window width and then
1612 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1613 * on. It assigns a new location to each item and sends this location to
1614 * the tooltip window if appropriate. Finally, it updates the rcBound
1615 * rect and calculates the new required toolbar window height.
1618 TOOLBAR_CalcToolbar (HWND hwnd)
1620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1621 SIZE sizeString, sizeButton;
1622 BOOL validImageList = FALSE;
1624 TOOLBAR_CalcStrings (hwnd, &sizeString);
1626 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1628 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1629 validImageList = TRUE;
1630 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1631 infoPtr->nButtonWidth = sizeButton.cx;
1632 infoPtr->nButtonHeight = sizeButton.cy;
1633 infoPtr->iTopMargin = default_top_margin(infoPtr);
1635 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1636 infoPtr->nButtonWidth = infoPtr->cxMin;
1637 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1638 infoPtr->nButtonWidth = infoPtr->cxMax;
1640 TOOLBAR_LayoutToolbar(hwnd);
1644 TOOLBAR_LayoutToolbar(HWND hwnd)
1646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1647 TBUTTON_INFO *btnPtr;
1649 INT i, nRows, nSepRows;
1652 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1653 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1655 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1657 x = infoPtr->nIndent;
1658 y = infoPtr->iTopMargin;
1659 cx = infoPtr->nButtonWidth;
1660 cy = infoPtr->nButtonHeight;
1662 nRows = nSepRows = 0;
1664 infoPtr->rcBound.top = y;
1665 infoPtr->rcBound.left = x;
1666 infoPtr->rcBound.bottom = y + cy;
1667 infoPtr->rcBound.right = x;
1669 btnPtr = infoPtr->buttons;
1671 TRACE("cy=%d\n", cy);
1673 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1676 if (btnPtr->fsState & TBSTATE_HIDDEN)
1678 SetRectEmpty (&btnPtr->rect);
1682 cy = infoPtr->nButtonHeight;
1684 if (btnPtr->fsStyle & BTNS_SEP) {
1685 if (infoPtr->dwStyle & CCS_VERT) {
1686 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1687 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nWidth;
1690 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1691 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1697 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1698 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1705 hOldFont = SelectObject (hdc, infoPtr->hFont);
1707 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1709 SelectObject (hdc, hOldFont);
1710 ReleaseDC (hwnd, hdc);
1712 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1713 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1718 cx = infoPtr->nButtonWidth;
1720 /* if size has been set manually then don't add on extra space
1721 * for the drop down arrow */
1722 if (!btnPtr->cx && hasDropDownArrows &&
1723 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1724 cx += DDARROW_WIDTH;
1726 if (btnPtr->fsState & TBSTATE_WRAP )
1729 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1731 if (infoPtr->rcBound.left > x)
1732 infoPtr->rcBound.left = x;
1733 if (infoPtr->rcBound.right < x + cx)
1734 infoPtr->rcBound.right = x + cx;
1735 if (infoPtr->rcBound.bottom < y + cy)
1736 infoPtr->rcBound.bottom = y + cy;
1738 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1740 /* btnPtr->nRow is zero based. The space between the rows is */
1741 /* also considered as a row. */
1742 btnPtr->nRow = nRows + nSepRows;
1744 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1745 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1750 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1754 if ( !(infoPtr->dwStyle & CCS_VERT))
1755 y += cy + ( (btnPtr->cx > 0 ) ?
1756 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1760 /* nSepRows is used to calculate the extra height following */
1764 x = infoPtr->nIndent;
1766 /* Increment row number unless this is the last button */
1767 /* and it has Wrap set. */
1768 if (i != infoPtr->nNumButtons-1)
1775 /* infoPtr->nRows is the number of rows on the toolbar */
1776 infoPtr->nRows = nRows + nSepRows + 1;
1778 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1783 TOOLBAR_InternalHitTest (HWND hwnd, const POINT *lpPt)
1785 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1786 TBUTTON_INFO *btnPtr;
1789 btnPtr = infoPtr->buttons;
1790 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1791 if (btnPtr->fsState & TBSTATE_HIDDEN)
1794 if (btnPtr->fsStyle & BTNS_SEP) {
1795 if (PtInRect (&btnPtr->rect, *lpPt)) {
1796 TRACE(" ON SEPARATOR %d!\n", i);
1801 if (PtInRect (&btnPtr->rect, *lpPt)) {
1802 TRACE(" ON BUTTON %d!\n", i);
1808 TRACE(" NOWHERE!\n");
1809 return TOOLBAR_NOWHERE;
1813 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1815 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, TBBUTTON *lpTbb, BOOL fUnicode)
1817 INT nOldButtons, nNewButtons, iButton;
1818 BOOL fHasString = FALSE;
1820 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1821 iIndex = infoPtr->nNumButtons;
1823 nOldButtons = infoPtr->nNumButtons;
1824 nNewButtons = nOldButtons + nAddButtons;
1826 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1827 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1828 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1829 infoPtr->nNumButtons += nAddButtons;
1831 /* insert new buttons data */
1832 for (iButton = 0; iButton < nAddButtons; iButton++) {
1833 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1835 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1837 ZeroMemory(btnPtr, sizeof(*btnPtr));
1839 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1840 btnPtr->idCommand = lpTbb[iButton].idCommand;
1841 btnPtr->fsState = lpTbb[iButton].fsState;
1842 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1843 btnPtr->dwData = lpTbb[iButton].dwData;
1844 if(HIWORD(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1847 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1849 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1853 btnPtr->iString = lpTbb[iButton].iString;
1855 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1858 if (infoPtr->nNumStrings > 0 || fHasString)
1859 TOOLBAR_CalcToolbar(infoPtr->hwndSelf);
1861 TOOLBAR_LayoutToolbar(infoPtr->hwndSelf);
1862 TOOLBAR_AutoSize(infoPtr->hwndSelf);
1864 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1865 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1871 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1873 TBUTTON_INFO *btnPtr;
1876 if (CommandIsIndex) {
1877 TRACE("command is really index command=%d\n", idCommand);
1878 if (idCommand >= infoPtr->nNumButtons) return -1;
1881 btnPtr = infoPtr->buttons;
1882 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1883 if (btnPtr->idCommand == idCommand) {
1884 TRACE("command=%d index=%d\n", idCommand, i);
1888 TRACE("no index found for command=%d\n", idCommand);
1894 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1896 TBUTTON_INFO *btnPtr;
1899 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1902 /* check index button */
1903 btnPtr = &infoPtr->buttons[nIndex];
1904 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1905 if (btnPtr->fsState & TBSTATE_CHECKED)
1909 /* check previous buttons */
1910 nRunIndex = nIndex - 1;
1911 while (nRunIndex >= 0) {
1912 btnPtr = &infoPtr->buttons[nRunIndex];
1913 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1914 if (btnPtr->fsState & TBSTATE_CHECKED)
1922 /* check next buttons */
1923 nRunIndex = nIndex + 1;
1924 while (nRunIndex < infoPtr->nNumButtons) {
1925 btnPtr = &infoPtr->buttons[nRunIndex];
1926 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1927 if (btnPtr->fsState & TBSTATE_CHECKED)
1940 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1941 WPARAM wParam, LPARAM lParam)
1947 msg.wParam = wParam;
1948 msg.lParam = lParam;
1949 msg.time = GetMessageTime ();
1950 msg.pt.x = (short)LOWORD(GetMessagePos ());
1951 msg.pt.y = (short)HIWORD(GetMessagePos ());
1953 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1957 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1959 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1962 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1963 ti.cbSize = sizeof (TTTOOLINFOW);
1964 ti.hwnd = infoPtr->hwndSelf;
1965 ti.uId = button->idCommand;
1967 ti.lpszText = LPSTR_TEXTCALLBACKW;
1968 /* ti.lParam = random value from the stack? */
1970 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1976 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1978 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1981 ZeroMemory(&ti, sizeof(ti));
1982 ti.cbSize = sizeof(ti);
1983 ti.hwnd = infoPtr->hwndSelf;
1984 ti.uId = button->idCommand;
1986 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1990 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1992 /* Set the toolTip only for non-hidden, non-separator button */
1993 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1997 ZeroMemory(&ti, sizeof(ti));
1998 ti.cbSize = sizeof(ti);
1999 ti.hwnd = infoPtr->hwndSelf;
2000 ti.uId = button->idCommand;
2001 ti.rect = button->rect;
2002 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2006 /* Creates the tooltip control */
2008 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2011 NMTOOLTIPSCREATED nmttc;
2013 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2014 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2015 infoPtr->hwndSelf, 0, 0, 0);
2017 if (!infoPtr->hwndToolTip)
2020 /* Send NM_TOOLTIPSCREATED notification */
2021 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2022 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2024 for (i = 0; i < infoPtr->nNumButtons; i++)
2026 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2027 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2031 /* keeps available button list box sorted by button id */
2032 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2036 PCUSTOMBUTTON btnInfo;
2037 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2039 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2041 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2043 /* position 0 is always separator */
2044 for (i = 1; i < count; i++)
2046 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2047 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2049 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2050 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2054 /* id higher than all others add to end */
2055 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2056 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2059 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2063 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2065 if (nIndexFrom == nIndexTo)
2068 /* MSDN states that iItem is the index of the button, rather than the
2069 * command ID as used by every other NMTOOLBAR notification */
2070 nmtb.iItem = nIndexFrom;
2071 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2073 PCUSTOMBUTTON btnInfo;
2075 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2076 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2078 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2080 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2081 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2082 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2083 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2086 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2088 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2090 /* last item is always separator, so -2 instead of -1 */
2091 if (nIndexTo >= (count - 2))
2092 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2094 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2096 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2097 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2099 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2103 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2107 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2109 /* MSDN states that iItem is the index of the button, rather than the
2110 * command ID as used by every other NMTOOLBAR notification */
2111 nmtb.iItem = nIndexAvail;
2112 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2114 PCUSTOMBUTTON btnInfo;
2116 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2117 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2118 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2120 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2122 if (nIndexAvail != 0) /* index == 0 indicates separator */
2124 /* remove from 'available buttons' list */
2125 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2126 if (nIndexAvail == count-1)
2127 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2129 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2133 PCUSTOMBUTTON btnNew;
2135 /* duplicate 'separator' button */
2136 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2141 /* insert into 'toolbar button' list */
2142 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2143 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2145 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2147 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2151 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2153 PCUSTOMBUTTON btnInfo;
2154 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2156 TRACE("Remove: index %d\n", index);
2158 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2160 /* send TBN_QUERYDELETE notification */
2161 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2165 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2166 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2168 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2170 /* insert into 'available button' list */
2171 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2172 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2176 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2180 /* drag list notification function for toolbar buttons list box */
2181 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2182 const DRAGLISTINFO *pDLI)
2184 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2185 switch (pDLI->uNotification)
2189 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2190 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2191 /* no dragging for last item (separator) */
2192 if (nCurrentItem >= (nCount - 1)) return FALSE;
2197 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2198 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2199 /* no dragging past last item (separator) */
2200 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2202 DrawInsert(hwnd, hwndList, nCurrentItem);
2203 /* FIXME: native uses "move button" cursor */
2204 return DL_COPYCURSOR;
2207 /* not over toolbar buttons list */
2208 if (nCurrentItem < 0)
2210 POINT ptWindow = pDLI->ptCursor;
2211 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2212 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2213 /* over available buttons list? */
2214 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2215 /* FIXME: native uses "move button" cursor */
2216 return DL_COPYCURSOR;
2218 /* clear drag arrow */
2219 DrawInsert(hwnd, hwndList, -1);
2220 return DL_STOPCURSOR;
2224 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2225 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2226 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2227 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2229 /* clear drag arrow */
2230 DrawInsert(hwnd, hwndList, -1);
2232 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2234 /* not over toolbar buttons list */
2237 POINT ptWindow = pDLI->ptCursor;
2238 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2239 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2240 /* over available buttons list? */
2241 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2242 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2247 /* Clear drag arrow */
2248 DrawInsert(hwnd, hwndList, -1);
2255 /* drag list notification function for available buttons list box */
2256 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2257 const DRAGLISTINFO *pDLI)
2259 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2260 switch (pDLI->uNotification)
2266 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2267 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2268 /* no dragging past last item (separator) */
2269 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2271 DrawInsert(hwnd, hwndList, nCurrentItem);
2272 /* FIXME: native uses "move button" cursor */
2273 return DL_COPYCURSOR;
2276 /* not over toolbar buttons list */
2277 if (nCurrentItem < 0)
2279 POINT ptWindow = pDLI->ptCursor;
2280 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2281 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2282 /* over available buttons list? */
2283 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2284 /* FIXME: native uses "move button" cursor */
2285 return DL_COPYCURSOR;
2287 /* clear drag arrow */
2288 DrawInsert(hwnd, hwndList, -1);
2289 return DL_STOPCURSOR;
2293 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2294 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2295 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2296 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2298 /* clear drag arrow */
2299 DrawInsert(hwnd, hwndList, -1);
2301 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2305 /* Clear drag arrow */
2306 DrawInsert(hwnd, hwndList, -1);
2312 extern UINT uDragListMessage;
2314 /***********************************************************************
2315 * TOOLBAR_CustomizeDialogProc
2316 * This function implements the toolbar customization dialog.
2318 static INT_PTR CALLBACK
2319 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2321 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2322 PCUSTOMBUTTON btnInfo;
2324 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2329 custInfo = (PCUSTDLG_INFO)lParam;
2330 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2337 NMTBINITCUSTOMIZE nmtbic;
2339 infoPtr = custInfo->tbInfo;
2341 /* send TBN_QUERYINSERT notification */
2342 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2344 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2347 nmtbic.hwndDialog = hwnd;
2348 /* Send TBN_INITCUSTOMIZE notification */
2349 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2352 TRACE("TBNRF_HIDEHELP requested\n");
2353 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2356 /* add items to 'toolbar buttons' list and check if removable */
2357 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2359 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2360 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2361 btnInfo->btn.fsStyle = BTNS_SEP;
2362 btnInfo->bVirtual = FALSE;
2363 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2365 /* send TBN_QUERYDELETE notification */
2366 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2368 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2369 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2372 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2374 /* insert separator button into 'available buttons' list */
2375 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2376 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2377 btnInfo->btn.fsStyle = BTNS_SEP;
2378 btnInfo->bVirtual = FALSE;
2379 btnInfo->bRemovable = TRUE;
2380 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2381 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2382 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2384 /* insert all buttons into dsa */
2387 /* send TBN_GETBUTTONINFO notification */
2390 nmtb.pszText = Buffer;
2393 /* Clear previous button's text */
2394 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2396 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2399 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2400 nmtb.tbButton.fsStyle, i,
2401 nmtb.tbButton.idCommand,
2402 nmtb.tbButton.iString,
2403 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2406 /* insert button into the apropriate list */
2407 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2410 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2411 btnInfo->bVirtual = FALSE;
2412 btnInfo->bRemovable = TRUE;
2416 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2417 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2420 btnInfo->btn = nmtb.tbButton;
2421 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2423 if (lstrlenW(nmtb.pszText))
2424 lstrcpyW(btnInfo->text, nmtb.pszText);
2425 else if (nmtb.tbButton.iString >= 0 &&
2426 nmtb.tbButton.iString < infoPtr->nNumStrings)
2428 lstrcpyW(btnInfo->text,
2429 infoPtr->strings[nmtb.tbButton.iString]);
2434 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2437 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2439 /* select first item in the 'available' list */
2440 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2442 /* append 'virtual' separator button to the 'toolbar buttons' list */
2443 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2444 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2445 btnInfo->btn.fsStyle = BTNS_SEP;
2446 btnInfo->bVirtual = TRUE;
2447 btnInfo->bRemovable = FALSE;
2448 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2449 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2450 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2452 /* select last item in the 'toolbar' list */
2453 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2454 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2456 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2457 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2459 /* set focus and disable buttons */
2460 PostMessageW (hwnd, WM_USER, 0, 0);
2465 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2466 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2468 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2472 EndDialog(hwnd, FALSE);
2476 switch (LOWORD(wParam))
2478 case IDC_TOOLBARBTN_LBOX:
2479 if (HIWORD(wParam) == LBN_SELCHANGE)
2481 PCUSTOMBUTTON btnInfo;
2486 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2487 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2489 /* send TBN_QUERYINSERT notification */
2491 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2493 /* get list box item */
2494 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2496 if (index == (count - 1))
2498 /* last item (virtual separator) */
2499 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2500 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2502 else if (index == (count - 2))
2504 /* second last item (last non-virtual item) */
2505 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2506 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2508 else if (index == 0)
2511 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2512 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2516 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2517 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2520 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2524 case IDC_MOVEUP_BTN:
2526 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2527 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2531 case IDC_MOVEDN_BTN: /* move down */
2533 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2534 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2538 case IDC_REMOVE_BTN: /* remove button */
2540 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2542 if (LB_ERR == index)
2545 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2549 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2552 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2555 case IDOK: /* Add button */
2560 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2561 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2563 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2568 EndDialog(hwnd, FALSE);
2578 /* delete items from 'toolbar buttons' listbox*/
2579 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2580 for (i = 0; i < count; i++)
2582 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2584 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2586 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2589 /* delete items from 'available buttons' listbox*/
2590 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2591 for (i = 0; i < count; i++)
2593 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2595 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2597 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2602 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2604 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2609 COLORREF oldText = 0;
2613 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2614 if (btnInfo == NULL)
2616 FIXME("btnInfo invalid!\n");
2620 /* set colors and select objects */
2621 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2622 if (btnInfo->bVirtual)
2623 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2625 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2626 hPen = CreatePen( PS_SOLID, 1,
2627 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2628 hOldPen = SelectObject (lpdis->hDC, hPen );
2629 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2631 /* fill background rectangle */
2632 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2633 lpdis->rcItem.right, lpdis->rcItem.bottom);
2635 /* calculate button and text rectangles */
2636 CopyRect (&rcButton, &lpdis->rcItem);
2637 InflateRect (&rcButton, -1, -1);
2638 CopyRect (&rcText, &rcButton);
2639 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2640 rcText.left = rcButton.right + 2;
2642 /* draw focus rectangle */
2643 if (lpdis->itemState & ODS_FOCUS)
2644 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2647 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2648 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2650 /* draw image and text */
2651 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2652 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2653 btnInfo->btn.iBitmap));
2654 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2655 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2657 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2658 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2660 /* delete objects and reset colors */
2661 SelectObject (lpdis->hDC, hOldBrush);
2662 SelectObject (lpdis->hDC, hOldPen);
2663 SetBkColor (lpdis->hDC, oldBk);
2664 SetTextColor (lpdis->hDC, oldText);
2665 DeleteObject( hPen );
2670 case WM_MEASUREITEM:
2671 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2673 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2675 lpmis->itemHeight = 15 + 8; /* default height */
2682 if (uDragListMessage && (uMsg == uDragListMessage))
2684 if (wParam == IDC_TOOLBARBTN_LBOX)
2686 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2687 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2688 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2691 else if (wParam == IDC_AVAILBTN_LBOX)
2693 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2694 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2695 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2704 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2707 INT nCountBefore = ImageList_GetImageCount(himlDef);
2713 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2714 /* Add bitmaps to the default image list */
2715 if (bitmap->hInst == NULL) /* a handle was passed */
2716 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2718 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2720 /* enlarge the bitmap if needed */
2721 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2722 if (bitmap->hInst != COMCTL32_hModule)
2723 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2725 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2726 DeleteObject(hbmLoad);
2730 nCountAfter = ImageList_GetImageCount(himlDef);
2731 nAdded = nCountAfter - nCountBefore;
2732 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2734 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2735 } else if (nAdded > (INT)bitmap->nButtons) {
2736 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2737 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2740 infoPtr->nNumBitmaps += nAdded;
2745 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2752 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2753 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2755 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2757 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2760 TRACE("Update icon size: %dx%d -> %dx%d\n",
2761 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2763 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2764 ILC_COLORDDB|ILC_MASK, 8, 2);
2765 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2766 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2767 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2768 infoPtr->himlInt = himlNew;
2770 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2771 ImageList_Destroy(himlDef);
2774 /***********************************************************************
2775 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2779 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2781 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2782 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2787 TRACE("hwnd=%p wParam=%lx lParam=%lx\n", hwnd, wParam, lParam);
2791 if (lpAddBmp->hInst == HINST_COMMCTRL)
2793 info.hInst = COMCTL32_hModule;
2794 switch (lpAddBmp->nID)
2796 case IDB_STD_SMALL_COLOR:
2798 info.nID = IDB_STD_SMALL;
2800 case IDB_STD_LARGE_COLOR:
2802 info.nID = IDB_STD_LARGE;
2804 case IDB_VIEW_SMALL_COLOR:
2806 info.nID = IDB_VIEW_SMALL;
2808 case IDB_VIEW_LARGE_COLOR:
2810 info.nID = IDB_VIEW_LARGE;
2812 case IDB_HIST_SMALL_COLOR:
2814 info.nID = IDB_HIST_SMALL;
2816 case IDB_HIST_LARGE_COLOR:
2818 info.nID = IDB_HIST_LARGE;
2824 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2826 /* Windows resize all the buttons to the size of a newly added standard image */
2827 if (lpAddBmp->nID & 1)
2829 /* large icons: 24x24. Will make the button 31x30 */
2830 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2834 /* small icons: 16x16. Will make the buttons 23x22 */
2835 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2838 TOOLBAR_CalcToolbar (hwnd);
2842 info.nButtons = (INT)wParam;
2843 info.hInst = lpAddBmp->hInst;
2844 info.nID = lpAddBmp->nID;
2845 TRACE("adding %d bitmaps!\n", info.nButtons);
2848 /* check if the bitmap is already loaded and compute iSumButtons */
2850 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2852 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2853 infoPtr->bitmaps[i].nID == info.nID)
2855 iSumButtons += infoPtr->bitmaps[i].nButtons;
2858 if (!infoPtr->cimlDef) {
2859 /* create new default image list */
2860 TRACE ("creating default image list!\n");
2862 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2863 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2864 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2865 infoPtr->himlInt = himlDef;
2868 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2872 WARN("No default image list available\n");
2876 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2879 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2880 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2881 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2882 infoPtr->nNumBitmapInfos++;
2883 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2885 InvalidateRect(hwnd, NULL, TRUE);
2891 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2894 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2895 INT nAddButtons = (UINT)wParam;
2897 TRACE("adding %ld buttons (unicode=%d)!\n", wParam, fUnicode);
2899 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2904 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2906 #define MAX_RESOURCE_STRING_LENGTH 512
2907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2908 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2909 INT nIndex = infoPtr->nNumStrings;
2911 if ((wParam) && (HIWORD(lParam) == 0)) {
2912 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2917 TRACE("adding string from resource!\n");
2919 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2920 szString, MAX_RESOURCE_STRING_LENGTH);
2922 TRACE("len=%d %s\n", len, debugstr_w(szString));
2923 if (len == 0 || len == 1)
2926 TRACE("Delimiter: 0x%x\n", *szString);
2927 delimiter = *szString;
2930 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2932 if (next_delim + 1 >= szString + len)
2934 /* this may happen if delimiter == '\0' or if the last char is a
2935 * delimiter (then it is ignored like the native does) */
2939 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2940 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2941 infoPtr->nNumStrings++;
2947 LPWSTR p = (LPWSTR)lParam;
2952 TRACE("adding string(s) from array!\n");
2956 TRACE("len=%d %s\n", len, debugstr_w(p));
2957 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2958 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2959 infoPtr->nNumStrings++;
2966 TOOLBAR_CalcToolbar(hwnd);
2972 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2975 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2980 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2981 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2987 TRACE("adding string(s) from array!\n");
2988 nIndex = infoPtr->nNumStrings;
2991 TRACE("len=%d \"%s\"\n", len, p);
2993 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2994 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2995 infoPtr->nNumStrings++;
3001 TOOLBAR_CalcToolbar(hwnd);
3007 TOOLBAR_AutoSize (HWND hwnd)
3009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3015 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3017 parent = GetParent (hwnd);
3019 if (!parent || !infoPtr->bDoRedraw)
3022 GetClientRect(parent, &parent_rect);
3024 x = parent_rect.left;
3025 y = parent_rect.top;
3027 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3029 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3030 cx = parent_rect.right - parent_rect.left;
3032 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3034 TOOLBAR_LayoutToolbar(hwnd);
3035 InvalidateRect( hwnd, NULL, TRUE );
3038 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3041 UINT uPosFlags = SWP_NOZORDER;
3043 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3045 GetWindowRect(hwnd, &window_rect);
3046 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3047 y = window_rect.top;
3049 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3051 GetWindowRect(hwnd, &window_rect);
3052 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3055 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3056 uPosFlags |= SWP_NOMOVE;
3058 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3059 cy += GetSystemMetrics(SM_CYEDGE);
3061 if (infoPtr->dwStyle & WS_BORDER)
3063 x = y = 1; /* FIXME: this looks wrong */
3064 cy += GetSystemMetrics(SM_CYEDGE);
3065 cx += GetSystemMetrics(SM_CXEDGE);
3068 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3076 TOOLBAR_ButtonCount (HWND hwnd)
3078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3080 return infoPtr->nNumButtons;
3085 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam)
3087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 infoPtr->dwStructSize = (DWORD)wParam;
3096 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 TBUTTON_INFO *btnPtr;
3102 TRACE("button %ld, iBitmap now %d\n", wParam, LOWORD(lParam));
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3108 btnPtr = &infoPtr->buttons[nIndex];
3109 btnPtr->iBitmap = LOWORD(lParam);
3111 /* we HAVE to erase the background, the new bitmap could be */
3113 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3120 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3123 TBUTTON_INFO *btnPtr;
3126 BOOL bChecked = FALSE;
3128 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3130 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3135 btnPtr = &infoPtr->buttons[nIndex];
3137 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3139 if (LOWORD(lParam) == FALSE)
3140 btnPtr->fsState &= ~TBSTATE_CHECKED;
3142 if (btnPtr->fsStyle & BTNS_GROUP) {
3144 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3145 if (nOldIndex == nIndex)
3147 if (nOldIndex != -1)
3148 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3150 btnPtr->fsState |= TBSTATE_CHECKED;
3153 if( bChecked != LOWORD(lParam) )
3155 if (nOldIndex != -1)
3156 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3157 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3160 /* FIXME: Send a WM_NOTIFY?? */
3167 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam)
3169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3171 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3176 TOOLBAR_Customize (HWND hwnd)
3178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3179 CUSTDLG_INFO custInfo;
3185 custInfo.tbInfo = infoPtr;
3186 custInfo.tbHwnd = hwnd;
3188 /* send TBN_BEGINADJUST notification */
3189 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3191 if (!(hRes = FindResourceW (COMCTL32_hModule,
3192 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3193 (LPWSTR)RT_DIALOG)))
3196 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3199 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3200 template, hwnd, TOOLBAR_CustomizeDialogProc,
3203 /* send TBN_ENDADJUST notification */
3204 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3211 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam)
3213 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3214 INT nIndex = (INT)wParam;
3216 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3218 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3221 memset(&nmtb, 0, sizeof(nmtb));
3222 nmtb.iItem = btnPtr->idCommand;
3223 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3224 nmtb.tbButton.idCommand = btnPtr->idCommand;
3225 nmtb.tbButton.fsState = btnPtr->fsState;
3226 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3227 nmtb.tbButton.dwData = btnPtr->dwData;
3228 nmtb.tbButton.iString = btnPtr->iString;
3229 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3231 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3233 if (infoPtr->nNumButtons == 1) {
3234 TRACE(" simple delete!\n");
3235 Free (infoPtr->buttons);
3236 infoPtr->buttons = NULL;
3237 infoPtr->nNumButtons = 0;
3240 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3241 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3243 infoPtr->nNumButtons--;
3244 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3246 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3247 nIndex * sizeof(TBUTTON_INFO));
3250 if (nIndex < infoPtr->nNumButtons) {
3251 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3252 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3258 TOOLBAR_LayoutToolbar(hwnd);
3260 InvalidateRect (hwnd, NULL, TRUE);
3267 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3269 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3270 TBUTTON_INFO *btnPtr;
3274 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3276 TRACE("hwnd=%p, btn index=%ld, lParam=0x%08lx\n", hwnd, wParam, lParam);
3281 btnPtr = &infoPtr->buttons[nIndex];
3283 bState = btnPtr->fsState & TBSTATE_ENABLED;
3285 /* update the toolbar button state */
3286 if(LOWORD(lParam) == FALSE) {
3287 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3289 btnPtr->fsState |= TBSTATE_ENABLED;
3292 /* redraw the button only if the state of the button changed */
3293 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3294 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3300 static inline LRESULT
3301 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3303 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3305 return infoPtr->bAnchor;
3310 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam)
3312 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3315 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3319 return infoPtr->buttons[nIndex].iBitmap;
3323 static inline LRESULT
3324 TOOLBAR_GetBitmapFlags (void)
3326 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3331 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3334 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3335 INT nIndex = (INT)wParam;
3336 TBUTTON_INFO *btnPtr;
3341 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3344 btnPtr = &infoPtr->buttons[nIndex];
3345 lpTbb->iBitmap = btnPtr->iBitmap;
3346 lpTbb->idCommand = btnPtr->idCommand;
3347 lpTbb->fsState = btnPtr->fsState;
3348 lpTbb->fsStyle = btnPtr->fsStyle;
3349 lpTbb->bReserved[0] = 0;
3350 lpTbb->bReserved[1] = 0;
3351 lpTbb->dwData = btnPtr->dwData;
3352 lpTbb->iString = btnPtr->iString;
3359 TOOLBAR_GetButtonInfoT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
3361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3363 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3364 TBUTTON_INFO *btnPtr;
3367 if (lpTbInfo == NULL)
3370 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3371 * the headers and tests shows that even with comctl 6 Vista accepts only the
3372 * original TBBUTTONINFO size
3374 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3376 WARN("Invalid button size\n");
3380 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3381 lpTbInfo->dwMask & 0x80000000);
3385 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3387 if (lpTbInfo->dwMask & TBIF_COMMAND)
3388 lpTbInfo->idCommand = btnPtr->idCommand;
3389 if (lpTbInfo->dwMask & TBIF_IMAGE)
3390 lpTbInfo->iImage = btnPtr->iBitmap;
3391 if (lpTbInfo->dwMask & TBIF_LPARAM)
3392 lpTbInfo->lParam = btnPtr->dwData;
3393 if (lpTbInfo->dwMask & TBIF_SIZE)
3394 /* tests show that for separators TBIF_SIZE returns not calculated width,
3395 but cx property, that differs from 0 only if application have
3396 specifically set it */
3397 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3398 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3399 if (lpTbInfo->dwMask & TBIF_STATE)
3400 lpTbInfo->fsState = btnPtr->fsState;
3401 if (lpTbInfo->dwMask & TBIF_STYLE)
3402 lpTbInfo->fsStyle = btnPtr->fsStyle;
3403 if (lpTbInfo->dwMask & TBIF_TEXT) {
3404 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3405 can't use TOOLBAR_GetText here */
3406 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3407 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3409 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3411 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3413 lpTbInfo->pszText[0] = '\0';
3420 TOOLBAR_GetButtonSize (HWND hwnd)
3422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3424 return MAKELONG((WORD)infoPtr->nButtonWidth,
3425 (WORD)infoPtr->nButtonHeight);
3430 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3432 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3439 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3443 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3445 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3446 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3451 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3458 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3462 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3466 ret = strlenW (lpText);
3469 strcpyW ((LPWSTR)lParam, lpText);
3477 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3480 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3481 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3485 static inline LRESULT
3486 TOOLBAR_GetExtendedStyle (HWND hwnd)
3488 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3492 return infoPtr->dwExStyle;
3497 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3499 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3500 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3501 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3506 TOOLBAR_GetHotItem (HWND hwnd)
3508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3510 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3513 if (infoPtr->nHotItem < 0)
3516 return (LRESULT)infoPtr->nHotItem;
3521 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3523 TRACE("hwnd=%p, wParam=%ld, lParam=0x%lx\n", hwnd, wParam, lParam);
3524 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3525 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3530 TOOLBAR_GetInsertMark (HWND hwnd, LPARAM lParam)
3532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3533 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3535 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3537 *lptbim = infoPtr->tbim;
3544 TOOLBAR_GetInsertMarkColor (HWND hwnd)
3546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3548 TRACE("hwnd = %p\n", hwnd);
3550 return (LRESULT)infoPtr->clrInsertMark;
3555 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3558 TBUTTON_INFO *btnPtr;
3562 nIndex = (INT)wParam;
3563 btnPtr = &infoPtr->buttons[nIndex];
3564 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3566 lpRect = (LPRECT)lParam;
3569 if (btnPtr->fsState & TBSTATE_HIDDEN)
3572 lpRect->left = btnPtr->rect.left;
3573 lpRect->right = btnPtr->rect.right;
3574 lpRect->bottom = btnPtr->rect.bottom;
3575 lpRect->top = btnPtr->rect.top;
3582 TOOLBAR_GetMaxSize (HWND hwnd, LPARAM lParam)
3584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 LPSIZE lpSize = (LPSIZE)lParam;
3590 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3591 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3593 TRACE("maximum size %d x %d\n",
3594 infoPtr->rcBound.right - infoPtr->rcBound.left,
3595 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3601 /* << TOOLBAR_GetObject >> */
3605 TOOLBAR_GetPadding (HWND hwnd)
3607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3610 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3611 return (LRESULT) oldPad;
3616 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3619 TBUTTON_INFO *btnPtr;
3623 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3624 btnPtr = &infoPtr->buttons[nIndex];
3625 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3627 lpRect = (LPRECT)lParam;
3631 lpRect->left = btnPtr->rect.left;
3632 lpRect->right = btnPtr->rect.right;
3633 lpRect->bottom = btnPtr->rect.bottom;
3634 lpRect->top = btnPtr->rect.top;
3641 TOOLBAR_GetRows (HWND hwnd)
3643 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 return infoPtr->nRows;
3650 TOOLBAR_GetState (HWND hwnd, WPARAM wParam)
3652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3655 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3659 return infoPtr->buttons[nIndex].fsState;
3664 TOOLBAR_GetStyle (HWND hwnd)
3666 return GetWindowLongW(hwnd, GWL_STYLE);
3671 TOOLBAR_GetTextRows (HWND hwnd)
3673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3675 return infoPtr->nMaxTextRows;
3680 TOOLBAR_GetToolTips (HWND hwnd)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3685 TOOLBAR_TooltipCreateControl(infoPtr);
3686 return (LRESULT)infoPtr->hwndToolTip;
3691 TOOLBAR_GetUnicodeFormat (HWND hwnd)
3693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3695 TRACE("%s hwnd=%p\n",
3696 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3698 return infoPtr->bUnicode;
3702 static inline LRESULT
3703 TOOLBAR_GetVersion (HWND hwnd)
3705 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3706 return infoPtr->iVersion;
3711 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3714 TBUTTON_INFO *btnPtr;
3719 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3723 btnPtr = &infoPtr->buttons[nIndex];
3724 if (LOWORD(lParam) == FALSE)
3725 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3727 btnPtr->fsState |= TBSTATE_HIDDEN;
3729 TOOLBAR_LayoutToolbar (hwnd);
3731 InvalidateRect (hwnd, NULL, TRUE);
3737 static inline LRESULT
3738 TOOLBAR_HitTest (HWND hwnd, LPARAM lParam)
3740 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3745 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3748 TBUTTON_INFO *btnPtr;
3752 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3756 btnPtr = &infoPtr->buttons[nIndex];
3757 oldState = btnPtr->fsState;
3758 if (LOWORD(lParam) == FALSE)
3759 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3761 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3763 if(oldState != btnPtr->fsState)
3764 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3771 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3774 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3775 INT nIndex = (INT)wParam;
3781 /* EPP: this seems to be an undocumented call (from my IE4)
3782 * I assume in that case that:
3783 * - index of insertion is at the end of existing buttons
3784 * I only see this happen with nIndex == -1, but it could have a special
3785 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3787 nIndex = infoPtr->nNumButtons;
3789 } else if (nIndex < 0)
3792 TRACE("inserting button index=%d\n", nIndex);
3793 if (nIndex > infoPtr->nNumButtons) {
3794 nIndex = infoPtr->nNumButtons;
3795 TRACE("adjust index=%d\n", nIndex);
3798 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3801 /* << TOOLBAR_InsertMarkHitTest >> */
3805 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam)
3807 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3810 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3814 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3819 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam)
3821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3824 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3828 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3833 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam)
3835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3838 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3842 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3847 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam)
3849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3852 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3856 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3861 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam)
3863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3866 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3870 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3875 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam)
3877 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3880 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3884 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3889 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3892 tbab.hInst = (HINSTANCE)lParam;
3895 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", hwnd, tbab.hInst, tbab.nID);
3897 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3902 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3905 WCHAR wAccel = (WCHAR)wParam;
3906 UINT* pIDButton = (UINT*)lParam;
3907 WCHAR wszAccel[] = {'&',wAccel,0};
3910 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3911 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3913 for (i = 0; i < infoPtr->nNumButtons; i++)
3915 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3916 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3917 !(btnPtr->fsState & TBSTATE_HIDDEN))
3919 int iLen = strlenW(wszAccel);
3920 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3927 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3932 if (!strncmpiW(lpszStr, wszAccel, iLen))
3934 *pIDButton = btnPtr->idCommand;
3946 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3951 TBUTTON_INFO *btnPtr;
3953 TRACE("hwnd = %p, wParam = %ld, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3955 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3959 btnPtr = &infoPtr->buttons[nIndex];
3960 oldState = btnPtr->fsState;
3963 btnPtr->fsState |= TBSTATE_MARKED;
3965 btnPtr->fsState &= ~TBSTATE_MARKED;
3967 if(oldState != btnPtr->fsState)
3968 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3974 /* fixes up an index of a button affected by a move */
3975 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3979 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3981 else if (*pIndex == nIndex)
3982 *pIndex = nMoveIndex;
3986 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3988 else if (*pIndex == nIndex)
3989 *pIndex = nMoveIndex;
3995 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4000 INT nMoveIndex = (INT)lParam;
4001 TBUTTON_INFO button;
4003 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4005 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4006 if ((nIndex == -1) || (nMoveIndex < 0))
4009 if (nMoveIndex > infoPtr->nNumButtons - 1)
4010 nMoveIndex = infoPtr->nNumButtons - 1;
4012 button = infoPtr->buttons[nIndex];
4014 /* move button right */
4015 if (nIndex < nMoveIndex)
4017 nCount = nMoveIndex - nIndex;
4018 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4019 infoPtr->buttons[nMoveIndex] = button;
4021 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4022 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4023 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4024 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4026 else if (nIndex > nMoveIndex) /* move button left */
4028 nCount = nIndex - nMoveIndex;
4029 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4030 infoPtr->buttons[nMoveIndex] = button;
4032 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4033 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4034 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4035 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4038 TOOLBAR_LayoutToolbar(hwnd);
4039 TOOLBAR_AutoSize(hwnd);
4040 InvalidateRect(hwnd, NULL, TRUE);
4047 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4050 TBUTTON_INFO *btnPtr;
4054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4058 btnPtr = &infoPtr->buttons[nIndex];
4059 oldState = btnPtr->fsState;
4060 if (LOWORD(lParam) == FALSE)
4061 btnPtr->fsState &= ~TBSTATE_PRESSED;
4063 btnPtr->fsState |= TBSTATE_PRESSED;
4065 if(oldState != btnPtr->fsState)
4066 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4071 /* FIXME: there might still be some confusion her between number of buttons
4072 * and number of bitmaps */
4074 TOOLBAR_ReplaceBitmap (HWND hwnd, LPARAM lParam)
4076 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4077 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4079 int i = 0, nOldButtons = 0, pos = 0;
4080 int nOldBitmaps, nNewBitmaps = 0;
4081 HIMAGELIST himlDef = 0;
4083 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
4084 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4085 lpReplace->nButtons);
4087 if (lpReplace->hInstOld == HINST_COMMCTRL)
4089 FIXME("changing standard bitmaps not implemented\n");
4092 else if (lpReplace->hInstOld != 0)
4093 FIXME("resources not in the current module not implemented\n");
4095 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4096 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4097 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4098 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4099 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4101 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4102 nOldButtons = tbi->nButtons;
4103 tbi->nButtons = lpReplace->nButtons;
4104 tbi->hInst = lpReplace->hInstNew;
4105 tbi->nID = lpReplace->nIDNew;
4106 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4109 pos += tbi->nButtons;
4112 if (nOldButtons == 0)
4114 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4118 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4121 if (lpReplace->hInstNew)
4122 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4124 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4126 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4127 nOldBitmaps = ImageList_GetImageCount(himlDef);
4129 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4131 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4132 ImageList_Remove(himlDef, i);
4136 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4137 nNewBitmaps = ImageList_GetImageCount(himlDef);
4138 DeleteObject(hBitmap);
4141 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4143 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4144 pos, nOldBitmaps, nNewBitmaps);
4146 InvalidateRect(hwnd, NULL, TRUE);
4151 /* helper for TOOLBAR_SaveRestoreW */
4153 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4155 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4156 debugstr_w(lpSave->pszValueName));
4162 /* helper for TOOLBAR_Restore */
4164 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4168 for (i = 0; i < infoPtr->nNumButtons; i++)
4170 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4173 Free(infoPtr->buttons);
4174 infoPtr->buttons = NULL;
4175 infoPtr->nNumButtons = 0;
4179 /* helper for TOOLBAR_SaveRestoreW */
4181 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4190 /* restore toolbar information */
4191 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4192 debugstr_w(lpSave->pszValueName));
4194 memset(&nmtbr, 0, sizeof(nmtbr));
4196 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4197 KEY_QUERY_VALUE, &hkey);
4199 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4201 if (!res && dwType != REG_BINARY)
4202 res = ERROR_FILE_NOT_FOUND;
4205 nmtbr.pData = Alloc(dwSize);
4206 nmtbr.cbData = dwSize;
4207 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4210 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4211 (LPBYTE)nmtbr.pData, &dwSize);
4214 nmtbr.pCurrent = nmtbr.pData;
4216 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4217 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4219 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4223 /* remove all existing buttons as this function is designed to
4224 * restore the toolbar to a previously saved state */
4225 TOOLBAR_DeleteAllButtons(infoPtr);
4227 for (i = 0; i < nmtbr.cButtons; i++)
4230 nmtbr.tbButton.iBitmap = -1;
4231 nmtbr.tbButton.fsState = 0;
4232 nmtbr.tbButton.fsStyle = 0;
4233 nmtbr.tbButton.idCommand = 0;
4234 if (*nmtbr.pCurrent == (DWORD)-1)
4237 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4238 /* when inserting separators, iBitmap controls it's size.
4239 0 sets default size (width) */
4240 nmtbr.tbButton.iBitmap = 0;
4242 else if (*nmtbr.pCurrent == (DWORD)-2)
4244 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4246 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4250 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4252 /* can't contain real string as we don't know whether
4253 * the client put an ANSI or Unicode string in there */
4254 if (HIWORD(nmtbr.tbButton.iString))
4255 nmtbr.tbButton.iString = 0;
4257 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4258 (LPARAM)&nmtbr.tbButton, TRUE);
4261 /* do legacy notifications */
4262 if (infoPtr->iVersion < 5)
4264 /* FIXME: send TBN_BEGINADJUST */
4265 FIXME("send TBN_GETBUTTONINFO for each button\n");
4266 /* FIXME: send TBN_ENDADJUST */
4269 /* remove all uninitialised buttons
4270 * note: loop backwards to avoid having to fixup i on a
4272 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4273 if (infoPtr->buttons[i].iBitmap == -1)
4274 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i);
4276 /* only indicate success if at least one button survived */
4277 if (infoPtr->nNumButtons > 0) ret = TRUE;
4288 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4290 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4292 if (lpSave == NULL) return 0;
4295 return TOOLBAR_Save(lpSave);
4297 return TOOLBAR_Restore(infoPtr, lpSave);
4302 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4304 LPWSTR pszValueName = 0, pszSubKey = 0;
4305 TBSAVEPARAMSW SaveW;
4309 if (lpSave == NULL) return 0;
4311 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4312 pszSubKey = Alloc(len * sizeof(WCHAR));
4313 if (pszSubKey) goto exit;
4314 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4316 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4317 pszValueName = Alloc(len * sizeof(WCHAR));
4318 if (!pszValueName) goto exit;
4319 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4321 SaveW.pszValueName = pszValueName;
4322 SaveW.pszSubKey = pszSubKey;
4323 SaveW.hkr = lpSave->hkr;
4324 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4327 Free (pszValueName);
4335 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4338 BOOL bOldAnchor = infoPtr->bAnchor;
4340 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4342 infoPtr->bAnchor = (BOOL)wParam;
4344 /* Native does not remove the hot effect from an already hot button */
4346 return (LRESULT)bOldAnchor;
4351 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4354 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4355 short width = (short)LOWORD(lParam);
4356 short height = (short)HIWORD(lParam);
4358 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", hwnd, wParam, lParam);
4361 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4363 /* 0 width or height is changed to 1 */
4369 if (infoPtr->nNumButtons > 0)
4370 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4371 infoPtr->nNumButtons,
4372 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4374 if (width < -1 || height < -1)
4376 /* Windows destroys the imagelist and seems to actually use negative
4377 * values to compute button sizes */
4378 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4382 /* width or height of -1 means no change */
4384 infoPtr->nBitmapWidth = width;
4386 infoPtr->nBitmapHeight = height;
4388 if ((himlDef == infoPtr->himlInt) &&
4389 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4391 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4392 infoPtr->nBitmapHeight);
4395 TOOLBAR_CalcToolbar(hwnd);
4396 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4402 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4405 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4406 TBUTTON_INFO *btnPtr;
4412 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4415 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4416 lptbbi->dwMask & 0x80000000);
4420 btnPtr = &infoPtr->buttons[nIndex];
4421 if (lptbbi->dwMask & TBIF_COMMAND)
4422 btnPtr->idCommand = lptbbi->idCommand;
4423 if (lptbbi->dwMask & TBIF_IMAGE)
4424 btnPtr->iBitmap = lptbbi->iImage;
4425 if (lptbbi->dwMask & TBIF_LPARAM)
4426 btnPtr->dwData = lptbbi->lParam;
4427 if (lptbbi->dwMask & TBIF_SIZE)
4428 btnPtr->cx = lptbbi->cx;
4429 if (lptbbi->dwMask & TBIF_STATE)
4430 btnPtr->fsState = lptbbi->fsState;
4431 if (lptbbi->dwMask & TBIF_STYLE)
4432 btnPtr->fsStyle = lptbbi->fsStyle;
4434 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4435 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4436 /* iString is index, zero it to make Str_SetPtr succeed */
4439 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4442 /* save the button rect to see if we need to redraw the whole toolbar */
4443 oldBtnRect = btnPtr->rect;
4444 TOOLBAR_LayoutToolbar(hwnd);
4446 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4447 InvalidateRect(hwnd, NULL, TRUE);
4449 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4456 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4459 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4460 TBUTTON_INFO *btnPtr;
4466 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4469 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4470 lptbbi->dwMask & 0x80000000);
4474 btnPtr = &infoPtr->buttons[nIndex];
4475 if (lptbbi->dwMask & TBIF_COMMAND)
4476 btnPtr->idCommand = lptbbi->idCommand;
4477 if (lptbbi->dwMask & TBIF_IMAGE)
4478 btnPtr->iBitmap = lptbbi->iImage;
4479 if (lptbbi->dwMask & TBIF_LPARAM)
4480 btnPtr->dwData = lptbbi->lParam;
4481 if (lptbbi->dwMask & TBIF_SIZE)
4482 btnPtr->cx = lptbbi->cx;
4483 if (lptbbi->dwMask & TBIF_STATE)
4484 btnPtr->fsState = lptbbi->fsState;
4485 if (lptbbi->dwMask & TBIF_STYLE)
4486 btnPtr->fsStyle = lptbbi->fsStyle;
4488 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4489 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4490 /* iString is index, zero it to make Str_SetPtr succeed */
4492 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4495 /* save the button rect to see if we need to redraw the whole toolbar */
4496 oldBtnRect = btnPtr->rect;
4497 TOOLBAR_LayoutToolbar(hwnd);
4499 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4500 InvalidateRect(hwnd, NULL, TRUE);
4502 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4509 TOOLBAR_SetButtonSize (HWND hwnd, LPARAM lParam)
4511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4512 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4514 if ((cx < 0) || (cy < 0))
4516 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4520 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4522 /* The documentation claims you can only change the button size before
4523 * any button has been added. But this is wrong.
4524 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4525 * it to the toolbar, and it checks that the return value is nonzero - mjm
4526 * Further testing shows that we must actually perform the change too.
4529 * The documentation also does not mention that if 0 is supplied for
4530 * either size, the system changes it to the default of 24 wide and
4531 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4533 if (cx == 0) cx = 24;
4534 if (cy == 0) cy = 22;
4536 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4537 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4539 infoPtr->nButtonWidth = cx;
4540 infoPtr->nButtonHeight = cy;
4542 infoPtr->iTopMargin = default_top_margin(infoPtr);
4543 TOOLBAR_LayoutToolbar(hwnd);
4549 TOOLBAR_SetButtonWidth (HWND hwnd, LPARAM lParam)
4551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4553 /* if setting to current values, ignore */
4554 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4555 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4556 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4557 infoPtr->cxMin, infoPtr->cxMax);
4561 /* save new values */
4562 infoPtr->cxMin = (short)LOWORD(lParam);
4563 infoPtr->cxMax = (short)HIWORD(lParam);
4565 /* otherwise we need to recalc the toolbar and in some cases
4566 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4567 which doesn't actually draw - GA). */
4568 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4569 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4571 TOOLBAR_CalcToolbar (hwnd);
4573 InvalidateRect (hwnd, NULL, TRUE);
4580 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4583 INT nIndex = (INT)wParam;
4585 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4588 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4590 if (infoPtr->hwndToolTip) {
4592 FIXME("change tool tip!\n");
4601 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4604 HIMAGELIST himl = (HIMAGELIST)lParam;
4605 HIMAGELIST himlTemp;
4608 if (infoPtr->iVersion >= 5)
4611 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4612 &infoPtr->cimlDis, himl, id);
4614 /* FIXME: redraw ? */
4616 return (LRESULT)himlTemp;
4621 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4626 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4628 dwTemp = infoPtr->dwDTFlags;
4629 infoPtr->dwDTFlags =
4630 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4632 return (LRESULT)dwTemp;
4635 /* This function differs a bit from what MSDN says it does:
4636 * 1. lParam contains extended style flags to OR with current style
4637 * (MSDN isn't clear on the OR bit)
4638 * 2. wParam appears to contain extended style flags to be reset
4639 * (MSDN says that this parameter is reserved)
4642 TOOLBAR_SetExtendedStyle (HWND hwnd, LPARAM lParam)
4644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4647 dwOldStyle = infoPtr->dwExStyle;
4648 infoPtr->dwExStyle = (DWORD)lParam;
4650 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4652 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4653 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4654 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4656 if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4657 TOOLBAR_CalcToolbar(hwnd);
4659 TOOLBAR_LayoutToolbar(hwnd);
4661 TOOLBAR_AutoSize(hwnd);
4662 InvalidateRect(hwnd, NULL, TRUE);
4664 return (LRESULT)dwOldStyle;
4669 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4671 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4672 HIMAGELIST himlTemp;
4673 HIMAGELIST himl = (HIMAGELIST)lParam;
4676 if (infoPtr->iVersion >= 5)
4679 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4681 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4682 &infoPtr->cimlHot, himl, id);
4684 /* FIXME: redraw ? */
4686 return (LRESULT)himlTemp;
4690 /* Makes previous hot button no longer hot, makes the specified
4691 * button hot and sends appropriate notifications. dwReason is one or
4692 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4693 * NOTE 1: this function does not validate nHit
4694 * NOTE 2: the name of this function is completely made up and
4695 * not based on any documentation from Microsoft. */
4697 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4699 if (infoPtr->nHotItem != nHit)
4701 NMTBHOTITEM nmhotitem;
4702 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4704 nmhotitem.dwFlags = dwReason;
4705 if(infoPtr->nHotItem >= 0)
4707 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4708 nmhotitem.idOld = oldBtnPtr->idCommand;
4712 nmhotitem.dwFlags |= HICF_ENTERING;
4713 nmhotitem.idOld = 0;
4718 btnPtr = &infoPtr->buttons[nHit];
4719 nmhotitem.idNew = btnPtr->idCommand;
4723 nmhotitem.dwFlags |= HICF_LEAVING;
4724 nmhotitem.idNew = 0;
4727 /* now change the hot and invalidate the old and new buttons - if the
4729 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4732 oldBtnPtr->bHot = FALSE;
4733 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4735 /* setting disabled buttons as hot fails even if the notify contains the button id */
4736 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4737 btnPtr->bHot = TRUE;
4738 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4739 infoPtr->nHotItem = nHit;
4742 infoPtr->nHotItem = -1;
4748 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4751 INT nOldHotItem = infoPtr->nHotItem;
4753 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4755 if ((INT)wParam >= infoPtr->nNumButtons)
4756 return infoPtr->nHotItem;
4758 if ((INT)wParam < 0)
4761 /* NOTE: an application can still remove the hot item even if anchor
4762 * highlighting is enabled */
4764 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4766 if (nOldHotItem < 0)
4769 return (LRESULT)nOldHotItem;
4774 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4776 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4777 HIMAGELIST himlTemp;
4778 HIMAGELIST himl = (HIMAGELIST)lParam;
4779 INT oldButtonWidth = infoPtr->nButtonWidth;
4780 INT oldBitmapWidth = infoPtr->nBitmapWidth;
4781 INT oldBitmapHeight = infoPtr->nBitmapHeight;
4784 if (infoPtr->iVersion >= 5)
4787 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4788 &infoPtr->cimlDef, himl, id);
4790 infoPtr->nNumBitmaps = 0;
4791 for (i = 0; i < infoPtr->cimlDef; i++)
4792 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4794 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4795 &infoPtr->nBitmapHeight))
4797 infoPtr->nBitmapWidth = 1;
4798 infoPtr->nBitmapHeight = 1;
4800 if ((oldBitmapWidth != infoPtr->nBitmapWidth) || (oldBitmapHeight != infoPtr->nBitmapHeight))
4802 TOOLBAR_CalcToolbar(hwnd);
4803 if (infoPtr->nButtonWidth < oldButtonWidth)
4804 TOOLBAR_SetButtonSize(hwnd, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4807 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4808 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4809 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4811 InvalidateRect(hwnd, NULL, TRUE);
4813 return (LRESULT)himlTemp;
4818 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam)
4820 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4822 infoPtr->nIndent = (INT)wParam;
4826 /* process only on indent changing */
4827 if(infoPtr->nIndent != (INT)wParam)
4829 infoPtr->nIndent = (INT)wParam;
4830 TOOLBAR_CalcToolbar (hwnd);
4831 InvalidateRect(hwnd, NULL, FALSE);
4839 TOOLBAR_SetInsertMark (HWND hwnd, LPARAM lParam)
4841 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4842 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4844 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4846 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4848 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4852 if ((lptbim->iButton == -1) ||
4853 ((lptbim->iButton < infoPtr->nNumButtons) &&
4854 (lptbim->iButton >= 0)))
4856 infoPtr->tbim = *lptbim;
4857 /* FIXME: don't need to update entire toolbar */
4858 InvalidateRect(hwnd, NULL, TRUE);
4861 ERR("Invalid button index %d\n", lptbim->iButton);
4868 TOOLBAR_SetInsertMarkColor (HWND hwnd, LPARAM lParam)
4870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4872 infoPtr->clrInsertMark = (COLORREF)lParam;
4874 /* FIXME: don't need to update entire toolbar */
4875 InvalidateRect(hwnd, NULL, TRUE);
4882 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam)
4884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4886 infoPtr->nMaxTextRows = (INT)wParam;
4888 TOOLBAR_CalcToolbar(hwnd);
4893 /* MSDN gives slightly wrong info on padding.
4894 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4895 * 2. It is not used to create a blank area between the edge of the button
4896 * and the text or image if TBSTYLE_LIST is set. It is used to control
4897 * the gap between the image and text.
4898 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4899 * to control the bottom and right borders [with the border being
4900 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4901 * is shared evenly on both sides of the button.
4902 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4905 TOOLBAR_SetPadding (HWND hwnd, LPARAM lParam)
4907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4910 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4911 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4912 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4913 TRACE("cx=%d, cy=%d\n",
4914 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4915 return (LRESULT) oldPad;
4920 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam)
4922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4927 hwndOldNotify = infoPtr->hwndNotify;
4928 infoPtr->hwndNotify = (HWND)wParam;
4930 return (LRESULT)hwndOldNotify;
4935 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4938 LPRECT lprc = (LPRECT)lParam;
4939 int rows = LOWORD(wParam);
4940 BOOL bLarger = HIWORD(wParam);
4944 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4946 if(infoPtr->nRows != rows)
4948 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4949 int curColumn = 0; /* Current column */
4950 int curRow = 0; /* Current row */
4951 int hidden = 0; /* Number of hidden buttons */
4952 int seps = 0; /* Number of separators */
4953 int idealWrap = 0; /* Ideal wrap point */
4958 Calculate new size and wrap points - Under windows, setrows will
4959 change the dimensions if needed to show the number of requested
4960 rows (if CCS_NORESIZE is set), or will take up the whole window
4961 (if no CCS_NORESIZE).
4963 Basic algorithm - If N buttons, and y rows requested, each row
4964 contains N/y buttons.
4966 FIXME: Handling of separators not obvious from testing results
4967 FIXME: Take width of window into account?
4970 /* Loop through the buttons one by one counting key items */
4971 for (i = 0; i < infoPtr->nNumButtons; i++ )
4973 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4974 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4976 else if (btnPtr[i].fsStyle & BTNS_SEP)
4980 /* FIXME: Separators make this quite complex */
4981 if (seps) FIXME("Separators unhandled\n");
4983 /* Round up so more per line, i.e., less rows */
4984 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / rows;
4986 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4987 achieve the requested number of rows. */
4988 if (bLarger && idealWrap > 1)
4990 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4991 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4993 if (resRows < rows && moreRows > rows)
4996 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
5000 curColumn = curRow = 0;
5002 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
5003 infoPtr->nNumButtons, hidden, rows);
5005 for (i = 0; i < infoPtr->nNumButtons; i++ )
5007 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
5010 /* Step on, wrap if necessary or flag next to wrap */
5019 if (curColumn > (idealWrap-1)) {
5021 btnPtr[i].fsState |= TBSTATE_WRAP;
5025 TRACE("Result - %d rows\n", curRow + 1);
5027 /* recalculate toolbar */
5028 TOOLBAR_CalcToolbar (hwnd);
5030 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
5031 if NORESIZE is NOT set, then the toolbar will always be resized to
5032 take up the whole window. With it set, sizing needs to be manual. */
5033 if (infoPtr->dwStyle & CCS_NORESIZE) {
5034 SetWindowPos(hwnd, NULL, 0, 0,
5035 infoPtr->rcBound.right - infoPtr->rcBound.left,
5036 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
5040 /* repaint toolbar */
5041 InvalidateRect(hwnd, NULL, TRUE);
5044 /* return bounding rectangle */
5046 lprc->left = infoPtr->rcBound.left;
5047 lprc->right = infoPtr->rcBound.right;
5048 lprc->top = infoPtr->rcBound.top;
5049 lprc->bottom = infoPtr->rcBound.bottom;
5057 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5059 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5060 TBUTTON_INFO *btnPtr;
5063 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5067 btnPtr = &infoPtr->buttons[nIndex];
5069 /* if hidden state has changed the invalidate entire window and recalc */
5070 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5071 btnPtr->fsState = LOWORD(lParam);
5072 TOOLBAR_CalcToolbar (hwnd);
5073 InvalidateRect(hwnd, 0, TRUE);
5077 /* process state changing if current state doesn't match new state */
5078 if(btnPtr->fsState != LOWORD(lParam))
5080 btnPtr->fsState = LOWORD(lParam);
5081 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5089 TOOLBAR_SetStyle (HWND hwnd, LPARAM lParam)
5091 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5097 static inline LRESULT
5098 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5100 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5102 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5104 infoPtr->hwndToolTip = (HWND)wParam;
5110 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
5112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5115 TRACE("%s hwnd=%p\n",
5116 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5118 bTemp = infoPtr->bUnicode;
5119 infoPtr->bUnicode = (BOOL)wParam;
5126 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5128 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5130 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5131 comctl32_color.clrBtnHighlight :
5132 infoPtr->clrBtnHighlight;
5133 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5134 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5140 TOOLBAR_SetColorScheme (HWND hwnd, const COLORSCHEME *lParam)
5142 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5144 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5145 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5146 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5148 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5149 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5150 InvalidateRect(hwnd, NULL, TRUE);
5156 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5158 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5159 INT iOldVersion = infoPtr->iVersion;
5161 infoPtr->iVersion = iVersion;
5163 if (infoPtr->iVersion >= 5)
5164 TOOLBAR_SetUnicodeFormat(hwnd, TRUE);
5171 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5174 WORD iString = HIWORD(wParam);
5175 WORD buffersize = LOWORD(wParam);
5176 LPSTR str = (LPSTR)lParam;
5179 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5181 if (iString < infoPtr->nNumStrings)
5183 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5186 TRACE("returning %s\n", debugstr_a(str));
5189 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5196 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5199 WORD iString = HIWORD(wParam);
5200 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5201 LPWSTR str = (LPWSTR)lParam;
5204 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5206 if (iString < infoPtr->nNumStrings)
5208 len = min(len, strlenW(infoPtr->strings[iString]));
5209 ret = (len+1)*sizeof(WCHAR);
5212 memcpy(str, infoPtr->strings[iString], ret);
5217 TRACE("returning %s\n", debugstr_w(str));
5220 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5225 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5226 * is the maximum size of the toolbar? */
5227 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5229 SIZE * pSize = (SIZE*)lParam;
5230 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5235 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5236 * caller to specify a reason why the hot item changed (rather than just the
5237 * HICF_OTHER that TB_SETHOTITEM sends). */
5239 TOOLBAR_SetHotItem2 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5241 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5242 INT nOldHotItem = infoPtr->nHotItem;
5244 TRACE("old item=%d, new item=%d, flags=%08x\n",
5245 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5247 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5250 /* NOTE: an application can still remove the hot item even if anchor
5251 * highlighting is enabled */
5253 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5257 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5260 /* Sets the toolbar global iListGap parameter which controls the amount of
5261 * spacing between the image and the text of buttons for TBSTYLE_LIST
5263 static LRESULT TOOLBAR_SetListGap(HWND hwnd, WPARAM wParam)
5265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5267 TRACE("hwnd=%p iListGap=%ld\n", hwnd, wParam);
5269 infoPtr->iListGap = (INT)wParam;
5271 InvalidateRect(hwnd, NULL, TRUE);
5276 /* Returns the number of maximum number of image lists associated with the
5277 * various states. */
5278 static LRESULT TOOLBAR_GetImageListCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
5280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5282 TRACE("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5284 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5288 TOOLBAR_GetIdealSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5290 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5291 LPSIZE lpsize = (LPSIZE)lParam;
5297 * Testing shows the following:
5298 * wParam = 0 adjust cx value
5299 * = 1 set cy value to max size.
5300 * lParam pointer to SIZE structure
5303 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5304 wParam, lParam, lpsize->cx, lpsize->cy);
5308 if (lpsize->cx == -1) {
5309 /* **** this is wrong, native measures each button and sets it */
5310 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5312 else if(HIWORD(lpsize->cx)) {
5314 HWND hwndParent = GetParent(hwnd);
5316 GetWindowRect(hwnd, &rc);
5317 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5318 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5319 lpsize->cx = max(rc.right-rc.left,
5320 infoPtr->rcBound.right - infoPtr->rcBound.left);
5323 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5327 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5330 FIXME("Unknown wParam %ld\n", wParam);
5333 TRACE("set to -> 0x%08x 0x%08x\n",
5334 lpsize->cx, lpsize->cy);
5338 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5340 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5342 InvalidateRect(hwnd, NULL, TRUE);
5348 TOOLBAR_Create (HWND hwnd, LPARAM lParam)
5350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5351 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5354 TRACE("hwnd = %p\n", hwnd);
5356 /* initialize info structure */
5357 infoPtr->nButtonWidth = 23;
5358 infoPtr->nButtonHeight = 22;
5359 infoPtr->nBitmapHeight = 16;
5360 infoPtr->nBitmapWidth = 16;
5362 infoPtr->nMaxTextRows = 1;
5363 infoPtr->cxMin = -1;
5364 infoPtr->cxMax = -1;
5365 infoPtr->nNumBitmaps = 0;
5366 infoPtr->nNumStrings = 0;
5368 infoPtr->bCaptured = FALSE;
5369 infoPtr->nButtonDown = -1;
5370 infoPtr->nButtonDrag = -1;
5371 infoPtr->nOldHit = -1;
5372 infoPtr->nHotItem = -1;
5373 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5374 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5375 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5376 infoPtr->bDragOutSent = FALSE;
5377 infoPtr->iVersion = 0;
5378 infoPtr->hwndSelf = hwnd;
5379 infoPtr->bDoRedraw = TRUE;
5380 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5381 infoPtr->clrBtnShadow = CLR_DEFAULT;
5382 infoPtr->szPadding.cx = DEFPAD_CX;
5383 infoPtr->szPadding.cy = DEFPAD_CY;
5384 infoPtr->iListGap = DEFLISTGAP;
5385 infoPtr->iTopMargin = default_top_margin(infoPtr);
5386 infoPtr->dwStyle = dwStyle;
5387 infoPtr->tbim.iButton = -1;
5388 GetClientRect(hwnd, &infoPtr->client_rect);
5389 infoPtr->bUnicode = infoPtr->hwndNotify &&
5390 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5391 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5393 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5394 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5396 OpenThemeData (hwnd, themeClass);
5398 TOOLBAR_CheckStyle (hwnd, dwStyle);
5405 TOOLBAR_Destroy (HWND hwnd)
5407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5409 /* delete tooltip control */
5410 if (infoPtr->hwndToolTip)
5411 DestroyWindow (infoPtr->hwndToolTip);
5413 /* delete temporary buffer for tooltip text */
5414 Free (infoPtr->pszTooltipText);
5415 Free (infoPtr->bitmaps); /* bitmaps list */
5417 /* delete button data */
5418 Free (infoPtr->buttons);
5420 /* delete strings */
5421 if (infoPtr->strings) {
5423 for (i = 0; i < infoPtr->nNumStrings; i++)
5424 Free (infoPtr->strings[i]);
5426 Free (infoPtr->strings);
5429 /* destroy internal image list */
5430 if (infoPtr->himlInt)
5431 ImageList_Destroy (infoPtr->himlInt);
5433 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5434 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5435 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5437 /* delete default font */
5438 DeleteObject (infoPtr->hDefaultFont);
5440 CloseThemeData (GetWindowTheme (hwnd));
5442 /* free toolbar info data */
5444 SetWindowLongPtrW (hwnd, 0, 0);
5451 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5454 NMTBCUSTOMDRAW tbcd;
5457 HTHEME theme = GetWindowTheme (hwnd);
5458 DWORD dwEraseCustDraw = 0;
5460 /* the app has told us not to redraw the toolbar */
5461 if (!infoPtr->bDoRedraw)
5464 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5465 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5466 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5467 tbcd.nmcd.hdc = (HDC)wParam;
5468 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5469 dwEraseCustDraw = ntfret & 0xffff;
5471 /* FIXME: in general the return flags *can* be or'ed together */
5472 switch (dwEraseCustDraw)
5474 case CDRF_DODEFAULT:
5476 case CDRF_SKIPDEFAULT:
5479 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5484 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5485 * to my parent for processing.
5487 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5489 HDC hdc = (HDC)wParam;
5494 parent = GetParent(hwnd);
5495 MapWindowPoints(hwnd, parent, &pt, 1);
5496 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5497 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5498 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5501 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5503 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5504 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5505 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5506 tbcd.nmcd.hdc = (HDC)wParam;
5507 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5508 dwEraseCustDraw = ntfret & 0xffff;
5509 switch (dwEraseCustDraw)
5511 case CDRF_DODEFAULT:
5513 case CDRF_SKIPDEFAULT:
5516 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5525 TOOLBAR_GetFont (HWND hwnd)
5527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5529 return (LRESULT)infoPtr->hFont;
5534 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5537 INT nNewHotItem = infoPtr->nHotItem;
5539 for (i = 0; i < infoPtr->nNumButtons; i++)
5542 if ((nNewHotItem + iDirection < 0) ||
5543 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5545 NMTBWRAPHOTITEM nmtbwhi;
5546 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5547 nmtbwhi.iDirection = iDirection;
5548 nmtbwhi.dwReason = dwReason;
5550 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5554 nNewHotItem += iDirection;
5555 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5557 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5558 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5560 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5567 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5572 nmkey.nVKey = (UINT)wParam;
5573 nmkey.uFlags = HIWORD(lParam);
5575 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5576 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5578 switch ((UINT)wParam)
5582 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5586 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5590 if ((infoPtr->nHotItem >= 0) &&
5591 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5593 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5594 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5605 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5610 pt.x = (short)LOWORD(lParam);
5611 pt.y = (short)HIWORD(lParam);
5612 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5615 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5616 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5617 TOOLBAR_Customize (hwnd);
5624 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5627 TBUTTON_INFO *btnPtr;
5632 BOOL bDragKeyPressed;
5636 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5637 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5639 bDragKeyPressed = (wParam & MK_SHIFT);
5641 if (infoPtr->hwndToolTip)
5642 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5643 WM_LBUTTONDOWN, wParam, lParam);
5645 pt.x = (short)LOWORD(lParam);
5646 pt.y = (short)HIWORD(lParam);
5647 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5649 btnPtr = &infoPtr->buttons[nHit];
5651 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5653 infoPtr->nButtonDrag = nHit;
5656 /* If drag cursor has not been loaded, load it.
5657 * Note: it doesn't need to be freed */
5659 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5660 SetCursor(hCursorDrag);
5665 infoPtr->nOldHit = nHit;
5667 CopyRect(&arrowRect, &btnPtr->rect);
5668 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5670 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5671 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5672 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5673 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5674 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5675 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5679 /* draw in pressed state */
5680 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5681 btnPtr->fsState |= TBSTATE_PRESSED;
5683 btnPtr->bDropDownPressed = TRUE;
5684 RedrawWindow(hwnd,&btnPtr->rect,0,
5685 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5687 memset(&nmtb, 0, sizeof(nmtb));
5688 nmtb.iItem = btnPtr->idCommand;
5689 nmtb.rcButton = btnPtr->rect;
5690 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5692 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5694 if (res != TBDDRET_TREATPRESSED)
5698 /* redraw button in unpressed state */
5699 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5700 btnPtr->fsState &= ~TBSTATE_PRESSED;
5702 btnPtr->bDropDownPressed = FALSE;
5703 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5705 /* find and set hot item
5706 * NOTE: native doesn't do this, but that is a bug */
5708 ScreenToClient(hwnd, &pt);
5709 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5710 if (!infoPtr->bAnchor || (nHit >= 0))
5711 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5713 /* remove any left mouse button down or double-click messages
5714 * so that we can get a toggle effect on the button */
5715 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5716 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5721 /* otherwise drop through and process as pushed */
5723 infoPtr->bCaptured = TRUE;
5724 infoPtr->nButtonDown = nHit;
5725 infoPtr->bDragOutSent = FALSE;
5727 btnPtr->fsState |= TBSTATE_PRESSED;
5729 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5731 if (btnPtr->fsState & TBSTATE_ENABLED)
5732 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5739 memset(&nmtb, 0, sizeof(nmtb));
5740 nmtb.iItem = btnPtr->idCommand;
5741 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5744 nmmouse.dwHitInfo = nHit;
5746 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5748 nmmouse.dwItemSpec = -1;
5751 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5752 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5755 ClientToScreen(hwnd, &pt);
5758 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5759 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5765 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5767 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5768 TBUTTON_INFO *btnPtr;
5776 if (infoPtr->hwndToolTip)
5777 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5778 WM_LBUTTONUP, wParam, lParam);
5780 pt.x = (short)LOWORD(lParam);
5781 pt.y = (short)HIWORD(lParam);
5782 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5784 if (!infoPtr->bAnchor || (nHit >= 0))
5785 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5787 if (infoPtr->nButtonDrag >= 0) {
5791 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5794 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5796 GetClientRect(hwnd, &rcClient);
5797 if (PtInRect(&rcClient, pt))
5804 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5807 if (nButton == infoPtr->nButtonDrag)
5809 /* if the button is moved sightly left and we have a
5810 * separator there then remove it */
5811 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5813 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5814 TOOLBAR_DeleteButton(hwnd, nButton - 1);
5816 else /* else insert a separator before the dragged button */
5819 memset(&tbb, 0, sizeof(tbb));
5820 tbb.fsStyle = BTNS_SEP;
5822 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5829 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5830 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5832 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5835 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5840 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5841 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag);
5844 /* button under cursor changed so need to re-set hot item */
5845 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5846 infoPtr->nButtonDrag = -1;
5848 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5850 else if (infoPtr->nButtonDown >= 0) {
5851 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5852 btnPtr->fsState &= ~TBSTATE_PRESSED;
5854 if (btnPtr->fsStyle & BTNS_CHECK) {
5855 if (btnPtr->fsStyle & BTNS_GROUP) {
5856 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5858 if ((nOldIndex != nHit) &&
5860 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5861 btnPtr->fsState |= TBSTATE_CHECKED;
5864 if (btnPtr->fsState & TBSTATE_CHECKED)
5865 btnPtr->fsState &= ~TBSTATE_CHECKED;
5867 btnPtr->fsState |= TBSTATE_CHECKED;
5871 if (nOldIndex != -1)
5872 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5875 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5876 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5877 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5879 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5881 infoPtr->nButtonDown = -1;
5883 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5884 TOOLBAR_SendNotify (&hdr, infoPtr,
5885 NM_RELEASEDCAPTURE);
5887 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5890 memset(&nmtb, 0, sizeof(nmtb));
5891 nmtb.iItem = btnPtr->idCommand;
5892 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5895 if (btnPtr->fsState & TBSTATE_ENABLED)
5897 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5898 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5900 /* In case we have just been destroyed... */
5906 /* !!! Undocumented - toolbar at 4.71 level and above sends
5907 * NM_CLICK with the NMMOUSE structure. */
5908 nmmouse.dwHitInfo = nHit;
5911 nmmouse.dwItemSpec = -1;
5914 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5915 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5918 ClientToScreen(hwnd, &pt);
5921 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5922 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5928 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5930 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5935 pt.x = (short)LOWORD(lParam);
5936 pt.y = (short)HIWORD(lParam);
5938 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5939 nmmouse.dwHitInfo = nHit;
5942 nmmouse.dwItemSpec = -1;
5944 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5945 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5948 ClientToScreen(hwnd, &pt);
5951 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5952 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5958 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5963 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5964 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5970 TOOLBAR_CaptureChanged(HWND hwnd)
5972 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5973 TBUTTON_INFO *btnPtr;
5975 infoPtr->bCaptured = FALSE;
5977 if (infoPtr->nButtonDown >= 0)
5979 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5980 btnPtr->fsState &= ~TBSTATE_PRESSED;
5982 infoPtr->nOldHit = -1;
5984 if (btnPtr->fsState & TBSTATE_ENABLED)
5985 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5991 TOOLBAR_MouseLeave (HWND hwnd)
5993 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5995 /* don't remove hot effects when in anchor highlighting mode or when a
5996 * drop-down button is pressed */
5997 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5999 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6000 if (!hotBtnPtr->bDropDownPressed)
6001 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6004 if (infoPtr->nOldHit < 0)
6007 /* If the last button we were over is depressed then make it not */
6008 /* depressed and redraw it */
6009 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6011 TBUTTON_INFO *btnPtr;
6014 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6016 btnPtr->fsState &= ~TBSTATE_PRESSED;
6019 InflateRect (&rc1, 1, 1);
6020 InvalidateRect (hwnd, &rc1, TRUE);
6023 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6026 ZeroMemory(&nmt, sizeof(nmt));
6027 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6028 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6029 infoPtr->bDragOutSent = TRUE;
6032 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6038 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6040 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6042 TRACKMOUSEEVENT trackinfo;
6044 TBUTTON_INFO *btnPtr;
6046 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6047 TOOLBAR_TooltipCreateControl(infoPtr);
6049 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6050 /* fill in the TRACKMOUSEEVENT struct */
6051 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6052 trackinfo.dwFlags = TME_QUERY;
6054 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6055 _TrackMouseEvent(&trackinfo);
6057 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6058 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6059 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6060 trackinfo.hwndTrack = hwnd;
6062 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6063 /* and can properly deactivate the hot toolbar button */
6064 _TrackMouseEvent(&trackinfo);
6068 if (infoPtr->hwndToolTip)
6069 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6070 WM_MOUSEMOVE, wParam, lParam);
6072 pt.x = (short)LOWORD(lParam);
6073 pt.y = (short)HIWORD(lParam);
6075 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6077 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6078 && (!infoPtr->bAnchor || (nHit >= 0)))
6079 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6081 if (infoPtr->nOldHit != nHit)
6083 if (infoPtr->bCaptured)
6085 if (!infoPtr->bDragOutSent)
6088 ZeroMemory(&nmt, sizeof(nmt));
6089 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6090 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6091 infoPtr->bDragOutSent = TRUE;
6094 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6095 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6096 btnPtr->fsState &= ~TBSTATE_PRESSED;
6097 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6099 else if (nHit == infoPtr->nButtonDown) {
6100 btnPtr->fsState |= TBSTATE_PRESSED;
6101 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6103 infoPtr->nOldHit = nHit;
6111 static inline LRESULT
6112 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6114 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6115 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6117 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6121 static inline LRESULT
6122 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6124 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6125 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6127 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6132 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6134 TOOLBAR_INFO *infoPtr;
6135 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6138 /* allocate memory for info structure */
6139 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
6140 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6143 infoPtr->dwStructSize = sizeof(TBBUTTON);
6145 infoPtr->nWidth = 0;
6147 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6148 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6149 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6150 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6153 /* native control does:
6154 * Get a lot of colors and brushes
6156 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6157 * CreateFontIndirectW(adr1)
6158 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6159 * hdc = GetDC(toolbar)
6160 * GetSystemMetrics(0x48)
6161 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6162 * 0, 0, 0, 0, "MARLETT")
6163 * oldfnt = SelectObject(hdc, fnt2)
6164 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6165 * GetTextMetricsW(hdc, adr3)
6166 * SelectObject(hdc, oldfnt)
6167 * DeleteObject(fnt2)
6169 * InvalidateRect(toolbar, 0, 1)
6170 * SetWindowLongW(toolbar, 0, addr)
6171 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6174 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6175 * ie 2 0x4600094c 0x4600094c 0x4600894d
6176 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6177 * rebar 0x50008844 0x40008844 0x50008845
6178 * pager 0x50000844 0x40000844 0x50008845
6179 * IC35mgr 0x5400084e **nochange**
6180 * on entry to _NCCREATE 0x5400084e
6181 * rowlist 0x5400004e **nochange**
6182 * on entry to _NCCREATE 0x5400004e
6186 /* I think the code below is a bug, but it is the way that the native
6187 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6188 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6189 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6190 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6191 * Somehow, the only cases of this seem to be MFC programs.
6193 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6194 * does not occur in the WM_STYLECHANGING routine.
6195 * (Guy Albertelli 9/2001)
6198 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6199 && !(cs->style & TBSTYLE_TRANSPARENT))
6200 styleadd |= TBSTYLE_TRANSPARENT;
6201 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6202 styleadd |= CCS_TOP; /* default to top */
6203 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6206 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6211 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6213 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6217 if (dwStyle & WS_MINIMIZE)
6218 return 0; /* Nothing to do */
6220 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6222 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6225 if (!(dwStyle & CCS_NODIVIDER))
6227 GetWindowRect (hwnd, &rcWindow);
6228 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6229 if( dwStyle & WS_BORDER )
6230 OffsetRect (&rcWindow, 1, 1);
6231 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6234 ReleaseDC( hwnd, hdc );
6240 /* handles requests from the tooltip control on what text to display */
6241 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6243 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6245 TRACE("button index = %d\n", index);
6247 Free (infoPtr->pszTooltipText);
6248 infoPtr->pszTooltipText = NULL;
6253 if (infoPtr->bUnicode)
6255 WCHAR wszBuffer[INFOTIPSIZE+1];
6256 NMTBGETINFOTIPW tbgit;
6257 unsigned int len; /* in chars */
6259 wszBuffer[0] = '\0';
6260 wszBuffer[INFOTIPSIZE] = '\0';
6262 tbgit.pszText = wszBuffer;
6263 tbgit.cchTextMax = INFOTIPSIZE;
6264 tbgit.iItem = lpnmtdi->hdr.idFrom;
6265 tbgit.lParam = infoPtr->buttons[index].dwData;
6267 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6269 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6271 len = strlenW(tbgit.pszText);
6272 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6274 /* need to allocate temporary buffer in infoPtr as there
6275 * isn't enough space in buffer passed to us by the
6276 * tooltip control */
6277 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6278 if (infoPtr->pszTooltipText)
6280 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6281 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6287 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6293 CHAR szBuffer[INFOTIPSIZE+1];
6294 NMTBGETINFOTIPA tbgit;
6295 unsigned int len; /* in chars */
6298 szBuffer[INFOTIPSIZE] = '\0';
6300 tbgit.pszText = szBuffer;
6301 tbgit.cchTextMax = INFOTIPSIZE;
6302 tbgit.iItem = lpnmtdi->hdr.idFrom;
6303 tbgit.lParam = infoPtr->buttons[index].dwData;
6305 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6307 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6309 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6310 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6312 /* need to allocate temporary buffer in infoPtr as there
6313 * isn't enough space in buffer passed to us by the
6314 * tooltip control */
6315 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6316 if (infoPtr->pszTooltipText)
6318 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6319 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6323 else if (tbgit.pszText[0])
6325 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6326 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6331 /* if button has text, but it is not shown then automatically
6332 * use that text as tooltip */
6333 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6334 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6336 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6337 unsigned int len = pszText ? strlenW(pszText) : 0;
6339 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6341 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6343 /* need to allocate temporary buffer in infoPtr as there
6344 * isn't enough space in buffer passed to us by the
6345 * tooltip control */
6346 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6347 if (infoPtr->pszTooltipText)
6349 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6350 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6356 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6361 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6363 /* last resort: send notification on to app */
6364 /* FIXME: find out what is really used here */
6365 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6369 static inline LRESULT
6370 TOOLBAR_Notify (HWND hwnd, LPARAM lParam)
6372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6373 LPNMHDR lpnmh = (LPNMHDR)lParam;
6375 switch (lpnmh->code)
6379 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6381 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6382 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6383 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6387 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6388 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6396 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6398 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6399 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6400 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6401 lppgs->iScroll, lppgs->iDir);
6405 case TTN_GETDISPINFOW:
6406 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6408 case TTN_GETDISPINFOA:
6409 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6419 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6423 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6425 if (lParam == NF_QUERY)
6428 if (lParam == NF_REQUERY) {
6429 format = SendMessageW(infoPtr->hwndNotify,
6430 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6431 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6432 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6443 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6449 /* fill ps.rcPaint with a default rect */
6450 ps.rcPaint = infoPtr->rcBound;
6452 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6454 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6456 TOOLBAR_Refresh (hwnd, hdc, &ps);
6457 if (!wParam) EndPaint (hwnd, &ps);
6464 TOOLBAR_SetFocus (HWND hwnd)
6466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6468 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6470 /* make first item hot */
6471 if (infoPtr->nNumButtons > 0)
6472 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6478 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6482 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6485 infoPtr->hFont = infoPtr->hDefaultFont;
6487 infoPtr->hFont = (HFONT)wParam;
6489 TOOLBAR_CalcToolbar(hwnd);
6492 InvalidateRect(hwnd, NULL, TRUE);
6497 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam)
6498 /*****************************************************
6501 * Handles the WM_SETREDRAW message.
6504 * According to testing V4.71 of COMCTL32 returns the
6505 * *previous* status of the redraw flag (either 0 or 1)
6506 * instead of the MSDN documented value of 0 if handled.
6507 * (For laughs see the "consistency" with same function
6510 *****************************************************/
6512 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6513 BOOL oldredraw = infoPtr->bDoRedraw;
6515 TRACE("set to %s\n",
6516 (wParam) ? "TRUE" : "FALSE");
6517 infoPtr->bDoRedraw = (BOOL) wParam;
6519 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6521 return (oldredraw) ? 1 : 0;
6526 TOOLBAR_Size (HWND hwnd)
6528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6530 TRACE("sizing toolbar!\n");
6532 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6534 RECT delta_width, delta_height, client, dummy;
6535 DWORD min_x, max_x, min_y, max_y;
6536 TBUTTON_INFO *btnPtr;
6539 GetClientRect(hwnd, &client);
6540 if(client.right > infoPtr->client_rect.right)
6542 min_x = infoPtr->client_rect.right;
6543 max_x = client.right;
6547 max_x = infoPtr->client_rect.right;
6548 min_x = client.right;
6550 if(client.bottom > infoPtr->client_rect.bottom)
6552 min_y = infoPtr->client_rect.bottom;
6553 max_y = client.bottom;
6557 max_y = infoPtr->client_rect.bottom;
6558 min_y = client.bottom;
6561 SetRect(&delta_width, min_x, 0, max_x, min_y);
6562 SetRect(&delta_height, 0, min_y, max_x, max_y);
6564 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6565 btnPtr = infoPtr->buttons;
6566 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6567 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6568 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6569 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6571 GetClientRect(hwnd, &infoPtr->client_rect);
6572 TOOLBAR_AutoSize(hwnd);
6578 TOOLBAR_StyleChanged (HWND hwnd, INT nType, const STYLESTRUCT *lpStyle)
6580 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6582 if (nType == GWL_STYLE)
6584 DWORD dwOldStyle = infoPtr->dwStyle;
6586 if (lpStyle->styleNew & TBSTYLE_LIST)
6587 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6589 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6591 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6593 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6595 infoPtr->dwStyle = lpStyle->styleNew;
6597 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6598 TOOLBAR_LayoutToolbar(hwnd);
6600 /* only resize if one of the CCS_* styles was changed */
6601 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6603 TOOLBAR_AutoSize (hwnd);
6605 InvalidateRect(hwnd, NULL, TRUE);
6614 TOOLBAR_SysColorChange ()
6616 COMCTL32_RefreshSysColors();
6622 /* update theme after a WM_THEMECHANGED message */
6623 static LRESULT theme_changed (HWND hwnd)
6625 HTHEME theme = GetWindowTheme (hwnd);
6626 CloseThemeData (theme);
6627 OpenThemeData (hwnd, themeClass);
6632 static LRESULT WINAPI
6633 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6637 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6638 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6640 if (!infoPtr && (uMsg != WM_NCCREATE))
6641 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6646 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6648 case TB_ADDBUTTONSA:
6649 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6651 case TB_ADDBUTTONSW:
6652 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6655 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6658 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6661 return TOOLBAR_AutoSize (hwnd);
6663 case TB_BUTTONCOUNT:
6664 return TOOLBAR_ButtonCount (hwnd);
6666 case TB_BUTTONSTRUCTSIZE:
6667 return TOOLBAR_ButtonStructSize (hwnd, wParam);
6669 case TB_CHANGEBITMAP:
6670 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6672 case TB_CHECKBUTTON:
6673 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6675 case TB_COMMANDTOINDEX:
6676 return TOOLBAR_CommandToIndex (hwnd, wParam);
6679 return TOOLBAR_Customize (hwnd);
6681 case TB_DELETEBUTTON:
6682 return TOOLBAR_DeleteButton (hwnd, wParam);
6684 case TB_ENABLEBUTTON:
6685 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6687 case TB_GETANCHORHIGHLIGHT:
6688 return TOOLBAR_GetAnchorHighlight (hwnd);
6691 return TOOLBAR_GetBitmap (hwnd, wParam);
6693 case TB_GETBITMAPFLAGS:
6694 return TOOLBAR_GetBitmapFlags ();
6697 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6699 case TB_GETBUTTONINFOA:
6700 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, FALSE);
6702 case TB_GETBUTTONINFOW:
6703 return TOOLBAR_GetButtonInfoT(hwnd, wParam, lParam, TRUE);
6705 case TB_GETBUTTONSIZE:
6706 return TOOLBAR_GetButtonSize (hwnd);
6708 case TB_GETBUTTONTEXTA:
6709 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6711 case TB_GETBUTTONTEXTW:
6712 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6714 case TB_GETDISABLEDIMAGELIST:
6715 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6717 case TB_GETEXTENDEDSTYLE:
6718 return TOOLBAR_GetExtendedStyle (hwnd);
6720 case TB_GETHOTIMAGELIST:
6721 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6724 return TOOLBAR_GetHotItem (hwnd);
6726 case TB_GETIMAGELIST:
6727 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6729 case TB_GETINSERTMARK:
6730 return TOOLBAR_GetInsertMark (hwnd, lParam);
6732 case TB_GETINSERTMARKCOLOR:
6733 return TOOLBAR_GetInsertMarkColor (hwnd);
6735 case TB_GETITEMRECT:
6736 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6739 return TOOLBAR_GetMaxSize (hwnd, lParam);
6741 /* case TB_GETOBJECT: */ /* 4.71 */
6744 return TOOLBAR_GetPadding (hwnd);
6747 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6750 return TOOLBAR_GetRows (hwnd);
6753 return TOOLBAR_GetState (hwnd, wParam);
6756 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6759 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6762 return TOOLBAR_GetStyle (hwnd);
6764 case TB_GETTEXTROWS:
6765 return TOOLBAR_GetTextRows (hwnd);
6767 case TB_GETTOOLTIPS:
6768 return TOOLBAR_GetToolTips (hwnd);
6770 case TB_GETUNICODEFORMAT:
6771 return TOOLBAR_GetUnicodeFormat (hwnd);
6774 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6777 return TOOLBAR_HitTest (hwnd, lParam);
6779 case TB_INDETERMINATE:
6780 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6782 case TB_INSERTBUTTONA:
6783 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6785 case TB_INSERTBUTTONW:
6786 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6788 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6790 case TB_ISBUTTONCHECKED:
6791 return TOOLBAR_IsButtonChecked (hwnd, wParam);
6793 case TB_ISBUTTONENABLED:
6794 return TOOLBAR_IsButtonEnabled (hwnd, wParam);
6796 case TB_ISBUTTONHIDDEN:
6797 return TOOLBAR_IsButtonHidden (hwnd, wParam);
6799 case TB_ISBUTTONHIGHLIGHTED:
6800 return TOOLBAR_IsButtonHighlighted (hwnd, wParam);
6802 case TB_ISBUTTONINDETERMINATE:
6803 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam);
6805 case TB_ISBUTTONPRESSED:
6806 return TOOLBAR_IsButtonPressed (hwnd, wParam);
6809 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6811 case TB_MAPACCELERATORA:
6812 case TB_MAPACCELERATORW:
6813 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6816 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6819 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6821 case TB_PRESSBUTTON:
6822 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6824 case TB_REPLACEBITMAP:
6825 return TOOLBAR_ReplaceBitmap (hwnd, lParam);
6827 case TB_SAVERESTOREA:
6828 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6830 case TB_SAVERESTOREW:
6831 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6833 case TB_SETANCHORHIGHLIGHT:
6834 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6836 case TB_SETBITMAPSIZE:
6837 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6839 case TB_SETBUTTONINFOA:
6840 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6842 case TB_SETBUTTONINFOW:
6843 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6845 case TB_SETBUTTONSIZE:
6846 return TOOLBAR_SetButtonSize (hwnd, lParam);
6848 case TB_SETBUTTONWIDTH:
6849 return TOOLBAR_SetButtonWidth (hwnd, lParam);
6852 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6854 case TB_SETDISABLEDIMAGELIST:
6855 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6857 case TB_SETDRAWTEXTFLAGS:
6858 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6860 case TB_SETEXTENDEDSTYLE:
6861 return TOOLBAR_SetExtendedStyle (hwnd, lParam);
6863 case TB_SETHOTIMAGELIST:
6864 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6867 return TOOLBAR_SetHotItem (hwnd, wParam);
6869 case TB_SETIMAGELIST:
6870 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6873 return TOOLBAR_SetIndent (hwnd, wParam);
6875 case TB_SETINSERTMARK:
6876 return TOOLBAR_SetInsertMark (hwnd, lParam);
6878 case TB_SETINSERTMARKCOLOR:
6879 return TOOLBAR_SetInsertMarkColor (hwnd, lParam);
6881 case TB_SETMAXTEXTROWS:
6882 return TOOLBAR_SetMaxTextRows (hwnd, wParam);
6885 return TOOLBAR_SetPadding (hwnd, lParam);
6888 return TOOLBAR_SetParent (hwnd, wParam);
6891 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6894 return TOOLBAR_SetState (hwnd, wParam, lParam);
6897 return TOOLBAR_SetStyle (hwnd, lParam);
6899 case TB_SETTOOLTIPS:
6900 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6902 case TB_SETUNICODEFORMAT:
6903 return TOOLBAR_SetUnicodeFormat (hwnd, wParam);
6906 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6908 case TB_SETHOTITEM2:
6909 return TOOLBAR_SetHotItem2 (hwnd, wParam, lParam);
6912 return TOOLBAR_SetListGap(hwnd, wParam);
6914 case TB_GETIMAGELISTCOUNT:
6915 return TOOLBAR_GetImageListCount(hwnd, wParam, lParam);
6917 case TB_GETIDEALSIZE:
6918 return TOOLBAR_GetIdealSize (hwnd, wParam, lParam);
6921 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6923 /* Common Control Messages */
6925 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6926 case CCM_GETCOLORSCHEME:
6927 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6929 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6930 case CCM_SETCOLORSCHEME:
6931 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6933 case CCM_GETVERSION:
6934 return TOOLBAR_GetVersion (hwnd);
6936 case CCM_SETVERSION:
6937 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6943 return TOOLBAR_Create (hwnd, lParam);
6946 return TOOLBAR_Destroy (hwnd);
6949 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6952 return TOOLBAR_GetFont (hwnd);
6955 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6957 /* case WM_KILLFOCUS: */
6959 case WM_LBUTTONDBLCLK:
6960 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6962 case WM_LBUTTONDOWN:
6963 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6966 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6969 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6971 case WM_RBUTTONDBLCLK:
6972 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6975 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6978 return TOOLBAR_MouseLeave (hwnd);
6980 case WM_CAPTURECHANGED:
6981 return TOOLBAR_CaptureChanged(hwnd);
6984 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6987 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6990 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6993 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6996 return TOOLBAR_Notify (hwnd, lParam);
6998 case WM_NOTIFYFORMAT:
6999 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7001 case WM_PRINTCLIENT:
7003 return TOOLBAR_Paint (hwnd, wParam);
7006 return TOOLBAR_SetFocus (hwnd);
7009 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7012 return TOOLBAR_SetRedraw (hwnd, wParam);
7015 return TOOLBAR_Size (hwnd);
7017 case WM_STYLECHANGED:
7018 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7020 case WM_SYSCOLORCHANGE:
7021 return TOOLBAR_SysColorChange ();
7023 case WM_THEMECHANGED:
7024 return theme_changed (hwnd);
7026 /* case WM_WININICHANGE: */
7031 case WM_MEASUREITEM:
7033 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7035 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7036 case PGM_FORWARDMOUSE:
7037 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7040 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
7041 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
7042 uMsg, wParam, lParam);
7043 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7049 TOOLBAR_Register (void)
7053 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7054 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7055 wndClass.lpfnWndProc = ToolbarWindowProc;
7056 wndClass.cbClsExtra = 0;
7057 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7058 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7059 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7060 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7062 RegisterClassW (&wndClass);
7067 TOOLBAR_Unregister (void)
7069 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7072 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7077 /* Check if the entry already exists */
7078 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7080 /* If this is a new entry we must create it and insert into the array */
7085 c = Alloc(sizeof(IMLENTRY));
7088 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7089 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7104 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7108 for (i = 0; i < *cies; i++)
7118 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
7126 for (i = 0; i < cies; i++)
7128 if (pies[i]->id == id)
7140 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
7142 HIMAGELIST himlDef = 0;
7143 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7146 himlDef = pie->himl;
7152 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7154 if (infoPtr->bUnicode)
7155 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7162 nmtba.iItem = nmtb->iItem;
7163 nmtba.pszText = Buffer;
7164 nmtba.cchText = 256;
7165 ZeroMemory(nmtba.pszText, nmtba.cchText);
7167 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7169 int ccht = strlen(nmtba.pszText);
7171 MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
7172 nmtb->pszText, nmtb->cchText);
7174 nmtb->tbButton = nmtba.tbButton;
7183 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo)
7187 /* MSDN states that iItem is the index of the button, rather than the
7188 * command ID as used by every other NMTOOLBAR notification */
7190 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7192 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);