4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
47 * - Button wrapping (under construction).
49 * - iListGap custom draw support.
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsoft's controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
61 * Differences between MSDN and actual native control operation:
62 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
63 * to the right of the bitmap. Otherwise, this style is
64 * identical to TBSTYLE_FLAT."
65 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
66 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
67 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
68 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
80 #include "wine/unicode.h"
86 #include "wine/debug.h"
88 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
90 static HCURSOR hCursorDrag = NULL;
99 BYTE bDropDownPressed;
104 INT cx; /* manually set size */
118 } IMLENTRY, *PIMLENTRY;
122 DWORD dwStructSize; /* size of TBBUTTON struct */
123 INT nWidth; /* width of the toolbar */
125 RECT rcBound; /* bounding rectangle */
131 INT nRows; /* number of button rows */
132 INT nMaxTextRows; /* maximum number of text rows */
133 INT cxMin; /* minimum button width */
134 INT cxMax; /* maximum button width */
135 INT nNumButtons; /* number of buttons */
136 INT nNumBitmaps; /* number of bitmaps */
137 INT nNumStrings; /* number of strings */
139 INT nButtonDown; /* toolbar button being pressed or -1 if none */
140 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
142 INT nHotItem; /* index of the "hot" item */
143 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
144 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
145 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
146 SIZE szPadding; /* padding values around button */
147 INT iListGap; /* default gap between text and image for toolbar with list style */
149 HFONT hFont; /* text font */
150 HIMAGELIST himlInt; /* image list created internally */
151 PIMLENTRY *himlDef; /* default image list array */
152 INT cimlDef; /* default image list array count */
153 PIMLENTRY *himlHot; /* hot image list array */
154 INT cimlHot; /* hot image list array count */
155 PIMLENTRY *himlDis; /* disabled image list array */
156 INT cimlDis; /* disabled image list array count */
157 HWND hwndToolTip; /* handle to tool tip control */
158 HWND hwndNotify; /* handle to the window that gets notifications */
159 HWND hwndSelf; /* my own handle */
160 BOOL bAnchor; /* anchor highlight enabled */
161 BOOL bDoRedraw; /* Redraw status */
162 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
163 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
164 BOOL bCaptured; /* mouse captured? */
165 DWORD dwStyle; /* regular toolbar style */
166 DWORD dwExStyle; /* extended toolbar style */
167 DWORD dwDTFlags; /* DrawText flags */
169 COLORREF clrInsertMark; /* insert mark color */
170 COLORREF clrBtnHighlight; /* color for Flat Separator */
171 COLORREF clrBtnShadow; /* color for Flag Separator */
173 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
174 * for TTN_GETDISPINFOW notification */
175 TBINSERTMARK tbim; /* info on insertion mark */
176 TBUTTON_INFO *buttons; /* pointer to button array */
177 LPWSTR *strings; /* pointer to string array */
178 TBITMAP_INFO *bitmaps;
179 } TOOLBAR_INFO, *PTOOLBAR_INFO;
182 /* used by customization dialog */
185 PTOOLBAR_INFO tbInfo;
187 } CUSTDLG_INFO, *PCUSTDLG_INFO;
195 } CUSTOMBUTTON, *PCUSTOMBUTTON;
204 #define SEPARATOR_WIDTH 8
206 #define BOTTOM_BORDER 2
207 #define DDARROW_WIDTH 11
208 #define ARROW_HEIGHT 3
209 #define INSERTMARK_WIDTH 2
215 /* vertical padding used in list mode when image is present */
218 /* how wide to treat the bitmap if it isn't present */
219 #define NONLIST_NOTEXT_OFFSET 2
221 #define TOOLBAR_NOWHERE (-1)
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
224 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
225 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
227 /* Used to find undocumented extended styles */
228 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
229 TBSTYLE_EX_UNDOC1 | \
230 TBSTYLE_EX_MIXEDBUTTONS | \
231 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
233 /* all of the CCS_ styles */
234 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
235 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
237 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
238 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
239 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
240 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
241 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
243 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
245 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
246 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
247 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
248 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
249 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
250 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
251 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
252 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
253 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
260 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
262 LPWSTR lpText = NULL;
264 /* NOTE: iString == -1 is undocumented */
265 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
266 lpText = (LPWSTR)btnPtr->iString;
267 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
268 lpText = infoPtr->strings[btnPtr->iString];
274 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
276 if (TRACE_ON(toolbar)){
277 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
278 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
279 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
280 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
282 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
283 btn_num, bP->idCommand,
284 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
285 bP->rect.left, bP->rect.top,
286 bP->rect.right, bP->rect.bottom);
292 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
294 if (TRACE_ON(toolbar)) {
297 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
299 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
300 iP->nNumStrings, iP->dwStyle);
301 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
303 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
304 (iP->bDoRedraw) ? "TRUE" : "FALSE");
305 for(i=0; i<iP->nNumButtons; i++) {
306 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
312 /***********************************************************************
315 * This function validates that the styles set are implemented and
316 * issues FIXME's warning of possible problems. In a perfect world this
317 * function should be null.
320 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
322 if (dwStyle & TBSTYLE_REGISTERDROP)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
328 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
330 if(!IsWindow(infoPtr->hwndSelf))
331 return 0; /* we have just been destroyed */
333 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
334 nmhdr->hwndFrom = infoPtr->hwndSelf;
337 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
338 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
340 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
354 INT ret = btnPtr->iBitmap;
356 if (ret == I_IMAGECALLBACK)
358 /* issue TBN_GETDISPINFO */
361 memset(&nmgd, 0, sizeof(nmgd));
362 nmgd.idCommand = btnPtr->idCommand;
363 nmgd.lParam = btnPtr->dwData;
364 nmgd.dwMask = TBNF_IMAGE;
365 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
366 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
367 if (nmgd.dwMask & TBNF_DI_SETITEM)
368 btnPtr->iBitmap = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
398 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
400 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
401 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
412 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
416 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
417 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
418 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
419 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
423 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
424 if ((*index == I_IMAGECALLBACK) ||
425 (*index == I_IMAGENONE)) return NULL;
426 ERR("TBN_GETDISPINFO returned invalid index %d\n",
433 case IMAGE_LIST_DEFAULT:
434 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
437 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 case IMAGE_LIST_DISABLED:
440 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
444 FIXME("Shouldn't reach here\n");
448 TRACE("no image list\n");
455 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
458 COLORREF oldcolor, newcolor;
460 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
461 myrect.right = myrect.left + 1;
462 myrect.top = lpRect->top + 2;
463 myrect.bottom = lpRect->bottom - 2;
465 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
466 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
467 oldcolor = SetBkColor (hdc, newcolor);
468 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
470 myrect.left = myrect.right;
471 myrect.right = myrect.left + 1;
473 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
474 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
475 SetBkColor (hdc, newcolor);
476 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
478 SetBkColor (hdc, oldcolor);
482 /***********************************************************************
483 * TOOLBAR_DrawDDFlatSeparator
485 * This function draws the separator that was flagged as BTNS_DROPDOWN.
486 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
487 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
488 * are horizontal as opposed to the vertical separators for not dropdown
491 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
494 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
497 COLORREF oldcolor, newcolor;
499 myrect.left = lpRect->left;
500 myrect.right = lpRect->right;
501 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
502 myrect.bottom = myrect.top + 1;
504 InflateRect (&myrect, -2, 0);
506 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
507 myrect.left, myrect.top, myrect.right, myrect.bottom);
509 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
510 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
511 oldcolor = SetBkColor (hdc, newcolor);
512 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
514 myrect.top = myrect.bottom;
515 myrect.bottom = myrect.top + 1;
517 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
518 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
519 SetBkColor (hdc, newcolor);
520 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
522 SetBkColor (hdc, oldcolor);
527 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
532 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
533 hOldPen = SelectObject ( hdc, hPen );
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+5, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+3, y++); x++;
540 MoveToEx (hdc, x, y, NULL);
541 LineTo (hdc, x+1, y++);
542 SelectObject( hdc, hOldPen );
543 DeleteObject( hPen );
547 * Draw the text string for this button.
548 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
549 * is non-zero, so we can simply check himlDef to see if we have
553 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
554 NMTBCUSTOMDRAW *tbcd)
556 HDC hdc = tbcd->nmcd.hdc;
559 COLORREF clrOldBk = 0;
561 UINT state = tbcd->nmcd.uItemState;
565 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
566 rcText->left, rcText->top, rcText->right, rcText->bottom);
568 hOldFont = SelectObject (hdc, infoPtr->hFont);
569 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
570 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
572 else if (state & CDIS_DISABLED) {
573 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
574 OffsetRect (rcText, 1, 1);
575 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
576 SetTextColor (hdc, comctl32_color.clr3dShadow);
577 OffsetRect (rcText, -1, -1);
579 else if (state & CDIS_INDETERMINATE) {
580 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
582 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
583 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
584 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
585 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
588 clrOld = SetTextColor (hdc, tbcd->clrText);
591 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
592 SetTextColor (hdc, clrOld);
593 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
595 SetBkColor (hdc, clrOldBk);
596 SetBkMode (hdc, oldBkMode);
598 SelectObject (hdc, hOldFont);
604 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
606 HDC hdc = tbcd->nmcd.hdc;
607 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
610 INT cx = lpRect->right - lpRect->left;
611 INT cy = lpRect->bottom - lpRect->top;
612 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
613 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
614 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
615 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
616 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
617 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
618 SetBkColor(hdc, clrBkOld);
619 SetTextColor(hdc, clrTextOld);
620 SelectObject (hdc, hbr);
624 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
627 HBITMAP hbmMask, hbmImage;
628 HDC hdcMask, hdcImage;
630 ImageList_GetIconSize(himl, &cx, &cy);
632 /* Create src image */
633 hdcImage = CreateCompatibleDC(hdc);
634 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
635 SelectObject(hdcImage, hbmImage);
636 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
637 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
640 hdcMask = CreateCompatibleDC(0);
641 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
642 SelectObject(hdcMask, hbmMask);
644 /* Remove the background and all white pixels */
645 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
646 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
647 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
648 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
650 /* draw the new mask 'etched' to hdc */
651 SetBkColor(hdc, RGB(255, 255, 255));
652 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
653 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
654 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
655 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
656 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
659 DeleteObject(hbmImage);
661 DeleteObject (hbmMask);
667 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
671 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
672 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
673 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
674 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
675 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
676 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
677 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
681 /* draws the image on a toolbar button */
683 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
685 HIMAGELIST himl = NULL;
686 BOOL draw_masked = FALSE;
689 UINT draw_flags = ILD_TRANSPARENT;
691 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
693 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
696 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
700 else if ((tbcd->nmcd.uItemState & CDIS_HOT)
701 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
703 /* if hot, attempt to draw with hot image list, if fails,
704 use default image list */
705 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
715 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
716 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
719 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
720 (tbcd->nmcd.uItemState & CDIS_MARKED))
721 draw_flags |= ILD_BLEND50;
723 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
724 index, himl, left, top, offset);
727 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
729 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
732 /* draws a blank frame for a toolbar button */
734 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
736 HDC hdc = tbcd->nmcd.hdc;
737 RECT rc = tbcd->nmcd.rc;
738 /* if the state is disabled or indeterminate then the button
739 * cannot have an interactive look like pressed or hot */
740 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
741 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
742 BOOL pressed_look = !non_interactive_state &&
743 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
744 (tbcd->nmcd.uItemState & CDIS_CHECKED));
746 /* app don't want us to draw any edges */
747 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
750 if (infoPtr->dwStyle & TBSTYLE_FLAT)
753 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
754 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
755 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
760 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE);
768 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
770 HDC hdc = tbcd->nmcd.hdc;
772 BOOL pressed = bDropDownPressed ||
773 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
775 if (infoPtr->dwStyle & TBSTYLE_FLAT)
778 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
779 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
780 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
781 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
782 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
787 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
789 DrawEdge (hdc, rcArrow, EDGE_RAISED,
790 BF_SOFT | BF_RECT | BF_MIDDLE);
794 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
796 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
798 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
799 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
802 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
805 /* draws a complete toolbar button */
807 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
810 DWORD dwStyle = infoPtr->dwStyle;
811 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
812 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
813 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
814 BOOL drawSepDropDownArrow = hasDropDownArrow &&
815 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
816 RECT rc, rcArrow, rcBitmap, rcText;
817 LPWSTR lpText = NULL;
822 HTHEME theme = GetWindowTheme (hwnd);
825 CopyRect (&rcArrow, &rc);
827 /* get a pointer to the text */
828 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
830 if (hasDropDownArrow)
834 if (dwStyle & TBSTYLE_FLAT)
835 right = max(rc.left, rc.right - DDARROW_WIDTH);
837 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
839 if (drawSepDropDownArrow)
842 rcArrow.left = right;
845 /* copy text & bitmap rects after adjusting for drop-down arrow
846 * so that text & bitmap is centred in the rectangle not containing
848 CopyRect(&rcText, &rc);
849 CopyRect(&rcBitmap, &rc);
851 /* Center the bitmap horizontally and vertically */
852 if (dwStyle & TBSTYLE_LIST)
855 infoPtr->nMaxTextRows > 0 &&
856 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
857 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
858 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
860 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
863 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
865 rcBitmap.top += infoPtr->szPadding.cy / 2;
867 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
868 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
869 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
870 TRACE("Text=%s\n", debugstr_w(lpText));
871 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
873 /* calculate text position */
876 rcText.left += GetSystemMetrics(SM_CXEDGE);
877 rcText.right -= GetSystemMetrics(SM_CXEDGE);
878 if (dwStyle & TBSTYLE_LIST)
880 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
881 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
885 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
886 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
888 rcText.top += infoPtr->szPadding.cy/2 + 2;
892 /* Initialize fields in all cases, because we use these later
893 * NOTE: applications can and do alter these to customize their
895 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
896 tbcd.clrText = comctl32_color.clrBtnText;
897 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
898 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
899 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
900 tbcd.clrMark = comctl32_color.clrHighlight;
901 tbcd.clrHighlightHotTrack = 0;
902 tbcd.nStringBkMode = TRANSPARENT;
903 tbcd.nHLStringBkMode = OPAQUE;
904 /* MSDN says that this is the text rectangle.
905 * But (why always a but) tracing of v5.7 of native shows
906 * that this is really a *relative* rectangle based on the
907 * the nmcd.rc. Also the left and top are always 0 ignoring
908 * any bitmap that might be present. */
909 tbcd.rcText.left = 0;
911 tbcd.rcText.right = rcText.right - rc.left;
912 tbcd.rcText.bottom = rcText.bottom - rc.top;
913 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
916 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
918 /* FIXME: what are these used for? */
922 /* Issue Item Prepaint notify */
923 infoPtr->dwItemCustDraw = 0;
924 infoPtr->dwItemCDFlag = 0;
925 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
927 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
928 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
929 tbcd.nmcd.lItemlParam = btnPtr->dwData;
930 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
931 /* reset these fields so the user can't alter the behaviour like native */
935 infoPtr->dwItemCustDraw = ntfret & 0xffff;
936 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
937 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
939 /* save the only part of the rect that the user can change */
940 rcText.right = tbcd.rcText.right + rc.left;
941 rcText.bottom = tbcd.rcText.bottom + rc.top;
945 if (btnPtr->fsStyle & BTNS_SEP) {
948 DrawThemeBackground (theme, hdc,
949 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
950 &tbcd.nmcd.rc, NULL);
953 /* with the FLAT style, iBitmap is the width and has already */
954 /* been taken into consideration in calculating the width */
955 /* so now we need to draw the vertical separator */
956 /* empirical tests show that iBitmap can/will be non-zero */
957 /* when drawing the vertical bar... */
958 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
959 if (btnPtr->fsStyle & BTNS_DROPDOWN)
960 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
962 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
964 else if (btnPtr->fsStyle != BTNS_SEP) {
965 FIXME("Draw some kind of separator: fsStyle=%x\n",
971 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
972 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
973 OffsetRect(&rcText, 1, 1);
975 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
976 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
977 TOOLBAR_DrawPattern (&rc, &tbcd);
979 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
980 && (tbcd.nmcd.uItemState & CDIS_HOT))
982 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
986 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
987 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
988 if (hasDropDownArrow)
989 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
990 SetBkColor(hdc, oldclr);
996 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
997 int stateId = TS_NORMAL;
999 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1000 stateId = TS_DISABLED;
1001 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1002 stateId = TS_PRESSED;
1003 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1004 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1005 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1006 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1009 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1012 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1014 if (drawSepDropDownArrow)
1018 int stateId = TS_NORMAL;
1020 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1021 stateId = TS_DISABLED;
1022 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1023 stateId = TS_PRESSED;
1024 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1025 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1026 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1029 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1030 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1033 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1036 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1037 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1038 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1039 SetBkMode (hdc, oldBkMode);
1041 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1043 if (hasDropDownArrow && !drawSepDropDownArrow)
1045 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1047 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1048 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1050 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1052 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1053 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1060 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1062 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1063 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1070 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1073 TBUTTON_INFO *btnPtr;
1075 RECT rcTemp, rcClient;
1076 NMTBCUSTOMDRAW tbcd;
1079 /* the app has told us not to redraw the toolbar */
1080 if (!infoPtr->bDoRedraw)
1083 /* if imagelist belongs to the app, it can be changed
1084 by the app after setting it */
1085 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1087 infoPtr->nNumBitmaps = 0;
1088 for (i = 0; i < infoPtr->cimlDef; i++)
1089 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1092 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1094 /* Send initial notify */
1095 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1096 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1097 tbcd.nmcd.hdc = hdc;
1098 tbcd.nmcd.rc = ps->rcPaint;
1099 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1100 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1102 GetClientRect(hwnd, &rcClient);
1104 /* redraw necessary buttons */
1105 btnPtr = infoPtr->buttons;
1106 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1109 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1111 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1112 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1116 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1117 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1119 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1122 /* draw insert mark if required */
1123 if (infoPtr->tbim.iButton != -1)
1125 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1127 rcInsertMark.top = rcButton.top;
1128 rcInsertMark.bottom = rcButton.bottom;
1129 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1130 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1132 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1133 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1136 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1138 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1139 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1140 tbcd.nmcd.hdc = hdc;
1141 tbcd.nmcd.rc = ps->rcPaint;
1142 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1146 /***********************************************************************
1147 * TOOLBAR_MeasureString
1149 * This function gets the width and height of a string in pixels. This
1150 * is done first by using GetTextExtentPoint to get the basic width
1151 * and height. The DrawText is called with DT_CALCRECT to get the exact
1152 * width. The reason is because the text may have more than one "&" (or
1153 * prefix characters as M$ likes to call them). The prefix character
1154 * indicates where the underline goes, except for the string "&&" which
1155 * is reduced to a single "&". GetTextExtentPoint does not process these
1156 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1159 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1160 HDC hdc, LPSIZE lpSize)
1167 if (infoPtr->nMaxTextRows > 0 &&
1168 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1169 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1170 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1172 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1174 if(lpText != NULL) {
1175 /* first get size of all the text */
1176 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1178 /* feed above size into the rectangle for DrawText */
1179 myrect.left = myrect.top = 0;
1180 myrect.right = lpSize->cx;
1181 myrect.bottom = lpSize->cy;
1183 /* Use DrawText to get true size as drawn (less pesky "&") */
1184 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1185 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1188 /* feed back to caller */
1189 lpSize->cx = myrect.right;
1190 lpSize->cy = myrect.bottom;
1194 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1197 /***********************************************************************
1198 * TOOLBAR_CalcStrings
1200 * This function walks through each string and measures it and returns
1201 * the largest height and width to caller.
1204 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1206 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1207 TBUTTON_INFO *btnPtr;
1216 if (infoPtr->nMaxTextRows == 0)
1220 hOldFont = SelectObject (hdc, infoPtr->hFont);
1222 if (infoPtr->nNumButtons == 0)
1226 GetTextMetricsW(hdc, &tm);
1227 lpSize->cy = tm.tmHeight;
1230 btnPtr = infoPtr->buttons;
1231 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1232 if(TOOLBAR_HasText(infoPtr, btnPtr))
1234 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1235 if (sz.cx > lpSize->cx)
1237 if (sz.cy > lpSize->cy)
1242 SelectObject (hdc, hOldFont);
1243 ReleaseDC (hwnd, hdc);
1245 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1248 /***********************************************************************
1249 * TOOLBAR_WrapToolbar
1251 * This function walks through the buttons and separators in the
1252 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1253 * wrapping should occur based on the width of the toolbar window.
1254 * It does *not* calculate button placement itself. That task
1255 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1256 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1257 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1259 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1260 * vertical toolbar lists.
1264 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1267 TBUTTON_INFO *btnPtr;
1270 BOOL bWrap, bButtonWrap;
1272 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1273 /* no layout is necessary. Applications may use this style */
1274 /* to perform their own layout on the toolbar. */
1275 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1276 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1278 btnPtr = infoPtr->buttons;
1279 x = infoPtr->nIndent;
1281 /* this can get the parents width, to know how far we can extend
1282 * this toolbar. We cannot use its height, as there may be multiple
1283 * toolbars in a rebar control
1285 GetClientRect( GetParent(hwnd), &rc );
1286 infoPtr->nWidth = rc.right - rc.left;
1287 bButtonWrap = FALSE;
1289 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1290 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1293 for (i = 0; i < infoPtr->nNumButtons; i++ )
1296 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1298 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1301 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1302 /* it is the actual width of the separator. This is used for */
1303 /* custom controls in toolbars. */
1305 /* BTNS_DROPDOWN separators are treated as buttons for */
1306 /* width. - GA 8/01 */
1307 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1308 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1309 cx = (btnPtr[i].iBitmap > 0) ?
1310 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1312 cx = infoPtr->nButtonWidth;
1314 /* Two or more adjacent separators form a separator group. */
1315 /* The first separator in a group should be wrapped to the */
1316 /* next row if the previous wrapping is on a button. */
1318 (btnPtr[i].fsStyle & BTNS_SEP) &&
1319 (i + 1 < infoPtr->nNumButtons ) &&
1320 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1322 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1323 btnPtr[i].fsState |= TBSTATE_WRAP;
1324 x = infoPtr->nIndent;
1326 bButtonWrap = FALSE;
1330 /* The layout makes sure the bitmap is visible, but not the button. */
1331 /* Test added to also wrap after a button that starts a row but */
1332 /* is bigger than the area. - GA 8/01 */
1333 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1334 > infoPtr->nWidth ) ||
1335 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1337 BOOL bFound = FALSE;
1339 /* If the current button is a separator and not hidden, */
1340 /* go to the next until it reaches a non separator. */
1341 /* Wrap the last separator if it is before a button. */
1342 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1343 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1344 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1345 i < infoPtr->nNumButtons )
1351 if( bFound && i < infoPtr->nNumButtons )
1354 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1355 i, btnPtr[i].fsStyle, x, cx);
1356 btnPtr[i].fsState |= TBSTATE_WRAP;
1357 x = infoPtr->nIndent;
1358 bButtonWrap = FALSE;
1361 else if ( i >= infoPtr->nNumButtons)
1364 /* If the current button is not a separator, find the last */
1365 /* separator and wrap it. */
1366 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1368 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1369 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1373 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1374 i, btnPtr[i].fsStyle, x, cx);
1375 x = infoPtr->nIndent;
1376 btnPtr[j].fsState |= TBSTATE_WRAP;
1377 bButtonWrap = FALSE;
1382 /* If no separator available for wrapping, wrap one of */
1383 /* non-hidden previous button. */
1387 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1389 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1394 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1395 i, btnPtr[i].fsStyle, x, cx);
1396 x = infoPtr->nIndent;
1397 btnPtr[j].fsState |= TBSTATE_WRAP;
1403 /* If all above failed, wrap the current button. */
1406 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1407 i, btnPtr[i].fsStyle, x, cx);
1408 btnPtr[i].fsState |= TBSTATE_WRAP;
1410 x = infoPtr->nIndent;
1411 if (btnPtr[i].fsStyle & BTNS_SEP )
1412 bButtonWrap = FALSE;
1418 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1419 i, btnPtr[i].fsStyle, x, cx);
1426 /***********************************************************************
1427 * TOOLBAR_MeasureButton
1429 * Calculates the width and height required for a button. Used in
1430 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1431 * the width of buttons that are autosized.
1433 * Note that it would have been rather elegant to use one piece of code for
1434 * both the laying out of the toolbar and for controlling where button parts
1435 * are drawn, but the native control has inconsistencies between the two that
1436 * prevent this from being effectively. These inconsistencies can be seen as
1437 * artefacts where parts of the button appear outside of the bounding button
1440 * There are several cases for the calculation of the button dimensions and
1441 * button part positioning:
1448 * +--------------------------------------------------------+ ^
1450 * | | pad.cy / 2 | centred | |
1451 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1452 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1453 * | |<------------>| | | | |
1454 * | +--------------+ +------------+ | |
1455 * |<-------------------------------------->| | |
1456 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1458 * +--------------------------------------------------------+ -
1459 * <-------------------------------------------------------->
1460 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1462 * Without Bitmap (I_IMAGENONE):
1464 * +-----------------------------------+ ^
1466 * | | centred | | LISTPAD_CY +
1467 * | +------------+ | | szText.cy
1470 * | +------------+ | |
1471 * |<----------------->| | |
1472 * | cxedge |<-----------> | |
1474 * +-----------------------------------+ -
1475 * <----------------------------------->
1476 * szText.cx + pad.cx
1480 * +--------------------------------------+ ^
1482 * | | padding.cy/2 | | DEFPAD_CY +
1483 * | +------------+ | | nBitmapHeight
1486 * | +------------+ | |
1487 * |<------------------->| | |
1488 * | cxedge + iListGap/2 |<-----------> | |
1489 * | nBitmapWidth | |
1490 * +--------------------------------------+ -
1491 * <-------------------------------------->
1492 * 2*cxedge + nBitmapWidth + iListGap
1499 * +-----------------------------------+ ^
1501 * | | pad.cy / 2 | | nBitmapHeight +
1502 * | - | | szText.cy +
1503 * | +------------+ | | DEFPAD_CY + 1
1504 * | centred | Bitmap | | |
1505 * |<----------------->| | | |
1506 * | +------------+ | |
1510 * | centred +---------------+ | |
1511 * |<--------------->| Text | | |
1512 * | +---------------+ | |
1513 * +-----------------------------------+ -
1514 * <----------------------------------->
1515 * pad.cx + max(nBitmapWidth, szText.cx)
1517 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1519 * +---------------------------------------+ ^
1521 * | | 2 + pad.cy / 2 | |
1522 * | - | | szText.cy +
1523 * | centred +-----------------+ | | pad.cy + 2
1524 * |<--------------->| Text | | |
1525 * | +-----------------+ | |
1527 * +---------------------------------------+ -
1528 * <--------------------------------------->
1529 * 2*cxedge + pad.cx + szText.cx
1532 * As for with bitmaps, but with szText.cx zero.
1534 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1537 if (infoPtr->dwStyle & TBSTYLE_LIST)
1539 /* set button height from bitmap / text height... */
1540 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1543 /* ... add on the necessary padding */
1544 if (bValidImageList)
1547 sizeButton.cy += DEFPAD_CY;
1549 sizeButton.cy += LISTPAD_CY;
1552 sizeButton.cy += infoPtr->szPadding.cy;
1554 /* calculate button width */
1557 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1558 infoPtr->nBitmapWidth + infoPtr->iListGap;
1559 if (sizeString.cx > 0)
1560 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1563 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1569 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1570 sizeString.cy + DEFPAD_CY;
1571 sizeButton.cx = infoPtr->szPadding.cx +
1572 max(sizeString.cx, infoPtr->nBitmapWidth);
1576 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1577 NONLIST_NOTEXT_OFFSET;
1578 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1579 infoPtr->szPadding.cx + sizeString.cx;
1586 /***********************************************************************
1587 * TOOLBAR_CalcToolbar
1589 * This function calculates button and separator placement. It first
1590 * calculates the button sizes, gets the toolbar window width and then
1591 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1592 * on. It assigns a new location to each item and sends this location to
1593 * the tooltip window if appropriate. Finally, it updates the rcBound
1594 * rect and calculates the new required toolbar window height.
1597 TOOLBAR_CalcToolbar (HWND hwnd)
1599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1600 DWORD dwStyle = infoPtr->dwStyle;
1601 TBUTTON_INFO *btnPtr;
1602 INT i, nRows, nSepRows;
1604 SIZE sizeString, sizeButton;
1606 BOOL validImageList = FALSE;
1607 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1609 TOOLBAR_CalcStrings (hwnd, &sizeString);
1611 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1613 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1614 validImageList = TRUE;
1615 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1616 infoPtr->nButtonWidth = sizeButton.cx;
1617 infoPtr->nButtonHeight = sizeButton.cy;
1619 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1620 infoPtr->nButtonWidth = infoPtr->cxMin;
1621 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1622 infoPtr->nButtonWidth = infoPtr->cxMax;
1624 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1626 x = infoPtr->nIndent;
1627 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1632 /* from above, minimum is a button, and possible text */
1633 cx = infoPtr->nButtonWidth;
1634 cy = infoPtr->nButtonHeight;
1636 nRows = nSepRows = 0;
1638 infoPtr->rcBound.top = y;
1639 infoPtr->rcBound.left = x;
1640 infoPtr->rcBound.bottom = y + cy;
1641 infoPtr->rcBound.right = x;
1643 btnPtr = infoPtr->buttons;
1645 TRACE("cy=%d\n", cy);
1647 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1650 if (btnPtr->fsState & TBSTATE_HIDDEN)
1652 SetRectEmpty (&btnPtr->rect);
1656 cy = infoPtr->nButtonHeight;
1658 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1659 /* it is the actual width of the separator. This is used for */
1660 /* custom controls in toolbars. */
1661 if (btnPtr->fsStyle & BTNS_SEP) {
1662 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1663 cy = (btnPtr->iBitmap > 0) ?
1664 btnPtr->iBitmap : SEPARATOR_WIDTH;
1665 cx = infoPtr->nButtonWidth;
1668 cx = (btnPtr->iBitmap > 0) ?
1669 btnPtr->iBitmap : SEPARATOR_WIDTH;
1675 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1676 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1683 hOldFont = SelectObject (hdc, infoPtr->hFont);
1685 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1687 SelectObject (hdc, hOldFont);
1688 ReleaseDC (hwnd, hdc);
1690 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1691 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1696 cx = infoPtr->nButtonWidth;
1698 /* if size has been set manually then don't add on extra space
1699 * for the drop down arrow */
1700 if (!btnPtr->cx && hasDropDownArrows &&
1701 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1702 cx += DDARROW_WIDTH;
1704 if (btnPtr->fsState & TBSTATE_WRAP )
1707 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1709 if (infoPtr->rcBound.left > x)
1710 infoPtr->rcBound.left = x;
1711 if (infoPtr->rcBound.right < x + cx)
1712 infoPtr->rcBound.right = x + cx;
1713 if (infoPtr->rcBound.bottom < y + cy)
1714 infoPtr->rcBound.bottom = y + cy;
1716 /* Set the toolTip only for non-hidden, non-separator button */
1717 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1721 ZeroMemory (&ti, sizeof(ti));
1722 ti.cbSize = sizeof(ti);
1724 ti.uId = btnPtr->idCommand;
1725 ti.rect = btnPtr->rect;
1726 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1730 /* btnPtr->nRow is zero based. The space between the rows is */
1731 /* also considered as a row. */
1732 btnPtr->nRow = nRows + nSepRows;
1734 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1735 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1740 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1744 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1745 /* it is the actual width of the separator. This is used for */
1746 /* custom controls in toolbars. */
1747 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1748 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1749 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1753 /* nSepRows is used to calculate the extra height follwoing */
1757 x = infoPtr->nIndent;
1759 /* Increment row number unless this is the last button */
1760 /* and it has Wrap set. */
1761 if (i != infoPtr->nNumButtons-1)
1768 /* infoPtr->nRows is the number of rows on the toolbar */
1769 infoPtr->nRows = nRows + nSepRows + 1;
1771 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1776 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1778 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1779 TBUTTON_INFO *btnPtr;
1782 btnPtr = infoPtr->buttons;
1783 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1784 if (btnPtr->fsState & TBSTATE_HIDDEN)
1787 if (btnPtr->fsStyle & BTNS_SEP) {
1788 if (PtInRect (&btnPtr->rect, *lpPt)) {
1789 TRACE(" ON SEPARATOR %d!\n", i);
1794 if (PtInRect (&btnPtr->rect, *lpPt)) {
1795 TRACE(" ON BUTTON %d!\n", i);
1801 TRACE(" NOWHERE!\n");
1802 return TOOLBAR_NOWHERE;
1807 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1809 TBUTTON_INFO *btnPtr;
1812 if (CommandIsIndex) {
1813 TRACE("command is really index command=%d\n", idCommand);
1814 if (idCommand >= infoPtr->nNumButtons) return -1;
1817 btnPtr = infoPtr->buttons;
1818 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1819 if (btnPtr->idCommand == idCommand) {
1820 TRACE("command=%d index=%d\n", idCommand, i);
1824 TRACE("no index found for command=%d\n", idCommand);
1830 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1832 TBUTTON_INFO *btnPtr;
1835 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1838 /* check index button */
1839 btnPtr = &infoPtr->buttons[nIndex];
1840 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1841 if (btnPtr->fsState & TBSTATE_CHECKED)
1845 /* check previous buttons */
1846 nRunIndex = nIndex - 1;
1847 while (nRunIndex >= 0) {
1848 btnPtr = &infoPtr->buttons[nRunIndex];
1849 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1850 if (btnPtr->fsState & TBSTATE_CHECKED)
1858 /* check next buttons */
1859 nRunIndex = nIndex + 1;
1860 while (nRunIndex < infoPtr->nNumButtons) {
1861 btnPtr = &infoPtr->buttons[nRunIndex];
1862 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1863 if (btnPtr->fsState & TBSTATE_CHECKED)
1876 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1877 WPARAM wParam, LPARAM lParam)
1883 msg.wParam = wParam;
1884 msg.lParam = lParam;
1885 msg.time = GetMessageTime ();
1886 msg.pt.x = LOWORD(GetMessagePos ());
1887 msg.pt.y = HIWORD(GetMessagePos ());
1889 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1892 /* keeps available button list box sorted by button id */
1893 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1897 PCUSTOMBUTTON btnInfo;
1898 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1900 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1902 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1904 /* position 0 is always separator */
1905 for (i = 1; i < count; i++)
1907 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1908 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1910 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1911 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1915 /* id higher than all others add to end */
1916 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1917 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1920 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1924 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1926 if (nIndexFrom == nIndexTo)
1929 /* MSDN states that iItem is the index of the button, rather than the
1930 * command ID as used by every other NMTOOLBAR notification */
1931 nmtb.iItem = nIndexFrom;
1932 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1934 PCUSTOMBUTTON btnInfo;
1936 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1937 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1939 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1941 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1942 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1943 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1944 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1947 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1949 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1951 /* last item is always separator, so -2 instead of -1 */
1952 if (nIndexTo >= (count - 2))
1953 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1955 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1957 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1958 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1960 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1964 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1968 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1970 /* MSDN states that iItem is the index of the button, rather than the
1971 * command ID as used by every other NMTOOLBAR notification */
1972 nmtb.iItem = nIndexAvail;
1973 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1975 PCUSTOMBUTTON btnInfo;
1977 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1978 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1979 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1981 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1983 if (nIndexAvail != 0) /* index == 0 indicates separator */
1985 /* remove from 'available buttons' list */
1986 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1987 if (nIndexAvail == count-1)
1988 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1990 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1994 PCUSTOMBUTTON btnNew;
1996 /* duplicate 'separator' button */
1997 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1998 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2002 /* insert into 'toolbar button' list */
2003 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2004 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2006 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2008 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2012 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2014 PCUSTOMBUTTON btnInfo;
2015 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2017 TRACE("Remove: index %d\n", index);
2019 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2021 /* send TBN_QUERYDELETE notification */
2022 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2026 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2027 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2029 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2031 /* insert into 'available button' list */
2032 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2033 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2037 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2041 /* drag list notification function for toolbar buttons list box */
2042 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2044 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2045 switch (pDLI->uNotification)
2049 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2050 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2051 /* no dragging for last item (separator) */
2052 if (nCurrentItem >= (nCount - 1)) return FALSE;
2057 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2058 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2059 /* no dragging past last item (separator) */
2060 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2062 DrawInsert(hwnd, hwndList, nCurrentItem);
2063 /* FIXME: native uses "move button" cursor */
2064 return DL_COPYCURSOR;
2067 /* not over toolbar buttons list */
2068 if (nCurrentItem < 0)
2070 POINT ptWindow = pDLI->ptCursor;
2071 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2072 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2073 /* over available buttons list? */
2074 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2075 /* FIXME: native uses "move button" cursor */
2076 return DL_COPYCURSOR;
2078 /* clear drag arrow */
2079 DrawInsert(hwnd, hwndList, -1);
2080 return DL_STOPCURSOR;
2084 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2085 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2086 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2087 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2089 /* clear drag arrow */
2090 DrawInsert(hwnd, hwndList, -1);
2092 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2094 /* not over toolbar buttons list */
2097 POINT ptWindow = pDLI->ptCursor;
2098 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2099 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2100 /* over available buttons list? */
2101 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2102 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2107 /* Clear drag arrow */
2108 DrawInsert(hwnd, hwndList, -1);
2115 /* drag list notification function for available buttons list box */
2116 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2118 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2119 switch (pDLI->uNotification)
2125 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2126 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2127 /* no dragging past last item (separator) */
2128 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2130 DrawInsert(hwnd, hwndList, nCurrentItem);
2131 /* FIXME: native uses "move button" cursor */
2132 return DL_COPYCURSOR;
2135 /* not over toolbar buttons list */
2136 if (nCurrentItem < 0)
2138 POINT ptWindow = pDLI->ptCursor;
2139 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2140 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2141 /* over available buttons list? */
2142 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2143 /* FIXME: native uses "move button" cursor */
2144 return DL_COPYCURSOR;
2146 /* clear drag arrow */
2147 DrawInsert(hwnd, hwndList, -1);
2148 return DL_STOPCURSOR;
2152 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2153 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2154 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2155 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2157 /* clear drag arrow */
2158 DrawInsert(hwnd, hwndList, -1);
2160 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2164 /* Clear drag arrow */
2165 DrawInsert(hwnd, hwndList, -1);
2171 extern UINT uDragListMessage;
2173 /***********************************************************************
2174 * TOOLBAR_CustomizeDialogProc
2175 * This function implements the toolbar customization dialog.
2177 static INT_PTR CALLBACK
2178 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2180 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2181 PCUSTOMBUTTON btnInfo;
2183 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2188 custInfo = (PCUSTDLG_INFO)lParam;
2189 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2197 infoPtr = custInfo->tbInfo;
2199 /* send TBN_QUERYINSERT notification */
2200 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2202 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2205 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2206 memcpy(&nmtb.iItem, &hwnd, sizeof(hwnd));
2207 /* Send TBN_INITCUSTOMIZE notification */
2208 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2211 TRACE("TBNRF_HIDEHELP requested\n");
2212 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2215 /* add items to 'toolbar buttons' list and check if removable */
2216 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2218 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2219 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2220 btnInfo->btn.fsStyle = BTNS_SEP;
2221 btnInfo->bVirtual = FALSE;
2222 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2224 /* send TBN_QUERYDELETE notification */
2225 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2227 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2228 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2231 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2233 /* insert separator button into 'available buttons' list */
2234 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2235 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2236 btnInfo->btn.fsStyle = BTNS_SEP;
2237 btnInfo->bVirtual = FALSE;
2238 btnInfo->bRemovable = TRUE;
2239 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2240 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2241 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2243 /* insert all buttons into dsa */
2246 /* send TBN_GETBUTTONINFO notification */
2249 nmtb.pszText = Buffer;
2252 /* Clear previous button's text */
2253 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2255 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2258 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2259 nmtb.tbButton.fsStyle, i,
2260 nmtb.tbButton.idCommand,
2261 nmtb.tbButton.iString,
2262 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2265 /* insert button into the apropriate list */
2266 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2269 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2270 btnInfo->bVirtual = FALSE;
2271 btnInfo->bRemovable = TRUE;
2275 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2276 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2279 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2280 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2282 if (lstrlenW(nmtb.pszText))
2283 lstrcpyW(btnInfo->text, nmtb.pszText);
2284 else if (nmtb.tbButton.iString >= 0 &&
2285 nmtb.tbButton.iString < infoPtr->nNumStrings)
2287 lstrcpyW(btnInfo->text,
2288 infoPtr->strings[nmtb.tbButton.iString]);
2293 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2296 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2298 /* select first item in the 'available' list */
2299 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2301 /* append 'virtual' separator button to the 'toolbar buttons' list */
2302 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2303 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2304 btnInfo->btn.fsStyle = BTNS_SEP;
2305 btnInfo->bVirtual = TRUE;
2306 btnInfo->bRemovable = FALSE;
2307 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2308 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2309 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2311 /* select last item in the 'toolbar' list */
2312 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2313 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2315 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2316 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2318 /* set focus and disable buttons */
2319 PostMessageW (hwnd, WM_USER, 0, 0);
2324 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2325 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2326 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2327 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2331 EndDialog(hwnd, FALSE);
2335 switch (LOWORD(wParam))
2337 case IDC_TOOLBARBTN_LBOX:
2338 if (HIWORD(wParam) == LBN_SELCHANGE)
2340 PCUSTOMBUTTON btnInfo;
2345 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2346 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2348 /* send TBN_QUERYINSERT notification */
2350 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2352 /* get list box item */
2353 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2355 if (index == (count - 1))
2357 /* last item (virtual separator) */
2358 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2359 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2361 else if (index == (count - 2))
2363 /* second last item (last non-virtual item) */
2364 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2365 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2367 else if (index == 0)
2370 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2371 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2375 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2376 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2379 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2383 case IDC_MOVEUP_BTN:
2385 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2386 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2390 case IDC_MOVEDN_BTN: /* move down */
2392 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2393 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2397 case IDC_REMOVE_BTN: /* remove button */
2399 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2401 if (LB_ERR == index)
2404 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2408 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2411 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2414 case IDOK: /* Add button */
2419 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2420 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2422 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2427 EndDialog(hwnd, FALSE);
2437 /* delete items from 'toolbar buttons' listbox*/
2438 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2439 for (i = 0; i < count; i++)
2441 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2443 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2445 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2448 /* delete items from 'available buttons' listbox*/
2449 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2450 for (i = 0; i < count; i++)
2452 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2454 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2456 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2461 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2463 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2468 COLORREF oldText = 0;
2472 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2473 if (btnInfo == NULL)
2475 FIXME("btnInfo invalid!\n");
2479 /* set colors and select objects */
2480 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2481 if (btnInfo->bVirtual)
2482 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2484 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2485 hPen = CreatePen( PS_SOLID, 1,
2486 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2487 hOldPen = SelectObject (lpdis->hDC, hPen );
2488 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2490 /* fill background rectangle */
2491 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2492 lpdis->rcItem.right, lpdis->rcItem.bottom);
2494 /* calculate button and text rectangles */
2495 CopyRect (&rcButton, &lpdis->rcItem);
2496 InflateRect (&rcButton, -1, -1);
2497 CopyRect (&rcText, &rcButton);
2498 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2499 rcText.left = rcButton.right + 2;
2501 /* draw focus rectangle */
2502 if (lpdis->itemState & ODS_FOCUS)
2503 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2506 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2507 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2509 /* draw image and text */
2510 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2511 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2512 btnInfo->btn.iBitmap));
2513 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2514 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2516 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2517 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2519 /* delete objects and reset colors */
2520 SelectObject (lpdis->hDC, hOldBrush);
2521 SelectObject (lpdis->hDC, hOldPen);
2522 SetBkColor (lpdis->hDC, oldBk);
2523 SetTextColor (lpdis->hDC, oldText);
2524 DeleteObject( hPen );
2529 case WM_MEASUREITEM:
2530 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2532 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2534 lpmis->itemHeight = 15 + 8; /* default height */
2541 if (uDragListMessage && (uMsg == uDragListMessage))
2543 if (wParam == IDC_TOOLBARBTN_LBOX)
2545 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2546 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2547 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2550 else if (wParam == IDC_AVAILBTN_LBOX)
2552 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2553 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2554 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2563 /***********************************************************************
2564 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2568 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2570 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2571 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2572 INT nIndex = 0, nButtons, nCount;
2576 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2580 if (lpAddBmp->hInst == HINST_COMMCTRL)
2582 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2584 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2586 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2591 TRACE ("adding %d internal bitmaps!\n", nButtons);
2593 /* Windows resize all the buttons to the size of a newly added standard image */
2594 if (lpAddBmp->nID & 1)
2597 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2598 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2600 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2601 MAKELPARAM((WORD)24, (WORD)24));
2602 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2603 MAKELPARAM((WORD)31, (WORD)30));
2608 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2609 MAKELPARAM((WORD)16, (WORD)16));
2610 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2611 MAKELPARAM((WORD)22, (WORD)22));
2614 TOOLBAR_CalcToolbar (hwnd);
2618 nButtons = (INT)wParam;
2622 TRACE ("adding %d bitmaps!\n", nButtons);
2625 if (!infoPtr->cimlDef) {
2626 /* create new default image list */
2627 TRACE ("creating default image list!\n");
2629 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2630 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2631 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2632 infoPtr->himlInt = himlDef;
2635 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2639 WARN("No default image list available\n");
2643 nCount = ImageList_GetImageCount(himlDef);
2645 /* Add bitmaps to the default image list */
2646 if (lpAddBmp->hInst == NULL)
2649 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2650 HDC hdcImage, hdcBitmap;
2652 /* copy the bitmap before adding it so that the user's bitmap
2653 * doesn't get modified.
2655 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2657 hdcImage = CreateCompatibleDC(0);
2658 hdcBitmap = CreateCompatibleDC(0);
2660 /* create new bitmap */
2661 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2662 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2663 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2665 /* Copy the user's image */
2666 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2667 hdcBitmap, 0, 0, SRCCOPY);
2669 SelectObject (hdcImage, hOldBitmapLoad);
2670 SelectObject (hdcBitmap, hOldBitmapBitmap);
2671 DeleteDC (hdcImage);
2672 DeleteDC (hdcBitmap);
2674 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2675 DeleteObject (hbmLoad);
2677 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2679 /* Add system bitmaps */
2680 switch (lpAddBmp->nID)
2682 case IDB_STD_SMALL_COLOR:
2683 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2684 MAKEINTRESOURCEW(IDB_STD_SMALL));
2685 nIndex = ImageList_AddMasked (himlDef,
2686 hbmLoad, comctl32_color.clrBtnFace);
2687 DeleteObject (hbmLoad);
2690 case IDB_STD_LARGE_COLOR:
2691 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2692 MAKEINTRESOURCEW(IDB_STD_LARGE));
2693 nIndex = ImageList_AddMasked (himlDef,
2694 hbmLoad, comctl32_color.clrBtnFace);
2695 DeleteObject (hbmLoad);
2698 case IDB_VIEW_SMALL_COLOR:
2699 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2700 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2701 nIndex = ImageList_AddMasked (himlDef,
2702 hbmLoad, comctl32_color.clrBtnFace);
2703 DeleteObject (hbmLoad);
2706 case IDB_VIEW_LARGE_COLOR:
2707 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2708 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2709 nIndex = ImageList_AddMasked (himlDef,
2710 hbmLoad, comctl32_color.clrBtnFace);
2711 DeleteObject (hbmLoad);
2714 case IDB_HIST_SMALL_COLOR:
2715 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2716 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2717 nIndex = ImageList_AddMasked (himlDef,
2718 hbmLoad, comctl32_color.clrBtnFace);
2719 DeleteObject (hbmLoad);
2722 case IDB_HIST_LARGE_COLOR:
2723 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2724 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2725 nIndex = ImageList_AddMasked (himlDef,
2726 hbmLoad, comctl32_color.clrBtnFace);
2727 DeleteObject (hbmLoad);
2731 nIndex = ImageList_GetImageCount (himlDef);
2732 ERR ("invalid imagelist!\n");
2738 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2739 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2740 DeleteObject (hbmLoad);
2743 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2745 if (infoPtr->nNumBitmapInfos == 0)
2747 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2751 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2752 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2753 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos * sizeof(TBITMAP_INFO));
2756 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2757 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2758 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2760 infoPtr->nNumBitmapInfos++;
2761 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2765 INT imagecount = ImageList_GetImageCount(himlDef);
2767 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2769 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2770 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2771 infoPtr->nNumBitmaps+nButtons,imagecount);
2773 infoPtr->nNumBitmaps = imagecount;
2776 infoPtr->nNumBitmaps += nButtons;
2779 InvalidateRect(hwnd, NULL, TRUE);
2786 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2789 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2790 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2792 TRACE("adding %d buttons!\n", wParam);
2794 nAddButtons = (UINT)wParam;
2795 nOldButtons = infoPtr->nNumButtons;
2796 nNewButtons = nOldButtons + nAddButtons;
2798 if (infoPtr->nNumButtons == 0) {
2800 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2803 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2805 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2806 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2807 nOldButtons * sizeof(TBUTTON_INFO));
2811 infoPtr->nNumButtons = nNewButtons;
2813 /* insert new button data */
2814 for (nCount = 0; nCount < nAddButtons; nCount++) {
2815 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2816 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2817 btnPtr->idCommand = lpTbb[nCount].idCommand;
2818 btnPtr->fsState = lpTbb[nCount].fsState;
2819 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2820 btnPtr->dwData = lpTbb[nCount].dwData;
2821 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2822 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2824 btnPtr->iString = lpTbb[nCount].iString;
2825 btnPtr->bHot = FALSE;
2827 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2830 ZeroMemory (&ti, sizeof(ti));
2831 ti.cbSize = sizeof(ti);
2833 ti.uId = btnPtr->idCommand;
2835 ti.lpszText = LPSTR_TEXTCALLBACKW;
2837 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2842 TOOLBAR_CalcToolbar (hwnd);
2843 TOOLBAR_AutoSize (hwnd);
2845 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2847 InvalidateRect(hwnd, NULL, TRUE);
2854 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2856 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2857 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2858 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2860 TRACE("adding %d buttons!\n", wParam);
2862 nAddButtons = (UINT)wParam;
2863 nOldButtons = infoPtr->nNumButtons;
2864 nNewButtons = nOldButtons + nAddButtons;
2866 if (infoPtr->nNumButtons == 0) {
2868 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2871 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2873 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2874 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2875 nOldButtons * sizeof(TBUTTON_INFO));
2879 infoPtr->nNumButtons = nNewButtons;
2881 /* insert new button data */
2882 for (nCount = 0; nCount < nAddButtons; nCount++) {
2883 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2884 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2885 btnPtr->idCommand = lpTbb[nCount].idCommand;
2886 btnPtr->fsState = lpTbb[nCount].fsState;
2887 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2888 btnPtr->dwData = lpTbb[nCount].dwData;
2889 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2890 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2892 btnPtr->iString = lpTbb[nCount].iString;
2893 btnPtr->bHot = FALSE;
2895 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2898 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2899 ti.cbSize = sizeof (TTTOOLINFOW);
2901 ti.uId = btnPtr->idCommand;
2903 ti.lpszText = LPSTR_TEXTCALLBACKW;
2906 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2911 TOOLBAR_CalcToolbar (hwnd);
2912 TOOLBAR_AutoSize (hwnd);
2914 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2916 InvalidateRect(hwnd, NULL, TRUE);
2923 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2928 if ((wParam) && (HIWORD(lParam) == 0)) {
2931 TRACE("adding string from resource!\n");
2933 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2935 TRACE("len=%d \"%s\"\n", len, szString);
2936 nIndex = infoPtr->nNumStrings;
2937 if (infoPtr->nNumStrings == 0) {
2939 Alloc (sizeof(LPWSTR));
2942 LPWSTR *oldStrings = infoPtr->strings;
2944 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2945 memcpy (&infoPtr->strings[0], &oldStrings[0],
2946 sizeof(LPWSTR) * infoPtr->nNumStrings);
2950 /*Alloc zeros out the allocated memory*/
2951 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2952 infoPtr->nNumStrings++;
2955 LPSTR p = (LPSTR)lParam;
2960 TRACE("adding string(s) from array!\n");
2962 nIndex = infoPtr->nNumStrings;
2965 TRACE("len=%d \"%s\"\n", len, p);
2967 if (infoPtr->nNumStrings == 0) {
2969 Alloc (sizeof(LPWSTR));
2972 LPWSTR *oldStrings = infoPtr->strings;
2974 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2975 memcpy (&infoPtr->strings[0], &oldStrings[0],
2976 sizeof(LPWSTR) * infoPtr->nNumStrings);
2980 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2981 infoPtr->nNumStrings++;
2992 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2994 #define MAX_RESOURCE_STRING_LENGTH 512
2995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2998 if ((wParam) && (HIWORD(lParam) == 0)) {
2999 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3001 TRACE("adding string from resource!\n");
3003 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
3004 szString, MAX_RESOURCE_STRING_LENGTH);
3006 TRACE("len=%d %s\n", len, debugstr_w(szString));
3007 TRACE("First char: 0x%x\n", *szString);
3008 if (szString[0] == L'|')
3010 PWSTR p = szString + 1;
3012 nIndex = infoPtr->nNumStrings;
3013 while (*p != L'|' && *p != L'\0') {
3016 if (infoPtr->nNumStrings == 0) {
3017 infoPtr->strings = Alloc (sizeof(LPWSTR));
3021 LPWSTR *oldStrings = infoPtr->strings;
3022 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3023 memcpy(&infoPtr->strings[0], &oldStrings[0],
3024 sizeof(LPWSTR) * infoPtr->nNumStrings);
3028 np=strchrW (p, '|');
3036 TRACE("len=%d %s\n", len, debugstr_w(p));
3037 infoPtr->strings[infoPtr->nNumStrings] =
3038 Alloc (sizeof(WCHAR)*(len+1));
3039 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3040 infoPtr->nNumStrings++;
3047 nIndex = infoPtr->nNumStrings;
3048 if (infoPtr->nNumStrings == 0) {
3050 Alloc (sizeof(LPWSTR));
3053 LPWSTR *oldStrings = infoPtr->strings;
3055 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3056 memcpy (&infoPtr->strings[0], &oldStrings[0],
3057 sizeof(LPWSTR) * infoPtr->nNumStrings);
3061 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3062 infoPtr->nNumStrings++;
3066 LPWSTR p = (LPWSTR)lParam;
3071 TRACE("adding string(s) from array!\n");
3072 nIndex = infoPtr->nNumStrings;
3076 TRACE("len=%d %s\n", len, debugstr_w(p));
3077 if (infoPtr->nNumStrings == 0) {
3079 Alloc (sizeof(LPWSTR));
3082 LPWSTR *oldStrings = infoPtr->strings;
3084 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3085 memcpy (&infoPtr->strings[0], &oldStrings[0],
3086 sizeof(LPWSTR) * infoPtr->nNumStrings);
3090 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3091 infoPtr->nNumStrings++;
3102 TOOLBAR_AutoSize (HWND hwnd)
3104 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3110 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3112 parent = GetParent (hwnd);
3114 if (!parent || !infoPtr->bDoRedraw)
3117 GetClientRect(parent, &parent_rect);
3119 x = parent_rect.left;
3120 y = parent_rect.top;
3122 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3124 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3125 cx = parent_rect.right - parent_rect.left;
3127 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3129 TOOLBAR_CalcToolbar(hwnd);
3130 InvalidateRect( hwnd, NULL, TRUE );
3133 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3136 UINT uPosFlags = SWP_NOZORDER;
3138 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3140 GetWindowRect(hwnd, &window_rect);
3141 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3142 y = window_rect.top;
3144 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3146 GetWindowRect(hwnd, &window_rect);
3147 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3150 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3151 uPosFlags |= SWP_NOMOVE;
3153 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3154 cy += GetSystemMetrics(SM_CYEDGE);
3156 if (infoPtr->dwStyle & WS_BORDER)
3158 x = y = 1; /* FIXME: this looks wrong */
3159 cy += GetSystemMetrics(SM_CYEDGE);
3160 cx += GetSystemMetrics(SM_CXEDGE);
3163 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3171 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3175 return infoPtr->nNumButtons;
3180 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3184 infoPtr->dwStructSize = (DWORD)wParam;
3191 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3194 TBUTTON_INFO *btnPtr;
3197 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3199 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3203 btnPtr = &infoPtr->buttons[nIndex];
3204 btnPtr->iBitmap = LOWORD(lParam);
3206 /* we HAVE to erase the background, the new bitmap could be */
3208 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3215 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3218 TBUTTON_INFO *btnPtr;
3221 BOOL bChecked = FALSE;
3223 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3225 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3230 btnPtr = &infoPtr->buttons[nIndex];
3232 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3234 if (LOWORD(lParam) == FALSE)
3235 btnPtr->fsState &= ~TBSTATE_CHECKED;
3237 if (btnPtr->fsStyle & BTNS_GROUP) {
3239 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3240 if (nOldIndex == nIndex)
3242 if (nOldIndex != -1)
3243 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3245 btnPtr->fsState |= TBSTATE_CHECKED;
3248 if( bChecked != LOWORD(lParam) )
3250 if (nOldIndex != -1)
3251 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3252 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3255 /* FIXME: Send a WM_NOTIFY?? */
3262 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3266 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3271 TOOLBAR_Customize (HWND hwnd)
3273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3274 CUSTDLG_INFO custInfo;
3280 custInfo.tbInfo = infoPtr;
3281 custInfo.tbHwnd = hwnd;
3283 /* send TBN_BEGINADJUST notification */
3284 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3286 if (!(hRes = FindResourceW (COMCTL32_hModule,
3287 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3288 (LPWSTR)RT_DIALOG)))
3291 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3294 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3295 (LPDLGTEMPLATEW)template,
3297 TOOLBAR_CustomizeDialogProc,
3300 /* send TBN_ENDADJUST notification */
3301 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3308 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3310 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3311 INT nIndex = (INT)wParam;
3313 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3315 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3318 memset(&nmtb, 0, sizeof(nmtb));
3319 nmtb.iItem = btnPtr->idCommand;
3320 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3321 nmtb.tbButton.idCommand = btnPtr->idCommand;
3322 nmtb.tbButton.fsState = btnPtr->fsState;
3323 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3324 nmtb.tbButton.dwData = btnPtr->dwData;
3325 nmtb.tbButton.iString = btnPtr->iString;
3326 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3328 if ((infoPtr->hwndToolTip) &&
3329 !(btnPtr->fsStyle & BTNS_SEP)) {
3332 ZeroMemory (&ti, sizeof(ti));
3333 ti.cbSize = sizeof(ti);
3335 ti.uId = infoPtr->buttons[nIndex].idCommand;
3337 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3340 if (infoPtr->nNumButtons == 1) {
3341 TRACE(" simple delete!\n");
3342 Free (infoPtr->buttons);
3343 infoPtr->buttons = NULL;
3344 infoPtr->nNumButtons = 0;
3347 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3348 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3350 infoPtr->nNumButtons--;
3351 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3353 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3354 nIndex * sizeof(TBUTTON_INFO));
3357 if (nIndex < infoPtr->nNumButtons) {
3358 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3359 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3365 TOOLBAR_CalcToolbar (hwnd);
3367 InvalidateRect (hwnd, NULL, TRUE);
3374 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3376 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3377 TBUTTON_INFO *btnPtr;
3381 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3383 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3388 btnPtr = &infoPtr->buttons[nIndex];
3390 bState = btnPtr->fsState & TBSTATE_ENABLED;
3392 /* update the toolbar button state */
3393 if(LOWORD(lParam) == FALSE) {
3394 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3396 btnPtr->fsState |= TBSTATE_ENABLED;
3399 /* redraw the button only if the state of the button changed */
3400 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3401 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3407 static inline LRESULT
3408 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3412 return infoPtr->bAnchor;
3417 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3422 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3426 return infoPtr->buttons[nIndex].iBitmap;
3430 static inline LRESULT
3431 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3433 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3438 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3441 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3442 INT nIndex = (INT)wParam;
3443 TBUTTON_INFO *btnPtr;
3448 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3451 btnPtr = &infoPtr->buttons[nIndex];
3452 lpTbb->iBitmap = btnPtr->iBitmap;
3453 lpTbb->idCommand = btnPtr->idCommand;
3454 lpTbb->fsState = btnPtr->fsState;
3455 lpTbb->fsStyle = btnPtr->fsStyle;
3456 lpTbb->bReserved[0] = 0;
3457 lpTbb->bReserved[1] = 0;
3458 lpTbb->dwData = btnPtr->dwData;
3459 lpTbb->iString = btnPtr->iString;
3466 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3469 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3470 TBUTTON_INFO *btnPtr;
3473 if (lpTbInfo == NULL)
3475 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3478 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3479 lpTbInfo->dwMask & 0x80000000);
3483 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3485 if (lpTbInfo->dwMask & TBIF_COMMAND)
3486 lpTbInfo->idCommand = btnPtr->idCommand;
3487 if (lpTbInfo->dwMask & TBIF_IMAGE)
3488 lpTbInfo->iImage = btnPtr->iBitmap;
3489 if (lpTbInfo->dwMask & TBIF_LPARAM)
3490 lpTbInfo->lParam = btnPtr->dwData;
3491 if (lpTbInfo->dwMask & TBIF_SIZE)
3492 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3493 if (lpTbInfo->dwMask & TBIF_STATE)
3494 lpTbInfo->fsState = btnPtr->fsState;
3495 if (lpTbInfo->dwMask & TBIF_STYLE)
3496 lpTbInfo->fsStyle = btnPtr->fsStyle;
3497 if (lpTbInfo->dwMask & TBIF_TEXT) {
3498 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3499 can't use TOOLBAR_GetText here */
3501 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3502 lpText = (LPWSTR)btnPtr->iString;
3503 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3505 lpTbInfo->pszText[0] = '\0';
3512 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3515 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3516 TBUTTON_INFO *btnPtr;
3519 if (lpTbInfo == NULL)
3521 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3524 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3525 lpTbInfo->dwMask & 0x80000000);
3529 btnPtr = &infoPtr->buttons[nIndex];
3534 if (lpTbInfo->dwMask & TBIF_COMMAND)
3535 lpTbInfo->idCommand = btnPtr->idCommand;
3536 if (lpTbInfo->dwMask & TBIF_IMAGE)
3537 lpTbInfo->iImage = btnPtr->iBitmap;
3538 if (lpTbInfo->dwMask & TBIF_LPARAM)
3539 lpTbInfo->lParam = btnPtr->dwData;
3540 if (lpTbInfo->dwMask & TBIF_SIZE)
3541 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3542 if (lpTbInfo->dwMask & TBIF_STATE)
3543 lpTbInfo->fsState = btnPtr->fsState;
3544 if (lpTbInfo->dwMask & TBIF_STYLE)
3545 lpTbInfo->fsStyle = btnPtr->fsStyle;
3546 if (lpTbInfo->dwMask & TBIF_TEXT) {
3547 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3548 can't use TOOLBAR_GetText here */
3550 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3551 lpText = (LPWSTR)btnPtr->iString;
3552 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3554 lpTbInfo->pszText[0] = '\0';
3562 TOOLBAR_GetButtonSize (HWND hwnd)
3564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3566 if (infoPtr->nNumButtons > 0)
3567 return MAKELONG((WORD)infoPtr->nButtonWidth,
3568 (WORD)infoPtr->nButtonHeight);
3570 return MAKELONG(23,22);
3575 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3584 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3588 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3590 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3591 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3596 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3603 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3607 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3611 ret = strlenW (lpText);
3614 strcpyW ((LPWSTR)lParam, lpText);
3622 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3624 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3625 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3626 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3630 inline static LRESULT
3631 TOOLBAR_GetExtendedStyle (HWND hwnd)
3633 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3637 return infoPtr->dwExStyle;
3642 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3644 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3645 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3646 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3651 TOOLBAR_GetHotItem (HWND hwnd)
3653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3655 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3658 if (infoPtr->nHotItem < 0)
3661 return (LRESULT)infoPtr->nHotItem;
3666 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3668 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3669 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3670 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3675 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3677 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3678 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3680 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3682 *lptbim = infoPtr->tbim;
3689 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3691 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3693 TRACE("hwnd = %p\n", hwnd);
3695 return (LRESULT)infoPtr->clrInsertMark;
3700 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3703 TBUTTON_INFO *btnPtr;
3707 nIndex = (INT)wParam;
3708 btnPtr = &infoPtr->buttons[nIndex];
3709 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3711 lpRect = (LPRECT)lParam;
3714 if (btnPtr->fsState & TBSTATE_HIDDEN)
3717 lpRect->left = btnPtr->rect.left;
3718 lpRect->right = btnPtr->rect.right;
3719 lpRect->bottom = btnPtr->rect.bottom;
3720 lpRect->top = btnPtr->rect.top;
3727 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3730 LPSIZE lpSize = (LPSIZE)lParam;
3735 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3736 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3738 TRACE("maximum size %ld x %ld\n",
3739 infoPtr->rcBound.right - infoPtr->rcBound.left,
3740 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3746 /* << TOOLBAR_GetObject >> */
3750 TOOLBAR_GetPadding (HWND hwnd)
3752 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3755 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3756 return (LRESULT) oldPad;
3761 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3764 TBUTTON_INFO *btnPtr;
3768 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3769 btnPtr = &infoPtr->buttons[nIndex];
3770 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3772 lpRect = (LPRECT)lParam;
3776 lpRect->left = btnPtr->rect.left;
3777 lpRect->right = btnPtr->rect.right;
3778 lpRect->bottom = btnPtr->rect.bottom;
3779 lpRect->top = btnPtr->rect.top;
3786 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3790 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3791 return infoPtr->nRows;
3798 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3803 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3807 return infoPtr->buttons[nIndex].fsState;
3812 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3814 return GetWindowLongW(hwnd, GWL_STYLE);
3819 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3823 return infoPtr->nMaxTextRows;
3828 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3832 return (LRESULT)infoPtr->hwndToolTip;
3837 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3841 TRACE("%s hwnd=%p\n",
3842 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3844 return infoPtr->bUnicode;
3848 inline static LRESULT
3849 TOOLBAR_GetVersion (HWND hwnd)
3851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3852 return infoPtr->iVersion;
3857 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3860 TBUTTON_INFO *btnPtr;
3865 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3869 btnPtr = &infoPtr->buttons[nIndex];
3870 if (LOWORD(lParam) == FALSE)
3871 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3873 btnPtr->fsState |= TBSTATE_HIDDEN;
3875 TOOLBAR_CalcToolbar (hwnd);
3877 InvalidateRect (hwnd, NULL, TRUE);
3883 inline static LRESULT
3884 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3886 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3891 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3894 TBUTTON_INFO *btnPtr;
3898 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3902 btnPtr = &infoPtr->buttons[nIndex];
3903 oldState = btnPtr->fsState;
3904 if (LOWORD(lParam) == FALSE)
3905 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3907 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3909 if(oldState != btnPtr->fsState)
3910 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3917 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3919 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3920 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3921 INT nIndex = (INT)wParam;
3922 TBUTTON_INFO *oldButtons;
3927 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3930 /* EPP: this seems to be an undocumented call (from my IE4)
3931 * I assume in that case that:
3932 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3933 * - index of insertion is at the end of existing buttons
3934 * I only see this happen with nIndex == -1, but it could have a special
3935 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3937 nIndex = infoPtr->nNumButtons;
3939 } else if (nIndex < 0)
3942 /* If the string passed is not an index, assume address of string
3943 and do our own AddString */
3944 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3948 TRACE("string %s passed instead of index, adding string\n",
3949 debugstr_a((LPSTR)lpTbb->iString));
3950 len = strlen((LPSTR)lpTbb->iString) + 2;
3952 strcpy(ptr, (LPSTR)lpTbb->iString);
3953 ptr[len - 1] = 0; /* ended by two '\0' */
3954 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3958 TRACE("inserting button index=%d\n", nIndex);
3959 if (nIndex > infoPtr->nNumButtons) {
3960 nIndex = infoPtr->nNumButtons;
3961 TRACE("adjust index=%d\n", nIndex);
3964 oldButtons = infoPtr->buttons;
3965 infoPtr->nNumButtons++;
3966 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3967 /* pre insert copy */
3969 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3970 nIndex * sizeof(TBUTTON_INFO));
3973 /* insert new button */
3974 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3975 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3976 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3977 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3978 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3979 /* if passed string and not index, then add string */
3980 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3981 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3984 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3986 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3989 ZeroMemory (&ti, sizeof(ti));
3990 ti.cbSize = sizeof (ti);
3992 ti.uId = lpTbb->idCommand;
3994 ti.lpszText = LPSTR_TEXTCALLBACKW;
3996 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4000 /* post insert copy */
4001 if (nIndex < infoPtr->nNumButtons - 1) {
4002 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4003 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4008 TOOLBAR_CalcToolbar (hwnd);
4009 TOOLBAR_AutoSize (hwnd);
4011 InvalidateRect (hwnd, NULL, TRUE);
4018 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4021 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4022 INT nIndex = (INT)wParam;
4023 TBUTTON_INFO *oldButtons;
4028 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4031 /* EPP: this seems to be an undocumented call (from my IE4)
4032 * I assume in that case that:
4033 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4034 * - index of insertion is at the end of existing buttons
4035 * I only see this happen with nIndex == -1, but it could have a special
4036 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4038 nIndex = infoPtr->nNumButtons;
4040 } else if (nIndex < 0)
4043 /* If the string passed is not an index, assume address of string
4044 and do our own AddString */
4045 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4049 TRACE("string %s passed instead of index, adding string\n",
4050 debugstr_w((LPWSTR)lpTbb->iString));
4051 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4052 ptr = Alloc(len*sizeof(WCHAR));
4053 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4054 ptr[len - 1] = 0; /* ended by two '\0' */
4055 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4059 TRACE("inserting button index=%d\n", nIndex);
4060 if (nIndex > infoPtr->nNumButtons) {
4061 nIndex = infoPtr->nNumButtons;
4062 TRACE("adjust index=%d\n", nIndex);
4065 oldButtons = infoPtr->buttons;
4066 infoPtr->nNumButtons++;
4067 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4068 /* pre insert copy */
4070 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4071 nIndex * sizeof(TBUTTON_INFO));
4074 /* insert new button */
4075 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4076 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4077 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4078 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4079 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4080 /* if passed string and not index, then add string */
4081 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4082 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4085 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4087 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4090 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4091 ti.cbSize = sizeof (TTTOOLINFOW);
4093 ti.uId = lpTbb->idCommand;
4095 ti.lpszText = LPSTR_TEXTCALLBACKW;
4097 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4101 /* post insert copy */
4102 if (nIndex < infoPtr->nNumButtons - 1) {
4103 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4104 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4109 TOOLBAR_CalcToolbar (hwnd);
4110 TOOLBAR_AutoSize (hwnd);
4112 InvalidateRect (hwnd, NULL, TRUE);
4118 /* << TOOLBAR_InsertMarkHitTest >> */
4122 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4127 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4131 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4136 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4141 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4145 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4150 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4155 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4159 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4164 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4169 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4173 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4178 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4183 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4187 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4192 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4194 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4197 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4201 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4206 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4209 tbab.hInst = (HINSTANCE)lParam;
4210 tbab.nID = (UINT_PTR)wParam;
4212 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4214 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4219 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4222 WCHAR wAccel = (WCHAR)wParam;
4223 UINT* pIDButton = (UINT*)lParam;
4224 WCHAR wszAccel[] = {'&',wAccel,0};
4227 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4228 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4230 for (i = 0; i < infoPtr->nNumButtons; i++)
4232 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4233 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4234 !(btnPtr->fsState & TBSTATE_HIDDEN))
4236 int iLen = strlenW(wszAccel);
4237 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4244 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4249 if (!strncmpiW(lpszStr, wszAccel, iLen))
4251 *pIDButton = btnPtr->idCommand;
4263 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4268 TBUTTON_INFO *btnPtr;
4270 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4272 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4276 btnPtr = &infoPtr->buttons[nIndex];
4277 oldState = btnPtr->fsState;
4280 btnPtr->fsState |= TBSTATE_MARKED;
4282 btnPtr->fsState &= ~TBSTATE_MARKED;
4284 if(oldState != btnPtr->fsState)
4285 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4291 /* fixes up an index of a button affected by a move */
4292 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4296 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4298 else if (*pIndex == nIndex)
4299 *pIndex = nMoveIndex;
4303 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4305 else if (*pIndex == nIndex)
4306 *pIndex = nMoveIndex;
4312 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4317 INT nMoveIndex = (INT)lParam;
4318 TBUTTON_INFO button;
4320 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4322 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4323 if ((nIndex == -1) || (nMoveIndex < 0))
4326 if (nMoveIndex > infoPtr->nNumButtons - 1)
4327 nMoveIndex = infoPtr->nNumButtons - 1;
4329 button = infoPtr->buttons[nIndex];
4331 /* move button right */
4332 if (nIndex < nMoveIndex)
4334 nCount = nMoveIndex - nIndex;
4335 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4336 infoPtr->buttons[nMoveIndex] = button;
4338 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4339 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4340 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4341 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4343 else if (nIndex > nMoveIndex) /* move button left */
4345 nCount = nIndex - nMoveIndex;
4346 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4347 infoPtr->buttons[nMoveIndex] = button;
4349 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4350 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4351 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4352 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4355 TOOLBAR_CalcToolbar(hwnd);
4356 TOOLBAR_AutoSize(hwnd);
4357 InvalidateRect(hwnd, NULL, TRUE);
4364 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4366 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4367 TBUTTON_INFO *btnPtr;
4371 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4375 btnPtr = &infoPtr->buttons[nIndex];
4376 oldState = btnPtr->fsState;
4377 if (LOWORD(lParam) == FALSE)
4378 btnPtr->fsState &= ~TBSTATE_PRESSED;
4380 btnPtr->fsState |= TBSTATE_PRESSED;
4382 if(oldState != btnPtr->fsState)
4383 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4388 /* FIXME: there might still be some confusion her between number of buttons
4389 * and number of bitmaps */
4391 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4393 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4394 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4396 HBITMAP hbmLoad = NULL;
4397 int i = 0, nOldButtons = 0, pos = 0;
4398 int nOldBitmaps, nNewBitmaps = 0;
4399 HIMAGELIST himlDef = 0;
4401 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4402 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4403 lpReplace->nButtons);
4405 if (lpReplace->hInstOld == HINST_COMMCTRL)
4407 FIXME("changing standard bitmaps not implemented\n");
4410 else if (lpReplace->hInstOld != 0)
4411 FIXME("resources not in the current module not implemented\n");
4413 if (lpReplace->hInstNew)
4415 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4420 hBitmap = (HBITMAP) lpReplace->nIDNew;
4423 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4424 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4425 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4426 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4427 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4429 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4430 nOldButtons = tbi->nButtons;
4431 tbi->nButtons = lpReplace->nButtons;
4432 tbi->hInst = lpReplace->hInstNew;
4433 tbi->nID = lpReplace->nIDNew;
4434 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4437 pos += tbi->nButtons;
4440 if (nOldButtons == 0)
4442 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4444 DeleteObject (hbmLoad);
4448 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4449 nOldBitmaps = ImageList_GetImageCount(himlDef);
4451 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4453 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4454 ImageList_Remove(himlDef, i);
4459 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4460 HDC hdcImage, hdcBitmap;
4462 /* copy the bitmap before adding it so that the user's bitmap
4463 * doesn't get modified.
4465 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4467 hdcImage = CreateCompatibleDC(0);
4468 hdcBitmap = CreateCompatibleDC(0);
4470 /* create new bitmap */
4471 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4472 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4473 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4475 /* Copy the user's image */
4476 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4477 hdcBitmap, 0, 0, SRCCOPY);
4479 SelectObject (hdcImage, hOldBitmapLoad);
4480 SelectObject (hdcBitmap, hOldBitmapBitmap);
4481 DeleteDC (hdcImage);
4482 DeleteDC (hdcBitmap);
4484 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4485 nNewBitmaps = ImageList_GetImageCount(himlDef);
4486 DeleteObject (hbmLoad);
4489 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4491 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4492 pos, nOldBitmaps, nNewBitmaps);
4494 InvalidateRect(hwnd, NULL, TRUE);
4497 DeleteObject (hbmLoad);
4502 /* helper for TOOLBAR_SaveRestoreW */
4504 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4506 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4507 debugstr_w(lpSave->pszValueName));
4513 /* helper for TOOLBAR_Restore */
4515 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4520 ZeroMemory(&ti, sizeof(ti));
4521 ti.cbSize = sizeof(ti);
4522 ti.hwnd = infoPtr->hwndSelf;
4524 for (i = 0; i < infoPtr->nNumButtons; i++)
4526 if ((infoPtr->hwndToolTip) &&
4527 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4529 ti.uId = infoPtr->buttons[i].idCommand;
4530 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4534 Free(infoPtr->buttons);
4535 infoPtr->buttons = NULL;
4536 infoPtr->nNumButtons = 0;
4540 /* helper for TOOLBAR_SaveRestoreW */
4542 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4551 /* restore toolbar information */
4552 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4553 debugstr_w(lpSave->pszValueName));
4555 memset(&nmtbr, 0, sizeof(nmtbr));
4557 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4558 KEY_QUERY_VALUE, &hkey);
4560 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4562 if (!res && dwType != REG_BINARY)
4563 res = ERROR_FILE_NOT_FOUND;
4566 nmtbr.pData = Alloc(dwSize);
4567 nmtbr.cbData = (UINT)dwSize;
4568 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4571 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4572 (LPBYTE)nmtbr.pData, &dwSize);
4575 nmtbr.pCurrent = nmtbr.pData;
4577 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4578 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4580 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4584 /* remove all existing buttons as this function is designed to
4585 * restore the toolbar to a previously saved state */
4586 TOOLBAR_DeleteAllButtons(infoPtr);
4588 for (i = 0; i < nmtbr.cButtons; i++)
4591 nmtbr.tbButton.iBitmap = -1;
4592 nmtbr.tbButton.fsState = 0;
4593 nmtbr.tbButton.fsStyle = 0;
4594 nmtbr.tbButton.idCommand = 0;
4595 if (*nmtbr.pCurrent == (DWORD)-1)
4598 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4599 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4601 else if (*nmtbr.pCurrent == (DWORD)-2)
4603 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4605 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4609 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4611 /* can't contain real string as we don't know whether
4612 * the client put an ANSI or Unicode string in there */
4613 if (HIWORD(nmtbr.tbButton.iString))
4614 nmtbr.tbButton.iString = 0;
4616 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4617 (LPARAM)&nmtbr.tbButton);
4620 /* do legacy notifications */
4621 if (infoPtr->iVersion < 5)
4623 /* FIXME: send TBN_BEGINADJUST */
4624 FIXME("send TBN_GETBUTTONINFO for each button\n");
4625 /* FIXME: send TBN_ENDADJUST */
4628 /* remove all uninitialised buttons
4629 * note: loop backwards to avoid having to fixup i on a
4631 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4632 if (infoPtr->buttons[i].iBitmap == -1)
4633 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4635 /* only indicate success if at least one button survived */
4636 if (infoPtr->nNumButtons > 0) ret = TRUE;
4647 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4651 if (lpSave == NULL) return 0;
4654 return TOOLBAR_Save(infoPtr, lpSave);
4656 return TOOLBAR_Restore(infoPtr, lpSave);
4661 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4663 LPWSTR pszValueName = 0, pszSubKey = 0;
4664 TBSAVEPARAMSW SaveW;
4668 if (lpSave == NULL) return 0;
4670 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4671 pszSubKey = Alloc(len * sizeof(WCHAR));
4672 if (pszSubKey) goto exit;
4673 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4675 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4676 pszValueName = Alloc(len * sizeof(WCHAR));
4677 if (!pszValueName) goto exit;
4678 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4680 SaveW.pszValueName = pszValueName;
4681 SaveW.pszSubKey = pszSubKey;
4682 SaveW.hkr = lpSave->hkr;
4683 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4686 Free (pszValueName);
4694 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4696 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4697 BOOL bOldAnchor = infoPtr->bAnchor;
4699 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4701 infoPtr->bAnchor = (BOOL)wParam;
4703 /* Native does not remove the hot effect from an already hot button */
4705 return (LRESULT)bOldAnchor;
4710 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4712 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4713 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4715 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4718 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4720 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4721 lParam = MAKELPARAM(16, 15);
4723 if (infoPtr->nNumButtons > 0)
4724 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4725 infoPtr->nNumButtons,
4726 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4727 LOWORD(lParam), HIWORD(lParam));
4729 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4730 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4733 if ((himlDef == infoPtr->himlInt) &&
4734 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4736 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4737 infoPtr->nBitmapHeight);
4745 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4748 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4749 TBUTTON_INFO *btnPtr;
4755 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4758 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4759 lptbbi->dwMask & 0x80000000);
4763 btnPtr = &infoPtr->buttons[nIndex];
4764 if (lptbbi->dwMask & TBIF_COMMAND)
4765 btnPtr->idCommand = lptbbi->idCommand;
4766 if (lptbbi->dwMask & TBIF_IMAGE)
4767 btnPtr->iBitmap = lptbbi->iImage;
4768 if (lptbbi->dwMask & TBIF_LPARAM)
4769 btnPtr->dwData = lptbbi->lParam;
4770 if (lptbbi->dwMask & TBIF_SIZE)
4771 btnPtr->cx = lptbbi->cx;
4772 if (lptbbi->dwMask & TBIF_STATE)
4773 btnPtr->fsState = lptbbi->fsState;
4774 if (lptbbi->dwMask & TBIF_STYLE)
4775 btnPtr->fsStyle = lptbbi->fsStyle;
4777 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4778 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4779 /* iString is index, zero it to make Str_SetPtr succeed */
4782 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4785 /* save the button rect to see if we need to redraw the whole toolbar */
4786 oldBtnRect = btnPtr->rect;
4787 TOOLBAR_CalcToolbar(hwnd);
4789 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4790 InvalidateRect(hwnd, NULL, TRUE);
4792 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4799 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4801 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4802 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4803 TBUTTON_INFO *btnPtr;
4809 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4812 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4813 lptbbi->dwMask & 0x80000000);
4817 btnPtr = &infoPtr->buttons[nIndex];
4818 if (lptbbi->dwMask & TBIF_COMMAND)
4819 btnPtr->idCommand = lptbbi->idCommand;
4820 if (lptbbi->dwMask & TBIF_IMAGE)
4821 btnPtr->iBitmap = lptbbi->iImage;
4822 if (lptbbi->dwMask & TBIF_LPARAM)
4823 btnPtr->dwData = lptbbi->lParam;
4824 if (lptbbi->dwMask & TBIF_SIZE)
4825 btnPtr->cx = lptbbi->cx;
4826 if (lptbbi->dwMask & TBIF_STATE)
4827 btnPtr->fsState = lptbbi->fsState;
4828 if (lptbbi->dwMask & TBIF_STYLE)
4829 btnPtr->fsStyle = lptbbi->fsStyle;
4831 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4832 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4833 /* iString is index, zero it to make Str_SetPtr succeed */
4835 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4838 /* save the button rect to see if we need to redraw the whole toolbar */
4839 oldBtnRect = btnPtr->rect;
4840 TOOLBAR_CalcToolbar(hwnd);
4842 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4843 InvalidateRect(hwnd, NULL, TRUE);
4845 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4852 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4855 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4857 if ((cx < 0) || (cy < 0))
4859 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4863 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4865 /* The documentation claims you can only change the button size before
4866 * any button has been added. But this is wrong.
4867 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4868 * it to the toolbar, and it checks that the return value is nonzero - mjm
4869 * Further testing shows that we must actually perform the change too.
4872 * The documentation also does not mention that if 0 is supplied for
4873 * either size, the system changes it to the default of 24 wide and
4874 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4876 infoPtr->nButtonWidth = (cx) ? cx : 24;
4877 infoPtr->nButtonHeight = (cy) ? cy : 22;
4883 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4887 /* if setting to current values, ignore */
4888 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4889 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4890 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4891 infoPtr->cxMin, infoPtr->cxMax);
4895 /* save new values */
4896 infoPtr->cxMin = (INT)LOWORD(lParam);
4897 infoPtr->cxMax = (INT)HIWORD(lParam);
4899 /* otherwise we need to recalc the toolbar and in some cases
4900 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4901 which doesn't actually draw - GA). */
4902 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4903 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4905 TOOLBAR_CalcToolbar (hwnd);
4907 InvalidateRect (hwnd, NULL, TRUE);
4914 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4916 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4917 INT nIndex = (INT)wParam;
4919 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4922 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4924 if (infoPtr->hwndToolTip) {
4926 FIXME("change tool tip!\n");
4935 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4938 HIMAGELIST himl = (HIMAGELIST)lParam;
4939 HIMAGELIST himlTemp;
4942 if (infoPtr->iVersion >= 5)
4945 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4946 &infoPtr->cimlDis, himl, id);
4948 /* FIXME: redraw ? */
4950 return (LRESULT)himlTemp;
4955 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4960 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4962 dwTemp = infoPtr->dwDTFlags;
4963 infoPtr->dwDTFlags =
4964 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4966 return (LRESULT)dwTemp;
4969 /* This function differs a bit from what MSDN says it does:
4970 * 1. lParam contains extended style flags to OR with current style
4971 * (MSDN isn't clear on the OR bit)
4972 * 2. wParam appears to contain extended style flags to be reset
4973 * (MSDN says that this parameter is reserved)
4976 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4981 dwTemp = infoPtr->dwExStyle;
4982 infoPtr->dwExStyle &= ~wParam;
4983 infoPtr->dwExStyle |= (DWORD)lParam;
4985 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4987 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4988 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4989 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4991 TOOLBAR_CalcToolbar (hwnd);
4993 TOOLBAR_AutoSize(hwnd);
4995 InvalidateRect(hwnd, NULL, TRUE);
4997 return (LRESULT)dwTemp;
5002 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5004 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5005 HIMAGELIST himlTemp;
5006 HIMAGELIST himl = (HIMAGELIST)lParam;
5009 if (infoPtr->iVersion >= 5)
5012 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
5014 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
5015 &infoPtr->cimlHot, himl, id);
5017 /* FIXME: redraw ? */
5019 return (LRESULT)himlTemp;
5023 /* Makes previous hot button no longer hot, makes the specified
5024 * button hot and sends appropriate notifications. dwReason is one or
5025 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5026 * NOTE 1: this function does not validate nHit
5027 * NOTE 2: the name of this function is completely made up and
5028 * not based on any documentation from Microsoft. */
5030 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5032 if (infoPtr->nHotItem != nHit)
5034 NMTBHOTITEM nmhotitem;
5035 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5036 LRESULT no_highlight;
5038 /* Remove the effect of an old hot button if the button was
5039 drawn with the hot button effect */
5040 if(infoPtr->nHotItem >= 0)
5042 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5043 oldBtnPtr->bHot = FALSE;
5046 infoPtr->nHotItem = nHit;
5048 /* It's not a separator or in nowhere. It's a hot button. */
5050 btnPtr = &infoPtr->buttons[nHit];
5052 nmhotitem.dwFlags = dwReason;
5054 nmhotitem.idOld = oldBtnPtr->idCommand;
5056 nmhotitem.dwFlags |= HICF_ENTERING;
5058 nmhotitem.idNew = btnPtr->idCommand;
5060 nmhotitem.dwFlags |= HICF_LEAVING;
5062 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5064 /* now invalidate the old and new buttons so they will be painted,
5065 * but only if they are enabled - disabled buttons cannot become hot */
5066 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5067 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5068 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5070 btnPtr->bHot = TRUE;
5071 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5077 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5080 INT nOldHotItem = infoPtr->nHotItem;
5082 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5084 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5087 /* NOTE: an application can still remove the hot item even if anchor
5088 * highlighting is enabled */
5090 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5091 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5093 if (nOldHotItem < 0)
5096 return (LRESULT)nOldHotItem;
5101 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5104 HIMAGELIST himlTemp;
5105 HIMAGELIST himl = (HIMAGELIST)lParam;
5108 if (infoPtr->iVersion >= 5)
5111 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5112 &infoPtr->cimlDef, himl, id);
5114 infoPtr->nNumBitmaps = 0;
5115 for (i = 0; i < infoPtr->cimlDef; i++)
5116 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5118 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5119 &infoPtr->nBitmapHeight))
5121 infoPtr->nBitmapWidth = 1;
5122 infoPtr->nBitmapHeight = 1;
5125 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5126 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5127 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5129 InvalidateRect(hwnd, NULL, TRUE);
5131 return (LRESULT)himlTemp;
5136 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 infoPtr->nIndent = (INT)wParam;
5144 /* process only on indent changing */
5145 if(infoPtr->nIndent != (INT)wParam)
5147 infoPtr->nIndent = (INT)wParam;
5148 TOOLBAR_CalcToolbar (hwnd);
5149 InvalidateRect(hwnd, NULL, FALSE);
5157 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5160 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5162 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5164 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5166 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5170 if ((lptbim->iButton == -1) ||
5171 ((lptbim->iButton < infoPtr->nNumButtons) &&
5172 (lptbim->iButton >= 0)))
5174 infoPtr->tbim = *lptbim;
5175 /* FIXME: don't need to update entire toolbar */
5176 InvalidateRect(hwnd, NULL, TRUE);
5179 ERR("Invalid button index %d\n", lptbim->iButton);
5186 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5190 infoPtr->clrInsertMark = (COLORREF)lParam;
5192 /* FIXME: don't need to update entire toolbar */
5193 InvalidateRect(hwnd, NULL, TRUE);
5200 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5204 infoPtr->nMaxTextRows = (INT)wParam;
5206 TOOLBAR_CalcToolbar(hwnd);
5211 /* MSDN gives slightly wrong info on padding.
5212 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5213 * 2. It is not used to create a blank area between the edge of the button
5214 * and the text or image if TBSTYLE_LIST is set. It is used to control
5215 * the gap between the image and text.
5216 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5217 * to control the bottom and right borders [with the border being
5218 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5219 * is shared evenly on both sides of the button.
5220 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5223 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5228 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5229 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5230 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5231 TRACE("cx=%ld, cy=%ld\n",
5232 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5233 return (LRESULT) oldPad;
5238 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5245 hwndOldNotify = infoPtr->hwndNotify;
5246 infoPtr->hwndNotify = (HWND)wParam;
5248 return (LRESULT)hwndOldNotify;
5253 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5255 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5256 LPRECT lprc = (LPRECT)lParam;
5260 if (LOWORD(wParam) > 1) {
5261 FIXME("multiple rows not supported!\n");
5264 if(infoPtr->nRows != LOWORD(wParam))
5266 infoPtr->nRows = LOWORD(wParam);
5268 /* recalculate toolbar */
5269 TOOLBAR_CalcToolbar (hwnd);
5271 /* repaint toolbar */
5272 InvalidateRect(hwnd, NULL, TRUE);
5275 /* return bounding rectangle */
5277 lprc->left = infoPtr->rcBound.left;
5278 lprc->right = infoPtr->rcBound.right;
5279 lprc->top = infoPtr->rcBound.top;
5280 lprc->bottom = infoPtr->rcBound.bottom;
5288 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5290 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5291 TBUTTON_INFO *btnPtr;
5294 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5298 btnPtr = &infoPtr->buttons[nIndex];
5300 /* if hidden state has changed the invalidate entire window and recalc */
5301 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5302 btnPtr->fsState = LOWORD(lParam);
5303 TOOLBAR_CalcToolbar (hwnd);
5304 InvalidateRect(hwnd, 0, TRUE);
5308 /* process state changing if current state doesn't match new state */
5309 if(btnPtr->fsState != LOWORD(lParam))
5311 btnPtr->fsState = LOWORD(lParam);
5312 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5320 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5322 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5328 inline static LRESULT
5329 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5333 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5335 infoPtr->hwndToolTip = (HWND)wParam;
5341 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5343 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5346 TRACE("%s hwnd=%p\n",
5347 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5349 bTemp = infoPtr->bUnicode;
5350 infoPtr->bUnicode = (BOOL)wParam;
5357 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5359 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5361 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5362 comctl32_color.clrBtnHighlight :
5363 infoPtr->clrBtnHighlight;
5364 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5365 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5371 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5373 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5375 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5376 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5377 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5379 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5380 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5381 InvalidateRect(hwnd, NULL, TRUE);
5387 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5390 INT iOldVersion = infoPtr->iVersion;
5392 infoPtr->iVersion = iVersion;
5394 if (infoPtr->iVersion >= 5)
5395 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5402 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5405 WORD iString = HIWORD(wParam);
5406 WORD buffersize = LOWORD(wParam);
5407 LPSTR str = (LPSTR)lParam;
5410 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5412 if (iString < infoPtr->nNumStrings)
5414 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5416 TRACE("returning %s\n", debugstr_a(str));
5419 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5426 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5429 WORD iString = HIWORD(wParam);
5430 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5431 LPWSTR str = (LPWSTR)lParam;
5434 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5436 if (iString < infoPtr->nNumStrings)
5438 len = min(len, strlenW(infoPtr->strings[iString]));
5439 ret = (len+1)*sizeof(WCHAR);
5440 memcpy(str, infoPtr->strings[iString], ret);
5443 TRACE("returning %s\n", debugstr_w(str));
5446 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5451 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5452 * is the maximum size of the toolbar? */
5453 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5455 SIZE * pSize = (SIZE*)lParam;
5456 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5461 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5462 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5463 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5466 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5469 INT nOldHotItem = infoPtr->nHotItem;
5471 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5472 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5474 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5477 /* NOTE: an application can still remove the hot item even if anchor
5478 * highlighting is enabled */
5480 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5484 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5487 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5488 * which controls the amount of spacing between the image and the text
5489 * of buttons for TBSTYLE_LIST toolbars. */
5490 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5492 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5494 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5497 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5499 infoPtr->iListGap = (INT)wParam;
5501 InvalidateRect(hwnd, NULL, TRUE);
5506 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5507 * of image lists associated with the various states. */
5508 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5512 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5514 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5518 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5521 LPSIZE lpsize = (LPSIZE)lParam;
5527 * Testing shows the following:
5528 * wParam = 0 adjust cx value
5529 * = 1 set cy value to max size.
5530 * lParam pointer to SIZE structure
5533 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5534 wParam, lParam, lpsize->cx, lpsize->cy);
5538 if (lpsize->cx == -1) {
5539 /* **** this is wrong, native measures each button and sets it */
5540 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5542 else if(HIWORD(lpsize->cx)) {
5544 HWND hwndParent = GetParent(hwnd);
5546 GetWindowRect(hwnd, &rc);
5547 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5548 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5549 rc.left, rc.top, rc.right, rc.bottom);
5550 lpsize->cx = max(rc.right-rc.left,
5551 infoPtr->rcBound.right - infoPtr->rcBound.left);
5554 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5558 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5561 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5565 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5566 lpsize->cx, lpsize->cy);
5570 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5572 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5574 InvalidateRect(hwnd, NULL, TRUE);
5580 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5583 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5586 TRACE("hwnd = %p\n", hwnd);
5588 /* initialize info structure */
5589 infoPtr->nButtonHeight = 22;
5590 infoPtr->nButtonWidth = 24;
5591 infoPtr->nBitmapHeight = 15;
5592 infoPtr->nBitmapWidth = 16;
5594 infoPtr->nMaxTextRows = 1;
5595 infoPtr->cxMin = -1;
5596 infoPtr->cxMax = -1;
5597 infoPtr->nNumBitmaps = 0;
5598 infoPtr->nNumStrings = 0;
5600 infoPtr->bCaptured = FALSE;
5601 infoPtr->nButtonDown = -1;
5602 infoPtr->nButtonDrag = -1;
5603 infoPtr->nOldHit = -1;
5604 infoPtr->nHotItem = -1;
5605 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5606 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5607 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5608 infoPtr->bDragOutSent = FALSE;
5609 infoPtr->iVersion = 0;
5610 infoPtr->hwndSelf = hwnd;
5611 infoPtr->bDoRedraw = TRUE;
5612 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5613 infoPtr->clrBtnShadow = CLR_DEFAULT;
5614 infoPtr->szPadding.cx = DEFPAD_CX;
5615 infoPtr->szPadding.cy = DEFPAD_CY;
5616 infoPtr->iListGap = DEFLISTGAP;
5617 infoPtr->dwStyle = dwStyle;
5618 infoPtr->tbim.iButton = -1;
5619 GetClientRect(hwnd, &infoPtr->client_rect);
5620 infoPtr->bUnicode = infoPtr->hwndNotify &&
5621 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5623 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5624 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5626 if (dwStyle & TBSTYLE_TOOLTIPS) {
5627 /* Create tooltip control */
5628 infoPtr->hwndToolTip =
5629 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5630 CW_USEDEFAULT, CW_USEDEFAULT,
5631 CW_USEDEFAULT, CW_USEDEFAULT,
5634 /* Send NM_TOOLTIPSCREATED notification */
5635 if (infoPtr->hwndToolTip)
5637 NMTOOLTIPSCREATED nmttc;
5639 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5641 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5645 OpenThemeData (hwnd, themeClass);
5647 TOOLBAR_CheckStyle (hwnd, dwStyle);
5649 TOOLBAR_CalcToolbar(hwnd);
5656 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5660 /* delete tooltip control */
5661 if (infoPtr->hwndToolTip)
5662 DestroyWindow (infoPtr->hwndToolTip);
5664 /* delete temporary buffer for tooltip text */
5665 Free (infoPtr->pszTooltipText);
5667 /* delete button data */
5668 if (infoPtr->buttons)
5669 Free (infoPtr->buttons);
5671 /* delete strings */
5672 if (infoPtr->strings) {
5674 for (i = 0; i < infoPtr->nNumStrings; i++)
5675 if (infoPtr->strings[i])
5676 Free (infoPtr->strings[i]);
5678 Free (infoPtr->strings);
5681 /* destroy internal image list */
5682 if (infoPtr->himlInt)
5683 ImageList_Destroy (infoPtr->himlInt);
5685 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5686 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5687 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5689 /* delete default font */
5691 DeleteObject (infoPtr->hDefaultFont);
5693 CloseThemeData (GetWindowTheme (hwnd));
5695 /* free toolbar info data */
5697 SetWindowLongPtrW (hwnd, 0, 0);
5704 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5707 NMTBCUSTOMDRAW tbcd;
5710 HTHEME theme = GetWindowTheme (hwnd);
5712 /* the app has told us not to redraw the toolbar */
5713 if (!infoPtr->bDoRedraw)
5716 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5717 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5718 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5719 tbcd.nmcd.hdc = (HDC)wParam;
5720 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5721 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5723 /* FIXME: in general the return flags *can* be or'ed together */
5724 switch (infoPtr->dwBaseCustDraw)
5726 case CDRF_DODEFAULT:
5728 case CDRF_SKIPDEFAULT:
5731 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5736 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5737 * to my parent for processing.
5739 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5741 HDC hdc = (HDC)wParam;
5746 parent = GetParent(hwnd);
5747 MapWindowPoints(hwnd, parent, &pt, 1);
5748 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5749 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5750 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5753 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5755 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5756 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5757 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5758 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5759 tbcd.nmcd.hdc = (HDC)wParam;
5760 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5761 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5762 switch (infoPtr->dwBaseCustDraw)
5764 case CDRF_DODEFAULT:
5766 case CDRF_SKIPDEFAULT:
5769 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5778 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5780 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5782 return (LRESULT)infoPtr->hFont;
5787 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5792 pt.x = (INT)LOWORD(lParam);
5793 pt.y = (INT)HIWORD(lParam);
5794 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5797 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5798 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5799 TOOLBAR_Customize (hwnd);
5806 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5808 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5809 TBUTTON_INFO *btnPtr;
5814 BOOL bDragKeyPressed;
5818 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5819 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5821 bDragKeyPressed = (wParam & MK_SHIFT);
5823 if (infoPtr->hwndToolTip)
5824 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5825 WM_LBUTTONDOWN, wParam, lParam);
5827 pt.x = (INT)LOWORD(lParam);
5828 pt.y = (INT)HIWORD(lParam);
5829 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5831 btnPtr = &infoPtr->buttons[nHit];
5833 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5835 infoPtr->nButtonDrag = nHit;
5838 /* If drag cursor has not been loaded, load it.
5839 * Note: it doesn't need to be freed */
5841 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5842 SetCursor(hCursorDrag);
5847 infoPtr->nOldHit = nHit;
5849 CopyRect(&arrowRect, &btnPtr->rect);
5850 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5852 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5853 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5854 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5855 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5856 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5857 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5861 /* draw in pressed state */
5862 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5863 btnPtr->fsState |= TBSTATE_PRESSED;
5865 btnPtr->bDropDownPressed = TRUE;
5866 RedrawWindow(hwnd,&btnPtr->rect,0,
5867 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5869 memset(&nmtb, 0, sizeof(nmtb));
5870 nmtb.iItem = btnPtr->idCommand;
5871 nmtb.rcButton = btnPtr->rect;
5872 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5874 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5876 if (res != TBDDRET_TREATPRESSED)
5880 /* redraw button in unpressed state */
5881 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5882 btnPtr->fsState &= ~TBSTATE_PRESSED;
5884 btnPtr->bDropDownPressed = FALSE;
5885 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5887 /* find and set hot item
5888 * NOTE: native doesn't do this, but that is a bug */
5890 ScreenToClient(hwnd, &pt);
5891 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5892 if (!infoPtr->bAnchor || (nHit >= 0))
5893 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5895 /* remove any left mouse button down or double-click messages
5896 * so that we can get a toggle effect on the button */
5897 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5898 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5903 /* otherwise drop through and process as pushed */
5905 infoPtr->bCaptured = TRUE;
5906 infoPtr->nButtonDown = nHit;
5907 infoPtr->bDragOutSent = FALSE;
5909 btnPtr->fsState |= TBSTATE_PRESSED;
5911 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5913 if (btnPtr->fsState & TBSTATE_ENABLED)
5914 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5921 memset(&nmtb, 0, sizeof(nmtb));
5922 nmtb.iItem = btnPtr->idCommand;
5923 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5926 nmmouse.dwHitInfo = nHit;
5928 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5930 nmmouse.dwItemSpec = -1;
5933 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5934 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5937 ClientToScreen(hwnd, &pt);
5940 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5941 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5947 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5950 TBUTTON_INFO *btnPtr;
5954 BOOL bSendMessage = TRUE;
5959 if (infoPtr->hwndToolTip)
5960 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5961 WM_LBUTTONUP, wParam, lParam);
5963 pt.x = (INT)LOWORD(lParam);
5964 pt.y = (INT)HIWORD(lParam);
5965 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5967 if (!infoPtr->bAnchor || (nHit >= 0))
5968 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5970 if (infoPtr->nButtonDrag >= 0) {
5974 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5977 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5979 GetClientRect(hwnd, &rcClient);
5980 if (PtInRect(&rcClient, pt))
5987 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5990 if (nButton == infoPtr->nButtonDrag)
5992 /* if the button is moved sightly left and we have a
5993 * separator there then remove it */
5994 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5996 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5997 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5999 else /* else insert a separator before the dragged button */
6002 memset(&tbb, 0, sizeof(tbb));
6003 tbb.fsStyle = BTNS_SEP;
6005 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6012 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6013 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6015 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6018 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6023 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6024 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6027 /* button under cursor changed so need to re-set hot item */
6028 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6029 infoPtr->nButtonDrag = -1;
6031 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6033 else if (infoPtr->nButtonDown >= 0) {
6034 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6035 btnPtr->fsState &= ~TBSTATE_PRESSED;
6037 if (btnPtr->fsStyle & BTNS_CHECK) {
6038 if (btnPtr->fsStyle & BTNS_GROUP) {
6039 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6041 if (nOldIndex == nHit)
6042 bSendMessage = FALSE;
6043 if ((nOldIndex != nHit) &&
6045 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6046 btnPtr->fsState |= TBSTATE_CHECKED;
6049 if (btnPtr->fsState & TBSTATE_CHECKED)
6050 btnPtr->fsState &= ~TBSTATE_CHECKED;
6052 btnPtr->fsState |= TBSTATE_CHECKED;
6056 if (nOldIndex != -1)
6057 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6060 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6061 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6062 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6064 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6066 infoPtr->nButtonDown = -1;
6068 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6069 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6070 NM_RELEASEDCAPTURE);
6072 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6075 memset(&nmtb, 0, sizeof(nmtb));
6076 nmtb.iItem = btnPtr->idCommand;
6077 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6080 if (btnPtr->fsState & TBSTATE_ENABLED)
6082 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6083 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
6087 /* !!! Undocumented - toolbar at 4.71 level and above sends
6088 * NM_CLICK with the NMMOUSE structure. */
6089 nmmouse.dwHitInfo = nHit;
6091 if (nmmouse.dwHitInfo < 0)
6092 nmmouse.dwItemSpec = -1;
6095 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6096 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6099 ClientToScreen(hwnd, &pt);
6102 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6103 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6109 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6116 pt.x = LOWORD(lParam);
6117 pt.y = HIWORD(lParam);
6119 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6120 nmmouse.dwHitInfo = nHit;
6123 nmmouse.dwItemSpec = -1;
6125 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6126 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6129 ClientToScreen(hwnd, &pt);
6132 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6133 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6139 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6141 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6144 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6145 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6151 TOOLBAR_CaptureChanged(HWND hwnd)
6153 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6154 TBUTTON_INFO *btnPtr;
6156 infoPtr->bCaptured = FALSE;
6158 if (infoPtr->nButtonDown >= 0)
6160 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6161 btnPtr->fsState &= ~TBSTATE_PRESSED;
6163 infoPtr->nOldHit = -1;
6165 if (btnPtr->fsState & TBSTATE_ENABLED)
6166 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6172 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6175 TBUTTON_INFO *hotBtnPtr;
6177 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6179 /* don't remove hot effects when in anchor highlighting mode or when a
6180 * drop-down button is pressed */
6181 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6182 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6184 if (infoPtr->nOldHit < 0)
6187 /* If the last button we were over is depressed then make it not */
6188 /* depressed and redraw it */
6189 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6191 TBUTTON_INFO *btnPtr;
6194 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6196 btnPtr->fsState &= ~TBSTATE_PRESSED;
6198 rc1 = hotBtnPtr->rect;
6199 InflateRect (&rc1, 1, 1);
6200 InvalidateRect (hwnd, &rc1, TRUE);
6203 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6206 ZeroMemory(&nmt, sizeof(nmt));
6207 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6208 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6209 infoPtr->bDragOutSent = TRUE;
6212 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6218 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6222 TRACKMOUSEEVENT trackinfo;
6224 TBUTTON_INFO *btnPtr;
6226 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6227 /* fill in the TRACKMOUSEEVENT struct */
6228 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6229 trackinfo.dwFlags = TME_QUERY;
6230 trackinfo.hwndTrack = hwnd;
6231 trackinfo.dwHoverTime = HOVER_DEFAULT;
6233 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6234 _TrackMouseEvent(&trackinfo);
6236 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6237 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6238 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6240 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6241 /* and can properly deactivate the hot toolbar button */
6242 _TrackMouseEvent(&trackinfo);
6246 if (infoPtr->hwndToolTip)
6247 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6248 WM_MOUSEMOVE, wParam, lParam);
6250 pt.x = (INT)LOWORD(lParam);
6251 pt.y = (INT)HIWORD(lParam);
6253 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6255 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6256 && (!infoPtr->bAnchor || (nHit >= 0)))
6257 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6259 if (infoPtr->nOldHit != nHit)
6261 if (infoPtr->bCaptured)
6263 if (!infoPtr->bDragOutSent)
6266 ZeroMemory(&nmt, sizeof(nmt));
6267 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6268 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6269 infoPtr->bDragOutSent = TRUE;
6272 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6273 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6274 btnPtr->fsState &= ~TBSTATE_PRESSED;
6275 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6277 else if (nHit == infoPtr->nButtonDown) {
6278 btnPtr->fsState |= TBSTATE_PRESSED;
6279 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6281 infoPtr->nOldHit = nHit;
6289 inline static LRESULT
6290 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6292 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6293 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6295 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6299 inline static LRESULT
6300 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6302 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6303 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6305 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6310 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6312 TOOLBAR_INFO *infoPtr;
6313 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6316 /* allocate memory for info structure */
6317 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6318 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6321 infoPtr->dwStructSize = sizeof(TBBUTTON);
6324 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6325 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6326 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6327 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6330 /* native control does:
6331 * Get a lot of colors and brushes
6333 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6334 * CreateFontIndirectW(adr1)
6335 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6336 * hdc = GetDC(toolbar)
6337 * GetSystemMetrics(0x48)
6338 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6339 * 0, 0, 0, 0, "MARLETT")
6340 * oldfnt = SelectObject(hdc, fnt2)
6341 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6342 * GetTextMetricsW(hdc, adr3)
6343 * SelectObject(hdc, oldfnt)
6344 * DeleteObject(fnt2)
6346 * InvalidateRect(toolbar, 0, 1)
6347 * SetWindowLongW(toolbar, 0, addr)
6348 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6351 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6352 * ie 2 0x4600094c 0x4600094c 0x4600894d
6353 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6354 * rebar 0x50008844 0x40008844 0x50008845
6355 * pager 0x50000844 0x40000844 0x50008845
6356 * IC35mgr 0x5400084e **nochange**
6357 * on entry to _NCCREATE 0x5400084e
6358 * rowlist 0x5400004e **nochange**
6359 * on entry to _NCCREATE 0x5400004e
6363 /* I think the code below is a bug, but it is the way that the native
6364 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6365 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6366 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6367 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6368 * Somehow, the only cases of this seem to be MFC programs.
6370 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6371 * does not occur in the WM_STYLECHANGING routine.
6372 * (Guy Albertelli 9/2001)
6375 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6376 && !(cs->style & TBSTYLE_TRANSPARENT))
6377 styleadd |= TBSTYLE_TRANSPARENT;
6378 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6379 styleadd |= CCS_TOP; /* default to top */
6380 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6383 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6388 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6390 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6394 if (dwStyle & WS_MINIMIZE)
6395 return 0; /* Nothing to do */
6397 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6399 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6402 if (!(dwStyle & CCS_NODIVIDER))
6404 GetWindowRect (hwnd, &rcWindow);
6405 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6406 if( dwStyle & WS_BORDER )
6407 OffsetRect (&rcWindow, 1, 1);
6408 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6411 ReleaseDC( hwnd, hdc );
6417 /* handles requests from the tooltip control on what text to display */
6418 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6420 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6422 TRACE("button index = %d\n", index);
6424 Free (infoPtr->pszTooltipText);
6425 infoPtr->pszTooltipText = NULL;
6430 if (infoPtr->bUnicode)
6432 WCHAR wszBuffer[INFOTIPSIZE+1];
6433 NMTBGETINFOTIPW tbgit;
6434 unsigned int len; /* in chars */
6436 wszBuffer[0] = '\0';
6437 wszBuffer[INFOTIPSIZE] = '\0';
6439 tbgit.pszText = wszBuffer;
6440 tbgit.cchTextMax = INFOTIPSIZE;
6441 tbgit.iItem = lpnmtdi->hdr.idFrom;
6442 tbgit.lParam = infoPtr->buttons[index].dwData;
6444 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6446 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6448 len = strlenW(tbgit.pszText);
6449 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6451 /* need to allocate temporary buffer in infoPtr as there
6452 * isn't enough space in buffer passed to us by the
6453 * tooltip control */
6454 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6455 if (infoPtr->pszTooltipText)
6457 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6458 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6464 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6470 CHAR szBuffer[INFOTIPSIZE+1];
6471 NMTBGETINFOTIPA tbgit;
6472 unsigned int len; /* in chars */
6475 szBuffer[INFOTIPSIZE] = '\0';
6477 tbgit.pszText = szBuffer;
6478 tbgit.cchTextMax = INFOTIPSIZE;
6479 tbgit.iItem = lpnmtdi->hdr.idFrom;
6480 tbgit.lParam = infoPtr->buttons[index].dwData;
6482 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6484 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6486 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6487 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6489 /* need to allocate temporary buffer in infoPtr as there
6490 * isn't enough space in buffer passed to us by the
6491 * tooltip control */
6492 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6493 if (infoPtr->pszTooltipText)
6495 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6496 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6502 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6507 /* if button has text, but it is not shown then automatically
6508 * use that text as tooltip */
6509 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6510 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6512 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6513 unsigned int len = pszText ? strlenW(pszText) : 0;
6515 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6517 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6519 /* need to allocate temporary buffer in infoPtr as there
6520 * isn't enough space in buffer passed to us by the
6521 * tooltip control */
6522 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6523 if (infoPtr->pszTooltipText)
6525 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6526 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6532 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6537 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6539 /* last resort: send notification on to app */
6540 /* FIXME: find out what is really used here */
6541 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6545 inline static LRESULT
6546 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6549 LPNMHDR lpnmh = (LPNMHDR)lParam;
6551 switch (lpnmh->code)
6555 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6557 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6558 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6559 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6563 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6564 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6572 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6574 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6575 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6576 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6577 lppgs->iScroll, lppgs->iDir);
6581 case TTN_GETDISPINFOW:
6582 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6584 case TTN_GETDISPINFOA:
6585 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6595 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6599 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6601 if (lParam == NF_QUERY)
6604 if (lParam == NF_REQUERY) {
6605 format = SendMessageW(infoPtr->hwndNotify,
6606 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6607 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6608 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6619 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6625 /* fill ps.rcPaint with a default rect */
6626 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6628 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6630 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6631 ps.rcPaint.left, ps.rcPaint.top,
6632 ps.rcPaint.right, ps.rcPaint.bottom);
6634 TOOLBAR_Refresh (hwnd, hdc, &ps);
6635 if (!wParam) EndPaint (hwnd, &ps);
6642 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6643 /*****************************************************
6646 * Handles the WM_SETREDRAW message.
6649 * According to testing V4.71 of COMCTL32 returns the
6650 * *previous* status of the redraw flag (either 0 or 1)
6651 * instead of the MSDN documented value of 0 if handled.
6652 * (For laughs see the "consistency" with same function
6655 *****************************************************/
6657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6658 BOOL oldredraw = infoPtr->bDoRedraw;
6660 TRACE("set to %s\n",
6661 (wParam) ? "TRUE" : "FALSE");
6662 infoPtr->bDoRedraw = (BOOL) wParam;
6664 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6666 return (oldredraw) ? 1 : 0;
6671 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6675 TRACE("sizing toolbar!\n");
6677 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6679 RECT delta_width, delta_height, client, dummy;
6680 DWORD min_x, max_x, min_y, max_y;
6681 TBUTTON_INFO *btnPtr;
6684 GetClientRect(hwnd, &client);
6685 if(client.right > infoPtr->client_rect.right)
6687 min_x = infoPtr->client_rect.right;
6688 max_x = client.right;
6692 max_x = infoPtr->client_rect.right;
6693 min_x = client.right;
6695 if(client.bottom > infoPtr->client_rect.bottom)
6697 min_y = infoPtr->client_rect.bottom;
6698 max_y = client.bottom;
6702 max_y = infoPtr->client_rect.bottom;
6703 min_y = client.bottom;
6706 SetRect(&delta_width, min_x, 0, max_x, min_y);
6707 SetRect(&delta_height, 0, min_y, max_x, max_y);
6709 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6710 btnPtr = infoPtr->buttons;
6711 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6712 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6713 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6714 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6716 GetClientRect(hwnd, &infoPtr->client_rect);
6717 TOOLBAR_AutoSize(hwnd);
6723 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6727 if (nType == GWL_STYLE)
6729 if (lpStyle->styleNew & TBSTYLE_LIST)
6730 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6732 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6734 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6736 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6738 infoPtr->dwStyle = lpStyle->styleNew;
6740 /* only resize if one of the CCS_* styles was changed */
6741 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6743 TOOLBAR_AutoSize (hwnd);
6745 InvalidateRect(hwnd, NULL, TRUE);
6754 TOOLBAR_SysColorChange (HWND hwnd)
6756 COMCTL32_RefreshSysColors();
6762 /* update theme after a WM_THEMECHANGED message */
6763 static LRESULT theme_changed (HWND hwnd)
6765 HTHEME theme = GetWindowTheme (hwnd);
6766 CloseThemeData (theme);
6767 OpenThemeData (hwnd, themeClass);
6772 static LRESULT WINAPI
6773 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6775 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6777 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6778 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6780 if (!infoPtr && (uMsg != WM_NCCREATE))
6781 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6786 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6788 case TB_ADDBUTTONSA:
6789 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6791 case TB_ADDBUTTONSW:
6792 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6795 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6798 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6801 return TOOLBAR_AutoSize (hwnd);
6803 case TB_BUTTONCOUNT:
6804 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6806 case TB_BUTTONSTRUCTSIZE:
6807 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6809 case TB_CHANGEBITMAP:
6810 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6812 case TB_CHECKBUTTON:
6813 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6815 case TB_COMMANDTOINDEX:
6816 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6819 return TOOLBAR_Customize (hwnd);
6821 case TB_DELETEBUTTON:
6822 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6824 case TB_ENABLEBUTTON:
6825 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6827 case TB_GETANCHORHIGHLIGHT:
6828 return TOOLBAR_GetAnchorHighlight (hwnd);
6831 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6833 case TB_GETBITMAPFLAGS:
6834 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6837 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6839 case TB_GETBUTTONINFOA:
6840 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6842 case TB_GETBUTTONINFOW:
6843 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6845 case TB_GETBUTTONSIZE:
6846 return TOOLBAR_GetButtonSize (hwnd);
6848 case TB_GETBUTTONTEXTA:
6849 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6851 case TB_GETBUTTONTEXTW:
6852 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6854 case TB_GETDISABLEDIMAGELIST:
6855 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6857 case TB_GETEXTENDEDSTYLE:
6858 return TOOLBAR_GetExtendedStyle (hwnd);
6860 case TB_GETHOTIMAGELIST:
6861 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6864 return TOOLBAR_GetHotItem (hwnd);
6866 case TB_GETIMAGELIST:
6867 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6869 case TB_GETINSERTMARK:
6870 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6872 case TB_GETINSERTMARKCOLOR:
6873 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6875 case TB_GETITEMRECT:
6876 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6879 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6881 /* case TB_GETOBJECT: */ /* 4.71 */
6884 return TOOLBAR_GetPadding (hwnd);
6887 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6890 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6893 return TOOLBAR_GetState (hwnd, wParam, lParam);
6896 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6899 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6902 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6904 case TB_GETTEXTROWS:
6905 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6907 case TB_GETTOOLTIPS:
6908 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6910 case TB_GETUNICODEFORMAT:
6911 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6914 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6917 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6919 case TB_INDETERMINATE:
6920 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6922 case TB_INSERTBUTTONA:
6923 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6925 case TB_INSERTBUTTONW:
6926 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6928 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6930 case TB_ISBUTTONCHECKED:
6931 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6933 case TB_ISBUTTONENABLED:
6934 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6936 case TB_ISBUTTONHIDDEN:
6937 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6939 case TB_ISBUTTONHIGHLIGHTED:
6940 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6942 case TB_ISBUTTONINDETERMINATE:
6943 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6945 case TB_ISBUTTONPRESSED:
6946 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6949 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6951 case TB_MAPACCELERATORA:
6952 case TB_MAPACCELERATORW:
6953 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6956 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6959 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6961 case TB_PRESSBUTTON:
6962 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6964 case TB_REPLACEBITMAP:
6965 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6967 case TB_SAVERESTOREA:
6968 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6970 case TB_SAVERESTOREW:
6971 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6973 case TB_SETANCHORHIGHLIGHT:
6974 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6976 case TB_SETBITMAPSIZE:
6977 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6979 case TB_SETBUTTONINFOA:
6980 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6982 case TB_SETBUTTONINFOW:
6983 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6985 case TB_SETBUTTONSIZE:
6986 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6988 case TB_SETBUTTONWIDTH:
6989 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6992 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6994 case TB_SETDISABLEDIMAGELIST:
6995 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6997 case TB_SETDRAWTEXTFLAGS:
6998 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7000 case TB_SETEXTENDEDSTYLE:
7001 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7003 case TB_SETHOTIMAGELIST:
7004 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7007 return TOOLBAR_SetHotItem (hwnd, wParam);
7009 case TB_SETIMAGELIST:
7010 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7013 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7015 case TB_SETINSERTMARK:
7016 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7018 case TB_SETINSERTMARKCOLOR:
7019 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7021 case TB_SETMAXTEXTROWS:
7022 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7025 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7028 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7031 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7034 return TOOLBAR_SetState (hwnd, wParam, lParam);
7037 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7039 case TB_SETTOOLTIPS:
7040 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7042 case TB_SETUNICODEFORMAT:
7043 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7046 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7049 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7052 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7055 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7058 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7061 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7063 /* Common Control Messages */
7065 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7066 case CCM_GETCOLORSCHEME:
7067 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7069 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7070 case CCM_SETCOLORSCHEME:
7071 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7073 case CCM_GETVERSION:
7074 return TOOLBAR_GetVersion (hwnd);
7076 case CCM_SETVERSION:
7077 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7083 return TOOLBAR_Create (hwnd, wParam, lParam);
7086 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7089 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7092 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7094 /* case WM_KEYDOWN: */
7095 /* case WM_KILLFOCUS: */
7097 case WM_LBUTTONDBLCLK:
7098 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7100 case WM_LBUTTONDOWN:
7101 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7104 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7107 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7109 case WM_RBUTTONDBLCLK:
7110 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7113 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7116 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7118 case WM_CAPTURECHANGED:
7119 return TOOLBAR_CaptureChanged(hwnd);
7122 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7125 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7128 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7131 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7134 return TOOLBAR_Notify (hwnd, wParam, lParam);
7136 case WM_NOTIFYFORMAT:
7137 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7140 return TOOLBAR_Paint (hwnd, wParam);
7143 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7146 return TOOLBAR_Size (hwnd, wParam, lParam);
7148 case WM_STYLECHANGED:
7149 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7151 case WM_SYSCOLORCHANGE:
7152 return TOOLBAR_SysColorChange (hwnd);
7154 case WM_THEMECHANGED:
7155 return theme_changed (hwnd);
7157 /* case WM_WININICHANGE: */
7162 case WM_MEASUREITEM:
7164 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7166 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7167 case PGM_FORWARDMOUSE:
7168 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7171 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7172 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7173 uMsg, wParam, lParam);
7174 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7180 TOOLBAR_Register (void)
7184 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7185 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7186 wndClass.lpfnWndProc = ToolbarWindowProc;
7187 wndClass.cbClsExtra = 0;
7188 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7189 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7190 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7191 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7193 RegisterClassW (&wndClass);
7198 TOOLBAR_Unregister (void)
7200 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7203 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7208 /* Check if the entry already exists */
7209 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7211 /* If this is a new entry we must create it and insert into the array */
7216 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7219 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7220 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7235 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7239 for (i = 0; i < *cies; i++)
7249 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7257 for (i = 0; i < cies; i++)
7259 if (pies[i]->id == id)
7271 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7273 HIMAGELIST himlDef = 0;
7274 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7277 himlDef = pie->himl;
7283 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7285 if (infoPtr->bUnicode)
7286 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7293 nmtba.iItem = nmtb->iItem;
7294 nmtba.pszText = Buffer;
7295 nmtba.cchText = 256;
7296 ZeroMemory(nmtba.pszText, nmtba.cchText);
7298 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7300 int ccht = strlen(nmtba.pszText);
7302 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7303 nmtb->pszText, nmtb->cchText);
7305 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7314 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7315 int iItem, PCUSTOMBUTTON btnInfo)
7319 /* MSDN states that iItem is the index of the button, rather than the
7320 * command ID as used by every other NMTOOLBAR notification */
7322 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7324 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);