4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
47 * - Button wrapping (under construction).
49 * - iListGap custom draw support.
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsoft's controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
61 * Differences between MSDN and actual native control operation:
62 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
63 * to the right of the bitmap. Otherwise, this style is
64 * identical to TBSTYLE_FLAT."
65 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
66 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
67 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
68 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
80 #include "wine/unicode.h"
84 #include "wine/debug.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
88 static HCURSOR hCursorDrag = NULL;
97 BYTE bDropDownPressed;
102 INT cx; /* manually set size */
116 } IMLENTRY, *PIMLENTRY;
120 DWORD dwStructSize; /* size of TBBUTTON struct */
121 INT nWidth; /* width of the toolbar */
123 RECT rcBound; /* bounding rectangle */
129 INT nRows; /* number of button rows */
130 INT nMaxTextRows; /* maximum number of text rows */
131 INT cxMin; /* minimum button width */
132 INT cxMax; /* maximum button width */
133 INT nNumButtons; /* number of buttons */
134 INT nNumBitmaps; /* number of bitmaps */
135 INT nNumStrings; /* number of strings */
137 INT nButtonDown; /* toolbar button being pressed or -1 if none */
138 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
140 INT nHotItem; /* index of the "hot" item */
141 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
142 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
143 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
144 SIZE szPadding; /* padding values around button */
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 BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
242 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
243 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
244 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
245 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
246 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
247 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
248 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
249 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
256 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
258 LPWSTR lpText = NULL;
260 /* NOTE: iString == -1 is undocumented */
261 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
262 lpText = (LPWSTR)btnPtr->iString;
263 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
264 lpText = infoPtr->strings[btnPtr->iString];
270 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
272 if (TRACE_ON(toolbar)){
273 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
274 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
275 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
276 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
278 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
279 btn_num, bP->idCommand,
280 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
281 bP->rect.left, bP->rect.top,
282 bP->rect.right, bP->rect.bottom);
288 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
290 if (TRACE_ON(toolbar)) {
293 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
295 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
296 iP->nNumStrings, iP->dwStyle);
297 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
299 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
300 (iP->bDoRedraw) ? "TRUE" : "FALSE");
301 for(i=0; i<iP->nNumButtons; i++) {
302 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
308 /***********************************************************************
311 * This function validates that the styles set are implemented and
312 * issues FIXME's warning of possible problems. In a perfect world this
313 * function should be null.
316 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
318 if (dwStyle & TBSTYLE_REGISTERDROP)
319 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
324 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
326 if(!IsWindow(infoPtr->hwndSelf))
327 return 0; /* we have just been destroyed */
329 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
330 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
334 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
336 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
337 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
340 /***********************************************************************
341 * TOOLBAR_GetBitmapIndex
343 * This function returns the bitmap index associated with a button.
344 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
345 * is issued to retrieve the index.
348 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
350 INT ret = btnPtr->iBitmap;
352 if (ret == I_IMAGECALLBACK)
354 /* issue TBN_GETDISPINFO */
357 memset(&nmgd, 0, sizeof(nmgd));
358 nmgd.idCommand = btnPtr->idCommand;
359 nmgd.lParam = btnPtr->dwData;
360 nmgd.dwMask = TBNF_IMAGE;
361 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
362 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
363 if (nmgd.dwMask & TBNF_DI_SETITEM)
364 btnPtr->iBitmap = nmgd.iImage;
366 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
367 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
370 if (ret != I_IMAGENONE)
371 ret = GETIBITMAP(infoPtr, ret);
378 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
381 INT id = GETHIMLID(infoPtr, index);
382 INT iBitmap = GETIBITMAP(infoPtr, index);
384 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
385 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
386 (index == I_IMAGECALLBACK))
394 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
396 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
397 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
401 /***********************************************************************
402 * TOOLBAR_GetImageListForDrawing
404 * This function validates the bitmap index (including I_IMAGECALLBACK
405 * functionality) and returns the corresponding image list.
408 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
412 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
413 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
414 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
415 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
419 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
420 if ((*index == I_IMAGECALLBACK) ||
421 (*index == I_IMAGENONE)) return NULL;
422 ERR("TBN_GETDISPINFO returned invalid index %d\n",
429 case IMAGE_LIST_DEFAULT:
430 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 case IMAGE_LIST_DISABLED:
436 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
440 FIXME("Shouldn't reach here\n");
444 TRACE("no image list\n");
451 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
454 COLORREF oldcolor, newcolor;
456 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
457 myrect.right = myrect.left + 1;
458 myrect.top = lpRect->top + 2;
459 myrect.bottom = lpRect->bottom - 2;
461 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
462 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
463 oldcolor = SetBkColor (hdc, newcolor);
464 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
466 myrect.left = myrect.right;
467 myrect.right = myrect.left + 1;
469 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
470 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
471 SetBkColor (hdc, newcolor);
472 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
474 SetBkColor (hdc, oldcolor);
478 /***********************************************************************
479 * TOOLBAR_DrawDDFlatSeparator
481 * This function draws the separator that was flagged as BTNS_DROPDOWN.
482 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
483 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
484 * are horizontal as opposed to the vertical separators for not dropdown
487 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
490 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
493 COLORREF oldcolor, newcolor;
495 myrect.left = lpRect->left;
496 myrect.right = lpRect->right;
497 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
498 myrect.bottom = myrect.top + 1;
500 InflateRect (&myrect, -2, 0);
502 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
503 myrect.left, myrect.top, myrect.right, myrect.bottom);
505 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
506 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
507 oldcolor = SetBkColor (hdc, newcolor);
508 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
510 myrect.top = myrect.bottom;
511 myrect.bottom = myrect.top + 1;
513 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
514 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
515 SetBkColor (hdc, newcolor);
516 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
518 SetBkColor (hdc, oldcolor);
523 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
528 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
529 hOldPen = SelectObject ( hdc, hPen );
532 MoveToEx (hdc, x, y, NULL);
533 LineTo (hdc, x+5, y++); x++;
534 MoveToEx (hdc, x, y, NULL);
535 LineTo (hdc, x+3, y++); x++;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+1, y++);
538 SelectObject( hdc, hOldPen );
539 DeleteObject( hPen );
543 * Draw the text string for this button.
544 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
545 * is non-zero, so we can simply check himlDef to see if we have
549 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
550 NMTBCUSTOMDRAW *tbcd)
552 HDC hdc = tbcd->nmcd.hdc;
555 COLORREF clrOldBk = 0;
557 UINT state = tbcd->nmcd.uItemState;
561 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
562 rcText->left, rcText->top, rcText->right, rcText->bottom);
564 hOldFont = SelectObject (hdc, infoPtr->hFont);
565 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
566 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
568 else if (state & CDIS_DISABLED) {
569 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
570 OffsetRect (rcText, 1, 1);
571 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
572 SetTextColor (hdc, comctl32_color.clr3dShadow);
573 OffsetRect (rcText, -1, -1);
575 else if (state & CDIS_INDETERMINATE) {
576 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
578 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
579 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
580 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
581 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
584 clrOld = SetTextColor (hdc, tbcd->clrText);
587 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
588 SetTextColor (hdc, clrOld);
589 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
591 SetBkColor (hdc, clrOldBk);
592 SetBkMode (hdc, oldBkMode);
594 SelectObject (hdc, hOldFont);
600 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
602 HDC hdc = tbcd->nmcd.hdc;
603 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
606 INT cx = lpRect->right - lpRect->left;
607 INT cy = lpRect->bottom - lpRect->top;
608 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
609 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
610 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
611 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
612 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
613 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
614 SetBkColor(hdc, clrBkOld);
615 SetTextColor(hdc, clrTextOld);
616 SelectObject (hdc, hbr);
620 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
623 HBITMAP hbmMask, hbmImage;
624 HDC hdcMask, hdcImage;
626 ImageList_GetIconSize(himl, &cx, &cy);
628 /* Create src image */
629 hdcImage = CreateCompatibleDC(hdc);
630 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
631 SelectObject(hdcImage, hbmImage);
632 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
633 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
636 hdcMask = CreateCompatibleDC(0);
637 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
638 SelectObject(hdcMask, hbmMask);
640 /* Remove the background and all white pixels */
641 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
642 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
643 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
644 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
646 /* draw the new mask 'etched' to hdc */
647 SetBkColor(hdc, RGB(255, 255, 255));
648 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
649 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
650 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
651 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
652 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
655 DeleteObject(hbmImage);
657 DeleteObject (hbmMask);
663 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
667 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
668 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
669 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
670 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
671 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
672 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
673 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
677 /* draws the image on a toolbar button */
679 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
681 HIMAGELIST himl = NULL;
682 BOOL draw_masked = FALSE;
685 UINT draw_flags = ILD_TRANSPARENT;
687 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
689 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
692 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
696 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
698 /* if hot, attempt to draw with hot image list, if fails,
699 use default image list */
700 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
705 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
710 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
711 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
714 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
715 (tbcd->nmcd.uItemState & CDIS_MARKED))
716 draw_flags |= ILD_BLEND50;
718 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
719 index, himl, left, top, offset);
722 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
724 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
727 /* draws a blank frame for a toolbar button */
729 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
731 HDC hdc = tbcd->nmcd.hdc;
732 RECT rc = tbcd->nmcd.rc;
733 /* if the state is disabled or indeterminate then the button
734 * cannot have an interactive look like pressed or hot */
735 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
736 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
737 BOOL pressed_look = !non_interactive_state &&
738 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
739 (tbcd->nmcd.uItemState & CDIS_CHECKED));
741 /* app don't want us to draw any edges */
742 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
745 if (infoPtr->dwStyle & TBSTYLE_FLAT)
748 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
749 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
750 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
755 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
757 DrawEdge (hdc, &rc, EDGE_RAISED,
758 BF_SOFT | BF_RECT | BF_MIDDLE);
763 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
765 HDC hdc = tbcd->nmcd.hdc;
767 BOOL pressed = bDropDownPressed ||
768 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
770 if (infoPtr->dwStyle & TBSTYLE_FLAT)
773 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
774 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
775 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
776 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
777 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
782 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
784 DrawEdge (hdc, rcArrow, EDGE_RAISED,
785 BF_SOFT | BF_RECT | BF_MIDDLE);
789 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
791 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
793 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
794 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
797 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
800 /* draws a complete toolbar button */
802 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
805 DWORD dwStyle = infoPtr->dwStyle;
806 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
807 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
808 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
809 BOOL drawSepDropDownArrow = hasDropDownArrow &&
810 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
811 RECT rc, rcArrow, rcBitmap, rcText;
812 LPWSTR lpText = NULL;
819 CopyRect (&rcArrow, &rc);
821 /* get a pointer to the text */
822 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
824 if (hasDropDownArrow)
828 if (dwStyle & TBSTYLE_FLAT)
829 right = max(rc.left, rc.right - DDARROW_WIDTH);
831 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
833 if (drawSepDropDownArrow)
836 rcArrow.left = right;
839 /* copy text & bitmap rects after adjusting for drop-down arrow
840 * so that text & bitmap is centred in the rectangle not containing
842 CopyRect(&rcText, &rc);
843 CopyRect(&rcBitmap, &rc);
845 /* Center the bitmap horizontally and vertically */
846 if (dwStyle & TBSTYLE_LIST)
849 infoPtr->nMaxTextRows > 0 &&
850 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
851 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
852 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
854 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
857 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
859 rcBitmap.top += infoPtr->szPadding.cy / 2;
861 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
862 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
863 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
864 TRACE("Text=%s\n", debugstr_w(lpText));
865 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
867 /* calculate text position */
870 rcText.left += GetSystemMetrics(SM_CXEDGE);
871 rcText.right -= GetSystemMetrics(SM_CXEDGE);
872 if (dwStyle & TBSTYLE_LIST)
874 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
875 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
879 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
880 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
882 rcText.top += infoPtr->szPadding.cy/2 + 2;
886 /* Initialize fields in all cases, because we use these later
887 * NOTE: applications can and do alter these to customize their
889 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
890 tbcd.clrText = comctl32_color.clrBtnText;
891 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
892 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
893 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
894 tbcd.clrMark = comctl32_color.clrHighlight;
895 tbcd.clrHighlightHotTrack = 0;
896 tbcd.nStringBkMode = TRANSPARENT;
897 tbcd.nHLStringBkMode = OPAQUE;
898 /* MSDN says that this is the text rectangle.
899 * But (why always a but) tracing of v5.7 of native shows
900 * that this is really a *relative* rectangle based on the
901 * the nmcd.rc. Also the left and top are always 0 ignoring
902 * any bitmap that might be present. */
903 tbcd.rcText.left = 0;
905 tbcd.rcText.right = rcText.right - rc.left;
906 tbcd.rcText.bottom = rcText.bottom - rc.top;
907 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
910 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
912 /* FIXME: what are these used for? */
916 /* Issue Item Prepaint notify */
917 infoPtr->dwItemCustDraw = 0;
918 infoPtr->dwItemCDFlag = 0;
919 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
921 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
922 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
923 tbcd.nmcd.lItemlParam = btnPtr->dwData;
924 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
925 /* reset these fields so the user can't alter the behaviour like native */
929 infoPtr->dwItemCustDraw = ntfret & 0xffff;
930 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
931 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
933 /* save the only part of the rect that the user can change */
934 rcText.right = tbcd.rcText.right + rc.left;
935 rcText.bottom = tbcd.rcText.bottom + rc.top;
939 if (btnPtr->fsStyle & BTNS_SEP) {
940 /* with the FLAT style, iBitmap is the width and has already */
941 /* been taken into consideration in calculating the width */
942 /* so now we need to draw the vertical separator */
943 /* empirical tests show that iBitmap can/will be non-zero */
944 /* when drawing the vertical bar... */
945 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
946 if (btnPtr->fsStyle & BTNS_DROPDOWN)
947 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
949 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
951 else if (btnPtr->fsStyle != BTNS_SEP) {
952 FIXME("Draw some kind of separator: fsStyle=%x\n",
958 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
959 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
960 OffsetRect(&rcText, 1, 1);
962 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
963 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
964 TOOLBAR_DrawPattern (&rc, &tbcd);
966 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
968 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
972 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
973 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
974 if (hasDropDownArrow)
975 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
976 SetBkColor(hdc, oldclr);
980 TOOLBAR_DrawFrame(infoPtr, &tbcd);
982 if (drawSepDropDownArrow)
983 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
985 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
986 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
987 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
988 SetBkMode (hdc, oldBkMode);
990 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
992 if (hasDropDownArrow && !drawSepDropDownArrow)
994 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
996 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
997 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
999 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1001 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1002 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1005 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1009 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1011 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1012 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1019 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1022 TBUTTON_INFO *btnPtr;
1024 RECT rcTemp, rcClient;
1025 NMTBCUSTOMDRAW tbcd;
1028 /* the app has told us not to redraw the toolbar */
1029 if (!infoPtr->bDoRedraw)
1032 /* if imagelist belongs to the app, it can be changed
1033 by the app after setting it */
1034 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1036 infoPtr->nNumBitmaps = 0;
1037 for (i = 0; i < infoPtr->cimlDef; i++)
1038 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1041 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1043 /* Send initial notify */
1044 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1045 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1046 tbcd.nmcd.hdc = hdc;
1047 tbcd.nmcd.rc = ps->rcPaint;
1048 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1049 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1051 GetClientRect(hwnd, &rcClient);
1053 /* redraw necessary buttons */
1054 btnPtr = infoPtr->buttons;
1055 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1058 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1060 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1061 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1065 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1066 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1068 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1071 /* draw insert mark if required */
1072 if (infoPtr->tbim.iButton != -1)
1074 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1076 rcInsertMark.top = rcButton.top;
1077 rcInsertMark.bottom = rcButton.bottom;
1078 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1079 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1081 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1082 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1085 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1087 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1088 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1089 tbcd.nmcd.hdc = hdc;
1090 tbcd.nmcd.rc = ps->rcPaint;
1091 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1095 /***********************************************************************
1096 * TOOLBAR_MeasureString
1098 * This function gets the width and height of a string in pixels. This
1099 * is done first by using GetTextExtentPoint to get the basic width
1100 * and height. The DrawText is called with DT_CALCRECT to get the exact
1101 * width. The reason is because the text may have more than one "&" (or
1102 * prefix characters as M$ likes to call them). The prefix character
1103 * indicates where the underline goes, except for the string "&&" which
1104 * is reduced to a single "&". GetTextExtentPoint does not process these
1105 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1108 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1109 HDC hdc, LPSIZE lpSize)
1116 if (infoPtr->nMaxTextRows > 0 &&
1117 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1118 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1119 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1121 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1123 if(lpText != NULL) {
1124 /* first get size of all the text */
1125 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1127 /* feed above size into the rectangle for DrawText */
1128 myrect.left = myrect.top = 0;
1129 myrect.right = lpSize->cx;
1130 myrect.bottom = lpSize->cy;
1132 /* Use DrawText to get true size as drawn (less pesky "&") */
1133 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1134 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1137 /* feed back to caller */
1138 lpSize->cx = myrect.right;
1139 lpSize->cy = myrect.bottom;
1143 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1146 /***********************************************************************
1147 * TOOLBAR_CalcStrings
1149 * This function walks through each string and measures it and returns
1150 * the largest height and width to caller.
1153 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1155 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1156 TBUTTON_INFO *btnPtr;
1165 if (infoPtr->nMaxTextRows == 0)
1169 hOldFont = SelectObject (hdc, infoPtr->hFont);
1171 if (infoPtr->nNumButtons == 0)
1175 GetTextMetricsW(hdc, &tm);
1176 lpSize->cy = tm.tmHeight;
1179 btnPtr = infoPtr->buttons;
1180 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1181 if(TOOLBAR_HasText(infoPtr, btnPtr))
1183 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1184 if (sz.cx > lpSize->cx)
1186 if (sz.cy > lpSize->cy)
1191 SelectObject (hdc, hOldFont);
1192 ReleaseDC (hwnd, hdc);
1194 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1197 /***********************************************************************
1198 * TOOLBAR_WrapToolbar
1200 * This function walks through the buttons and separators in the
1201 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1202 * wrapping should occur based on the width of the toolbar window.
1203 * It does *not* calculate button placement itself. That task
1204 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1205 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1206 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1208 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1209 * vertical toolbar lists.
1213 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1216 TBUTTON_INFO *btnPtr;
1219 BOOL bWrap, bButtonWrap;
1221 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1222 /* no layout is necessary. Applications may use this style */
1223 /* to perform their own layout on the toolbar. */
1224 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1225 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1227 btnPtr = infoPtr->buttons;
1228 x = infoPtr->nIndent;
1230 /* this can get the parents width, to know how far we can extend
1231 * this toolbar. We cannot use its height, as there may be multiple
1232 * toolbars in a rebar control
1234 GetClientRect( GetParent(hwnd), &rc );
1235 infoPtr->nWidth = rc.right - rc.left;
1236 bButtonWrap = FALSE;
1238 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1239 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1242 for (i = 0; i < infoPtr->nNumButtons; i++ )
1245 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1247 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1250 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1251 /* it is the actual width of the separator. This is used for */
1252 /* custom controls in toolbars. */
1254 /* BTNS_DROPDOWN separators are treated as buttons for */
1255 /* width. - GA 8/01 */
1256 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1257 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1258 cx = (btnPtr[i].iBitmap > 0) ?
1259 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1261 cx = infoPtr->nButtonWidth;
1263 /* Two or more adjacent separators form a separator group. */
1264 /* The first separator in a group should be wrapped to the */
1265 /* next row if the previous wrapping is on a button. */
1267 (btnPtr[i].fsStyle & BTNS_SEP) &&
1268 (i + 1 < infoPtr->nNumButtons ) &&
1269 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1271 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1272 btnPtr[i].fsState |= TBSTATE_WRAP;
1273 x = infoPtr->nIndent;
1275 bButtonWrap = FALSE;
1279 /* The layout makes sure the bitmap is visible, but not the button. */
1280 /* Test added to also wrap after a button that starts a row but */
1281 /* is bigger than the area. - GA 8/01 */
1282 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1283 > infoPtr->nWidth ) ||
1284 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1286 BOOL bFound = FALSE;
1288 /* If the current button is a separator and not hidden, */
1289 /* go to the next until it reaches a non separator. */
1290 /* Wrap the last separator if it is before a button. */
1291 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1292 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1293 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1294 i < infoPtr->nNumButtons )
1300 if( bFound && i < infoPtr->nNumButtons )
1303 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1304 i, btnPtr[i].fsStyle, x, cx);
1305 btnPtr[i].fsState |= TBSTATE_WRAP;
1306 x = infoPtr->nIndent;
1307 bButtonWrap = FALSE;
1310 else if ( i >= infoPtr->nNumButtons)
1313 /* If the current button is not a separator, find the last */
1314 /* separator and wrap it. */
1315 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1317 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1318 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1322 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1323 i, btnPtr[i].fsStyle, x, cx);
1324 x = infoPtr->nIndent;
1325 btnPtr[j].fsState |= TBSTATE_WRAP;
1326 bButtonWrap = FALSE;
1331 /* If no separator available for wrapping, wrap one of */
1332 /* non-hidden previous button. */
1336 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1338 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1343 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1344 i, btnPtr[i].fsStyle, x, cx);
1345 x = infoPtr->nIndent;
1346 btnPtr[j].fsState |= TBSTATE_WRAP;
1352 /* If all above failed, wrap the current button. */
1355 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1356 i, btnPtr[i].fsStyle, x, cx);
1357 btnPtr[i].fsState |= TBSTATE_WRAP;
1359 x = infoPtr->nIndent;
1360 if (btnPtr[i].fsStyle & BTNS_SEP )
1361 bButtonWrap = FALSE;
1367 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1368 i, btnPtr[i].fsStyle, x, cx);
1375 /***********************************************************************
1376 * TOOLBAR_MeasureButton
1378 * Calculates the width and height required for a button. Used in
1379 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1380 * the width of buttons that are autosized.
1382 * Note that it would have been rather elegant to use one piece of code for
1383 * both the laying out of the toolbar and for controlling where button parts
1384 * are drawn, but the native control has inconsistencies between the two that
1385 * prevent this from being effectively. These inconsistencies can be seen as
1386 * artefacts where parts of the button appear outside of the bounding button
1389 * There are several cases for the calculation of the button dimensions and
1390 * button part positioning:
1397 * +--------------------------------------------------------+ ^
1399 * | | pad.cy / 2 | centred | |
1400 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1401 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1402 * | |<------------>| | | | |
1403 * | +--------------+ +------------+ | |
1404 * |<-------------------------------------->| | |
1405 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1407 * +--------------------------------------------------------+ -
1408 * <-------------------------------------------------------->
1409 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1411 * Without Bitmap (I_IMAGENONE):
1413 * +-----------------------------------+ ^
1415 * | | centred | | LISTPAD_CY +
1416 * | +------------+ | | szText.cy
1419 * | +------------+ | |
1420 * |<----------------->| | |
1421 * | cxedge |<-----------> | |
1423 * +-----------------------------------+ -
1424 * <----------------------------------->
1425 * szText.cx + pad.cx
1429 * +--------------------------------------+ ^
1431 * | | padding.cy/2 | | DEFPAD_CY +
1432 * | +------------+ | | nBitmapHeight
1435 * | +------------+ | |
1436 * |<------------------->| | |
1437 * | cxedge + iListGap/2 |<-----------> | |
1438 * | nBitmapWidth | |
1439 * +--------------------------------------+ -
1440 * <-------------------------------------->
1441 * 2*cxedge + nBitmapWidth + iListGap
1448 * +-----------------------------------+ ^
1450 * | | pad.cy / 2 | | nBitmapHeight +
1451 * | - | | szText.cy +
1452 * | +------------+ | | DEFPAD_CY + 1
1453 * | centred | Bitmap | | |
1454 * |<----------------->| | | |
1455 * | +------------+ | |
1459 * | centred +---------------+ | |
1460 * |<--------------->| Text | | |
1461 * | +---------------+ | |
1462 * +-----------------------------------+ -
1463 * <----------------------------------->
1464 * pad.cx + max(nBitmapWidth, szText.cx)
1466 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1468 * +---------------------------------------+ ^
1470 * | | 2 + pad.cy / 2 | |
1471 * | - | | szText.cy +
1472 * | centred +-----------------+ | | pad.cy + 2
1473 * |<--------------->| Text | | |
1474 * | +-----------------+ | |
1476 * +---------------------------------------+ -
1477 * <--------------------------------------->
1478 * 2*cxedge + pad.cx + szText.cx
1481 * As for with bitmaps, but with szText.cx zero.
1483 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1486 if (infoPtr->dwStyle & TBSTYLE_LIST)
1488 /* set button height from bitmap / text height... */
1489 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1492 /* ... add on the necessary padding */
1493 if (bValidImageList)
1496 sizeButton.cy += DEFPAD_CY;
1498 sizeButton.cy += LISTPAD_CY;
1501 sizeButton.cy += infoPtr->szPadding.cy;
1503 /* calculate button width */
1506 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1507 infoPtr->nBitmapWidth + infoPtr->iListGap;
1508 if (sizeString.cx > 0)
1509 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1512 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1518 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1519 sizeString.cy + DEFPAD_CY;
1520 sizeButton.cx = infoPtr->szPadding.cx +
1521 max(sizeString.cx, infoPtr->nBitmapWidth);
1525 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1526 NONLIST_NOTEXT_OFFSET;
1527 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1528 infoPtr->szPadding.cx + sizeString.cx;
1535 /***********************************************************************
1536 * TOOLBAR_CalcToolbar
1538 * This function calculates button and separator placement. It first
1539 * calculates the button sizes, gets the toolbar window width and then
1540 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1541 * on. It assigns a new location to each item and sends this location to
1542 * the tooltip window if appropriate. Finally, it updates the rcBound
1543 * rect and calculates the new required toolbar window height.
1546 TOOLBAR_CalcToolbar (HWND hwnd)
1548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1549 DWORD dwStyle = infoPtr->dwStyle;
1550 TBUTTON_INFO *btnPtr;
1551 INT i, nRows, nSepRows;
1553 SIZE sizeString, sizeButton;
1555 BOOL validImageList = FALSE;
1556 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1558 TOOLBAR_CalcStrings (hwnd, &sizeString);
1560 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1562 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1563 validImageList = TRUE;
1564 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1565 infoPtr->nButtonWidth = sizeButton.cx;
1566 infoPtr->nButtonHeight = sizeButton.cy;
1568 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1569 infoPtr->nButtonWidth = infoPtr->cxMin;
1570 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1571 infoPtr->nButtonWidth = infoPtr->cxMax;
1573 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1575 x = infoPtr->nIndent;
1576 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1581 /* from above, minimum is a button, and possible text */
1582 cx = infoPtr->nButtonWidth;
1583 cy = infoPtr->nButtonHeight;
1585 nRows = nSepRows = 0;
1587 infoPtr->rcBound.top = y;
1588 infoPtr->rcBound.left = x;
1589 infoPtr->rcBound.bottom = y + cy;
1590 infoPtr->rcBound.right = x;
1592 btnPtr = infoPtr->buttons;
1594 TRACE("cy=%d\n", cy);
1596 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1599 if (btnPtr->fsState & TBSTATE_HIDDEN)
1601 SetRectEmpty (&btnPtr->rect);
1605 cy = infoPtr->nButtonHeight;
1607 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1608 /* it is the actual width of the separator. This is used for */
1609 /* custom controls in toolbars. */
1610 if (btnPtr->fsStyle & BTNS_SEP) {
1611 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1612 cy = (btnPtr->iBitmap > 0) ?
1613 btnPtr->iBitmap : SEPARATOR_WIDTH;
1614 cx = infoPtr->nButtonWidth;
1617 cx = (btnPtr->iBitmap > 0) ?
1618 btnPtr->iBitmap : SEPARATOR_WIDTH;
1624 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1625 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1632 hOldFont = SelectObject (hdc, infoPtr->hFont);
1634 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1636 SelectObject (hdc, hOldFont);
1637 ReleaseDC (hwnd, hdc);
1639 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1640 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1645 cx = infoPtr->nButtonWidth;
1647 /* if size has been set manually then don't add on extra space
1648 * for the drop down arrow */
1649 if (!btnPtr->cx && hasDropDownArrows &&
1650 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1651 cx += DDARROW_WIDTH;
1653 if (btnPtr->fsState & TBSTATE_WRAP )
1656 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1658 if (infoPtr->rcBound.left > x)
1659 infoPtr->rcBound.left = x;
1660 if (infoPtr->rcBound.right < x + cx)
1661 infoPtr->rcBound.right = x + cx;
1662 if (infoPtr->rcBound.bottom < y + cy)
1663 infoPtr->rcBound.bottom = y + cy;
1665 /* Set the toolTip only for non-hidden, non-separator button */
1666 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1670 ZeroMemory (&ti, sizeof(ti));
1671 ti.cbSize = sizeof(ti);
1673 ti.uId = btnPtr->idCommand;
1674 ti.rect = btnPtr->rect;
1675 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1679 /* btnPtr->nRow is zero based. The space between the rows is */
1680 /* also considered as a row. */
1681 btnPtr->nRow = nRows + nSepRows;
1683 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1684 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1689 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1693 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1694 /* it is the actual width of the separator. This is used for */
1695 /* custom controls in toolbars. */
1696 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1697 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1698 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1702 /* nSepRows is used to calculate the extra height follwoing */
1706 x = infoPtr->nIndent;
1708 /* Increment row number unless this is the last button */
1709 /* and it has Wrap set. */
1710 if (i != infoPtr->nNumButtons-1)
1717 /* infoPtr->nRows is the number of rows on the toolbar */
1718 infoPtr->nRows = nRows + nSepRows + 1;
1720 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1725 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1728 TBUTTON_INFO *btnPtr;
1731 btnPtr = infoPtr->buttons;
1732 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1733 if (btnPtr->fsState & TBSTATE_HIDDEN)
1736 if (btnPtr->fsStyle & BTNS_SEP) {
1737 if (PtInRect (&btnPtr->rect, *lpPt)) {
1738 TRACE(" ON SEPARATOR %d!\n", i);
1743 if (PtInRect (&btnPtr->rect, *lpPt)) {
1744 TRACE(" ON BUTTON %d!\n", i);
1750 TRACE(" NOWHERE!\n");
1751 return TOOLBAR_NOWHERE;
1756 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1758 TBUTTON_INFO *btnPtr;
1761 if (CommandIsIndex) {
1762 TRACE("command is really index command=%d\n", idCommand);
1763 if (idCommand >= infoPtr->nNumButtons) return -1;
1766 btnPtr = infoPtr->buttons;
1767 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1768 if (btnPtr->idCommand == idCommand) {
1769 TRACE("command=%d index=%d\n", idCommand, i);
1773 TRACE("no index found for command=%d\n", idCommand);
1779 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1781 TBUTTON_INFO *btnPtr;
1784 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1787 /* check index button */
1788 btnPtr = &infoPtr->buttons[nIndex];
1789 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1790 if (btnPtr->fsState & TBSTATE_CHECKED)
1794 /* check previous buttons */
1795 nRunIndex = nIndex - 1;
1796 while (nRunIndex >= 0) {
1797 btnPtr = &infoPtr->buttons[nRunIndex];
1798 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1799 if (btnPtr->fsState & TBSTATE_CHECKED)
1807 /* check next buttons */
1808 nRunIndex = nIndex + 1;
1809 while (nRunIndex < infoPtr->nNumButtons) {
1810 btnPtr = &infoPtr->buttons[nRunIndex];
1811 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1812 if (btnPtr->fsState & TBSTATE_CHECKED)
1825 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1826 WPARAM wParam, LPARAM lParam)
1832 msg.wParam = wParam;
1833 msg.lParam = lParam;
1834 msg.time = GetMessageTime ();
1835 msg.pt.x = LOWORD(GetMessagePos ());
1836 msg.pt.y = HIWORD(GetMessagePos ());
1838 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1841 /* keeps available button list box sorted by button id */
1842 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1846 PCUSTOMBUTTON btnInfo;
1847 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1849 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1851 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1853 /* position 0 is always separator */
1854 for (i = 1; i < count; i++)
1856 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1857 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1859 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1860 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1864 /* id higher than all others add to end */
1865 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1866 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1869 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1873 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1875 if (nIndexFrom == nIndexTo)
1878 /* MSDN states that iItem is the index of the button, rather than the
1879 * command ID as used by every other NMTOOLBAR notification */
1880 nmtb.iItem = nIndexFrom;
1881 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1883 PCUSTOMBUTTON btnInfo;
1885 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1886 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1888 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1890 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1891 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1892 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1893 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1896 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1898 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1900 /* last item is always separator, so -2 instead of -1 */
1901 if (nIndexTo >= (count - 2))
1902 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1904 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1906 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1907 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1909 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1913 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1917 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1919 /* MSDN states that iItem is the index of the button, rather than the
1920 * command ID as used by every other NMTOOLBAR notification */
1921 nmtb.iItem = nIndexAvail;
1922 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1924 PCUSTOMBUTTON btnInfo;
1926 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1927 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1928 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1930 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1932 if (nIndexAvail != 0) /* index == 0 indicates separator */
1934 /* remove from 'available buttons' list */
1935 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1936 if (nIndexAvail == count-1)
1937 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1939 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1943 PCUSTOMBUTTON btnNew;
1945 /* duplicate 'separator' button */
1946 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1947 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1951 /* insert into 'toolbar button' list */
1952 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1953 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1955 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1957 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1961 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1963 PCUSTOMBUTTON btnInfo;
1964 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1966 TRACE("Remove: index %d\n", index);
1968 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
1970 /* send TBN_QUERYDELETE notification */
1971 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
1975 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
1976 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
1978 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1980 /* insert into 'available button' list */
1981 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
1982 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
1986 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1990 /* drag list notification function for toolbar buttons list box */
1991 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1993 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1994 switch (pDLI->uNotification)
1998 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1999 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2000 /* no dragging for last item (separator) */
2001 if (nCurrentItem >= (nCount - 1)) return FALSE;
2006 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2007 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2008 /* no dragging past last item (separator) */
2009 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2011 DrawInsert(hwnd, hwndList, nCurrentItem);
2012 /* FIXME: native uses "move button" cursor */
2013 return DL_COPYCURSOR;
2016 /* not over toolbar buttons list */
2017 if (nCurrentItem < 0)
2019 POINT ptWindow = pDLI->ptCursor;
2020 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2021 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2022 /* over available buttons list? */
2023 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2024 /* FIXME: native uses "move button" cursor */
2025 return DL_COPYCURSOR;
2027 /* clear drag arrow */
2028 DrawInsert(hwnd, hwndList, -1);
2029 return DL_STOPCURSOR;
2033 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2034 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2035 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2036 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2038 /* clear drag arrow */
2039 DrawInsert(hwnd, hwndList, -1);
2041 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2043 /* not over toolbar buttons list */
2046 POINT ptWindow = pDLI->ptCursor;
2047 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2048 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2049 /* over available buttons list? */
2050 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2051 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2056 /* Clear drag arrow */
2057 DrawInsert(hwnd, hwndList, -1);
2064 /* drag list notification function for available buttons list box */
2065 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2067 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2068 switch (pDLI->uNotification)
2074 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2075 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2076 /* no dragging past last item (separator) */
2077 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2079 DrawInsert(hwnd, hwndList, nCurrentItem);
2080 /* FIXME: native uses "move button" cursor */
2081 return DL_COPYCURSOR;
2084 /* not over toolbar buttons list */
2085 if (nCurrentItem < 0)
2087 POINT ptWindow = pDLI->ptCursor;
2088 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2089 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2090 /* over available buttons list? */
2091 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2092 /* FIXME: native uses "move button" cursor */
2093 return DL_COPYCURSOR;
2095 /* clear drag arrow */
2096 DrawInsert(hwnd, hwndList, -1);
2097 return DL_STOPCURSOR;
2101 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2102 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2103 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2104 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2106 /* clear drag arrow */
2107 DrawInsert(hwnd, hwndList, -1);
2109 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2113 /* Clear drag arrow */
2114 DrawInsert(hwnd, hwndList, -1);
2120 extern UINT uDragListMessage;
2122 /***********************************************************************
2123 * TOOLBAR_CustomizeDialogProc
2124 * This function implements the toolbar customization dialog.
2126 static INT_PTR CALLBACK
2127 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2129 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2130 PCUSTOMBUTTON btnInfo;
2132 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2137 custInfo = (PCUSTDLG_INFO)lParam;
2138 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2146 infoPtr = custInfo->tbInfo;
2148 /* send TBN_QUERYINSERT notification */
2149 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2151 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2154 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2155 /* FIXME: this hack won't work on 64-bit - we need to declare a structure for this */
2156 nmtb.iItem = (int)hwnd;
2157 /* Send TBN_INITCUSTOMIZE notification */
2158 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2161 TRACE("TBNRF_HIDEHELP requested\n");
2162 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2165 /* add items to 'toolbar buttons' list and check if removable */
2166 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2168 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2169 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2170 btnInfo->btn.fsStyle = BTNS_SEP;
2171 btnInfo->bVirtual = FALSE;
2172 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2174 /* send TBN_QUERYDELETE notification */
2175 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2177 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2178 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2181 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2183 /* insert separator button into 'available buttons' list */
2184 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2185 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2186 btnInfo->btn.fsStyle = BTNS_SEP;
2187 btnInfo->bVirtual = FALSE;
2188 btnInfo->bRemovable = TRUE;
2189 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2190 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2191 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2193 /* insert all buttons into dsa */
2196 /* send TBN_GETBUTTONINFO notification */
2199 nmtb.pszText = Buffer;
2202 /* Clear previous button's text */
2203 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2205 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2208 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2209 nmtb.tbButton.fsStyle, i,
2210 nmtb.tbButton.idCommand,
2211 nmtb.tbButton.iString,
2212 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2215 /* insert button into the apropriate list */
2216 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2219 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2220 btnInfo->bVirtual = FALSE;
2221 btnInfo->bRemovable = TRUE;
2225 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2226 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2229 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2230 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2232 if (lstrlenW(nmtb.pszText))
2233 lstrcpyW(btnInfo->text, nmtb.pszText);
2234 else if (nmtb.tbButton.iString >= 0 &&
2235 nmtb.tbButton.iString < infoPtr->nNumStrings)
2237 lstrcpyW(btnInfo->text,
2238 infoPtr->strings[nmtb.tbButton.iString]);
2243 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2246 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2248 /* select first item in the 'available' list */
2249 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2251 /* append 'virtual' separator button to the 'toolbar buttons' list */
2252 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2253 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2254 btnInfo->btn.fsStyle = BTNS_SEP;
2255 btnInfo->bVirtual = TRUE;
2256 btnInfo->bRemovable = FALSE;
2257 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2258 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2259 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2261 /* select last item in the 'toolbar' list */
2262 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2263 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2265 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2266 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2268 /* set focus and disable buttons */
2269 PostMessageW (hwnd, WM_USER, 0, 0);
2274 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2275 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2276 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2277 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2281 EndDialog(hwnd, FALSE);
2285 switch (LOWORD(wParam))
2287 case IDC_TOOLBARBTN_LBOX:
2288 if (HIWORD(wParam) == LBN_SELCHANGE)
2290 PCUSTOMBUTTON btnInfo;
2295 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2296 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2298 /* send TBN_QUERYINSERT notification */
2300 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2302 /* get list box item */
2303 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2305 if (index == (count - 1))
2307 /* last item (virtual separator) */
2308 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2309 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2311 else if (index == (count - 2))
2313 /* second last item (last non-virtual item) */
2314 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2315 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2317 else if (index == 0)
2320 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2321 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2325 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2326 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2329 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2333 case IDC_MOVEUP_BTN:
2335 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2336 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2340 case IDC_MOVEDN_BTN: /* move down */
2342 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2343 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2347 case IDC_REMOVE_BTN: /* remove button */
2349 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2351 if (LB_ERR == index)
2354 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2358 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2361 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2364 case IDOK: /* Add button */
2369 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2370 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2372 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2377 EndDialog(hwnd, FALSE);
2387 /* delete items from 'toolbar buttons' listbox*/
2388 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2389 for (i = 0; i < count; i++)
2391 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2393 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2395 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2398 /* delete items from 'available buttons' listbox*/
2399 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2400 for (i = 0; i < count; i++)
2402 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2404 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2406 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2411 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2413 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2418 COLORREF oldText = 0;
2422 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2423 if (btnInfo == NULL)
2425 FIXME("btnInfo invalid!\n");
2429 /* set colors and select objects */
2430 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2431 if (btnInfo->bVirtual)
2432 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2434 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2435 hPen = CreatePen( PS_SOLID, 1,
2436 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2437 hOldPen = SelectObject (lpdis->hDC, hPen );
2438 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2440 /* fill background rectangle */
2441 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2442 lpdis->rcItem.right, lpdis->rcItem.bottom);
2444 /* calculate button and text rectangles */
2445 CopyRect (&rcButton, &lpdis->rcItem);
2446 InflateRect (&rcButton, -1, -1);
2447 CopyRect (&rcText, &rcButton);
2448 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2449 rcText.left = rcButton.right + 2;
2451 /* draw focus rectangle */
2452 if (lpdis->itemState & ODS_FOCUS)
2453 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2456 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2457 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2459 /* draw image and text */
2460 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2461 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2462 btnInfo->btn.iBitmap));
2463 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2464 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2466 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2467 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2469 /* delete objects and reset colors */
2470 SelectObject (lpdis->hDC, hOldBrush);
2471 SelectObject (lpdis->hDC, hOldPen);
2472 SetBkColor (lpdis->hDC, oldBk);
2473 SetTextColor (lpdis->hDC, oldText);
2474 DeleteObject( hPen );
2479 case WM_MEASUREITEM:
2480 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2482 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2484 lpmis->itemHeight = 15 + 8; /* default height */
2491 if (uDragListMessage && (uMsg == uDragListMessage))
2493 if (wParam == IDC_TOOLBARBTN_LBOX)
2495 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2496 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2497 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2500 else if (wParam == IDC_AVAILBTN_LBOX)
2502 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2503 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2504 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2513 /***********************************************************************
2514 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2518 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2521 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2522 INT nIndex = 0, nButtons, nCount;
2526 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2530 if (lpAddBmp->hInst == HINST_COMMCTRL)
2532 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2534 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2536 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2541 TRACE ("adding %d internal bitmaps!\n", nButtons);
2543 /* Windows resize all the buttons to the size of a newly added standard image */
2544 if (lpAddBmp->nID & 1)
2547 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2548 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2550 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2551 MAKELPARAM((WORD)24, (WORD)24));
2552 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2553 MAKELPARAM((WORD)31, (WORD)30));
2558 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2559 MAKELPARAM((WORD)16, (WORD)16));
2560 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2561 MAKELPARAM((WORD)22, (WORD)22));
2564 TOOLBAR_CalcToolbar (hwnd);
2568 nButtons = (INT)wParam;
2572 TRACE ("adding %d bitmaps!\n", nButtons);
2575 if (!infoPtr->cimlDef) {
2576 /* create new default image list */
2577 TRACE ("creating default image list!\n");
2579 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2580 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2581 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2582 infoPtr->himlInt = himlDef;
2585 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2589 WARN("No default image list available\n");
2593 nCount = ImageList_GetImageCount(himlDef);
2595 /* Add bitmaps to the default image list */
2596 if (lpAddBmp->hInst == NULL)
2599 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2600 HDC hdcImage, hdcBitmap;
2602 /* copy the bitmap before adding it so that the user's bitmap
2603 * doesn't get modified.
2605 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2607 hdcImage = CreateCompatibleDC(0);
2608 hdcBitmap = CreateCompatibleDC(0);
2610 /* create new bitmap */
2611 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2612 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2613 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2615 /* Copy the user's image */
2616 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2617 hdcBitmap, 0, 0, SRCCOPY);
2619 SelectObject (hdcImage, hOldBitmapLoad);
2620 SelectObject (hdcBitmap, hOldBitmapBitmap);
2621 DeleteDC (hdcImage);
2622 DeleteDC (hdcBitmap);
2624 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2625 DeleteObject (hbmLoad);
2627 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2629 /* Add system bitmaps */
2630 switch (lpAddBmp->nID)
2632 case IDB_STD_SMALL_COLOR:
2633 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2634 MAKEINTRESOURCEW(IDB_STD_SMALL));
2635 nIndex = ImageList_AddMasked (himlDef,
2636 hbmLoad, comctl32_color.clrBtnFace);
2637 DeleteObject (hbmLoad);
2640 case IDB_STD_LARGE_COLOR:
2641 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2642 MAKEINTRESOURCEW(IDB_STD_LARGE));
2643 nIndex = ImageList_AddMasked (himlDef,
2644 hbmLoad, comctl32_color.clrBtnFace);
2645 DeleteObject (hbmLoad);
2648 case IDB_VIEW_SMALL_COLOR:
2649 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2650 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2651 nIndex = ImageList_AddMasked (himlDef,
2652 hbmLoad, comctl32_color.clrBtnFace);
2653 DeleteObject (hbmLoad);
2656 case IDB_VIEW_LARGE_COLOR:
2657 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2658 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2659 nIndex = ImageList_AddMasked (himlDef,
2660 hbmLoad, comctl32_color.clrBtnFace);
2661 DeleteObject (hbmLoad);
2664 case IDB_HIST_SMALL_COLOR:
2665 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2666 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2667 nIndex = ImageList_AddMasked (himlDef,
2668 hbmLoad, comctl32_color.clrBtnFace);
2669 DeleteObject (hbmLoad);
2672 case IDB_HIST_LARGE_COLOR:
2673 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2674 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2675 nIndex = ImageList_AddMasked (himlDef,
2676 hbmLoad, comctl32_color.clrBtnFace);
2677 DeleteObject (hbmLoad);
2681 nIndex = ImageList_GetImageCount (himlDef);
2682 ERR ("invalid imagelist!\n");
2688 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2689 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2690 DeleteObject (hbmLoad);
2693 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2695 if (infoPtr->nNumBitmapInfos == 0)
2697 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2701 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2702 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2703 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos * sizeof(TBITMAP_INFO));
2706 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2707 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2708 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2710 infoPtr->nNumBitmapInfos++;
2711 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2715 INT imagecount = ImageList_GetImageCount(himlDef);
2717 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2719 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2720 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2721 infoPtr->nNumBitmaps+nButtons,imagecount);
2723 infoPtr->nNumBitmaps = imagecount;
2726 infoPtr->nNumBitmaps += nButtons;
2729 InvalidateRect(hwnd, NULL, TRUE);
2736 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2739 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2740 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2742 TRACE("adding %d buttons!\n", wParam);
2744 nAddButtons = (UINT)wParam;
2745 nOldButtons = infoPtr->nNumButtons;
2746 nNewButtons = nOldButtons + nAddButtons;
2748 if (infoPtr->nNumButtons == 0) {
2750 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2753 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2755 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2756 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2757 nOldButtons * sizeof(TBUTTON_INFO));
2761 infoPtr->nNumButtons = nNewButtons;
2763 /* insert new button data */
2764 for (nCount = 0; nCount < nAddButtons; nCount++) {
2765 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2766 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2767 btnPtr->idCommand = lpTbb[nCount].idCommand;
2768 btnPtr->fsState = lpTbb[nCount].fsState;
2769 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2770 btnPtr->dwData = lpTbb[nCount].dwData;
2771 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2772 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2774 btnPtr->iString = lpTbb[nCount].iString;
2775 btnPtr->bHot = FALSE;
2777 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2780 ZeroMemory (&ti, sizeof(ti));
2781 ti.cbSize = sizeof(ti);
2783 ti.uId = btnPtr->idCommand;
2785 ti.lpszText = LPSTR_TEXTCALLBACKW;
2787 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2792 TOOLBAR_CalcToolbar (hwnd);
2793 TOOLBAR_AutoSize (hwnd);
2795 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2797 InvalidateRect(hwnd, NULL, TRUE);
2804 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2806 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2807 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2808 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2810 TRACE("adding %d buttons!\n", wParam);
2812 nAddButtons = (UINT)wParam;
2813 nOldButtons = infoPtr->nNumButtons;
2814 nNewButtons = nOldButtons + nAddButtons;
2816 if (infoPtr->nNumButtons == 0) {
2818 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2821 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2823 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2824 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2825 nOldButtons * sizeof(TBUTTON_INFO));
2829 infoPtr->nNumButtons = nNewButtons;
2831 /* insert new button data */
2832 for (nCount = 0; nCount < nAddButtons; nCount++) {
2833 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2834 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2835 btnPtr->idCommand = lpTbb[nCount].idCommand;
2836 btnPtr->fsState = lpTbb[nCount].fsState;
2837 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2838 btnPtr->dwData = lpTbb[nCount].dwData;
2839 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2840 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2842 btnPtr->iString = lpTbb[nCount].iString;
2843 btnPtr->bHot = FALSE;
2845 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2848 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2849 ti.cbSize = sizeof (TTTOOLINFOW);
2851 ti.uId = btnPtr->idCommand;
2853 ti.lpszText = LPSTR_TEXTCALLBACKW;
2856 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2861 TOOLBAR_CalcToolbar (hwnd);
2862 TOOLBAR_AutoSize (hwnd);
2864 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2866 InvalidateRect(hwnd, NULL, TRUE);
2873 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2878 if ((wParam) && (HIWORD(lParam) == 0)) {
2881 TRACE("adding string from resource!\n");
2883 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2885 TRACE("len=%d \"%s\"\n", len, szString);
2886 nIndex = infoPtr->nNumStrings;
2887 if (infoPtr->nNumStrings == 0) {
2889 Alloc (sizeof(LPWSTR));
2892 LPWSTR *oldStrings = infoPtr->strings;
2894 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2895 memcpy (&infoPtr->strings[0], &oldStrings[0],
2896 sizeof(LPWSTR) * infoPtr->nNumStrings);
2900 /*Alloc zeros out the allocated memory*/
2901 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2902 infoPtr->nNumStrings++;
2905 LPSTR p = (LPSTR)lParam;
2910 TRACE("adding string(s) from array!\n");
2912 nIndex = infoPtr->nNumStrings;
2915 TRACE("len=%d \"%s\"\n", len, p);
2917 if (infoPtr->nNumStrings == 0) {
2919 Alloc (sizeof(LPWSTR));
2922 LPWSTR *oldStrings = infoPtr->strings;
2924 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2925 memcpy (&infoPtr->strings[0], &oldStrings[0],
2926 sizeof(LPWSTR) * infoPtr->nNumStrings);
2930 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2931 infoPtr->nNumStrings++;
2942 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2944 #define MAX_RESOURCE_STRING_LENGTH 512
2945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2948 if ((wParam) && (HIWORD(lParam) == 0)) {
2949 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2951 TRACE("adding string from resource!\n");
2953 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2954 szString, MAX_RESOURCE_STRING_LENGTH);
2956 TRACE("len=%d %s\n", len, debugstr_w(szString));
2957 TRACE("First char: 0x%x\n", *szString);
2958 if (szString[0] == L'|')
2960 PWSTR p = szString + 1;
2962 nIndex = infoPtr->nNumStrings;
2963 while (*p != L'|' && *p != L'\0') {
2966 if (infoPtr->nNumStrings == 0) {
2967 infoPtr->strings = Alloc (sizeof(LPWSTR));
2971 LPWSTR *oldStrings = infoPtr->strings;
2972 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2973 memcpy(&infoPtr->strings[0], &oldStrings[0],
2974 sizeof(LPWSTR) * infoPtr->nNumStrings);
2978 np=strchrW (p, '|');
2986 TRACE("len=%d %s\n", len, debugstr_w(p));
2987 infoPtr->strings[infoPtr->nNumStrings] =
2988 Alloc (sizeof(WCHAR)*(len+1));
2989 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2990 infoPtr->nNumStrings++;
2997 nIndex = infoPtr->nNumStrings;
2998 if (infoPtr->nNumStrings == 0) {
3000 Alloc (sizeof(LPWSTR));
3003 LPWSTR *oldStrings = infoPtr->strings;
3005 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3006 memcpy (&infoPtr->strings[0], &oldStrings[0],
3007 sizeof(LPWSTR) * infoPtr->nNumStrings);
3011 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3012 infoPtr->nNumStrings++;
3016 LPWSTR p = (LPWSTR)lParam;
3021 TRACE("adding string(s) from array!\n");
3022 nIndex = infoPtr->nNumStrings;
3026 TRACE("len=%d %s\n", len, debugstr_w(p));
3027 if (infoPtr->nNumStrings == 0) {
3029 Alloc (sizeof(LPWSTR));
3032 LPWSTR *oldStrings = infoPtr->strings;
3034 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3035 memcpy (&infoPtr->strings[0], &oldStrings[0],
3036 sizeof(LPWSTR) * infoPtr->nNumStrings);
3040 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3041 infoPtr->nNumStrings++;
3052 TOOLBAR_AutoSize (HWND hwnd)
3054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3060 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3062 parent = GetParent (hwnd);
3064 if (!parent || !infoPtr->bDoRedraw)
3067 GetClientRect(parent, &parent_rect);
3069 x = parent_rect.left;
3070 y = parent_rect.top;
3072 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3074 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3075 cx = parent_rect.right - parent_rect.left;
3077 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3079 TOOLBAR_CalcToolbar(hwnd);
3080 InvalidateRect( hwnd, NULL, TRUE );
3083 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3086 UINT uPosFlags = SWP_NOZORDER;
3088 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3090 GetWindowRect(hwnd, &window_rect);
3091 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3092 y = window_rect.top;
3094 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3096 GetWindowRect(hwnd, &window_rect);
3097 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3100 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3101 uPosFlags |= SWP_NOMOVE;
3103 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3104 cy += GetSystemMetrics(SM_CYEDGE);
3106 if (infoPtr->dwStyle & WS_BORDER)
3108 x = y = 1; /* FIXME: this looks wrong */
3109 cy += GetSystemMetrics(SM_CYEDGE);
3110 cx += GetSystemMetrics(SM_CXEDGE);
3113 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3121 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3123 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 return infoPtr->nNumButtons;
3130 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3134 infoPtr->dwStructSize = (DWORD)wParam;
3141 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3144 TBUTTON_INFO *btnPtr;
3147 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3149 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3153 btnPtr = &infoPtr->buttons[nIndex];
3154 btnPtr->iBitmap = LOWORD(lParam);
3156 /* we HAVE to erase the background, the new bitmap could be */
3158 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3165 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3168 TBUTTON_INFO *btnPtr;
3171 BOOL bChecked = FALSE;
3173 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3175 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3180 btnPtr = &infoPtr->buttons[nIndex];
3182 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3184 if (LOWORD(lParam) == FALSE)
3185 btnPtr->fsState &= ~TBSTATE_CHECKED;
3187 if (btnPtr->fsStyle & BTNS_GROUP) {
3189 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3190 if (nOldIndex == nIndex)
3192 if (nOldIndex != -1)
3193 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3195 btnPtr->fsState |= TBSTATE_CHECKED;
3198 if( bChecked != LOWORD(lParam) )
3200 if (nOldIndex != -1)
3201 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3202 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3205 /* FIXME: Send a WM_NOTIFY?? */
3212 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3216 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3221 TOOLBAR_Customize (HWND hwnd)
3223 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3224 CUSTDLG_INFO custInfo;
3230 custInfo.tbInfo = infoPtr;
3231 custInfo.tbHwnd = hwnd;
3233 /* send TBN_BEGINADJUST notification */
3234 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3236 if (!(hRes = FindResourceW (COMCTL32_hModule,
3237 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3238 (LPWSTR)RT_DIALOG)))
3241 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3244 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3245 (LPDLGTEMPLATEW)template,
3247 TOOLBAR_CustomizeDialogProc,
3250 /* send TBN_ENDADJUST notification */
3251 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3258 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3260 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3261 INT nIndex = (INT)wParam;
3263 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3265 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3268 memset(&nmtb, 0, sizeof(nmtb));
3269 nmtb.iItem = btnPtr->idCommand;
3270 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3271 nmtb.tbButton.idCommand = btnPtr->idCommand;
3272 nmtb.tbButton.fsState = btnPtr->fsState;
3273 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3274 nmtb.tbButton.dwData = btnPtr->dwData;
3275 nmtb.tbButton.iString = btnPtr->iString;
3276 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3278 if ((infoPtr->hwndToolTip) &&
3279 !(btnPtr->fsStyle & BTNS_SEP)) {
3282 ZeroMemory (&ti, sizeof(ti));
3283 ti.cbSize = sizeof(ti);
3285 ti.uId = infoPtr->buttons[nIndex].idCommand;
3287 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3290 if (infoPtr->nNumButtons == 1) {
3291 TRACE(" simple delete!\n");
3292 Free (infoPtr->buttons);
3293 infoPtr->buttons = NULL;
3294 infoPtr->nNumButtons = 0;
3297 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3298 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3300 infoPtr->nNumButtons--;
3301 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3303 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3304 nIndex * sizeof(TBUTTON_INFO));
3307 if (nIndex < infoPtr->nNumButtons) {
3308 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3309 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3315 TOOLBAR_CalcToolbar (hwnd);
3317 InvalidateRect (hwnd, NULL, TRUE);
3324 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3326 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3327 TBUTTON_INFO *btnPtr;
3331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3333 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3338 btnPtr = &infoPtr->buttons[nIndex];
3340 bState = btnPtr->fsState & TBSTATE_ENABLED;
3342 /* update the toolbar button state */
3343 if(LOWORD(lParam) == FALSE) {
3344 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3346 btnPtr->fsState |= TBSTATE_ENABLED;
3349 /* redraw the button only if the state of the button changed */
3350 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3351 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3357 static inline LRESULT
3358 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 return infoPtr->bAnchor;
3367 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3372 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3376 return infoPtr->buttons[nIndex].iBitmap;
3380 static inline LRESULT
3381 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3383 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3388 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3391 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3392 INT nIndex = (INT)wParam;
3393 TBUTTON_INFO *btnPtr;
3398 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3401 btnPtr = &infoPtr->buttons[nIndex];
3402 lpTbb->iBitmap = btnPtr->iBitmap;
3403 lpTbb->idCommand = btnPtr->idCommand;
3404 lpTbb->fsState = btnPtr->fsState;
3405 lpTbb->fsStyle = btnPtr->fsStyle;
3406 lpTbb->bReserved[0] = 0;
3407 lpTbb->bReserved[1] = 0;
3408 lpTbb->dwData = btnPtr->dwData;
3409 lpTbb->iString = btnPtr->iString;
3416 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3419 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3420 TBUTTON_INFO *btnPtr;
3423 if (lpTbInfo == NULL)
3425 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3428 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3429 lpTbInfo->dwMask & 0x80000000);
3433 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3435 if (lpTbInfo->dwMask & TBIF_COMMAND)
3436 lpTbInfo->idCommand = btnPtr->idCommand;
3437 if (lpTbInfo->dwMask & TBIF_IMAGE)
3438 lpTbInfo->iImage = btnPtr->iBitmap;
3439 if (lpTbInfo->dwMask & TBIF_LPARAM)
3440 lpTbInfo->lParam = btnPtr->dwData;
3441 if (lpTbInfo->dwMask & TBIF_SIZE)
3442 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3443 if (lpTbInfo->dwMask & TBIF_STATE)
3444 lpTbInfo->fsState = btnPtr->fsState;
3445 if (lpTbInfo->dwMask & TBIF_STYLE)
3446 lpTbInfo->fsStyle = btnPtr->fsStyle;
3447 if (lpTbInfo->dwMask & TBIF_TEXT) {
3448 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3449 can't use TOOLBAR_GetText here */
3451 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3452 lpText = (LPWSTR)btnPtr->iString;
3453 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3455 lpTbInfo->pszText[0] = '\0';
3462 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3465 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3466 TBUTTON_INFO *btnPtr;
3469 if (lpTbInfo == NULL)
3471 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3475 lpTbInfo->dwMask & 0x80000000);
3479 btnPtr = &infoPtr->buttons[nIndex];
3484 if (lpTbInfo->dwMask & TBIF_COMMAND)
3485 lpTbInfo->idCommand = btnPtr->idCommand;
3486 if (lpTbInfo->dwMask & TBIF_IMAGE)
3487 lpTbInfo->iImage = btnPtr->iBitmap;
3488 if (lpTbInfo->dwMask & TBIF_LPARAM)
3489 lpTbInfo->lParam = btnPtr->dwData;
3490 if (lpTbInfo->dwMask & TBIF_SIZE)
3491 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3492 if (lpTbInfo->dwMask & TBIF_STATE)
3493 lpTbInfo->fsState = btnPtr->fsState;
3494 if (lpTbInfo->dwMask & TBIF_STYLE)
3495 lpTbInfo->fsStyle = btnPtr->fsStyle;
3496 if (lpTbInfo->dwMask & TBIF_TEXT) {
3497 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3498 can't use TOOLBAR_GetText here */
3500 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3501 lpText = (LPWSTR)btnPtr->iString;
3502 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3504 lpTbInfo->pszText[0] = '\0';
3512 TOOLBAR_GetButtonSize (HWND hwnd)
3514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3516 if (infoPtr->nNumButtons > 0)
3517 return MAKELONG((WORD)infoPtr->nButtonWidth,
3518 (WORD)infoPtr->nButtonHeight);
3520 return MAKELONG(23,22);
3525 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3534 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3538 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3540 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3541 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3546 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3553 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3557 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3561 ret = strlenW (lpText);
3564 strcpyW ((LPWSTR)lParam, lpText);
3572 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3574 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3575 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3576 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3580 inline static LRESULT
3581 TOOLBAR_GetExtendedStyle (HWND hwnd)
3583 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3587 return infoPtr->dwExStyle;
3592 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3594 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3595 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3596 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3601 TOOLBAR_GetHotItem (HWND hwnd)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3605 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3608 if (infoPtr->nHotItem < 0)
3611 return (LRESULT)infoPtr->nHotItem;
3616 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3618 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3619 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3620 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3625 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3627 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3628 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3630 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3632 *lptbim = infoPtr->tbim;
3639 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3643 TRACE("hwnd = %p\n", hwnd);
3645 return (LRESULT)infoPtr->clrInsertMark;
3650 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3653 TBUTTON_INFO *btnPtr;
3657 nIndex = (INT)wParam;
3658 btnPtr = &infoPtr->buttons[nIndex];
3659 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3661 lpRect = (LPRECT)lParam;
3664 if (btnPtr->fsState & TBSTATE_HIDDEN)
3667 lpRect->left = btnPtr->rect.left;
3668 lpRect->right = btnPtr->rect.right;
3669 lpRect->bottom = btnPtr->rect.bottom;
3670 lpRect->top = btnPtr->rect.top;
3677 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3680 LPSIZE lpSize = (LPSIZE)lParam;
3685 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3686 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3688 TRACE("maximum size %ld x %ld\n",
3689 infoPtr->rcBound.right - infoPtr->rcBound.left,
3690 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3696 /* << TOOLBAR_GetObject >> */
3700 TOOLBAR_GetPadding (HWND hwnd)
3702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3705 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3706 return (LRESULT) oldPad;
3711 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3714 TBUTTON_INFO *btnPtr;
3718 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3719 btnPtr = &infoPtr->buttons[nIndex];
3720 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3722 lpRect = (LPRECT)lParam;
3726 lpRect->left = btnPtr->rect.left;
3727 lpRect->right = btnPtr->rect.right;
3728 lpRect->bottom = btnPtr->rect.bottom;
3729 lpRect->top = btnPtr->rect.top;
3736 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3740 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3741 return infoPtr->nRows;
3748 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3753 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3757 return infoPtr->buttons[nIndex].fsState;
3762 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3764 return GetWindowLongW(hwnd, GWL_STYLE);
3769 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3773 return infoPtr->nMaxTextRows;
3778 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3780 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3782 return (LRESULT)infoPtr->hwndToolTip;
3787 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3791 TRACE("%s hwnd=%p\n",
3792 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3794 return infoPtr->bUnicode;
3798 inline static LRESULT
3799 TOOLBAR_GetVersion (HWND hwnd)
3801 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3802 return infoPtr->iVersion;
3807 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3810 TBUTTON_INFO *btnPtr;
3815 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3819 btnPtr = &infoPtr->buttons[nIndex];
3820 if (LOWORD(lParam) == FALSE)
3821 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3823 btnPtr->fsState |= TBSTATE_HIDDEN;
3825 TOOLBAR_CalcToolbar (hwnd);
3827 InvalidateRect (hwnd, NULL, TRUE);
3833 inline static LRESULT
3834 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3836 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3841 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3844 TBUTTON_INFO *btnPtr;
3848 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3852 btnPtr = &infoPtr->buttons[nIndex];
3853 oldState = btnPtr->fsState;
3854 if (LOWORD(lParam) == FALSE)
3855 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3857 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3859 if(oldState != btnPtr->fsState)
3860 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3867 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3869 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3870 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3871 INT nIndex = (INT)wParam;
3872 TBUTTON_INFO *oldButtons;
3877 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3880 /* EPP: this seems to be an undocumented call (from my IE4)
3881 * I assume in that case that:
3882 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3883 * - index of insertion is at the end of existing buttons
3884 * I only see this happen with nIndex == -1, but it could have a special
3885 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3887 nIndex = infoPtr->nNumButtons;
3889 } else if (nIndex < 0)
3892 /* If the string passed is not an index, assume address of string
3893 and do our own AddString */
3894 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3898 TRACE("string %s passed instead of index, adding string\n",
3899 debugstr_a((LPSTR)lpTbb->iString));
3900 len = strlen((LPSTR)lpTbb->iString) + 2;
3902 strcpy(ptr, (LPSTR)lpTbb->iString);
3903 ptr[len - 1] = 0; /* ended by two '\0' */
3904 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3908 TRACE("inserting button index=%d\n", nIndex);
3909 if (nIndex > infoPtr->nNumButtons) {
3910 nIndex = infoPtr->nNumButtons;
3911 TRACE("adjust index=%d\n", nIndex);
3914 oldButtons = infoPtr->buttons;
3915 infoPtr->nNumButtons++;
3916 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3917 /* pre insert copy */
3919 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3920 nIndex * sizeof(TBUTTON_INFO));
3923 /* insert new button */
3924 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3925 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3926 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3927 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3928 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3929 /* if passed string and not index, then add string */
3930 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3931 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3934 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3936 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3939 ZeroMemory (&ti, sizeof(ti));
3940 ti.cbSize = sizeof (ti);
3942 ti.uId = lpTbb->idCommand;
3944 ti.lpszText = LPSTR_TEXTCALLBACKW;
3946 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3950 /* post insert copy */
3951 if (nIndex < infoPtr->nNumButtons - 1) {
3952 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3953 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3958 TOOLBAR_CalcToolbar (hwnd);
3959 TOOLBAR_AutoSize (hwnd);
3961 InvalidateRect (hwnd, NULL, TRUE);
3968 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3971 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3972 INT nIndex = (INT)wParam;
3973 TBUTTON_INFO *oldButtons;
3978 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3981 /* EPP: this seems to be an undocumented call (from my IE4)
3982 * I assume in that case that:
3983 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3984 * - index of insertion is at the end of existing buttons
3985 * I only see this happen with nIndex == -1, but it could have a special
3986 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3988 nIndex = infoPtr->nNumButtons;
3990 } else if (nIndex < 0)
3993 /* If the string passed is not an index, assume address of string
3994 and do our own AddString */
3995 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3999 TRACE("string %s passed instead of index, adding string\n",
4000 debugstr_w((LPWSTR)lpTbb->iString));
4001 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4002 ptr = Alloc(len*sizeof(WCHAR));
4003 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4004 ptr[len - 1] = 0; /* ended by two '\0' */
4005 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4009 TRACE("inserting button index=%d\n", nIndex);
4010 if (nIndex > infoPtr->nNumButtons) {
4011 nIndex = infoPtr->nNumButtons;
4012 TRACE("adjust index=%d\n", nIndex);
4015 oldButtons = infoPtr->buttons;
4016 infoPtr->nNumButtons++;
4017 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4018 /* pre insert copy */
4020 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4021 nIndex * sizeof(TBUTTON_INFO));
4024 /* insert new button */
4025 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4026 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4027 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4028 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4029 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4030 /* if passed string and not index, then add string */
4031 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4032 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4035 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4037 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4040 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4041 ti.cbSize = sizeof (TTTOOLINFOW);
4043 ti.uId = lpTbb->idCommand;
4045 ti.lpszText = LPSTR_TEXTCALLBACKW;
4047 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4051 /* post insert copy */
4052 if (nIndex < infoPtr->nNumButtons - 1) {
4053 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4054 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4059 TOOLBAR_CalcToolbar (hwnd);
4060 TOOLBAR_AutoSize (hwnd);
4062 InvalidateRect (hwnd, NULL, TRUE);
4068 /* << TOOLBAR_InsertMarkHitTest >> */
4072 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4077 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4081 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4086 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4091 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4095 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4100 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4105 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4109 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4114 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4116 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4119 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4123 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4128 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4130 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4133 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4137 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4142 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4144 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4147 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4151 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4156 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4159 tbab.hInst = (HINSTANCE)lParam;
4160 tbab.nID = (UINT_PTR)wParam;
4162 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4164 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4169 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4172 WCHAR wAccel = (WCHAR)wParam;
4173 UINT* pIDButton = (UINT*)lParam;
4174 WCHAR wszAccel[] = {'&',wAccel,0};
4177 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4178 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4180 for (i = 0; i < infoPtr->nNumButtons; i++)
4182 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4183 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4184 !(btnPtr->fsState & TBSTATE_HIDDEN))
4186 int iLen = strlenW(wszAccel);
4187 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4194 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4199 if (!strncmpiW(lpszStr, wszAccel, iLen))
4201 *pIDButton = btnPtr->idCommand;
4213 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4218 TBUTTON_INFO *btnPtr;
4220 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4222 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4226 btnPtr = &infoPtr->buttons[nIndex];
4227 oldState = btnPtr->fsState;
4230 btnPtr->fsState |= TBSTATE_MARKED;
4232 btnPtr->fsState &= ~TBSTATE_MARKED;
4234 if(oldState != btnPtr->fsState)
4235 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4241 /* fixes up an index of a button affected by a move */
4242 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4246 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4248 else if (*pIndex == nIndex)
4249 *pIndex = nMoveIndex;
4253 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4255 else if (*pIndex == nIndex)
4256 *pIndex = nMoveIndex;
4262 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4267 INT nMoveIndex = (INT)lParam;
4268 TBUTTON_INFO button;
4270 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4272 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4273 if ((nIndex == -1) || (nMoveIndex < 0))
4276 if (nMoveIndex > infoPtr->nNumButtons - 1)
4277 nMoveIndex = infoPtr->nNumButtons - 1;
4279 button = infoPtr->buttons[nIndex];
4281 /* move button right */
4282 if (nIndex < nMoveIndex)
4284 nCount = nMoveIndex - nIndex;
4285 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4286 infoPtr->buttons[nMoveIndex] = button;
4288 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4289 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4290 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4291 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4293 else if (nIndex > nMoveIndex) /* move button left */
4295 nCount = nIndex - nMoveIndex;
4296 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4297 infoPtr->buttons[nMoveIndex] = button;
4299 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4300 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4301 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4302 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4305 TOOLBAR_CalcToolbar(hwnd);
4306 TOOLBAR_AutoSize(hwnd);
4307 InvalidateRect(hwnd, NULL, TRUE);
4314 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4317 TBUTTON_INFO *btnPtr;
4321 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4325 btnPtr = &infoPtr->buttons[nIndex];
4326 oldState = btnPtr->fsState;
4327 if (LOWORD(lParam) == FALSE)
4328 btnPtr->fsState &= ~TBSTATE_PRESSED;
4330 btnPtr->fsState |= TBSTATE_PRESSED;
4332 if(oldState != btnPtr->fsState)
4333 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4338 /* FIXME: there might still be some confusion her between number of buttons
4339 * and number of bitmaps */
4341 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4343 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4344 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4346 HBITMAP hbmLoad = NULL;
4347 int i = 0, nOldButtons = 0, pos = 0;
4348 int nOldBitmaps, nNewBitmaps = 0;
4349 HIMAGELIST himlDef = 0;
4351 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4352 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4353 lpReplace->nButtons);
4355 if (lpReplace->hInstOld == HINST_COMMCTRL)
4357 FIXME("changing standard bitmaps not implemented\n");
4360 else if (lpReplace->hInstOld != 0)
4361 FIXME("resources not in the current module not implemented\n");
4363 if (lpReplace->hInstNew)
4365 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4370 hBitmap = (HBITMAP) lpReplace->nIDNew;
4373 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4374 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4375 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4376 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4377 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4379 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4380 nOldButtons = tbi->nButtons;
4381 tbi->nButtons = lpReplace->nButtons;
4382 tbi->hInst = lpReplace->hInstNew;
4383 tbi->nID = lpReplace->nIDNew;
4384 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4387 pos += tbi->nButtons;
4390 if (nOldButtons == 0)
4392 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4394 DeleteObject (hbmLoad);
4398 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4399 nOldBitmaps = ImageList_GetImageCount(himlDef);
4401 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4403 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4404 ImageList_Remove(himlDef, i);
4409 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4410 HDC hdcImage, hdcBitmap;
4412 /* copy the bitmap before adding it so that the user's bitmap
4413 * doesn't get modified.
4415 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4417 hdcImage = CreateCompatibleDC(0);
4418 hdcBitmap = CreateCompatibleDC(0);
4420 /* create new bitmap */
4421 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4422 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4423 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4425 /* Copy the user's image */
4426 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4427 hdcBitmap, 0, 0, SRCCOPY);
4429 SelectObject (hdcImage, hOldBitmapLoad);
4430 SelectObject (hdcBitmap, hOldBitmapBitmap);
4431 DeleteDC (hdcImage);
4432 DeleteDC (hdcBitmap);
4434 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4435 nNewBitmaps = ImageList_GetImageCount(himlDef);
4436 DeleteObject (hbmLoad);
4439 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4441 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4442 pos, nOldBitmaps, nNewBitmaps);
4444 InvalidateRect(hwnd, NULL, TRUE);
4447 DeleteObject (hbmLoad);
4452 /* helper for TOOLBAR_SaveRestoreW */
4454 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4456 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4457 debugstr_w(lpSave->pszValueName));
4463 /* helper for TOOLBAR_Restore */
4465 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4470 ZeroMemory(&ti, sizeof(ti));
4471 ti.cbSize = sizeof(ti);
4472 ti.hwnd = infoPtr->hwndSelf;
4474 for (i = 0; i < infoPtr->nNumButtons; i++)
4476 if ((infoPtr->hwndToolTip) &&
4477 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4479 ti.uId = infoPtr->buttons[i].idCommand;
4480 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4484 Free(infoPtr->buttons);
4485 infoPtr->buttons = NULL;
4486 infoPtr->nNumButtons = 0;
4490 /* helper for TOOLBAR_SaveRestoreW */
4492 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4501 /* restore toolbar information */
4502 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4503 debugstr_w(lpSave->pszValueName));
4505 memset(&nmtbr, 0, sizeof(nmtbr));
4507 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4508 KEY_QUERY_VALUE, &hkey);
4510 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4512 if (!res && dwType != REG_BINARY)
4513 res = ERROR_FILE_NOT_FOUND;
4516 nmtbr.pData = Alloc(dwSize);
4517 nmtbr.cbData = (UINT)dwSize;
4518 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4521 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4522 (LPBYTE)nmtbr.pData, &dwSize);
4525 nmtbr.pCurrent = nmtbr.pData;
4527 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4528 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4530 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4534 /* remove all existing buttons as this function is designed to
4535 * restore the toolbar to a previously saved state */
4536 TOOLBAR_DeleteAllButtons(infoPtr);
4538 for (i = 0; i < nmtbr.cButtons; i++)
4541 nmtbr.tbButton.iBitmap = -1;
4542 nmtbr.tbButton.fsState = 0;
4543 nmtbr.tbButton.fsStyle = 0;
4544 nmtbr.tbButton.idCommand = 0;
4545 if (*nmtbr.pCurrent == (DWORD)-1)
4548 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4549 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4551 else if (*nmtbr.pCurrent == (DWORD)-2)
4553 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4555 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4559 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4561 /* can't contain real string as we don't know whether
4562 * the client put an ANSI or Unicode string in there */
4563 if (HIWORD(nmtbr.tbButton.iString))
4564 nmtbr.tbButton.iString = 0;
4566 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4567 (LPARAM)&nmtbr.tbButton);
4570 /* do legacy notifications */
4571 if (infoPtr->iVersion < 5)
4573 /* FIXME: send TBN_BEGINADJUST */
4574 FIXME("send TBN_GETBUTTONINFO for each button\n");
4575 /* FIXME: send TBN_ENDADJUST */
4578 /* remove all uninitialised buttons
4579 * note: loop backwards to avoid having to fixup i on a
4581 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4582 if (infoPtr->buttons[i].iBitmap == -1)
4583 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4585 /* only indicate success if at least one button survived */
4586 if (infoPtr->nNumButtons > 0) ret = TRUE;
4597 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4601 if (lpSave == NULL) return 0;
4604 return TOOLBAR_Save(infoPtr, lpSave);
4606 return TOOLBAR_Restore(infoPtr, lpSave);
4611 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4613 LPWSTR pszValueName = 0, pszSubKey = 0;
4614 TBSAVEPARAMSW SaveW;
4618 if (lpSave == NULL) return 0;
4620 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4621 pszSubKey = Alloc(len * sizeof(WCHAR));
4622 if (pszSubKey) goto exit;
4623 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4625 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4626 pszValueName = Alloc(len * sizeof(WCHAR));
4627 if (!pszValueName) goto exit;
4628 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4630 SaveW.pszValueName = pszValueName;
4631 SaveW.pszSubKey = pszSubKey;
4632 SaveW.hkr = lpSave->hkr;
4633 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4636 Free (pszValueName);
4644 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4647 BOOL bOldAnchor = infoPtr->bAnchor;
4649 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4651 infoPtr->bAnchor = (BOOL)wParam;
4653 /* Native does not remove the hot effect from an already hot button */
4655 return (LRESULT)bOldAnchor;
4660 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4662 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4663 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4665 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4668 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4670 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4673 if (infoPtr->nNumButtons > 0)
4674 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4675 infoPtr->nNumButtons,
4676 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4677 LOWORD(lParam), HIWORD(lParam));
4679 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4680 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4683 if ((himlDef == infoPtr->himlInt) &&
4684 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4686 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4687 infoPtr->nBitmapHeight);
4695 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4697 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4698 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4699 TBUTTON_INFO *btnPtr;
4705 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4708 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4709 lptbbi->dwMask & 0x80000000);
4713 btnPtr = &infoPtr->buttons[nIndex];
4714 if (lptbbi->dwMask & TBIF_COMMAND)
4715 btnPtr->idCommand = lptbbi->idCommand;
4716 if (lptbbi->dwMask & TBIF_IMAGE)
4717 btnPtr->iBitmap = lptbbi->iImage;
4718 if (lptbbi->dwMask & TBIF_LPARAM)
4719 btnPtr->dwData = lptbbi->lParam;
4720 if (lptbbi->dwMask & TBIF_SIZE)
4721 btnPtr->cx = lptbbi->cx;
4722 if (lptbbi->dwMask & TBIF_STATE)
4723 btnPtr->fsState = lptbbi->fsState;
4724 if (lptbbi->dwMask & TBIF_STYLE)
4725 btnPtr->fsStyle = lptbbi->fsStyle;
4727 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4728 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4729 /* iString is index, zero it to make Str_SetPtr succeed */
4732 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4735 /* save the button rect to see if we need to redraw the whole toolbar */
4736 oldBtnRect = btnPtr->rect;
4737 TOOLBAR_CalcToolbar(hwnd);
4739 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4740 InvalidateRect(hwnd, NULL, TRUE);
4742 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4749 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4751 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4752 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4753 TBUTTON_INFO *btnPtr;
4759 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4762 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4763 lptbbi->dwMask & 0x80000000);
4767 btnPtr = &infoPtr->buttons[nIndex];
4768 if (lptbbi->dwMask & TBIF_COMMAND)
4769 btnPtr->idCommand = lptbbi->idCommand;
4770 if (lptbbi->dwMask & TBIF_IMAGE)
4771 btnPtr->iBitmap = lptbbi->iImage;
4772 if (lptbbi->dwMask & TBIF_LPARAM)
4773 btnPtr->dwData = lptbbi->lParam;
4774 if (lptbbi->dwMask & TBIF_SIZE)
4775 btnPtr->cx = lptbbi->cx;
4776 if (lptbbi->dwMask & TBIF_STATE)
4777 btnPtr->fsState = lptbbi->fsState;
4778 if (lptbbi->dwMask & TBIF_STYLE)
4779 btnPtr->fsStyle = lptbbi->fsStyle;
4781 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4782 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4783 /* iString is index, zero it to make Str_SetPtr succeed */
4785 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4788 /* save the button rect to see if we need to redraw the whole toolbar */
4789 oldBtnRect = btnPtr->rect;
4790 TOOLBAR_CalcToolbar(hwnd);
4792 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4793 InvalidateRect(hwnd, NULL, TRUE);
4795 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4802 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4805 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4807 if ((cx < 0) || (cy < 0))
4809 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4813 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4815 /* The documentation claims you can only change the button size before
4816 * any button has been added. But this is wrong.
4817 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4818 * it to the toolbar, and it checks that the return value is nonzero - mjm
4819 * Further testing shows that we must actually perform the change too.
4822 * The documentation also does not mention that if 0 is supplied for
4823 * either size, the system changes it to the default of 24 wide and
4824 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4826 infoPtr->nButtonWidth = (cx) ? cx : 24;
4827 infoPtr->nButtonHeight = (cy) ? cy : 22;
4833 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4835 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4837 /* if setting to current values, ignore */
4838 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4839 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4840 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4841 infoPtr->cxMin, infoPtr->cxMax);
4845 /* save new values */
4846 infoPtr->cxMin = (INT)LOWORD(lParam);
4847 infoPtr->cxMax = (INT)HIWORD(lParam);
4849 /* otherwise we need to recalc the toolbar and in some cases
4850 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4851 which doesn't actually draw - GA). */
4852 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4853 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4855 TOOLBAR_CalcToolbar (hwnd);
4857 InvalidateRect (hwnd, NULL, TRUE);
4864 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4867 INT nIndex = (INT)wParam;
4869 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4872 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4874 if (infoPtr->hwndToolTip) {
4876 FIXME("change tool tip!\n");
4885 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4887 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4888 HIMAGELIST himl = (HIMAGELIST)lParam;
4889 HIMAGELIST himlTemp;
4892 if (infoPtr->iVersion >= 5)
4895 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4896 &infoPtr->cimlDis, himl, id);
4898 /* FIXME: redraw ? */
4900 return (LRESULT)himlTemp;
4905 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4910 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4912 dwTemp = infoPtr->dwDTFlags;
4913 infoPtr->dwDTFlags =
4914 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4916 return (LRESULT)dwTemp;
4919 /* This function differs a bit from what MSDN says it does:
4920 * 1. lParam contains extended style flags to OR with current style
4921 * (MSDN isn't clear on the OR bit)
4922 * 2. wParam appears to contain extended style flags to be reset
4923 * (MSDN says that this parameter is reserved)
4926 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4931 dwTemp = infoPtr->dwExStyle;
4932 infoPtr->dwExStyle &= ~wParam;
4933 infoPtr->dwExStyle |= (DWORD)lParam;
4935 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4937 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4938 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4939 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4941 TOOLBAR_CalcToolbar (hwnd);
4943 TOOLBAR_AutoSize(hwnd);
4945 InvalidateRect(hwnd, NULL, TRUE);
4947 return (LRESULT)dwTemp;
4952 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4954 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4955 HIMAGELIST himlTemp;
4956 HIMAGELIST himl = (HIMAGELIST)lParam;
4959 if (infoPtr->iVersion >= 5)
4962 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4964 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4965 &infoPtr->cimlHot, himl, id);
4967 /* FIXME: redraw ? */
4969 return (LRESULT)himlTemp;
4973 /* Makes previous hot button no longer hot, makes the specified
4974 * button hot and sends appropriate notifications. dwReason is one or
4975 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4976 * NOTE 1: this function does not validate nHit
4977 * NOTE 2: the name of this function is completely made up and
4978 * not based on any documentation from Microsoft. */
4980 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4982 if (infoPtr->nHotItem != nHit)
4984 NMTBHOTITEM nmhotitem;
4985 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4986 LRESULT no_highlight;
4988 /* Remove the effect of an old hot button if the button was
4989 drawn with the hot button effect */
4990 if(infoPtr->nHotItem >= 0)
4992 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4993 oldBtnPtr->bHot = FALSE;
4996 infoPtr->nHotItem = nHit;
4998 /* It's not a separator or in nowhere. It's a hot button. */
5000 btnPtr = &infoPtr->buttons[nHit];
5002 nmhotitem.dwFlags = dwReason;
5004 nmhotitem.idOld = oldBtnPtr->idCommand;
5006 nmhotitem.dwFlags |= HICF_ENTERING;
5008 nmhotitem.idNew = btnPtr->idCommand;
5010 nmhotitem.dwFlags |= HICF_LEAVING;
5012 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5014 /* now invalidate the old and new buttons so they will be painted,
5015 * but only if they are enabled - disabled buttons cannot become hot */
5016 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5017 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5018 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5020 btnPtr->bHot = TRUE;
5021 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5027 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5030 INT nOldHotItem = infoPtr->nHotItem;
5032 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5034 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5037 /* NOTE: an application can still remove the hot item even if anchor
5038 * highlighting is enabled */
5040 if (infoPtr->dwStyle & TBSTYLE_FLAT)
5041 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5043 if (nOldHotItem < 0)
5046 return (LRESULT)nOldHotItem;
5051 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5054 HIMAGELIST himlTemp;
5055 HIMAGELIST himl = (HIMAGELIST)lParam;
5058 if (infoPtr->iVersion >= 5)
5061 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5062 &infoPtr->cimlDef, himl, id);
5064 infoPtr->nNumBitmaps = 0;
5065 for (i = 0; i < infoPtr->cimlDef; i++)
5066 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5068 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5069 &infoPtr->nBitmapHeight))
5071 infoPtr->nBitmapWidth = 1;
5072 infoPtr->nBitmapHeight = 1;
5075 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5076 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5077 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5079 InvalidateRect(hwnd, NULL, TRUE);
5081 return (LRESULT)himlTemp;
5086 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5090 infoPtr->nIndent = (INT)wParam;
5094 /* process only on indent changing */
5095 if(infoPtr->nIndent != (INT)wParam)
5097 infoPtr->nIndent = (INT)wParam;
5098 TOOLBAR_CalcToolbar (hwnd);
5099 InvalidateRect(hwnd, NULL, FALSE);
5107 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5109 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5110 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5112 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5114 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5116 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5120 if ((lptbim->iButton == -1) ||
5121 ((lptbim->iButton < infoPtr->nNumButtons) &&
5122 (lptbim->iButton >= 0)))
5124 infoPtr->tbim = *lptbim;
5125 /* FIXME: don't need to update entire toolbar */
5126 InvalidateRect(hwnd, NULL, TRUE);
5129 ERR("Invalid button index %d\n", lptbim->iButton);
5136 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 infoPtr->clrInsertMark = (COLORREF)lParam;
5142 /* FIXME: don't need to update entire toolbar */
5143 InvalidateRect(hwnd, NULL, TRUE);
5150 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5154 infoPtr->nMaxTextRows = (INT)wParam;
5156 TOOLBAR_CalcToolbar(hwnd);
5161 /* MSDN gives slightly wrong info on padding.
5162 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5163 * 2. It is not used to create a blank area between the edge of the button
5164 * and the text or image if TBSTYLE_LIST is set. It is used to control
5165 * the gap between the image and text.
5166 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5167 * to control the bottom and right borders [with the border being
5168 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5169 * is shared evenly on both sides of the button.
5170 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5173 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5178 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5179 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5180 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5181 TRACE("cx=%ld, cy=%ld\n",
5182 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5183 return (LRESULT) oldPad;
5188 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5195 hwndOldNotify = infoPtr->hwndNotify;
5196 infoPtr->hwndNotify = (HWND)wParam;
5198 return (LRESULT)hwndOldNotify;
5203 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5206 LPRECT lprc = (LPRECT)lParam;
5210 if (LOWORD(wParam) > 1) {
5211 FIXME("multiple rows not supported!\n");
5214 if(infoPtr->nRows != LOWORD(wParam))
5216 infoPtr->nRows = LOWORD(wParam);
5218 /* recalculate toolbar */
5219 TOOLBAR_CalcToolbar (hwnd);
5221 /* repaint toolbar */
5222 InvalidateRect(hwnd, NULL, TRUE);
5225 /* return bounding rectangle */
5227 lprc->left = infoPtr->rcBound.left;
5228 lprc->right = infoPtr->rcBound.right;
5229 lprc->top = infoPtr->rcBound.top;
5230 lprc->bottom = infoPtr->rcBound.bottom;
5238 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5241 TBUTTON_INFO *btnPtr;
5244 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5248 btnPtr = &infoPtr->buttons[nIndex];
5250 /* if hidden state has changed the invalidate entire window and recalc */
5251 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5252 btnPtr->fsState = LOWORD(lParam);
5253 TOOLBAR_CalcToolbar (hwnd);
5254 InvalidateRect(hwnd, 0, TRUE);
5258 /* process state changing if current state doesn't match new state */
5259 if(btnPtr->fsState != LOWORD(lParam))
5261 btnPtr->fsState = LOWORD(lParam);
5262 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5270 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5272 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5278 inline static LRESULT
5279 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5283 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5285 infoPtr->hwndToolTip = (HWND)wParam;
5291 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5296 TRACE("%s hwnd=%p\n",
5297 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5299 bTemp = infoPtr->bUnicode;
5300 infoPtr->bUnicode = (BOOL)wParam;
5307 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5311 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5312 comctl32_color.clrBtnHighlight :
5313 infoPtr->clrBtnHighlight;
5314 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5315 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5321 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5325 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5326 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5327 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5329 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5330 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5331 InvalidateRect(hwnd, NULL, TRUE);
5337 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5339 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5340 INT iOldVersion = infoPtr->iVersion;
5342 infoPtr->iVersion = iVersion;
5344 if (infoPtr->iVersion >= 5)
5345 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5352 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5355 WORD iString = HIWORD(wParam);
5356 WORD buffersize = LOWORD(wParam);
5357 LPSTR str = (LPSTR)lParam;
5360 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5362 if (iString < infoPtr->nNumStrings)
5364 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5366 TRACE("returning %s\n", debugstr_a(str));
5369 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5376 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5379 WORD iString = HIWORD(wParam);
5380 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5381 LPWSTR str = (LPWSTR)lParam;
5384 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5386 if (iString < infoPtr->nNumStrings)
5388 len = min(len, strlenW(infoPtr->strings[iString]));
5389 ret = (len+1)*sizeof(WCHAR);
5390 memcpy(str, infoPtr->strings[iString], ret);
5393 TRACE("returning %s\n", debugstr_w(str));
5396 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5401 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5402 * is the maximum size of the toolbar? */
5403 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5405 SIZE * pSize = (SIZE*)lParam;
5406 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5411 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5412 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5413 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5416 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5419 INT nOldHotItem = infoPtr->nHotItem;
5421 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5422 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5424 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5427 /* NOTE: an application can still remove the hot item even if anchor
5428 * highlighting is enabled */
5430 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5434 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5437 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5438 * which controls the amount of spacing between the image and the text
5439 * of buttons for TBSTYLE_LIST toolbars. */
5440 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5444 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5447 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5449 infoPtr->iListGap = (INT)wParam;
5451 InvalidateRect(hwnd, NULL, TRUE);
5456 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5457 * of image lists associated with the various states. */
5458 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5460 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5462 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5464 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5468 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5470 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5471 LPSIZE lpsize = (LPSIZE)lParam;
5477 * Testing shows the following:
5478 * wParam = 0 adjust cx value
5479 * = 1 set cy value to max size.
5480 * lParam pointer to SIZE structure
5483 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5484 wParam, lParam, lpsize->cx, lpsize->cy);
5488 if (lpsize->cx == -1) {
5489 /* **** this is wrong, native measures each button and sets it */
5490 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5492 else if(HIWORD(lpsize->cx)) {
5494 HWND hwndParent = GetParent(hwnd);
5496 GetWindowRect(hwnd, &rc);
5497 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5498 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5499 rc.left, rc.top, rc.right, rc.bottom);
5500 lpsize->cx = max(rc.right-rc.left,
5501 infoPtr->rcBound.right - infoPtr->rcBound.left);
5504 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5508 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5511 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5515 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5516 lpsize->cx, lpsize->cy);
5520 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5522 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5524 InvalidateRect(hwnd, NULL, TRUE);
5530 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5532 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5533 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5536 TRACE("hwnd = %p\n", hwnd);
5538 /* initialize info structure */
5539 infoPtr->nButtonHeight = 22;
5540 infoPtr->nButtonWidth = 24;
5541 infoPtr->nBitmapHeight = 15;
5542 infoPtr->nBitmapWidth = 16;
5544 infoPtr->nMaxTextRows = 1;
5545 infoPtr->cxMin = -1;
5546 infoPtr->cxMax = -1;
5547 infoPtr->nNumBitmaps = 0;
5548 infoPtr->nNumStrings = 0;
5550 infoPtr->bCaptured = FALSE;
5551 infoPtr->nButtonDown = -1;
5552 infoPtr->nButtonDrag = -1;
5553 infoPtr->nOldHit = -1;
5554 infoPtr->nHotItem = -1;
5555 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5556 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5557 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5558 infoPtr->bDragOutSent = FALSE;
5559 infoPtr->iVersion = 0;
5560 infoPtr->hwndSelf = hwnd;
5561 infoPtr->bDoRedraw = TRUE;
5562 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5563 infoPtr->clrBtnShadow = CLR_DEFAULT;
5564 infoPtr->szPadding.cx = DEFPAD_CX;
5565 infoPtr->szPadding.cy = DEFPAD_CY;
5566 infoPtr->iListGap = DEFLISTGAP;
5567 infoPtr->dwStyle = dwStyle;
5568 infoPtr->tbim.iButton = -1;
5569 GetClientRect(hwnd, &infoPtr->client_rect);
5570 infoPtr->bUnicode = infoPtr->hwndNotify &&
5571 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5573 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5574 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5576 if (dwStyle & TBSTYLE_TOOLTIPS) {
5577 /* Create tooltip control */
5578 infoPtr->hwndToolTip =
5579 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5580 CW_USEDEFAULT, CW_USEDEFAULT,
5581 CW_USEDEFAULT, CW_USEDEFAULT,
5584 /* Send NM_TOOLTIPSCREATED notification */
5585 if (infoPtr->hwndToolTip)
5587 NMTOOLTIPSCREATED nmttc;
5589 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5591 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5595 TOOLBAR_CheckStyle (hwnd, dwStyle);
5597 TOOLBAR_CalcToolbar(hwnd);
5604 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5608 /* delete tooltip control */
5609 if (infoPtr->hwndToolTip)
5610 DestroyWindow (infoPtr->hwndToolTip);
5612 /* delete temporary buffer for tooltip text */
5613 Free (infoPtr->pszTooltipText);
5615 /* delete button data */
5616 if (infoPtr->buttons)
5617 Free (infoPtr->buttons);
5619 /* delete strings */
5620 if (infoPtr->strings) {
5622 for (i = 0; i < infoPtr->nNumStrings; i++)
5623 if (infoPtr->strings[i])
5624 Free (infoPtr->strings[i]);
5626 Free (infoPtr->strings);
5629 /* destroy internal image list */
5630 if (infoPtr->himlInt)
5631 ImageList_Destroy (infoPtr->himlInt);
5633 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5634 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5635 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5637 /* delete default font */
5639 DeleteObject (infoPtr->hDefaultFont);
5641 /* free toolbar info data */
5643 SetWindowLongPtrW (hwnd, 0, 0);
5650 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5653 NMTBCUSTOMDRAW tbcd;
5657 /* the app has told us not to redraw the toolbar */
5658 if (!infoPtr->bDoRedraw)
5661 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5662 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5663 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5664 tbcd.nmcd.hdc = (HDC)wParam;
5665 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5666 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5668 /* FIXME: in general the return flags *can* be or'ed together */
5669 switch (infoPtr->dwBaseCustDraw)
5671 case CDRF_DODEFAULT:
5673 case CDRF_SKIPDEFAULT:
5676 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5681 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5682 * to my parent for processing.
5684 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5686 HDC hdc = (HDC)wParam;
5691 parent = GetParent(hwnd);
5692 MapWindowPoints(hwnd, parent, &pt, 1);
5693 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5694 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5695 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5698 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5700 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5701 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5702 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5703 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5704 tbcd.nmcd.hdc = (HDC)wParam;
5705 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5706 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5707 switch (infoPtr->dwBaseCustDraw)
5709 case CDRF_DODEFAULT:
5711 case CDRF_SKIPDEFAULT:
5714 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5723 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5727 return (LRESULT)infoPtr->hFont;
5732 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5737 pt.x = (INT)LOWORD(lParam);
5738 pt.y = (INT)HIWORD(lParam);
5739 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5742 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5743 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5744 TOOLBAR_Customize (hwnd);
5751 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5754 TBUTTON_INFO *btnPtr;
5759 BOOL bDragKeyPressed;
5763 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5764 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5766 bDragKeyPressed = (wParam & MK_SHIFT);
5768 if (infoPtr->hwndToolTip)
5769 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5770 WM_LBUTTONDOWN, wParam, lParam);
5772 pt.x = (INT)LOWORD(lParam);
5773 pt.y = (INT)HIWORD(lParam);
5774 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5776 btnPtr = &infoPtr->buttons[nHit];
5778 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5780 infoPtr->nButtonDrag = nHit;
5783 /* If drag cursor has not been loaded, load it.
5784 * Note: it doesn't need to be freed */
5786 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5787 SetCursor(hCursorDrag);
5792 infoPtr->nOldHit = nHit;
5794 CopyRect(&arrowRect, &btnPtr->rect);
5795 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5797 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5798 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5799 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5800 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5801 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5802 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5806 /* draw in pressed state */
5807 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5808 btnPtr->fsState |= TBSTATE_PRESSED;
5810 btnPtr->bDropDownPressed = TRUE;
5811 RedrawWindow(hwnd,&btnPtr->rect,0,
5812 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5814 memset(&nmtb, 0, sizeof(nmtb));
5815 nmtb.iItem = btnPtr->idCommand;
5816 nmtb.rcButton = btnPtr->rect;
5817 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5819 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5821 if (res != TBDDRET_TREATPRESSED)
5825 /* redraw button in unpressed state */
5826 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5827 btnPtr->fsState &= ~TBSTATE_PRESSED;
5829 btnPtr->bDropDownPressed = FALSE;
5830 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5832 /* find and set hot item
5833 * NOTE: native doesn't do this, but that is a bug */
5835 ScreenToClient(hwnd, &pt);
5836 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5837 if (!infoPtr->bAnchor || (nHit >= 0))
5838 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5840 /* remove any left mouse button down or double-click messages
5841 * so that we can get a toggle effect on the button */
5842 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5843 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5848 /* otherwise drop through and process as pushed */
5850 infoPtr->bCaptured = TRUE;
5851 infoPtr->nButtonDown = nHit;
5852 infoPtr->bDragOutSent = FALSE;
5854 btnPtr->fsState |= TBSTATE_PRESSED;
5856 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5858 if (btnPtr->fsState & TBSTATE_ENABLED)
5859 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5866 memset(&nmtb, 0, sizeof(nmtb));
5867 nmtb.iItem = btnPtr->idCommand;
5868 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5871 nmmouse.dwHitInfo = nHit;
5873 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5875 nmmouse.dwItemSpec = -1;
5878 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5879 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5882 ClientToScreen(hwnd, &pt);
5885 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5886 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5892 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5895 TBUTTON_INFO *btnPtr;
5899 BOOL bSendMessage = TRUE;
5904 if (infoPtr->hwndToolTip)
5905 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5906 WM_LBUTTONUP, wParam, lParam);
5908 pt.x = (INT)LOWORD(lParam);
5909 pt.y = (INT)HIWORD(lParam);
5910 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5912 if (!infoPtr->bAnchor || (nHit >= 0))
5913 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5915 if (infoPtr->nButtonDrag >= 0) {
5919 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5922 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5924 GetClientRect(hwnd, &rcClient);
5925 if (PtInRect(&rcClient, pt))
5932 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5935 if (nButton == infoPtr->nButtonDrag)
5937 /* if the button is moved sightly left and we have a
5938 * separator there then remove it */
5939 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5941 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5942 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5944 else /* else insert a separator before the dragged button */
5947 memset(&tbb, 0, sizeof(tbb));
5948 tbb.fsStyle = BTNS_SEP;
5950 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5957 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5958 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5960 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5963 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5968 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5969 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5972 /* button under cursor changed so need to re-set hot item */
5973 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5974 infoPtr->nButtonDrag = -1;
5976 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5978 else if (infoPtr->nButtonDown >= 0) {
5979 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5980 btnPtr->fsState &= ~TBSTATE_PRESSED;
5982 if (btnPtr->fsStyle & BTNS_CHECK) {
5983 if (btnPtr->fsStyle & BTNS_GROUP) {
5984 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5986 if (nOldIndex == nHit)
5987 bSendMessage = FALSE;
5988 if ((nOldIndex != nHit) &&
5990 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5991 btnPtr->fsState |= TBSTATE_CHECKED;
5994 if (btnPtr->fsState & TBSTATE_CHECKED)
5995 btnPtr->fsState &= ~TBSTATE_CHECKED;
5997 btnPtr->fsState |= TBSTATE_CHECKED;
6001 if (nOldIndex != -1)
6002 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6005 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6006 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6007 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6009 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6011 infoPtr->nButtonDown = -1;
6013 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6014 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6015 NM_RELEASEDCAPTURE);
6017 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6020 memset(&nmtb, 0, sizeof(nmtb));
6021 nmtb.iItem = btnPtr->idCommand;
6022 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6025 if (btnPtr->fsState & TBSTATE_ENABLED)
6027 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6028 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
6032 /* !!! Undocumented - toolbar at 4.71 level and above sends
6033 * NM_CLICK with the NMMOUSE structure. */
6034 nmmouse.dwHitInfo = nHit;
6036 if (nmmouse.dwHitInfo < 0)
6037 nmmouse.dwItemSpec = -1;
6040 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6041 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6044 ClientToScreen(hwnd, &pt);
6047 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6048 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6054 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6061 pt.x = LOWORD(lParam);
6062 pt.y = HIWORD(lParam);
6064 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6065 nmmouse.dwHitInfo = nHit;
6068 nmmouse.dwItemSpec = -1;
6070 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6071 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6074 ClientToScreen(hwnd, &pt);
6077 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6078 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6084 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6089 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6090 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6096 TOOLBAR_CaptureChanged(HWND hwnd)
6098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6099 TBUTTON_INFO *btnPtr;
6101 infoPtr->bCaptured = FALSE;
6103 if (infoPtr->nButtonDown >= 0)
6105 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6106 btnPtr->fsState &= ~TBSTATE_PRESSED;
6108 infoPtr->nOldHit = -1;
6110 if (btnPtr->fsState & TBSTATE_ENABLED)
6111 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6117 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6120 TBUTTON_INFO *hotBtnPtr;
6122 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6124 /* don't remove hot effects when in anchor highlighting mode or when a
6125 * drop-down button is pressed */
6126 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6127 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6129 if (infoPtr->nOldHit < 0)
6132 /* If the last button we were over is depressed then make it not */
6133 /* depressed and redraw it */
6134 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6136 TBUTTON_INFO *btnPtr;
6139 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6141 btnPtr->fsState &= ~TBSTATE_PRESSED;
6143 rc1 = hotBtnPtr->rect;
6144 InflateRect (&rc1, 1, 1);
6145 InvalidateRect (hwnd, &rc1, TRUE);
6148 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6151 ZeroMemory(&nmt, sizeof(nmt));
6152 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6153 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6154 infoPtr->bDragOutSent = TRUE;
6157 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6163 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6167 TRACKMOUSEEVENT trackinfo;
6169 TBUTTON_INFO *btnPtr;
6171 if (infoPtr->dwStyle & TBSTYLE_FLAT) {
6172 /* fill in the TRACKMOUSEEVENT struct */
6173 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6174 trackinfo.dwFlags = TME_QUERY;
6175 trackinfo.hwndTrack = hwnd;
6176 trackinfo.dwHoverTime = HOVER_DEFAULT;
6178 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6179 _TrackMouseEvent(&trackinfo);
6181 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6182 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6183 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6185 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6186 /* and can properly deactivate the hot toolbar button */
6187 _TrackMouseEvent(&trackinfo);
6191 if (infoPtr->hwndToolTip)
6192 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6193 WM_MOUSEMOVE, wParam, lParam);
6195 pt.x = (INT)LOWORD(lParam);
6196 pt.y = (INT)HIWORD(lParam);
6198 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6200 if ((infoPtr->dwStyle & TBSTYLE_FLAT) && (!infoPtr->bAnchor || (nHit >= 0)))
6201 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6203 if (infoPtr->nOldHit != nHit)
6205 if (infoPtr->bCaptured)
6207 if (!infoPtr->bDragOutSent)
6210 ZeroMemory(&nmt, sizeof(nmt));
6211 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6212 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6213 infoPtr->bDragOutSent = TRUE;
6216 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6217 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6218 btnPtr->fsState &= ~TBSTATE_PRESSED;
6219 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6221 else if (nHit == infoPtr->nButtonDown) {
6222 btnPtr->fsState |= TBSTATE_PRESSED;
6223 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6225 infoPtr->nOldHit = nHit;
6233 inline static LRESULT
6234 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6236 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6237 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6239 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6243 inline static LRESULT
6244 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6246 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6247 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6249 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6254 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6256 TOOLBAR_INFO *infoPtr;
6257 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6260 /* allocate memory for info structure */
6261 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6262 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6265 infoPtr->dwStructSize = sizeof(TBBUTTON);
6268 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6269 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6270 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6271 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6274 /* native control does:
6275 * Get a lot of colors and brushes
6277 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6278 * CreateFontIndirectW(adr1)
6279 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6280 * hdc = GetDC(toolbar)
6281 * GetSystemMetrics(0x48)
6282 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6283 * 0, 0, 0, 0, "MARLETT")
6284 * oldfnt = SelectObject(hdc, fnt2)
6285 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6286 * GetTextMetricsW(hdc, adr3)
6287 * SelectObject(hdc, oldfnt)
6288 * DeleteObject(fnt2)
6290 * InvalidateRect(toolbar, 0, 1)
6291 * SetWindowLongW(toolbar, 0, addr)
6292 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6295 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6296 * ie 2 0x4600094c 0x4600094c 0x4600894d
6297 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6298 * rebar 0x50008844 0x40008844 0x50008845
6299 * pager 0x50000844 0x40000844 0x50008845
6300 * IC35mgr 0x5400084e **nochange**
6301 * on entry to _NCCREATE 0x5400084e
6302 * rowlist 0x5400004e **nochange**
6303 * on entry to _NCCREATE 0x5400004e
6307 /* I think the code below is a bug, but it is the way that the native
6308 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6309 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6310 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6311 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6312 * Somehow, the only cases of this seem to be MFC programs.
6314 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6315 * does not occur in the WM_STYLECHANGING routine.
6316 * (Guy Albertelli 9/2001)
6319 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6320 styleadd |= TBSTYLE_TRANSPARENT;
6321 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6322 styleadd |= CCS_TOP; /* default to top */
6323 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6326 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6331 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6333 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6337 if (dwStyle & WS_MINIMIZE)
6338 return 0; /* Nothing to do */
6340 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6342 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6345 if (!(dwStyle & CCS_NODIVIDER))
6347 GetWindowRect (hwnd, &rcWindow);
6348 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6349 if( dwStyle & WS_BORDER )
6350 OffsetRect (&rcWindow, 1, 1);
6351 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6354 ReleaseDC( hwnd, hdc );
6360 /* handles requests from the tooltip control on what text to display */
6361 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6363 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6365 TRACE("button index = %d\n", index);
6367 Free (infoPtr->pszTooltipText);
6368 infoPtr->pszTooltipText = NULL;
6373 if (infoPtr->bUnicode)
6375 WCHAR wszBuffer[INFOTIPSIZE+1];
6376 NMTBGETINFOTIPW tbgit;
6377 unsigned int len; /* in chars */
6379 wszBuffer[0] = '\0';
6380 wszBuffer[INFOTIPSIZE] = '\0';
6382 tbgit.pszText = wszBuffer;
6383 tbgit.cchTextMax = INFOTIPSIZE;
6384 tbgit.iItem = lpnmtdi->hdr.idFrom;
6385 tbgit.lParam = infoPtr->buttons[index].dwData;
6387 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6389 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6391 len = strlenW(tbgit.pszText);
6392 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6394 /* need to allocate temporary buffer in infoPtr as there
6395 * isn't enough space in buffer passed to us by the
6396 * tooltip control */
6397 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6398 if (infoPtr->pszTooltipText)
6400 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6401 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6407 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6413 CHAR szBuffer[INFOTIPSIZE+1];
6414 NMTBGETINFOTIPA tbgit;
6415 unsigned int len; /* in chars */
6418 szBuffer[INFOTIPSIZE] = '\0';
6420 tbgit.pszText = szBuffer;
6421 tbgit.cchTextMax = INFOTIPSIZE;
6422 tbgit.iItem = lpnmtdi->hdr.idFrom;
6423 tbgit.lParam = infoPtr->buttons[index].dwData;
6425 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6427 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6429 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6430 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6432 /* need to allocate temporary buffer in infoPtr as there
6433 * isn't enough space in buffer passed to us by the
6434 * tooltip control */
6435 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6436 if (infoPtr->pszTooltipText)
6438 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6439 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6445 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6450 /* if button has text, but it is not shown then automatically
6451 * use that text as tooltip */
6452 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6453 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6455 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6456 unsigned int len = pszText ? strlenW(pszText) : 0;
6458 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6460 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6462 /* need to allocate temporary buffer in infoPtr as there
6463 * isn't enough space in buffer passed to us by the
6464 * tooltip control */
6465 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6466 if (infoPtr->pszTooltipText)
6468 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6469 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6475 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6480 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6482 /* last resort: send notification on to app */
6483 /* FIXME: find out what is really used here */
6484 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6488 inline static LRESULT
6489 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6491 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6492 LPNMHDR lpnmh = (LPNMHDR)lParam;
6494 switch (lpnmh->code)
6498 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6500 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6501 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6502 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6506 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6507 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6515 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6517 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6518 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6519 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6520 lppgs->iScroll, lppgs->iDir);
6524 case TTN_GETDISPINFOW:
6525 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6527 case TTN_GETDISPINFOA:
6528 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6538 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6542 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6544 if (lParam == NF_QUERY)
6547 if (lParam == NF_REQUERY) {
6548 format = SendMessageW(infoPtr->hwndNotify,
6549 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6550 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6551 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6562 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6568 /* fill ps.rcPaint with a default rect */
6569 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6571 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6573 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6574 ps.rcPaint.left, ps.rcPaint.top,
6575 ps.rcPaint.right, ps.rcPaint.bottom);
6577 TOOLBAR_Refresh (hwnd, hdc, &ps);
6578 if (!wParam) EndPaint (hwnd, &ps);
6585 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6586 /*****************************************************
6589 * Handles the WM_SETREDRAW message.
6592 * According to testing V4.71 of COMCTL32 returns the
6593 * *previous* status of the redraw flag (either 0 or 1)
6594 * instead of the MSDN documented value of 0 if handled.
6595 * (For laughs see the "consistency" with same function
6598 *****************************************************/
6600 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6601 BOOL oldredraw = infoPtr->bDoRedraw;
6603 TRACE("set to %s\n",
6604 (wParam) ? "TRUE" : "FALSE");
6605 infoPtr->bDoRedraw = (BOOL) wParam;
6607 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6609 return (oldredraw) ? 1 : 0;
6614 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6616 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6618 TRACE("sizing toolbar!\n");
6620 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6622 RECT delta_width, delta_height, client, dummy;
6623 DWORD min_x, max_x, min_y, max_y;
6624 TBUTTON_INFO *btnPtr;
6627 GetClientRect(hwnd, &client);
6628 if(client.right > infoPtr->client_rect.right)
6630 min_x = infoPtr->client_rect.right;
6631 max_x = client.right;
6635 max_x = infoPtr->client_rect.right;
6636 min_x = client.right;
6638 if(client.bottom > infoPtr->client_rect.bottom)
6640 min_y = infoPtr->client_rect.bottom;
6641 max_y = client.bottom;
6645 max_y = infoPtr->client_rect.bottom;
6646 min_y = client.bottom;
6649 SetRect(&delta_width, min_x, 0, max_x, min_y);
6650 SetRect(&delta_height, 0, min_y, max_x, max_y);
6652 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6653 btnPtr = infoPtr->buttons;
6654 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6655 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6656 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6657 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6659 GetClientRect(hwnd, &infoPtr->client_rect);
6660 TOOLBAR_AutoSize(hwnd);
6666 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6670 if (nType == GWL_STYLE)
6672 if (lpStyle->styleNew & TBSTYLE_LIST)
6673 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6675 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6677 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6679 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6681 infoPtr->dwStyle = lpStyle->styleNew;
6683 /* only resize if one of the CCS_* styles was changed */
6684 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6686 TOOLBAR_AutoSize (hwnd);
6688 InvalidateRect(hwnd, NULL, TRUE);
6697 TOOLBAR_SysColorChange (HWND hwnd)
6699 COMCTL32_RefreshSysColors();
6706 static LRESULT WINAPI
6707 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6709 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6711 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6712 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6714 if (!infoPtr && (uMsg != WM_NCCREATE))
6715 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6720 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6722 case TB_ADDBUTTONSA:
6723 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6725 case TB_ADDBUTTONSW:
6726 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6729 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6732 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6735 return TOOLBAR_AutoSize (hwnd);
6737 case TB_BUTTONCOUNT:
6738 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6740 case TB_BUTTONSTRUCTSIZE:
6741 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6743 case TB_CHANGEBITMAP:
6744 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6746 case TB_CHECKBUTTON:
6747 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6749 case TB_COMMANDTOINDEX:
6750 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6753 return TOOLBAR_Customize (hwnd);
6755 case TB_DELETEBUTTON:
6756 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6758 case TB_ENABLEBUTTON:
6759 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6761 case TB_GETANCHORHIGHLIGHT:
6762 return TOOLBAR_GetAnchorHighlight (hwnd);
6765 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6767 case TB_GETBITMAPFLAGS:
6768 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6771 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6773 case TB_GETBUTTONINFOA:
6774 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6776 case TB_GETBUTTONINFOW:
6777 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6779 case TB_GETBUTTONSIZE:
6780 return TOOLBAR_GetButtonSize (hwnd);
6782 case TB_GETBUTTONTEXTA:
6783 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6785 case TB_GETBUTTONTEXTW:
6786 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6788 case TB_GETDISABLEDIMAGELIST:
6789 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6791 case TB_GETEXTENDEDSTYLE:
6792 return TOOLBAR_GetExtendedStyle (hwnd);
6794 case TB_GETHOTIMAGELIST:
6795 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6798 return TOOLBAR_GetHotItem (hwnd);
6800 case TB_GETIMAGELIST:
6801 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6803 case TB_GETINSERTMARK:
6804 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6806 case TB_GETINSERTMARKCOLOR:
6807 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6809 case TB_GETITEMRECT:
6810 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6813 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6815 /* case TB_GETOBJECT: */ /* 4.71 */
6818 return TOOLBAR_GetPadding (hwnd);
6821 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6824 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6827 return TOOLBAR_GetState (hwnd, wParam, lParam);
6830 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6833 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6836 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6838 case TB_GETTEXTROWS:
6839 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6841 case TB_GETTOOLTIPS:
6842 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6844 case TB_GETUNICODEFORMAT:
6845 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6848 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6851 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6853 case TB_INDETERMINATE:
6854 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6856 case TB_INSERTBUTTONA:
6857 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6859 case TB_INSERTBUTTONW:
6860 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6862 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6864 case TB_ISBUTTONCHECKED:
6865 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6867 case TB_ISBUTTONENABLED:
6868 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6870 case TB_ISBUTTONHIDDEN:
6871 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6873 case TB_ISBUTTONHIGHLIGHTED:
6874 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6876 case TB_ISBUTTONINDETERMINATE:
6877 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6879 case TB_ISBUTTONPRESSED:
6880 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6883 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6885 case TB_MAPACCELERATORA:
6886 case TB_MAPACCELERATORW:
6887 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6890 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6893 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6895 case TB_PRESSBUTTON:
6896 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6898 case TB_REPLACEBITMAP:
6899 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6901 case TB_SAVERESTOREA:
6902 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6904 case TB_SAVERESTOREW:
6905 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6907 case TB_SETANCHORHIGHLIGHT:
6908 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6910 case TB_SETBITMAPSIZE:
6911 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6913 case TB_SETBUTTONINFOA:
6914 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6916 case TB_SETBUTTONINFOW:
6917 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6919 case TB_SETBUTTONSIZE:
6920 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6922 case TB_SETBUTTONWIDTH:
6923 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6926 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6928 case TB_SETDISABLEDIMAGELIST:
6929 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6931 case TB_SETDRAWTEXTFLAGS:
6932 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6934 case TB_SETEXTENDEDSTYLE:
6935 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6937 case TB_SETHOTIMAGELIST:
6938 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6941 return TOOLBAR_SetHotItem (hwnd, wParam);
6943 case TB_SETIMAGELIST:
6944 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6947 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6949 case TB_SETINSERTMARK:
6950 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6952 case TB_SETINSERTMARKCOLOR:
6953 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6955 case TB_SETMAXTEXTROWS:
6956 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6959 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6962 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6965 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6968 return TOOLBAR_SetState (hwnd, wParam, lParam);
6971 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6973 case TB_SETTOOLTIPS:
6974 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6976 case TB_SETUNICODEFORMAT:
6977 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6980 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6983 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6986 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6989 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6992 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6995 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6997 /* Common Control Messages */
6999 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7000 case CCM_GETCOLORSCHEME:
7001 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7003 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7004 case CCM_SETCOLORSCHEME:
7005 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7007 case CCM_GETVERSION:
7008 return TOOLBAR_GetVersion (hwnd);
7010 case CCM_SETVERSION:
7011 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7017 return TOOLBAR_Create (hwnd, wParam, lParam);
7020 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7023 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7026 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7028 /* case WM_KEYDOWN: */
7029 /* case WM_KILLFOCUS: */
7031 case WM_LBUTTONDBLCLK:
7032 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7034 case WM_LBUTTONDOWN:
7035 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7038 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7041 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7043 case WM_RBUTTONDBLCLK:
7044 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7047 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7050 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7052 case WM_CAPTURECHANGED:
7053 return TOOLBAR_CaptureChanged(hwnd);
7056 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7059 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7062 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7065 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7068 return TOOLBAR_Notify (hwnd, wParam, lParam);
7070 case WM_NOTIFYFORMAT:
7071 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7074 return TOOLBAR_Paint (hwnd, wParam);
7077 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7080 return TOOLBAR_Size (hwnd, wParam, lParam);
7082 case WM_STYLECHANGED:
7083 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7085 case WM_SYSCOLORCHANGE:
7086 return TOOLBAR_SysColorChange (hwnd);
7088 /* case WM_WININICHANGE: */
7093 case WM_MEASUREITEM:
7095 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7097 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7098 case PGM_FORWARDMOUSE:
7099 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7102 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7103 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7104 uMsg, wParam, lParam);
7105 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7111 TOOLBAR_Register (void)
7115 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7116 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7117 wndClass.lpfnWndProc = ToolbarWindowProc;
7118 wndClass.cbClsExtra = 0;
7119 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7120 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7121 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7122 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7124 RegisterClassW (&wndClass);
7129 TOOLBAR_Unregister (void)
7131 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7134 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7139 /* Check if the entry already exists */
7140 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7142 /* If this is a new entry we must create it and insert into the array */
7147 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7150 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7151 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7166 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7170 for (i = 0; i < *cies; i++)
7180 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7188 for (i = 0; i < cies; i++)
7190 if (pies[i]->id == id)
7202 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7204 HIMAGELIST himlDef = 0;
7205 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7208 himlDef = pie->himl;
7214 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7216 if (infoPtr->bUnicode)
7217 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7224 nmtba.iItem = nmtb->iItem;
7225 nmtba.pszText = Buffer;
7226 nmtba.cchText = 256;
7227 ZeroMemory(nmtba.pszText, nmtba.cchText);
7229 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7231 int ccht = strlen(nmtba.pszText);
7233 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7234 nmtb->pszText, nmtb->cchText);
7236 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7246 int iItem, PCUSTOMBUTTON btnInfo)
7250 /* MSDN states that iItem is the index of the button, rather than the
7251 * command ID as used by every other NMTOOLBAR notification */
7253 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7255 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);