4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
98 BYTE bDropDownPressed;
103 INT cx; /* manually set size */
117 } IMLENTRY, *PIMLENTRY;
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
124 RECT rcBound; /* bounding rectangle */
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nHotItem; /* index of the "hot" item */
142 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding; /* padding values around button */
146 INT iListGap; /* default gap between text and image for toolbar with list style */
148 HFONT hFont; /* text font */
149 HIMAGELIST himlInt; /* image list created internally */
150 PIMLENTRY *himlDef; /* default image list array */
151 INT cimlDef; /* default image list array count */
152 PIMLENTRY *himlHot; /* hot image list array */
153 INT cimlHot; /* hot image list array count */
154 PIMLENTRY *himlDis; /* disabled image list array */
155 INT cimlDis; /* disabled image list array count */
156 HWND hwndToolTip; /* handle to tool tip control */
157 HWND hwndNotify; /* handle to the window that gets notifications */
158 HWND hwndSelf; /* my own handle */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bDoRedraw; /* Redraw status */
161 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
162 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
163 BOOL bCaptured; /* mouse captured? */
164 DWORD dwStyle; /* regular toolbar style */
165 DWORD dwExStyle; /* extended toolbar style */
166 DWORD dwDTFlags; /* DrawText flags */
168 COLORREF clrInsertMark; /* insert mark color */
169 COLORREF clrBtnHighlight; /* color for Flat Separator */
170 COLORREF clrBtnShadow; /* color for Flag Separator */
172 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
173 * for TTN_GETDISPINFOW notification */
174 TBINSERTMARK tbim; /* info on insertion mark */
175 TBUTTON_INFO *buttons; /* pointer to button array */
176 LPWSTR *strings; /* pointer to string array */
177 TBITMAP_INFO *bitmaps;
178 } TOOLBAR_INFO, *PTOOLBAR_INFO;
181 /* used by customization dialog */
184 PTOOLBAR_INFO tbInfo;
186 } CUSTDLG_INFO, *PCUSTDLG_INFO;
194 } CUSTOMBUTTON, *PCUSTOMBUTTON;
203 #define SEPARATOR_WIDTH 8
205 #define BOTTOM_BORDER 2
206 #define DDARROW_WIDTH 11
207 #define ARROW_HEIGHT 3
208 #define INSERTMARK_WIDTH 2
214 /* vertical padding used in list mode when image is present */
217 /* how wide to treat the bitmap if it isn't present */
218 #define NONLIST_NOTEXT_OFFSET 2
220 #define TOOLBAR_NOWHERE (-1)
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 /* Used to find undocumented extended styles */
227 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
228 TBSTYLE_EX_UNDOC1 | \
229 TBSTYLE_EX_MIXEDBUTTONS | \
230 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
232 /* all of the CCS_ styles */
233 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
234 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
236 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
237 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
238 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
239 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
240 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
242 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
255 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
259 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
261 LPWSTR lpText = NULL;
263 /* NOTE: iString == -1 is undocumented */
264 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
265 lpText = (LPWSTR)btnPtr->iString;
266 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
267 lpText = infoPtr->strings[btnPtr->iString];
273 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
275 if (TRACE_ON(toolbar)){
276 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
277 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
278 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
279 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
281 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
282 btn_num, bP->idCommand,
283 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
284 bP->rect.left, bP->rect.top,
285 bP->rect.right, bP->rect.bottom);
291 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
293 if (TRACE_ON(toolbar)) {
296 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
298 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
299 iP->nNumStrings, iP->dwStyle);
300 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
302 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
303 (iP->bDoRedraw) ? "TRUE" : "FALSE");
304 for(i=0; i<iP->nNumButtons; i++) {
305 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
311 /***********************************************************************
314 * This function validates that the styles set are implemented and
315 * issues FIXME's warning of possible problems. In a perfect world this
316 * function should be null.
319 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
321 if (dwStyle & TBSTYLE_REGISTERDROP)
322 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
327 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
329 if(!IsWindow(infoPtr->hwndSelf))
330 return 0; /* we have just been destroyed */
332 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
333 nmhdr->hwndFrom = infoPtr->hwndSelf;
336 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
337 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
339 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
340 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
343 /***********************************************************************
344 * TOOLBAR_GetBitmapIndex
346 * This function returns the bitmap index associated with a button.
347 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
348 * is issued to retrieve the index.
351 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
353 INT ret = btnPtr->iBitmap;
355 if (ret == I_IMAGECALLBACK)
357 /* issue TBN_GETDISPINFO */
360 memset(&nmgd, 0, sizeof(nmgd));
361 nmgd.idCommand = btnPtr->idCommand;
362 nmgd.lParam = btnPtr->dwData;
363 nmgd.dwMask = TBNF_IMAGE;
364 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
365 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
366 if (nmgd.dwMask & TBNF_DI_SETITEM)
367 btnPtr->iBitmap = nmgd.iImage;
369 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
370 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
373 if (ret != I_IMAGENONE)
374 ret = GETIBITMAP(infoPtr, ret);
381 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
384 INT id = GETHIMLID(infoPtr, index);
385 INT iBitmap = GETIBITMAP(infoPtr, index);
387 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
388 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
389 (index == I_IMAGECALLBACK))
397 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
399 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
400 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
404 /***********************************************************************
405 * TOOLBAR_GetImageListForDrawing
407 * This function validates the bitmap index (including I_IMAGECALLBACK
408 * functionality) and returns the corresponding image list.
411 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
415 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
416 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
417 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
418 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
422 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
423 if ((*index == I_IMAGECALLBACK) ||
424 (*index == I_IMAGENONE)) return NULL;
425 ERR("TBN_GETDISPINFO returned invalid index %d\n",
432 case IMAGE_LIST_DEFAULT:
433 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 case IMAGE_LIST_DISABLED:
439 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 FIXME("Shouldn't reach here\n");
447 TRACE("no image list\n");
454 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
457 COLORREF oldcolor, newcolor;
459 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
460 myrect.right = myrect.left + 1;
461 myrect.top = lpRect->top + 2;
462 myrect.bottom = lpRect->bottom - 2;
464 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
465 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
466 oldcolor = SetBkColor (hdc, newcolor);
467 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
469 myrect.left = myrect.right;
470 myrect.right = myrect.left + 1;
472 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
473 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
474 SetBkColor (hdc, newcolor);
475 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
477 SetBkColor (hdc, oldcolor);
481 /***********************************************************************
482 * TOOLBAR_DrawDDFlatSeparator
484 * This function draws the separator that was flagged as BTNS_DROPDOWN.
485 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
486 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
487 * are horizontal as opposed to the vertical separators for not dropdown
490 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
493 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
496 COLORREF oldcolor, newcolor;
498 myrect.left = lpRect->left;
499 myrect.right = lpRect->right;
500 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
501 myrect.bottom = myrect.top + 1;
503 InflateRect (&myrect, -2, 0);
505 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
506 myrect.left, myrect.top, myrect.right, myrect.bottom);
508 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
509 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
510 oldcolor = SetBkColor (hdc, newcolor);
511 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
513 myrect.top = myrect.bottom;
514 myrect.bottom = myrect.top + 1;
516 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
517 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
518 SetBkColor (hdc, newcolor);
519 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
521 SetBkColor (hdc, oldcolor);
526 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
531 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
532 hOldPen = SelectObject ( hdc, hPen );
535 MoveToEx (hdc, x, y, NULL);
536 LineTo (hdc, x+5, y++); x++;
537 MoveToEx (hdc, x, y, NULL);
538 LineTo (hdc, x+3, y++); x++;
539 MoveToEx (hdc, x, y, NULL);
540 LineTo (hdc, x+1, y++);
541 SelectObject( hdc, hOldPen );
542 DeleteObject( hPen );
546 * Draw the text string for this button.
547 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
548 * is non-zero, so we can simply check himlDef to see if we have
552 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
553 NMTBCUSTOMDRAW *tbcd)
555 HDC hdc = tbcd->nmcd.hdc;
558 COLORREF clrOldBk = 0;
560 UINT state = tbcd->nmcd.uItemState;
564 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
565 rcText->left, rcText->top, rcText->right, rcText->bottom);
567 hOldFont = SelectObject (hdc, infoPtr->hFont);
568 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
569 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
571 else if (state & CDIS_DISABLED) {
572 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
573 OffsetRect (rcText, 1, 1);
574 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
575 SetTextColor (hdc, comctl32_color.clr3dShadow);
576 OffsetRect (rcText, -1, -1);
578 else if (state & CDIS_INDETERMINATE) {
579 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
581 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
582 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
583 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
584 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
587 clrOld = SetTextColor (hdc, tbcd->clrText);
590 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
591 SetTextColor (hdc, clrOld);
592 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
594 SetBkColor (hdc, clrOldBk);
595 SetBkMode (hdc, oldBkMode);
597 SelectObject (hdc, hOldFont);
603 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
605 HDC hdc = tbcd->nmcd.hdc;
606 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
609 INT cx = lpRect->right - lpRect->left;
610 INT cy = lpRect->bottom - lpRect->top;
611 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
612 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
613 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
614 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
615 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
616 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
617 SetBkColor(hdc, clrBkOld);
618 SetTextColor(hdc, clrTextOld);
619 SelectObject (hdc, hbr);
623 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
626 HBITMAP hbmMask, hbmImage;
627 HDC hdcMask, hdcImage;
629 ImageList_GetIconSize(himl, &cx, &cy);
631 /* Create src image */
632 hdcImage = CreateCompatibleDC(hdc);
633 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
634 SelectObject(hdcImage, hbmImage);
635 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
636 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
639 hdcMask = CreateCompatibleDC(0);
640 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
641 SelectObject(hdcMask, hbmMask);
643 /* Remove the background and all white pixels */
644 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
645 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
646 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
647 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
649 /* draw the new mask 'etched' to hdc */
650 SetBkColor(hdc, RGB(255, 255, 255));
651 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
652 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
653 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
654 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
655 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
658 DeleteObject(hbmImage);
660 DeleteObject (hbmMask);
666 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
670 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
671 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
672 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
673 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
674 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
675 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
676 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
680 /* draws the image on a toolbar button */
682 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
684 HIMAGELIST himl = NULL;
685 BOOL draw_masked = FALSE;
688 UINT draw_flags = ILD_TRANSPARENT;
690 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
692 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
695 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
699 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
700 ((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 if (GetParent(hwnd))
1283 /* this can get the parents width, to know how far we can extend
1284 * this toolbar. We cannot use its height, as there may be multiple
1285 * toolbars in a rebar control
1287 GetClientRect( GetParent(hwnd), &rc );
1288 infoPtr->nWidth = rc.right - rc.left;
1292 GetWindowRect( hwnd, &rc );
1293 infoPtr->nWidth = rc.right - rc.left;
1296 bButtonWrap = FALSE;
1298 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1299 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1302 for (i = 0; i < infoPtr->nNumButtons; i++ )
1305 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1307 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1310 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1311 /* it is the actual width of the separator. This is used for */
1312 /* custom controls in toolbars. */
1314 /* BTNS_DROPDOWN separators are treated as buttons for */
1315 /* width. - GA 8/01 */
1316 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1317 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1318 cx = (btnPtr[i].iBitmap > 0) ?
1319 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1321 cx = infoPtr->nButtonWidth;
1323 /* Two or more adjacent separators form a separator group. */
1324 /* The first separator in a group should be wrapped to the */
1325 /* next row if the previous wrapping is on a button. */
1327 (btnPtr[i].fsStyle & BTNS_SEP) &&
1328 (i + 1 < infoPtr->nNumButtons ) &&
1329 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1331 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1332 btnPtr[i].fsState |= TBSTATE_WRAP;
1333 x = infoPtr->nIndent;
1335 bButtonWrap = FALSE;
1339 /* The layout makes sure the bitmap is visible, but not the button. */
1340 /* Test added to also wrap after a button that starts a row but */
1341 /* is bigger than the area. - GA 8/01 */
1342 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1343 > infoPtr->nWidth ) ||
1344 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1346 BOOL bFound = FALSE;
1348 /* If the current button is a separator and not hidden, */
1349 /* go to the next until it reaches a non separator. */
1350 /* Wrap the last separator if it is before a button. */
1351 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1352 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1353 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1354 i < infoPtr->nNumButtons )
1360 if( bFound && i < infoPtr->nNumButtons )
1363 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1364 i, btnPtr[i].fsStyle, x, cx);
1365 btnPtr[i].fsState |= TBSTATE_WRAP;
1366 x = infoPtr->nIndent;
1367 bButtonWrap = FALSE;
1370 else if ( i >= infoPtr->nNumButtons)
1373 /* If the current button is not a separator, find the last */
1374 /* separator and wrap it. */
1375 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1377 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1378 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1382 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1383 i, btnPtr[i].fsStyle, x, cx);
1384 x = infoPtr->nIndent;
1385 btnPtr[j].fsState |= TBSTATE_WRAP;
1386 bButtonWrap = FALSE;
1391 /* If no separator available for wrapping, wrap one of */
1392 /* non-hidden previous button. */
1396 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1398 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1403 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1404 i, btnPtr[i].fsStyle, x, cx);
1405 x = infoPtr->nIndent;
1406 btnPtr[j].fsState |= TBSTATE_WRAP;
1412 /* If all above failed, wrap the current button. */
1415 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1416 i, btnPtr[i].fsStyle, x, cx);
1417 btnPtr[i].fsState |= TBSTATE_WRAP;
1419 x = infoPtr->nIndent;
1420 if (btnPtr[i].fsStyle & BTNS_SEP )
1421 bButtonWrap = FALSE;
1427 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1428 i, btnPtr[i].fsStyle, x, cx);
1435 /***********************************************************************
1436 * TOOLBAR_MeasureButton
1438 * Calculates the width and height required for a button. Used in
1439 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1440 * the width of buttons that are autosized.
1442 * Note that it would have been rather elegant to use one piece of code for
1443 * both the laying out of the toolbar and for controlling where button parts
1444 * are drawn, but the native control has inconsistencies between the two that
1445 * prevent this from being effectively. These inconsistencies can be seen as
1446 * artefacts where parts of the button appear outside of the bounding button
1449 * There are several cases for the calculation of the button dimensions and
1450 * button part positioning:
1457 * +--------------------------------------------------------+ ^
1459 * | | pad.cy / 2 | centred | |
1460 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1461 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1462 * | |<------------>| | | | |
1463 * | +--------------+ +------------+ | |
1464 * |<-------------------------------------->| | |
1465 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1467 * +--------------------------------------------------------+ -
1468 * <-------------------------------------------------------->
1469 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1471 * Without Bitmap (I_IMAGENONE):
1473 * +-----------------------------------+ ^
1475 * | | centred | | LISTPAD_CY +
1476 * | +------------+ | | szText.cy
1479 * | +------------+ | |
1480 * |<----------------->| | |
1481 * | cxedge |<-----------> | |
1483 * +-----------------------------------+ -
1484 * <----------------------------------->
1485 * szText.cx + pad.cx
1489 * +--------------------------------------+ ^
1491 * | | padding.cy/2 | | DEFPAD_CY +
1492 * | +------------+ | | nBitmapHeight
1495 * | +------------+ | |
1496 * |<------------------->| | |
1497 * | cxedge + iListGap/2 |<-----------> | |
1498 * | nBitmapWidth | |
1499 * +--------------------------------------+ -
1500 * <-------------------------------------->
1501 * 2*cxedge + nBitmapWidth + iListGap
1508 * +-----------------------------------+ ^
1510 * | | pad.cy / 2 | | nBitmapHeight +
1511 * | - | | szText.cy +
1512 * | +------------+ | | DEFPAD_CY + 1
1513 * | centred | Bitmap | | |
1514 * |<----------------->| | | |
1515 * | +------------+ | |
1519 * | centred +---------------+ | |
1520 * |<--------------->| Text | | |
1521 * | +---------------+ | |
1522 * +-----------------------------------+ -
1523 * <----------------------------------->
1524 * pad.cx + max(nBitmapWidth, szText.cx)
1526 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1528 * +---------------------------------------+ ^
1530 * | | 2 + pad.cy / 2 | |
1531 * | - | | szText.cy +
1532 * | centred +-----------------+ | | pad.cy + 2
1533 * |<--------------->| Text | | |
1534 * | +-----------------+ | |
1536 * +---------------------------------------+ -
1537 * <--------------------------------------->
1538 * 2*cxedge + pad.cx + szText.cx
1541 * As for with bitmaps, but with szText.cx zero.
1543 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1546 if (infoPtr->dwStyle & TBSTYLE_LIST)
1548 /* set button height from bitmap / text height... */
1549 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1552 /* ... add on the necessary padding */
1553 if (bValidImageList)
1556 sizeButton.cy += DEFPAD_CY;
1558 sizeButton.cy += LISTPAD_CY;
1561 sizeButton.cy += infoPtr->szPadding.cy;
1563 /* calculate button width */
1566 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1567 infoPtr->nBitmapWidth + infoPtr->iListGap;
1568 if (sizeString.cx > 0)
1569 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1572 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1578 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1579 sizeString.cy + DEFPAD_CY;
1580 sizeButton.cx = infoPtr->szPadding.cx +
1581 max(sizeString.cx, infoPtr->nBitmapWidth);
1585 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1586 NONLIST_NOTEXT_OFFSET;
1587 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1588 infoPtr->szPadding.cx + sizeString.cx;
1595 /***********************************************************************
1596 * TOOLBAR_CalcToolbar
1598 * This function calculates button and separator placement. It first
1599 * calculates the button sizes, gets the toolbar window width and then
1600 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1601 * on. It assigns a new location to each item and sends this location to
1602 * the tooltip window if appropriate. Finally, it updates the rcBound
1603 * rect and calculates the new required toolbar window height.
1606 TOOLBAR_CalcToolbar (HWND hwnd)
1608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1609 DWORD dwStyle = infoPtr->dwStyle;
1610 TBUTTON_INFO *btnPtr;
1611 INT i, nRows, nSepRows;
1613 SIZE sizeString, sizeButton;
1615 BOOL validImageList = FALSE;
1616 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1618 TOOLBAR_CalcStrings (hwnd, &sizeString);
1620 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1622 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1623 validImageList = TRUE;
1624 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1625 infoPtr->nButtonWidth = sizeButton.cx;
1626 infoPtr->nButtonHeight = sizeButton.cy;
1628 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1629 infoPtr->nButtonWidth = infoPtr->cxMin;
1630 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1631 infoPtr->nButtonWidth = infoPtr->cxMax;
1633 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1635 x = infoPtr->nIndent;
1636 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1641 /* from above, minimum is a button, and possible text */
1642 cx = infoPtr->nButtonWidth;
1643 cy = infoPtr->nButtonHeight;
1645 nRows = nSepRows = 0;
1647 infoPtr->rcBound.top = y;
1648 infoPtr->rcBound.left = x;
1649 infoPtr->rcBound.bottom = y + cy;
1650 infoPtr->rcBound.right = x;
1652 btnPtr = infoPtr->buttons;
1654 TRACE("cy=%d\n", cy);
1656 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1659 if (btnPtr->fsState & TBSTATE_HIDDEN)
1661 SetRectEmpty (&btnPtr->rect);
1665 cy = infoPtr->nButtonHeight;
1667 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1668 /* it is the actual width of the separator. This is used for */
1669 /* custom controls in toolbars. */
1670 if (btnPtr->fsStyle & BTNS_SEP) {
1671 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1672 cy = (btnPtr->iBitmap > 0) ?
1673 btnPtr->iBitmap : SEPARATOR_WIDTH;
1674 cx = infoPtr->nButtonWidth;
1677 cx = (btnPtr->iBitmap > 0) ?
1678 btnPtr->iBitmap : SEPARATOR_WIDTH;
1684 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1685 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1692 hOldFont = SelectObject (hdc, infoPtr->hFont);
1694 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1696 SelectObject (hdc, hOldFont);
1697 ReleaseDC (hwnd, hdc);
1699 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1700 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1705 cx = infoPtr->nButtonWidth;
1707 /* if size has been set manually then don't add on extra space
1708 * for the drop down arrow */
1709 if (!btnPtr->cx && hasDropDownArrows &&
1710 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1711 cx += DDARROW_WIDTH;
1713 if (btnPtr->fsState & TBSTATE_WRAP )
1716 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1718 if (infoPtr->rcBound.left > x)
1719 infoPtr->rcBound.left = x;
1720 if (infoPtr->rcBound.right < x + cx)
1721 infoPtr->rcBound.right = x + cx;
1722 if (infoPtr->rcBound.bottom < y + cy)
1723 infoPtr->rcBound.bottom = y + cy;
1725 /* Set the toolTip only for non-hidden, non-separator button */
1726 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1730 ZeroMemory (&ti, sizeof(ti));
1731 ti.cbSize = sizeof(ti);
1733 ti.uId = btnPtr->idCommand;
1734 ti.rect = btnPtr->rect;
1735 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1739 /* btnPtr->nRow is zero based. The space between the rows is */
1740 /* also considered as a row. */
1741 btnPtr->nRow = nRows + nSepRows;
1743 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1744 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1749 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1753 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1754 /* it is the actual width of the separator. This is used for */
1755 /* custom controls in toolbars. */
1756 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1757 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1758 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1762 /* nSepRows is used to calculate the extra height follwoing */
1766 x = infoPtr->nIndent;
1768 /* Increment row number unless this is the last button */
1769 /* and it has Wrap set. */
1770 if (i != infoPtr->nNumButtons-1)
1777 /* infoPtr->nRows is the number of rows on the toolbar */
1778 infoPtr->nRows = nRows + nSepRows + 1;
1780 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1785 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1788 TBUTTON_INFO *btnPtr;
1791 btnPtr = infoPtr->buttons;
1792 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1793 if (btnPtr->fsState & TBSTATE_HIDDEN)
1796 if (btnPtr->fsStyle & BTNS_SEP) {
1797 if (PtInRect (&btnPtr->rect, *lpPt)) {
1798 TRACE(" ON SEPARATOR %d!\n", i);
1803 if (PtInRect (&btnPtr->rect, *lpPt)) {
1804 TRACE(" ON BUTTON %d!\n", i);
1810 TRACE(" NOWHERE!\n");
1811 return TOOLBAR_NOWHERE;
1816 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1818 TBUTTON_INFO *btnPtr;
1821 if (CommandIsIndex) {
1822 TRACE("command is really index command=%d\n", idCommand);
1823 if (idCommand >= infoPtr->nNumButtons) return -1;
1826 btnPtr = infoPtr->buttons;
1827 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1828 if (btnPtr->idCommand == idCommand) {
1829 TRACE("command=%d index=%d\n", idCommand, i);
1833 TRACE("no index found for command=%d\n", idCommand);
1839 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1841 TBUTTON_INFO *btnPtr;
1844 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1847 /* check index button */
1848 btnPtr = &infoPtr->buttons[nIndex];
1849 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1850 if (btnPtr->fsState & TBSTATE_CHECKED)
1854 /* check previous buttons */
1855 nRunIndex = nIndex - 1;
1856 while (nRunIndex >= 0) {
1857 btnPtr = &infoPtr->buttons[nRunIndex];
1858 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1859 if (btnPtr->fsState & TBSTATE_CHECKED)
1867 /* check next buttons */
1868 nRunIndex = nIndex + 1;
1869 while (nRunIndex < infoPtr->nNumButtons) {
1870 btnPtr = &infoPtr->buttons[nRunIndex];
1871 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1872 if (btnPtr->fsState & TBSTATE_CHECKED)
1885 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1886 WPARAM wParam, LPARAM lParam)
1892 msg.wParam = wParam;
1893 msg.lParam = lParam;
1894 msg.time = GetMessageTime ();
1895 msg.pt.x = LOWORD(GetMessagePos ());
1896 msg.pt.y = HIWORD(GetMessagePos ());
1898 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1901 /* keeps available button list box sorted by button id */
1902 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1906 PCUSTOMBUTTON btnInfo;
1907 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1909 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1911 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1913 /* position 0 is always separator */
1914 for (i = 1; i < count; i++)
1916 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1917 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1919 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1920 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1924 /* id higher than all others add to end */
1925 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1926 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1929 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1933 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1935 if (nIndexFrom == nIndexTo)
1938 /* MSDN states that iItem is the index of the button, rather than the
1939 * command ID as used by every other NMTOOLBAR notification */
1940 nmtb.iItem = nIndexFrom;
1941 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1943 PCUSTOMBUTTON btnInfo;
1945 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1946 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1948 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1950 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1951 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1952 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1953 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1956 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1958 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1960 /* last item is always separator, so -2 instead of -1 */
1961 if (nIndexTo >= (count - 2))
1962 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1964 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1966 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1967 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1969 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1973 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1977 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1979 /* MSDN states that iItem is the index of the button, rather than the
1980 * command ID as used by every other NMTOOLBAR notification */
1981 nmtb.iItem = nIndexAvail;
1982 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1984 PCUSTOMBUTTON btnInfo;
1986 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1987 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1988 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1990 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1992 if (nIndexAvail != 0) /* index == 0 indicates separator */
1994 /* remove from 'available buttons' list */
1995 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1996 if (nIndexAvail == count-1)
1997 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1999 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2003 PCUSTOMBUTTON btnNew;
2005 /* duplicate 'separator' button */
2006 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2007 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2011 /* insert into 'toolbar button' list */
2012 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2013 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2015 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2017 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2021 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2023 PCUSTOMBUTTON btnInfo;
2024 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2026 TRACE("Remove: index %d\n", index);
2028 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2030 /* send TBN_QUERYDELETE notification */
2031 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2035 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2036 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2038 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2040 /* insert into 'available button' list */
2041 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2042 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2046 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2050 /* drag list notification function for toolbar buttons list box */
2051 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2053 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2054 switch (pDLI->uNotification)
2058 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2059 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2060 /* no dragging for last item (separator) */
2061 if (nCurrentItem >= (nCount - 1)) return FALSE;
2066 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2067 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2068 /* no dragging past last item (separator) */
2069 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2071 DrawInsert(hwnd, hwndList, nCurrentItem);
2072 /* FIXME: native uses "move button" cursor */
2073 return DL_COPYCURSOR;
2076 /* not over toolbar buttons list */
2077 if (nCurrentItem < 0)
2079 POINT ptWindow = pDLI->ptCursor;
2080 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2081 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2082 /* over available buttons list? */
2083 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2084 /* FIXME: native uses "move button" cursor */
2085 return DL_COPYCURSOR;
2087 /* clear drag arrow */
2088 DrawInsert(hwnd, hwndList, -1);
2089 return DL_STOPCURSOR;
2093 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2094 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2095 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2096 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2098 /* clear drag arrow */
2099 DrawInsert(hwnd, hwndList, -1);
2101 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2103 /* not over toolbar buttons list */
2106 POINT ptWindow = pDLI->ptCursor;
2107 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2108 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2109 /* over available buttons list? */
2110 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2111 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2116 /* Clear drag arrow */
2117 DrawInsert(hwnd, hwndList, -1);
2124 /* drag list notification function for available buttons list box */
2125 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2127 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2128 switch (pDLI->uNotification)
2134 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2135 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2136 /* no dragging past last item (separator) */
2137 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2139 DrawInsert(hwnd, hwndList, nCurrentItem);
2140 /* FIXME: native uses "move button" cursor */
2141 return DL_COPYCURSOR;
2144 /* not over toolbar buttons list */
2145 if (nCurrentItem < 0)
2147 POINT ptWindow = pDLI->ptCursor;
2148 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2149 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2150 /* over available buttons list? */
2151 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2152 /* FIXME: native uses "move button" cursor */
2153 return DL_COPYCURSOR;
2155 /* clear drag arrow */
2156 DrawInsert(hwnd, hwndList, -1);
2157 return DL_STOPCURSOR;
2161 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2162 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2163 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2164 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2166 /* clear drag arrow */
2167 DrawInsert(hwnd, hwndList, -1);
2169 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2173 /* Clear drag arrow */
2174 DrawInsert(hwnd, hwndList, -1);
2180 extern UINT uDragListMessage;
2182 /***********************************************************************
2183 * TOOLBAR_CustomizeDialogProc
2184 * This function implements the toolbar customization dialog.
2186 static INT_PTR CALLBACK
2187 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2189 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2190 PCUSTOMBUTTON btnInfo;
2192 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2197 custInfo = (PCUSTDLG_INFO)lParam;
2198 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2205 NMTBINITCUSTOMIZE nmtbic;
2207 infoPtr = custInfo->tbInfo;
2209 /* send TBN_QUERYINSERT notification */
2210 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2212 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2215 nmtbic.hwndDialog = hwnd;
2216 /* Send TBN_INITCUSTOMIZE notification */
2217 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2220 TRACE("TBNRF_HIDEHELP requested\n");
2221 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2224 /* add items to 'toolbar buttons' list and check if removable */
2225 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2227 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2228 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2229 btnInfo->btn.fsStyle = BTNS_SEP;
2230 btnInfo->bVirtual = FALSE;
2231 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2233 /* send TBN_QUERYDELETE notification */
2234 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2236 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2237 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2240 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2242 /* insert separator button into 'available buttons' list */
2243 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2244 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2245 btnInfo->btn.fsStyle = BTNS_SEP;
2246 btnInfo->bVirtual = FALSE;
2247 btnInfo->bRemovable = TRUE;
2248 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2249 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2250 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2252 /* insert all buttons into dsa */
2255 /* send TBN_GETBUTTONINFO notification */
2258 nmtb.pszText = Buffer;
2261 /* Clear previous button's text */
2262 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2264 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2267 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2268 nmtb.tbButton.fsStyle, i,
2269 nmtb.tbButton.idCommand,
2270 nmtb.tbButton.iString,
2271 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2274 /* insert button into the apropriate list */
2275 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2278 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2279 btnInfo->bVirtual = FALSE;
2280 btnInfo->bRemovable = TRUE;
2284 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2285 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2288 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2289 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2291 if (lstrlenW(nmtb.pszText))
2292 lstrcpyW(btnInfo->text, nmtb.pszText);
2293 else if (nmtb.tbButton.iString >= 0 &&
2294 nmtb.tbButton.iString < infoPtr->nNumStrings)
2296 lstrcpyW(btnInfo->text,
2297 infoPtr->strings[nmtb.tbButton.iString]);
2302 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2305 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2307 /* select first item in the 'available' list */
2308 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2310 /* append 'virtual' separator button to the 'toolbar buttons' list */
2311 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2312 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2313 btnInfo->btn.fsStyle = BTNS_SEP;
2314 btnInfo->bVirtual = TRUE;
2315 btnInfo->bRemovable = FALSE;
2316 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2317 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2318 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2320 /* select last item in the 'toolbar' list */
2321 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2324 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2325 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2327 /* set focus and disable buttons */
2328 PostMessageW (hwnd, WM_USER, 0, 0);
2333 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2334 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2335 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2336 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2340 EndDialog(hwnd, FALSE);
2344 switch (LOWORD(wParam))
2346 case IDC_TOOLBARBTN_LBOX:
2347 if (HIWORD(wParam) == LBN_SELCHANGE)
2349 PCUSTOMBUTTON btnInfo;
2354 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2355 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2357 /* send TBN_QUERYINSERT notification */
2359 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2361 /* get list box item */
2362 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2364 if (index == (count - 1))
2366 /* last item (virtual separator) */
2367 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2368 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2370 else if (index == (count - 2))
2372 /* second last item (last non-virtual item) */
2373 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2374 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2376 else if (index == 0)
2379 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2380 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2384 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2385 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2388 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2392 case IDC_MOVEUP_BTN:
2394 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2395 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2399 case IDC_MOVEDN_BTN: /* move down */
2401 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2402 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2406 case IDC_REMOVE_BTN: /* remove button */
2408 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2410 if (LB_ERR == index)
2413 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2417 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2420 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2423 case IDOK: /* Add button */
2428 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2429 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2431 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2436 EndDialog(hwnd, FALSE);
2446 /* delete items from 'toolbar buttons' listbox*/
2447 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2448 for (i = 0; i < count; i++)
2450 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2452 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2454 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2457 /* delete items from 'available buttons' listbox*/
2458 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2459 for (i = 0; i < count; i++)
2461 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2463 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2465 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2470 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2472 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2477 COLORREF oldText = 0;
2481 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2482 if (btnInfo == NULL)
2484 FIXME("btnInfo invalid!\n");
2488 /* set colors and select objects */
2489 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2490 if (btnInfo->bVirtual)
2491 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2493 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2494 hPen = CreatePen( PS_SOLID, 1,
2495 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2496 hOldPen = SelectObject (lpdis->hDC, hPen );
2497 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2499 /* fill background rectangle */
2500 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2501 lpdis->rcItem.right, lpdis->rcItem.bottom);
2503 /* calculate button and text rectangles */
2504 CopyRect (&rcButton, &lpdis->rcItem);
2505 InflateRect (&rcButton, -1, -1);
2506 CopyRect (&rcText, &rcButton);
2507 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2508 rcText.left = rcButton.right + 2;
2510 /* draw focus rectangle */
2511 if (lpdis->itemState & ODS_FOCUS)
2512 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2515 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2516 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2518 /* draw image and text */
2519 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2520 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2521 btnInfo->btn.iBitmap));
2522 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2523 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2525 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2526 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2528 /* delete objects and reset colors */
2529 SelectObject (lpdis->hDC, hOldBrush);
2530 SelectObject (lpdis->hDC, hOldPen);
2531 SetBkColor (lpdis->hDC, oldBk);
2532 SetTextColor (lpdis->hDC, oldText);
2533 DeleteObject( hPen );
2538 case WM_MEASUREITEM:
2539 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2541 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2543 lpmis->itemHeight = 15 + 8; /* default height */
2550 if (uDragListMessage && (uMsg == uDragListMessage))
2552 if (wParam == IDC_TOOLBARBTN_LBOX)
2554 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2555 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2556 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2559 else if (wParam == IDC_AVAILBTN_LBOX)
2561 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2562 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2563 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2572 /***********************************************************************
2573 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2577 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2579 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2580 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2581 INT nIndex = 0, nButtons, nCount;
2585 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2589 if (lpAddBmp->hInst == HINST_COMMCTRL)
2591 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2593 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2595 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2600 TRACE ("adding %d internal bitmaps!\n", nButtons);
2602 /* Windows resize all the buttons to the size of a newly added standard image */
2603 if (lpAddBmp->nID & 1)
2606 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2607 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2609 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2610 MAKELPARAM((WORD)24, (WORD)24));
2611 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2612 MAKELPARAM((WORD)31, (WORD)30));
2617 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2618 MAKELPARAM((WORD)16, (WORD)16));
2619 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2620 MAKELPARAM((WORD)22, (WORD)22));
2623 TOOLBAR_CalcToolbar (hwnd);
2627 nButtons = (INT)wParam;
2631 TRACE ("adding %d bitmaps!\n", nButtons);
2634 if (!infoPtr->cimlDef) {
2635 /* create new default image list */
2636 TRACE ("creating default image list!\n");
2638 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2639 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2640 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2641 infoPtr->himlInt = himlDef;
2644 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2648 WARN("No default image list available\n");
2652 nCount = ImageList_GetImageCount(himlDef);
2654 /* Add bitmaps to the default image list */
2655 if (lpAddBmp->hInst == NULL)
2658 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2659 HDC hdcImage, hdcBitmap;
2661 /* copy the bitmap before adding it so that the user's bitmap
2662 * doesn't get modified.
2664 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2666 hdcImage = CreateCompatibleDC(0);
2667 hdcBitmap = CreateCompatibleDC(0);
2669 /* create new bitmap */
2670 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2671 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2672 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2674 /* Copy the user's image */
2675 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2676 hdcBitmap, 0, 0, SRCCOPY);
2678 SelectObject (hdcImage, hOldBitmapLoad);
2679 SelectObject (hdcBitmap, hOldBitmapBitmap);
2680 DeleteDC (hdcImage);
2681 DeleteDC (hdcBitmap);
2683 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2684 DeleteObject (hbmLoad);
2686 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2688 /* Add system bitmaps */
2689 switch (lpAddBmp->nID)
2691 case IDB_STD_SMALL_COLOR:
2692 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2693 IDB_STD_SMALL, 0, NULL, 0);
2694 nIndex = ImageList_AddMasked (himlDef,
2695 hbmLoad, comctl32_color.clrBtnFace);
2696 DeleteObject (hbmLoad);
2699 case IDB_STD_LARGE_COLOR:
2700 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2701 IDB_STD_LARGE, 0, NULL, 0);
2702 nIndex = ImageList_AddMasked (himlDef,
2703 hbmLoad, comctl32_color.clrBtnFace);
2704 DeleteObject (hbmLoad);
2707 case IDB_VIEW_SMALL_COLOR:
2708 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2709 IDB_VIEW_SMALL, 0, NULL, 0);
2710 nIndex = ImageList_AddMasked (himlDef,
2711 hbmLoad, comctl32_color.clrBtnFace);
2712 DeleteObject (hbmLoad);
2715 case IDB_VIEW_LARGE_COLOR:
2716 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2717 IDB_VIEW_LARGE, 0, NULL, 0);
2718 nIndex = ImageList_AddMasked (himlDef,
2719 hbmLoad, comctl32_color.clrBtnFace);
2720 DeleteObject (hbmLoad);
2723 case IDB_HIST_SMALL_COLOR:
2724 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2725 IDB_HIST_SMALL, 0, NULL, 0);
2726 nIndex = ImageList_AddMasked (himlDef,
2727 hbmLoad, comctl32_color.clrBtnFace);
2728 DeleteObject (hbmLoad);
2731 case IDB_HIST_LARGE_COLOR:
2732 hbmLoad = CreateMappedBitmap (COMCTL32_hModule,
2733 IDB_HIST_LARGE, 0, NULL, 0);
2734 nIndex = ImageList_AddMasked (himlDef,
2735 hbmLoad, comctl32_color.clrBtnFace);
2736 DeleteObject (hbmLoad);
2740 nIndex = ImageList_GetImageCount (himlDef);
2741 ERR ("invalid imagelist!\n");
2747 hbmLoad = CreateMappedBitmap(lpAddBmp->hInst, lpAddBmp->nID, 0, NULL, 0);
2748 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2749 DeleteObject (hbmLoad);
2752 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2754 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2755 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2756 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2757 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2759 infoPtr->nNumBitmapInfos++;
2760 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2764 INT imagecount = ImageList_GetImageCount(himlDef);
2766 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2768 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",
2769 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2770 infoPtr->nNumBitmaps+nButtons,imagecount);
2772 infoPtr->nNumBitmaps = imagecount;
2775 infoPtr->nNumBitmaps += nButtons;
2778 InvalidateRect(hwnd, NULL, TRUE);
2785 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2788 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2789 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2791 TRACE("adding %d buttons!\n", wParam);
2793 nAddButtons = (UINT)wParam;
2794 nOldButtons = infoPtr->nNumButtons;
2795 nNewButtons = nOldButtons + nAddButtons;
2797 if (infoPtr->nNumButtons == 0) {
2799 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2802 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2804 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2805 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2806 nOldButtons * sizeof(TBUTTON_INFO));
2810 infoPtr->nNumButtons = nNewButtons;
2812 /* insert new button data */
2813 for (nCount = 0; nCount < nAddButtons; nCount++) {
2814 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2815 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2816 btnPtr->idCommand = lpTbb[nCount].idCommand;
2817 btnPtr->fsState = lpTbb[nCount].fsState;
2818 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2819 btnPtr->dwData = lpTbb[nCount].dwData;
2820 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2821 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2823 btnPtr->iString = lpTbb[nCount].iString;
2824 btnPtr->bHot = FALSE;
2826 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2829 ZeroMemory (&ti, sizeof(ti));
2830 ti.cbSize = sizeof(ti);
2832 ti.uId = btnPtr->idCommand;
2834 ti.lpszText = LPSTR_TEXTCALLBACKW;
2836 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2841 TOOLBAR_CalcToolbar (hwnd);
2842 TOOLBAR_AutoSize (hwnd);
2844 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2846 InvalidateRect(hwnd, NULL, TRUE);
2853 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2855 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2856 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2857 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2859 TRACE("adding %d buttons!\n", wParam);
2861 nAddButtons = (UINT)wParam;
2862 nOldButtons = infoPtr->nNumButtons;
2863 nNewButtons = nOldButtons + nAddButtons;
2865 if (infoPtr->nNumButtons == 0) {
2867 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2870 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2872 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2873 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2874 nOldButtons * sizeof(TBUTTON_INFO));
2878 infoPtr->nNumButtons = nNewButtons;
2880 /* insert new button data */
2881 for (nCount = 0; nCount < nAddButtons; nCount++) {
2882 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2883 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2884 btnPtr->idCommand = lpTbb[nCount].idCommand;
2885 btnPtr->fsState = lpTbb[nCount].fsState;
2886 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2887 btnPtr->dwData = lpTbb[nCount].dwData;
2888 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2889 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2891 btnPtr->iString = lpTbb[nCount].iString;
2892 btnPtr->bHot = FALSE;
2894 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2897 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2898 ti.cbSize = sizeof (TTTOOLINFOW);
2900 ti.uId = btnPtr->idCommand;
2902 ti.lpszText = LPSTR_TEXTCALLBACKW;
2905 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2910 TOOLBAR_CalcToolbar (hwnd);
2911 TOOLBAR_AutoSize (hwnd);
2913 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2915 InvalidateRect(hwnd, NULL, TRUE);
2922 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2927 if ((wParam) && (HIWORD(lParam) == 0)) {
2930 TRACE("adding string from resource!\n");
2932 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2934 TRACE("len=%d \"%s\"\n", len, szString);
2935 nIndex = infoPtr->nNumStrings;
2936 if (infoPtr->nNumStrings == 0) {
2938 Alloc (sizeof(LPWSTR));
2941 LPWSTR *oldStrings = infoPtr->strings;
2943 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2944 memcpy (&infoPtr->strings[0], &oldStrings[0],
2945 sizeof(LPWSTR) * infoPtr->nNumStrings);
2949 /*Alloc zeros out the allocated memory*/
2950 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2951 infoPtr->nNumStrings++;
2954 LPSTR p = (LPSTR)lParam;
2959 TRACE("adding string(s) from array!\n");
2961 nIndex = infoPtr->nNumStrings;
2964 TRACE("len=%d \"%s\"\n", len, p);
2966 if (infoPtr->nNumStrings == 0) {
2968 Alloc (sizeof(LPWSTR));
2971 LPWSTR *oldStrings = infoPtr->strings;
2973 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2974 memcpy (&infoPtr->strings[0], &oldStrings[0],
2975 sizeof(LPWSTR) * infoPtr->nNumStrings);
2979 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2980 infoPtr->nNumStrings++;
2991 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2993 #define MAX_RESOURCE_STRING_LENGTH 512
2994 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2997 if ((wParam) && (HIWORD(lParam) == 0)) {
2998 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3000 TRACE("adding string from resource!\n");
3002 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
3003 szString, MAX_RESOURCE_STRING_LENGTH);
3005 TRACE("len=%d %s\n", len, debugstr_w(szString));
3006 TRACE("First char: 0x%x\n", *szString);
3007 if (szString[0] == L'|')
3009 PWSTR p = szString + 1;
3011 nIndex = infoPtr->nNumStrings;
3012 while (*p != L'|' && *p != L'\0') {
3015 if (infoPtr->nNumStrings == 0) {
3016 infoPtr->strings = Alloc (sizeof(LPWSTR));
3020 LPWSTR *oldStrings = infoPtr->strings;
3021 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3022 memcpy(&infoPtr->strings[0], &oldStrings[0],
3023 sizeof(LPWSTR) * infoPtr->nNumStrings);
3027 np=strchrW (p, '|');
3035 TRACE("len=%d %s\n", len, debugstr_w(p));
3036 infoPtr->strings[infoPtr->nNumStrings] =
3037 Alloc (sizeof(WCHAR)*(len+1));
3038 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3039 infoPtr->nNumStrings++;
3046 nIndex = infoPtr->nNumStrings;
3047 if (infoPtr->nNumStrings == 0) {
3049 Alloc (sizeof(LPWSTR));
3052 LPWSTR *oldStrings = infoPtr->strings;
3054 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3055 memcpy (&infoPtr->strings[0], &oldStrings[0],
3056 sizeof(LPWSTR) * infoPtr->nNumStrings);
3060 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3061 infoPtr->nNumStrings++;
3065 LPWSTR p = (LPWSTR)lParam;
3070 TRACE("adding string(s) from array!\n");
3071 nIndex = infoPtr->nNumStrings;
3075 TRACE("len=%d %s\n", len, debugstr_w(p));
3076 if (infoPtr->nNumStrings == 0) {
3078 Alloc (sizeof(LPWSTR));
3081 LPWSTR *oldStrings = infoPtr->strings;
3083 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3084 memcpy (&infoPtr->strings[0], &oldStrings[0],
3085 sizeof(LPWSTR) * infoPtr->nNumStrings);
3089 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3090 infoPtr->nNumStrings++;
3101 TOOLBAR_AutoSize (HWND hwnd)
3103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3109 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3111 parent = GetParent (hwnd);
3113 if (!parent || !infoPtr->bDoRedraw)
3116 GetClientRect(parent, &parent_rect);
3118 x = parent_rect.left;
3119 y = parent_rect.top;
3121 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3123 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3124 cx = parent_rect.right - parent_rect.left;
3126 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3128 TOOLBAR_CalcToolbar(hwnd);
3129 InvalidateRect( hwnd, NULL, TRUE );
3132 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3135 UINT uPosFlags = SWP_NOZORDER;
3137 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3139 GetWindowRect(hwnd, &window_rect);
3140 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3141 y = window_rect.top;
3143 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3145 GetWindowRect(hwnd, &window_rect);
3146 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3149 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3150 uPosFlags |= SWP_NOMOVE;
3152 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3153 cy += GetSystemMetrics(SM_CYEDGE);
3155 if (infoPtr->dwStyle & WS_BORDER)
3157 x = y = 1; /* FIXME: this looks wrong */
3158 cy += GetSystemMetrics(SM_CYEDGE);
3159 cx += GetSystemMetrics(SM_CXEDGE);
3162 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3170 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3174 return infoPtr->nNumButtons;
3179 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3181 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3183 infoPtr->dwStructSize = (DWORD)wParam;
3190 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3192 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3193 TBUTTON_INFO *btnPtr;
3196 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3198 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3202 btnPtr = &infoPtr->buttons[nIndex];
3203 btnPtr->iBitmap = LOWORD(lParam);
3205 /* we HAVE to erase the background, the new bitmap could be */
3207 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3214 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3216 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3217 TBUTTON_INFO *btnPtr;
3220 BOOL bChecked = FALSE;
3222 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3224 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3229 btnPtr = &infoPtr->buttons[nIndex];
3231 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3233 if (LOWORD(lParam) == FALSE)
3234 btnPtr->fsState &= ~TBSTATE_CHECKED;
3236 if (btnPtr->fsStyle & BTNS_GROUP) {
3238 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3239 if (nOldIndex == nIndex)
3241 if (nOldIndex != -1)
3242 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3244 btnPtr->fsState |= TBSTATE_CHECKED;
3247 if( bChecked != LOWORD(lParam) )
3249 if (nOldIndex != -1)
3250 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3251 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3254 /* FIXME: Send a WM_NOTIFY?? */
3261 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3270 TOOLBAR_Customize (HWND hwnd)
3272 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3273 CUSTDLG_INFO custInfo;
3279 custInfo.tbInfo = infoPtr;
3280 custInfo.tbHwnd = hwnd;
3282 /* send TBN_BEGINADJUST notification */
3283 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3285 if (!(hRes = FindResourceW (COMCTL32_hModule,
3286 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3287 (LPWSTR)RT_DIALOG)))
3290 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3293 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3294 (LPCDLGTEMPLATEW)template,
3296 TOOLBAR_CustomizeDialogProc,
3299 /* send TBN_ENDADJUST notification */
3300 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3307 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3310 INT nIndex = (INT)wParam;
3312 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3314 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3317 memset(&nmtb, 0, sizeof(nmtb));
3318 nmtb.iItem = btnPtr->idCommand;
3319 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3320 nmtb.tbButton.idCommand = btnPtr->idCommand;
3321 nmtb.tbButton.fsState = btnPtr->fsState;
3322 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3323 nmtb.tbButton.dwData = btnPtr->dwData;
3324 nmtb.tbButton.iString = btnPtr->iString;
3325 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3327 if ((infoPtr->hwndToolTip) &&
3328 !(btnPtr->fsStyle & BTNS_SEP)) {
3331 ZeroMemory (&ti, sizeof(ti));
3332 ti.cbSize = sizeof(ti);
3334 ti.uId = infoPtr->buttons[nIndex].idCommand;
3336 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3339 if (infoPtr->nNumButtons == 1) {
3340 TRACE(" simple delete!\n");
3341 Free (infoPtr->buttons);
3342 infoPtr->buttons = NULL;
3343 infoPtr->nNumButtons = 0;
3346 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3347 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3349 infoPtr->nNumButtons--;
3350 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3352 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3353 nIndex * sizeof(TBUTTON_INFO));
3356 if (nIndex < infoPtr->nNumButtons) {
3357 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3358 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3364 TOOLBAR_CalcToolbar (hwnd);
3366 InvalidateRect (hwnd, NULL, TRUE);
3373 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3376 TBUTTON_INFO *btnPtr;
3380 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3382 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3387 btnPtr = &infoPtr->buttons[nIndex];
3389 bState = btnPtr->fsState & TBSTATE_ENABLED;
3391 /* update the toolbar button state */
3392 if(LOWORD(lParam) == FALSE) {
3393 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3395 btnPtr->fsState |= TBSTATE_ENABLED;
3398 /* redraw the button only if the state of the button changed */
3399 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3400 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3406 static inline LRESULT
3407 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3411 return infoPtr->bAnchor;
3416 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3421 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3425 return infoPtr->buttons[nIndex].iBitmap;
3429 static inline LRESULT
3430 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3432 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3437 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3440 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3441 INT nIndex = (INT)wParam;
3442 TBUTTON_INFO *btnPtr;
3447 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3450 btnPtr = &infoPtr->buttons[nIndex];
3451 lpTbb->iBitmap = btnPtr->iBitmap;
3452 lpTbb->idCommand = btnPtr->idCommand;
3453 lpTbb->fsState = btnPtr->fsState;
3454 lpTbb->fsStyle = btnPtr->fsStyle;
3455 lpTbb->bReserved[0] = 0;
3456 lpTbb->bReserved[1] = 0;
3457 lpTbb->dwData = btnPtr->dwData;
3458 lpTbb->iString = btnPtr->iString;
3465 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3468 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3469 TBUTTON_INFO *btnPtr;
3472 if (lpTbInfo == NULL)
3474 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3477 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3478 lpTbInfo->dwMask & 0x80000000);
3482 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3484 if (lpTbInfo->dwMask & TBIF_COMMAND)
3485 lpTbInfo->idCommand = btnPtr->idCommand;
3486 if (lpTbInfo->dwMask & TBIF_IMAGE)
3487 lpTbInfo->iImage = btnPtr->iBitmap;
3488 if (lpTbInfo->dwMask & TBIF_LPARAM)
3489 lpTbInfo->lParam = btnPtr->dwData;
3490 if (lpTbInfo->dwMask & TBIF_SIZE)
3491 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3492 if (lpTbInfo->dwMask & TBIF_STATE)
3493 lpTbInfo->fsState = btnPtr->fsState;
3494 if (lpTbInfo->dwMask & TBIF_STYLE)
3495 lpTbInfo->fsStyle = btnPtr->fsStyle;
3496 if (lpTbInfo->dwMask & TBIF_TEXT) {
3497 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3498 can't use TOOLBAR_GetText here */
3500 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3501 lpText = (LPWSTR)btnPtr->iString;
3502 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3504 lpTbInfo->pszText[0] = '\0';
3511 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3514 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3515 TBUTTON_INFO *btnPtr;
3518 if (lpTbInfo == NULL)
3520 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3523 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3524 lpTbInfo->dwMask & 0x80000000);
3528 btnPtr = &infoPtr->buttons[nIndex];
3533 if (lpTbInfo->dwMask & TBIF_COMMAND)
3534 lpTbInfo->idCommand = btnPtr->idCommand;
3535 if (lpTbInfo->dwMask & TBIF_IMAGE)
3536 lpTbInfo->iImage = btnPtr->iBitmap;
3537 if (lpTbInfo->dwMask & TBIF_LPARAM)
3538 lpTbInfo->lParam = btnPtr->dwData;
3539 if (lpTbInfo->dwMask & TBIF_SIZE)
3540 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3541 if (lpTbInfo->dwMask & TBIF_STATE)
3542 lpTbInfo->fsState = btnPtr->fsState;
3543 if (lpTbInfo->dwMask & TBIF_STYLE)
3544 lpTbInfo->fsStyle = btnPtr->fsStyle;
3545 if (lpTbInfo->dwMask & TBIF_TEXT) {
3546 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3547 can't use TOOLBAR_GetText here */
3549 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3550 lpText = (LPWSTR)btnPtr->iString;
3551 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3553 lpTbInfo->pszText[0] = '\0';
3561 TOOLBAR_GetButtonSize (HWND hwnd)
3563 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3565 if (infoPtr->nNumButtons > 0)
3566 return MAKELONG((WORD)infoPtr->nButtonWidth,
3567 (WORD)infoPtr->nButtonHeight);
3569 return MAKELONG(23,22);
3574 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3576 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3583 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3587 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3589 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3590 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3595 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3602 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3606 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3610 ret = strlenW (lpText);
3613 strcpyW ((LPWSTR)lParam, lpText);
3621 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3623 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3624 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3625 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3629 inline static LRESULT
3630 TOOLBAR_GetExtendedStyle (HWND hwnd)
3632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3636 return infoPtr->dwExStyle;
3641 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3643 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3644 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3645 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3650 TOOLBAR_GetHotItem (HWND hwnd)
3652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3654 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3657 if (infoPtr->nHotItem < 0)
3660 return (LRESULT)infoPtr->nHotItem;
3665 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3667 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3668 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3669 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3674 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3676 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3677 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3679 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3681 *lptbim = infoPtr->tbim;
3688 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3692 TRACE("hwnd = %p\n", hwnd);
3694 return (LRESULT)infoPtr->clrInsertMark;
3699 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3702 TBUTTON_INFO *btnPtr;
3706 nIndex = (INT)wParam;
3707 btnPtr = &infoPtr->buttons[nIndex];
3708 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3710 lpRect = (LPRECT)lParam;
3713 if (btnPtr->fsState & TBSTATE_HIDDEN)
3716 lpRect->left = btnPtr->rect.left;
3717 lpRect->right = btnPtr->rect.right;
3718 lpRect->bottom = btnPtr->rect.bottom;
3719 lpRect->top = btnPtr->rect.top;
3726 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 LPSIZE lpSize = (LPSIZE)lParam;
3734 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3735 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3737 TRACE("maximum size %ld x %ld\n",
3738 infoPtr->rcBound.right - infoPtr->rcBound.left,
3739 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3745 /* << TOOLBAR_GetObject >> */
3749 TOOLBAR_GetPadding (HWND hwnd)
3751 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3754 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3755 return (LRESULT) oldPad;
3760 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3762 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3763 TBUTTON_INFO *btnPtr;
3767 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3768 btnPtr = &infoPtr->buttons[nIndex];
3769 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3771 lpRect = (LPRECT)lParam;
3775 lpRect->left = btnPtr->rect.left;
3776 lpRect->right = btnPtr->rect.right;
3777 lpRect->bottom = btnPtr->rect.bottom;
3778 lpRect->top = btnPtr->rect.top;
3785 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3789 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3790 return infoPtr->nRows;
3797 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3802 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3806 return infoPtr->buttons[nIndex].fsState;
3811 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3813 return GetWindowLongW(hwnd, GWL_STYLE);
3818 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3820 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3822 return infoPtr->nMaxTextRows;
3827 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3831 return (LRESULT)infoPtr->hwndToolTip;
3836 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 TRACE("%s hwnd=%p\n",
3841 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3843 return infoPtr->bUnicode;
3847 inline static LRESULT
3848 TOOLBAR_GetVersion (HWND hwnd)
3850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3851 return infoPtr->iVersion;
3856 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3859 TBUTTON_INFO *btnPtr;
3864 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3868 btnPtr = &infoPtr->buttons[nIndex];
3869 if (LOWORD(lParam) == FALSE)
3870 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3872 btnPtr->fsState |= TBSTATE_HIDDEN;
3874 TOOLBAR_CalcToolbar (hwnd);
3876 InvalidateRect (hwnd, NULL, TRUE);
3882 inline static LRESULT
3883 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3885 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3890 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3892 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3893 TBUTTON_INFO *btnPtr;
3897 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3901 btnPtr = &infoPtr->buttons[nIndex];
3902 oldState = btnPtr->fsState;
3903 if (LOWORD(lParam) == FALSE)
3904 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3906 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3908 if(oldState != btnPtr->fsState)
3909 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3916 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3919 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3920 INT nIndex = (INT)wParam;
3921 TBUTTON_INFO *oldButtons;
3926 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3929 /* EPP: this seems to be an undocumented call (from my IE4)
3930 * I assume in that case that:
3931 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3932 * - index of insertion is at the end of existing buttons
3933 * I only see this happen with nIndex == -1, but it could have a special
3934 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3936 nIndex = infoPtr->nNumButtons;
3938 } else if (nIndex < 0)
3941 /* If the string passed is not an index, assume address of string
3942 and do our own AddString */
3943 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3947 TRACE("string %s passed instead of index, adding string\n",
3948 debugstr_a((LPSTR)lpTbb->iString));
3949 len = strlen((LPSTR)lpTbb->iString) + 2;
3951 strcpy(ptr, (LPSTR)lpTbb->iString);
3952 ptr[len - 1] = 0; /* ended by two '\0' */
3953 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3957 TRACE("inserting button index=%d\n", nIndex);
3958 if (nIndex > infoPtr->nNumButtons) {
3959 nIndex = infoPtr->nNumButtons;
3960 TRACE("adjust index=%d\n", nIndex);
3963 oldButtons = infoPtr->buttons;
3964 infoPtr->nNumButtons++;
3965 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3966 /* pre insert copy */
3968 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3969 nIndex * sizeof(TBUTTON_INFO));
3972 /* insert new button */
3973 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3974 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3975 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3976 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3977 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3978 /* if passed string and not index, then add string */
3979 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3980 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3983 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3985 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3988 ZeroMemory (&ti, sizeof(ti));
3989 ti.cbSize = sizeof (ti);
3991 ti.uId = lpTbb->idCommand;
3993 ti.lpszText = LPSTR_TEXTCALLBACKW;
3995 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3999 /* post insert copy */
4000 if (nIndex < infoPtr->nNumButtons - 1) {
4001 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4002 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4007 TOOLBAR_CalcToolbar (hwnd);
4008 TOOLBAR_AutoSize (hwnd);
4010 InvalidateRect (hwnd, NULL, TRUE);
4017 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4019 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4020 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4021 INT nIndex = (INT)wParam;
4022 TBUTTON_INFO *oldButtons;
4027 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4030 /* EPP: this seems to be an undocumented call (from my IE4)
4031 * I assume in that case that:
4032 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4033 * - index of insertion is at the end of existing buttons
4034 * I only see this happen with nIndex == -1, but it could have a special
4035 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4037 nIndex = infoPtr->nNumButtons;
4039 } else if (nIndex < 0)
4042 /* If the string passed is not an index, assume address of string
4043 and do our own AddString */
4044 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4048 TRACE("string %s passed instead of index, adding string\n",
4049 debugstr_w((LPWSTR)lpTbb->iString));
4050 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4051 ptr = Alloc(len*sizeof(WCHAR));
4052 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4053 ptr[len - 1] = 0; /* ended by two '\0' */
4054 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4058 TRACE("inserting button index=%d\n", nIndex);
4059 if (nIndex > infoPtr->nNumButtons) {
4060 nIndex = infoPtr->nNumButtons;
4061 TRACE("adjust index=%d\n", nIndex);
4064 oldButtons = infoPtr->buttons;
4065 infoPtr->nNumButtons++;
4066 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4067 /* pre insert copy */
4069 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4070 nIndex * sizeof(TBUTTON_INFO));
4073 /* insert new button */
4074 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4075 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4076 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4077 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4078 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4079 /* if passed string and not index, then add string */
4080 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4081 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4084 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4086 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4089 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4090 ti.cbSize = sizeof (TTTOOLINFOW);
4092 ti.uId = lpTbb->idCommand;
4094 ti.lpszText = LPSTR_TEXTCALLBACKW;
4096 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4100 /* post insert copy */
4101 if (nIndex < infoPtr->nNumButtons - 1) {
4102 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4103 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4108 TOOLBAR_CalcToolbar (hwnd);
4109 TOOLBAR_AutoSize (hwnd);
4111 InvalidateRect (hwnd, NULL, TRUE);
4117 /* << TOOLBAR_InsertMarkHitTest >> */
4121 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4123 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4126 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4130 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4135 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4140 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4144 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4149 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4154 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4158 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4163 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4168 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4172 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4177 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4179 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4182 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4186 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4191 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4196 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4200 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4205 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4208 tbab.hInst = (HINSTANCE)lParam;
4209 tbab.nID = (UINT_PTR)wParam;
4211 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4213 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4218 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4221 WCHAR wAccel = (WCHAR)wParam;
4222 UINT* pIDButton = (UINT*)lParam;
4223 WCHAR wszAccel[] = {'&',wAccel,0};
4226 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4227 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4229 for (i = 0; i < infoPtr->nNumButtons; i++)
4231 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4232 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4233 !(btnPtr->fsState & TBSTATE_HIDDEN))
4235 int iLen = strlenW(wszAccel);
4236 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4243 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4248 if (!strncmpiW(lpszStr, wszAccel, iLen))
4250 *pIDButton = btnPtr->idCommand;
4262 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4267 TBUTTON_INFO *btnPtr;
4269 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4271 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4275 btnPtr = &infoPtr->buttons[nIndex];
4276 oldState = btnPtr->fsState;
4279 btnPtr->fsState |= TBSTATE_MARKED;
4281 btnPtr->fsState &= ~TBSTATE_MARKED;
4283 if(oldState != btnPtr->fsState)
4284 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4290 /* fixes up an index of a button affected by a move */
4291 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4295 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4297 else if (*pIndex == nIndex)
4298 *pIndex = nMoveIndex;
4302 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4304 else if (*pIndex == nIndex)
4305 *pIndex = nMoveIndex;
4311 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4316 INT nMoveIndex = (INT)lParam;
4317 TBUTTON_INFO button;
4319 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4321 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4322 if ((nIndex == -1) || (nMoveIndex < 0))
4325 if (nMoveIndex > infoPtr->nNumButtons - 1)
4326 nMoveIndex = infoPtr->nNumButtons - 1;
4328 button = infoPtr->buttons[nIndex];
4330 /* move button right */
4331 if (nIndex < nMoveIndex)
4333 nCount = nMoveIndex - nIndex;
4334 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4335 infoPtr->buttons[nMoveIndex] = button;
4337 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4338 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4339 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4340 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4342 else if (nIndex > nMoveIndex) /* move button left */
4344 nCount = nIndex - nMoveIndex;
4345 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4346 infoPtr->buttons[nMoveIndex] = button;
4348 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4349 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4350 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4351 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4354 TOOLBAR_CalcToolbar(hwnd);
4355 TOOLBAR_AutoSize(hwnd);
4356 InvalidateRect(hwnd, NULL, TRUE);
4363 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4366 TBUTTON_INFO *btnPtr;
4370 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4374 btnPtr = &infoPtr->buttons[nIndex];
4375 oldState = btnPtr->fsState;
4376 if (LOWORD(lParam) == FALSE)
4377 btnPtr->fsState &= ~TBSTATE_PRESSED;
4379 btnPtr->fsState |= TBSTATE_PRESSED;
4381 if(oldState != btnPtr->fsState)
4382 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4387 /* FIXME: there might still be some confusion her between number of buttons
4388 * and number of bitmaps */
4390 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4393 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4395 HBITMAP hbmLoad = NULL;
4396 int i = 0, nOldButtons = 0, pos = 0;
4397 int nOldBitmaps, nNewBitmaps = 0;
4398 HIMAGELIST himlDef = 0;
4400 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4401 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4402 lpReplace->nButtons);
4404 if (lpReplace->hInstOld == HINST_COMMCTRL)
4406 FIXME("changing standard bitmaps not implemented\n");
4409 else if (lpReplace->hInstOld != 0)
4410 FIXME("resources not in the current module not implemented\n");
4412 if (lpReplace->hInstNew)
4414 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4419 hBitmap = (HBITMAP) lpReplace->nIDNew;
4422 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4423 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4424 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4425 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4426 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4428 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4429 nOldButtons = tbi->nButtons;
4430 tbi->nButtons = lpReplace->nButtons;
4431 tbi->hInst = lpReplace->hInstNew;
4432 tbi->nID = lpReplace->nIDNew;
4433 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4436 pos += tbi->nButtons;
4439 if (nOldButtons == 0)
4441 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4443 DeleteObject (hbmLoad);
4447 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4448 nOldBitmaps = ImageList_GetImageCount(himlDef);
4450 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4452 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4453 ImageList_Remove(himlDef, i);
4458 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4459 HDC hdcImage, hdcBitmap;
4461 /* copy the bitmap before adding it so that the user's bitmap
4462 * doesn't get modified.
4464 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4466 hdcImage = CreateCompatibleDC(0);
4467 hdcBitmap = CreateCompatibleDC(0);
4469 /* create new bitmap */
4470 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4471 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4472 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4474 /* Copy the user's image */
4475 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4476 hdcBitmap, 0, 0, SRCCOPY);
4478 SelectObject (hdcImage, hOldBitmapLoad);
4479 SelectObject (hdcBitmap, hOldBitmapBitmap);
4480 DeleteDC (hdcImage);
4481 DeleteDC (hdcBitmap);
4483 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4484 nNewBitmaps = ImageList_GetImageCount(himlDef);
4485 DeleteObject (hbmLoad);
4488 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4490 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4491 pos, nOldBitmaps, nNewBitmaps);
4493 InvalidateRect(hwnd, NULL, TRUE);
4496 DeleteObject (hbmLoad);
4501 /* helper for TOOLBAR_SaveRestoreW */
4503 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4505 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4506 debugstr_w(lpSave->pszValueName));
4512 /* helper for TOOLBAR_Restore */
4514 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4519 ZeroMemory(&ti, sizeof(ti));
4520 ti.cbSize = sizeof(ti);
4521 ti.hwnd = infoPtr->hwndSelf;
4523 for (i = 0; i < infoPtr->nNumButtons; i++)
4525 if ((infoPtr->hwndToolTip) &&
4526 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4528 ti.uId = infoPtr->buttons[i].idCommand;
4529 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4533 Free(infoPtr->buttons);
4534 infoPtr->buttons = NULL;
4535 infoPtr->nNumButtons = 0;
4539 /* helper for TOOLBAR_SaveRestoreW */
4541 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4550 /* restore toolbar information */
4551 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4552 debugstr_w(lpSave->pszValueName));
4554 memset(&nmtbr, 0, sizeof(nmtbr));
4556 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4557 KEY_QUERY_VALUE, &hkey);
4559 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4561 if (!res && dwType != REG_BINARY)
4562 res = ERROR_FILE_NOT_FOUND;
4565 nmtbr.pData = Alloc(dwSize);
4566 nmtbr.cbData = (UINT)dwSize;
4567 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4570 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4571 (LPBYTE)nmtbr.pData, &dwSize);
4574 nmtbr.pCurrent = nmtbr.pData;
4576 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4577 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4579 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4583 /* remove all existing buttons as this function is designed to
4584 * restore the toolbar to a previously saved state */
4585 TOOLBAR_DeleteAllButtons(infoPtr);
4587 for (i = 0; i < nmtbr.cButtons; i++)
4590 nmtbr.tbButton.iBitmap = -1;
4591 nmtbr.tbButton.fsState = 0;
4592 nmtbr.tbButton.fsStyle = 0;
4593 nmtbr.tbButton.idCommand = 0;
4594 if (*nmtbr.pCurrent == (DWORD)-1)
4597 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4598 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4600 else if (*nmtbr.pCurrent == (DWORD)-2)
4602 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4604 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4608 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4610 /* can't contain real string as we don't know whether
4611 * the client put an ANSI or Unicode string in there */
4612 if (HIWORD(nmtbr.tbButton.iString))
4613 nmtbr.tbButton.iString = 0;
4615 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4616 (LPARAM)&nmtbr.tbButton);
4619 /* do legacy notifications */
4620 if (infoPtr->iVersion < 5)
4622 /* FIXME: send TBN_BEGINADJUST */
4623 FIXME("send TBN_GETBUTTONINFO for each button\n");
4624 /* FIXME: send TBN_ENDADJUST */
4627 /* remove all uninitialised buttons
4628 * note: loop backwards to avoid having to fixup i on a
4630 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4631 if (infoPtr->buttons[i].iBitmap == -1)
4632 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4634 /* only indicate success if at least one button survived */
4635 if (infoPtr->nNumButtons > 0) ret = TRUE;
4646 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4650 if (lpSave == NULL) return 0;
4653 return TOOLBAR_Save(infoPtr, lpSave);
4655 return TOOLBAR_Restore(infoPtr, lpSave);
4660 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4662 LPWSTR pszValueName = 0, pszSubKey = 0;
4663 TBSAVEPARAMSW SaveW;
4667 if (lpSave == NULL) return 0;
4669 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4670 pszSubKey = Alloc(len * sizeof(WCHAR));
4671 if (pszSubKey) goto exit;
4672 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4674 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4675 pszValueName = Alloc(len * sizeof(WCHAR));
4676 if (!pszValueName) goto exit;
4677 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4679 SaveW.pszValueName = pszValueName;
4680 SaveW.pszSubKey = pszSubKey;
4681 SaveW.hkr = lpSave->hkr;
4682 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4685 Free (pszValueName);
4693 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4695 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4696 BOOL bOldAnchor = infoPtr->bAnchor;
4698 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4700 infoPtr->bAnchor = (BOOL)wParam;
4702 /* Native does not remove the hot effect from an already hot button */
4704 return (LRESULT)bOldAnchor;
4709 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4711 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4712 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4714 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4717 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4719 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4720 lParam = MAKELPARAM(16, 15);
4722 if (infoPtr->nNumButtons > 0)
4723 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4724 infoPtr->nNumButtons,
4725 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4726 LOWORD(lParam), HIWORD(lParam));
4728 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4729 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4732 if ((himlDef == infoPtr->himlInt) &&
4733 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4735 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4736 infoPtr->nBitmapHeight);
4744 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4747 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4748 TBUTTON_INFO *btnPtr;
4754 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4757 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4758 lptbbi->dwMask & 0x80000000);
4762 btnPtr = &infoPtr->buttons[nIndex];
4763 if (lptbbi->dwMask & TBIF_COMMAND)
4764 btnPtr->idCommand = lptbbi->idCommand;
4765 if (lptbbi->dwMask & TBIF_IMAGE)
4766 btnPtr->iBitmap = lptbbi->iImage;
4767 if (lptbbi->dwMask & TBIF_LPARAM)
4768 btnPtr->dwData = lptbbi->lParam;
4769 if (lptbbi->dwMask & TBIF_SIZE)
4770 btnPtr->cx = lptbbi->cx;
4771 if (lptbbi->dwMask & TBIF_STATE)
4772 btnPtr->fsState = lptbbi->fsState;
4773 if (lptbbi->dwMask & TBIF_STYLE)
4774 btnPtr->fsStyle = lptbbi->fsStyle;
4776 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4777 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4778 /* iString is index, zero it to make Str_SetPtr succeed */
4781 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4784 /* save the button rect to see if we need to redraw the whole toolbar */
4785 oldBtnRect = btnPtr->rect;
4786 TOOLBAR_CalcToolbar(hwnd);
4788 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4789 InvalidateRect(hwnd, NULL, TRUE);
4791 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4798 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4801 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4802 TBUTTON_INFO *btnPtr;
4808 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4811 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4812 lptbbi->dwMask & 0x80000000);
4816 btnPtr = &infoPtr->buttons[nIndex];
4817 if (lptbbi->dwMask & TBIF_COMMAND)
4818 btnPtr->idCommand = lptbbi->idCommand;
4819 if (lptbbi->dwMask & TBIF_IMAGE)
4820 btnPtr->iBitmap = lptbbi->iImage;
4821 if (lptbbi->dwMask & TBIF_LPARAM)
4822 btnPtr->dwData = lptbbi->lParam;
4823 if (lptbbi->dwMask & TBIF_SIZE)
4824 btnPtr->cx = lptbbi->cx;
4825 if (lptbbi->dwMask & TBIF_STATE)
4826 btnPtr->fsState = lptbbi->fsState;
4827 if (lptbbi->dwMask & TBIF_STYLE)
4828 btnPtr->fsStyle = lptbbi->fsStyle;
4830 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4831 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4832 /* iString is index, zero it to make Str_SetPtr succeed */
4834 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4837 /* save the button rect to see if we need to redraw the whole toolbar */
4838 oldBtnRect = btnPtr->rect;
4839 TOOLBAR_CalcToolbar(hwnd);
4841 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4842 InvalidateRect(hwnd, NULL, TRUE);
4844 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4851 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4854 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4856 if ((cx < 0) || (cy < 0))
4858 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4862 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4864 /* The documentation claims you can only change the button size before
4865 * any button has been added. But this is wrong.
4866 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4867 * it to the toolbar, and it checks that the return value is nonzero - mjm
4868 * Further testing shows that we must actually perform the change too.
4871 * The documentation also does not mention that if 0 is supplied for
4872 * either size, the system changes it to the default of 24 wide and
4873 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4875 infoPtr->nButtonWidth = (cx) ? cx : 24;
4876 infoPtr->nButtonHeight = (cy) ? cy : 22;
4882 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4886 /* if setting to current values, ignore */
4887 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4888 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4889 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4890 infoPtr->cxMin, infoPtr->cxMax);
4894 /* save new values */
4895 infoPtr->cxMin = (INT)LOWORD(lParam);
4896 infoPtr->cxMax = (INT)HIWORD(lParam);
4898 /* otherwise we need to recalc the toolbar and in some cases
4899 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4900 which doesn't actually draw - GA). */
4901 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4902 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4904 TOOLBAR_CalcToolbar (hwnd);
4906 InvalidateRect (hwnd, NULL, TRUE);
4913 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4916 INT nIndex = (INT)wParam;
4918 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4921 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4923 if (infoPtr->hwndToolTip) {
4925 FIXME("change tool tip!\n");
4934 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4937 HIMAGELIST himl = (HIMAGELIST)lParam;
4938 HIMAGELIST himlTemp;
4941 if (infoPtr->iVersion >= 5)
4944 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4945 &infoPtr->cimlDis, himl, id);
4947 /* FIXME: redraw ? */
4949 return (LRESULT)himlTemp;
4954 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4956 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4959 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4961 dwTemp = infoPtr->dwDTFlags;
4962 infoPtr->dwDTFlags =
4963 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4965 return (LRESULT)dwTemp;
4968 /* This function differs a bit from what MSDN says it does:
4969 * 1. lParam contains extended style flags to OR with current style
4970 * (MSDN isn't clear on the OR bit)
4971 * 2. wParam appears to contain extended style flags to be reset
4972 * (MSDN says that this parameter is reserved)
4975 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4980 dwTemp = infoPtr->dwExStyle;
4981 infoPtr->dwExStyle &= ~wParam;
4982 infoPtr->dwExStyle |= (DWORD)lParam;
4984 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4986 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4987 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4988 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4990 TOOLBAR_CalcToolbar (hwnd);
4992 TOOLBAR_AutoSize(hwnd);
4994 InvalidateRect(hwnd, NULL, TRUE);
4996 return (LRESULT)dwTemp;
5001 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5004 HIMAGELIST himlTemp;
5005 HIMAGELIST himl = (HIMAGELIST)lParam;
5008 if (infoPtr->iVersion >= 5)
5011 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
5013 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
5014 &infoPtr->cimlHot, himl, id);
5016 /* FIXME: redraw ? */
5018 return (LRESULT)himlTemp;
5022 /* Makes previous hot button no longer hot, makes the specified
5023 * button hot and sends appropriate notifications. dwReason is one or
5024 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5025 * NOTE 1: this function does not validate nHit
5026 * NOTE 2: the name of this function is completely made up and
5027 * not based on any documentation from Microsoft. */
5029 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5031 if (infoPtr->nHotItem != nHit)
5033 NMTBHOTITEM nmhotitem;
5034 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5035 LRESULT no_highlight;
5037 /* Remove the effect of an old hot button if the button was
5038 drawn with the hot button effect */
5039 if(infoPtr->nHotItem >= 0)
5041 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5042 oldBtnPtr->bHot = FALSE;
5045 infoPtr->nHotItem = nHit;
5047 /* It's not a separator or in nowhere. It's a hot button. */
5049 btnPtr = &infoPtr->buttons[nHit];
5051 nmhotitem.dwFlags = dwReason;
5053 nmhotitem.idOld = oldBtnPtr->idCommand;
5055 nmhotitem.dwFlags |= HICF_ENTERING;
5057 nmhotitem.idNew = btnPtr->idCommand;
5059 nmhotitem.dwFlags |= HICF_LEAVING;
5061 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5063 /* now invalidate the old and new buttons so they will be painted,
5064 * but only if they are enabled - disabled buttons cannot become hot */
5065 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5066 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5067 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5069 btnPtr->bHot = TRUE;
5070 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5076 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5079 INT nOldHotItem = infoPtr->nHotItem;
5081 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5083 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5086 /* NOTE: an application can still remove the hot item even if anchor
5087 * highlighting is enabled */
5089 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5090 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5092 if (nOldHotItem < 0)
5095 return (LRESULT)nOldHotItem;
5100 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5103 HIMAGELIST himlTemp;
5104 HIMAGELIST himl = (HIMAGELIST)lParam;
5107 if (infoPtr->iVersion >= 5)
5110 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5111 &infoPtr->cimlDef, himl, id);
5113 infoPtr->nNumBitmaps = 0;
5114 for (i = 0; i < infoPtr->cimlDef; i++)
5115 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5117 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5118 &infoPtr->nBitmapHeight))
5120 infoPtr->nBitmapWidth = 1;
5121 infoPtr->nBitmapHeight = 1;
5124 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5125 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5126 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5128 InvalidateRect(hwnd, NULL, TRUE);
5130 return (LRESULT)himlTemp;
5135 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5139 infoPtr->nIndent = (INT)wParam;
5143 /* process only on indent changing */
5144 if(infoPtr->nIndent != (INT)wParam)
5146 infoPtr->nIndent = (INT)wParam;
5147 TOOLBAR_CalcToolbar (hwnd);
5148 InvalidateRect(hwnd, NULL, FALSE);
5156 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5158 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5159 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5161 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5163 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5165 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5169 if ((lptbim->iButton == -1) ||
5170 ((lptbim->iButton < infoPtr->nNumButtons) &&
5171 (lptbim->iButton >= 0)))
5173 infoPtr->tbim = *lptbim;
5174 /* FIXME: don't need to update entire toolbar */
5175 InvalidateRect(hwnd, NULL, TRUE);
5178 ERR("Invalid button index %d\n", lptbim->iButton);
5185 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5187 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5189 infoPtr->clrInsertMark = (COLORREF)lParam;
5191 /* FIXME: don't need to update entire toolbar */
5192 InvalidateRect(hwnd, NULL, TRUE);
5199 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5201 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5203 infoPtr->nMaxTextRows = (INT)wParam;
5205 TOOLBAR_CalcToolbar(hwnd);
5210 /* MSDN gives slightly wrong info on padding.
5211 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5212 * 2. It is not used to create a blank area between the edge of the button
5213 * and the text or image if TBSTYLE_LIST is set. It is used to control
5214 * the gap between the image and text.
5215 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5216 * to control the bottom and right borders [with the border being
5217 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5218 * is shared evenly on both sides of the button.
5219 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5222 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5227 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5228 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5229 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5230 TRACE("cx=%ld, cy=%ld\n",
5231 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5232 return (LRESULT) oldPad;
5237 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5244 hwndOldNotify = infoPtr->hwndNotify;
5245 infoPtr->hwndNotify = (HWND)wParam;
5247 return (LRESULT)hwndOldNotify;
5252 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5254 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5255 LPRECT lprc = (LPRECT)lParam;
5259 if (LOWORD(wParam) > 1) {
5260 FIXME("multiple rows not supported!\n");
5263 if(infoPtr->nRows != LOWORD(wParam))
5265 infoPtr->nRows = LOWORD(wParam);
5267 /* recalculate toolbar */
5268 TOOLBAR_CalcToolbar (hwnd);
5270 /* repaint toolbar */
5271 InvalidateRect(hwnd, NULL, TRUE);
5274 /* return bounding rectangle */
5276 lprc->left = infoPtr->rcBound.left;
5277 lprc->right = infoPtr->rcBound.right;
5278 lprc->top = infoPtr->rcBound.top;
5279 lprc->bottom = infoPtr->rcBound.bottom;
5287 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5290 TBUTTON_INFO *btnPtr;
5293 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5297 btnPtr = &infoPtr->buttons[nIndex];
5299 /* if hidden state has changed the invalidate entire window and recalc */
5300 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5301 btnPtr->fsState = LOWORD(lParam);
5302 TOOLBAR_CalcToolbar (hwnd);
5303 InvalidateRect(hwnd, 0, TRUE);
5307 /* process state changing if current state doesn't match new state */
5308 if(btnPtr->fsState != LOWORD(lParam))
5310 btnPtr->fsState = LOWORD(lParam);
5311 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5319 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5321 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5327 inline static LRESULT
5328 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5330 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5332 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5334 infoPtr->hwndToolTip = (HWND)wParam;
5340 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5345 TRACE("%s hwnd=%p\n",
5346 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5348 bTemp = infoPtr->bUnicode;
5349 infoPtr->bUnicode = (BOOL)wParam;
5356 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5358 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5360 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5361 comctl32_color.clrBtnHighlight :
5362 infoPtr->clrBtnHighlight;
5363 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5364 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5370 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5374 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5375 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5376 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5378 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5379 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5380 InvalidateRect(hwnd, NULL, TRUE);
5386 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5389 INT iOldVersion = infoPtr->iVersion;
5391 infoPtr->iVersion = iVersion;
5393 if (infoPtr->iVersion >= 5)
5394 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5401 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5403 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5404 WORD iString = HIWORD(wParam);
5405 WORD buffersize = LOWORD(wParam);
5406 LPSTR str = (LPSTR)lParam;
5409 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5411 if (iString < infoPtr->nNumStrings)
5413 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5415 TRACE("returning %s\n", debugstr_a(str));
5418 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5425 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5428 WORD iString = HIWORD(wParam);
5429 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5430 LPWSTR str = (LPWSTR)lParam;
5433 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5435 if (iString < infoPtr->nNumStrings)
5437 len = min(len, strlenW(infoPtr->strings[iString]));
5438 ret = (len+1)*sizeof(WCHAR);
5439 memcpy(str, infoPtr->strings[iString], ret);
5442 TRACE("returning %s\n", debugstr_w(str));
5445 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5450 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5451 * is the maximum size of the toolbar? */
5452 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5454 SIZE * pSize = (SIZE*)lParam;
5455 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5460 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5461 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5462 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5465 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5468 INT nOldHotItem = infoPtr->nHotItem;
5470 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5471 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5473 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5476 /* NOTE: an application can still remove the hot item even if anchor
5477 * highlighting is enabled */
5479 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5483 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5486 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5487 * which controls the amount of spacing between the image and the text
5488 * of buttons for TBSTYLE_LIST toolbars. */
5489 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5491 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5493 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5496 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5498 infoPtr->iListGap = (INT)wParam;
5500 InvalidateRect(hwnd, NULL, TRUE);
5505 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5506 * of image lists associated with the various states. */
5507 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5509 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5511 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5513 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5517 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5520 LPSIZE lpsize = (LPSIZE)lParam;
5526 * Testing shows the following:
5527 * wParam = 0 adjust cx value
5528 * = 1 set cy value to max size.
5529 * lParam pointer to SIZE structure
5532 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5533 wParam, lParam, lpsize->cx, lpsize->cy);
5537 if (lpsize->cx == -1) {
5538 /* **** this is wrong, native measures each button and sets it */
5539 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5541 else if(HIWORD(lpsize->cx)) {
5543 HWND hwndParent = GetParent(hwnd);
5545 GetWindowRect(hwnd, &rc);
5546 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5547 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5548 rc.left, rc.top, rc.right, rc.bottom);
5549 lpsize->cx = max(rc.right-rc.left,
5550 infoPtr->rcBound.right - infoPtr->rcBound.left);
5553 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5557 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5560 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5564 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5565 lpsize->cx, lpsize->cy);
5569 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5571 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5573 InvalidateRect(hwnd, NULL, TRUE);
5579 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5582 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5585 TRACE("hwnd = %p\n", hwnd);
5587 /* initialize info structure */
5588 infoPtr->nButtonHeight = 22;
5589 infoPtr->nButtonWidth = 24;
5590 infoPtr->nBitmapHeight = 15;
5591 infoPtr->nBitmapWidth = 16;
5593 infoPtr->nMaxTextRows = 1;
5594 infoPtr->cxMin = -1;
5595 infoPtr->cxMax = -1;
5596 infoPtr->nNumBitmaps = 0;
5597 infoPtr->nNumStrings = 0;
5599 infoPtr->bCaptured = FALSE;
5600 infoPtr->nButtonDown = -1;
5601 infoPtr->nButtonDrag = -1;
5602 infoPtr->nOldHit = -1;
5603 infoPtr->nHotItem = -1;
5604 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5605 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5606 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5607 infoPtr->bDragOutSent = FALSE;
5608 infoPtr->iVersion = 0;
5609 infoPtr->hwndSelf = hwnd;
5610 infoPtr->bDoRedraw = TRUE;
5611 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5612 infoPtr->clrBtnShadow = CLR_DEFAULT;
5613 infoPtr->szPadding.cx = DEFPAD_CX;
5614 infoPtr->szPadding.cy = DEFPAD_CY;
5615 infoPtr->iListGap = DEFLISTGAP;
5616 infoPtr->dwStyle = dwStyle;
5617 infoPtr->tbim.iButton = -1;
5618 GetClientRect(hwnd, &infoPtr->client_rect);
5619 infoPtr->bUnicode = infoPtr->hwndNotify &&
5620 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5622 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5623 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5625 if (dwStyle & TBSTYLE_TOOLTIPS) {
5626 /* Create tooltip control */
5627 infoPtr->hwndToolTip =
5628 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5629 CW_USEDEFAULT, CW_USEDEFAULT,
5630 CW_USEDEFAULT, CW_USEDEFAULT,
5633 /* Send NM_TOOLTIPSCREATED notification */
5634 if (infoPtr->hwndToolTip)
5636 NMTOOLTIPSCREATED nmttc;
5638 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5640 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5644 OpenThemeData (hwnd, themeClass);
5646 TOOLBAR_CheckStyle (hwnd, dwStyle);
5648 TOOLBAR_CalcToolbar(hwnd);
5655 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5659 /* delete tooltip control */
5660 if (infoPtr->hwndToolTip)
5661 DestroyWindow (infoPtr->hwndToolTip);
5663 /* delete temporary buffer for tooltip text */
5664 Free (infoPtr->pszTooltipText);
5665 Free (infoPtr->bitmaps); /* bitmaps list */
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_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5790 INT nNewHotItem = infoPtr->nHotItem;
5792 for (i = 0; i < infoPtr->nNumButtons; i++)
5795 if ((nNewHotItem + iDirection < 0) ||
5796 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5798 NMTBWRAPHOTITEM nmtbwhi;
5799 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5800 nmtbwhi.iDirection = iDirection;
5801 nmtbwhi.dwReason = dwReason;
5803 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5807 nNewHotItem += iDirection;
5808 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5810 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5811 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5813 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5820 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5825 nmkey.nVKey = (UINT)wParam;
5826 nmkey.uFlags = HIWORD(lParam);
5828 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5829 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5831 switch ((UINT)wParam)
5835 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5839 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5843 if ((infoPtr->nHotItem >= 0) &&
5844 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5846 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5847 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5858 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5863 pt.x = (INT)LOWORD(lParam);
5864 pt.y = (INT)HIWORD(lParam);
5865 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5868 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5869 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5870 TOOLBAR_Customize (hwnd);
5877 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5880 TBUTTON_INFO *btnPtr;
5885 BOOL bDragKeyPressed;
5889 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5890 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5892 bDragKeyPressed = (wParam & MK_SHIFT);
5894 if (infoPtr->hwndToolTip)
5895 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5896 WM_LBUTTONDOWN, wParam, lParam);
5898 pt.x = (INT)LOWORD(lParam);
5899 pt.y = (INT)HIWORD(lParam);
5900 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5902 btnPtr = &infoPtr->buttons[nHit];
5904 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5906 infoPtr->nButtonDrag = nHit;
5909 /* If drag cursor has not been loaded, load it.
5910 * Note: it doesn't need to be freed */
5912 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5913 SetCursor(hCursorDrag);
5918 infoPtr->nOldHit = nHit;
5920 CopyRect(&arrowRect, &btnPtr->rect);
5921 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5923 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5924 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5925 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5926 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5927 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5928 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5932 /* draw in pressed state */
5933 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5934 btnPtr->fsState |= TBSTATE_PRESSED;
5936 btnPtr->bDropDownPressed = TRUE;
5937 RedrawWindow(hwnd,&btnPtr->rect,0,
5938 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5940 memset(&nmtb, 0, sizeof(nmtb));
5941 nmtb.iItem = btnPtr->idCommand;
5942 nmtb.rcButton = btnPtr->rect;
5943 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5945 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5947 if (res != TBDDRET_TREATPRESSED)
5951 /* redraw button in unpressed state */
5952 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5953 btnPtr->fsState &= ~TBSTATE_PRESSED;
5955 btnPtr->bDropDownPressed = FALSE;
5956 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5958 /* find and set hot item
5959 * NOTE: native doesn't do this, but that is a bug */
5961 ScreenToClient(hwnd, &pt);
5962 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5963 if (!infoPtr->bAnchor || (nHit >= 0))
5964 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5966 /* remove any left mouse button down or double-click messages
5967 * so that we can get a toggle effect on the button */
5968 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5969 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5974 /* otherwise drop through and process as pushed */
5976 infoPtr->bCaptured = TRUE;
5977 infoPtr->nButtonDown = nHit;
5978 infoPtr->bDragOutSent = FALSE;
5980 btnPtr->fsState |= TBSTATE_PRESSED;
5982 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5984 if (btnPtr->fsState & TBSTATE_ENABLED)
5985 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5992 memset(&nmtb, 0, sizeof(nmtb));
5993 nmtb.iItem = btnPtr->idCommand;
5994 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5997 nmmouse.dwHitInfo = nHit;
5999 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
6001 nmmouse.dwItemSpec = -1;
6004 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6005 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6008 ClientToScreen(hwnd, &pt);
6011 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
6012 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
6018 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
6020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6021 TBUTTON_INFO *btnPtr;
6025 BOOL bSendMessage = TRUE;
6030 if (infoPtr->hwndToolTip)
6031 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6032 WM_LBUTTONUP, wParam, lParam);
6034 pt.x = (INT)LOWORD(lParam);
6035 pt.y = (INT)HIWORD(lParam);
6036 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6038 if (!infoPtr->bAnchor || (nHit >= 0))
6039 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6041 if (infoPtr->nButtonDrag >= 0) {
6045 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
6048 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
6050 GetClientRect(hwnd, &rcClient);
6051 if (PtInRect(&rcClient, pt))
6058 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
6061 if (nButton == infoPtr->nButtonDrag)
6063 /* if the button is moved sightly left and we have a
6064 * separator there then remove it */
6065 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
6067 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
6068 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
6070 else /* else insert a separator before the dragged button */
6073 memset(&tbb, 0, sizeof(tbb));
6074 tbb.fsStyle = BTNS_SEP;
6076 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6083 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6084 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6086 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6089 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6094 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6095 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6098 /* button under cursor changed so need to re-set hot item */
6099 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6100 infoPtr->nButtonDrag = -1;
6102 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6104 else if (infoPtr->nButtonDown >= 0) {
6105 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6106 btnPtr->fsState &= ~TBSTATE_PRESSED;
6108 if (btnPtr->fsStyle & BTNS_CHECK) {
6109 if (btnPtr->fsStyle & BTNS_GROUP) {
6110 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6112 if (nOldIndex == nHit)
6113 bSendMessage = FALSE;
6114 if ((nOldIndex != nHit) &&
6116 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6117 btnPtr->fsState |= TBSTATE_CHECKED;
6120 if (btnPtr->fsState & TBSTATE_CHECKED)
6121 btnPtr->fsState &= ~TBSTATE_CHECKED;
6123 btnPtr->fsState |= TBSTATE_CHECKED;
6127 if (nOldIndex != -1)
6128 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6131 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6132 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6133 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6135 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6137 infoPtr->nButtonDown = -1;
6139 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6140 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6141 NM_RELEASEDCAPTURE);
6143 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6146 memset(&nmtb, 0, sizeof(nmtb));
6147 nmtb.iItem = btnPtr->idCommand;
6148 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6151 if (btnPtr->fsState & TBSTATE_ENABLED)
6153 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6154 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6158 /* !!! Undocumented - toolbar at 4.71 level and above sends
6159 * NM_CLICK with the NMMOUSE structure. */
6160 nmmouse.dwHitInfo = nHit;
6163 nmmouse.dwItemSpec = -1;
6166 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6167 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6170 ClientToScreen(hwnd, &pt);
6173 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6174 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6180 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6187 pt.x = LOWORD(lParam);
6188 pt.y = HIWORD(lParam);
6190 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6191 nmmouse.dwHitInfo = nHit;
6194 nmmouse.dwItemSpec = -1;
6196 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6197 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6200 ClientToScreen(hwnd, &pt);
6203 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6204 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6210 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6215 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6216 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6222 TOOLBAR_CaptureChanged(HWND hwnd)
6224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6225 TBUTTON_INFO *btnPtr;
6227 infoPtr->bCaptured = FALSE;
6229 if (infoPtr->nButtonDown >= 0)
6231 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6232 btnPtr->fsState &= ~TBSTATE_PRESSED;
6234 infoPtr->nOldHit = -1;
6236 if (btnPtr->fsState & TBSTATE_ENABLED)
6237 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6243 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6245 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6246 TBUTTON_INFO *hotBtnPtr;
6248 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6250 /* don't remove hot effects when in anchor highlighting mode or when a
6251 * drop-down button is pressed */
6252 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6253 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6255 if (infoPtr->nOldHit < 0)
6258 /* If the last button we were over is depressed then make it not */
6259 /* depressed and redraw it */
6260 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6262 TBUTTON_INFO *btnPtr;
6265 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6267 btnPtr->fsState &= ~TBSTATE_PRESSED;
6269 rc1 = hotBtnPtr->rect;
6270 InflateRect (&rc1, 1, 1);
6271 InvalidateRect (hwnd, &rc1, TRUE);
6274 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6277 ZeroMemory(&nmt, sizeof(nmt));
6278 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6279 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6280 infoPtr->bDragOutSent = TRUE;
6283 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6289 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6293 TRACKMOUSEEVENT trackinfo;
6295 TBUTTON_INFO *btnPtr;
6297 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6298 /* fill in the TRACKMOUSEEVENT struct */
6299 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6300 trackinfo.dwFlags = TME_QUERY;
6301 trackinfo.hwndTrack = hwnd;
6302 trackinfo.dwHoverTime = HOVER_DEFAULT;
6304 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6305 _TrackMouseEvent(&trackinfo);
6307 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6308 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6309 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6311 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6312 /* and can properly deactivate the hot toolbar button */
6313 _TrackMouseEvent(&trackinfo);
6317 if (infoPtr->hwndToolTip)
6318 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6319 WM_MOUSEMOVE, wParam, lParam);
6321 pt.x = (INT)LOWORD(lParam);
6322 pt.y = (INT)HIWORD(lParam);
6324 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6326 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6327 && (!infoPtr->bAnchor || (nHit >= 0)))
6328 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6330 if (infoPtr->nOldHit != nHit)
6332 if (infoPtr->bCaptured)
6334 if (!infoPtr->bDragOutSent)
6337 ZeroMemory(&nmt, sizeof(nmt));
6338 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6339 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6340 infoPtr->bDragOutSent = TRUE;
6343 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6344 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6345 btnPtr->fsState &= ~TBSTATE_PRESSED;
6346 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6348 else if (nHit == infoPtr->nButtonDown) {
6349 btnPtr->fsState |= TBSTATE_PRESSED;
6350 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6352 infoPtr->nOldHit = nHit;
6360 inline static LRESULT
6361 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6363 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6364 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6366 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6370 inline static LRESULT
6371 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6373 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6374 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6376 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6381 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6383 TOOLBAR_INFO *infoPtr;
6384 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6387 /* allocate memory for info structure */
6388 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6389 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6392 infoPtr->dwStructSize = sizeof(TBBUTTON);
6394 infoPtr->nWidth = 0;
6396 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6397 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6398 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6399 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6402 /* native control does:
6403 * Get a lot of colors and brushes
6405 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6406 * CreateFontIndirectW(adr1)
6407 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6408 * hdc = GetDC(toolbar)
6409 * GetSystemMetrics(0x48)
6410 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6411 * 0, 0, 0, 0, "MARLETT")
6412 * oldfnt = SelectObject(hdc, fnt2)
6413 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6414 * GetTextMetricsW(hdc, adr3)
6415 * SelectObject(hdc, oldfnt)
6416 * DeleteObject(fnt2)
6418 * InvalidateRect(toolbar, 0, 1)
6419 * SetWindowLongW(toolbar, 0, addr)
6420 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6423 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6424 * ie 2 0x4600094c 0x4600094c 0x4600894d
6425 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6426 * rebar 0x50008844 0x40008844 0x50008845
6427 * pager 0x50000844 0x40000844 0x50008845
6428 * IC35mgr 0x5400084e **nochange**
6429 * on entry to _NCCREATE 0x5400084e
6430 * rowlist 0x5400004e **nochange**
6431 * on entry to _NCCREATE 0x5400004e
6435 /* I think the code below is a bug, but it is the way that the native
6436 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6437 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6438 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6439 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6440 * Somehow, the only cases of this seem to be MFC programs.
6442 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6443 * does not occur in the WM_STYLECHANGING routine.
6444 * (Guy Albertelli 9/2001)
6447 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6448 && !(cs->style & TBSTYLE_TRANSPARENT))
6449 styleadd |= TBSTYLE_TRANSPARENT;
6450 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6451 styleadd |= CCS_TOP; /* default to top */
6452 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6455 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6460 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6462 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6466 if (dwStyle & WS_MINIMIZE)
6467 return 0; /* Nothing to do */
6469 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6471 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6474 if (!(dwStyle & CCS_NODIVIDER))
6476 GetWindowRect (hwnd, &rcWindow);
6477 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6478 if( dwStyle & WS_BORDER )
6479 OffsetRect (&rcWindow, 1, 1);
6480 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6483 ReleaseDC( hwnd, hdc );
6489 /* handles requests from the tooltip control on what text to display */
6490 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6492 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6494 TRACE("button index = %d\n", index);
6496 Free (infoPtr->pszTooltipText);
6497 infoPtr->pszTooltipText = NULL;
6502 if (infoPtr->bUnicode)
6504 WCHAR wszBuffer[INFOTIPSIZE+1];
6505 NMTBGETINFOTIPW tbgit;
6506 unsigned int len; /* in chars */
6508 wszBuffer[0] = '\0';
6509 wszBuffer[INFOTIPSIZE] = '\0';
6511 tbgit.pszText = wszBuffer;
6512 tbgit.cchTextMax = INFOTIPSIZE;
6513 tbgit.iItem = lpnmtdi->hdr.idFrom;
6514 tbgit.lParam = infoPtr->buttons[index].dwData;
6516 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6518 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6520 len = strlenW(tbgit.pszText);
6521 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6523 /* need to allocate temporary buffer in infoPtr as there
6524 * isn't enough space in buffer passed to us by the
6525 * tooltip control */
6526 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6527 if (infoPtr->pszTooltipText)
6529 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6530 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6536 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6542 CHAR szBuffer[INFOTIPSIZE+1];
6543 NMTBGETINFOTIPA tbgit;
6544 unsigned int len; /* in chars */
6547 szBuffer[INFOTIPSIZE] = '\0';
6549 tbgit.pszText = szBuffer;
6550 tbgit.cchTextMax = INFOTIPSIZE;
6551 tbgit.iItem = lpnmtdi->hdr.idFrom;
6552 tbgit.lParam = infoPtr->buttons[index].dwData;
6554 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6556 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6558 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6559 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6561 /* need to allocate temporary buffer in infoPtr as there
6562 * isn't enough space in buffer passed to us by the
6563 * tooltip control */
6564 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6565 if (infoPtr->pszTooltipText)
6567 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6568 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6574 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6575 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6580 /* if button has text, but it is not shown then automatically
6581 * use that text as tooltip */
6582 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6583 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6585 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6586 unsigned int len = pszText ? strlenW(pszText) : 0;
6588 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6590 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6592 /* need to allocate temporary buffer in infoPtr as there
6593 * isn't enough space in buffer passed to us by the
6594 * tooltip control */
6595 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6596 if (infoPtr->pszTooltipText)
6598 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6599 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6605 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6610 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6612 /* last resort: send notification on to app */
6613 /* FIXME: find out what is really used here */
6614 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6618 inline static LRESULT
6619 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6622 LPNMHDR lpnmh = (LPNMHDR)lParam;
6624 switch (lpnmh->code)
6628 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6630 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6631 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6632 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6636 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6637 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6645 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6647 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6648 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6649 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6650 lppgs->iScroll, lppgs->iDir);
6654 case TTN_GETDISPINFOW:
6655 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6657 case TTN_GETDISPINFOA:
6658 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6668 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6672 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6674 if (lParam == NF_QUERY)
6677 if (lParam == NF_REQUERY) {
6678 format = SendMessageW(infoPtr->hwndNotify,
6679 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6680 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6681 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6692 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6698 /* fill ps.rcPaint with a default rect */
6699 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6701 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6703 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6704 ps.rcPaint.left, ps.rcPaint.top,
6705 ps.rcPaint.right, ps.rcPaint.bottom);
6707 TOOLBAR_Refresh (hwnd, hdc, &ps);
6708 if (!wParam) EndPaint (hwnd, &ps);
6715 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6717 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6719 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6721 /* make first item hot */
6722 if (infoPtr->nNumButtons > 0)
6723 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6730 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6731 /*****************************************************
6734 * Handles the WM_SETREDRAW message.
6737 * According to testing V4.71 of COMCTL32 returns the
6738 * *previous* status of the redraw flag (either 0 or 1)
6739 * instead of the MSDN documented value of 0 if handled.
6740 * (For laughs see the "consistency" with same function
6743 *****************************************************/
6745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6746 BOOL oldredraw = infoPtr->bDoRedraw;
6748 TRACE("set to %s\n",
6749 (wParam) ? "TRUE" : "FALSE");
6750 infoPtr->bDoRedraw = (BOOL) wParam;
6752 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6754 return (oldredraw) ? 1 : 0;
6759 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6761 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6763 TRACE("sizing toolbar!\n");
6765 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6767 RECT delta_width, delta_height, client, dummy;
6768 DWORD min_x, max_x, min_y, max_y;
6769 TBUTTON_INFO *btnPtr;
6772 GetClientRect(hwnd, &client);
6773 if(client.right > infoPtr->client_rect.right)
6775 min_x = infoPtr->client_rect.right;
6776 max_x = client.right;
6780 max_x = infoPtr->client_rect.right;
6781 min_x = client.right;
6783 if(client.bottom > infoPtr->client_rect.bottom)
6785 min_y = infoPtr->client_rect.bottom;
6786 max_y = client.bottom;
6790 max_y = infoPtr->client_rect.bottom;
6791 min_y = client.bottom;
6794 SetRect(&delta_width, min_x, 0, max_x, min_y);
6795 SetRect(&delta_height, 0, min_y, max_x, max_y);
6797 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6798 btnPtr = infoPtr->buttons;
6799 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6800 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6801 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6802 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6804 GetClientRect(hwnd, &infoPtr->client_rect);
6805 TOOLBAR_AutoSize(hwnd);
6811 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6815 if (nType == GWL_STYLE)
6817 if (lpStyle->styleNew & TBSTYLE_LIST)
6818 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6820 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6822 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6824 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6826 infoPtr->dwStyle = lpStyle->styleNew;
6828 /* only resize if one of the CCS_* styles was changed */
6829 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6831 TOOLBAR_AutoSize (hwnd);
6833 InvalidateRect(hwnd, NULL, TRUE);
6842 TOOLBAR_SysColorChange (HWND hwnd)
6844 COMCTL32_RefreshSysColors();
6850 /* update theme after a WM_THEMECHANGED message */
6851 static LRESULT theme_changed (HWND hwnd)
6853 HTHEME theme = GetWindowTheme (hwnd);
6854 CloseThemeData (theme);
6855 OpenThemeData (hwnd, themeClass);
6860 static LRESULT WINAPI
6861 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6865 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6866 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6868 if (!infoPtr && (uMsg != WM_NCCREATE))
6869 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6874 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6876 case TB_ADDBUTTONSA:
6877 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6879 case TB_ADDBUTTONSW:
6880 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6883 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6886 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6889 return TOOLBAR_AutoSize (hwnd);
6891 case TB_BUTTONCOUNT:
6892 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6894 case TB_BUTTONSTRUCTSIZE:
6895 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6897 case TB_CHANGEBITMAP:
6898 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6900 case TB_CHECKBUTTON:
6901 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6903 case TB_COMMANDTOINDEX:
6904 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6907 return TOOLBAR_Customize (hwnd);
6909 case TB_DELETEBUTTON:
6910 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6912 case TB_ENABLEBUTTON:
6913 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6915 case TB_GETANCHORHIGHLIGHT:
6916 return TOOLBAR_GetAnchorHighlight (hwnd);
6919 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6921 case TB_GETBITMAPFLAGS:
6922 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6925 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6927 case TB_GETBUTTONINFOA:
6928 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6930 case TB_GETBUTTONINFOW:
6931 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6933 case TB_GETBUTTONSIZE:
6934 return TOOLBAR_GetButtonSize (hwnd);
6936 case TB_GETBUTTONTEXTA:
6937 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6939 case TB_GETBUTTONTEXTW:
6940 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6942 case TB_GETDISABLEDIMAGELIST:
6943 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6945 case TB_GETEXTENDEDSTYLE:
6946 return TOOLBAR_GetExtendedStyle (hwnd);
6948 case TB_GETHOTIMAGELIST:
6949 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6952 return TOOLBAR_GetHotItem (hwnd);
6954 case TB_GETIMAGELIST:
6955 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6957 case TB_GETINSERTMARK:
6958 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6960 case TB_GETINSERTMARKCOLOR:
6961 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6963 case TB_GETITEMRECT:
6964 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6967 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6969 /* case TB_GETOBJECT: */ /* 4.71 */
6972 return TOOLBAR_GetPadding (hwnd);
6975 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6978 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6981 return TOOLBAR_GetState (hwnd, wParam, lParam);
6984 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6987 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6990 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6992 case TB_GETTEXTROWS:
6993 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6995 case TB_GETTOOLTIPS:
6996 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6998 case TB_GETUNICODEFORMAT:
6999 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
7002 return TOOLBAR_HideButton (hwnd, wParam, lParam);
7005 return TOOLBAR_HitTest (hwnd, wParam, lParam);
7007 case TB_INDETERMINATE:
7008 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
7010 case TB_INSERTBUTTONA:
7011 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
7013 case TB_INSERTBUTTONW:
7014 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
7016 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
7018 case TB_ISBUTTONCHECKED:
7019 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
7021 case TB_ISBUTTONENABLED:
7022 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
7024 case TB_ISBUTTONHIDDEN:
7025 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
7027 case TB_ISBUTTONHIGHLIGHTED:
7028 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
7030 case TB_ISBUTTONINDETERMINATE:
7031 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
7033 case TB_ISBUTTONPRESSED:
7034 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
7037 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
7039 case TB_MAPACCELERATORA:
7040 case TB_MAPACCELERATORW:
7041 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
7044 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7047 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7049 case TB_PRESSBUTTON:
7050 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7052 case TB_REPLACEBITMAP:
7053 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7055 case TB_SAVERESTOREA:
7056 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7058 case TB_SAVERESTOREW:
7059 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7061 case TB_SETANCHORHIGHLIGHT:
7062 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7064 case TB_SETBITMAPSIZE:
7065 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7067 case TB_SETBUTTONINFOA:
7068 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7070 case TB_SETBUTTONINFOW:
7071 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7073 case TB_SETBUTTONSIZE:
7074 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7076 case TB_SETBUTTONWIDTH:
7077 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7080 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7082 case TB_SETDISABLEDIMAGELIST:
7083 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7085 case TB_SETDRAWTEXTFLAGS:
7086 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7088 case TB_SETEXTENDEDSTYLE:
7089 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7091 case TB_SETHOTIMAGELIST:
7092 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7095 return TOOLBAR_SetHotItem (hwnd, wParam);
7097 case TB_SETIMAGELIST:
7098 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7101 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7103 case TB_SETINSERTMARK:
7104 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7106 case TB_SETINSERTMARKCOLOR:
7107 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7109 case TB_SETMAXTEXTROWS:
7110 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7113 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7116 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7119 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7122 return TOOLBAR_SetState (hwnd, wParam, lParam);
7125 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7127 case TB_SETTOOLTIPS:
7128 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7130 case TB_SETUNICODEFORMAT:
7131 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7134 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7137 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7140 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7143 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7146 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7149 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7151 /* Common Control Messages */
7153 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7154 case CCM_GETCOLORSCHEME:
7155 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7157 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7158 case CCM_SETCOLORSCHEME:
7159 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7161 case CCM_GETVERSION:
7162 return TOOLBAR_GetVersion (hwnd);
7164 case CCM_SETVERSION:
7165 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7171 return TOOLBAR_Create (hwnd, wParam, lParam);
7174 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7177 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7180 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7183 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7185 /* case WM_KILLFOCUS: */
7187 case WM_LBUTTONDBLCLK:
7188 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7190 case WM_LBUTTONDOWN:
7191 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7194 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7197 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7199 case WM_RBUTTONDBLCLK:
7200 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7203 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7206 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7208 case WM_CAPTURECHANGED:
7209 return TOOLBAR_CaptureChanged(hwnd);
7212 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7215 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7218 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7221 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7224 return TOOLBAR_Notify (hwnd, wParam, lParam);
7226 case WM_NOTIFYFORMAT:
7227 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7229 case WM_PRINTCLIENT:
7231 return TOOLBAR_Paint (hwnd, wParam);
7234 return TOOLBAR_SetFocus (hwnd, wParam);
7237 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7240 return TOOLBAR_Size (hwnd, wParam, lParam);
7242 case WM_STYLECHANGED:
7243 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7245 case WM_SYSCOLORCHANGE:
7246 return TOOLBAR_SysColorChange (hwnd);
7248 case WM_THEMECHANGED:
7249 return theme_changed (hwnd);
7251 /* case WM_WININICHANGE: */
7256 case WM_MEASUREITEM:
7258 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7260 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7261 case PGM_FORWARDMOUSE:
7262 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7265 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7266 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7267 uMsg, wParam, lParam);
7268 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7274 TOOLBAR_Register (void)
7278 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7279 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7280 wndClass.lpfnWndProc = ToolbarWindowProc;
7281 wndClass.cbClsExtra = 0;
7282 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7283 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7284 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7285 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7287 RegisterClassW (&wndClass);
7292 TOOLBAR_Unregister (void)
7294 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7297 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7302 /* Check if the entry already exists */
7303 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7305 /* If this is a new entry we must create it and insert into the array */
7310 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7313 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7314 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7329 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7333 for (i = 0; i < *cies; i++)
7343 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7351 for (i = 0; i < cies; i++)
7353 if (pies[i]->id == id)
7365 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7367 HIMAGELIST himlDef = 0;
7368 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7371 himlDef = pie->himl;
7377 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7379 if (infoPtr->bUnicode)
7380 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7387 nmtba.iItem = nmtb->iItem;
7388 nmtba.pszText = Buffer;
7389 nmtba.cchText = 256;
7390 ZeroMemory(nmtba.pszText, nmtba.cchText);
7392 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7394 int ccht = strlen(nmtba.pszText);
7396 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7397 nmtb->pszText, nmtb->cchText);
7399 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7408 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7409 int iItem, PCUSTOMBUTTON btnInfo)
7413 /* MSDN states that iItem is the index of the button, rather than the
7414 * command ID as used by every other NMTOOLBAR notification */
7416 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7418 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);