4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
98 BYTE bDropDownPressed;
103 INT cx; /* manually set size */
117 } IMLENTRY, *PIMLENTRY;
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
124 RECT rcBound; /* bounding rectangle */
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nHotItem; /* index of the "hot" item */
142 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding; /* padding values around button */
146 INT iListGap; /* default gap between text and image for toolbar with list style */
148 HFONT hFont; /* text font */
149 HIMAGELIST himlInt; /* image list created internally */
150 PIMLENTRY *himlDef; /* default image list array */
151 INT cimlDef; /* default image list array count */
152 PIMLENTRY *himlHot; /* hot image list array */
153 INT cimlHot; /* hot image list array count */
154 PIMLENTRY *himlDis; /* disabled image list array */
155 INT cimlDis; /* disabled image list array count */
156 HWND hwndToolTip; /* handle to tool tip control */
157 HWND hwndNotify; /* handle to the window that gets notifications */
158 HWND hwndSelf; /* my own handle */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bDoRedraw; /* Redraw status */
161 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
162 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
163 BOOL bCaptured; /* mouse captured? */
164 DWORD dwStyle; /* regular toolbar style */
165 DWORD dwExStyle; /* extended toolbar style */
166 DWORD dwDTFlags; /* DrawText flags */
168 COLORREF clrInsertMark; /* insert mark color */
169 COLORREF clrBtnHighlight; /* color for Flat Separator */
170 COLORREF clrBtnShadow; /* color for Flag Separator */
172 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
173 * for TTN_GETDISPINFOW notification */
174 TBINSERTMARK tbim; /* info on insertion mark */
175 TBUTTON_INFO *buttons; /* pointer to button array */
176 LPWSTR *strings; /* pointer to string array */
177 TBITMAP_INFO *bitmaps;
178 } TOOLBAR_INFO, *PTOOLBAR_INFO;
181 /* used by customization dialog */
184 PTOOLBAR_INFO tbInfo;
186 } CUSTDLG_INFO, *PCUSTDLG_INFO;
194 } CUSTOMBUTTON, *PCUSTOMBUTTON;
203 #define SEPARATOR_WIDTH 8
205 #define BOTTOM_BORDER 2
206 #define DDARROW_WIDTH 11
207 #define ARROW_HEIGHT 3
208 #define INSERTMARK_WIDTH 2
214 /* vertical padding used in list mode when image is present */
217 /* how wide to treat the bitmap if it isn't present */
218 #define NONLIST_NOTEXT_OFFSET 2
220 #define TOOLBAR_NOWHERE (-1)
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 /* Used to find undocumented extended styles */
227 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
228 TBSTYLE_EX_UNDOC1 | \
229 TBSTYLE_EX_MIXEDBUTTONS | \
230 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
232 /* all of the CCS_ styles */
233 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
234 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
236 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
237 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
238 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
239 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
240 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
242 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
254 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
257 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
261 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
263 LPWSTR lpText = NULL;
265 /* NOTE: iString == -1 is undocumented */
266 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
267 lpText = (LPWSTR)btnPtr->iString;
268 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
269 lpText = infoPtr->strings[btnPtr->iString];
275 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
277 if (TRACE_ON(toolbar)){
278 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
279 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
280 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
281 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
283 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
284 btn_num, bP->idCommand,
285 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
286 bP->rect.left, bP->rect.top,
287 bP->rect.right, bP->rect.bottom);
293 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
295 if (TRACE_ON(toolbar)) {
298 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
300 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
301 iP->nNumStrings, iP->dwStyle);
302 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
304 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
305 (iP->bDoRedraw) ? "TRUE" : "FALSE");
306 for(i=0; i<iP->nNumButtons; i++) {
307 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
313 /***********************************************************************
316 * This function validates that the styles set are implemented and
317 * issues FIXME's warning of possible problems. In a perfect world this
318 * function should be null.
321 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
323 if (dwStyle & TBSTYLE_REGISTERDROP)
324 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
329 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
331 if(!IsWindow(infoPtr->hwndSelf))
332 return 0; /* we have just been destroyed */
334 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
335 nmhdr->hwndFrom = infoPtr->hwndSelf;
338 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
339 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
341 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
342 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
345 /***********************************************************************
346 * TOOLBAR_GetBitmapIndex
348 * This function returns the bitmap index associated with a button.
349 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
350 * is issued to retrieve the index.
353 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
355 INT ret = btnPtr->iBitmap;
357 if (ret == I_IMAGECALLBACK)
359 /* issue TBN_GETDISPINFO */
362 memset(&nmgd, 0, sizeof(nmgd));
363 nmgd.idCommand = btnPtr->idCommand;
364 nmgd.lParam = btnPtr->dwData;
365 nmgd.dwMask = TBNF_IMAGE;
366 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
367 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
368 if (nmgd.dwMask & TBNF_DI_SETITEM)
369 btnPtr->iBitmap = nmgd.iImage;
371 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
372 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
375 if (ret != I_IMAGENONE)
376 ret = GETIBITMAP(infoPtr, ret);
383 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
386 INT id = GETHIMLID(infoPtr, index);
387 INT iBitmap = GETIBITMAP(infoPtr, index);
389 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
390 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
391 (index == I_IMAGECALLBACK))
399 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
401 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
402 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
406 /***********************************************************************
407 * TOOLBAR_GetImageListForDrawing
409 * This function validates the bitmap index (including I_IMAGECALLBACK
410 * functionality) and returns the corresponding image list.
413 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
417 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
418 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
419 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
420 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
424 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
425 if ((*index == I_IMAGECALLBACK) ||
426 (*index == I_IMAGENONE)) return NULL;
427 ERR("TBN_GETDISPINFO returned invalid index %d\n",
434 case IMAGE_LIST_DEFAULT:
435 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
440 case IMAGE_LIST_DISABLED:
441 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
445 FIXME("Shouldn't reach here\n");
449 TRACE("no image list\n");
456 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
459 COLORREF oldcolor, newcolor;
461 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
462 myrect.right = myrect.left + 1;
463 myrect.top = lpRect->top + 2;
464 myrect.bottom = lpRect->bottom - 2;
466 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
467 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
468 oldcolor = SetBkColor (hdc, newcolor);
469 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
471 myrect.left = myrect.right;
472 myrect.right = myrect.left + 1;
474 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
475 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
476 SetBkColor (hdc, newcolor);
477 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
479 SetBkColor (hdc, oldcolor);
483 /***********************************************************************
484 * TOOLBAR_DrawDDFlatSeparator
486 * This function draws the separator that was flagged as BTNS_DROPDOWN.
487 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
488 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
489 * are horizontal as opposed to the vertical separators for not dropdown
492 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
495 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
498 COLORREF oldcolor, newcolor;
500 myrect.left = lpRect->left;
501 myrect.right = lpRect->right;
502 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
503 myrect.bottom = myrect.top + 1;
505 InflateRect (&myrect, -2, 0);
507 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
508 myrect.left, myrect.top, myrect.right, myrect.bottom);
510 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
511 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
512 oldcolor = SetBkColor (hdc, newcolor);
513 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
515 myrect.top = myrect.bottom;
516 myrect.bottom = myrect.top + 1;
518 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
519 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
520 SetBkColor (hdc, newcolor);
521 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
523 SetBkColor (hdc, oldcolor);
528 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
533 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
534 hOldPen = SelectObject ( hdc, hPen );
537 MoveToEx (hdc, x, y, NULL);
538 LineTo (hdc, x+5, y++); x++;
539 MoveToEx (hdc, x, y, NULL);
540 LineTo (hdc, x+3, y++); x++;
541 MoveToEx (hdc, x, y, NULL);
542 LineTo (hdc, x+1, y++);
543 SelectObject( hdc, hOldPen );
544 DeleteObject( hPen );
548 * Draw the text string for this button.
549 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
550 * is non-zero, so we can simply check himlDef to see if we have
554 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
555 NMTBCUSTOMDRAW *tbcd)
557 HDC hdc = tbcd->nmcd.hdc;
560 COLORREF clrOldBk = 0;
562 UINT state = tbcd->nmcd.uItemState;
566 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
567 rcText->left, rcText->top, rcText->right, rcText->bottom);
569 hOldFont = SelectObject (hdc, infoPtr->hFont);
570 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
571 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
573 else if (state & CDIS_DISABLED) {
574 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
575 OffsetRect (rcText, 1, 1);
576 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
577 SetTextColor (hdc, comctl32_color.clr3dShadow);
578 OffsetRect (rcText, -1, -1);
580 else if (state & CDIS_INDETERMINATE) {
581 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
583 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
584 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
585 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
586 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
589 clrOld = SetTextColor (hdc, tbcd->clrText);
592 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
593 SetTextColor (hdc, clrOld);
594 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
596 SetBkColor (hdc, clrOldBk);
597 SetBkMode (hdc, oldBkMode);
599 SelectObject (hdc, hOldFont);
605 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
607 HDC hdc = tbcd->nmcd.hdc;
608 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
611 INT cx = lpRect->right - lpRect->left;
612 INT cy = lpRect->bottom - lpRect->top;
613 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
614 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
615 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
616 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
617 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
618 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
619 SetBkColor(hdc, clrBkOld);
620 SetTextColor(hdc, clrTextOld);
621 SelectObject (hdc, hbr);
625 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
628 HBITMAP hbmMask, hbmImage;
629 HDC hdcMask, hdcImage;
631 ImageList_GetIconSize(himl, &cx, &cy);
633 /* Create src image */
634 hdcImage = CreateCompatibleDC(hdc);
635 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
636 SelectObject(hdcImage, hbmImage);
637 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
638 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
641 hdcMask = CreateCompatibleDC(0);
642 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
643 SelectObject(hdcMask, hbmMask);
645 /* Remove the background and all white pixels */
646 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
647 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
648 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
649 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
651 /* draw the new mask 'etched' to hdc */
652 SetBkColor(hdc, RGB(255, 255, 255));
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
654 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
655 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
656 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
657 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
660 DeleteObject(hbmImage);
662 DeleteObject (hbmMask);
668 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
672 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
673 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
674 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
675 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
676 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
677 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
678 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
682 /* draws the image on a toolbar button */
684 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
686 HIMAGELIST himl = NULL;
687 BOOL draw_masked = FALSE;
690 UINT draw_flags = ILD_TRANSPARENT;
692 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
694 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
697 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
701 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
702 ((tbcd->nmcd.uItemState & CDIS_HOT)
703 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
705 /* if hot, attempt to draw with hot image list, if fails,
706 use default image list */
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
709 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
712 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
717 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
718 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
721 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
722 (tbcd->nmcd.uItemState & CDIS_MARKED))
723 draw_flags |= ILD_BLEND50;
725 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
726 index, himl, left, top, offset);
729 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
731 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
734 /* draws a blank frame for a toolbar button */
736 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
738 HDC hdc = tbcd->nmcd.hdc;
739 RECT rc = tbcd->nmcd.rc;
740 /* if the state is disabled or indeterminate then the button
741 * cannot have an interactive look like pressed or hot */
742 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
743 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
744 BOOL pressed_look = !non_interactive_state &&
745 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
746 (tbcd->nmcd.uItemState & CDIS_CHECKED));
748 /* app don't want us to draw any edges */
749 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
752 if (infoPtr->dwStyle & TBSTYLE_FLAT)
755 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
756 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
757 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
762 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
764 DrawEdge (hdc, &rc, EDGE_RAISED,
765 BF_SOFT | BF_RECT | BF_MIDDLE);
770 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
772 HDC hdc = tbcd->nmcd.hdc;
774 BOOL pressed = bDropDownPressed ||
775 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
777 if (infoPtr->dwStyle & TBSTYLE_FLAT)
780 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
781 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
782 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
783 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
784 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
789 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
791 DrawEdge (hdc, rcArrow, EDGE_RAISED,
792 BF_SOFT | BF_RECT | BF_MIDDLE);
796 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
798 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
800 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
801 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
804 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
807 /* draws a complete toolbar button */
809 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
811 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
812 DWORD dwStyle = infoPtr->dwStyle;
813 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
814 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
815 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
816 BOOL drawSepDropDownArrow = hasDropDownArrow &&
817 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
818 RECT rc, rcArrow, rcBitmap, rcText;
819 LPWSTR lpText = NULL;
824 HTHEME theme = GetWindowTheme (hwnd);
827 CopyRect (&rcArrow, &rc);
829 /* get a pointer to the text */
830 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
832 if (hasDropDownArrow)
836 if (dwStyle & TBSTYLE_FLAT)
837 right = max(rc.left, rc.right - DDARROW_WIDTH);
839 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
841 if (drawSepDropDownArrow)
844 rcArrow.left = right;
847 /* copy text & bitmap rects after adjusting for drop-down arrow
848 * so that text & bitmap is centred in the rectangle not containing
850 CopyRect(&rcText, &rc);
851 CopyRect(&rcBitmap, &rc);
853 /* Center the bitmap horizontally and vertically */
854 if (dwStyle & TBSTYLE_LIST)
857 infoPtr->nMaxTextRows > 0 &&
858 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
859 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
860 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
862 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
865 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
867 rcBitmap.top += infoPtr->szPadding.cy / 2;
869 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
870 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
871 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
872 TRACE("Text=%s\n", debugstr_w(lpText));
873 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
875 /* calculate text position */
878 rcText.left += GetSystemMetrics(SM_CXEDGE);
879 rcText.right -= GetSystemMetrics(SM_CXEDGE);
880 if (dwStyle & TBSTYLE_LIST)
882 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
883 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
887 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
888 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
890 rcText.top += infoPtr->szPadding.cy/2 + 2;
894 /* Initialize fields in all cases, because we use these later
895 * NOTE: applications can and do alter these to customize their
897 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
898 tbcd.clrText = comctl32_color.clrBtnText;
899 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
900 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
901 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
902 tbcd.clrMark = comctl32_color.clrHighlight;
903 tbcd.clrHighlightHotTrack = 0;
904 tbcd.nStringBkMode = TRANSPARENT;
905 tbcd.nHLStringBkMode = OPAQUE;
906 /* MSDN says that this is the text rectangle.
907 * But (why always a but) tracing of v5.7 of native shows
908 * that this is really a *relative* rectangle based on the
909 * the nmcd.rc. Also the left and top are always 0 ignoring
910 * any bitmap that might be present. */
911 tbcd.rcText.left = 0;
913 tbcd.rcText.right = rcText.right - rc.left;
914 tbcd.rcText.bottom = rcText.bottom - rc.top;
915 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
918 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
920 /* FIXME: what are these used for? */
924 /* Issue Item Prepaint notify */
925 infoPtr->dwItemCustDraw = 0;
926 infoPtr->dwItemCDFlag = 0;
927 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
929 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
930 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
931 tbcd.nmcd.lItemlParam = btnPtr->dwData;
932 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
933 /* reset these fields so the user can't alter the behaviour like native */
937 infoPtr->dwItemCustDraw = ntfret & 0xffff;
938 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
939 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
941 /* save the only part of the rect that the user can change */
942 rcText.right = tbcd.rcText.right + rc.left;
943 rcText.bottom = tbcd.rcText.bottom + rc.top;
947 if (btnPtr->fsStyle & BTNS_SEP) {
950 DrawThemeBackground (theme, hdc,
951 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
952 &tbcd.nmcd.rc, NULL);
955 /* with the FLAT style, iBitmap is the width and has already */
956 /* been taken into consideration in calculating the width */
957 /* so now we need to draw the vertical separator */
958 /* empirical tests show that iBitmap can/will be non-zero */
959 /* when drawing the vertical bar... */
960 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
961 if (btnPtr->fsStyle & BTNS_DROPDOWN)
962 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
964 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
966 else if (btnPtr->fsStyle != BTNS_SEP) {
967 FIXME("Draw some kind of separator: fsStyle=%x\n",
973 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
974 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
975 OffsetRect(&rcText, 1, 1);
977 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
978 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
979 TOOLBAR_DrawPattern (&rc, &tbcd);
981 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
982 && (tbcd.nmcd.uItemState & CDIS_HOT))
984 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
989 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
990 if (hasDropDownArrow)
991 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
992 SetBkColor(hdc, oldclr);
998 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
999 int stateId = TS_NORMAL;
1001 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1002 stateId = TS_DISABLED;
1003 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1004 stateId = TS_PRESSED;
1005 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1006 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1007 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1008 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1011 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1014 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1016 if (drawSepDropDownArrow)
1020 int stateId = TS_NORMAL;
1022 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1023 stateId = TS_DISABLED;
1024 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1025 stateId = TS_PRESSED;
1026 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1027 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1028 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1031 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1032 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1035 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1038 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1039 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1040 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1041 SetBkMode (hdc, oldBkMode);
1043 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1045 if (hasDropDownArrow && !drawSepDropDownArrow)
1047 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1050 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1052 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1054 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1062 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1064 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1065 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1072 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1075 TBUTTON_INFO *btnPtr;
1077 RECT rcTemp, rcClient;
1078 NMTBCUSTOMDRAW tbcd;
1081 /* the app has told us not to redraw the toolbar */
1082 if (!infoPtr->bDoRedraw)
1085 /* if imagelist belongs to the app, it can be changed
1086 by the app after setting it */
1087 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1089 infoPtr->nNumBitmaps = 0;
1090 for (i = 0; i < infoPtr->cimlDef; i++)
1091 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1094 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1096 /* change the imagelist icon size if we manage the list and it is necessary */
1097 TOOLBAR_CheckImageListIconSize(infoPtr);
1099 /* Send initial notify */
1100 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1101 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1102 tbcd.nmcd.hdc = hdc;
1103 tbcd.nmcd.rc = ps->rcPaint;
1104 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1105 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1107 GetClientRect(hwnd, &rcClient);
1109 /* redraw necessary buttons */
1110 btnPtr = infoPtr->buttons;
1111 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1114 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1116 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1117 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1121 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1122 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1124 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1127 /* draw insert mark if required */
1128 if (infoPtr->tbim.iButton != -1)
1130 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1132 rcInsertMark.top = rcButton.top;
1133 rcInsertMark.bottom = rcButton.bottom;
1134 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1135 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1137 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1138 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1141 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1143 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1144 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1145 tbcd.nmcd.hdc = hdc;
1146 tbcd.nmcd.rc = ps->rcPaint;
1147 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1151 /***********************************************************************
1152 * TOOLBAR_MeasureString
1154 * This function gets the width and height of a string in pixels. This
1155 * is done first by using GetTextExtentPoint to get the basic width
1156 * and height. The DrawText is called with DT_CALCRECT to get the exact
1157 * width. The reason is because the text may have more than one "&" (or
1158 * prefix characters as M$ likes to call them). The prefix character
1159 * indicates where the underline goes, except for the string "&&" which
1160 * is reduced to a single "&". GetTextExtentPoint does not process these
1161 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1164 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1165 HDC hdc, LPSIZE lpSize)
1172 if (infoPtr->nMaxTextRows > 0 &&
1173 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1174 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1175 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1177 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1179 if(lpText != NULL) {
1180 /* first get size of all the text */
1181 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1183 /* feed above size into the rectangle for DrawText */
1184 myrect.left = myrect.top = 0;
1185 myrect.right = lpSize->cx;
1186 myrect.bottom = lpSize->cy;
1188 /* Use DrawText to get true size as drawn (less pesky "&") */
1189 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1190 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1193 /* feed back to caller */
1194 lpSize->cx = myrect.right;
1195 lpSize->cy = myrect.bottom;
1199 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1202 /***********************************************************************
1203 * TOOLBAR_CalcStrings
1205 * This function walks through each string and measures it and returns
1206 * the largest height and width to caller.
1209 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1212 TBUTTON_INFO *btnPtr;
1221 if (infoPtr->nMaxTextRows == 0)
1225 hOldFont = SelectObject (hdc, infoPtr->hFont);
1227 if (infoPtr->nNumButtons == 0)
1231 GetTextMetricsW(hdc, &tm);
1232 lpSize->cy = tm.tmHeight;
1235 btnPtr = infoPtr->buttons;
1236 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1237 if(TOOLBAR_HasText(infoPtr, btnPtr))
1239 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1240 if (sz.cx > lpSize->cx)
1242 if (sz.cy > lpSize->cy)
1247 SelectObject (hdc, hOldFont);
1248 ReleaseDC (hwnd, hdc);
1250 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1253 /***********************************************************************
1254 * TOOLBAR_WrapToolbar
1256 * This function walks through the buttons and separators in the
1257 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1258 * wrapping should occur based on the width of the toolbar window.
1259 * It does *not* calculate button placement itself. That task
1260 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1261 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1262 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1264 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1265 * vertical toolbar lists.
1269 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1272 TBUTTON_INFO *btnPtr;
1275 BOOL bWrap, bButtonWrap;
1277 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1278 /* no layout is necessary. Applications may use this style */
1279 /* to perform their own layout on the toolbar. */
1280 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1281 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1283 btnPtr = infoPtr->buttons;
1284 x = infoPtr->nIndent;
1286 if (GetParent(hwnd))
1288 /* this can get the parents width, to know how far we can extend
1289 * this toolbar. We cannot use its height, as there may be multiple
1290 * toolbars in a rebar control
1292 GetClientRect( GetParent(hwnd), &rc );
1293 infoPtr->nWidth = rc.right - rc.left;
1297 GetWindowRect( hwnd, &rc );
1298 infoPtr->nWidth = rc.right - rc.left;
1301 bButtonWrap = FALSE;
1303 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1304 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1307 for (i = 0; i < infoPtr->nNumButtons; i++ )
1310 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1312 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1315 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1316 /* it is the actual width of the separator. This is used for */
1317 /* custom controls in toolbars. */
1319 /* BTNS_DROPDOWN separators are treated as buttons for */
1320 /* width. - GA 8/01 */
1321 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1322 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1323 cx = (btnPtr[i].iBitmap > 0) ?
1324 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1326 cx = infoPtr->nButtonWidth;
1328 /* Two or more adjacent separators form a separator group. */
1329 /* The first separator in a group should be wrapped to the */
1330 /* next row if the previous wrapping is on a button. */
1332 (btnPtr[i].fsStyle & BTNS_SEP) &&
1333 (i + 1 < infoPtr->nNumButtons ) &&
1334 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1336 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1337 btnPtr[i].fsState |= TBSTATE_WRAP;
1338 x = infoPtr->nIndent;
1340 bButtonWrap = FALSE;
1344 /* The layout makes sure the bitmap is visible, but not the button. */
1345 /* Test added to also wrap after a button that starts a row but */
1346 /* is bigger than the area. - GA 8/01 */
1347 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1348 > infoPtr->nWidth ) ||
1349 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1351 BOOL bFound = FALSE;
1353 /* If the current button is a separator and not hidden, */
1354 /* go to the next until it reaches a non separator. */
1355 /* Wrap the last separator if it is before a button. */
1356 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1357 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1358 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1359 i < infoPtr->nNumButtons )
1365 if( bFound && i < infoPtr->nNumButtons )
1368 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1369 i, btnPtr[i].fsStyle, x, cx);
1370 btnPtr[i].fsState |= TBSTATE_WRAP;
1371 x = infoPtr->nIndent;
1372 bButtonWrap = FALSE;
1375 else if ( i >= infoPtr->nNumButtons)
1378 /* If the current button is not a separator, find the last */
1379 /* separator and wrap it. */
1380 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1382 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1383 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1387 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1388 i, btnPtr[i].fsStyle, x, cx);
1389 x = infoPtr->nIndent;
1390 btnPtr[j].fsState |= TBSTATE_WRAP;
1391 bButtonWrap = FALSE;
1396 /* If no separator available for wrapping, wrap one of */
1397 /* non-hidden previous button. */
1401 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1403 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1408 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1409 i, btnPtr[i].fsStyle, x, cx);
1410 x = infoPtr->nIndent;
1411 btnPtr[j].fsState |= TBSTATE_WRAP;
1417 /* If all above failed, wrap the current button. */
1420 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1421 i, btnPtr[i].fsStyle, x, cx);
1422 btnPtr[i].fsState |= TBSTATE_WRAP;
1424 x = infoPtr->nIndent;
1425 if (btnPtr[i].fsStyle & BTNS_SEP )
1426 bButtonWrap = FALSE;
1432 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1433 i, btnPtr[i].fsStyle, x, cx);
1440 /***********************************************************************
1441 * TOOLBAR_MeasureButton
1443 * Calculates the width and height required for a button. Used in
1444 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1445 * the width of buttons that are autosized.
1447 * Note that it would have been rather elegant to use one piece of code for
1448 * both the laying out of the toolbar and for controlling where button parts
1449 * are drawn, but the native control has inconsistencies between the two that
1450 * prevent this from being effectively. These inconsistencies can be seen as
1451 * artefacts where parts of the button appear outside of the bounding button
1454 * There are several cases for the calculation of the button dimensions and
1455 * button part positioning:
1462 * +--------------------------------------------------------+ ^
1464 * | | pad.cy / 2 | centred | |
1465 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1466 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1467 * | |<------------>| | | | |
1468 * | +--------------+ +------------+ | |
1469 * |<-------------------------------------->| | |
1470 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1472 * +--------------------------------------------------------+ -
1473 * <-------------------------------------------------------->
1474 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1476 * Without Bitmap (I_IMAGENONE):
1478 * +-----------------------------------+ ^
1480 * | | centred | | LISTPAD_CY +
1481 * | +------------+ | | szText.cy
1484 * | +------------+ | |
1485 * |<----------------->| | |
1486 * | cxedge |<-----------> | |
1488 * +-----------------------------------+ -
1489 * <----------------------------------->
1490 * szText.cx + pad.cx
1494 * +--------------------------------------+ ^
1496 * | | padding.cy/2 | | DEFPAD_CY +
1497 * | +------------+ | | nBitmapHeight
1500 * | +------------+ | |
1501 * |<------------------->| | |
1502 * | cxedge + iListGap/2 |<-----------> | |
1503 * | nBitmapWidth | |
1504 * +--------------------------------------+ -
1505 * <-------------------------------------->
1506 * 2*cxedge + nBitmapWidth + iListGap
1513 * +-----------------------------------+ ^
1515 * | | pad.cy / 2 | | nBitmapHeight +
1516 * | - | | szText.cy +
1517 * | +------------+ | | DEFPAD_CY + 1
1518 * | centred | Bitmap | | |
1519 * |<----------------->| | | |
1520 * | +------------+ | |
1524 * | centred +---------------+ | |
1525 * |<--------------->| Text | | |
1526 * | +---------------+ | |
1527 * +-----------------------------------+ -
1528 * <----------------------------------->
1529 * pad.cx + max(nBitmapWidth, szText.cx)
1531 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1533 * +---------------------------------------+ ^
1535 * | | 2 + pad.cy / 2 | |
1536 * | - | | szText.cy +
1537 * | centred +-----------------+ | | pad.cy + 2
1538 * |<--------------->| Text | | |
1539 * | +-----------------+ | |
1541 * +---------------------------------------+ -
1542 * <--------------------------------------->
1543 * 2*cxedge + pad.cx + szText.cx
1546 * As for with bitmaps, but with szText.cx zero.
1548 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1551 if (infoPtr->dwStyle & TBSTYLE_LIST)
1553 /* set button height from bitmap / text height... */
1554 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1557 /* ... add on the necessary padding */
1558 if (bValidImageList)
1561 sizeButton.cy += DEFPAD_CY;
1563 sizeButton.cy += LISTPAD_CY;
1566 sizeButton.cy += infoPtr->szPadding.cy;
1568 /* calculate button width */
1571 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1572 infoPtr->nBitmapWidth + infoPtr->iListGap;
1573 if (sizeString.cx > 0)
1574 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1577 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1583 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1584 sizeString.cy + DEFPAD_CY;
1585 sizeButton.cx = infoPtr->szPadding.cx +
1586 max(sizeString.cx, infoPtr->nBitmapWidth);
1590 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1591 NONLIST_NOTEXT_OFFSET;
1592 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1593 infoPtr->szPadding.cx + sizeString.cx;
1600 /***********************************************************************
1601 * TOOLBAR_CalcToolbar
1603 * This function calculates button and separator placement. It first
1604 * calculates the button sizes, gets the toolbar window width and then
1605 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1606 * on. It assigns a new location to each item and sends this location to
1607 * the tooltip window if appropriate. Finally, it updates the rcBound
1608 * rect and calculates the new required toolbar window height.
1611 TOOLBAR_CalcToolbar (HWND hwnd)
1613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1614 DWORD dwStyle = infoPtr->dwStyle;
1615 TBUTTON_INFO *btnPtr;
1616 INT i, nRows, nSepRows;
1618 SIZE sizeString, sizeButton;
1620 BOOL validImageList = FALSE;
1621 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1623 TOOLBAR_CalcStrings (hwnd, &sizeString);
1625 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1627 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1628 validImageList = TRUE;
1629 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1630 infoPtr->nButtonWidth = sizeButton.cx;
1631 infoPtr->nButtonHeight = sizeButton.cy;
1633 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1634 infoPtr->nButtonWidth = infoPtr->cxMin;
1635 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1636 infoPtr->nButtonWidth = infoPtr->cxMax;
1638 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1640 x = infoPtr->nIndent;
1641 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1646 /* from above, minimum is a button, and possible text */
1647 cx = infoPtr->nButtonWidth;
1648 cy = infoPtr->nButtonHeight;
1650 nRows = nSepRows = 0;
1652 infoPtr->rcBound.top = y;
1653 infoPtr->rcBound.left = x;
1654 infoPtr->rcBound.bottom = y + cy;
1655 infoPtr->rcBound.right = x;
1657 btnPtr = infoPtr->buttons;
1659 TRACE("cy=%d\n", cy);
1661 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1664 if (btnPtr->fsState & TBSTATE_HIDDEN)
1666 SetRectEmpty (&btnPtr->rect);
1670 cy = infoPtr->nButtonHeight;
1672 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1673 /* it is the actual width of the separator. This is used for */
1674 /* custom controls in toolbars. */
1675 if (btnPtr->fsStyle & BTNS_SEP) {
1676 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1677 cy = (btnPtr->iBitmap > 0) ?
1678 btnPtr->iBitmap : SEPARATOR_WIDTH;
1679 cx = infoPtr->nButtonWidth;
1682 cx = (btnPtr->iBitmap > 0) ?
1683 btnPtr->iBitmap : SEPARATOR_WIDTH;
1689 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1690 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1697 hOldFont = SelectObject (hdc, infoPtr->hFont);
1699 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1701 SelectObject (hdc, hOldFont);
1702 ReleaseDC (hwnd, hdc);
1704 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1705 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1710 cx = infoPtr->nButtonWidth;
1712 /* if size has been set manually then don't add on extra space
1713 * for the drop down arrow */
1714 if (!btnPtr->cx && hasDropDownArrows &&
1715 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1716 cx += DDARROW_WIDTH;
1718 if (btnPtr->fsState & TBSTATE_WRAP )
1721 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1723 if (infoPtr->rcBound.left > x)
1724 infoPtr->rcBound.left = x;
1725 if (infoPtr->rcBound.right < x + cx)
1726 infoPtr->rcBound.right = x + cx;
1727 if (infoPtr->rcBound.bottom < y + cy)
1728 infoPtr->rcBound.bottom = y + cy;
1730 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1732 /* btnPtr->nRow is zero based. The space between the rows is */
1733 /* also considered as a row. */
1734 btnPtr->nRow = nRows + nSepRows;
1736 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1737 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1742 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1746 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1747 /* it is the actual width of the separator. This is used for */
1748 /* custom controls in toolbars. */
1749 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1750 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1751 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1755 /* nSepRows is used to calculate the extra height follwoing */
1759 x = infoPtr->nIndent;
1761 /* Increment row number unless this is the last button */
1762 /* and it has Wrap set. */
1763 if (i != infoPtr->nNumButtons-1)
1770 /* infoPtr->nRows is the number of rows on the toolbar */
1771 infoPtr->nRows = nRows + nSepRows + 1;
1773 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1778 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1780 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1781 TBUTTON_INFO *btnPtr;
1784 btnPtr = infoPtr->buttons;
1785 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1786 if (btnPtr->fsState & TBSTATE_HIDDEN)
1789 if (btnPtr->fsStyle & BTNS_SEP) {
1790 if (PtInRect (&btnPtr->rect, *lpPt)) {
1791 TRACE(" ON SEPARATOR %d!\n", i);
1796 if (PtInRect (&btnPtr->rect, *lpPt)) {
1797 TRACE(" ON BUTTON %d!\n", i);
1803 TRACE(" NOWHERE!\n");
1804 return TOOLBAR_NOWHERE;
1809 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1811 TBUTTON_INFO *btnPtr;
1814 if (CommandIsIndex) {
1815 TRACE("command is really index command=%d\n", idCommand);
1816 if (idCommand >= infoPtr->nNumButtons) return -1;
1819 btnPtr = infoPtr->buttons;
1820 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1821 if (btnPtr->idCommand == idCommand) {
1822 TRACE("command=%d index=%d\n", idCommand, i);
1826 TRACE("no index found for command=%d\n", idCommand);
1832 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1834 TBUTTON_INFO *btnPtr;
1837 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1840 /* check index button */
1841 btnPtr = &infoPtr->buttons[nIndex];
1842 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1843 if (btnPtr->fsState & TBSTATE_CHECKED)
1847 /* check previous buttons */
1848 nRunIndex = nIndex - 1;
1849 while (nRunIndex >= 0) {
1850 btnPtr = &infoPtr->buttons[nRunIndex];
1851 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1852 if (btnPtr->fsState & TBSTATE_CHECKED)
1860 /* check next buttons */
1861 nRunIndex = nIndex + 1;
1862 while (nRunIndex < infoPtr->nNumButtons) {
1863 btnPtr = &infoPtr->buttons[nRunIndex];
1864 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1865 if (btnPtr->fsState & TBSTATE_CHECKED)
1878 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1879 WPARAM wParam, LPARAM lParam)
1885 msg.wParam = wParam;
1886 msg.lParam = lParam;
1887 msg.time = GetMessageTime ();
1888 msg.pt.x = LOWORD(GetMessagePos ());
1889 msg.pt.y = HIWORD(GetMessagePos ());
1891 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1895 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1897 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1900 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1901 ti.cbSize = sizeof (TTTOOLINFOW);
1902 ti.hwnd = infoPtr->hwndSelf;
1903 ti.uId = button->idCommand;
1905 ti.lpszText = LPSTR_TEXTCALLBACKW;
1906 /* ti.lParam = random value from the stack? */
1908 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1914 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1916 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1919 ZeroMemory(&ti, sizeof(ti));
1920 ti.cbSize = sizeof(ti);
1921 ti.hwnd = infoPtr->hwndSelf;
1922 ti.uId = button->idCommand;
1924 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1928 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1930 /* Set the toolTip only for non-hidden, non-separator button */
1931 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1935 ZeroMemory(&ti, sizeof(ti));
1936 ti.cbSize = sizeof(ti);
1937 ti.hwnd = infoPtr->hwndSelf;
1938 ti.uId = button->idCommand;
1939 ti.rect = button->rect;
1940 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1944 /* Creates the tooltip control */
1946 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1949 NMTOOLTIPSCREATED nmttc;
1951 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
1952 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1953 infoPtr->hwndSelf, 0, 0, 0);
1955 if (!infoPtr->hwndToolTip)
1958 /* Send NM_TOOLTIPSCREATED notification */
1959 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1960 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1962 for (i = 0; i < infoPtr->nNumButtons; i++)
1964 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1965 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1969 /* keeps available button list box sorted by button id */
1970 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1974 PCUSTOMBUTTON btnInfo;
1975 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1977 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1979 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1981 /* position 0 is always separator */
1982 for (i = 1; i < count; i++)
1984 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1985 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1987 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1988 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1992 /* id higher than all others add to end */
1993 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1994 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1997 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2001 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2003 if (nIndexFrom == nIndexTo)
2006 /* MSDN states that iItem is the index of the button, rather than the
2007 * command ID as used by every other NMTOOLBAR notification */
2008 nmtb.iItem = nIndexFrom;
2009 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2011 PCUSTOMBUTTON btnInfo;
2013 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2014 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2016 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2018 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2019 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2020 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2021 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2024 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2026 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2028 /* last item is always separator, so -2 instead of -1 */
2029 if (nIndexTo >= (count - 2))
2030 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2032 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2034 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2035 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2037 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2041 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2045 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2047 /* MSDN states that iItem is the index of the button, rather than the
2048 * command ID as used by every other NMTOOLBAR notification */
2049 nmtb.iItem = nIndexAvail;
2050 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2052 PCUSTOMBUTTON btnInfo;
2054 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2055 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2056 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2058 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2060 if (nIndexAvail != 0) /* index == 0 indicates separator */
2062 /* remove from 'available buttons' list */
2063 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2064 if (nIndexAvail == count-1)
2065 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2067 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2071 PCUSTOMBUTTON btnNew;
2073 /* duplicate 'separator' button */
2074 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2075 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2079 /* insert into 'toolbar button' list */
2080 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2081 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2083 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2085 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2089 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2091 PCUSTOMBUTTON btnInfo;
2092 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2094 TRACE("Remove: index %d\n", index);
2096 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2098 /* send TBN_QUERYDELETE notification */
2099 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2103 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2104 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2106 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2108 /* insert into 'available button' list */
2109 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2110 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2114 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2118 /* drag list notification function for toolbar buttons list box */
2119 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2121 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2122 switch (pDLI->uNotification)
2126 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2127 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2128 /* no dragging for last item (separator) */
2129 if (nCurrentItem >= (nCount - 1)) return FALSE;
2134 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2135 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2136 /* no dragging past last item (separator) */
2137 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2139 DrawInsert(hwnd, hwndList, nCurrentItem);
2140 /* FIXME: native uses "move button" cursor */
2141 return DL_COPYCURSOR;
2144 /* not over toolbar buttons list */
2145 if (nCurrentItem < 0)
2147 POINT ptWindow = pDLI->ptCursor;
2148 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2149 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2150 /* over available buttons list? */
2151 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2152 /* FIXME: native uses "move button" cursor */
2153 return DL_COPYCURSOR;
2155 /* clear drag arrow */
2156 DrawInsert(hwnd, hwndList, -1);
2157 return DL_STOPCURSOR;
2161 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2162 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2163 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2164 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2166 /* clear drag arrow */
2167 DrawInsert(hwnd, hwndList, -1);
2169 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2171 /* not over toolbar buttons list */
2174 POINT ptWindow = pDLI->ptCursor;
2175 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2176 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2177 /* over available buttons list? */
2178 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2179 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2184 /* Clear drag arrow */
2185 DrawInsert(hwnd, hwndList, -1);
2192 /* drag list notification function for available buttons list box */
2193 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2195 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2196 switch (pDLI->uNotification)
2202 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2203 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2204 /* no dragging past last item (separator) */
2205 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2207 DrawInsert(hwnd, hwndList, nCurrentItem);
2208 /* FIXME: native uses "move button" cursor */
2209 return DL_COPYCURSOR;
2212 /* not over toolbar buttons list */
2213 if (nCurrentItem < 0)
2215 POINT ptWindow = pDLI->ptCursor;
2216 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2217 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2218 /* over available buttons list? */
2219 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2220 /* FIXME: native uses "move button" cursor */
2221 return DL_COPYCURSOR;
2223 /* clear drag arrow */
2224 DrawInsert(hwnd, hwndList, -1);
2225 return DL_STOPCURSOR;
2229 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2230 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2231 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2232 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2234 /* clear drag arrow */
2235 DrawInsert(hwnd, hwndList, -1);
2237 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2241 /* Clear drag arrow */
2242 DrawInsert(hwnd, hwndList, -1);
2248 extern UINT uDragListMessage;
2250 /***********************************************************************
2251 * TOOLBAR_CustomizeDialogProc
2252 * This function implements the toolbar customization dialog.
2254 static INT_PTR CALLBACK
2255 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2257 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2258 PCUSTOMBUTTON btnInfo;
2260 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2265 custInfo = (PCUSTDLG_INFO)lParam;
2266 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2273 NMTBINITCUSTOMIZE nmtbic;
2275 infoPtr = custInfo->tbInfo;
2277 /* send TBN_QUERYINSERT notification */
2278 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2280 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2283 nmtbic.hwndDialog = hwnd;
2284 /* Send TBN_INITCUSTOMIZE notification */
2285 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2288 TRACE("TBNRF_HIDEHELP requested\n");
2289 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2292 /* add items to 'toolbar buttons' list and check if removable */
2293 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2295 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2296 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2297 btnInfo->btn.fsStyle = BTNS_SEP;
2298 btnInfo->bVirtual = FALSE;
2299 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2301 /* send TBN_QUERYDELETE notification */
2302 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2304 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2305 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2308 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2310 /* insert separator button into 'available buttons' list */
2311 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2312 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2313 btnInfo->btn.fsStyle = BTNS_SEP;
2314 btnInfo->bVirtual = FALSE;
2315 btnInfo->bRemovable = TRUE;
2316 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2317 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2318 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2320 /* insert all buttons into dsa */
2323 /* send TBN_GETBUTTONINFO notification */
2326 nmtb.pszText = Buffer;
2329 /* Clear previous button's text */
2330 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2332 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2335 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2336 nmtb.tbButton.fsStyle, i,
2337 nmtb.tbButton.idCommand,
2338 nmtb.tbButton.iString,
2339 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2342 /* insert button into the apropriate list */
2343 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2346 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2347 btnInfo->bVirtual = FALSE;
2348 btnInfo->bRemovable = TRUE;
2352 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2353 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2356 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2357 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2359 if (lstrlenW(nmtb.pszText))
2360 lstrcpyW(btnInfo->text, nmtb.pszText);
2361 else if (nmtb.tbButton.iString >= 0 &&
2362 nmtb.tbButton.iString < infoPtr->nNumStrings)
2364 lstrcpyW(btnInfo->text,
2365 infoPtr->strings[nmtb.tbButton.iString]);
2370 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2373 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2375 /* select first item in the 'available' list */
2376 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2378 /* append 'virtual' separator button to the 'toolbar buttons' list */
2379 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2380 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2381 btnInfo->btn.fsStyle = BTNS_SEP;
2382 btnInfo->bVirtual = TRUE;
2383 btnInfo->bRemovable = FALSE;
2384 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2385 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2386 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2388 /* select last item in the 'toolbar' list */
2389 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2390 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2392 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2393 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2395 /* set focus and disable buttons */
2396 PostMessageW (hwnd, WM_USER, 0, 0);
2401 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2402 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2403 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2404 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2408 EndDialog(hwnd, FALSE);
2412 switch (LOWORD(wParam))
2414 case IDC_TOOLBARBTN_LBOX:
2415 if (HIWORD(wParam) == LBN_SELCHANGE)
2417 PCUSTOMBUTTON btnInfo;
2422 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2423 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2425 /* send TBN_QUERYINSERT notification */
2427 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2429 /* get list box item */
2430 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2432 if (index == (count - 1))
2434 /* last item (virtual separator) */
2435 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2436 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2438 else if (index == (count - 2))
2440 /* second last item (last non-virtual item) */
2441 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2442 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2444 else if (index == 0)
2447 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2448 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2453 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2456 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2460 case IDC_MOVEUP_BTN:
2462 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2463 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2467 case IDC_MOVEDN_BTN: /* move down */
2469 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2470 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2474 case IDC_REMOVE_BTN: /* remove button */
2476 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2478 if (LB_ERR == index)
2481 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2485 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2488 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2491 case IDOK: /* Add button */
2496 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2497 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2499 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2504 EndDialog(hwnd, FALSE);
2514 /* delete items from 'toolbar buttons' listbox*/
2515 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2516 for (i = 0; i < count; i++)
2518 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2520 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2522 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2525 /* delete items from 'available buttons' listbox*/
2526 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2527 for (i = 0; i < count; i++)
2529 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2531 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2533 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2538 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2540 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2545 COLORREF oldText = 0;
2549 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2550 if (btnInfo == NULL)
2552 FIXME("btnInfo invalid!\n");
2556 /* set colors and select objects */
2557 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2558 if (btnInfo->bVirtual)
2559 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2561 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2562 hPen = CreatePen( PS_SOLID, 1,
2563 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2564 hOldPen = SelectObject (lpdis->hDC, hPen );
2565 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2567 /* fill background rectangle */
2568 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2569 lpdis->rcItem.right, lpdis->rcItem.bottom);
2571 /* calculate button and text rectangles */
2572 CopyRect (&rcButton, &lpdis->rcItem);
2573 InflateRect (&rcButton, -1, -1);
2574 CopyRect (&rcText, &rcButton);
2575 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2576 rcText.left = rcButton.right + 2;
2578 /* draw focus rectangle */
2579 if (lpdis->itemState & ODS_FOCUS)
2580 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2583 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2584 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2586 /* draw image and text */
2587 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2588 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2589 btnInfo->btn.iBitmap));
2590 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2591 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2593 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2594 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2596 /* delete objects and reset colors */
2597 SelectObject (lpdis->hDC, hOldBrush);
2598 SelectObject (lpdis->hDC, hOldPen);
2599 SetBkColor (lpdis->hDC, oldBk);
2600 SetTextColor (lpdis->hDC, oldText);
2601 DeleteObject( hPen );
2606 case WM_MEASUREITEM:
2607 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2609 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2611 lpmis->itemHeight = 15 + 8; /* default height */
2618 if (uDragListMessage && (uMsg == uDragListMessage))
2620 if (wParam == IDC_TOOLBARBTN_LBOX)
2622 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2623 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2624 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2627 else if (wParam == IDC_AVAILBTN_LBOX)
2629 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2630 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2631 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2640 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2643 INT nCountBefore = ImageList_GetImageCount(himlDef);
2649 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2650 /* Add bitmaps to the default image list */
2651 if (bitmap->hInst == NULL) /* a handle was passed */
2654 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2655 HDC hdcImage, hdcBitmap;
2657 /* copy the bitmap before adding it so that the user's bitmap
2658 * doesn't get modified.
2660 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2662 hdcImage = CreateCompatibleDC(0);
2663 hdcBitmap = CreateCompatibleDC(0);
2665 /* create new bitmap */
2666 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2667 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2668 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2670 /* Copy the user's image */
2671 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2672 hdcBitmap, 0, 0, SRCCOPY);
2674 SelectObject (hdcImage, hOldBitmapLoad);
2675 SelectObject (hdcBitmap, hOldBitmapBitmap);
2676 DeleteDC (hdcImage);
2677 DeleteDC (hdcBitmap);
2680 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2682 /* enlarge the bitmap if needed */
2683 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2684 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2686 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2687 DeleteObject(hbmLoad);
2691 nCountAfter = ImageList_GetImageCount(himlDef);
2692 nAdded = nCountAfter - nCountBefore;
2693 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2695 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2696 } else if (nAdded > (INT)bitmap->nButtons) {
2697 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2698 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2701 infoPtr->nNumBitmaps += nAdded;
2706 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2713 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2714 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2716 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2718 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2721 TRACE("Update icon size: %dx%d -> %dx%d\n",
2722 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2724 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2725 ILC_COLORDDB|ILC_MASK, 8, 2);
2726 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2727 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2728 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2729 infoPtr->himlInt = himlNew;
2731 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2732 ImageList_Destroy(himlDef);
2735 /***********************************************************************
2736 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2740 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2743 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2748 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2752 if (lpAddBmp->hInst == HINST_COMMCTRL)
2754 info.hInst = COMCTL32_hModule;
2755 switch (lpAddBmp->nID)
2757 case IDB_STD_SMALL_COLOR:
2759 info.nID = IDB_STD_SMALL;
2761 case IDB_STD_LARGE_COLOR:
2763 info.nID = IDB_STD_LARGE;
2765 case IDB_VIEW_SMALL_COLOR:
2767 info.nID = IDB_VIEW_SMALL;
2769 case IDB_VIEW_LARGE_COLOR:
2771 info.nID = IDB_VIEW_LARGE;
2773 case IDB_HIST_SMALL_COLOR:
2775 info.nID = IDB_HIST_SMALL;
2777 case IDB_HIST_LARGE_COLOR:
2779 info.nID = IDB_HIST_LARGE;
2785 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2787 /* Windows resize all the buttons to the size of a newly added standard image */
2788 if (lpAddBmp->nID & 1)
2791 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2792 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2794 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2795 MAKELPARAM((WORD)24, (WORD)24));
2796 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2797 MAKELPARAM((WORD)31, (WORD)30));
2802 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2803 MAKELPARAM((WORD)16, (WORD)16));
2804 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2805 MAKELPARAM((WORD)22, (WORD)22));
2808 TOOLBAR_CalcToolbar (hwnd);
2812 info.nButtons = (INT)wParam;
2813 info.hInst = lpAddBmp->hInst;
2814 info.nID = lpAddBmp->nID;
2815 TRACE("adding %d bitmaps!\n", info.nButtons);
2818 /* check if the bitmap is already loaded and compute iSumButtons */
2820 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2822 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2823 infoPtr->bitmaps[i].nID == info.nID)
2825 iSumButtons += infoPtr->bitmaps[i].nButtons;
2828 if (!infoPtr->cimlDef) {
2829 /* create new default image list */
2830 TRACE ("creating default image list!\n");
2832 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2833 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2834 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2835 infoPtr->himlInt = himlDef;
2838 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2842 WARN("No default image list available\n");
2846 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2849 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2850 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2851 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2852 infoPtr->nNumBitmapInfos++;
2853 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2855 InvalidateRect(hwnd, NULL, TRUE);
2861 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2864 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2865 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2867 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2869 nAddButtons = (UINT)wParam;
2870 nOldButtons = infoPtr->nNumButtons;
2871 nNewButtons = nOldButtons + nAddButtons;
2873 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2874 infoPtr->nNumButtons = nNewButtons;
2876 /* insert new button data */
2877 for (nCount = 0; nCount < nAddButtons; nCount++) {
2878 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2879 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2880 btnPtr->idCommand = lpTbb[nCount].idCommand;
2881 btnPtr->fsState = lpTbb[nCount].fsState;
2882 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2883 btnPtr->dwData = lpTbb[nCount].dwData;
2884 btnPtr->bHot = FALSE;
2885 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2888 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2890 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2893 btnPtr->iString = lpTbb[nCount].iString;
2895 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2898 TOOLBAR_CalcToolbar (hwnd);
2899 TOOLBAR_AutoSize (hwnd);
2901 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2903 InvalidateRect(hwnd, NULL, TRUE);
2910 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2912 #define MAX_RESOURCE_STRING_LENGTH 512
2913 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2914 INT nIndex = infoPtr->nNumStrings;
2916 if ((wParam) && (HIWORD(lParam) == 0)) {
2917 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2922 TRACE("adding string from resource!\n");
2924 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2925 szString, MAX_RESOURCE_STRING_LENGTH);
2927 TRACE("len=%d %s\n", len, debugstr_w(szString));
2928 if (len == 0 || len == 1)
2931 TRACE("Delimiter: 0x%x\n", *szString);
2932 delimiter = *szString;
2935 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2937 if (next_delim + 1 >= szString + len)
2939 /* this may happen if delimiter == '\0' or if the last char is a
2940 * delimiter (then it is ignored like the native does) */
2944 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2945 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2946 infoPtr->nNumStrings++;
2952 LPWSTR p = (LPWSTR)lParam;
2957 TRACE("adding string(s) from array!\n");
2961 TRACE("len=%d %s\n", len, debugstr_w(p));
2962 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2963 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2964 infoPtr->nNumStrings++;
2975 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2982 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2983 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2989 TRACE("adding string(s) from array!\n");
2990 nIndex = infoPtr->nNumStrings;
2993 TRACE("len=%d \"%s\"\n", len, p);
2995 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2996 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2997 infoPtr->nNumStrings++;
3007 TOOLBAR_AutoSize (HWND hwnd)
3009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3015 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3017 parent = GetParent (hwnd);
3019 if (!parent || !infoPtr->bDoRedraw)
3022 GetClientRect(parent, &parent_rect);
3024 x = parent_rect.left;
3025 y = parent_rect.top;
3027 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3029 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3030 cx = parent_rect.right - parent_rect.left;
3032 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3034 TOOLBAR_CalcToolbar(hwnd);
3035 InvalidateRect( hwnd, NULL, TRUE );
3038 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3041 UINT uPosFlags = SWP_NOZORDER;
3043 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3045 GetWindowRect(hwnd, &window_rect);
3046 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3047 y = window_rect.top;
3049 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3051 GetWindowRect(hwnd, &window_rect);
3052 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3055 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3056 uPosFlags |= SWP_NOMOVE;
3058 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3059 cy += GetSystemMetrics(SM_CYEDGE);
3061 if (infoPtr->dwStyle & WS_BORDER)
3063 x = y = 1; /* FIXME: this looks wrong */
3064 cy += GetSystemMetrics(SM_CYEDGE);
3065 cx += GetSystemMetrics(SM_CXEDGE);
3068 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3076 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3080 return infoPtr->nNumButtons;
3085 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 infoPtr->dwStructSize = (DWORD)wParam;
3096 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 TBUTTON_INFO *btnPtr;
3102 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3108 btnPtr = &infoPtr->buttons[nIndex];
3109 btnPtr->iBitmap = LOWORD(lParam);
3111 /* we HAVE to erase the background, the new bitmap could be */
3113 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3120 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3123 TBUTTON_INFO *btnPtr;
3126 BOOL bChecked = FALSE;
3128 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3130 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3135 btnPtr = &infoPtr->buttons[nIndex];
3137 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3139 if (LOWORD(lParam) == FALSE)
3140 btnPtr->fsState &= ~TBSTATE_CHECKED;
3142 if (btnPtr->fsStyle & BTNS_GROUP) {
3144 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3145 if (nOldIndex == nIndex)
3147 if (nOldIndex != -1)
3148 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3150 btnPtr->fsState |= TBSTATE_CHECKED;
3153 if( bChecked != LOWORD(lParam) )
3155 if (nOldIndex != -1)
3156 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3157 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3160 /* FIXME: Send a WM_NOTIFY?? */
3167 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3171 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3176 TOOLBAR_Customize (HWND hwnd)
3178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3179 CUSTDLG_INFO custInfo;
3185 custInfo.tbInfo = infoPtr;
3186 custInfo.tbHwnd = hwnd;
3188 /* send TBN_BEGINADJUST notification */
3189 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3191 if (!(hRes = FindResourceW (COMCTL32_hModule,
3192 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3193 (LPWSTR)RT_DIALOG)))
3196 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3199 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3200 (LPCDLGTEMPLATEW)template,
3202 TOOLBAR_CustomizeDialogProc,
3205 /* send TBN_ENDADJUST notification */
3206 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3213 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3216 INT nIndex = (INT)wParam;
3218 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3220 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3223 memset(&nmtb, 0, sizeof(nmtb));
3224 nmtb.iItem = btnPtr->idCommand;
3225 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3226 nmtb.tbButton.idCommand = btnPtr->idCommand;
3227 nmtb.tbButton.fsState = btnPtr->fsState;
3228 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3229 nmtb.tbButton.dwData = btnPtr->dwData;
3230 nmtb.tbButton.iString = btnPtr->iString;
3231 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3233 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3235 if (infoPtr->nNumButtons == 1) {
3236 TRACE(" simple delete!\n");
3237 Free (infoPtr->buttons);
3238 infoPtr->buttons = NULL;
3239 infoPtr->nNumButtons = 0;
3242 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3243 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3245 infoPtr->nNumButtons--;
3246 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3248 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3249 nIndex * sizeof(TBUTTON_INFO));
3252 if (nIndex < infoPtr->nNumButtons) {
3253 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3254 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3260 TOOLBAR_CalcToolbar (hwnd);
3262 InvalidateRect (hwnd, NULL, TRUE);
3269 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3272 TBUTTON_INFO *btnPtr;
3276 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3278 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3283 btnPtr = &infoPtr->buttons[nIndex];
3285 bState = btnPtr->fsState & TBSTATE_ENABLED;
3287 /* update the toolbar button state */
3288 if(LOWORD(lParam) == FALSE) {
3289 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3291 btnPtr->fsState |= TBSTATE_ENABLED;
3294 /* redraw the button only if the state of the button changed */
3295 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3296 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3302 static inline LRESULT
3303 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3307 return infoPtr->bAnchor;
3312 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3321 return infoPtr->buttons[nIndex].iBitmap;
3325 static inline LRESULT
3326 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3328 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3333 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3335 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3336 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3337 INT nIndex = (INT)wParam;
3338 TBUTTON_INFO *btnPtr;
3343 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3346 btnPtr = &infoPtr->buttons[nIndex];
3347 lpTbb->iBitmap = btnPtr->iBitmap;
3348 lpTbb->idCommand = btnPtr->idCommand;
3349 lpTbb->fsState = btnPtr->fsState;
3350 lpTbb->fsStyle = btnPtr->fsStyle;
3351 lpTbb->bReserved[0] = 0;
3352 lpTbb->bReserved[1] = 0;
3353 lpTbb->dwData = btnPtr->dwData;
3354 lpTbb->iString = btnPtr->iString;
3361 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3363 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3364 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3365 TBUTTON_INFO *btnPtr;
3368 if (lpTbInfo == NULL)
3370 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3373 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3374 lpTbInfo->dwMask & 0x80000000);
3378 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3380 if (lpTbInfo->dwMask & TBIF_COMMAND)
3381 lpTbInfo->idCommand = btnPtr->idCommand;
3382 if (lpTbInfo->dwMask & TBIF_IMAGE)
3383 lpTbInfo->iImage = btnPtr->iBitmap;
3384 if (lpTbInfo->dwMask & TBIF_LPARAM)
3385 lpTbInfo->lParam = btnPtr->dwData;
3386 if (lpTbInfo->dwMask & TBIF_SIZE)
3387 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3388 if (lpTbInfo->dwMask & TBIF_STATE)
3389 lpTbInfo->fsState = btnPtr->fsState;
3390 if (lpTbInfo->dwMask & TBIF_STYLE)
3391 lpTbInfo->fsStyle = btnPtr->fsStyle;
3392 if (lpTbInfo->dwMask & TBIF_TEXT) {
3393 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3394 can't use TOOLBAR_GetText here */
3396 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3397 lpText = (LPWSTR)btnPtr->iString;
3398 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3400 lpTbInfo->pszText[0] = '\0';
3407 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3411 TBUTTON_INFO *btnPtr;
3414 if (lpTbInfo == NULL)
3416 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3419 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3420 lpTbInfo->dwMask & 0x80000000);
3424 btnPtr = &infoPtr->buttons[nIndex];
3429 if (lpTbInfo->dwMask & TBIF_COMMAND)
3430 lpTbInfo->idCommand = btnPtr->idCommand;
3431 if (lpTbInfo->dwMask & TBIF_IMAGE)
3432 lpTbInfo->iImage = btnPtr->iBitmap;
3433 if (lpTbInfo->dwMask & TBIF_LPARAM)
3434 lpTbInfo->lParam = btnPtr->dwData;
3435 if (lpTbInfo->dwMask & TBIF_SIZE)
3436 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3437 if (lpTbInfo->dwMask & TBIF_STATE)
3438 lpTbInfo->fsState = btnPtr->fsState;
3439 if (lpTbInfo->dwMask & TBIF_STYLE)
3440 lpTbInfo->fsStyle = btnPtr->fsStyle;
3441 if (lpTbInfo->dwMask & TBIF_TEXT) {
3442 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3443 can't use TOOLBAR_GetText here */
3445 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3446 lpText = (LPWSTR)btnPtr->iString;
3447 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3449 lpTbInfo->pszText[0] = '\0';
3457 TOOLBAR_GetButtonSize (HWND hwnd)
3459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3461 if (infoPtr->nNumButtons > 0)
3462 return MAKELONG((WORD)infoPtr->nButtonWidth,
3463 (WORD)infoPtr->nButtonHeight);
3465 return MAKELONG(23,22);
3470 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3472 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3479 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3483 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3485 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3486 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3491 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3498 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3502 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3506 ret = strlenW (lpText);
3509 strcpyW ((LPWSTR)lParam, lpText);
3517 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3519 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3520 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3521 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3525 inline static LRESULT
3526 TOOLBAR_GetExtendedStyle (HWND hwnd)
3528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3532 return infoPtr->dwExStyle;
3537 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3539 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3540 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3541 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3546 TOOLBAR_GetHotItem (HWND hwnd)
3548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3550 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3553 if (infoPtr->nHotItem < 0)
3556 return (LRESULT)infoPtr->nHotItem;
3561 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3563 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3564 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3565 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3570 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3573 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3575 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3577 *lptbim = infoPtr->tbim;
3584 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3586 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3588 TRACE("hwnd = %p\n", hwnd);
3590 return (LRESULT)infoPtr->clrInsertMark;
3595 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3598 TBUTTON_INFO *btnPtr;
3602 nIndex = (INT)wParam;
3603 btnPtr = &infoPtr->buttons[nIndex];
3604 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3606 lpRect = (LPRECT)lParam;
3609 if (btnPtr->fsState & TBSTATE_HIDDEN)
3612 lpRect->left = btnPtr->rect.left;
3613 lpRect->right = btnPtr->rect.right;
3614 lpRect->bottom = btnPtr->rect.bottom;
3615 lpRect->top = btnPtr->rect.top;
3622 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3624 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3625 LPSIZE lpSize = (LPSIZE)lParam;
3630 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3631 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3633 TRACE("maximum size %ld x %ld\n",
3634 infoPtr->rcBound.right - infoPtr->rcBound.left,
3635 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3641 /* << TOOLBAR_GetObject >> */
3645 TOOLBAR_GetPadding (HWND hwnd)
3647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3650 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3651 return (LRESULT) oldPad;
3656 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3659 TBUTTON_INFO *btnPtr;
3663 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3664 btnPtr = &infoPtr->buttons[nIndex];
3665 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3667 lpRect = (LPRECT)lParam;
3671 lpRect->left = btnPtr->rect.left;
3672 lpRect->right = btnPtr->rect.right;
3673 lpRect->bottom = btnPtr->rect.bottom;
3674 lpRect->top = btnPtr->rect.top;
3681 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3683 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3685 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3686 return infoPtr->nRows;
3693 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3695 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3698 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3702 return infoPtr->buttons[nIndex].fsState;
3707 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3709 return GetWindowLongW(hwnd, GWL_STYLE);
3714 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3716 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3718 return infoPtr->nMaxTextRows;
3723 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3727 return (LRESULT)infoPtr->hwndToolTip;
3732 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3736 TRACE("%s hwnd=%p\n",
3737 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3739 return infoPtr->bUnicode;
3743 inline static LRESULT
3744 TOOLBAR_GetVersion (HWND hwnd)
3746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3747 return infoPtr->iVersion;
3752 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3754 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3755 TBUTTON_INFO *btnPtr;
3760 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3764 btnPtr = &infoPtr->buttons[nIndex];
3765 if (LOWORD(lParam) == FALSE)
3766 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3768 btnPtr->fsState |= TBSTATE_HIDDEN;
3770 TOOLBAR_CalcToolbar (hwnd);
3772 InvalidateRect (hwnd, NULL, TRUE);
3778 inline static LRESULT
3779 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3781 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3786 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3789 TBUTTON_INFO *btnPtr;
3793 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3797 btnPtr = &infoPtr->buttons[nIndex];
3798 oldState = btnPtr->fsState;
3799 if (LOWORD(lParam) == FALSE)
3800 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3802 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3804 if(oldState != btnPtr->fsState)
3805 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3812 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3814 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3815 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3816 INT nIndex = (INT)wParam;
3817 TBUTTON_INFO *oldButtons;
3822 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3825 /* EPP: this seems to be an undocumented call (from my IE4)
3826 * I assume in that case that:
3827 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3828 * - index of insertion is at the end of existing buttons
3829 * I only see this happen with nIndex == -1, but it could have a special
3830 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3832 nIndex = infoPtr->nNumButtons;
3834 } else if (nIndex < 0)
3837 /* If the string passed is not an index, assume address of string
3838 and do our own AddString */
3839 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3843 TRACE("string %s passed instead of index, adding string\n",
3844 debugstr_a((LPSTR)lpTbb->iString));
3845 len = strlen((LPSTR)lpTbb->iString) + 2;
3847 strcpy(ptr, (LPSTR)lpTbb->iString);
3848 ptr[len - 1] = 0; /* ended by two '\0' */
3849 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3853 TRACE("inserting button index=%d\n", nIndex);
3854 if (nIndex > infoPtr->nNumButtons) {
3855 nIndex = infoPtr->nNumButtons;
3856 TRACE("adjust index=%d\n", nIndex);
3859 oldButtons = infoPtr->buttons;
3860 infoPtr->nNumButtons++;
3861 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3862 /* pre insert copy */
3864 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3865 nIndex * sizeof(TBUTTON_INFO));
3868 /* insert new button */
3869 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3870 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3871 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3872 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3873 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3874 /* if passed string and not index, then add string */
3875 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3876 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3879 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3881 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3883 /* post insert copy */
3884 if (nIndex < infoPtr->nNumButtons - 1) {
3885 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3886 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3891 TOOLBAR_CalcToolbar (hwnd);
3892 TOOLBAR_AutoSize (hwnd);
3894 InvalidateRect (hwnd, NULL, TRUE);
3901 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3904 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3905 INT nIndex = (INT)wParam;
3906 TBUTTON_INFO *oldButtons;
3911 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3914 /* EPP: this seems to be an undocumented call (from my IE4)
3915 * I assume in that case that:
3916 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3917 * - index of insertion is at the end of existing buttons
3918 * I only see this happen with nIndex == -1, but it could have a special
3919 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3921 nIndex = infoPtr->nNumButtons;
3923 } else if (nIndex < 0)
3926 /* If the string passed is not an index, assume address of string
3927 and do our own AddString */
3928 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3932 TRACE("string %s passed instead of index, adding string\n",
3933 debugstr_w((LPWSTR)lpTbb->iString));
3934 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3935 ptr = Alloc(len*sizeof(WCHAR));
3936 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3937 ptr[len - 1] = 0; /* ended by two '\0' */
3938 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3942 TRACE("inserting button index=%d\n", nIndex);
3943 if (nIndex > infoPtr->nNumButtons) {
3944 nIndex = infoPtr->nNumButtons;
3945 TRACE("adjust index=%d\n", nIndex);
3948 oldButtons = infoPtr->buttons;
3949 infoPtr->nNumButtons++;
3950 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3951 /* pre insert copy */
3953 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3954 nIndex * sizeof(TBUTTON_INFO));
3957 /* insert new button */
3958 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3959 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3960 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3961 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3962 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3963 /* if passed string and not index, then add string */
3964 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3965 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3968 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3970 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3972 /* post insert copy */
3973 if (nIndex < infoPtr->nNumButtons - 1) {
3974 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3975 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3980 TOOLBAR_CalcToolbar (hwnd);
3981 TOOLBAR_AutoSize (hwnd);
3983 InvalidateRect (hwnd, NULL, TRUE);
3989 /* << TOOLBAR_InsertMarkHitTest >> */
3993 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3998 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4002 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4007 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4012 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4016 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4021 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4026 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4030 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4035 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4037 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4040 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4044 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4049 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4058 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4063 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4068 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4072 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4077 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4080 tbab.hInst = (HINSTANCE)lParam;
4081 tbab.nID = (UINT_PTR)wParam;
4083 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4085 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4090 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4093 WCHAR wAccel = (WCHAR)wParam;
4094 UINT* pIDButton = (UINT*)lParam;
4095 WCHAR wszAccel[] = {'&',wAccel,0};
4098 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4099 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4101 for (i = 0; i < infoPtr->nNumButtons; i++)
4103 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4104 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4105 !(btnPtr->fsState & TBSTATE_HIDDEN))
4107 int iLen = strlenW(wszAccel);
4108 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4115 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4120 if (!strncmpiW(lpszStr, wszAccel, iLen))
4122 *pIDButton = btnPtr->idCommand;
4134 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4139 TBUTTON_INFO *btnPtr;
4141 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4143 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4147 btnPtr = &infoPtr->buttons[nIndex];
4148 oldState = btnPtr->fsState;
4151 btnPtr->fsState |= TBSTATE_MARKED;
4153 btnPtr->fsState &= ~TBSTATE_MARKED;
4155 if(oldState != btnPtr->fsState)
4156 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4162 /* fixes up an index of a button affected by a move */
4163 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4167 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4169 else if (*pIndex == nIndex)
4170 *pIndex = nMoveIndex;
4174 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4176 else if (*pIndex == nIndex)
4177 *pIndex = nMoveIndex;
4183 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4185 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4188 INT nMoveIndex = (INT)lParam;
4189 TBUTTON_INFO button;
4191 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4193 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4194 if ((nIndex == -1) || (nMoveIndex < 0))
4197 if (nMoveIndex > infoPtr->nNumButtons - 1)
4198 nMoveIndex = infoPtr->nNumButtons - 1;
4200 button = infoPtr->buttons[nIndex];
4202 /* move button right */
4203 if (nIndex < nMoveIndex)
4205 nCount = nMoveIndex - nIndex;
4206 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4207 infoPtr->buttons[nMoveIndex] = button;
4209 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4210 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4211 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4212 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4214 else if (nIndex > nMoveIndex) /* move button left */
4216 nCount = nIndex - nMoveIndex;
4217 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4218 infoPtr->buttons[nMoveIndex] = button;
4220 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4221 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4222 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4223 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4226 TOOLBAR_CalcToolbar(hwnd);
4227 TOOLBAR_AutoSize(hwnd);
4228 InvalidateRect(hwnd, NULL, TRUE);
4235 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4238 TBUTTON_INFO *btnPtr;
4242 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4246 btnPtr = &infoPtr->buttons[nIndex];
4247 oldState = btnPtr->fsState;
4248 if (LOWORD(lParam) == FALSE)
4249 btnPtr->fsState &= ~TBSTATE_PRESSED;
4251 btnPtr->fsState |= TBSTATE_PRESSED;
4253 if(oldState != btnPtr->fsState)
4254 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4259 /* FIXME: there might still be some confusion her between number of buttons
4260 * and number of bitmaps */
4262 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4265 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4267 HBITMAP hbmLoad = NULL;
4268 int i = 0, nOldButtons = 0, pos = 0;
4269 int nOldBitmaps, nNewBitmaps = 0;
4270 HIMAGELIST himlDef = 0;
4272 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4273 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4274 lpReplace->nButtons);
4276 if (lpReplace->hInstOld == HINST_COMMCTRL)
4278 FIXME("changing standard bitmaps not implemented\n");
4281 else if (lpReplace->hInstOld != 0)
4282 FIXME("resources not in the current module not implemented\n");
4284 if (lpReplace->hInstNew)
4286 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4291 hBitmap = (HBITMAP) lpReplace->nIDNew;
4294 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4295 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4296 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4297 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4298 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4300 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4301 nOldButtons = tbi->nButtons;
4302 tbi->nButtons = lpReplace->nButtons;
4303 tbi->hInst = lpReplace->hInstNew;
4304 tbi->nID = lpReplace->nIDNew;
4305 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4308 pos += tbi->nButtons;
4311 if (nOldButtons == 0)
4313 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4315 DeleteObject (hbmLoad);
4319 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4320 nOldBitmaps = ImageList_GetImageCount(himlDef);
4322 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4324 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4325 ImageList_Remove(himlDef, i);
4330 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4331 HDC hdcImage, hdcBitmap;
4333 /* copy the bitmap before adding it so that the user's bitmap
4334 * doesn't get modified.
4336 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4338 hdcImage = CreateCompatibleDC(0);
4339 hdcBitmap = CreateCompatibleDC(0);
4341 /* create new bitmap */
4342 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4343 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4344 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4346 /* Copy the user's image */
4347 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4348 hdcBitmap, 0, 0, SRCCOPY);
4350 SelectObject (hdcImage, hOldBitmapLoad);
4351 SelectObject (hdcBitmap, hOldBitmapBitmap);
4352 DeleteDC (hdcImage);
4353 DeleteDC (hdcBitmap);
4355 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4356 nNewBitmaps = ImageList_GetImageCount(himlDef);
4357 DeleteObject (hbmLoad);
4360 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4362 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4363 pos, nOldBitmaps, nNewBitmaps);
4365 InvalidateRect(hwnd, NULL, TRUE);
4368 DeleteObject (hbmLoad);
4373 /* helper for TOOLBAR_SaveRestoreW */
4375 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4377 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4378 debugstr_w(lpSave->pszValueName));
4384 /* helper for TOOLBAR_Restore */
4386 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4390 for (i = 0; i < infoPtr->nNumButtons; i++)
4392 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4395 Free(infoPtr->buttons);
4396 infoPtr->buttons = NULL;
4397 infoPtr->nNumButtons = 0;
4401 /* helper for TOOLBAR_SaveRestoreW */
4403 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4412 /* restore toolbar information */
4413 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4414 debugstr_w(lpSave->pszValueName));
4416 memset(&nmtbr, 0, sizeof(nmtbr));
4418 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4419 KEY_QUERY_VALUE, &hkey);
4421 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4423 if (!res && dwType != REG_BINARY)
4424 res = ERROR_FILE_NOT_FOUND;
4427 nmtbr.pData = Alloc(dwSize);
4428 nmtbr.cbData = (UINT)dwSize;
4429 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4432 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4433 (LPBYTE)nmtbr.pData, &dwSize);
4436 nmtbr.pCurrent = nmtbr.pData;
4438 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4439 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4441 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4445 /* remove all existing buttons as this function is designed to
4446 * restore the toolbar to a previously saved state */
4447 TOOLBAR_DeleteAllButtons(infoPtr);
4449 for (i = 0; i < nmtbr.cButtons; i++)
4452 nmtbr.tbButton.iBitmap = -1;
4453 nmtbr.tbButton.fsState = 0;
4454 nmtbr.tbButton.fsStyle = 0;
4455 nmtbr.tbButton.idCommand = 0;
4456 if (*nmtbr.pCurrent == (DWORD)-1)
4459 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4460 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4462 else if (*nmtbr.pCurrent == (DWORD)-2)
4464 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4466 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4470 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4472 /* can't contain real string as we don't know whether
4473 * the client put an ANSI or Unicode string in there */
4474 if (HIWORD(nmtbr.tbButton.iString))
4475 nmtbr.tbButton.iString = 0;
4477 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4478 (LPARAM)&nmtbr.tbButton);
4481 /* do legacy notifications */
4482 if (infoPtr->iVersion < 5)
4484 /* FIXME: send TBN_BEGINADJUST */
4485 FIXME("send TBN_GETBUTTONINFO for each button\n");
4486 /* FIXME: send TBN_ENDADJUST */
4489 /* remove all uninitialised buttons
4490 * note: loop backwards to avoid having to fixup i on a
4492 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4493 if (infoPtr->buttons[i].iBitmap == -1)
4494 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4496 /* only indicate success if at least one button survived */
4497 if (infoPtr->nNumButtons > 0) ret = TRUE;
4508 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4512 if (lpSave == NULL) return 0;
4515 return TOOLBAR_Save(infoPtr, lpSave);
4517 return TOOLBAR_Restore(infoPtr, lpSave);
4522 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4524 LPWSTR pszValueName = 0, pszSubKey = 0;
4525 TBSAVEPARAMSW SaveW;
4529 if (lpSave == NULL) return 0;
4531 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4532 pszSubKey = Alloc(len * sizeof(WCHAR));
4533 if (pszSubKey) goto exit;
4534 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4536 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4537 pszValueName = Alloc(len * sizeof(WCHAR));
4538 if (!pszValueName) goto exit;
4539 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4541 SaveW.pszValueName = pszValueName;
4542 SaveW.pszSubKey = pszSubKey;
4543 SaveW.hkr = lpSave->hkr;
4544 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4547 Free (pszValueName);
4555 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4558 BOOL bOldAnchor = infoPtr->bAnchor;
4560 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4562 infoPtr->bAnchor = (BOOL)wParam;
4564 /* Native does not remove the hot effect from an already hot button */
4566 return (LRESULT)bOldAnchor;
4571 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4573 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4574 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4576 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4579 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4581 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4582 lParam = MAKELPARAM(16, 15);
4584 if (infoPtr->nNumButtons > 0)
4585 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4586 infoPtr->nNumButtons,
4587 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4588 LOWORD(lParam), HIWORD(lParam));
4590 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4591 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4594 if ((himlDef == infoPtr->himlInt) &&
4595 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4597 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4598 infoPtr->nBitmapHeight);
4601 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4607 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4610 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4611 TBUTTON_INFO *btnPtr;
4617 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4620 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4621 lptbbi->dwMask & 0x80000000);
4625 btnPtr = &infoPtr->buttons[nIndex];
4626 if (lptbbi->dwMask & TBIF_COMMAND)
4627 btnPtr->idCommand = lptbbi->idCommand;
4628 if (lptbbi->dwMask & TBIF_IMAGE)
4629 btnPtr->iBitmap = lptbbi->iImage;
4630 if (lptbbi->dwMask & TBIF_LPARAM)
4631 btnPtr->dwData = lptbbi->lParam;
4632 if (lptbbi->dwMask & TBIF_SIZE)
4633 btnPtr->cx = lptbbi->cx;
4634 if (lptbbi->dwMask & TBIF_STATE)
4635 btnPtr->fsState = lptbbi->fsState;
4636 if (lptbbi->dwMask & TBIF_STYLE)
4637 btnPtr->fsStyle = lptbbi->fsStyle;
4639 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4640 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4641 /* iString is index, zero it to make Str_SetPtr succeed */
4644 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4647 /* save the button rect to see if we need to redraw the whole toolbar */
4648 oldBtnRect = btnPtr->rect;
4649 TOOLBAR_CalcToolbar(hwnd);
4651 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4652 InvalidateRect(hwnd, NULL, TRUE);
4654 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4661 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4663 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4664 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4665 TBUTTON_INFO *btnPtr;
4671 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4674 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4675 lptbbi->dwMask & 0x80000000);
4679 btnPtr = &infoPtr->buttons[nIndex];
4680 if (lptbbi->dwMask & TBIF_COMMAND)
4681 btnPtr->idCommand = lptbbi->idCommand;
4682 if (lptbbi->dwMask & TBIF_IMAGE)
4683 btnPtr->iBitmap = lptbbi->iImage;
4684 if (lptbbi->dwMask & TBIF_LPARAM)
4685 btnPtr->dwData = lptbbi->lParam;
4686 if (lptbbi->dwMask & TBIF_SIZE)
4687 btnPtr->cx = lptbbi->cx;
4688 if (lptbbi->dwMask & TBIF_STATE)
4689 btnPtr->fsState = lptbbi->fsState;
4690 if (lptbbi->dwMask & TBIF_STYLE)
4691 btnPtr->fsStyle = lptbbi->fsStyle;
4693 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4694 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4695 /* iString is index, zero it to make Str_SetPtr succeed */
4697 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4700 /* save the button rect to see if we need to redraw the whole toolbar */
4701 oldBtnRect = btnPtr->rect;
4702 TOOLBAR_CalcToolbar(hwnd);
4704 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4705 InvalidateRect(hwnd, NULL, TRUE);
4707 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4714 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4716 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4717 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4719 if ((cx < 0) || (cy < 0))
4721 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4725 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4727 /* The documentation claims you can only change the button size before
4728 * any button has been added. But this is wrong.
4729 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4730 * it to the toolbar, and it checks that the return value is nonzero - mjm
4731 * Further testing shows that we must actually perform the change too.
4734 * The documentation also does not mention that if 0 is supplied for
4735 * either size, the system changes it to the default of 24 wide and
4736 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4738 infoPtr->nButtonWidth = (cx) ? cx : 24;
4739 infoPtr->nButtonHeight = (cy) ? cy : 22;
4745 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4749 /* if setting to current values, ignore */
4750 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4751 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4752 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4753 infoPtr->cxMin, infoPtr->cxMax);
4757 /* save new values */
4758 infoPtr->cxMin = (INT)LOWORD(lParam);
4759 infoPtr->cxMax = (INT)HIWORD(lParam);
4761 /* otherwise we need to recalc the toolbar and in some cases
4762 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4763 which doesn't actually draw - GA). */
4764 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4765 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4767 TOOLBAR_CalcToolbar (hwnd);
4769 InvalidateRect (hwnd, NULL, TRUE);
4776 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4778 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4779 INT nIndex = (INT)wParam;
4781 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4784 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4786 if (infoPtr->hwndToolTip) {
4788 FIXME("change tool tip!\n");
4797 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4800 HIMAGELIST himl = (HIMAGELIST)lParam;
4801 HIMAGELIST himlTemp;
4804 if (infoPtr->iVersion >= 5)
4807 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4808 &infoPtr->cimlDis, himl, id);
4810 /* FIXME: redraw ? */
4812 return (LRESULT)himlTemp;
4817 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4822 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4824 dwTemp = infoPtr->dwDTFlags;
4825 infoPtr->dwDTFlags =
4826 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4828 return (LRESULT)dwTemp;
4831 /* This function differs a bit from what MSDN says it does:
4832 * 1. lParam contains extended style flags to OR with current style
4833 * (MSDN isn't clear on the OR bit)
4834 * 2. wParam appears to contain extended style flags to be reset
4835 * (MSDN says that this parameter is reserved)
4838 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4843 dwTemp = infoPtr->dwExStyle;
4844 infoPtr->dwExStyle &= ~wParam;
4845 infoPtr->dwExStyle |= (DWORD)lParam;
4847 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4849 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4850 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4851 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4853 TOOLBAR_CalcToolbar (hwnd);
4855 TOOLBAR_AutoSize(hwnd);
4857 InvalidateRect(hwnd, NULL, TRUE);
4859 return (LRESULT)dwTemp;
4864 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4867 HIMAGELIST himlTemp;
4868 HIMAGELIST himl = (HIMAGELIST)lParam;
4871 if (infoPtr->iVersion >= 5)
4874 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4876 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4877 &infoPtr->cimlHot, himl, id);
4879 /* FIXME: redraw ? */
4881 return (LRESULT)himlTemp;
4885 /* Makes previous hot button no longer hot, makes the specified
4886 * button hot and sends appropriate notifications. dwReason is one or
4887 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4888 * NOTE 1: this function does not validate nHit
4889 * NOTE 2: the name of this function is completely made up and
4890 * not based on any documentation from Microsoft. */
4892 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4894 if (infoPtr->nHotItem != nHit)
4896 NMTBHOTITEM nmhotitem;
4897 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4898 LRESULT no_highlight;
4900 /* Remove the effect of an old hot button if the button was
4901 drawn with the hot button effect */
4902 if(infoPtr->nHotItem >= 0)
4904 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4905 oldBtnPtr->bHot = FALSE;
4908 infoPtr->nHotItem = nHit;
4910 /* It's not a separator or in nowhere. It's a hot button. */
4912 btnPtr = &infoPtr->buttons[nHit];
4914 nmhotitem.dwFlags = dwReason;
4916 nmhotitem.idOld = oldBtnPtr->idCommand;
4918 nmhotitem.dwFlags |= HICF_ENTERING;
4920 nmhotitem.idNew = btnPtr->idCommand;
4922 nmhotitem.dwFlags |= HICF_LEAVING;
4924 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
4926 /* now invalidate the old and new buttons so they will be painted,
4927 * but only if they are enabled - disabled buttons cannot become hot */
4928 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
4929 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4930 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
4932 btnPtr->bHot = TRUE;
4933 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4939 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4942 INT nOldHotItem = infoPtr->nHotItem;
4944 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4946 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4949 /* NOTE: an application can still remove the hot item even if anchor
4950 * highlighting is enabled */
4952 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
4953 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4955 if (nOldHotItem < 0)
4958 return (LRESULT)nOldHotItem;
4963 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4966 HIMAGELIST himlTemp;
4967 HIMAGELIST himl = (HIMAGELIST)lParam;
4970 if (infoPtr->iVersion >= 5)
4973 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4974 &infoPtr->cimlDef, himl, id);
4976 infoPtr->nNumBitmaps = 0;
4977 for (i = 0; i < infoPtr->cimlDef; i++)
4978 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4980 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4981 &infoPtr->nBitmapHeight))
4983 infoPtr->nBitmapWidth = 1;
4984 infoPtr->nBitmapHeight = 1;
4987 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4988 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4989 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4991 InvalidateRect(hwnd, NULL, TRUE);
4993 return (LRESULT)himlTemp;
4998 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5002 infoPtr->nIndent = (INT)wParam;
5006 /* process only on indent changing */
5007 if(infoPtr->nIndent != (INT)wParam)
5009 infoPtr->nIndent = (INT)wParam;
5010 TOOLBAR_CalcToolbar (hwnd);
5011 InvalidateRect(hwnd, NULL, FALSE);
5019 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5022 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5024 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5026 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5028 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5032 if ((lptbim->iButton == -1) ||
5033 ((lptbim->iButton < infoPtr->nNumButtons) &&
5034 (lptbim->iButton >= 0)))
5036 infoPtr->tbim = *lptbim;
5037 /* FIXME: don't need to update entire toolbar */
5038 InvalidateRect(hwnd, NULL, TRUE);
5041 ERR("Invalid button index %d\n", lptbim->iButton);
5048 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5050 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5052 infoPtr->clrInsertMark = (COLORREF)lParam;
5054 /* FIXME: don't need to update entire toolbar */
5055 InvalidateRect(hwnd, NULL, TRUE);
5062 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5066 infoPtr->nMaxTextRows = (INT)wParam;
5068 TOOLBAR_CalcToolbar(hwnd);
5073 /* MSDN gives slightly wrong info on padding.
5074 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5075 * 2. It is not used to create a blank area between the edge of the button
5076 * and the text or image if TBSTYLE_LIST is set. It is used to control
5077 * the gap between the image and text.
5078 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5079 * to control the bottom and right borders [with the border being
5080 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5081 * is shared evenly on both sides of the button.
5082 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5085 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5090 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5091 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5092 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5093 TRACE("cx=%ld, cy=%ld\n",
5094 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5095 return (LRESULT) oldPad;
5100 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5107 hwndOldNotify = infoPtr->hwndNotify;
5108 infoPtr->hwndNotify = (HWND)wParam;
5110 return (LRESULT)hwndOldNotify;
5115 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5118 LPRECT lprc = (LPRECT)lParam;
5122 if (LOWORD(wParam) > 1) {
5123 FIXME("multiple rows not supported!\n");
5126 if(infoPtr->nRows != LOWORD(wParam))
5128 infoPtr->nRows = LOWORD(wParam);
5130 /* recalculate toolbar */
5131 TOOLBAR_CalcToolbar (hwnd);
5133 /* repaint toolbar */
5134 InvalidateRect(hwnd, NULL, TRUE);
5137 /* return bounding rectangle */
5139 lprc->left = infoPtr->rcBound.left;
5140 lprc->right = infoPtr->rcBound.right;
5141 lprc->top = infoPtr->rcBound.top;
5142 lprc->bottom = infoPtr->rcBound.bottom;
5150 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5153 TBUTTON_INFO *btnPtr;
5156 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5160 btnPtr = &infoPtr->buttons[nIndex];
5162 /* if hidden state has changed the invalidate entire window and recalc */
5163 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5164 btnPtr->fsState = LOWORD(lParam);
5165 TOOLBAR_CalcToolbar (hwnd);
5166 InvalidateRect(hwnd, 0, TRUE);
5170 /* process state changing if current state doesn't match new state */
5171 if(btnPtr->fsState != LOWORD(lParam))
5173 btnPtr->fsState = LOWORD(lParam);
5174 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5182 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5184 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5190 inline static LRESULT
5191 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5195 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5197 infoPtr->hwndToolTip = (HWND)wParam;
5203 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5208 TRACE("%s hwnd=%p\n",
5209 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5211 bTemp = infoPtr->bUnicode;
5212 infoPtr->bUnicode = (BOOL)wParam;
5219 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5223 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5224 comctl32_color.clrBtnHighlight :
5225 infoPtr->clrBtnHighlight;
5226 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5227 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5233 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5235 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5237 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5238 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5239 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5241 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5242 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5243 InvalidateRect(hwnd, NULL, TRUE);
5249 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5251 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5252 INT iOldVersion = infoPtr->iVersion;
5254 infoPtr->iVersion = iVersion;
5256 if (infoPtr->iVersion >= 5)
5257 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5264 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5267 WORD iString = HIWORD(wParam);
5268 WORD buffersize = LOWORD(wParam);
5269 LPSTR str = (LPSTR)lParam;
5272 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5274 if (iString < infoPtr->nNumStrings)
5276 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5278 TRACE("returning %s\n", debugstr_a(str));
5281 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5288 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5290 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5291 WORD iString = HIWORD(wParam);
5292 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5293 LPWSTR str = (LPWSTR)lParam;
5296 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5298 if (iString < infoPtr->nNumStrings)
5300 len = min(len, strlenW(infoPtr->strings[iString]));
5301 ret = (len+1)*sizeof(WCHAR);
5302 memcpy(str, infoPtr->strings[iString], ret);
5305 TRACE("returning %s\n", debugstr_w(str));
5308 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5313 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5314 * is the maximum size of the toolbar? */
5315 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5317 SIZE * pSize = (SIZE*)lParam;
5318 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5323 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5324 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5325 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5328 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5330 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5331 INT nOldHotItem = infoPtr->nHotItem;
5333 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5334 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5336 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5339 /* NOTE: an application can still remove the hot item even if anchor
5340 * highlighting is enabled */
5342 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5346 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5349 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5350 * which controls the amount of spacing between the image and the text
5351 * of buttons for TBSTYLE_LIST toolbars. */
5352 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5356 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5359 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5361 infoPtr->iListGap = (INT)wParam;
5363 InvalidateRect(hwnd, NULL, TRUE);
5368 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5369 * of image lists associated with the various states. */
5370 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5374 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5376 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5380 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5382 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5383 LPSIZE lpsize = (LPSIZE)lParam;
5389 * Testing shows the following:
5390 * wParam = 0 adjust cx value
5391 * = 1 set cy value to max size.
5392 * lParam pointer to SIZE structure
5395 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5396 wParam, lParam, lpsize->cx, lpsize->cy);
5400 if (lpsize->cx == -1) {
5401 /* **** this is wrong, native measures each button and sets it */
5402 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5404 else if(HIWORD(lpsize->cx)) {
5406 HWND hwndParent = GetParent(hwnd);
5408 GetWindowRect(hwnd, &rc);
5409 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5410 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5411 rc.left, rc.top, rc.right, rc.bottom);
5412 lpsize->cx = max(rc.right-rc.left,
5413 infoPtr->rcBound.right - infoPtr->rcBound.left);
5416 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5420 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5423 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5427 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5428 lpsize->cx, lpsize->cy);
5432 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5434 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5436 InvalidateRect(hwnd, NULL, TRUE);
5442 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5445 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5448 TRACE("hwnd = %p\n", hwnd);
5450 /* initialize info structure */
5451 infoPtr->nButtonHeight = 22;
5452 infoPtr->nButtonWidth = 24;
5453 infoPtr->nBitmapHeight = 15;
5454 infoPtr->nBitmapWidth = 16;
5456 infoPtr->nMaxTextRows = 1;
5457 infoPtr->cxMin = -1;
5458 infoPtr->cxMax = -1;
5459 infoPtr->nNumBitmaps = 0;
5460 infoPtr->nNumStrings = 0;
5462 infoPtr->bCaptured = FALSE;
5463 infoPtr->nButtonDown = -1;
5464 infoPtr->nButtonDrag = -1;
5465 infoPtr->nOldHit = -1;
5466 infoPtr->nHotItem = -1;
5467 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5468 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5469 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5470 infoPtr->bDragOutSent = FALSE;
5471 infoPtr->iVersion = 0;
5472 infoPtr->hwndSelf = hwnd;
5473 infoPtr->bDoRedraw = TRUE;
5474 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5475 infoPtr->clrBtnShadow = CLR_DEFAULT;
5476 infoPtr->szPadding.cx = DEFPAD_CX;
5477 infoPtr->szPadding.cy = DEFPAD_CY;
5478 infoPtr->iListGap = DEFLISTGAP;
5479 infoPtr->dwStyle = dwStyle;
5480 infoPtr->tbim.iButton = -1;
5481 GetClientRect(hwnd, &infoPtr->client_rect);
5482 infoPtr->bUnicode = infoPtr->hwndNotify &&
5483 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5484 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5486 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5487 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5489 OpenThemeData (hwnd, themeClass);
5491 TOOLBAR_CheckStyle (hwnd, dwStyle);
5493 TOOLBAR_CalcToolbar(hwnd);
5500 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5504 /* delete tooltip control */
5505 if (infoPtr->hwndToolTip)
5506 DestroyWindow (infoPtr->hwndToolTip);
5508 /* delete temporary buffer for tooltip text */
5509 Free (infoPtr->pszTooltipText);
5510 Free (infoPtr->bitmaps); /* bitmaps list */
5512 /* delete button data */
5513 if (infoPtr->buttons)
5514 Free (infoPtr->buttons);
5516 /* delete strings */
5517 if (infoPtr->strings) {
5519 for (i = 0; i < infoPtr->nNumStrings; i++)
5520 if (infoPtr->strings[i])
5521 Free (infoPtr->strings[i]);
5523 Free (infoPtr->strings);
5526 /* destroy internal image list */
5527 if (infoPtr->himlInt)
5528 ImageList_Destroy (infoPtr->himlInt);
5530 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5531 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5532 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5534 /* delete default font */
5536 DeleteObject (infoPtr->hDefaultFont);
5538 CloseThemeData (GetWindowTheme (hwnd));
5540 /* free toolbar info data */
5542 SetWindowLongPtrW (hwnd, 0, 0);
5549 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5552 NMTBCUSTOMDRAW tbcd;
5555 HTHEME theme = GetWindowTheme (hwnd);
5557 /* the app has told us not to redraw the toolbar */
5558 if (!infoPtr->bDoRedraw)
5561 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5562 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5563 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5564 tbcd.nmcd.hdc = (HDC)wParam;
5565 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5566 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5568 /* FIXME: in general the return flags *can* be or'ed together */
5569 switch (infoPtr->dwBaseCustDraw)
5571 case CDRF_DODEFAULT:
5573 case CDRF_SKIPDEFAULT:
5576 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5581 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5582 * to my parent for processing.
5584 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5586 HDC hdc = (HDC)wParam;
5591 parent = GetParent(hwnd);
5592 MapWindowPoints(hwnd, parent, &pt, 1);
5593 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5594 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5595 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5598 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5600 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5601 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5602 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5603 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5604 tbcd.nmcd.hdc = (HDC)wParam;
5605 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5606 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5607 switch (infoPtr->dwBaseCustDraw)
5609 case CDRF_DODEFAULT:
5611 case CDRF_SKIPDEFAULT:
5614 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5623 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5627 return (LRESULT)infoPtr->hFont;
5632 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5635 INT nNewHotItem = infoPtr->nHotItem;
5637 for (i = 0; i < infoPtr->nNumButtons; i++)
5640 if ((nNewHotItem + iDirection < 0) ||
5641 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5643 NMTBWRAPHOTITEM nmtbwhi;
5644 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5645 nmtbwhi.iDirection = iDirection;
5646 nmtbwhi.dwReason = dwReason;
5648 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5652 nNewHotItem += iDirection;
5653 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5655 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5656 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5658 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5665 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5670 nmkey.nVKey = (UINT)wParam;
5671 nmkey.uFlags = HIWORD(lParam);
5673 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5674 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5676 switch ((UINT)wParam)
5680 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5684 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5688 if ((infoPtr->nHotItem >= 0) &&
5689 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5691 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5692 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5703 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5708 pt.x = (INT)LOWORD(lParam);
5709 pt.y = (INT)HIWORD(lParam);
5710 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5713 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5714 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5715 TOOLBAR_Customize (hwnd);
5722 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5725 TBUTTON_INFO *btnPtr;
5730 BOOL bDragKeyPressed;
5734 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5735 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5737 bDragKeyPressed = (wParam & MK_SHIFT);
5739 if (infoPtr->hwndToolTip)
5740 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5741 WM_LBUTTONDOWN, wParam, lParam);
5743 pt.x = (INT)LOWORD(lParam);
5744 pt.y = (INT)HIWORD(lParam);
5745 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5747 btnPtr = &infoPtr->buttons[nHit];
5749 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5751 infoPtr->nButtonDrag = nHit;
5754 /* If drag cursor has not been loaded, load it.
5755 * Note: it doesn't need to be freed */
5757 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5758 SetCursor(hCursorDrag);
5763 infoPtr->nOldHit = nHit;
5765 CopyRect(&arrowRect, &btnPtr->rect);
5766 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5768 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5769 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5770 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5771 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5772 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5773 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5777 /* draw in pressed state */
5778 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5779 btnPtr->fsState |= TBSTATE_PRESSED;
5781 btnPtr->bDropDownPressed = TRUE;
5782 RedrawWindow(hwnd,&btnPtr->rect,0,
5783 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5785 memset(&nmtb, 0, sizeof(nmtb));
5786 nmtb.iItem = btnPtr->idCommand;
5787 nmtb.rcButton = btnPtr->rect;
5788 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5790 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5792 if (res != TBDDRET_TREATPRESSED)
5796 /* redraw button in unpressed state */
5797 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5798 btnPtr->fsState &= ~TBSTATE_PRESSED;
5800 btnPtr->bDropDownPressed = FALSE;
5801 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5803 /* find and set hot item
5804 * NOTE: native doesn't do this, but that is a bug */
5806 ScreenToClient(hwnd, &pt);
5807 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5808 if (!infoPtr->bAnchor || (nHit >= 0))
5809 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5811 /* remove any left mouse button down or double-click messages
5812 * so that we can get a toggle effect on the button */
5813 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5814 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5819 /* otherwise drop through and process as pushed */
5821 infoPtr->bCaptured = TRUE;
5822 infoPtr->nButtonDown = nHit;
5823 infoPtr->bDragOutSent = FALSE;
5825 btnPtr->fsState |= TBSTATE_PRESSED;
5827 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5829 if (btnPtr->fsState & TBSTATE_ENABLED)
5830 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5837 memset(&nmtb, 0, sizeof(nmtb));
5838 nmtb.iItem = btnPtr->idCommand;
5839 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5842 nmmouse.dwHitInfo = nHit;
5844 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5846 nmmouse.dwItemSpec = -1;
5849 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5850 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5853 ClientToScreen(hwnd, &pt);
5856 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5857 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5863 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5866 TBUTTON_INFO *btnPtr;
5870 BOOL bSendMessage = TRUE;
5875 if (infoPtr->hwndToolTip)
5876 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5877 WM_LBUTTONUP, wParam, lParam);
5879 pt.x = (INT)LOWORD(lParam);
5880 pt.y = (INT)HIWORD(lParam);
5881 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5883 if (!infoPtr->bAnchor || (nHit >= 0))
5884 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5886 if (infoPtr->nButtonDrag >= 0) {
5890 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5893 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5895 GetClientRect(hwnd, &rcClient);
5896 if (PtInRect(&rcClient, pt))
5903 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5906 if (nButton == infoPtr->nButtonDrag)
5908 /* if the button is moved sightly left and we have a
5909 * separator there then remove it */
5910 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5912 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5913 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5915 else /* else insert a separator before the dragged button */
5918 memset(&tbb, 0, sizeof(tbb));
5919 tbb.fsStyle = BTNS_SEP;
5921 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5928 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5929 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5931 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5934 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5939 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5940 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5943 /* button under cursor changed so need to re-set hot item */
5944 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5945 infoPtr->nButtonDrag = -1;
5947 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5949 else if (infoPtr->nButtonDown >= 0) {
5950 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5951 btnPtr->fsState &= ~TBSTATE_PRESSED;
5953 if (btnPtr->fsStyle & BTNS_CHECK) {
5954 if (btnPtr->fsStyle & BTNS_GROUP) {
5955 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5957 if (nOldIndex == nHit)
5958 bSendMessage = FALSE;
5959 if ((nOldIndex != nHit) &&
5961 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5962 btnPtr->fsState |= TBSTATE_CHECKED;
5965 if (btnPtr->fsState & TBSTATE_CHECKED)
5966 btnPtr->fsState &= ~TBSTATE_CHECKED;
5968 btnPtr->fsState |= TBSTATE_CHECKED;
5972 if (nOldIndex != -1)
5973 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5976 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5977 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5978 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5980 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5982 infoPtr->nButtonDown = -1;
5984 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5985 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5986 NM_RELEASEDCAPTURE);
5988 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5991 memset(&nmtb, 0, sizeof(nmtb));
5992 nmtb.iItem = btnPtr->idCommand;
5993 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5996 if (btnPtr->fsState & TBSTATE_ENABLED)
5998 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5999 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6003 /* !!! Undocumented - toolbar at 4.71 level and above sends
6004 * NM_CLICK with the NMMOUSE structure. */
6005 nmmouse.dwHitInfo = nHit;
6008 nmmouse.dwItemSpec = -1;
6011 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6012 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6015 ClientToScreen(hwnd, &pt);
6018 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6019 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6025 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6027 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6032 pt.x = LOWORD(lParam);
6033 pt.y = HIWORD(lParam);
6035 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6036 nmmouse.dwHitInfo = nHit;
6039 nmmouse.dwItemSpec = -1;
6041 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6042 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6045 ClientToScreen(hwnd, &pt);
6048 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6049 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6055 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6057 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6060 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6061 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6067 TOOLBAR_CaptureChanged(HWND hwnd)
6069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6070 TBUTTON_INFO *btnPtr;
6072 infoPtr->bCaptured = FALSE;
6074 if (infoPtr->nButtonDown >= 0)
6076 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6077 btnPtr->fsState &= ~TBSTATE_PRESSED;
6079 infoPtr->nOldHit = -1;
6081 if (btnPtr->fsState & TBSTATE_ENABLED)
6082 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6088 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6091 TBUTTON_INFO *hotBtnPtr;
6093 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6095 /* don't remove hot effects when in anchor highlighting mode or when a
6096 * drop-down button is pressed */
6097 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6098 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6100 if (infoPtr->nOldHit < 0)
6103 /* If the last button we were over is depressed then make it not */
6104 /* depressed and redraw it */
6105 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6107 TBUTTON_INFO *btnPtr;
6110 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6112 btnPtr->fsState &= ~TBSTATE_PRESSED;
6114 rc1 = hotBtnPtr->rect;
6115 InflateRect (&rc1, 1, 1);
6116 InvalidateRect (hwnd, &rc1, TRUE);
6119 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6122 ZeroMemory(&nmt, sizeof(nmt));
6123 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6124 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6125 infoPtr->bDragOutSent = TRUE;
6128 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6134 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6138 TRACKMOUSEEVENT trackinfo;
6140 TBUTTON_INFO *btnPtr;
6142 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6143 TOOLBAR_TooltipCreateControl(infoPtr);
6145 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6146 /* fill in the TRACKMOUSEEVENT struct */
6147 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6148 trackinfo.dwFlags = TME_QUERY;
6150 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6151 _TrackMouseEvent(&trackinfo);
6153 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6154 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6155 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6156 trackinfo.hwndTrack = hwnd;
6158 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6159 /* and can properly deactivate the hot toolbar button */
6160 _TrackMouseEvent(&trackinfo);
6164 if (infoPtr->hwndToolTip)
6165 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6166 WM_MOUSEMOVE, wParam, lParam);
6168 pt.x = (INT)LOWORD(lParam);
6169 pt.y = (INT)HIWORD(lParam);
6171 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6173 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6174 && (!infoPtr->bAnchor || (nHit >= 0)))
6175 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6177 if (infoPtr->nOldHit != nHit)
6179 if (infoPtr->bCaptured)
6181 if (!infoPtr->bDragOutSent)
6184 ZeroMemory(&nmt, sizeof(nmt));
6185 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6186 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6187 infoPtr->bDragOutSent = TRUE;
6190 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6191 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6192 btnPtr->fsState &= ~TBSTATE_PRESSED;
6193 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6195 else if (nHit == infoPtr->nButtonDown) {
6196 btnPtr->fsState |= TBSTATE_PRESSED;
6197 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6199 infoPtr->nOldHit = nHit;
6207 inline static LRESULT
6208 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6210 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6211 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6213 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6217 inline static LRESULT
6218 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6220 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6221 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6223 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6228 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6230 TOOLBAR_INFO *infoPtr;
6231 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6234 /* allocate memory for info structure */
6235 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6236 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6239 infoPtr->dwStructSize = sizeof(TBBUTTON);
6241 infoPtr->nWidth = 0;
6243 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6244 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6245 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6246 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6249 /* native control does:
6250 * Get a lot of colors and brushes
6252 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6253 * CreateFontIndirectW(adr1)
6254 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6255 * hdc = GetDC(toolbar)
6256 * GetSystemMetrics(0x48)
6257 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6258 * 0, 0, 0, 0, "MARLETT")
6259 * oldfnt = SelectObject(hdc, fnt2)
6260 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6261 * GetTextMetricsW(hdc, adr3)
6262 * SelectObject(hdc, oldfnt)
6263 * DeleteObject(fnt2)
6265 * InvalidateRect(toolbar, 0, 1)
6266 * SetWindowLongW(toolbar, 0, addr)
6267 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6270 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6271 * ie 2 0x4600094c 0x4600094c 0x4600894d
6272 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6273 * rebar 0x50008844 0x40008844 0x50008845
6274 * pager 0x50000844 0x40000844 0x50008845
6275 * IC35mgr 0x5400084e **nochange**
6276 * on entry to _NCCREATE 0x5400084e
6277 * rowlist 0x5400004e **nochange**
6278 * on entry to _NCCREATE 0x5400004e
6282 /* I think the code below is a bug, but it is the way that the native
6283 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6284 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6285 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6286 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6287 * Somehow, the only cases of this seem to be MFC programs.
6289 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6290 * does not occur in the WM_STYLECHANGING routine.
6291 * (Guy Albertelli 9/2001)
6294 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6295 && !(cs->style & TBSTYLE_TRANSPARENT))
6296 styleadd |= TBSTYLE_TRANSPARENT;
6297 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6298 styleadd |= CCS_TOP; /* default to top */
6299 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6302 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6307 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6309 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6313 if (dwStyle & WS_MINIMIZE)
6314 return 0; /* Nothing to do */
6316 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6318 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6321 if (!(dwStyle & CCS_NODIVIDER))
6323 GetWindowRect (hwnd, &rcWindow);
6324 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6325 if( dwStyle & WS_BORDER )
6326 OffsetRect (&rcWindow, 1, 1);
6327 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6330 ReleaseDC( hwnd, hdc );
6336 /* handles requests from the tooltip control on what text to display */
6337 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6339 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6341 TRACE("button index = %d\n", index);
6343 Free (infoPtr->pszTooltipText);
6344 infoPtr->pszTooltipText = NULL;
6349 if (infoPtr->bUnicode)
6351 WCHAR wszBuffer[INFOTIPSIZE+1];
6352 NMTBGETINFOTIPW tbgit;
6353 unsigned int len; /* in chars */
6355 wszBuffer[0] = '\0';
6356 wszBuffer[INFOTIPSIZE] = '\0';
6358 tbgit.pszText = wszBuffer;
6359 tbgit.cchTextMax = INFOTIPSIZE;
6360 tbgit.iItem = lpnmtdi->hdr.idFrom;
6361 tbgit.lParam = infoPtr->buttons[index].dwData;
6363 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6365 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6367 len = strlenW(tbgit.pszText);
6368 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6370 /* need to allocate temporary buffer in infoPtr as there
6371 * isn't enough space in buffer passed to us by the
6372 * tooltip control */
6373 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6374 if (infoPtr->pszTooltipText)
6376 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6377 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6383 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6389 CHAR szBuffer[INFOTIPSIZE+1];
6390 NMTBGETINFOTIPA tbgit;
6391 unsigned int len; /* in chars */
6394 szBuffer[INFOTIPSIZE] = '\0';
6396 tbgit.pszText = szBuffer;
6397 tbgit.cchTextMax = INFOTIPSIZE;
6398 tbgit.iItem = lpnmtdi->hdr.idFrom;
6399 tbgit.lParam = infoPtr->buttons[index].dwData;
6401 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6403 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6405 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6406 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6408 /* need to allocate temporary buffer in infoPtr as there
6409 * isn't enough space in buffer passed to us by the
6410 * tooltip control */
6411 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6412 if (infoPtr->pszTooltipText)
6414 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6415 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6421 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6422 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6427 /* if button has text, but it is not shown then automatically
6428 * use that text as tooltip */
6429 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6430 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6432 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6433 unsigned int len = pszText ? strlenW(pszText) : 0;
6435 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6437 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6439 /* need to allocate temporary buffer in infoPtr as there
6440 * isn't enough space in buffer passed to us by the
6441 * tooltip control */
6442 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6443 if (infoPtr->pszTooltipText)
6445 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6446 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6452 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6457 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6459 /* last resort: send notification on to app */
6460 /* FIXME: find out what is really used here */
6461 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6465 inline static LRESULT
6466 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6469 LPNMHDR lpnmh = (LPNMHDR)lParam;
6471 switch (lpnmh->code)
6475 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6477 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6478 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6479 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6483 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6484 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6492 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6494 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6495 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6496 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6497 lppgs->iScroll, lppgs->iDir);
6501 case TTN_GETDISPINFOW:
6502 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6504 case TTN_GETDISPINFOA:
6505 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6515 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6519 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6521 if (lParam == NF_QUERY)
6524 if (lParam == NF_REQUERY) {
6525 format = SendMessageW(infoPtr->hwndNotify,
6526 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6527 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6528 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6539 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6545 /* fill ps.rcPaint with a default rect */
6546 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6548 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6550 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6551 ps.rcPaint.left, ps.rcPaint.top,
6552 ps.rcPaint.right, ps.rcPaint.bottom);
6554 TOOLBAR_Refresh (hwnd, hdc, &ps);
6555 if (!wParam) EndPaint (hwnd, &ps);
6562 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6566 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6568 /* make first item hot */
6569 if (infoPtr->nNumButtons > 0)
6570 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6577 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6578 /*****************************************************
6581 * Handles the WM_SETREDRAW message.
6584 * According to testing V4.71 of COMCTL32 returns the
6585 * *previous* status of the redraw flag (either 0 or 1)
6586 * instead of the MSDN documented value of 0 if handled.
6587 * (For laughs see the "consistency" with same function
6590 *****************************************************/
6592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6593 BOOL oldredraw = infoPtr->bDoRedraw;
6595 TRACE("set to %s\n",
6596 (wParam) ? "TRUE" : "FALSE");
6597 infoPtr->bDoRedraw = (BOOL) wParam;
6599 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6601 return (oldredraw) ? 1 : 0;
6606 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6610 TRACE("sizing toolbar!\n");
6612 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6614 RECT delta_width, delta_height, client, dummy;
6615 DWORD min_x, max_x, min_y, max_y;
6616 TBUTTON_INFO *btnPtr;
6619 GetClientRect(hwnd, &client);
6620 if(client.right > infoPtr->client_rect.right)
6622 min_x = infoPtr->client_rect.right;
6623 max_x = client.right;
6627 max_x = infoPtr->client_rect.right;
6628 min_x = client.right;
6630 if(client.bottom > infoPtr->client_rect.bottom)
6632 min_y = infoPtr->client_rect.bottom;
6633 max_y = client.bottom;
6637 max_y = infoPtr->client_rect.bottom;
6638 min_y = client.bottom;
6641 SetRect(&delta_width, min_x, 0, max_x, min_y);
6642 SetRect(&delta_height, 0, min_y, max_x, max_y);
6644 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6645 btnPtr = infoPtr->buttons;
6646 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6647 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6648 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6649 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6651 GetClientRect(hwnd, &infoPtr->client_rect);
6652 TOOLBAR_AutoSize(hwnd);
6658 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6662 if (nType == GWL_STYLE)
6664 DWORD dwOldStyle = infoPtr->dwStyle;
6666 if (lpStyle->styleNew & TBSTYLE_LIST)
6667 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6669 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6671 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6673 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6675 infoPtr->dwStyle = lpStyle->styleNew;
6677 /* only resize if one of the CCS_* styles was changed */
6678 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6680 TOOLBAR_AutoSize (hwnd);
6682 InvalidateRect(hwnd, NULL, TRUE);
6691 TOOLBAR_SysColorChange (HWND hwnd)
6693 COMCTL32_RefreshSysColors();
6699 /* update theme after a WM_THEMECHANGED message */
6700 static LRESULT theme_changed (HWND hwnd)
6702 HTHEME theme = GetWindowTheme (hwnd);
6703 CloseThemeData (theme);
6704 OpenThemeData (hwnd, themeClass);
6709 static LRESULT WINAPI
6710 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6712 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6714 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6715 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6717 if (!infoPtr && (uMsg != WM_NCCREATE))
6718 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6723 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6725 case TB_ADDBUTTONSA:
6726 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6728 case TB_ADDBUTTONSW:
6729 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6732 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6735 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6738 return TOOLBAR_AutoSize (hwnd);
6740 case TB_BUTTONCOUNT:
6741 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6743 case TB_BUTTONSTRUCTSIZE:
6744 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6746 case TB_CHANGEBITMAP:
6747 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6749 case TB_CHECKBUTTON:
6750 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6752 case TB_COMMANDTOINDEX:
6753 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6756 return TOOLBAR_Customize (hwnd);
6758 case TB_DELETEBUTTON:
6759 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6761 case TB_ENABLEBUTTON:
6762 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6764 case TB_GETANCHORHIGHLIGHT:
6765 return TOOLBAR_GetAnchorHighlight (hwnd);
6768 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6770 case TB_GETBITMAPFLAGS:
6771 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6774 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6776 case TB_GETBUTTONINFOA:
6777 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6779 case TB_GETBUTTONINFOW:
6780 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6782 case TB_GETBUTTONSIZE:
6783 return TOOLBAR_GetButtonSize (hwnd);
6785 case TB_GETBUTTONTEXTA:
6786 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6788 case TB_GETBUTTONTEXTW:
6789 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6791 case TB_GETDISABLEDIMAGELIST:
6792 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6794 case TB_GETEXTENDEDSTYLE:
6795 return TOOLBAR_GetExtendedStyle (hwnd);
6797 case TB_GETHOTIMAGELIST:
6798 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6801 return TOOLBAR_GetHotItem (hwnd);
6803 case TB_GETIMAGELIST:
6804 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6806 case TB_GETINSERTMARK:
6807 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6809 case TB_GETINSERTMARKCOLOR:
6810 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6812 case TB_GETITEMRECT:
6813 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6816 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6818 /* case TB_GETOBJECT: */ /* 4.71 */
6821 return TOOLBAR_GetPadding (hwnd);
6824 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6827 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6830 return TOOLBAR_GetState (hwnd, wParam, lParam);
6833 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6836 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6839 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6841 case TB_GETTEXTROWS:
6842 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6844 case TB_GETTOOLTIPS:
6845 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6847 case TB_GETUNICODEFORMAT:
6848 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6851 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6854 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6856 case TB_INDETERMINATE:
6857 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6859 case TB_INSERTBUTTONA:
6860 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6862 case TB_INSERTBUTTONW:
6863 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6865 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6867 case TB_ISBUTTONCHECKED:
6868 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6870 case TB_ISBUTTONENABLED:
6871 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6873 case TB_ISBUTTONHIDDEN:
6874 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6876 case TB_ISBUTTONHIGHLIGHTED:
6877 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6879 case TB_ISBUTTONINDETERMINATE:
6880 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6882 case TB_ISBUTTONPRESSED:
6883 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6886 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6888 case TB_MAPACCELERATORA:
6889 case TB_MAPACCELERATORW:
6890 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6893 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6896 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6898 case TB_PRESSBUTTON:
6899 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6901 case TB_REPLACEBITMAP:
6902 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6904 case TB_SAVERESTOREA:
6905 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6907 case TB_SAVERESTOREW:
6908 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6910 case TB_SETANCHORHIGHLIGHT:
6911 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6913 case TB_SETBITMAPSIZE:
6914 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6916 case TB_SETBUTTONINFOA:
6917 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6919 case TB_SETBUTTONINFOW:
6920 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6922 case TB_SETBUTTONSIZE:
6923 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6925 case TB_SETBUTTONWIDTH:
6926 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6929 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6931 case TB_SETDISABLEDIMAGELIST:
6932 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6934 case TB_SETDRAWTEXTFLAGS:
6935 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6937 case TB_SETEXTENDEDSTYLE:
6938 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6940 case TB_SETHOTIMAGELIST:
6941 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6944 return TOOLBAR_SetHotItem (hwnd, wParam);
6946 case TB_SETIMAGELIST:
6947 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6950 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6952 case TB_SETINSERTMARK:
6953 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6955 case TB_SETINSERTMARKCOLOR:
6956 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6958 case TB_SETMAXTEXTROWS:
6959 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6962 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6965 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6968 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6971 return TOOLBAR_SetState (hwnd, wParam, lParam);
6974 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6976 case TB_SETTOOLTIPS:
6977 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6979 case TB_SETUNICODEFORMAT:
6980 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6983 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6986 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6989 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6992 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6995 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6998 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7000 /* Common Control Messages */
7002 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7003 case CCM_GETCOLORSCHEME:
7004 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7006 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7007 case CCM_SETCOLORSCHEME:
7008 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7010 case CCM_GETVERSION:
7011 return TOOLBAR_GetVersion (hwnd);
7013 case CCM_SETVERSION:
7014 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7020 return TOOLBAR_Create (hwnd, wParam, lParam);
7023 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7026 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7029 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7032 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7034 /* case WM_KILLFOCUS: */
7036 case WM_LBUTTONDBLCLK:
7037 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7039 case WM_LBUTTONDOWN:
7040 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7043 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7046 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7048 case WM_RBUTTONDBLCLK:
7049 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7052 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7055 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7057 case WM_CAPTURECHANGED:
7058 return TOOLBAR_CaptureChanged(hwnd);
7061 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7064 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7067 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7070 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7073 return TOOLBAR_Notify (hwnd, wParam, lParam);
7075 case WM_NOTIFYFORMAT:
7076 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7078 case WM_PRINTCLIENT:
7080 return TOOLBAR_Paint (hwnd, wParam);
7083 return TOOLBAR_SetFocus (hwnd, wParam);
7086 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7089 return TOOLBAR_Size (hwnd, wParam, lParam);
7091 case WM_STYLECHANGED:
7092 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7094 case WM_SYSCOLORCHANGE:
7095 return TOOLBAR_SysColorChange (hwnd);
7097 case WM_THEMECHANGED:
7098 return theme_changed (hwnd);
7100 /* case WM_WININICHANGE: */
7105 case WM_MEASUREITEM:
7107 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7109 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7110 case PGM_FORWARDMOUSE:
7111 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7114 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7115 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7116 uMsg, wParam, lParam);
7117 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7123 TOOLBAR_Register (void)
7127 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7128 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7129 wndClass.lpfnWndProc = ToolbarWindowProc;
7130 wndClass.cbClsExtra = 0;
7131 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7132 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7133 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7134 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7136 RegisterClassW (&wndClass);
7141 TOOLBAR_Unregister (void)
7143 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7146 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7151 /* Check if the entry already exists */
7152 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7154 /* If this is a new entry we must create it and insert into the array */
7159 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7162 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7163 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7178 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7182 for (i = 0; i < *cies; i++)
7192 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7200 for (i = 0; i < cies; i++)
7202 if (pies[i]->id == id)
7214 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7216 HIMAGELIST himlDef = 0;
7217 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7220 himlDef = pie->himl;
7226 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7228 if (infoPtr->bUnicode)
7229 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7236 nmtba.iItem = nmtb->iItem;
7237 nmtba.pszText = Buffer;
7238 nmtba.cchText = 256;
7239 ZeroMemory(nmtba.pszText, nmtba.cchText);
7241 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7243 int ccht = strlen(nmtba.pszText);
7245 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7246 nmtb->pszText, nmtb->cchText);
7248 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7257 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7258 int iItem, PCUSTOMBUTTON btnInfo)
7262 /* MSDN states that iItem is the index of the button, rather than the
7263 * command ID as used by every other NMTOOLBAR notification */
7265 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7267 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);