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).
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 */
128 INT nVBitmapHeight; /* see TOOLBAR_Create for an explanation */
131 INT nRows; /* number of button rows */
132 INT nMaxTextRows; /* maximum number of text rows */
133 INT cxMin; /* minimum button width */
134 INT cxMax; /* maximum button width */
135 INT nNumButtons; /* number of buttons */
136 INT nNumBitmaps; /* number of bitmaps */
137 INT nNumStrings; /* number of strings */
139 INT nButtonDown; /* toolbar button being pressed or -1 if none */
140 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
142 INT nHotItem; /* index of the "hot" item */
143 SIZE szPadding; /* padding values around button */
144 INT iTopMargin; /* the top margin */
145 INT iListGap; /* default gap between text and image for toolbar with list style */
147 HFONT hFont; /* text font */
148 HIMAGELIST himlInt; /* image list created internally */
149 PIMLENTRY *himlDef; /* default image list array */
150 INT cimlDef; /* default image list array count */
151 PIMLENTRY *himlHot; /* hot image list array */
152 INT cimlHot; /* hot image list array count */
153 PIMLENTRY *himlDis; /* disabled image list array */
154 INT cimlDis; /* disabled image list array count */
155 HWND hwndToolTip; /* handle to tool tip control */
156 HWND hwndNotify; /* handle to the window that gets notifications */
157 HWND hwndSelf; /* my own handle */
158 BOOL bAnchor; /* anchor highlight enabled */
159 BOOL bDoRedraw; /* Redraw status */
160 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
161 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
162 BOOL bCaptured; /* mouse captured? */
163 DWORD dwStyle; /* regular toolbar style */
164 DWORD dwExStyle; /* extended toolbar style */
165 DWORD dwDTFlags; /* DrawText flags */
167 COLORREF clrInsertMark; /* insert mark color */
168 COLORREF clrBtnHighlight; /* color for Flat Separator */
169 COLORREF clrBtnShadow; /* color for Flag Separator */
171 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
172 * for TTN_GETDISPINFOW notification */
173 TBINSERTMARK tbim; /* info on insertion mark */
174 TBUTTON_INFO *buttons; /* pointer to button array */
175 LPWSTR *strings; /* pointer to string array */
176 TBITMAP_INFO *bitmaps;
177 } TOOLBAR_INFO, *PTOOLBAR_INFO;
180 /* used by customization dialog */
183 PTOOLBAR_INFO tbInfo;
185 } CUSTDLG_INFO, *PCUSTDLG_INFO;
193 } CUSTOMBUTTON, *PCUSTOMBUTTON;
202 #define SEPARATOR_WIDTH 8
204 #define BOTTOM_BORDER 2
205 #define DDARROW_WIDTH 11
206 #define ARROW_HEIGHT 3
207 #define INSERTMARK_WIDTH 2
213 /* vertical padding used in list mode when image is present */
216 /* how wide to treat the bitmap if it isn't present */
217 #define NONLIST_NOTEXT_OFFSET 2
219 #define TOOLBAR_NOWHERE (-1)
221 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
222 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
223 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
225 /* Used to find undocumented extended styles */
226 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
227 TBSTYLE_EX_UNDOC1 | \
228 TBSTYLE_EX_MIXEDBUTTONS | \
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(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
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_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
257 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 inline static int default_top_margin(TOOLBAR_INFO *infoPtr)
261 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
265 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
267 LPWSTR lpText = NULL;
269 /* NOTE: iString == -1 is undocumented */
270 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
271 lpText = (LPWSTR)btnPtr->iString;
272 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
273 lpText = infoPtr->strings[btnPtr->iString];
279 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
281 if (TRACE_ON(toolbar)){
282 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
283 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
284 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
285 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
287 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
288 btn_num, bP->idCommand,
289 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
290 bP->rect.left, bP->rect.top,
291 bP->rect.right, bP->rect.bottom);
297 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
299 if (TRACE_ON(toolbar)) {
302 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
304 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
305 iP->nNumStrings, iP->dwStyle);
306 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
308 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
309 (iP->bDoRedraw) ? "TRUE" : "FALSE");
310 for(i=0; i<iP->nNumButtons; i++) {
311 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
317 /***********************************************************************
320 * This function validates that the styles set are implemented and
321 * issues FIXME's warning of possible problems. In a perfect world this
322 * function should be null.
325 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
327 if (dwStyle & TBSTYLE_REGISTERDROP)
328 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
333 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
335 if(!IsWindow(infoPtr->hwndSelf))
336 return 0; /* we have just been destroyed */
338 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
339 nmhdr->hwndFrom = infoPtr->hwndSelf;
342 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
343 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
345 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
346 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
349 /***********************************************************************
350 * TOOLBAR_GetBitmapIndex
352 * This function returns the bitmap index associated with a button.
353 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
354 * is issued to retrieve the index.
357 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
359 INT ret = btnPtr->iBitmap;
361 if (ret == I_IMAGECALLBACK)
363 /* issue TBN_GETDISPINFO */
366 memset(&nmgd, 0, sizeof(nmgd));
367 nmgd.idCommand = btnPtr->idCommand;
368 nmgd.lParam = btnPtr->dwData;
369 nmgd.dwMask = TBNF_IMAGE;
370 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
371 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
372 if (nmgd.dwMask & TBNF_DI_SETITEM)
373 btnPtr->iBitmap = nmgd.iImage;
375 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
376 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
379 if (ret != I_IMAGENONE)
380 ret = GETIBITMAP(infoPtr, ret);
387 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
390 INT id = GETHIMLID(infoPtr, index);
391 INT iBitmap = GETIBITMAP(infoPtr, index);
393 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
394 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
395 (index == I_IMAGECALLBACK))
403 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
405 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
406 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
410 /***********************************************************************
411 * TOOLBAR_GetImageListForDrawing
413 * This function validates the bitmap index (including I_IMAGECALLBACK
414 * functionality) and returns the corresponding image list.
417 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
421 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
422 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
423 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
424 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
428 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
429 if ((*index == I_IMAGECALLBACK) ||
430 (*index == I_IMAGENONE)) return NULL;
431 ERR("TBN_GETDISPINFO returned invalid index %d\n",
438 case IMAGE_LIST_DEFAULT:
439 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
442 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
444 case IMAGE_LIST_DISABLED:
445 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
449 FIXME("Shouldn't reach here\n");
453 TRACE("no image list\n");
460 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
463 COLORREF oldcolor, newcolor;
465 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
466 myrect.right = myrect.left + 1;
467 myrect.top = lpRect->top + 2;
468 myrect.bottom = lpRect->bottom - 2;
470 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
471 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
472 oldcolor = SetBkColor (hdc, newcolor);
473 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
475 myrect.left = myrect.right;
476 myrect.right = myrect.left + 1;
478 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
479 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
480 SetBkColor (hdc, newcolor);
481 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
483 SetBkColor (hdc, oldcolor);
487 /***********************************************************************
488 * TOOLBAR_DrawDDFlatSeparator
490 * This function draws the separator that was flagged as BTNS_DROPDOWN.
491 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
492 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
493 * are horizontal as opposed to the vertical separators for not dropdown
496 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
499 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
502 COLORREF oldcolor, newcolor;
504 myrect.left = lpRect->left;
505 myrect.right = lpRect->right;
506 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
507 myrect.bottom = myrect.top + 1;
509 InflateRect (&myrect, -2, 0);
511 TRACE("rect=(%d,%d)-(%d,%d)\n",
512 myrect.left, myrect.top, myrect.right, myrect.bottom);
514 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
515 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
516 oldcolor = SetBkColor (hdc, newcolor);
517 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
519 myrect.top = myrect.bottom;
520 myrect.bottom = myrect.top + 1;
522 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
523 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
524 SetBkColor (hdc, newcolor);
525 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
527 SetBkColor (hdc, oldcolor);
532 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
537 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
538 hOldPen = SelectObject ( hdc, hPen );
541 MoveToEx (hdc, x, y, NULL);
542 LineTo (hdc, x+5, y++); x++;
543 MoveToEx (hdc, x, y, NULL);
544 LineTo (hdc, x+3, y++); x++;
545 MoveToEx (hdc, x, y, NULL);
546 LineTo (hdc, x+1, y++);
547 SelectObject( hdc, hOldPen );
548 DeleteObject( hPen );
552 * Draw the text string for this button.
553 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
554 * is non-zero, so we can simply check himlDef to see if we have
558 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
559 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
561 HDC hdc = tbcd->nmcd.hdc;
564 COLORREF clrOldBk = 0;
566 UINT state = tbcd->nmcd.uItemState;
570 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
571 rcText->left, rcText->top, rcText->right, rcText->bottom);
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
575 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
577 else if (state & CDIS_DISABLED) {
578 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
579 OffsetRect (rcText, 1, 1);
580 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
581 SetTextColor (hdc, comctl32_color.clr3dShadow);
582 OffsetRect (rcText, -1, -1);
584 else if (state & CDIS_INDETERMINATE) {
585 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
587 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
588 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
589 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
590 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
593 clrOld = SetTextColor (hdc, tbcd->clrText);
596 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
597 SetTextColor (hdc, clrOld);
598 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
600 SetBkColor (hdc, clrOldBk);
601 SetBkMode (hdc, oldBkMode);
603 SelectObject (hdc, hOldFont);
609 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
611 HDC hdc = tbcd->nmcd.hdc;
612 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
615 INT cx = lpRect->right - lpRect->left;
616 INT cy = lpRect->bottom - lpRect->top;
617 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
618 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
619 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
620 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
621 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
622 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
623 SetBkColor(hdc, clrBkOld);
624 SetTextColor(hdc, clrTextOld);
625 SelectObject (hdc, hbr);
629 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
632 HBITMAP hbmMask, hbmImage;
633 HDC hdcMask, hdcImage;
635 ImageList_GetIconSize(himl, &cx, &cy);
637 /* Create src image */
638 hdcImage = CreateCompatibleDC(hdc);
639 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
640 SelectObject(hdcImage, hbmImage);
641 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
642 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
645 hdcMask = CreateCompatibleDC(0);
646 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
647 SelectObject(hdcMask, hbmMask);
649 /* Remove the background and all white pixels */
650 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
651 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
652 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
653 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
655 /* draw the new mask 'etched' to hdc */
656 SetBkColor(hdc, RGB(255, 255, 255));
657 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
658 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
659 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
660 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
661 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
664 DeleteObject(hbmImage);
666 DeleteObject (hbmMask);
672 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
676 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
678 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
679 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
680 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
681 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
682 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
686 /* draws the image on a toolbar button */
688 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
689 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
691 HIMAGELIST himl = NULL;
692 BOOL draw_masked = FALSE;
695 UINT draw_flags = ILD_TRANSPARENT;
697 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
699 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
706 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
707 ((tbcd->nmcd.uItemState & CDIS_HOT)
708 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
710 /* if hot, attempt to draw with hot image list, if fails,
711 use default image list */
712 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
722 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
723 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
726 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
727 (tbcd->nmcd.uItemState & CDIS_MARKED))
728 draw_flags |= ILD_BLEND50;
730 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
731 index, himl, left, top, offset);
734 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
736 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
739 /* draws a blank frame for a toolbar button */
741 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
743 HDC hdc = tbcd->nmcd.hdc;
744 RECT rc = tbcd->nmcd.rc;
745 /* if the state is disabled or indeterminate then the button
746 * cannot have an interactive look like pressed or hot */
747 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
748 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
749 BOOL pressed_look = !non_interactive_state &&
750 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
751 (tbcd->nmcd.uItemState & CDIS_CHECKED));
753 /* app don't want us to draw any edges */
754 if (dwItemCDFlag & TBCDRF_NOEDGES)
757 if (infoPtr->dwStyle & TBSTYLE_FLAT)
760 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
761 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
762 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
767 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
769 DrawEdge (hdc, &rc, EDGE_RAISED,
770 BF_SOFT | BF_RECT | BF_MIDDLE);
775 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
777 HDC hdc = tbcd->nmcd.hdc;
779 BOOL pressed = bDropDownPressed ||
780 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
782 if (infoPtr->dwStyle & TBSTYLE_FLAT)
785 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
786 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
787 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
788 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
789 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
794 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
796 DrawEdge (hdc, rcArrow, EDGE_RAISED,
797 BF_SOFT | BF_RECT | BF_MIDDLE);
801 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
803 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
805 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
806 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
809 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
812 /* draws a complete toolbar button */
814 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
817 DWORD dwStyle = infoPtr->dwStyle;
818 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
819 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
820 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
821 BOOL drawSepDropDownArrow = hasDropDownArrow &&
822 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
823 RECT rc, rcArrow, rcBitmap, rcText;
824 LPWSTR lpText = NULL;
829 DWORD dwItemCustDraw;
831 HTHEME theme = GetWindowTheme (hwnd);
834 CopyRect (&rcArrow, &rc);
836 /* separator - doesn't send NM_CUSTOMDRAW */
837 if (btnPtr->fsStyle & BTNS_SEP) {
840 DrawThemeBackground (theme, hdc,
841 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
845 /* with the FLAT style, iBitmap is the width and has already */
846 /* been taken into consideration in calculating the width */
847 /* so now we need to draw the vertical separator */
848 /* empirical tests show that iBitmap can/will be non-zero */
849 /* when drawing the vertical bar... */
850 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
851 if (btnPtr->fsStyle & BTNS_DROPDOWN)
852 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
854 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
856 else if (btnPtr->fsStyle != BTNS_SEP) {
857 FIXME("Draw some kind of separator: fsStyle=%x\n",
863 /* get a pointer to the text */
864 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
866 if (hasDropDownArrow)
870 if (dwStyle & TBSTYLE_FLAT)
871 right = max(rc.left, rc.right - DDARROW_WIDTH);
873 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
875 if (drawSepDropDownArrow)
878 rcArrow.left = right;
881 /* copy text & bitmap rects after adjusting for drop-down arrow
882 * so that text & bitmap is centred in the rectangle not containing
884 CopyRect(&rcText, &rc);
885 CopyRect(&rcBitmap, &rc);
887 /* Center the bitmap horizontally and vertically */
888 if (dwStyle & TBSTYLE_LIST)
891 infoPtr->nMaxTextRows > 0 &&
892 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
893 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
894 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
896 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
899 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
901 rcBitmap.top += infoPtr->szPadding.cy / 2;
903 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
904 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
905 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
906 TRACE("Text=%s\n", debugstr_w(lpText));
907 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
909 /* calculate text position */
912 rcText.left += GetSystemMetrics(SM_CXEDGE);
913 rcText.right -= GetSystemMetrics(SM_CXEDGE);
914 if (dwStyle & TBSTYLE_LIST)
916 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
917 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
921 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
922 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
924 rcText.top += infoPtr->szPadding.cy/2 + 2;
928 /* Initialize fields in all cases, because we use these later
929 * NOTE: applications can and do alter these to customize their
931 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
932 tbcd.clrText = comctl32_color.clrBtnText;
933 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
934 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
935 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
936 tbcd.clrMark = comctl32_color.clrHighlight;
937 tbcd.clrHighlightHotTrack = 0;
938 tbcd.nStringBkMode = TRANSPARENT;
939 tbcd.nHLStringBkMode = OPAQUE;
940 /* MSDN says that this is the text rectangle.
941 * But (why always a but) tracing of v5.7 of native shows
942 * that this is really a *relative* rectangle based on the
943 * the nmcd.rc. Also the left and top are always 0 ignoring
944 * any bitmap that might be present. */
945 tbcd.rcText.left = 0;
947 tbcd.rcText.right = rcText.right - rc.left;
948 tbcd.rcText.bottom = rcText.bottom - rc.top;
949 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
952 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
954 /* FIXME: what are these used for? */
958 /* Issue Item Prepaint notify */
961 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
963 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
964 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
965 tbcd.nmcd.lItemlParam = btnPtr->dwData;
966 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
967 /* reset these fields so the user can't alter the behaviour like native */
971 dwItemCustDraw = ntfret & 0xffff;
972 dwItemCDFlag = ntfret & 0xffff0000;
973 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
975 /* save the only part of the rect that the user can change */
976 rcText.right = tbcd.rcText.right + rc.left;
977 rcText.bottom = tbcd.rcText.bottom + rc.top;
980 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
981 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
982 OffsetRect(&rcText, 1, 1);
984 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
985 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
986 TOOLBAR_DrawPattern (&rc, &tbcd);
988 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
989 && (tbcd.nmcd.uItemState & CDIS_HOT))
991 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
995 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
996 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
997 if (hasDropDownArrow)
998 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
999 SetBkColor(hdc, oldclr);
1005 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1006 int stateId = TS_NORMAL;
1008 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1009 stateId = TS_DISABLED;
1010 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1011 stateId = TS_PRESSED;
1012 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1013 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1014 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1015 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1018 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1021 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1023 if (drawSepDropDownArrow)
1027 int stateId = TS_NORMAL;
1029 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1030 stateId = TS_DISABLED;
1031 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1032 stateId = TS_PRESSED;
1033 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1034 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1035 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1038 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1039 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1042 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1045 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1046 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1047 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1048 SetBkMode (hdc, oldBkMode);
1050 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1052 if (hasDropDownArrow && !drawSepDropDownArrow)
1054 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1059 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1061 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1065 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1068 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1070 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1071 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1078 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1081 TBUTTON_INFO *btnPtr;
1083 RECT rcTemp, rcClient;
1084 NMTBCUSTOMDRAW tbcd;
1086 DWORD dwBaseCustDraw;
1088 /* the app has told us not to redraw the toolbar */
1089 if (!infoPtr->bDoRedraw)
1092 /* if imagelist belongs to the app, it can be changed
1093 by the app after setting it */
1094 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1096 infoPtr->nNumBitmaps = 0;
1097 for (i = 0; i < infoPtr->cimlDef; i++)
1098 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1101 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1103 /* change the imagelist icon size if we manage the list and it is necessary */
1104 TOOLBAR_CheckImageListIconSize(infoPtr);
1106 /* Send initial notify */
1107 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1108 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1109 tbcd.nmcd.hdc = hdc;
1110 tbcd.nmcd.rc = ps->rcPaint;
1111 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1112 dwBaseCustDraw = ntfret & 0xffff;
1114 GetClientRect(hwnd, &rcClient);
1116 /* redraw necessary buttons */
1117 btnPtr = infoPtr->buttons;
1118 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1121 if (!RectVisible(hdc, &btnPtr->rect))
1123 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1125 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1126 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1130 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1131 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1133 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1136 /* draw insert mark if required */
1137 if (infoPtr->tbim.iButton != -1)
1139 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1141 rcInsertMark.top = rcButton.top;
1142 rcInsertMark.bottom = rcButton.bottom;
1143 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1144 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1146 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1147 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1150 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1152 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1153 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1154 tbcd.nmcd.hdc = hdc;
1155 tbcd.nmcd.rc = ps->rcPaint;
1156 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1160 /***********************************************************************
1161 * TOOLBAR_MeasureString
1163 * This function gets the width and height of a string in pixels. This
1164 * is done first by using GetTextExtentPoint to get the basic width
1165 * and height. The DrawText is called with DT_CALCRECT to get the exact
1166 * width. The reason is because the text may have more than one "&" (or
1167 * prefix characters as M$ likes to call them). The prefix character
1168 * indicates where the underline goes, except for the string "&&" which
1169 * is reduced to a single "&". GetTextExtentPoint does not process these
1170 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1173 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1174 HDC hdc, LPSIZE lpSize)
1181 if (infoPtr->nMaxTextRows > 0 &&
1182 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1183 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1184 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1186 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1188 if(lpText != NULL) {
1189 /* first get size of all the text */
1190 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1192 /* feed above size into the rectangle for DrawText */
1193 myrect.left = myrect.top = 0;
1194 myrect.right = lpSize->cx;
1195 myrect.bottom = lpSize->cy;
1197 /* Use DrawText to get true size as drawn (less pesky "&") */
1198 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1199 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1202 /* feed back to caller */
1203 lpSize->cx = myrect.right;
1204 lpSize->cy = myrect.bottom;
1208 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1211 /***********************************************************************
1212 * TOOLBAR_CalcStrings
1214 * This function walks through each string and measures it and returns
1215 * the largest height and width to caller.
1218 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1221 TBUTTON_INFO *btnPtr;
1230 if (infoPtr->nMaxTextRows == 0)
1234 hOldFont = SelectObject (hdc, infoPtr->hFont);
1236 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1240 GetTextMetricsW(hdc, &tm);
1241 lpSize->cy = tm.tmHeight;
1244 btnPtr = infoPtr->buttons;
1245 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1246 if(TOOLBAR_HasText(infoPtr, btnPtr))
1248 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1249 if (sz.cx > lpSize->cx)
1251 if (sz.cy > lpSize->cy)
1256 SelectObject (hdc, hOldFont);
1257 ReleaseDC (hwnd, hdc);
1259 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1262 /***********************************************************************
1263 * TOOLBAR_WrapToolbar
1265 * This function walks through the buttons and separators in the
1266 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1267 * wrapping should occur based on the width of the toolbar window.
1268 * It does *not* calculate button placement itself. That task
1269 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1270 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1271 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1273 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1274 * vertical toolbar lists.
1278 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1281 TBUTTON_INFO *btnPtr;
1284 BOOL bWrap, bButtonWrap;
1286 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1287 /* no layout is necessary. Applications may use this style */
1288 /* to perform their own layout on the toolbar. */
1289 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1290 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1292 btnPtr = infoPtr->buttons;
1293 x = infoPtr->nIndent;
1295 if (GetParent(hwnd))
1297 /* this can get the parents width, to know how far we can extend
1298 * this toolbar. We cannot use its height, as there may be multiple
1299 * toolbars in a rebar control
1301 GetClientRect( GetParent(hwnd), &rc );
1302 infoPtr->nWidth = rc.right - rc.left;
1306 GetWindowRect( hwnd, &rc );
1307 infoPtr->nWidth = rc.right - rc.left;
1310 bButtonWrap = FALSE;
1312 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1313 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1316 for (i = 0; i < infoPtr->nNumButtons; i++ )
1319 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1321 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1324 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1325 /* it is the actual width of the separator. This is used for */
1326 /* custom controls in toolbars. */
1328 /* BTNS_DROPDOWN separators are treated as buttons for */
1329 /* width. - GA 8/01 */
1330 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1331 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1332 cx = (btnPtr[i].iBitmap > 0) ?
1333 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1335 cx = infoPtr->nButtonWidth;
1337 /* Two or more adjacent separators form a separator group. */
1338 /* The first separator in a group should be wrapped to the */
1339 /* next row if the previous wrapping is on a button. */
1341 (btnPtr[i].fsStyle & BTNS_SEP) &&
1342 (i + 1 < infoPtr->nNumButtons ) &&
1343 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1345 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1346 btnPtr[i].fsState |= TBSTATE_WRAP;
1347 x = infoPtr->nIndent;
1349 bButtonWrap = FALSE;
1353 /* The layout makes sure the bitmap is visible, but not the button. */
1354 /* Test added to also wrap after a button that starts a row but */
1355 /* is bigger than the area. - GA 8/01 */
1356 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1357 > infoPtr->nWidth ) ||
1358 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1360 BOOL bFound = FALSE;
1362 /* If the current button is a separator and not hidden, */
1363 /* go to the next until it reaches a non separator. */
1364 /* Wrap the last separator if it is before a button. */
1365 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1366 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1367 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1368 i < infoPtr->nNumButtons )
1374 if( bFound && i < infoPtr->nNumButtons )
1377 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1378 i, btnPtr[i].fsStyle, x, cx);
1379 btnPtr[i].fsState |= TBSTATE_WRAP;
1380 x = infoPtr->nIndent;
1381 bButtonWrap = FALSE;
1384 else if ( i >= infoPtr->nNumButtons)
1387 /* If the current button is not a separator, find the last */
1388 /* separator and wrap it. */
1389 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1391 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1392 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1396 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1397 i, btnPtr[i].fsStyle, x, cx);
1398 x = infoPtr->nIndent;
1399 btnPtr[j].fsState |= TBSTATE_WRAP;
1400 bButtonWrap = FALSE;
1405 /* If no separator available for wrapping, wrap one of */
1406 /* non-hidden previous button. */
1410 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1412 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1417 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1418 i, btnPtr[i].fsStyle, x, cx);
1419 x = infoPtr->nIndent;
1420 btnPtr[j].fsState |= TBSTATE_WRAP;
1426 /* If all above failed, wrap the current button. */
1429 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1430 i, btnPtr[i].fsStyle, x, cx);
1431 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(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1560 if (infoPtr->dwStyle & TBSTYLE_LIST)
1562 /* set button height from bitmap / text height... */
1563 sizeButton.cy = max((bHasBitmap ? infoPtr->nVBitmapHeight : 0),
1566 /* ... add on the necessary padding */
1567 if (bValidImageList)
1570 sizeButton.cy += DEFPAD_CY;
1572 sizeButton.cy += LISTPAD_CY;
1575 sizeButton.cy += infoPtr->szPadding.cy;
1577 /* calculate button width */
1580 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1581 infoPtr->nBitmapWidth + infoPtr->iListGap;
1582 if (sizeString.cx > 0)
1583 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1586 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1592 sizeButton.cy = infoPtr->nVBitmapHeight + DEFPAD_CY;
1593 if (sizeString.cy > 0)
1594 sizeButton.cy += 1 + sizeString.cy;
1595 sizeButton.cx = infoPtr->szPadding.cx +
1596 max(sizeString.cx, infoPtr->nBitmapWidth);
1600 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1601 NONLIST_NOTEXT_OFFSET;
1602 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1603 infoPtr->szPadding.cx + sizeString.cx;
1610 /***********************************************************************
1611 * TOOLBAR_CalcToolbar
1613 * This function calculates button and separator placement. It first
1614 * calculates the button sizes, gets the toolbar window width and then
1615 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1616 * on. It assigns a new location to each item and sends this location to
1617 * the tooltip window if appropriate. Finally, it updates the rcBound
1618 * rect and calculates the new required toolbar window height.
1621 TOOLBAR_CalcToolbar (HWND hwnd)
1623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1624 SIZE sizeString, sizeButton;
1625 BOOL validImageList = FALSE;
1627 TOOLBAR_CalcStrings (hwnd, &sizeString);
1629 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1631 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1632 validImageList = TRUE;
1633 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1634 infoPtr->nButtonWidth = sizeButton.cx;
1635 infoPtr->nButtonHeight = sizeButton.cy;
1636 infoPtr->iTopMargin = default_top_margin(infoPtr);
1638 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1639 infoPtr->nButtonWidth = infoPtr->cxMin;
1640 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1641 infoPtr->nButtonWidth = infoPtr->cxMax;
1643 TOOLBAR_LayoutToolbar(hwnd);
1647 TOOLBAR_LayoutToolbar(HWND hwnd)
1649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1650 TBUTTON_INFO *btnPtr;
1652 INT i, nRows, nSepRows;
1655 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1656 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1658 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1660 x = infoPtr->nIndent;
1661 y = infoPtr->iTopMargin;
1662 cx = infoPtr->nButtonWidth;
1663 cy = infoPtr->nButtonHeight;
1665 nRows = nSepRows = 0;
1667 infoPtr->rcBound.top = y;
1668 infoPtr->rcBound.left = x;
1669 infoPtr->rcBound.bottom = y + cy;
1670 infoPtr->rcBound.right = x;
1672 btnPtr = infoPtr->buttons;
1674 TRACE("cy=%d\n", cy);
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1679 if (btnPtr->fsState & TBSTATE_HIDDEN)
1681 SetRectEmpty (&btnPtr->rect);
1685 cy = infoPtr->nButtonHeight;
1687 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1688 /* it is the actual width of the separator. This is used for */
1689 /* custom controls in toolbars. */
1690 if (btnPtr->fsStyle & BTNS_SEP) {
1691 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1692 cy = (btnPtr->iBitmap > 0) ?
1693 btnPtr->iBitmap : SEPARATOR_WIDTH;
1694 cx = infoPtr->nButtonWidth;
1697 cx = (btnPtr->iBitmap > 0) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH;
1704 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1705 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1712 hOldFont = SelectObject (hdc, infoPtr->hFont);
1714 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1716 SelectObject (hdc, hOldFont);
1717 ReleaseDC (hwnd, hdc);
1719 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1720 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1725 cx = infoPtr->nButtonWidth;
1727 /* if size has been set manually then don't add on extra space
1728 * for the drop down arrow */
1729 if (!btnPtr->cx && hasDropDownArrows &&
1730 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1731 cx += DDARROW_WIDTH;
1733 if (btnPtr->fsState & TBSTATE_WRAP )
1736 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1738 if (infoPtr->rcBound.left > x)
1739 infoPtr->rcBound.left = x;
1740 if (infoPtr->rcBound.right < x + cx)
1741 infoPtr->rcBound.right = x + cx;
1742 if (infoPtr->rcBound.bottom < y + cy)
1743 infoPtr->rcBound.bottom = y + cy;
1745 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1747 /* btnPtr->nRow is zero based. The space between the rows is */
1748 /* also considered as a row. */
1749 btnPtr->nRow = nRows + nSepRows;
1751 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1752 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1757 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1761 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1762 /* it is the actual width of the separator. This is used for */
1763 /* custom controls in toolbars. */
1764 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1765 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1766 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1770 /* nSepRows is used to calculate the extra height follwoing */
1774 x = infoPtr->nIndent;
1776 /* Increment row number unless this is the last button */
1777 /* and it has Wrap set. */
1778 if (i != infoPtr->nNumButtons-1)
1785 /* infoPtr->nRows is the number of rows on the toolbar */
1786 infoPtr->nRows = nRows + nSepRows + 1;
1788 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1793 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1796 TBUTTON_INFO *btnPtr;
1799 btnPtr = infoPtr->buttons;
1800 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1801 if (btnPtr->fsState & TBSTATE_HIDDEN)
1804 if (btnPtr->fsStyle & BTNS_SEP) {
1805 if (PtInRect (&btnPtr->rect, *lpPt)) {
1806 TRACE(" ON SEPARATOR %d!\n", i);
1811 if (PtInRect (&btnPtr->rect, *lpPt)) {
1812 TRACE(" ON BUTTON %d!\n", i);
1818 TRACE(" NOWHERE!\n");
1819 return TOOLBAR_NOWHERE;
1824 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1826 TBUTTON_INFO *btnPtr;
1829 if (CommandIsIndex) {
1830 TRACE("command is really index command=%d\n", idCommand);
1831 if (idCommand >= infoPtr->nNumButtons) return -1;
1834 btnPtr = infoPtr->buttons;
1835 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1836 if (btnPtr->idCommand == idCommand) {
1837 TRACE("command=%d index=%d\n", idCommand, i);
1841 TRACE("no index found for command=%d\n", idCommand);
1847 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1849 TBUTTON_INFO *btnPtr;
1852 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1855 /* check index button */
1856 btnPtr = &infoPtr->buttons[nIndex];
1857 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1858 if (btnPtr->fsState & TBSTATE_CHECKED)
1862 /* check previous buttons */
1863 nRunIndex = nIndex - 1;
1864 while (nRunIndex >= 0) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1875 /* check next buttons */
1876 nRunIndex = nIndex + 1;
1877 while (nRunIndex < infoPtr->nNumButtons) {
1878 btnPtr = &infoPtr->buttons[nRunIndex];
1879 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1880 if (btnPtr->fsState & TBSTATE_CHECKED)
1893 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1894 WPARAM wParam, LPARAM lParam)
1900 msg.wParam = wParam;
1901 msg.lParam = lParam;
1902 msg.time = GetMessageTime ();
1903 msg.pt.x = (short)LOWORD(GetMessagePos ());
1904 msg.pt.y = (short)HIWORD(GetMessagePos ());
1906 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1910 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1912 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1915 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1916 ti.cbSize = sizeof (TTTOOLINFOW);
1917 ti.hwnd = infoPtr->hwndSelf;
1918 ti.uId = button->idCommand;
1920 ti.lpszText = LPSTR_TEXTCALLBACKW;
1921 /* ti.lParam = random value from the stack? */
1923 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1929 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1931 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1934 ZeroMemory(&ti, sizeof(ti));
1935 ti.cbSize = sizeof(ti);
1936 ti.hwnd = infoPtr->hwndSelf;
1937 ti.uId = button->idCommand;
1939 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1943 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1945 /* Set the toolTip only for non-hidden, non-separator button */
1946 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1950 ZeroMemory(&ti, sizeof(ti));
1951 ti.cbSize = sizeof(ti);
1952 ti.hwnd = infoPtr->hwndSelf;
1953 ti.uId = button->idCommand;
1954 ti.rect = button->rect;
1955 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1959 /* Creates the tooltip control */
1961 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1964 NMTOOLTIPSCREATED nmttc;
1966 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1967 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1968 infoPtr->hwndSelf, 0, 0, 0);
1970 if (!infoPtr->hwndToolTip)
1973 /* Send NM_TOOLTIPSCREATED notification */
1974 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1975 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1977 for (i = 0; i < infoPtr->nNumButtons; i++)
1979 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1980 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1984 /* keeps available button list box sorted by button id */
1985 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1989 PCUSTOMBUTTON btnInfo;
1990 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1994 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1996 /* position 0 is always separator */
1997 for (i = 1; i < count; i++)
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2000 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2002 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2003 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2007 /* id higher than all others add to end */
2008 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2009 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2012 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2016 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2018 if (nIndexFrom == nIndexTo)
2021 /* MSDN states that iItem is the index of the button, rather than the
2022 * command ID as used by every other NMTOOLBAR notification */
2023 nmtb.iItem = nIndexFrom;
2024 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2026 PCUSTOMBUTTON btnInfo;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2029 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2034 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2035 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2036 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2039 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2041 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2043 /* last item is always separator, so -2 instead of -1 */
2044 if (nIndexTo >= (count - 2))
2045 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2047 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2049 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2050 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2052 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2056 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2060 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2062 /* MSDN states that iItem is the index of the button, rather than the
2063 * command ID as used by every other NMTOOLBAR notification */
2064 nmtb.iItem = nIndexAvail;
2065 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2067 PCUSTOMBUTTON btnInfo;
2069 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2070 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2071 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2073 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2075 if (nIndexAvail != 0) /* index == 0 indicates separator */
2077 /* remove from 'available buttons' list */
2078 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2079 if (nIndexAvail == count-1)
2080 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2082 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2086 PCUSTOMBUTTON btnNew;
2088 /* duplicate 'separator' button */
2089 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2090 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2094 /* insert into 'toolbar button' list */
2095 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2096 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2098 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2100 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2104 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2106 PCUSTOMBUTTON btnInfo;
2107 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2109 TRACE("Remove: index %d\n", index);
2111 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2113 /* send TBN_QUERYDELETE notification */
2114 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2118 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2119 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2121 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2123 /* insert into 'available button' list */
2124 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2125 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2129 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2133 /* drag list notification function for toolbar buttons list box */
2134 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2136 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2137 switch (pDLI->uNotification)
2141 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2142 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2143 /* no dragging for last item (separator) */
2144 if (nCurrentItem >= (nCount - 1)) return FALSE;
2149 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2150 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2151 /* no dragging past last item (separator) */
2152 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2154 DrawInsert(hwnd, hwndList, nCurrentItem);
2155 /* FIXME: native uses "move button" cursor */
2156 return DL_COPYCURSOR;
2159 /* not over toolbar buttons list */
2160 if (nCurrentItem < 0)
2162 POINT ptWindow = pDLI->ptCursor;
2163 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2164 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2165 /* over available buttons list? */
2166 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2167 /* FIXME: native uses "move button" cursor */
2168 return DL_COPYCURSOR;
2170 /* clear drag arrow */
2171 DrawInsert(hwnd, hwndList, -1);
2172 return DL_STOPCURSOR;
2176 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2177 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2178 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2179 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2181 /* clear drag arrow */
2182 DrawInsert(hwnd, hwndList, -1);
2184 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2186 /* not over toolbar buttons list */
2189 POINT ptWindow = pDLI->ptCursor;
2190 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2191 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2192 /* over available buttons list? */
2193 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2194 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2199 /* Clear drag arrow */
2200 DrawInsert(hwnd, hwndList, -1);
2207 /* drag list notification function for available buttons list box */
2208 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2210 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2211 switch (pDLI->uNotification)
2217 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2218 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2219 /* no dragging past last item (separator) */
2220 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2222 DrawInsert(hwnd, hwndList, nCurrentItem);
2223 /* FIXME: native uses "move button" cursor */
2224 return DL_COPYCURSOR;
2227 /* not over toolbar buttons list */
2228 if (nCurrentItem < 0)
2230 POINT ptWindow = pDLI->ptCursor;
2231 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2232 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2233 /* over available buttons list? */
2234 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2235 /* FIXME: native uses "move button" cursor */
2236 return DL_COPYCURSOR;
2238 /* clear drag arrow */
2239 DrawInsert(hwnd, hwndList, -1);
2240 return DL_STOPCURSOR;
2244 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2245 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2246 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2247 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2249 /* clear drag arrow */
2250 DrawInsert(hwnd, hwndList, -1);
2252 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2256 /* Clear drag arrow */
2257 DrawInsert(hwnd, hwndList, -1);
2263 extern UINT uDragListMessage;
2265 /***********************************************************************
2266 * TOOLBAR_CustomizeDialogProc
2267 * This function implements the toolbar customization dialog.
2269 static INT_PTR CALLBACK
2270 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2272 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2273 PCUSTOMBUTTON btnInfo;
2275 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2280 custInfo = (PCUSTDLG_INFO)lParam;
2281 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2288 NMTBINITCUSTOMIZE nmtbic;
2290 infoPtr = custInfo->tbInfo;
2292 /* send TBN_QUERYINSERT notification */
2293 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2295 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2298 nmtbic.hwndDialog = hwnd;
2299 /* Send TBN_INITCUSTOMIZE notification */
2300 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2303 TRACE("TBNRF_HIDEHELP requested\n");
2304 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2307 /* add items to 'toolbar buttons' list and check if removable */
2308 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2310 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2311 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2312 btnInfo->btn.fsStyle = BTNS_SEP;
2313 btnInfo->bVirtual = FALSE;
2314 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2316 /* send TBN_QUERYDELETE notification */
2317 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2319 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2320 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2323 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2325 /* insert separator button into 'available buttons' list */
2326 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2327 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2328 btnInfo->btn.fsStyle = BTNS_SEP;
2329 btnInfo->bVirtual = FALSE;
2330 btnInfo->bRemovable = TRUE;
2331 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2332 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2333 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2335 /* insert all buttons into dsa */
2338 /* send TBN_GETBUTTONINFO notification */
2341 nmtb.pszText = Buffer;
2344 /* Clear previous button's text */
2345 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2347 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2350 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2351 nmtb.tbButton.fsStyle, i,
2352 nmtb.tbButton.idCommand,
2353 nmtb.tbButton.iString,
2354 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2357 /* insert button into the apropriate list */
2358 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2361 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2362 btnInfo->bVirtual = FALSE;
2363 btnInfo->bRemovable = TRUE;
2367 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2368 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2371 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2372 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2374 if (lstrlenW(nmtb.pszText))
2375 lstrcpyW(btnInfo->text, nmtb.pszText);
2376 else if (nmtb.tbButton.iString >= 0 &&
2377 nmtb.tbButton.iString < infoPtr->nNumStrings)
2379 lstrcpyW(btnInfo->text,
2380 infoPtr->strings[nmtb.tbButton.iString]);
2385 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2388 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2390 /* select first item in the 'available' list */
2391 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2393 /* append 'virtual' separator button to the 'toolbar buttons' list */
2394 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2395 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2396 btnInfo->btn.fsStyle = BTNS_SEP;
2397 btnInfo->bVirtual = TRUE;
2398 btnInfo->bRemovable = FALSE;
2399 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2400 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2401 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2403 /* select last item in the 'toolbar' list */
2404 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2405 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2407 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2408 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2410 /* set focus and disable buttons */
2411 PostMessageW (hwnd, WM_USER, 0, 0);
2416 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2417 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2418 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2419 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2423 EndDialog(hwnd, FALSE);
2427 switch (LOWORD(wParam))
2429 case IDC_TOOLBARBTN_LBOX:
2430 if (HIWORD(wParam) == LBN_SELCHANGE)
2432 PCUSTOMBUTTON btnInfo;
2437 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2438 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2440 /* send TBN_QUERYINSERT notification */
2442 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2444 /* get list box item */
2445 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2447 if (index == (count - 1))
2449 /* last item (virtual separator) */
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2453 else if (index == (count - 2))
2455 /* second last item (last non-virtual item) */
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2457 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2459 else if (index == 0)
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2463 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2468 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2471 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2475 case IDC_MOVEUP_BTN:
2477 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2478 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2482 case IDC_MOVEDN_BTN: /* move down */
2484 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2485 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2489 case IDC_REMOVE_BTN: /* remove button */
2491 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2493 if (LB_ERR == index)
2496 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2500 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2503 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2506 case IDOK: /* Add button */
2511 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2512 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2514 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2519 EndDialog(hwnd, FALSE);
2529 /* delete items from 'toolbar buttons' listbox*/
2530 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2531 for (i = 0; i < count; i++)
2533 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2535 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2537 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2540 /* delete items from 'available buttons' listbox*/
2541 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2542 for (i = 0; i < count; i++)
2544 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2546 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2548 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2553 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2555 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2560 COLORREF oldText = 0;
2564 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2565 if (btnInfo == NULL)
2567 FIXME("btnInfo invalid!\n");
2571 /* set colors and select objects */
2572 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2573 if (btnInfo->bVirtual)
2574 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2576 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2577 hPen = CreatePen( PS_SOLID, 1,
2578 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2579 hOldPen = SelectObject (lpdis->hDC, hPen );
2580 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2582 /* fill background rectangle */
2583 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2584 lpdis->rcItem.right, lpdis->rcItem.bottom);
2586 /* calculate button and text rectangles */
2587 CopyRect (&rcButton, &lpdis->rcItem);
2588 InflateRect (&rcButton, -1, -1);
2589 CopyRect (&rcText, &rcButton);
2590 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2591 rcText.left = rcButton.right + 2;
2593 /* draw focus rectangle */
2594 if (lpdis->itemState & ODS_FOCUS)
2595 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2598 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2599 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2601 /* draw image and text */
2602 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2603 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2604 btnInfo->btn.iBitmap));
2605 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2606 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2608 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2609 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2611 /* delete objects and reset colors */
2612 SelectObject (lpdis->hDC, hOldBrush);
2613 SelectObject (lpdis->hDC, hOldPen);
2614 SetBkColor (lpdis->hDC, oldBk);
2615 SetTextColor (lpdis->hDC, oldText);
2616 DeleteObject( hPen );
2621 case WM_MEASUREITEM:
2622 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2624 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2626 lpmis->itemHeight = 15 + 8; /* default height */
2633 if (uDragListMessage && (uMsg == uDragListMessage))
2635 if (wParam == IDC_TOOLBARBTN_LBOX)
2637 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2638 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2642 else if (wParam == IDC_AVAILBTN_LBOX)
2644 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2645 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2646 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2655 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2658 INT nCountBefore = ImageList_GetImageCount(himlDef);
2664 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2665 /* Add bitmaps to the default image list */
2666 if (bitmap->hInst == NULL) /* a handle was passed */
2669 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2670 HDC hdcImage, hdcBitmap;
2672 /* copy the bitmap before adding it so that the user's bitmap
2673 * doesn't get modified.
2675 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2677 hdcImage = CreateCompatibleDC(0);
2678 hdcBitmap = CreateCompatibleDC(0);
2680 /* create new bitmap */
2681 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2682 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2683 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2685 /* Copy the user's image */
2686 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2687 hdcBitmap, 0, 0, SRCCOPY);
2689 SelectObject (hdcImage, hOldBitmapLoad);
2690 SelectObject (hdcBitmap, hOldBitmapBitmap);
2691 DeleteDC (hdcImage);
2692 DeleteDC (hdcBitmap);
2695 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2697 /* enlarge the bitmap if needed */
2698 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2699 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2701 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2702 DeleteObject(hbmLoad);
2706 nCountAfter = ImageList_GetImageCount(himlDef);
2707 nAdded = nCountAfter - nCountBefore;
2708 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2710 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2711 } else if (nAdded > (INT)bitmap->nButtons) {
2712 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2713 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2716 infoPtr->nNumBitmaps += nAdded;
2721 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2728 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2729 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2731 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2733 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2736 TRACE("Update icon size: %dx%d -> %dx%d\n",
2737 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2739 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2740 ILC_COLORDDB|ILC_MASK, 8, 2);
2741 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2742 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2743 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2744 infoPtr->himlInt = himlNew;
2746 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2747 ImageList_Destroy(himlDef);
2750 /***********************************************************************
2751 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2755 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2757 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2758 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2763 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2767 if (lpAddBmp->hInst == HINST_COMMCTRL)
2769 info.hInst = COMCTL32_hModule;
2770 switch (lpAddBmp->nID)
2772 case IDB_STD_SMALL_COLOR:
2774 info.nID = IDB_STD_SMALL;
2776 case IDB_STD_LARGE_COLOR:
2778 info.nID = IDB_STD_LARGE;
2780 case IDB_VIEW_SMALL_COLOR:
2782 info.nID = IDB_VIEW_SMALL;
2784 case IDB_VIEW_LARGE_COLOR:
2786 info.nID = IDB_VIEW_LARGE;
2788 case IDB_HIST_SMALL_COLOR:
2790 info.nID = IDB_HIST_SMALL;
2792 case IDB_HIST_LARGE_COLOR:
2794 info.nID = IDB_HIST_LARGE;
2800 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2802 /* Windows resize all the buttons to the size of a newly added standard image */
2803 if (lpAddBmp->nID & 1)
2806 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2807 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2809 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2810 MAKELPARAM((WORD)24, (WORD)24));
2811 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2812 MAKELPARAM((WORD)31, (WORD)30));
2817 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2818 MAKELPARAM((WORD)16, (WORD)16));
2819 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2820 MAKELPARAM((WORD)22, (WORD)22));
2823 TOOLBAR_CalcToolbar (hwnd);
2827 info.nButtons = (INT)wParam;
2828 info.hInst = lpAddBmp->hInst;
2829 info.nID = lpAddBmp->nID;
2830 TRACE("adding %d bitmaps!\n", info.nButtons);
2833 /* check if the bitmap is already loaded and compute iSumButtons */
2835 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2837 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2838 infoPtr->bitmaps[i].nID == info.nID)
2840 iSumButtons += infoPtr->bitmaps[i].nButtons;
2843 if (!infoPtr->cimlDef) {
2844 /* create new default image list */
2845 TRACE ("creating default image list!\n");
2847 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2848 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2849 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2850 infoPtr->himlInt = himlDef;
2853 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2857 WARN("No default image list available\n");
2861 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2864 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2865 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2866 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2867 infoPtr->nNumBitmapInfos++;
2868 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2870 InvalidateRect(hwnd, NULL, TRUE);
2876 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2878 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2879 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2880 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2881 BOOL fHasString = FALSE;
2883 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2885 nAddButtons = (UINT)wParam;
2886 nOldButtons = infoPtr->nNumButtons;
2887 nNewButtons = nOldButtons + nAddButtons;
2889 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2890 infoPtr->nNumButtons = nNewButtons;
2892 /* insert new button data */
2893 for (nCount = 0; nCount < nAddButtons; nCount++) {
2894 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2895 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2896 btnPtr->idCommand = lpTbb[nCount].idCommand;
2897 btnPtr->fsState = lpTbb[nCount].fsState;
2898 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2899 btnPtr->dwData = lpTbb[nCount].dwData;
2900 btnPtr->bHot = FALSE;
2901 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2904 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2906 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2910 btnPtr->iString = lpTbb[nCount].iString;
2912 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2915 if (infoPtr->nNumStrings > 0 || fHasString)
2916 TOOLBAR_CalcToolbar(hwnd);
2918 TOOLBAR_LayoutToolbar(hwnd);
2919 TOOLBAR_AutoSize (hwnd);
2921 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2923 InvalidateRect(hwnd, NULL, TRUE);
2930 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2932 #define MAX_RESOURCE_STRING_LENGTH 512
2933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2934 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2935 INT nIndex = infoPtr->nNumStrings;
2937 if ((wParam) && (HIWORD(lParam) == 0)) {
2938 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2943 TRACE("adding string from resource!\n");
2945 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2946 szString, MAX_RESOURCE_STRING_LENGTH);
2948 TRACE("len=%d %s\n", len, debugstr_w(szString));
2949 if (len == 0 || len == 1)
2952 TRACE("Delimiter: 0x%x\n", *szString);
2953 delimiter = *szString;
2956 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2958 if (next_delim + 1 >= szString + len)
2960 /* this may happen if delimiter == '\0' or if the last char is a
2961 * delimiter (then it is ignored like the native does) */
2965 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2966 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2967 infoPtr->nNumStrings++;
2973 LPWSTR p = (LPWSTR)lParam;
2978 TRACE("adding string(s) from array!\n");
2982 TRACE("len=%d %s\n", len, debugstr_w(p));
2983 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2984 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2985 infoPtr->nNumStrings++;
2992 TOOLBAR_CalcToolbar(hwnd);
2998 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3001 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3006 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
3007 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
3013 TRACE("adding string(s) from array!\n");
3014 nIndex = infoPtr->nNumStrings;
3017 TRACE("len=%d \"%s\"\n", len, p);
3019 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3020 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3021 infoPtr->nNumStrings++;
3027 TOOLBAR_CalcToolbar(hwnd);
3033 TOOLBAR_AutoSize (HWND hwnd)
3035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3041 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3043 parent = GetParent (hwnd);
3045 if (!parent || !infoPtr->bDoRedraw)
3048 GetClientRect(parent, &parent_rect);
3050 x = parent_rect.left;
3051 y = parent_rect.top;
3053 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3055 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3056 cx = parent_rect.right - parent_rect.left;
3058 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3060 TOOLBAR_LayoutToolbar(hwnd);
3061 InvalidateRect( hwnd, NULL, TRUE );
3064 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3067 UINT uPosFlags = SWP_NOZORDER;
3069 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3071 GetWindowRect(hwnd, &window_rect);
3072 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3073 y = window_rect.top;
3075 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3077 GetWindowRect(hwnd, &window_rect);
3078 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3081 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3082 uPosFlags |= SWP_NOMOVE;
3084 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3085 cy += GetSystemMetrics(SM_CYEDGE);
3087 if (infoPtr->dwStyle & WS_BORDER)
3089 x = y = 1; /* FIXME: this looks wrong */
3090 cy += GetSystemMetrics(SM_CYEDGE);
3091 cx += GetSystemMetrics(SM_CXEDGE);
3094 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3102 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3104 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3106 return infoPtr->nNumButtons;
3111 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3115 infoPtr->dwStructSize = (DWORD)wParam;
3122 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 TBUTTON_INFO *btnPtr;
3128 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3134 btnPtr = &infoPtr->buttons[nIndex];
3135 btnPtr->iBitmap = LOWORD(lParam);
3137 /* we HAVE to erase the background, the new bitmap could be */
3139 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3146 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3149 TBUTTON_INFO *btnPtr;
3152 BOOL bChecked = FALSE;
3154 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3156 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3161 btnPtr = &infoPtr->buttons[nIndex];
3163 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3165 if (LOWORD(lParam) == FALSE)
3166 btnPtr->fsState &= ~TBSTATE_CHECKED;
3168 if (btnPtr->fsStyle & BTNS_GROUP) {
3170 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3171 if (nOldIndex == nIndex)
3173 if (nOldIndex != -1)
3174 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3176 btnPtr->fsState |= TBSTATE_CHECKED;
3179 if( bChecked != LOWORD(lParam) )
3181 if (nOldIndex != -1)
3182 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3183 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3186 /* FIXME: Send a WM_NOTIFY?? */
3193 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3197 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3202 TOOLBAR_Customize (HWND hwnd)
3204 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3205 CUSTDLG_INFO custInfo;
3211 custInfo.tbInfo = infoPtr;
3212 custInfo.tbHwnd = hwnd;
3214 /* send TBN_BEGINADJUST notification */
3215 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3217 if (!(hRes = FindResourceW (COMCTL32_hModule,
3218 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3219 (LPWSTR)RT_DIALOG)))
3222 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3225 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3226 (LPCDLGTEMPLATEW)template,
3228 TOOLBAR_CustomizeDialogProc,
3231 /* send TBN_ENDADJUST notification */
3232 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3239 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3241 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3242 INT nIndex = (INT)wParam;
3244 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3246 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3249 memset(&nmtb, 0, sizeof(nmtb));
3250 nmtb.iItem = btnPtr->idCommand;
3251 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3252 nmtb.tbButton.idCommand = btnPtr->idCommand;
3253 nmtb.tbButton.fsState = btnPtr->fsState;
3254 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3255 nmtb.tbButton.dwData = btnPtr->dwData;
3256 nmtb.tbButton.iString = btnPtr->iString;
3257 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3259 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3261 if (infoPtr->nNumButtons == 1) {
3262 TRACE(" simple delete!\n");
3263 Free (infoPtr->buttons);
3264 infoPtr->buttons = NULL;
3265 infoPtr->nNumButtons = 0;
3268 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3269 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3271 infoPtr->nNumButtons--;
3272 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3274 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3275 nIndex * sizeof(TBUTTON_INFO));
3278 if (nIndex < infoPtr->nNumButtons) {
3279 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3280 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3286 TOOLBAR_LayoutToolbar(hwnd);
3288 InvalidateRect (hwnd, NULL, TRUE);
3295 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3298 TBUTTON_INFO *btnPtr;
3302 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3304 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3309 btnPtr = &infoPtr->buttons[nIndex];
3311 bState = btnPtr->fsState & TBSTATE_ENABLED;
3313 /* update the toolbar button state */
3314 if(LOWORD(lParam) == FALSE) {
3315 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3317 btnPtr->fsState |= TBSTATE_ENABLED;
3320 /* redraw the button only if the state of the button changed */
3321 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3322 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3328 static inline LRESULT
3329 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3333 return infoPtr->bAnchor;
3338 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3343 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3347 return infoPtr->buttons[nIndex].iBitmap;
3351 static inline LRESULT
3352 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3354 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3359 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3363 INT nIndex = (INT)wParam;
3364 TBUTTON_INFO *btnPtr;
3369 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3372 btnPtr = &infoPtr->buttons[nIndex];
3373 lpTbb->iBitmap = btnPtr->iBitmap;
3374 lpTbb->idCommand = btnPtr->idCommand;
3375 lpTbb->fsState = btnPtr->fsState;
3376 lpTbb->fsStyle = btnPtr->fsStyle;
3377 lpTbb->bReserved[0] = 0;
3378 lpTbb->bReserved[1] = 0;
3379 lpTbb->dwData = btnPtr->dwData;
3380 lpTbb->iString = btnPtr->iString;
3387 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3390 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3391 TBUTTON_INFO *btnPtr;
3394 if (lpTbInfo == NULL)
3396 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3399 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3400 lpTbInfo->dwMask & 0x80000000);
3404 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3406 if (lpTbInfo->dwMask & TBIF_COMMAND)
3407 lpTbInfo->idCommand = btnPtr->idCommand;
3408 if (lpTbInfo->dwMask & TBIF_IMAGE)
3409 lpTbInfo->iImage = btnPtr->iBitmap;
3410 if (lpTbInfo->dwMask & TBIF_LPARAM)
3411 lpTbInfo->lParam = btnPtr->dwData;
3412 if (lpTbInfo->dwMask & TBIF_SIZE)
3413 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3414 if (lpTbInfo->dwMask & TBIF_STATE)
3415 lpTbInfo->fsState = btnPtr->fsState;
3416 if (lpTbInfo->dwMask & TBIF_STYLE)
3417 lpTbInfo->fsStyle = btnPtr->fsStyle;
3418 if (lpTbInfo->dwMask & TBIF_TEXT) {
3419 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3420 can't use TOOLBAR_GetText here */
3422 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3423 lpText = (LPWSTR)btnPtr->iString;
3424 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3426 lpTbInfo->pszText[0] = '\0';
3433 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3435 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3436 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3437 TBUTTON_INFO *btnPtr;
3440 if (lpTbInfo == NULL)
3442 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3445 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3446 lpTbInfo->dwMask & 0x80000000);
3450 btnPtr = &infoPtr->buttons[nIndex];
3455 if (lpTbInfo->dwMask & TBIF_COMMAND)
3456 lpTbInfo->idCommand = btnPtr->idCommand;
3457 if (lpTbInfo->dwMask & TBIF_IMAGE)
3458 lpTbInfo->iImage = btnPtr->iBitmap;
3459 if (lpTbInfo->dwMask & TBIF_LPARAM)
3460 lpTbInfo->lParam = btnPtr->dwData;
3461 if (lpTbInfo->dwMask & TBIF_SIZE)
3462 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3463 if (lpTbInfo->dwMask & TBIF_STATE)
3464 lpTbInfo->fsState = btnPtr->fsState;
3465 if (lpTbInfo->dwMask & TBIF_STYLE)
3466 lpTbInfo->fsStyle = btnPtr->fsStyle;
3467 if (lpTbInfo->dwMask & TBIF_TEXT) {
3468 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3469 can't use TOOLBAR_GetText here */
3471 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3472 lpText = (LPWSTR)btnPtr->iString;
3473 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3475 lpTbInfo->pszText[0] = '\0';
3483 TOOLBAR_GetButtonSize (HWND hwnd)
3485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3487 return MAKELONG((WORD)infoPtr->nButtonWidth,
3488 (WORD)infoPtr->nButtonHeight);
3493 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3502 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3506 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3508 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3509 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3514 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3521 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3525 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3529 ret = strlenW (lpText);
3532 strcpyW ((LPWSTR)lParam, lpText);
3540 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3542 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3543 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3544 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3548 inline static LRESULT
3549 TOOLBAR_GetExtendedStyle (HWND hwnd)
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3555 return infoPtr->dwExStyle;
3560 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3563 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3564 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3569 TOOLBAR_GetHotItem (HWND hwnd)
3571 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3573 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3576 if (infoPtr->nHotItem < 0)
3579 return (LRESULT)infoPtr->nHotItem;
3584 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3586 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3587 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3588 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3593 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3596 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3598 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3600 *lptbim = infoPtr->tbim;
3607 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3611 TRACE("hwnd = %p\n", hwnd);
3613 return (LRESULT)infoPtr->clrInsertMark;
3618 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3621 TBUTTON_INFO *btnPtr;
3625 nIndex = (INT)wParam;
3626 btnPtr = &infoPtr->buttons[nIndex];
3627 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3629 lpRect = (LPRECT)lParam;
3632 if (btnPtr->fsState & TBSTATE_HIDDEN)
3635 lpRect->left = btnPtr->rect.left;
3636 lpRect->right = btnPtr->rect.right;
3637 lpRect->bottom = btnPtr->rect.bottom;
3638 lpRect->top = btnPtr->rect.top;
3645 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3648 LPSIZE lpSize = (LPSIZE)lParam;
3653 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3654 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3656 TRACE("maximum size %d x %d\n",
3657 infoPtr->rcBound.right - infoPtr->rcBound.left,
3658 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3664 /* << TOOLBAR_GetObject >> */
3668 TOOLBAR_GetPadding (HWND hwnd)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3673 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3674 return (LRESULT) oldPad;
3679 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3682 TBUTTON_INFO *btnPtr;
3686 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3687 btnPtr = &infoPtr->buttons[nIndex];
3688 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3690 lpRect = (LPRECT)lParam;
3694 lpRect->left = btnPtr->rect.left;
3695 lpRect->right = btnPtr->rect.right;
3696 lpRect->bottom = btnPtr->rect.bottom;
3697 lpRect->top = btnPtr->rect.top;
3704 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3708 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3709 return infoPtr->nRows;
3716 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3721 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3725 return infoPtr->buttons[nIndex].fsState;
3730 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3732 return GetWindowLongW(hwnd, GWL_STYLE);
3737 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3741 return infoPtr->nMaxTextRows;
3746 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3748 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3750 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3751 TOOLBAR_TooltipCreateControl(infoPtr);
3752 return (LRESULT)infoPtr->hwndToolTip;
3757 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3759 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3761 TRACE("%s hwnd=%p\n",
3762 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3764 return infoPtr->bUnicode;
3768 inline static LRESULT
3769 TOOLBAR_GetVersion (HWND hwnd)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3772 return infoPtr->iVersion;
3777 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3780 TBUTTON_INFO *btnPtr;
3785 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3789 btnPtr = &infoPtr->buttons[nIndex];
3790 if (LOWORD(lParam) == FALSE)
3791 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3793 btnPtr->fsState |= TBSTATE_HIDDEN;
3795 TOOLBAR_CalcToolbar (hwnd);
3797 InvalidateRect (hwnd, NULL, TRUE);
3803 inline static LRESULT
3804 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3806 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3811 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3814 TBUTTON_INFO *btnPtr;
3818 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3822 btnPtr = &infoPtr->buttons[nIndex];
3823 oldState = btnPtr->fsState;
3824 if (LOWORD(lParam) == FALSE)
3825 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3827 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3829 if(oldState != btnPtr->fsState)
3830 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3837 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3841 INT nIndex = (INT)wParam;
3846 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3849 /* EPP: this seems to be an undocumented call (from my IE4)
3850 * I assume in that case that:
3851 * - index of insertion is at the end of existing buttons
3852 * I only see this happen with nIndex == -1, but it could have a special
3853 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3855 nIndex = infoPtr->nNumButtons;
3857 } else if (nIndex < 0)
3860 TRACE("inserting button index=%d\n", nIndex);
3861 if (nIndex > infoPtr->nNumButtons) {
3862 nIndex = infoPtr->nNumButtons;
3863 TRACE("adjust index=%d\n", nIndex);
3866 infoPtr->nNumButtons++;
3867 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3868 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3869 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3871 /* insert new button */
3872 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3873 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3874 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3875 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3876 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3877 /* if passed string and not index, then add string */
3878 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3880 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3882 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3885 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3887 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3889 if (infoPtr->nNumStrings > 0)
3890 TOOLBAR_CalcToolbar(hwnd);
3892 TOOLBAR_LayoutToolbar(hwnd);
3893 TOOLBAR_AutoSize (hwnd);
3895 InvalidateRect (hwnd, NULL, TRUE);
3900 /* << TOOLBAR_InsertMarkHitTest >> */
3904 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3906 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3909 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3913 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3918 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3920 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3923 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3927 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3932 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3937 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3941 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3946 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3951 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3955 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3960 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3965 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3969 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3974 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3979 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3983 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3988 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3991 tbab.hInst = (HINSTANCE)lParam;
3992 tbab.nID = (UINT_PTR)wParam;
3994 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3996 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4001 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4004 WCHAR wAccel = (WCHAR)wParam;
4005 UINT* pIDButton = (UINT*)lParam;
4006 WCHAR wszAccel[] = {'&',wAccel,0};
4009 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4010 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4012 for (i = 0; i < infoPtr->nNumButtons; i++)
4014 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4015 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4016 !(btnPtr->fsState & TBSTATE_HIDDEN))
4018 int iLen = strlenW(wszAccel);
4019 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4026 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4031 if (!strncmpiW(lpszStr, wszAccel, iLen))
4033 *pIDButton = btnPtr->idCommand;
4045 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4050 TBUTTON_INFO *btnPtr;
4052 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4058 btnPtr = &infoPtr->buttons[nIndex];
4059 oldState = btnPtr->fsState;
4062 btnPtr->fsState |= TBSTATE_MARKED;
4064 btnPtr->fsState &= ~TBSTATE_MARKED;
4066 if(oldState != btnPtr->fsState)
4067 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4073 /* fixes up an index of a button affected by a move */
4074 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4078 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4080 else if (*pIndex == nIndex)
4081 *pIndex = nMoveIndex;
4085 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4087 else if (*pIndex == nIndex)
4088 *pIndex = nMoveIndex;
4094 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4099 INT nMoveIndex = (INT)lParam;
4100 TBUTTON_INFO button;
4102 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4105 if ((nIndex == -1) || (nMoveIndex < 0))
4108 if (nMoveIndex > infoPtr->nNumButtons - 1)
4109 nMoveIndex = infoPtr->nNumButtons - 1;
4111 button = infoPtr->buttons[nIndex];
4113 /* move button right */
4114 if (nIndex < nMoveIndex)
4116 nCount = nMoveIndex - nIndex;
4117 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4118 infoPtr->buttons[nMoveIndex] = button;
4120 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4121 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4122 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4123 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4125 else if (nIndex > nMoveIndex) /* move button left */
4127 nCount = nIndex - nMoveIndex;
4128 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4129 infoPtr->buttons[nMoveIndex] = button;
4131 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4132 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4133 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4134 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4137 TOOLBAR_CalcToolbar(hwnd);
4138 TOOLBAR_AutoSize(hwnd);
4139 InvalidateRect(hwnd, NULL, TRUE);
4146 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4149 TBUTTON_INFO *btnPtr;
4153 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4157 btnPtr = &infoPtr->buttons[nIndex];
4158 oldState = btnPtr->fsState;
4159 if (LOWORD(lParam) == FALSE)
4160 btnPtr->fsState &= ~TBSTATE_PRESSED;
4162 btnPtr->fsState |= TBSTATE_PRESSED;
4164 if(oldState != btnPtr->fsState)
4165 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4170 /* FIXME: there might still be some confusion her between number of buttons
4171 * and number of bitmaps */
4173 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4176 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4178 HBITMAP hbmLoad = NULL;
4179 int i = 0, nOldButtons = 0, pos = 0;
4180 int nOldBitmaps, nNewBitmaps = 0;
4181 HIMAGELIST himlDef = 0;
4183 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4184 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4185 lpReplace->nButtons);
4187 if (lpReplace->hInstOld == HINST_COMMCTRL)
4189 FIXME("changing standard bitmaps not implemented\n");
4192 else if (lpReplace->hInstOld != 0)
4193 FIXME("resources not in the current module not implemented\n");
4195 if (lpReplace->hInstNew)
4197 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4202 hBitmap = (HBITMAP) lpReplace->nIDNew;
4205 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4206 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4207 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4208 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4209 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4211 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4212 nOldButtons = tbi->nButtons;
4213 tbi->nButtons = lpReplace->nButtons;
4214 tbi->hInst = lpReplace->hInstNew;
4215 tbi->nID = lpReplace->nIDNew;
4216 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4219 pos += tbi->nButtons;
4222 if (nOldButtons == 0)
4224 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4226 DeleteObject (hbmLoad);
4230 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4231 nOldBitmaps = ImageList_GetImageCount(himlDef);
4233 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4235 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4236 ImageList_Remove(himlDef, i);
4241 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4242 HDC hdcImage, hdcBitmap;
4244 /* copy the bitmap before adding it so that the user's bitmap
4245 * doesn't get modified.
4247 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4249 hdcImage = CreateCompatibleDC(0);
4250 hdcBitmap = CreateCompatibleDC(0);
4252 /* create new bitmap */
4253 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4254 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4255 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4257 /* Copy the user's image */
4258 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4259 hdcBitmap, 0, 0, SRCCOPY);
4261 SelectObject (hdcImage, hOldBitmapLoad);
4262 SelectObject (hdcBitmap, hOldBitmapBitmap);
4263 DeleteDC (hdcImage);
4264 DeleteDC (hdcBitmap);
4266 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4267 nNewBitmaps = ImageList_GetImageCount(himlDef);
4268 DeleteObject (hbmLoad);
4271 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4273 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4274 pos, nOldBitmaps, nNewBitmaps);
4276 InvalidateRect(hwnd, NULL, TRUE);
4279 DeleteObject (hbmLoad);
4284 /* helper for TOOLBAR_SaveRestoreW */
4286 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4288 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4289 debugstr_w(lpSave->pszValueName));
4295 /* helper for TOOLBAR_Restore */
4297 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4301 for (i = 0; i < infoPtr->nNumButtons; i++)
4303 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4306 Free(infoPtr->buttons);
4307 infoPtr->buttons = NULL;
4308 infoPtr->nNumButtons = 0;
4312 /* helper for TOOLBAR_SaveRestoreW */
4314 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4323 /* restore toolbar information */
4324 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4325 debugstr_w(lpSave->pszValueName));
4327 memset(&nmtbr, 0, sizeof(nmtbr));
4329 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4330 KEY_QUERY_VALUE, &hkey);
4332 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4334 if (!res && dwType != REG_BINARY)
4335 res = ERROR_FILE_NOT_FOUND;
4338 nmtbr.pData = Alloc(dwSize);
4339 nmtbr.cbData = (UINT)dwSize;
4340 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4343 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4344 (LPBYTE)nmtbr.pData, &dwSize);
4347 nmtbr.pCurrent = nmtbr.pData;
4349 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4350 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4352 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4356 /* remove all existing buttons as this function is designed to
4357 * restore the toolbar to a previously saved state */
4358 TOOLBAR_DeleteAllButtons(infoPtr);
4360 for (i = 0; i < nmtbr.cButtons; i++)
4363 nmtbr.tbButton.iBitmap = -1;
4364 nmtbr.tbButton.fsState = 0;
4365 nmtbr.tbButton.fsStyle = 0;
4366 nmtbr.tbButton.idCommand = 0;
4367 if (*nmtbr.pCurrent == (DWORD)-1)
4370 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4371 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4373 else if (*nmtbr.pCurrent == (DWORD)-2)
4375 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4377 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4381 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4383 /* can't contain real string as we don't know whether
4384 * the client put an ANSI or Unicode string in there */
4385 if (HIWORD(nmtbr.tbButton.iString))
4386 nmtbr.tbButton.iString = 0;
4388 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4389 (LPARAM)&nmtbr.tbButton, TRUE);
4392 /* do legacy notifications */
4393 if (infoPtr->iVersion < 5)
4395 /* FIXME: send TBN_BEGINADJUST */
4396 FIXME("send TBN_GETBUTTONINFO for each button\n");
4397 /* FIXME: send TBN_ENDADJUST */
4400 /* remove all uninitialised buttons
4401 * note: loop backwards to avoid having to fixup i on a
4403 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4404 if (infoPtr->buttons[i].iBitmap == -1)
4405 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4407 /* only indicate success if at least one button survived */
4408 if (infoPtr->nNumButtons > 0) ret = TRUE;
4419 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4423 if (lpSave == NULL) return 0;
4426 return TOOLBAR_Save(infoPtr, lpSave);
4428 return TOOLBAR_Restore(infoPtr, lpSave);
4433 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4435 LPWSTR pszValueName = 0, pszSubKey = 0;
4436 TBSAVEPARAMSW SaveW;
4440 if (lpSave == NULL) return 0;
4442 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4443 pszSubKey = Alloc(len * sizeof(WCHAR));
4444 if (pszSubKey) goto exit;
4445 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4447 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4448 pszValueName = Alloc(len * sizeof(WCHAR));
4449 if (!pszValueName) goto exit;
4450 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4452 SaveW.pszValueName = pszValueName;
4453 SaveW.pszSubKey = pszSubKey;
4454 SaveW.hkr = lpSave->hkr;
4455 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4458 Free (pszValueName);
4466 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4469 BOOL bOldAnchor = infoPtr->bAnchor;
4471 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4473 infoPtr->bAnchor = (BOOL)wParam;
4475 /* Native does not remove the hot effect from an already hot button */
4477 return (LRESULT)bOldAnchor;
4482 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4485 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4487 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4490 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4492 if (LOWORD(lParam) == 0)
4493 lParam = MAKELPARAM(1, HIWORD(lParam));
4495 if (HIWORD(lParam)==0)
4496 lParam = MAKELPARAM(LOWORD(lParam), 1);
4498 if (infoPtr->nNumButtons > 0)
4499 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4500 infoPtr->nNumButtons,
4501 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4502 LOWORD(lParam), HIWORD(lParam));
4504 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4505 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4507 if ((himlDef == infoPtr->himlInt) &&
4508 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4510 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4511 infoPtr->nBitmapHeight);
4514 TOOLBAR_CalcToolbar(hwnd);
4515 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4521 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4524 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4525 TBUTTON_INFO *btnPtr;
4531 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4534 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4535 lptbbi->dwMask & 0x80000000);
4539 btnPtr = &infoPtr->buttons[nIndex];
4540 if (lptbbi->dwMask & TBIF_COMMAND)
4541 btnPtr->idCommand = lptbbi->idCommand;
4542 if (lptbbi->dwMask & TBIF_IMAGE)
4543 btnPtr->iBitmap = lptbbi->iImage;
4544 if (lptbbi->dwMask & TBIF_LPARAM)
4545 btnPtr->dwData = lptbbi->lParam;
4546 if (lptbbi->dwMask & TBIF_SIZE)
4547 btnPtr->cx = lptbbi->cx;
4548 if (lptbbi->dwMask & TBIF_STATE)
4549 btnPtr->fsState = lptbbi->fsState;
4550 if (lptbbi->dwMask & TBIF_STYLE)
4551 btnPtr->fsStyle = lptbbi->fsStyle;
4553 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4554 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4555 /* iString is index, zero it to make Str_SetPtr succeed */
4558 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4561 /* save the button rect to see if we need to redraw the whole toolbar */
4562 oldBtnRect = btnPtr->rect;
4563 TOOLBAR_CalcToolbar(hwnd);
4565 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4566 InvalidateRect(hwnd, NULL, TRUE);
4568 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4575 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4578 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4579 TBUTTON_INFO *btnPtr;
4585 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4588 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4589 lptbbi->dwMask & 0x80000000);
4593 btnPtr = &infoPtr->buttons[nIndex];
4594 if (lptbbi->dwMask & TBIF_COMMAND)
4595 btnPtr->idCommand = lptbbi->idCommand;
4596 if (lptbbi->dwMask & TBIF_IMAGE)
4597 btnPtr->iBitmap = lptbbi->iImage;
4598 if (lptbbi->dwMask & TBIF_LPARAM)
4599 btnPtr->dwData = lptbbi->lParam;
4600 if (lptbbi->dwMask & TBIF_SIZE)
4601 btnPtr->cx = lptbbi->cx;
4602 if (lptbbi->dwMask & TBIF_STATE)
4603 btnPtr->fsState = lptbbi->fsState;
4604 if (lptbbi->dwMask & TBIF_STYLE)
4605 btnPtr->fsStyle = lptbbi->fsStyle;
4607 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4608 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4609 /* iString is index, zero it to make Str_SetPtr succeed */
4611 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4614 /* save the button rect to see if we need to redraw the whole toolbar */
4615 oldBtnRect = btnPtr->rect;
4616 TOOLBAR_CalcToolbar(hwnd);
4618 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4619 InvalidateRect(hwnd, NULL, TRUE);
4621 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4628 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4631 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4633 if ((cx < 0) || (cy < 0))
4635 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4639 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4641 /* The documentation claims you can only change the button size before
4642 * any button has been added. But this is wrong.
4643 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4644 * it to the toolbar, and it checks that the return value is nonzero - mjm
4645 * Further testing shows that we must actually perform the change too.
4648 * The documentation also does not mention that if 0 is supplied for
4649 * either size, the system changes it to the default of 24 wide and
4650 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4652 if (cx == 0) cx = 24;
4653 if (cy == 0) cx = 22;
4655 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4656 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nVBitmapHeight);
4658 infoPtr->nButtonWidth = cx;
4659 infoPtr->nButtonHeight = cy;
4661 infoPtr->iTopMargin = default_top_margin(infoPtr);
4662 TOOLBAR_LayoutToolbar(hwnd);
4668 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4672 /* if setting to current values, ignore */
4673 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4674 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4675 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4676 infoPtr->cxMin, infoPtr->cxMax);
4680 /* save new values */
4681 infoPtr->cxMin = (short)LOWORD(lParam);
4682 infoPtr->cxMax = (short)HIWORD(lParam);
4684 /* otherwise we need to recalc the toolbar and in some cases
4685 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4686 which doesn't actually draw - GA). */
4687 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4688 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4690 TOOLBAR_CalcToolbar (hwnd);
4692 InvalidateRect (hwnd, NULL, TRUE);
4699 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4702 INT nIndex = (INT)wParam;
4704 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4707 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4709 if (infoPtr->hwndToolTip) {
4711 FIXME("change tool tip!\n");
4720 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4723 HIMAGELIST himl = (HIMAGELIST)lParam;
4724 HIMAGELIST himlTemp;
4727 if (infoPtr->iVersion >= 5)
4730 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4731 &infoPtr->cimlDis, himl, id);
4733 /* FIXME: redraw ? */
4735 return (LRESULT)himlTemp;
4740 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4745 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4747 dwTemp = infoPtr->dwDTFlags;
4748 infoPtr->dwDTFlags =
4749 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4751 return (LRESULT)dwTemp;
4754 /* This function differs a bit from what MSDN says it does:
4755 * 1. lParam contains extended style flags to OR with current style
4756 * (MSDN isn't clear on the OR bit)
4757 * 2. wParam appears to contain extended style flags to be reset
4758 * (MSDN says that this parameter is reserved)
4761 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4766 dwTemp = infoPtr->dwExStyle;
4767 infoPtr->dwExStyle &= ~wParam;
4768 infoPtr->dwExStyle |= (DWORD)lParam;
4770 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4772 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4773 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4774 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4776 TOOLBAR_CalcToolbar (hwnd);
4778 TOOLBAR_AutoSize(hwnd);
4780 InvalidateRect(hwnd, NULL, TRUE);
4782 return (LRESULT)dwTemp;
4787 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4790 HIMAGELIST himlTemp;
4791 HIMAGELIST himl = (HIMAGELIST)lParam;
4794 if (infoPtr->iVersion >= 5)
4797 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4799 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4800 &infoPtr->cimlHot, himl, id);
4802 /* FIXME: redraw ? */
4804 return (LRESULT)himlTemp;
4808 /* Makes previous hot button no longer hot, makes the specified
4809 * button hot and sends appropriate notifications. dwReason is one or
4810 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4811 * NOTE 1: this function does not validate nHit
4812 * NOTE 2: the name of this function is completely made up and
4813 * not based on any documentation from Microsoft. */
4815 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4817 if (infoPtr->nHotItem != nHit)
4819 NMTBHOTITEM nmhotitem;
4820 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4822 nmhotitem.dwFlags = dwReason;
4823 if(infoPtr->nHotItem >= 0)
4825 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4826 nmhotitem.idOld = oldBtnPtr->idCommand;
4830 nmhotitem.dwFlags |= HICF_ENTERING;
4831 nmhotitem.idOld = 0;
4836 btnPtr = &infoPtr->buttons[nHit];
4837 nmhotitem.idNew = btnPtr->idCommand;
4841 nmhotitem.dwFlags |= HICF_LEAVING;
4842 nmhotitem.idNew = 0;
4845 /* now change the hot and invalidate the old and new buttons - if the
4847 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4850 oldBtnPtr->bHot = FALSE;
4851 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4853 /* setting disabled buttons as hot fails even if the notify contains the button id */
4854 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4855 btnPtr->bHot = TRUE;
4856 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4857 infoPtr->nHotItem = nHit;
4860 infoPtr->nHotItem = -1;
4866 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4869 INT nOldHotItem = infoPtr->nHotItem;
4871 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4873 if ((INT)wParam > infoPtr->nNumButtons)
4874 return infoPtr->nHotItem;
4876 if ((INT)wParam < 0)
4879 /* NOTE: an application can still remove the hot item even if anchor
4880 * highlighting is enabled */
4882 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4884 if (nOldHotItem < 0)
4887 return (LRESULT)nOldHotItem;
4892 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4895 HIMAGELIST himlTemp;
4896 HIMAGELIST himl = (HIMAGELIST)lParam;
4899 if (infoPtr->iVersion >= 5)
4902 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4903 &infoPtr->cimlDef, himl, id);
4905 infoPtr->nNumBitmaps = 0;
4906 for (i = 0; i < infoPtr->cimlDef; i++)
4907 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4909 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4910 &infoPtr->nBitmapHeight))
4912 infoPtr->nBitmapWidth = 1;
4913 infoPtr->nBitmapHeight = 1;
4915 infoPtr->nVBitmapHeight = infoPtr->nBitmapHeight;
4916 TOOLBAR_CalcToolbar(hwnd);
4918 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4919 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4920 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4922 InvalidateRect(hwnd, NULL, TRUE);
4924 return (LRESULT)himlTemp;
4929 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4933 infoPtr->nIndent = (INT)wParam;
4937 /* process only on indent changing */
4938 if(infoPtr->nIndent != (INT)wParam)
4940 infoPtr->nIndent = (INT)wParam;
4941 TOOLBAR_CalcToolbar (hwnd);
4942 InvalidateRect(hwnd, NULL, FALSE);
4950 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4952 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4953 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4955 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4957 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4959 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4963 if ((lptbim->iButton == -1) ||
4964 ((lptbim->iButton < infoPtr->nNumButtons) &&
4965 (lptbim->iButton >= 0)))
4967 infoPtr->tbim = *lptbim;
4968 /* FIXME: don't need to update entire toolbar */
4969 InvalidateRect(hwnd, NULL, TRUE);
4972 ERR("Invalid button index %d\n", lptbim->iButton);
4979 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4983 infoPtr->clrInsertMark = (COLORREF)lParam;
4985 /* FIXME: don't need to update entire toolbar */
4986 InvalidateRect(hwnd, NULL, TRUE);
4993 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4997 infoPtr->nMaxTextRows = (INT)wParam;
4999 TOOLBAR_CalcToolbar(hwnd);
5004 /* MSDN gives slightly wrong info on padding.
5005 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5006 * 2. It is not used to create a blank area between the edge of the button
5007 * and the text or image if TBSTYLE_LIST is set. It is used to control
5008 * the gap between the image and text.
5009 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5010 * to control the bottom and right borders [with the border being
5011 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5012 * is shared evenly on both sides of the button.
5013 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5016 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5021 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5022 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5023 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5024 TRACE("cx=%d, cy=%d\n",
5025 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5026 return (LRESULT) oldPad;
5031 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5038 hwndOldNotify = infoPtr->hwndNotify;
5039 infoPtr->hwndNotify = (HWND)wParam;
5041 return (LRESULT)hwndOldNotify;
5046 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5049 LPRECT lprc = (LPRECT)lParam;
5053 if (LOWORD(wParam) > 1) {
5054 FIXME("multiple rows not supported!\n");
5057 if(infoPtr->nRows != LOWORD(wParam))
5059 infoPtr->nRows = LOWORD(wParam);
5061 /* recalculate toolbar */
5062 TOOLBAR_CalcToolbar (hwnd);
5064 /* repaint toolbar */
5065 InvalidateRect(hwnd, NULL, TRUE);
5068 /* return bounding rectangle */
5070 lprc->left = infoPtr->rcBound.left;
5071 lprc->right = infoPtr->rcBound.right;
5072 lprc->top = infoPtr->rcBound.top;
5073 lprc->bottom = infoPtr->rcBound.bottom;
5081 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5084 TBUTTON_INFO *btnPtr;
5087 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5091 btnPtr = &infoPtr->buttons[nIndex];
5093 /* if hidden state has changed the invalidate entire window and recalc */
5094 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5095 btnPtr->fsState = LOWORD(lParam);
5096 TOOLBAR_CalcToolbar (hwnd);
5097 InvalidateRect(hwnd, 0, TRUE);
5101 /* process state changing if current state doesn't match new state */
5102 if(btnPtr->fsState != LOWORD(lParam))
5104 btnPtr->fsState = LOWORD(lParam);
5105 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5113 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5115 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5121 inline static LRESULT
5122 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5126 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5128 infoPtr->hwndToolTip = (HWND)wParam;
5134 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5139 TRACE("%s hwnd=%p\n",
5140 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5142 bTemp = infoPtr->bUnicode;
5143 infoPtr->bUnicode = (BOOL)wParam;
5150 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5154 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5155 comctl32_color.clrBtnHighlight :
5156 infoPtr->clrBtnHighlight;
5157 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5158 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5164 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5168 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5169 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5170 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5172 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5173 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5174 InvalidateRect(hwnd, NULL, TRUE);
5180 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5183 INT iOldVersion = infoPtr->iVersion;
5185 infoPtr->iVersion = iVersion;
5187 if (infoPtr->iVersion >= 5)
5188 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5195 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5198 WORD iString = HIWORD(wParam);
5199 WORD buffersize = LOWORD(wParam);
5200 LPSTR str = (LPSTR)lParam;
5203 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5205 if (iString < infoPtr->nNumStrings)
5207 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5209 TRACE("returning %s\n", debugstr_a(str));
5212 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5219 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5222 WORD iString = HIWORD(wParam);
5223 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5224 LPWSTR str = (LPWSTR)lParam;
5227 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5229 if (iString < infoPtr->nNumStrings)
5231 len = min(len, strlenW(infoPtr->strings[iString]));
5232 ret = (len+1)*sizeof(WCHAR);
5233 memcpy(str, infoPtr->strings[iString], ret);
5236 TRACE("returning %s\n", debugstr_w(str));
5239 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5244 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5245 * is the maximum size of the toolbar? */
5246 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5248 SIZE * pSize = (SIZE*)lParam;
5249 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5254 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5255 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5256 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5259 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5261 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5262 INT nOldHotItem = infoPtr->nHotItem;
5264 TRACE("old item=%d, new item=%d, flags=%08x\n",
5265 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5267 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5270 /* NOTE: an application can still remove the hot item even if anchor
5271 * highlighting is enabled */
5273 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5277 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5280 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5281 * which controls the amount of spacing between the image and the text
5282 * of buttons for TBSTYLE_LIST toolbars. */
5283 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5287 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5290 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5292 infoPtr->iListGap = (INT)wParam;
5294 InvalidateRect(hwnd, NULL, TRUE);
5299 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5300 * of image lists associated with the various states. */
5301 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5303 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5305 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5307 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5311 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5314 LPSIZE lpsize = (LPSIZE)lParam;
5320 * Testing shows the following:
5321 * wParam = 0 adjust cx value
5322 * = 1 set cy value to max size.
5323 * lParam pointer to SIZE structure
5326 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5327 wParam, lParam, lpsize->cx, lpsize->cy);
5331 if (lpsize->cx == -1) {
5332 /* **** this is wrong, native measures each button and sets it */
5333 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5335 else if(HIWORD(lpsize->cx)) {
5337 HWND hwndParent = GetParent(hwnd);
5339 GetWindowRect(hwnd, &rc);
5340 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5341 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5342 rc.left, rc.top, rc.right, rc.bottom);
5343 lpsize->cx = max(rc.right-rc.left,
5344 infoPtr->rcBound.right - infoPtr->rcBound.left);
5347 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5351 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5354 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5358 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5359 lpsize->cx, lpsize->cy);
5363 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5365 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5367 InvalidateRect(hwnd, NULL, TRUE);
5373 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5376 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5379 TRACE("hwnd = %p\n", hwnd);
5381 /* initialize info structure */
5382 infoPtr->nButtonWidth = 23;
5383 infoPtr->nButtonHeight = 22;
5384 infoPtr->nBitmapHeight = 15;
5385 infoPtr->nBitmapWidth = 16;
5386 /* By default Windows creates an image list with 16x15 icons but computes the button size as
5387 * if the icons were 16x16. That's why we keep infoPtr->nVBitmapHeight. After a call to
5388 * TB_SETBITMAPSIZE or TB_SETIMAGELIST the nVBitmapHeight = nBitmapHeight.
5390 infoPtr->nVBitmapHeight = 16;
5392 infoPtr->nMaxTextRows = 1;
5393 infoPtr->cxMin = -1;
5394 infoPtr->cxMax = -1;
5395 infoPtr->nNumBitmaps = 0;
5396 infoPtr->nNumStrings = 0;
5398 infoPtr->bCaptured = FALSE;
5399 infoPtr->nButtonDown = -1;
5400 infoPtr->nButtonDrag = -1;
5401 infoPtr->nOldHit = -1;
5402 infoPtr->nHotItem = -1;
5403 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5404 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5405 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5406 infoPtr->bDragOutSent = FALSE;
5407 infoPtr->iVersion = 0;
5408 infoPtr->hwndSelf = hwnd;
5409 infoPtr->bDoRedraw = TRUE;
5410 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5411 infoPtr->clrBtnShadow = CLR_DEFAULT;
5412 infoPtr->szPadding.cx = DEFPAD_CX;
5413 infoPtr->szPadding.cy = DEFPAD_CY;
5414 infoPtr->iListGap = DEFLISTGAP;
5415 infoPtr->iTopMargin = default_top_margin(infoPtr);
5416 infoPtr->dwStyle = dwStyle;
5417 infoPtr->tbim.iButton = -1;
5418 GetClientRect(hwnd, &infoPtr->client_rect);
5419 infoPtr->bUnicode = infoPtr->hwndNotify &&
5420 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5421 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5423 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5424 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5426 OpenThemeData (hwnd, themeClass);
5428 TOOLBAR_CheckStyle (hwnd, dwStyle);
5435 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5439 /* delete tooltip control */
5440 if (infoPtr->hwndToolTip)
5441 DestroyWindow (infoPtr->hwndToolTip);
5443 /* delete temporary buffer for tooltip text */
5444 Free (infoPtr->pszTooltipText);
5445 Free (infoPtr->bitmaps); /* bitmaps list */
5447 /* delete button data */
5448 if (infoPtr->buttons)
5449 Free (infoPtr->buttons);
5451 /* delete strings */
5452 if (infoPtr->strings) {
5454 for (i = 0; i < infoPtr->nNumStrings; i++)
5455 if (infoPtr->strings[i])
5456 Free (infoPtr->strings[i]);
5458 Free (infoPtr->strings);
5461 /* destroy internal image list */
5462 if (infoPtr->himlInt)
5463 ImageList_Destroy (infoPtr->himlInt);
5465 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5466 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5467 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5469 /* delete default font */
5470 DeleteObject (infoPtr->hDefaultFont);
5472 CloseThemeData (GetWindowTheme (hwnd));
5474 /* free toolbar info data */
5476 SetWindowLongPtrW (hwnd, 0, 0);
5483 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5486 NMTBCUSTOMDRAW tbcd;
5489 HTHEME theme = GetWindowTheme (hwnd);
5490 DWORD dwEraseCustDraw = 0;
5492 /* the app has told us not to redraw the toolbar */
5493 if (!infoPtr->bDoRedraw)
5496 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5497 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5498 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5499 tbcd.nmcd.hdc = (HDC)wParam;
5500 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5501 dwEraseCustDraw = ntfret & 0xffff;
5503 /* FIXME: in general the return flags *can* be or'ed together */
5504 switch (dwEraseCustDraw)
5506 case CDRF_DODEFAULT:
5508 case CDRF_SKIPDEFAULT:
5511 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5516 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5517 * to my parent for processing.
5519 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5521 HDC hdc = (HDC)wParam;
5526 parent = GetParent(hwnd);
5527 MapWindowPoints(hwnd, parent, &pt, 1);
5528 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5529 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5530 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5533 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5535 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5536 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5537 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5538 tbcd.nmcd.hdc = (HDC)wParam;
5539 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5540 dwEraseCustDraw = ntfret & 0xffff;
5541 switch (dwEraseCustDraw)
5543 case CDRF_DODEFAULT:
5545 case CDRF_SKIPDEFAULT:
5548 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5557 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5559 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5561 return (LRESULT)infoPtr->hFont;
5566 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5569 INT nNewHotItem = infoPtr->nHotItem;
5571 for (i = 0; i < infoPtr->nNumButtons; i++)
5574 if ((nNewHotItem + iDirection < 0) ||
5575 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5577 NMTBWRAPHOTITEM nmtbwhi;
5578 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5579 nmtbwhi.iDirection = iDirection;
5580 nmtbwhi.dwReason = dwReason;
5582 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5586 nNewHotItem += iDirection;
5587 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5589 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5590 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5592 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5599 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5604 nmkey.nVKey = (UINT)wParam;
5605 nmkey.uFlags = HIWORD(lParam);
5607 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5608 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5610 switch ((UINT)wParam)
5614 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5618 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5622 if ((infoPtr->nHotItem >= 0) &&
5623 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5625 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5626 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5637 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5642 pt.x = (short)LOWORD(lParam);
5643 pt.y = (short)HIWORD(lParam);
5644 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5647 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5648 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5649 TOOLBAR_Customize (hwnd);
5656 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5659 TBUTTON_INFO *btnPtr;
5664 BOOL bDragKeyPressed;
5668 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5669 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5671 bDragKeyPressed = (wParam & MK_SHIFT);
5673 if (infoPtr->hwndToolTip)
5674 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5675 WM_LBUTTONDOWN, wParam, lParam);
5677 pt.x = (short)LOWORD(lParam);
5678 pt.y = (short)HIWORD(lParam);
5679 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5681 btnPtr = &infoPtr->buttons[nHit];
5683 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5685 infoPtr->nButtonDrag = nHit;
5688 /* If drag cursor has not been loaded, load it.
5689 * Note: it doesn't need to be freed */
5691 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5692 SetCursor(hCursorDrag);
5697 infoPtr->nOldHit = nHit;
5699 CopyRect(&arrowRect, &btnPtr->rect);
5700 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5702 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5703 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5704 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5705 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5706 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5707 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5711 /* draw in pressed state */
5712 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5713 btnPtr->fsState |= TBSTATE_PRESSED;
5715 btnPtr->bDropDownPressed = TRUE;
5716 RedrawWindow(hwnd,&btnPtr->rect,0,
5717 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5719 memset(&nmtb, 0, sizeof(nmtb));
5720 nmtb.iItem = btnPtr->idCommand;
5721 nmtb.rcButton = btnPtr->rect;
5722 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5724 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5726 if (res != TBDDRET_TREATPRESSED)
5730 /* redraw button in unpressed state */
5731 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5732 btnPtr->fsState &= ~TBSTATE_PRESSED;
5734 btnPtr->bDropDownPressed = FALSE;
5735 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5737 /* find and set hot item
5738 * NOTE: native doesn't do this, but that is a bug */
5740 ScreenToClient(hwnd, &pt);
5741 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5742 if (!infoPtr->bAnchor || (nHit >= 0))
5743 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5745 /* remove any left mouse button down or double-click messages
5746 * so that we can get a toggle effect on the button */
5747 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5748 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5753 /* otherwise drop through and process as pushed */
5755 infoPtr->bCaptured = TRUE;
5756 infoPtr->nButtonDown = nHit;
5757 infoPtr->bDragOutSent = FALSE;
5759 btnPtr->fsState |= TBSTATE_PRESSED;
5761 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5763 if (btnPtr->fsState & TBSTATE_ENABLED)
5764 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5771 memset(&nmtb, 0, sizeof(nmtb));
5772 nmtb.iItem = btnPtr->idCommand;
5773 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5776 nmmouse.dwHitInfo = nHit;
5778 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5780 nmmouse.dwItemSpec = -1;
5783 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5784 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5787 ClientToScreen(hwnd, &pt);
5790 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5791 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5797 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5800 TBUTTON_INFO *btnPtr;
5804 BOOL bSendMessage = TRUE;
5809 if (infoPtr->hwndToolTip)
5810 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5811 WM_LBUTTONUP, wParam, lParam);
5813 pt.x = (short)LOWORD(lParam);
5814 pt.y = (short)HIWORD(lParam);
5815 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5817 if (!infoPtr->bAnchor || (nHit >= 0))
5818 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5820 if (infoPtr->nButtonDrag >= 0) {
5824 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5827 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5829 GetClientRect(hwnd, &rcClient);
5830 if (PtInRect(&rcClient, pt))
5837 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5840 if (nButton == infoPtr->nButtonDrag)
5842 /* if the button is moved sightly left and we have a
5843 * separator there then remove it */
5844 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5846 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5847 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5849 else /* else insert a separator before the dragged button */
5852 memset(&tbb, 0, sizeof(tbb));
5853 tbb.fsStyle = BTNS_SEP;
5855 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5862 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5863 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5865 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5868 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5873 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5874 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5877 /* button under cursor changed so need to re-set hot item */
5878 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5879 infoPtr->nButtonDrag = -1;
5881 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5883 else if (infoPtr->nButtonDown >= 0) {
5884 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5885 btnPtr->fsState &= ~TBSTATE_PRESSED;
5887 if (btnPtr->fsStyle & BTNS_CHECK) {
5888 if (btnPtr->fsStyle & BTNS_GROUP) {
5889 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5891 if (nOldIndex == nHit)
5892 bSendMessage = FALSE;
5893 if ((nOldIndex != nHit) &&
5895 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5896 btnPtr->fsState |= TBSTATE_CHECKED;
5899 if (btnPtr->fsState & TBSTATE_CHECKED)
5900 btnPtr->fsState &= ~TBSTATE_CHECKED;
5902 btnPtr->fsState |= TBSTATE_CHECKED;
5906 if (nOldIndex != -1)
5907 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5910 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5911 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5912 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5914 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5916 infoPtr->nButtonDown = -1;
5918 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5919 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5920 NM_RELEASEDCAPTURE);
5922 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5925 memset(&nmtb, 0, sizeof(nmtb));
5926 nmtb.iItem = btnPtr->idCommand;
5927 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5930 if (btnPtr->fsState & TBSTATE_ENABLED)
5932 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5933 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5937 /* !!! Undocumented - toolbar at 4.71 level and above sends
5938 * NM_CLICK with the NMMOUSE structure. */
5939 nmmouse.dwHitInfo = nHit;
5942 nmmouse.dwItemSpec = -1;
5945 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5946 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5949 ClientToScreen(hwnd, &pt);
5952 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5953 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5959 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5966 pt.x = (short)LOWORD(lParam);
5967 pt.y = (short)HIWORD(lParam);
5969 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5970 nmmouse.dwHitInfo = nHit;
5973 nmmouse.dwItemSpec = -1;
5975 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5976 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5979 ClientToScreen(hwnd, &pt);
5982 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5983 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5989 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5991 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5994 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5995 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6001 TOOLBAR_CaptureChanged(HWND hwnd)
6003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6004 TBUTTON_INFO *btnPtr;
6006 infoPtr->bCaptured = FALSE;
6008 if (infoPtr->nButtonDown >= 0)
6010 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6011 btnPtr->fsState &= ~TBSTATE_PRESSED;
6013 infoPtr->nOldHit = -1;
6015 if (btnPtr->fsState & TBSTATE_ENABLED)
6016 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6022 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6024 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6026 /* don't remove hot effects when in anchor highlighting mode or when a
6027 * drop-down button is pressed */
6028 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
6030 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
6031 if (!hotBtnPtr->bDropDownPressed)
6032 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6035 if (infoPtr->nOldHit < 0)
6038 /* If the last button we were over is depressed then make it not */
6039 /* depressed and redraw it */
6040 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6042 TBUTTON_INFO *btnPtr;
6045 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6047 btnPtr->fsState &= ~TBSTATE_PRESSED;
6050 InflateRect (&rc1, 1, 1);
6051 InvalidateRect (hwnd, &rc1, TRUE);
6054 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6057 ZeroMemory(&nmt, sizeof(nmt));
6058 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6059 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6060 infoPtr->bDragOutSent = TRUE;
6063 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6069 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6073 TRACKMOUSEEVENT trackinfo;
6075 TBUTTON_INFO *btnPtr;
6077 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6078 TOOLBAR_TooltipCreateControl(infoPtr);
6080 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6081 /* fill in the TRACKMOUSEEVENT struct */
6082 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6083 trackinfo.dwFlags = TME_QUERY;
6085 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6086 _TrackMouseEvent(&trackinfo);
6088 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6089 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6090 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6091 trackinfo.hwndTrack = hwnd;
6093 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6094 /* and can properly deactivate the hot toolbar button */
6095 _TrackMouseEvent(&trackinfo);
6099 if (infoPtr->hwndToolTip)
6100 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6101 WM_MOUSEMOVE, wParam, lParam);
6103 pt.x = (short)LOWORD(lParam);
6104 pt.y = (short)HIWORD(lParam);
6106 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6108 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6109 && (!infoPtr->bAnchor || (nHit >= 0)))
6110 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6112 if (infoPtr->nOldHit != nHit)
6114 if (infoPtr->bCaptured)
6116 if (!infoPtr->bDragOutSent)
6119 ZeroMemory(&nmt, sizeof(nmt));
6120 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6121 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6122 infoPtr->bDragOutSent = TRUE;
6125 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6126 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6127 btnPtr->fsState &= ~TBSTATE_PRESSED;
6128 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6130 else if (nHit == infoPtr->nButtonDown) {
6131 btnPtr->fsState |= TBSTATE_PRESSED;
6132 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6134 infoPtr->nOldHit = nHit;
6142 inline static LRESULT
6143 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6145 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6146 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6148 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6152 inline static LRESULT
6153 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6155 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6156 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6158 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6163 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6165 TOOLBAR_INFO *infoPtr;
6166 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6169 /* allocate memory for info structure */
6170 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6171 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6174 infoPtr->dwStructSize = sizeof(TBBUTTON);
6176 infoPtr->nWidth = 0;
6178 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6179 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6180 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6181 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6184 /* native control does:
6185 * Get a lot of colors and brushes
6187 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6188 * CreateFontIndirectW(adr1)
6189 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6190 * hdc = GetDC(toolbar)
6191 * GetSystemMetrics(0x48)
6192 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6193 * 0, 0, 0, 0, "MARLETT")
6194 * oldfnt = SelectObject(hdc, fnt2)
6195 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6196 * GetTextMetricsW(hdc, adr3)
6197 * SelectObject(hdc, oldfnt)
6198 * DeleteObject(fnt2)
6200 * InvalidateRect(toolbar, 0, 1)
6201 * SetWindowLongW(toolbar, 0, addr)
6202 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6205 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6206 * ie 2 0x4600094c 0x4600094c 0x4600894d
6207 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6208 * rebar 0x50008844 0x40008844 0x50008845
6209 * pager 0x50000844 0x40000844 0x50008845
6210 * IC35mgr 0x5400084e **nochange**
6211 * on entry to _NCCREATE 0x5400084e
6212 * rowlist 0x5400004e **nochange**
6213 * on entry to _NCCREATE 0x5400004e
6217 /* I think the code below is a bug, but it is the way that the native
6218 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6219 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6220 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6221 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6222 * Somehow, the only cases of this seem to be MFC programs.
6224 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6225 * does not occur in the WM_STYLECHANGING routine.
6226 * (Guy Albertelli 9/2001)
6229 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6230 && !(cs->style & TBSTYLE_TRANSPARENT))
6231 styleadd |= TBSTYLE_TRANSPARENT;
6232 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6233 styleadd |= CCS_TOP; /* default to top */
6234 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6237 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6242 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6244 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6248 if (dwStyle & WS_MINIMIZE)
6249 return 0; /* Nothing to do */
6251 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6253 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6256 if (!(dwStyle & CCS_NODIVIDER))
6258 GetWindowRect (hwnd, &rcWindow);
6259 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6260 if( dwStyle & WS_BORDER )
6261 OffsetRect (&rcWindow, 1, 1);
6262 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6265 ReleaseDC( hwnd, hdc );
6271 /* handles requests from the tooltip control on what text to display */
6272 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6274 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6276 TRACE("button index = %d\n", index);
6278 Free (infoPtr->pszTooltipText);
6279 infoPtr->pszTooltipText = NULL;
6284 if (infoPtr->bUnicode)
6286 WCHAR wszBuffer[INFOTIPSIZE+1];
6287 NMTBGETINFOTIPW tbgit;
6288 unsigned int len; /* in chars */
6290 wszBuffer[0] = '\0';
6291 wszBuffer[INFOTIPSIZE] = '\0';
6293 tbgit.pszText = wszBuffer;
6294 tbgit.cchTextMax = INFOTIPSIZE;
6295 tbgit.iItem = lpnmtdi->hdr.idFrom;
6296 tbgit.lParam = infoPtr->buttons[index].dwData;
6298 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6300 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6302 len = strlenW(tbgit.pszText);
6303 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6305 /* need to allocate temporary buffer in infoPtr as there
6306 * isn't enough space in buffer passed to us by the
6307 * tooltip control */
6308 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6309 if (infoPtr->pszTooltipText)
6311 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6312 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6318 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6324 CHAR szBuffer[INFOTIPSIZE+1];
6325 NMTBGETINFOTIPA tbgit;
6326 unsigned int len; /* in chars */
6329 szBuffer[INFOTIPSIZE] = '\0';
6331 tbgit.pszText = szBuffer;
6332 tbgit.cchTextMax = INFOTIPSIZE;
6333 tbgit.iItem = lpnmtdi->hdr.idFrom;
6334 tbgit.lParam = infoPtr->buttons[index].dwData;
6336 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6338 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6340 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6341 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
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*sizeof(WCHAR));
6347 if (infoPtr->pszTooltipText)
6349 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6350 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6356 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6357 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6362 /* if button has text, but it is not shown then automatically
6363 * use that text as tooltip */
6364 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6365 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6367 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6368 unsigned int len = pszText ? strlenW(pszText) : 0;
6370 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6372 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6374 /* need to allocate temporary buffer in infoPtr as there
6375 * isn't enough space in buffer passed to us by the
6376 * tooltip control */
6377 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6378 if (infoPtr->pszTooltipText)
6380 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6381 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6387 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6392 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6394 /* last resort: send notification on to app */
6395 /* FIXME: find out what is really used here */
6396 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6400 inline static LRESULT
6401 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6403 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6404 LPNMHDR lpnmh = (LPNMHDR)lParam;
6406 switch (lpnmh->code)
6410 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6412 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6413 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6414 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6418 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6419 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6427 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6429 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6430 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6431 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6432 lppgs->iScroll, lppgs->iDir);
6436 case TTN_GETDISPINFOW:
6437 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6439 case TTN_GETDISPINFOA:
6440 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6450 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6454 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6456 if (lParam == NF_QUERY)
6459 if (lParam == NF_REQUERY) {
6460 format = SendMessageW(infoPtr->hwndNotify,
6461 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6462 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6463 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6474 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6480 /* fill ps.rcPaint with a default rect */
6481 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6483 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6485 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6486 ps.rcPaint.left, ps.rcPaint.top,
6487 ps.rcPaint.right, ps.rcPaint.bottom);
6489 TOOLBAR_Refresh (hwnd, hdc, &ps);
6490 if (!wParam) EndPaint (hwnd, &ps);
6497 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6501 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6503 /* make first item hot */
6504 if (infoPtr->nNumButtons > 0)
6505 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6511 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6515 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6518 infoPtr->hFont = infoPtr->hDefaultFont;
6520 infoPtr->hFont = (HFONT)wParam;
6522 TOOLBAR_CalcToolbar(hwnd);
6525 InvalidateRect(hwnd, NULL, TRUE);
6530 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6531 /*****************************************************
6534 * Handles the WM_SETREDRAW message.
6537 * According to testing V4.71 of COMCTL32 returns the
6538 * *previous* status of the redraw flag (either 0 or 1)
6539 * instead of the MSDN documented value of 0 if handled.
6540 * (For laughs see the "consistency" with same function
6543 *****************************************************/
6545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6546 BOOL oldredraw = infoPtr->bDoRedraw;
6548 TRACE("set to %s\n",
6549 (wParam) ? "TRUE" : "FALSE");
6550 infoPtr->bDoRedraw = (BOOL) wParam;
6552 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6554 return (oldredraw) ? 1 : 0;
6559 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6563 TRACE("sizing toolbar!\n");
6565 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6567 RECT delta_width, delta_height, client, dummy;
6568 DWORD min_x, max_x, min_y, max_y;
6569 TBUTTON_INFO *btnPtr;
6572 GetClientRect(hwnd, &client);
6573 if(client.right > infoPtr->client_rect.right)
6575 min_x = infoPtr->client_rect.right;
6576 max_x = client.right;
6580 max_x = infoPtr->client_rect.right;
6581 min_x = client.right;
6583 if(client.bottom > infoPtr->client_rect.bottom)
6585 min_y = infoPtr->client_rect.bottom;
6586 max_y = client.bottom;
6590 max_y = infoPtr->client_rect.bottom;
6591 min_y = client.bottom;
6594 SetRect(&delta_width, min_x, 0, max_x, min_y);
6595 SetRect(&delta_height, 0, min_y, max_x, max_y);
6597 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6598 btnPtr = infoPtr->buttons;
6599 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6600 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6601 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6602 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6604 GetClientRect(hwnd, &infoPtr->client_rect);
6605 TOOLBAR_AutoSize(hwnd);
6611 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6615 if (nType == GWL_STYLE)
6617 DWORD dwOldStyle = infoPtr->dwStyle;
6619 if (lpStyle->styleNew & TBSTYLE_LIST)
6620 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6622 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6624 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6626 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6628 infoPtr->dwStyle = lpStyle->styleNew;
6630 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6631 TOOLBAR_LayoutToolbar(hwnd);
6633 /* only resize if one of the CCS_* styles was changed */
6634 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6636 TOOLBAR_AutoSize (hwnd);
6638 InvalidateRect(hwnd, NULL, TRUE);
6647 TOOLBAR_SysColorChange (HWND hwnd)
6649 COMCTL32_RefreshSysColors();
6655 /* update theme after a WM_THEMECHANGED message */
6656 static LRESULT theme_changed (HWND hwnd)
6658 HTHEME theme = GetWindowTheme (hwnd);
6659 CloseThemeData (theme);
6660 OpenThemeData (hwnd, themeClass);
6665 static LRESULT WINAPI
6666 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6670 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6671 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6673 if (!infoPtr && (uMsg != WM_NCCREATE))
6674 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6679 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6681 case TB_ADDBUTTONSA:
6682 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6684 case TB_ADDBUTTONSW:
6685 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6688 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6691 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6694 return TOOLBAR_AutoSize (hwnd);
6696 case TB_BUTTONCOUNT:
6697 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6699 case TB_BUTTONSTRUCTSIZE:
6700 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6702 case TB_CHANGEBITMAP:
6703 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6705 case TB_CHECKBUTTON:
6706 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6708 case TB_COMMANDTOINDEX:
6709 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6712 return TOOLBAR_Customize (hwnd);
6714 case TB_DELETEBUTTON:
6715 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6717 case TB_ENABLEBUTTON:
6718 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6720 case TB_GETANCHORHIGHLIGHT:
6721 return TOOLBAR_GetAnchorHighlight (hwnd);
6724 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6726 case TB_GETBITMAPFLAGS:
6727 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6730 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6732 case TB_GETBUTTONINFOA:
6733 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6735 case TB_GETBUTTONINFOW:
6736 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6738 case TB_GETBUTTONSIZE:
6739 return TOOLBAR_GetButtonSize (hwnd);
6741 case TB_GETBUTTONTEXTA:
6742 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6744 case TB_GETBUTTONTEXTW:
6745 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6747 case TB_GETDISABLEDIMAGELIST:
6748 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6750 case TB_GETEXTENDEDSTYLE:
6751 return TOOLBAR_GetExtendedStyle (hwnd);
6753 case TB_GETHOTIMAGELIST:
6754 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6757 return TOOLBAR_GetHotItem (hwnd);
6759 case TB_GETIMAGELIST:
6760 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6762 case TB_GETINSERTMARK:
6763 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6765 case TB_GETINSERTMARKCOLOR:
6766 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6768 case TB_GETITEMRECT:
6769 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6772 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6774 /* case TB_GETOBJECT: */ /* 4.71 */
6777 return TOOLBAR_GetPadding (hwnd);
6780 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6783 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6786 return TOOLBAR_GetState (hwnd, wParam, lParam);
6789 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6792 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6795 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6797 case TB_GETTEXTROWS:
6798 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6800 case TB_GETTOOLTIPS:
6801 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6803 case TB_GETUNICODEFORMAT:
6804 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6807 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6810 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6812 case TB_INDETERMINATE:
6813 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6815 case TB_INSERTBUTTONA:
6816 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6818 case TB_INSERTBUTTONW:
6819 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6821 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6823 case TB_ISBUTTONCHECKED:
6824 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6826 case TB_ISBUTTONENABLED:
6827 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6829 case TB_ISBUTTONHIDDEN:
6830 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6832 case TB_ISBUTTONHIGHLIGHTED:
6833 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6835 case TB_ISBUTTONINDETERMINATE:
6836 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6838 case TB_ISBUTTONPRESSED:
6839 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6842 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6844 case TB_MAPACCELERATORA:
6845 case TB_MAPACCELERATORW:
6846 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6849 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6852 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6854 case TB_PRESSBUTTON:
6855 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6857 case TB_REPLACEBITMAP:
6858 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6860 case TB_SAVERESTOREA:
6861 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6863 case TB_SAVERESTOREW:
6864 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6866 case TB_SETANCHORHIGHLIGHT:
6867 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6869 case TB_SETBITMAPSIZE:
6870 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6872 case TB_SETBUTTONINFOA:
6873 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6875 case TB_SETBUTTONINFOW:
6876 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6878 case TB_SETBUTTONSIZE:
6879 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6881 case TB_SETBUTTONWIDTH:
6882 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6885 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6887 case TB_SETDISABLEDIMAGELIST:
6888 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6890 case TB_SETDRAWTEXTFLAGS:
6891 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6893 case TB_SETEXTENDEDSTYLE:
6894 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6896 case TB_SETHOTIMAGELIST:
6897 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6900 return TOOLBAR_SetHotItem (hwnd, wParam);
6902 case TB_SETIMAGELIST:
6903 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6906 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6908 case TB_SETINSERTMARK:
6909 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6911 case TB_SETINSERTMARKCOLOR:
6912 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6914 case TB_SETMAXTEXTROWS:
6915 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6918 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6921 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6924 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6927 return TOOLBAR_SetState (hwnd, wParam, lParam);
6930 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6932 case TB_SETTOOLTIPS:
6933 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6935 case TB_SETUNICODEFORMAT:
6936 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6939 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6942 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6945 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6948 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6951 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6954 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6956 /* Common Control Messages */
6958 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6959 case CCM_GETCOLORSCHEME:
6960 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6962 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6963 case CCM_SETCOLORSCHEME:
6964 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6966 case CCM_GETVERSION:
6967 return TOOLBAR_GetVersion (hwnd);
6969 case CCM_SETVERSION:
6970 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6976 return TOOLBAR_Create (hwnd, wParam, lParam);
6979 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6982 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6985 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6988 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6990 /* case WM_KILLFOCUS: */
6992 case WM_LBUTTONDBLCLK:
6993 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6995 case WM_LBUTTONDOWN:
6996 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6999 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7002 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7004 case WM_RBUTTONDBLCLK:
7005 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7008 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7011 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7013 case WM_CAPTURECHANGED:
7014 return TOOLBAR_CaptureChanged(hwnd);
7017 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7020 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7023 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7026 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7029 return TOOLBAR_Notify (hwnd, wParam, lParam);
7031 case WM_NOTIFYFORMAT:
7032 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7034 case WM_PRINTCLIENT:
7036 return TOOLBAR_Paint (hwnd, wParam);
7039 return TOOLBAR_SetFocus (hwnd, wParam);
7042 return TOOLBAR_SetFont(hwnd, wParam, lParam);
7045 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7048 return TOOLBAR_Size (hwnd, wParam, lParam);
7050 case WM_STYLECHANGED:
7051 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7053 case WM_SYSCOLORCHANGE:
7054 return TOOLBAR_SysColorChange (hwnd);
7056 case WM_THEMECHANGED:
7057 return theme_changed (hwnd);
7059 /* case WM_WININICHANGE: */
7064 case WM_MEASUREITEM:
7066 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7068 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7069 case PGM_FORWARDMOUSE:
7070 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7073 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7074 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7075 uMsg, wParam, lParam);
7076 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7082 TOOLBAR_Register (void)
7086 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7087 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7088 wndClass.lpfnWndProc = ToolbarWindowProc;
7089 wndClass.cbClsExtra = 0;
7090 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7091 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7092 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7093 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7095 RegisterClassW (&wndClass);
7100 TOOLBAR_Unregister (void)
7102 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7105 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7110 /* Check if the entry already exists */
7111 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7113 /* If this is a new entry we must create it and insert into the array */
7118 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7121 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7122 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7137 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7141 for (i = 0; i < *cies; i++)
7151 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7159 for (i = 0; i < cies; i++)
7161 if (pies[i]->id == id)
7173 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7175 HIMAGELIST himlDef = 0;
7176 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7179 himlDef = pie->himl;
7185 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7187 if (infoPtr->bUnicode)
7188 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7195 nmtba.iItem = nmtb->iItem;
7196 nmtba.pszText = Buffer;
7197 nmtba.cchText = 256;
7198 ZeroMemory(nmtba.pszText, nmtba.cchText);
7200 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7202 int ccht = strlen(nmtba.pszText);
7204 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7205 nmtb->pszText, nmtb->cchText);
7207 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7216 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7217 int iItem, PCUSTOMBUTTON btnInfo)
7221 /* MSDN states that iItem is the index of the button, rather than the
7222 * command ID as used by every other NMTOOLBAR notification */
7224 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7226 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);