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 if (infoPtr->nNumBitmapInfos == 0)
2756 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2760 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2761 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2762 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos * sizeof(TBITMAP_INFO));
2765 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2766 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2767 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2769 infoPtr->nNumBitmapInfos++;
2770 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2774 INT imagecount = ImageList_GetImageCount(himlDef);
2776 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2778 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",
2779 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2780 infoPtr->nNumBitmaps+nButtons,imagecount);
2782 infoPtr->nNumBitmaps = imagecount;
2785 infoPtr->nNumBitmaps += nButtons;
2788 InvalidateRect(hwnd, NULL, TRUE);
2795 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2798 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2799 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2801 TRACE("adding %d buttons!\n", wParam);
2803 nAddButtons = (UINT)wParam;
2804 nOldButtons = infoPtr->nNumButtons;
2805 nNewButtons = nOldButtons + nAddButtons;
2807 if (infoPtr->nNumButtons == 0) {
2809 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2812 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2814 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2815 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2816 nOldButtons * sizeof(TBUTTON_INFO));
2820 infoPtr->nNumButtons = nNewButtons;
2822 /* insert new button data */
2823 for (nCount = 0; nCount < nAddButtons; nCount++) {
2824 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2825 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2826 btnPtr->idCommand = lpTbb[nCount].idCommand;
2827 btnPtr->fsState = lpTbb[nCount].fsState;
2828 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2829 btnPtr->dwData = lpTbb[nCount].dwData;
2830 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2831 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2833 btnPtr->iString = lpTbb[nCount].iString;
2834 btnPtr->bHot = FALSE;
2836 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2839 ZeroMemory (&ti, sizeof(ti));
2840 ti.cbSize = sizeof(ti);
2842 ti.uId = btnPtr->idCommand;
2844 ti.lpszText = LPSTR_TEXTCALLBACKW;
2846 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2851 TOOLBAR_CalcToolbar (hwnd);
2852 TOOLBAR_AutoSize (hwnd);
2854 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2856 InvalidateRect(hwnd, NULL, TRUE);
2863 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2866 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2867 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2869 TRACE("adding %d buttons!\n", wParam);
2871 nAddButtons = (UINT)wParam;
2872 nOldButtons = infoPtr->nNumButtons;
2873 nNewButtons = nOldButtons + nAddButtons;
2875 if (infoPtr->nNumButtons == 0) {
2877 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2880 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2882 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2883 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2884 nOldButtons * sizeof(TBUTTON_INFO));
2888 infoPtr->nNumButtons = nNewButtons;
2890 /* insert new button data */
2891 for (nCount = 0; nCount < nAddButtons; nCount++) {
2892 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2893 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2894 btnPtr->idCommand = lpTbb[nCount].idCommand;
2895 btnPtr->fsState = lpTbb[nCount].fsState;
2896 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2897 btnPtr->dwData = lpTbb[nCount].dwData;
2898 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2899 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2901 btnPtr->iString = lpTbb[nCount].iString;
2902 btnPtr->bHot = FALSE;
2904 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2907 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2908 ti.cbSize = sizeof (TTTOOLINFOW);
2910 ti.uId = btnPtr->idCommand;
2912 ti.lpszText = LPSTR_TEXTCALLBACKW;
2915 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2920 TOOLBAR_CalcToolbar (hwnd);
2921 TOOLBAR_AutoSize (hwnd);
2923 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2925 InvalidateRect(hwnd, NULL, TRUE);
2932 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2937 if ((wParam) && (HIWORD(lParam) == 0)) {
2940 TRACE("adding string from resource!\n");
2942 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2944 TRACE("len=%d \"%s\"\n", len, szString);
2945 nIndex = infoPtr->nNumStrings;
2946 if (infoPtr->nNumStrings == 0) {
2948 Alloc (sizeof(LPWSTR));
2951 LPWSTR *oldStrings = infoPtr->strings;
2953 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2954 memcpy (&infoPtr->strings[0], &oldStrings[0],
2955 sizeof(LPWSTR) * infoPtr->nNumStrings);
2959 /*Alloc zeros out the allocated memory*/
2960 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2961 infoPtr->nNumStrings++;
2964 LPSTR p = (LPSTR)lParam;
2969 TRACE("adding string(s) from array!\n");
2971 nIndex = infoPtr->nNumStrings;
2974 TRACE("len=%d \"%s\"\n", len, p);
2976 if (infoPtr->nNumStrings == 0) {
2978 Alloc (sizeof(LPWSTR));
2981 LPWSTR *oldStrings = infoPtr->strings;
2983 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2984 memcpy (&infoPtr->strings[0], &oldStrings[0],
2985 sizeof(LPWSTR) * infoPtr->nNumStrings);
2989 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2990 infoPtr->nNumStrings++;
3001 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3003 #define MAX_RESOURCE_STRING_LENGTH 512
3004 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3007 if ((wParam) && (HIWORD(lParam) == 0)) {
3008 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3010 TRACE("adding string from resource!\n");
3012 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
3013 szString, MAX_RESOURCE_STRING_LENGTH);
3015 TRACE("len=%d %s\n", len, debugstr_w(szString));
3016 TRACE("First char: 0x%x\n", *szString);
3017 if (szString[0] == L'|')
3019 PWSTR p = szString + 1;
3021 nIndex = infoPtr->nNumStrings;
3022 while (*p != L'|' && *p != L'\0') {
3025 if (infoPtr->nNumStrings == 0) {
3026 infoPtr->strings = Alloc (sizeof(LPWSTR));
3030 LPWSTR *oldStrings = infoPtr->strings;
3031 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3032 memcpy(&infoPtr->strings[0], &oldStrings[0],
3033 sizeof(LPWSTR) * infoPtr->nNumStrings);
3037 np=strchrW (p, '|');
3045 TRACE("len=%d %s\n", len, debugstr_w(p));
3046 infoPtr->strings[infoPtr->nNumStrings] =
3047 Alloc (sizeof(WCHAR)*(len+1));
3048 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3049 infoPtr->nNumStrings++;
3056 nIndex = infoPtr->nNumStrings;
3057 if (infoPtr->nNumStrings == 0) {
3059 Alloc (sizeof(LPWSTR));
3062 LPWSTR *oldStrings = infoPtr->strings;
3064 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3065 memcpy (&infoPtr->strings[0], &oldStrings[0],
3066 sizeof(LPWSTR) * infoPtr->nNumStrings);
3070 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3071 infoPtr->nNumStrings++;
3075 LPWSTR p = (LPWSTR)lParam;
3080 TRACE("adding string(s) from array!\n");
3081 nIndex = infoPtr->nNumStrings;
3085 TRACE("len=%d %s\n", len, debugstr_w(p));
3086 if (infoPtr->nNumStrings == 0) {
3088 Alloc (sizeof(LPWSTR));
3091 LPWSTR *oldStrings = infoPtr->strings;
3093 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3094 memcpy (&infoPtr->strings[0], &oldStrings[0],
3095 sizeof(LPWSTR) * infoPtr->nNumStrings);
3099 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3100 infoPtr->nNumStrings++;
3111 TOOLBAR_AutoSize (HWND hwnd)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3119 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3121 parent = GetParent (hwnd);
3123 if (!parent || !infoPtr->bDoRedraw)
3126 GetClientRect(parent, &parent_rect);
3128 x = parent_rect.left;
3129 y = parent_rect.top;
3131 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3133 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3134 cx = parent_rect.right - parent_rect.left;
3136 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3138 TOOLBAR_CalcToolbar(hwnd);
3139 InvalidateRect( hwnd, NULL, TRUE );
3142 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3145 UINT uPosFlags = SWP_NOZORDER;
3147 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3149 GetWindowRect(hwnd, &window_rect);
3150 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3151 y = window_rect.top;
3153 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3155 GetWindowRect(hwnd, &window_rect);
3156 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3159 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3160 uPosFlags |= SWP_NOMOVE;
3162 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3163 cy += GetSystemMetrics(SM_CYEDGE);
3165 if (infoPtr->dwStyle & WS_BORDER)
3167 x = y = 1; /* FIXME: this looks wrong */
3168 cy += GetSystemMetrics(SM_CYEDGE);
3169 cx += GetSystemMetrics(SM_CXEDGE);
3172 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3180 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3184 return infoPtr->nNumButtons;
3189 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3193 infoPtr->dwStructSize = (DWORD)wParam;
3200 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3203 TBUTTON_INFO *btnPtr;
3206 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3208 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3212 btnPtr = &infoPtr->buttons[nIndex];
3213 btnPtr->iBitmap = LOWORD(lParam);
3215 /* we HAVE to erase the background, the new bitmap could be */
3217 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3224 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3226 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3227 TBUTTON_INFO *btnPtr;
3230 BOOL bChecked = FALSE;
3232 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3234 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3239 btnPtr = &infoPtr->buttons[nIndex];
3241 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3243 if (LOWORD(lParam) == FALSE)
3244 btnPtr->fsState &= ~TBSTATE_CHECKED;
3246 if (btnPtr->fsStyle & BTNS_GROUP) {
3248 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3249 if (nOldIndex == nIndex)
3251 if (nOldIndex != -1)
3252 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3254 btnPtr->fsState |= TBSTATE_CHECKED;
3257 if( bChecked != LOWORD(lParam) )
3259 if (nOldIndex != -1)
3260 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3261 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3264 /* FIXME: Send a WM_NOTIFY?? */
3271 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3275 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3280 TOOLBAR_Customize (HWND hwnd)
3282 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3283 CUSTDLG_INFO custInfo;
3289 custInfo.tbInfo = infoPtr;
3290 custInfo.tbHwnd = hwnd;
3292 /* send TBN_BEGINADJUST notification */
3293 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3295 if (!(hRes = FindResourceW (COMCTL32_hModule,
3296 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3297 (LPWSTR)RT_DIALOG)))
3300 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3303 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3304 (LPCDLGTEMPLATEW)template,
3306 TOOLBAR_CustomizeDialogProc,
3309 /* send TBN_ENDADJUST notification */
3310 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3317 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3319 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3320 INT nIndex = (INT)wParam;
3322 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3324 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3327 memset(&nmtb, 0, sizeof(nmtb));
3328 nmtb.iItem = btnPtr->idCommand;
3329 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3330 nmtb.tbButton.idCommand = btnPtr->idCommand;
3331 nmtb.tbButton.fsState = btnPtr->fsState;
3332 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3333 nmtb.tbButton.dwData = btnPtr->dwData;
3334 nmtb.tbButton.iString = btnPtr->iString;
3335 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3337 if ((infoPtr->hwndToolTip) &&
3338 !(btnPtr->fsStyle & BTNS_SEP)) {
3341 ZeroMemory (&ti, sizeof(ti));
3342 ti.cbSize = sizeof(ti);
3344 ti.uId = infoPtr->buttons[nIndex].idCommand;
3346 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3349 if (infoPtr->nNumButtons == 1) {
3350 TRACE(" simple delete!\n");
3351 Free (infoPtr->buttons);
3352 infoPtr->buttons = NULL;
3353 infoPtr->nNumButtons = 0;
3356 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3357 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3359 infoPtr->nNumButtons--;
3360 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3362 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3363 nIndex * sizeof(TBUTTON_INFO));
3366 if (nIndex < infoPtr->nNumButtons) {
3367 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3368 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3374 TOOLBAR_CalcToolbar (hwnd);
3376 InvalidateRect (hwnd, NULL, TRUE);
3383 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3386 TBUTTON_INFO *btnPtr;
3390 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3392 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3397 btnPtr = &infoPtr->buttons[nIndex];
3399 bState = btnPtr->fsState & TBSTATE_ENABLED;
3401 /* update the toolbar button state */
3402 if(LOWORD(lParam) == FALSE) {
3403 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3405 btnPtr->fsState |= TBSTATE_ENABLED;
3408 /* redraw the button only if the state of the button changed */
3409 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3410 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3416 static inline LRESULT
3417 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3421 return infoPtr->bAnchor;
3426 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3431 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3435 return infoPtr->buttons[nIndex].iBitmap;
3439 static inline LRESULT
3440 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3442 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3447 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3450 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3451 INT nIndex = (INT)wParam;
3452 TBUTTON_INFO *btnPtr;
3457 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3460 btnPtr = &infoPtr->buttons[nIndex];
3461 lpTbb->iBitmap = btnPtr->iBitmap;
3462 lpTbb->idCommand = btnPtr->idCommand;
3463 lpTbb->fsState = btnPtr->fsState;
3464 lpTbb->fsStyle = btnPtr->fsStyle;
3465 lpTbb->bReserved[0] = 0;
3466 lpTbb->bReserved[1] = 0;
3467 lpTbb->dwData = btnPtr->dwData;
3468 lpTbb->iString = btnPtr->iString;
3475 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3477 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3478 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3479 TBUTTON_INFO *btnPtr;
3482 if (lpTbInfo == NULL)
3484 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3487 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3488 lpTbInfo->dwMask & 0x80000000);
3492 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3494 if (lpTbInfo->dwMask & TBIF_COMMAND)
3495 lpTbInfo->idCommand = btnPtr->idCommand;
3496 if (lpTbInfo->dwMask & TBIF_IMAGE)
3497 lpTbInfo->iImage = btnPtr->iBitmap;
3498 if (lpTbInfo->dwMask & TBIF_LPARAM)
3499 lpTbInfo->lParam = btnPtr->dwData;
3500 if (lpTbInfo->dwMask & TBIF_SIZE)
3501 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3502 if (lpTbInfo->dwMask & TBIF_STATE)
3503 lpTbInfo->fsState = btnPtr->fsState;
3504 if (lpTbInfo->dwMask & TBIF_STYLE)
3505 lpTbInfo->fsStyle = btnPtr->fsStyle;
3506 if (lpTbInfo->dwMask & TBIF_TEXT) {
3507 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3508 can't use TOOLBAR_GetText here */
3510 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3511 lpText = (LPWSTR)btnPtr->iString;
3512 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3514 lpTbInfo->pszText[0] = '\0';
3521 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3524 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3525 TBUTTON_INFO *btnPtr;
3528 if (lpTbInfo == NULL)
3530 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3533 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3534 lpTbInfo->dwMask & 0x80000000);
3538 btnPtr = &infoPtr->buttons[nIndex];
3543 if (lpTbInfo->dwMask & TBIF_COMMAND)
3544 lpTbInfo->idCommand = btnPtr->idCommand;
3545 if (lpTbInfo->dwMask & TBIF_IMAGE)
3546 lpTbInfo->iImage = btnPtr->iBitmap;
3547 if (lpTbInfo->dwMask & TBIF_LPARAM)
3548 lpTbInfo->lParam = btnPtr->dwData;
3549 if (lpTbInfo->dwMask & TBIF_SIZE)
3550 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3551 if (lpTbInfo->dwMask & TBIF_STATE)
3552 lpTbInfo->fsState = btnPtr->fsState;
3553 if (lpTbInfo->dwMask & TBIF_STYLE)
3554 lpTbInfo->fsStyle = btnPtr->fsStyle;
3555 if (lpTbInfo->dwMask & TBIF_TEXT) {
3556 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3557 can't use TOOLBAR_GetText here */
3559 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3560 lpText = (LPWSTR)btnPtr->iString;
3561 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3563 lpTbInfo->pszText[0] = '\0';
3571 TOOLBAR_GetButtonSize (HWND hwnd)
3573 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3575 if (infoPtr->nNumButtons > 0)
3576 return MAKELONG((WORD)infoPtr->nButtonWidth,
3577 (WORD)infoPtr->nButtonHeight);
3579 return MAKELONG(23,22);
3584 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3586 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3597 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3599 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3600 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3605 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3612 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3616 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3620 ret = strlenW (lpText);
3623 strcpyW ((LPWSTR)lParam, lpText);
3631 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3633 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3634 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3635 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3639 inline static LRESULT
3640 TOOLBAR_GetExtendedStyle (HWND hwnd)
3642 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3646 return infoPtr->dwExStyle;
3651 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3653 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3654 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3655 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3660 TOOLBAR_GetHotItem (HWND hwnd)
3662 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3664 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3667 if (infoPtr->nHotItem < 0)
3670 return (LRESULT)infoPtr->nHotItem;
3675 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3677 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3678 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3679 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3684 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3687 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3689 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3691 *lptbim = infoPtr->tbim;
3698 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3700 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3702 TRACE("hwnd = %p\n", hwnd);
3704 return (LRESULT)infoPtr->clrInsertMark;
3709 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3711 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3712 TBUTTON_INFO *btnPtr;
3716 nIndex = (INT)wParam;
3717 btnPtr = &infoPtr->buttons[nIndex];
3718 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3720 lpRect = (LPRECT)lParam;
3723 if (btnPtr->fsState & TBSTATE_HIDDEN)
3726 lpRect->left = btnPtr->rect.left;
3727 lpRect->right = btnPtr->rect.right;
3728 lpRect->bottom = btnPtr->rect.bottom;
3729 lpRect->top = btnPtr->rect.top;
3736 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3739 LPSIZE lpSize = (LPSIZE)lParam;
3744 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3745 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3747 TRACE("maximum size %ld x %ld\n",
3748 infoPtr->rcBound.right - infoPtr->rcBound.left,
3749 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3755 /* << TOOLBAR_GetObject >> */
3759 TOOLBAR_GetPadding (HWND hwnd)
3761 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3764 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3765 return (LRESULT) oldPad;
3770 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3772 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3773 TBUTTON_INFO *btnPtr;
3777 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3778 btnPtr = &infoPtr->buttons[nIndex];
3779 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3781 lpRect = (LPRECT)lParam;
3785 lpRect->left = btnPtr->rect.left;
3786 lpRect->right = btnPtr->rect.right;
3787 lpRect->bottom = btnPtr->rect.bottom;
3788 lpRect->top = btnPtr->rect.top;
3795 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3799 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3800 return infoPtr->nRows;
3807 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3812 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3816 return infoPtr->buttons[nIndex].fsState;
3821 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3823 return GetWindowLongW(hwnd, GWL_STYLE);
3828 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3832 return infoPtr->nMaxTextRows;
3837 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3841 return (LRESULT)infoPtr->hwndToolTip;
3846 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3848 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3850 TRACE("%s hwnd=%p\n",
3851 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3853 return infoPtr->bUnicode;
3857 inline static LRESULT
3858 TOOLBAR_GetVersion (HWND hwnd)
3860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3861 return infoPtr->iVersion;
3866 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 TBUTTON_INFO *btnPtr;
3874 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3878 btnPtr = &infoPtr->buttons[nIndex];
3879 if (LOWORD(lParam) == FALSE)
3880 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3882 btnPtr->fsState |= TBSTATE_HIDDEN;
3884 TOOLBAR_CalcToolbar (hwnd);
3886 InvalidateRect (hwnd, NULL, TRUE);
3892 inline static LRESULT
3893 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3895 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3900 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3902 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3903 TBUTTON_INFO *btnPtr;
3907 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3911 btnPtr = &infoPtr->buttons[nIndex];
3912 oldState = btnPtr->fsState;
3913 if (LOWORD(lParam) == FALSE)
3914 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3916 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3918 if(oldState != btnPtr->fsState)
3919 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3926 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3929 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3930 INT nIndex = (INT)wParam;
3931 TBUTTON_INFO *oldButtons;
3936 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3939 /* EPP: this seems to be an undocumented call (from my IE4)
3940 * I assume in that case that:
3941 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3942 * - index of insertion is at the end of existing buttons
3943 * I only see this happen with nIndex == -1, but it could have a special
3944 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3946 nIndex = infoPtr->nNumButtons;
3948 } else if (nIndex < 0)
3951 /* If the string passed is not an index, assume address of string
3952 and do our own AddString */
3953 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3957 TRACE("string %s passed instead of index, adding string\n",
3958 debugstr_a((LPSTR)lpTbb->iString));
3959 len = strlen((LPSTR)lpTbb->iString) + 2;
3961 strcpy(ptr, (LPSTR)lpTbb->iString);
3962 ptr[len - 1] = 0; /* ended by two '\0' */
3963 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3967 TRACE("inserting button index=%d\n", nIndex);
3968 if (nIndex > infoPtr->nNumButtons) {
3969 nIndex = infoPtr->nNumButtons;
3970 TRACE("adjust index=%d\n", nIndex);
3973 oldButtons = infoPtr->buttons;
3974 infoPtr->nNumButtons++;
3975 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3976 /* pre insert copy */
3978 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3979 nIndex * sizeof(TBUTTON_INFO));
3982 /* insert new button */
3983 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3984 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3985 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3986 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3987 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3988 /* if passed string and not index, then add string */
3989 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3990 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3993 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3995 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3998 ZeroMemory (&ti, sizeof(ti));
3999 ti.cbSize = sizeof (ti);
4001 ti.uId = lpTbb->idCommand;
4003 ti.lpszText = LPSTR_TEXTCALLBACKW;
4005 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4009 /* post insert copy */
4010 if (nIndex < infoPtr->nNumButtons - 1) {
4011 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4012 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4017 TOOLBAR_CalcToolbar (hwnd);
4018 TOOLBAR_AutoSize (hwnd);
4020 InvalidateRect (hwnd, NULL, TRUE);
4027 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4030 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4031 INT nIndex = (INT)wParam;
4032 TBUTTON_INFO *oldButtons;
4037 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4040 /* EPP: this seems to be an undocumented call (from my IE4)
4041 * I assume in that case that:
4042 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4043 * - index of insertion is at the end of existing buttons
4044 * I only see this happen with nIndex == -1, but it could have a special
4045 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4047 nIndex = infoPtr->nNumButtons;
4049 } else if (nIndex < 0)
4052 /* If the string passed is not an index, assume address of string
4053 and do our own AddString */
4054 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4058 TRACE("string %s passed instead of index, adding string\n",
4059 debugstr_w((LPWSTR)lpTbb->iString));
4060 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4061 ptr = Alloc(len*sizeof(WCHAR));
4062 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4063 ptr[len - 1] = 0; /* ended by two '\0' */
4064 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4068 TRACE("inserting button index=%d\n", nIndex);
4069 if (nIndex > infoPtr->nNumButtons) {
4070 nIndex = infoPtr->nNumButtons;
4071 TRACE("adjust index=%d\n", nIndex);
4074 oldButtons = infoPtr->buttons;
4075 infoPtr->nNumButtons++;
4076 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4077 /* pre insert copy */
4079 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4080 nIndex * sizeof(TBUTTON_INFO));
4083 /* insert new button */
4084 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4085 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4086 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4087 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4088 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4089 /* if passed string and not index, then add string */
4090 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4091 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4094 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4096 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4099 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4100 ti.cbSize = sizeof (TTTOOLINFOW);
4102 ti.uId = lpTbb->idCommand;
4104 ti.lpszText = LPSTR_TEXTCALLBACKW;
4106 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4110 /* post insert copy */
4111 if (nIndex < infoPtr->nNumButtons - 1) {
4112 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4113 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4118 TOOLBAR_CalcToolbar (hwnd);
4119 TOOLBAR_AutoSize (hwnd);
4121 InvalidateRect (hwnd, NULL, TRUE);
4127 /* << TOOLBAR_InsertMarkHitTest >> */
4131 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4136 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4140 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4145 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4150 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4154 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4159 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4164 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4168 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4173 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4178 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4182 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4187 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4189 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4192 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4196 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4201 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4206 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4210 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4215 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4218 tbab.hInst = (HINSTANCE)lParam;
4219 tbab.nID = (UINT_PTR)wParam;
4221 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4223 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4228 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4230 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4231 WCHAR wAccel = (WCHAR)wParam;
4232 UINT* pIDButton = (UINT*)lParam;
4233 WCHAR wszAccel[] = {'&',wAccel,0};
4236 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4237 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4239 for (i = 0; i < infoPtr->nNumButtons; i++)
4241 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4242 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4243 !(btnPtr->fsState & TBSTATE_HIDDEN))
4245 int iLen = strlenW(wszAccel);
4246 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4253 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4258 if (!strncmpiW(lpszStr, wszAccel, iLen))
4260 *pIDButton = btnPtr->idCommand;
4272 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4277 TBUTTON_INFO *btnPtr;
4279 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4281 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4285 btnPtr = &infoPtr->buttons[nIndex];
4286 oldState = btnPtr->fsState;
4289 btnPtr->fsState |= TBSTATE_MARKED;
4291 btnPtr->fsState &= ~TBSTATE_MARKED;
4293 if(oldState != btnPtr->fsState)
4294 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4300 /* fixes up an index of a button affected by a move */
4301 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4305 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4307 else if (*pIndex == nIndex)
4308 *pIndex = nMoveIndex;
4312 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4314 else if (*pIndex == nIndex)
4315 *pIndex = nMoveIndex;
4321 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4326 INT nMoveIndex = (INT)lParam;
4327 TBUTTON_INFO button;
4329 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4332 if ((nIndex == -1) || (nMoveIndex < 0))
4335 if (nMoveIndex > infoPtr->nNumButtons - 1)
4336 nMoveIndex = infoPtr->nNumButtons - 1;
4338 button = infoPtr->buttons[nIndex];
4340 /* move button right */
4341 if (nIndex < nMoveIndex)
4343 nCount = nMoveIndex - nIndex;
4344 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4345 infoPtr->buttons[nMoveIndex] = button;
4347 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4348 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4349 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4350 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4352 else if (nIndex > nMoveIndex) /* move button left */
4354 nCount = nIndex - nMoveIndex;
4355 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4356 infoPtr->buttons[nMoveIndex] = button;
4358 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4359 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4360 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4361 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4364 TOOLBAR_CalcToolbar(hwnd);
4365 TOOLBAR_AutoSize(hwnd);
4366 InvalidateRect(hwnd, NULL, TRUE);
4373 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4376 TBUTTON_INFO *btnPtr;
4380 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4384 btnPtr = &infoPtr->buttons[nIndex];
4385 oldState = btnPtr->fsState;
4386 if (LOWORD(lParam) == FALSE)
4387 btnPtr->fsState &= ~TBSTATE_PRESSED;
4389 btnPtr->fsState |= TBSTATE_PRESSED;
4391 if(oldState != btnPtr->fsState)
4392 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4397 /* FIXME: there might still be some confusion her between number of buttons
4398 * and number of bitmaps */
4400 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4402 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4403 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4405 HBITMAP hbmLoad = NULL;
4406 int i = 0, nOldButtons = 0, pos = 0;
4407 int nOldBitmaps, nNewBitmaps = 0;
4408 HIMAGELIST himlDef = 0;
4410 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4411 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4412 lpReplace->nButtons);
4414 if (lpReplace->hInstOld == HINST_COMMCTRL)
4416 FIXME("changing standard bitmaps not implemented\n");
4419 else if (lpReplace->hInstOld != 0)
4420 FIXME("resources not in the current module not implemented\n");
4422 if (lpReplace->hInstNew)
4424 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4429 hBitmap = (HBITMAP) lpReplace->nIDNew;
4432 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4433 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4434 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4435 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4436 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4438 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4439 nOldButtons = tbi->nButtons;
4440 tbi->nButtons = lpReplace->nButtons;
4441 tbi->hInst = lpReplace->hInstNew;
4442 tbi->nID = lpReplace->nIDNew;
4443 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4446 pos += tbi->nButtons;
4449 if (nOldButtons == 0)
4451 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4453 DeleteObject (hbmLoad);
4457 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4458 nOldBitmaps = ImageList_GetImageCount(himlDef);
4460 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4462 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4463 ImageList_Remove(himlDef, i);
4468 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4469 HDC hdcImage, hdcBitmap;
4471 /* copy the bitmap before adding it so that the user's bitmap
4472 * doesn't get modified.
4474 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4476 hdcImage = CreateCompatibleDC(0);
4477 hdcBitmap = CreateCompatibleDC(0);
4479 /* create new bitmap */
4480 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4481 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4482 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4484 /* Copy the user's image */
4485 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4486 hdcBitmap, 0, 0, SRCCOPY);
4488 SelectObject (hdcImage, hOldBitmapLoad);
4489 SelectObject (hdcBitmap, hOldBitmapBitmap);
4490 DeleteDC (hdcImage);
4491 DeleteDC (hdcBitmap);
4493 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4494 nNewBitmaps = ImageList_GetImageCount(himlDef);
4495 DeleteObject (hbmLoad);
4498 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4500 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4501 pos, nOldBitmaps, nNewBitmaps);
4503 InvalidateRect(hwnd, NULL, TRUE);
4506 DeleteObject (hbmLoad);
4511 /* helper for TOOLBAR_SaveRestoreW */
4513 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4515 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4516 debugstr_w(lpSave->pszValueName));
4522 /* helper for TOOLBAR_Restore */
4524 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4529 ZeroMemory(&ti, sizeof(ti));
4530 ti.cbSize = sizeof(ti);
4531 ti.hwnd = infoPtr->hwndSelf;
4533 for (i = 0; i < infoPtr->nNumButtons; i++)
4535 if ((infoPtr->hwndToolTip) &&
4536 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4538 ti.uId = infoPtr->buttons[i].idCommand;
4539 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4543 Free(infoPtr->buttons);
4544 infoPtr->buttons = NULL;
4545 infoPtr->nNumButtons = 0;
4549 /* helper for TOOLBAR_SaveRestoreW */
4551 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4560 /* restore toolbar information */
4561 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4562 debugstr_w(lpSave->pszValueName));
4564 memset(&nmtbr, 0, sizeof(nmtbr));
4566 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4567 KEY_QUERY_VALUE, &hkey);
4569 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4571 if (!res && dwType != REG_BINARY)
4572 res = ERROR_FILE_NOT_FOUND;
4575 nmtbr.pData = Alloc(dwSize);
4576 nmtbr.cbData = (UINT)dwSize;
4577 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4580 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4581 (LPBYTE)nmtbr.pData, &dwSize);
4584 nmtbr.pCurrent = nmtbr.pData;
4586 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4587 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4589 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4593 /* remove all existing buttons as this function is designed to
4594 * restore the toolbar to a previously saved state */
4595 TOOLBAR_DeleteAllButtons(infoPtr);
4597 for (i = 0; i < nmtbr.cButtons; i++)
4600 nmtbr.tbButton.iBitmap = -1;
4601 nmtbr.tbButton.fsState = 0;
4602 nmtbr.tbButton.fsStyle = 0;
4603 nmtbr.tbButton.idCommand = 0;
4604 if (*nmtbr.pCurrent == (DWORD)-1)
4607 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4608 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4610 else if (*nmtbr.pCurrent == (DWORD)-2)
4612 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4614 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4618 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4620 /* can't contain real string as we don't know whether
4621 * the client put an ANSI or Unicode string in there */
4622 if (HIWORD(nmtbr.tbButton.iString))
4623 nmtbr.tbButton.iString = 0;
4625 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4626 (LPARAM)&nmtbr.tbButton);
4629 /* do legacy notifications */
4630 if (infoPtr->iVersion < 5)
4632 /* FIXME: send TBN_BEGINADJUST */
4633 FIXME("send TBN_GETBUTTONINFO for each button\n");
4634 /* FIXME: send TBN_ENDADJUST */
4637 /* remove all uninitialised buttons
4638 * note: loop backwards to avoid having to fixup i on a
4640 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4641 if (infoPtr->buttons[i].iBitmap == -1)
4642 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4644 /* only indicate success if at least one button survived */
4645 if (infoPtr->nNumButtons > 0) ret = TRUE;
4656 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4660 if (lpSave == NULL) return 0;
4663 return TOOLBAR_Save(infoPtr, lpSave);
4665 return TOOLBAR_Restore(infoPtr, lpSave);
4670 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4672 LPWSTR pszValueName = 0, pszSubKey = 0;
4673 TBSAVEPARAMSW SaveW;
4677 if (lpSave == NULL) return 0;
4679 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4680 pszSubKey = Alloc(len * sizeof(WCHAR));
4681 if (pszSubKey) goto exit;
4682 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4684 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4685 pszValueName = Alloc(len * sizeof(WCHAR));
4686 if (!pszValueName) goto exit;
4687 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4689 SaveW.pszValueName = pszValueName;
4690 SaveW.pszSubKey = pszSubKey;
4691 SaveW.hkr = lpSave->hkr;
4692 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4695 Free (pszValueName);
4703 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4705 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4706 BOOL bOldAnchor = infoPtr->bAnchor;
4708 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4710 infoPtr->bAnchor = (BOOL)wParam;
4712 /* Native does not remove the hot effect from an already hot button */
4714 return (LRESULT)bOldAnchor;
4719 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4721 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4722 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4724 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4727 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4729 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4730 lParam = MAKELPARAM(16, 15);
4732 if (infoPtr->nNumButtons > 0)
4733 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4734 infoPtr->nNumButtons,
4735 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4736 LOWORD(lParam), HIWORD(lParam));
4738 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4739 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4742 if ((himlDef == infoPtr->himlInt) &&
4743 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4745 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4746 infoPtr->nBitmapHeight);
4754 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4757 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4758 TBUTTON_INFO *btnPtr;
4764 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4767 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4768 lptbbi->dwMask & 0x80000000);
4772 btnPtr = &infoPtr->buttons[nIndex];
4773 if (lptbbi->dwMask & TBIF_COMMAND)
4774 btnPtr->idCommand = lptbbi->idCommand;
4775 if (lptbbi->dwMask & TBIF_IMAGE)
4776 btnPtr->iBitmap = lptbbi->iImage;
4777 if (lptbbi->dwMask & TBIF_LPARAM)
4778 btnPtr->dwData = lptbbi->lParam;
4779 if (lptbbi->dwMask & TBIF_SIZE)
4780 btnPtr->cx = lptbbi->cx;
4781 if (lptbbi->dwMask & TBIF_STATE)
4782 btnPtr->fsState = lptbbi->fsState;
4783 if (lptbbi->dwMask & TBIF_STYLE)
4784 btnPtr->fsStyle = lptbbi->fsStyle;
4786 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4787 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4788 /* iString is index, zero it to make Str_SetPtr succeed */
4791 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4794 /* save the button rect to see if we need to redraw the whole toolbar */
4795 oldBtnRect = btnPtr->rect;
4796 TOOLBAR_CalcToolbar(hwnd);
4798 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4799 InvalidateRect(hwnd, NULL, TRUE);
4801 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4808 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4811 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4812 TBUTTON_INFO *btnPtr;
4818 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4821 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4822 lptbbi->dwMask & 0x80000000);
4826 btnPtr = &infoPtr->buttons[nIndex];
4827 if (lptbbi->dwMask & TBIF_COMMAND)
4828 btnPtr->idCommand = lptbbi->idCommand;
4829 if (lptbbi->dwMask & TBIF_IMAGE)
4830 btnPtr->iBitmap = lptbbi->iImage;
4831 if (lptbbi->dwMask & TBIF_LPARAM)
4832 btnPtr->dwData = lptbbi->lParam;
4833 if (lptbbi->dwMask & TBIF_SIZE)
4834 btnPtr->cx = lptbbi->cx;
4835 if (lptbbi->dwMask & TBIF_STATE)
4836 btnPtr->fsState = lptbbi->fsState;
4837 if (lptbbi->dwMask & TBIF_STYLE)
4838 btnPtr->fsStyle = lptbbi->fsStyle;
4840 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4841 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4842 /* iString is index, zero it to make Str_SetPtr succeed */
4844 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4847 /* save the button rect to see if we need to redraw the whole toolbar */
4848 oldBtnRect = btnPtr->rect;
4849 TOOLBAR_CalcToolbar(hwnd);
4851 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4852 InvalidateRect(hwnd, NULL, TRUE);
4854 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4861 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4864 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4866 if ((cx < 0) || (cy < 0))
4868 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4872 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4874 /* The documentation claims you can only change the button size before
4875 * any button has been added. But this is wrong.
4876 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4877 * it to the toolbar, and it checks that the return value is nonzero - mjm
4878 * Further testing shows that we must actually perform the change too.
4881 * The documentation also does not mention that if 0 is supplied for
4882 * either size, the system changes it to the default of 24 wide and
4883 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4885 infoPtr->nButtonWidth = (cx) ? cx : 24;
4886 infoPtr->nButtonHeight = (cy) ? cy : 22;
4892 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4896 /* if setting to current values, ignore */
4897 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4898 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4899 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4900 infoPtr->cxMin, infoPtr->cxMax);
4904 /* save new values */
4905 infoPtr->cxMin = (INT)LOWORD(lParam);
4906 infoPtr->cxMax = (INT)HIWORD(lParam);
4908 /* otherwise we need to recalc the toolbar and in some cases
4909 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4910 which doesn't actually draw - GA). */
4911 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4912 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4914 TOOLBAR_CalcToolbar (hwnd);
4916 InvalidateRect (hwnd, NULL, TRUE);
4923 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4926 INT nIndex = (INT)wParam;
4928 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4931 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4933 if (infoPtr->hwndToolTip) {
4935 FIXME("change tool tip!\n");
4944 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4947 HIMAGELIST himl = (HIMAGELIST)lParam;
4948 HIMAGELIST himlTemp;
4951 if (infoPtr->iVersion >= 5)
4954 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4955 &infoPtr->cimlDis, himl, id);
4957 /* FIXME: redraw ? */
4959 return (LRESULT)himlTemp;
4964 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4966 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4969 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4971 dwTemp = infoPtr->dwDTFlags;
4972 infoPtr->dwDTFlags =
4973 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4975 return (LRESULT)dwTemp;
4978 /* This function differs a bit from what MSDN says it does:
4979 * 1. lParam contains extended style flags to OR with current style
4980 * (MSDN isn't clear on the OR bit)
4981 * 2. wParam appears to contain extended style flags to be reset
4982 * (MSDN says that this parameter is reserved)
4985 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4990 dwTemp = infoPtr->dwExStyle;
4991 infoPtr->dwExStyle &= ~wParam;
4992 infoPtr->dwExStyle |= (DWORD)lParam;
4994 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4996 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4997 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4998 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
5000 TOOLBAR_CalcToolbar (hwnd);
5002 TOOLBAR_AutoSize(hwnd);
5004 InvalidateRect(hwnd, NULL, TRUE);
5006 return (LRESULT)dwTemp;
5011 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5013 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5014 HIMAGELIST himlTemp;
5015 HIMAGELIST himl = (HIMAGELIST)lParam;
5018 if (infoPtr->iVersion >= 5)
5021 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
5023 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
5024 &infoPtr->cimlHot, himl, id);
5026 /* FIXME: redraw ? */
5028 return (LRESULT)himlTemp;
5032 /* Makes previous hot button no longer hot, makes the specified
5033 * button hot and sends appropriate notifications. dwReason is one or
5034 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5035 * NOTE 1: this function does not validate nHit
5036 * NOTE 2: the name of this function is completely made up and
5037 * not based on any documentation from Microsoft. */
5039 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5041 if (infoPtr->nHotItem != nHit)
5043 NMTBHOTITEM nmhotitem;
5044 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5045 LRESULT no_highlight;
5047 /* Remove the effect of an old hot button if the button was
5048 drawn with the hot button effect */
5049 if(infoPtr->nHotItem >= 0)
5051 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5052 oldBtnPtr->bHot = FALSE;
5055 infoPtr->nHotItem = nHit;
5057 /* It's not a separator or in nowhere. It's a hot button. */
5059 btnPtr = &infoPtr->buttons[nHit];
5061 nmhotitem.dwFlags = dwReason;
5063 nmhotitem.idOld = oldBtnPtr->idCommand;
5065 nmhotitem.dwFlags |= HICF_ENTERING;
5067 nmhotitem.idNew = btnPtr->idCommand;
5069 nmhotitem.dwFlags |= HICF_LEAVING;
5071 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5073 /* now invalidate the old and new buttons so they will be painted,
5074 * but only if they are enabled - disabled buttons cannot become hot */
5075 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5076 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5077 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5079 btnPtr->bHot = TRUE;
5080 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5086 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5089 INT nOldHotItem = infoPtr->nHotItem;
5091 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5093 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5096 /* NOTE: an application can still remove the hot item even if anchor
5097 * highlighting is enabled */
5099 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5100 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5102 if (nOldHotItem < 0)
5105 return (LRESULT)nOldHotItem;
5110 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5113 HIMAGELIST himlTemp;
5114 HIMAGELIST himl = (HIMAGELIST)lParam;
5117 if (infoPtr->iVersion >= 5)
5120 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5121 &infoPtr->cimlDef, himl, id);
5123 infoPtr->nNumBitmaps = 0;
5124 for (i = 0; i < infoPtr->cimlDef; i++)
5125 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5127 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5128 &infoPtr->nBitmapHeight))
5130 infoPtr->nBitmapWidth = 1;
5131 infoPtr->nBitmapHeight = 1;
5134 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5135 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5136 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5138 InvalidateRect(hwnd, NULL, TRUE);
5140 return (LRESULT)himlTemp;
5145 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5149 infoPtr->nIndent = (INT)wParam;
5153 /* process only on indent changing */
5154 if(infoPtr->nIndent != (INT)wParam)
5156 infoPtr->nIndent = (INT)wParam;
5157 TOOLBAR_CalcToolbar (hwnd);
5158 InvalidateRect(hwnd, NULL, FALSE);
5166 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5169 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5171 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5173 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5175 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5179 if ((lptbim->iButton == -1) ||
5180 ((lptbim->iButton < infoPtr->nNumButtons) &&
5181 (lptbim->iButton >= 0)))
5183 infoPtr->tbim = *lptbim;
5184 /* FIXME: don't need to update entire toolbar */
5185 InvalidateRect(hwnd, NULL, TRUE);
5188 ERR("Invalid button index %d\n", lptbim->iButton);
5195 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5199 infoPtr->clrInsertMark = (COLORREF)lParam;
5201 /* FIXME: don't need to update entire toolbar */
5202 InvalidateRect(hwnd, NULL, TRUE);
5209 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5213 infoPtr->nMaxTextRows = (INT)wParam;
5215 TOOLBAR_CalcToolbar(hwnd);
5220 /* MSDN gives slightly wrong info on padding.
5221 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5222 * 2. It is not used to create a blank area between the edge of the button
5223 * and the text or image if TBSTYLE_LIST is set. It is used to control
5224 * the gap between the image and text.
5225 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5226 * to control the bottom and right borders [with the border being
5227 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5228 * is shared evenly on both sides of the button.
5229 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5232 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5234 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5237 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5238 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5239 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5240 TRACE("cx=%ld, cy=%ld\n",
5241 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5242 return (LRESULT) oldPad;
5247 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5249 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5254 hwndOldNotify = infoPtr->hwndNotify;
5255 infoPtr->hwndNotify = (HWND)wParam;
5257 return (LRESULT)hwndOldNotify;
5262 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5265 LPRECT lprc = (LPRECT)lParam;
5269 if (LOWORD(wParam) > 1) {
5270 FIXME("multiple rows not supported!\n");
5273 if(infoPtr->nRows != LOWORD(wParam))
5275 infoPtr->nRows = LOWORD(wParam);
5277 /* recalculate toolbar */
5278 TOOLBAR_CalcToolbar (hwnd);
5280 /* repaint toolbar */
5281 InvalidateRect(hwnd, NULL, TRUE);
5284 /* return bounding rectangle */
5286 lprc->left = infoPtr->rcBound.left;
5287 lprc->right = infoPtr->rcBound.right;
5288 lprc->top = infoPtr->rcBound.top;
5289 lprc->bottom = infoPtr->rcBound.bottom;
5297 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5300 TBUTTON_INFO *btnPtr;
5303 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5307 btnPtr = &infoPtr->buttons[nIndex];
5309 /* if hidden state has changed the invalidate entire window and recalc */
5310 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5311 btnPtr->fsState = LOWORD(lParam);
5312 TOOLBAR_CalcToolbar (hwnd);
5313 InvalidateRect(hwnd, 0, TRUE);
5317 /* process state changing if current state doesn't match new state */
5318 if(btnPtr->fsState != LOWORD(lParam))
5320 btnPtr->fsState = LOWORD(lParam);
5321 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5329 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5331 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5337 inline static LRESULT
5338 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5342 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5344 infoPtr->hwndToolTip = (HWND)wParam;
5350 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5352 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5355 TRACE("%s hwnd=%p\n",
5356 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5358 bTemp = infoPtr->bUnicode;
5359 infoPtr->bUnicode = (BOOL)wParam;
5366 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5368 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5370 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5371 comctl32_color.clrBtnHighlight :
5372 infoPtr->clrBtnHighlight;
5373 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5374 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5380 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5382 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5384 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5385 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5386 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5388 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5389 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5390 InvalidateRect(hwnd, NULL, TRUE);
5396 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5398 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5399 INT iOldVersion = infoPtr->iVersion;
5401 infoPtr->iVersion = iVersion;
5403 if (infoPtr->iVersion >= 5)
5404 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5411 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5414 WORD iString = HIWORD(wParam);
5415 WORD buffersize = LOWORD(wParam);
5416 LPSTR str = (LPSTR)lParam;
5419 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5421 if (iString < infoPtr->nNumStrings)
5423 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5425 TRACE("returning %s\n", debugstr_a(str));
5428 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5435 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5438 WORD iString = HIWORD(wParam);
5439 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5440 LPWSTR str = (LPWSTR)lParam;
5443 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5445 if (iString < infoPtr->nNumStrings)
5447 len = min(len, strlenW(infoPtr->strings[iString]));
5448 ret = (len+1)*sizeof(WCHAR);
5449 memcpy(str, infoPtr->strings[iString], ret);
5452 TRACE("returning %s\n", debugstr_w(str));
5455 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5460 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5461 * is the maximum size of the toolbar? */
5462 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5464 SIZE * pSize = (SIZE*)lParam;
5465 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5470 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5471 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5472 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5475 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5477 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5478 INT nOldHotItem = infoPtr->nHotItem;
5480 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5481 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5483 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5486 /* NOTE: an application can still remove the hot item even if anchor
5487 * highlighting is enabled */
5489 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5493 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5496 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5497 * which controls the amount of spacing between the image and the text
5498 * of buttons for TBSTYLE_LIST toolbars. */
5499 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5501 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5503 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5506 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5508 infoPtr->iListGap = (INT)wParam;
5510 InvalidateRect(hwnd, NULL, TRUE);
5515 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5516 * of image lists associated with the various states. */
5517 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5521 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5523 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5527 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5529 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5530 LPSIZE lpsize = (LPSIZE)lParam;
5536 * Testing shows the following:
5537 * wParam = 0 adjust cx value
5538 * = 1 set cy value to max size.
5539 * lParam pointer to SIZE structure
5542 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5543 wParam, lParam, lpsize->cx, lpsize->cy);
5547 if (lpsize->cx == -1) {
5548 /* **** this is wrong, native measures each button and sets it */
5549 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5551 else if(HIWORD(lpsize->cx)) {
5553 HWND hwndParent = GetParent(hwnd);
5555 GetWindowRect(hwnd, &rc);
5556 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5557 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5558 rc.left, rc.top, rc.right, rc.bottom);
5559 lpsize->cx = max(rc.right-rc.left,
5560 infoPtr->rcBound.right - infoPtr->rcBound.left);
5563 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5567 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5570 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5574 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5575 lpsize->cx, lpsize->cy);
5579 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5581 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5583 InvalidateRect(hwnd, NULL, TRUE);
5589 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5591 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5592 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5595 TRACE("hwnd = %p\n", hwnd);
5597 /* initialize info structure */
5598 infoPtr->nButtonHeight = 22;
5599 infoPtr->nButtonWidth = 24;
5600 infoPtr->nBitmapHeight = 15;
5601 infoPtr->nBitmapWidth = 16;
5603 infoPtr->nMaxTextRows = 1;
5604 infoPtr->cxMin = -1;
5605 infoPtr->cxMax = -1;
5606 infoPtr->nNumBitmaps = 0;
5607 infoPtr->nNumStrings = 0;
5609 infoPtr->bCaptured = FALSE;
5610 infoPtr->nButtonDown = -1;
5611 infoPtr->nButtonDrag = -1;
5612 infoPtr->nOldHit = -1;
5613 infoPtr->nHotItem = -1;
5614 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5615 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5616 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5617 infoPtr->bDragOutSent = FALSE;
5618 infoPtr->iVersion = 0;
5619 infoPtr->hwndSelf = hwnd;
5620 infoPtr->bDoRedraw = TRUE;
5621 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5622 infoPtr->clrBtnShadow = CLR_DEFAULT;
5623 infoPtr->szPadding.cx = DEFPAD_CX;
5624 infoPtr->szPadding.cy = DEFPAD_CY;
5625 infoPtr->iListGap = DEFLISTGAP;
5626 infoPtr->dwStyle = dwStyle;
5627 infoPtr->tbim.iButton = -1;
5628 GetClientRect(hwnd, &infoPtr->client_rect);
5629 infoPtr->bUnicode = infoPtr->hwndNotify &&
5630 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5632 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5633 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5635 if (dwStyle & TBSTYLE_TOOLTIPS) {
5636 /* Create tooltip control */
5637 infoPtr->hwndToolTip =
5638 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5639 CW_USEDEFAULT, CW_USEDEFAULT,
5640 CW_USEDEFAULT, CW_USEDEFAULT,
5643 /* Send NM_TOOLTIPSCREATED notification */
5644 if (infoPtr->hwndToolTip)
5646 NMTOOLTIPSCREATED nmttc;
5648 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5650 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5654 OpenThemeData (hwnd, themeClass);
5656 TOOLBAR_CheckStyle (hwnd, dwStyle);
5658 TOOLBAR_CalcToolbar(hwnd);
5665 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5669 /* delete tooltip control */
5670 if (infoPtr->hwndToolTip)
5671 DestroyWindow (infoPtr->hwndToolTip);
5673 /* delete temporary buffer for tooltip text */
5674 Free (infoPtr->pszTooltipText);
5676 /* delete button data */
5677 if (infoPtr->buttons)
5678 Free (infoPtr->buttons);
5680 /* delete strings */
5681 if (infoPtr->strings) {
5683 for (i = 0; i < infoPtr->nNumStrings; i++)
5684 if (infoPtr->strings[i])
5685 Free (infoPtr->strings[i]);
5687 Free (infoPtr->strings);
5690 /* destroy internal image list */
5691 if (infoPtr->himlInt)
5692 ImageList_Destroy (infoPtr->himlInt);
5694 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5695 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5696 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5698 /* delete default font */
5700 DeleteObject (infoPtr->hDefaultFont);
5702 CloseThemeData (GetWindowTheme (hwnd));
5704 /* free toolbar info data */
5706 SetWindowLongPtrW (hwnd, 0, 0);
5713 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5716 NMTBCUSTOMDRAW tbcd;
5719 HTHEME theme = GetWindowTheme (hwnd);
5721 /* the app has told us not to redraw the toolbar */
5722 if (!infoPtr->bDoRedraw)
5725 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5726 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5727 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5728 tbcd.nmcd.hdc = (HDC)wParam;
5729 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5730 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5732 /* FIXME: in general the return flags *can* be or'ed together */
5733 switch (infoPtr->dwBaseCustDraw)
5735 case CDRF_DODEFAULT:
5737 case CDRF_SKIPDEFAULT:
5740 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5745 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5746 * to my parent for processing.
5748 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5750 HDC hdc = (HDC)wParam;
5755 parent = GetParent(hwnd);
5756 MapWindowPoints(hwnd, parent, &pt, 1);
5757 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5758 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5759 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5762 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5764 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5765 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5766 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5767 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5768 tbcd.nmcd.hdc = (HDC)wParam;
5769 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5770 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5771 switch (infoPtr->dwBaseCustDraw)
5773 case CDRF_DODEFAULT:
5775 case CDRF_SKIPDEFAULT:
5778 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5787 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5791 return (LRESULT)infoPtr->hFont;
5796 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5799 INT nNewHotItem = infoPtr->nHotItem;
5801 for (i = 0; i < infoPtr->nNumButtons; i++)
5804 if ((nNewHotItem + iDirection < 0) ||
5805 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5807 NMTBWRAPHOTITEM nmtbwhi;
5808 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5809 nmtbwhi.iDirection = iDirection;
5810 nmtbwhi.dwReason = dwReason;
5812 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5816 nNewHotItem += iDirection;
5817 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5819 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5820 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5822 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5829 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5834 nmkey.nVKey = (UINT)wParam;
5835 nmkey.uFlags = HIWORD(lParam);
5837 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5838 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5840 switch ((UINT)wParam)
5844 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5848 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5852 if ((infoPtr->nHotItem >= 0) &&
5853 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5855 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5856 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5867 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5872 pt.x = (INT)LOWORD(lParam);
5873 pt.y = (INT)HIWORD(lParam);
5874 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5877 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5878 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5879 TOOLBAR_Customize (hwnd);
5886 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5889 TBUTTON_INFO *btnPtr;
5894 BOOL bDragKeyPressed;
5898 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5899 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5901 bDragKeyPressed = (wParam & MK_SHIFT);
5903 if (infoPtr->hwndToolTip)
5904 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5905 WM_LBUTTONDOWN, wParam, lParam);
5907 pt.x = (INT)LOWORD(lParam);
5908 pt.y = (INT)HIWORD(lParam);
5909 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5911 btnPtr = &infoPtr->buttons[nHit];
5913 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5915 infoPtr->nButtonDrag = nHit;
5918 /* If drag cursor has not been loaded, load it.
5919 * Note: it doesn't need to be freed */
5921 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5922 SetCursor(hCursorDrag);
5927 infoPtr->nOldHit = nHit;
5929 CopyRect(&arrowRect, &btnPtr->rect);
5930 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5932 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5933 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5934 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5935 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5936 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5937 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5941 /* draw in pressed state */
5942 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5943 btnPtr->fsState |= TBSTATE_PRESSED;
5945 btnPtr->bDropDownPressed = TRUE;
5946 RedrawWindow(hwnd,&btnPtr->rect,0,
5947 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5949 memset(&nmtb, 0, sizeof(nmtb));
5950 nmtb.iItem = btnPtr->idCommand;
5951 nmtb.rcButton = btnPtr->rect;
5952 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5954 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5956 if (res != TBDDRET_TREATPRESSED)
5960 /* redraw button in unpressed state */
5961 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5962 btnPtr->fsState &= ~TBSTATE_PRESSED;
5964 btnPtr->bDropDownPressed = FALSE;
5965 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5967 /* find and set hot item
5968 * NOTE: native doesn't do this, but that is a bug */
5970 ScreenToClient(hwnd, &pt);
5971 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5972 if (!infoPtr->bAnchor || (nHit >= 0))
5973 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5975 /* remove any left mouse button down or double-click messages
5976 * so that we can get a toggle effect on the button */
5977 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5978 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5983 /* otherwise drop through and process as pushed */
5985 infoPtr->bCaptured = TRUE;
5986 infoPtr->nButtonDown = nHit;
5987 infoPtr->bDragOutSent = FALSE;
5989 btnPtr->fsState |= TBSTATE_PRESSED;
5991 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5993 if (btnPtr->fsState & TBSTATE_ENABLED)
5994 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6001 memset(&nmtb, 0, sizeof(nmtb));
6002 nmtb.iItem = btnPtr->idCommand;
6003 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
6006 nmmouse.dwHitInfo = nHit;
6008 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
6010 nmmouse.dwItemSpec = -1;
6013 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6014 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6017 ClientToScreen(hwnd, &pt);
6020 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
6021 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
6027 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
6029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6030 TBUTTON_INFO *btnPtr;
6034 BOOL bSendMessage = TRUE;
6039 if (infoPtr->hwndToolTip)
6040 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6041 WM_LBUTTONUP, wParam, lParam);
6043 pt.x = (INT)LOWORD(lParam);
6044 pt.y = (INT)HIWORD(lParam);
6045 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6047 if (!infoPtr->bAnchor || (nHit >= 0))
6048 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6050 if (infoPtr->nButtonDrag >= 0) {
6054 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
6057 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
6059 GetClientRect(hwnd, &rcClient);
6060 if (PtInRect(&rcClient, pt))
6067 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
6070 if (nButton == infoPtr->nButtonDrag)
6072 /* if the button is moved sightly left and we have a
6073 * separator there then remove it */
6074 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
6076 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
6077 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
6079 else /* else insert a separator before the dragged button */
6082 memset(&tbb, 0, sizeof(tbb));
6083 tbb.fsStyle = BTNS_SEP;
6085 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6092 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6093 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6095 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6098 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6103 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6104 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6107 /* button under cursor changed so need to re-set hot item */
6108 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6109 infoPtr->nButtonDrag = -1;
6111 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6113 else if (infoPtr->nButtonDown >= 0) {
6114 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6115 btnPtr->fsState &= ~TBSTATE_PRESSED;
6117 if (btnPtr->fsStyle & BTNS_CHECK) {
6118 if (btnPtr->fsStyle & BTNS_GROUP) {
6119 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6121 if (nOldIndex == nHit)
6122 bSendMessage = FALSE;
6123 if ((nOldIndex != nHit) &&
6125 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6126 btnPtr->fsState |= TBSTATE_CHECKED;
6129 if (btnPtr->fsState & TBSTATE_CHECKED)
6130 btnPtr->fsState &= ~TBSTATE_CHECKED;
6132 btnPtr->fsState |= TBSTATE_CHECKED;
6136 if (nOldIndex != -1)
6137 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6140 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6141 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6142 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6144 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6146 infoPtr->nButtonDown = -1;
6148 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6149 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6150 NM_RELEASEDCAPTURE);
6152 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6155 memset(&nmtb, 0, sizeof(nmtb));
6156 nmtb.iItem = btnPtr->idCommand;
6157 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6160 if (btnPtr->fsState & TBSTATE_ENABLED)
6162 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6163 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6167 /* !!! Undocumented - toolbar at 4.71 level and above sends
6168 * NM_CLICK with the NMMOUSE structure. */
6169 nmmouse.dwHitInfo = nHit;
6172 nmmouse.dwItemSpec = -1;
6175 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6176 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6179 ClientToScreen(hwnd, &pt);
6182 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6183 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6189 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6196 pt.x = LOWORD(lParam);
6197 pt.y = HIWORD(lParam);
6199 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6200 nmmouse.dwHitInfo = nHit;
6203 nmmouse.dwItemSpec = -1;
6205 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6206 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6209 ClientToScreen(hwnd, &pt);
6212 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6213 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6219 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6224 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6225 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6231 TOOLBAR_CaptureChanged(HWND hwnd)
6233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6234 TBUTTON_INFO *btnPtr;
6236 infoPtr->bCaptured = FALSE;
6238 if (infoPtr->nButtonDown >= 0)
6240 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6241 btnPtr->fsState &= ~TBSTATE_PRESSED;
6243 infoPtr->nOldHit = -1;
6245 if (btnPtr->fsState & TBSTATE_ENABLED)
6246 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6252 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6254 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6255 TBUTTON_INFO *hotBtnPtr;
6257 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6259 /* don't remove hot effects when in anchor highlighting mode or when a
6260 * drop-down button is pressed */
6261 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6262 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6264 if (infoPtr->nOldHit < 0)
6267 /* If the last button we were over is depressed then make it not */
6268 /* depressed and redraw it */
6269 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6271 TBUTTON_INFO *btnPtr;
6274 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6276 btnPtr->fsState &= ~TBSTATE_PRESSED;
6278 rc1 = hotBtnPtr->rect;
6279 InflateRect (&rc1, 1, 1);
6280 InvalidateRect (hwnd, &rc1, TRUE);
6283 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6286 ZeroMemory(&nmt, sizeof(nmt));
6287 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6288 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6289 infoPtr->bDragOutSent = TRUE;
6292 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6298 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6302 TRACKMOUSEEVENT trackinfo;
6304 TBUTTON_INFO *btnPtr;
6306 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6307 /* fill in the TRACKMOUSEEVENT struct */
6308 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6309 trackinfo.dwFlags = TME_QUERY;
6310 trackinfo.hwndTrack = hwnd;
6311 trackinfo.dwHoverTime = HOVER_DEFAULT;
6313 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6314 _TrackMouseEvent(&trackinfo);
6316 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6317 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6318 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6320 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6321 /* and can properly deactivate the hot toolbar button */
6322 _TrackMouseEvent(&trackinfo);
6326 if (infoPtr->hwndToolTip)
6327 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6328 WM_MOUSEMOVE, wParam, lParam);
6330 pt.x = (INT)LOWORD(lParam);
6331 pt.y = (INT)HIWORD(lParam);
6333 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6335 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6336 && (!infoPtr->bAnchor || (nHit >= 0)))
6337 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6339 if (infoPtr->nOldHit != nHit)
6341 if (infoPtr->bCaptured)
6343 if (!infoPtr->bDragOutSent)
6346 ZeroMemory(&nmt, sizeof(nmt));
6347 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6348 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6349 infoPtr->bDragOutSent = TRUE;
6352 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6353 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6354 btnPtr->fsState &= ~TBSTATE_PRESSED;
6355 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6357 else if (nHit == infoPtr->nButtonDown) {
6358 btnPtr->fsState |= TBSTATE_PRESSED;
6359 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6361 infoPtr->nOldHit = nHit;
6369 inline static LRESULT
6370 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6372 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6373 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6375 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6379 inline static LRESULT
6380 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6382 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6383 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6385 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6390 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6392 TOOLBAR_INFO *infoPtr;
6393 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6396 /* allocate memory for info structure */
6397 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6398 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6401 infoPtr->dwStructSize = sizeof(TBBUTTON);
6403 infoPtr->nWidth = 0;
6405 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6406 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6407 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6408 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6411 /* native control does:
6412 * Get a lot of colors and brushes
6414 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6415 * CreateFontIndirectW(adr1)
6416 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6417 * hdc = GetDC(toolbar)
6418 * GetSystemMetrics(0x48)
6419 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6420 * 0, 0, 0, 0, "MARLETT")
6421 * oldfnt = SelectObject(hdc, fnt2)
6422 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6423 * GetTextMetricsW(hdc, adr3)
6424 * SelectObject(hdc, oldfnt)
6425 * DeleteObject(fnt2)
6427 * InvalidateRect(toolbar, 0, 1)
6428 * SetWindowLongW(toolbar, 0, addr)
6429 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6432 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6433 * ie 2 0x4600094c 0x4600094c 0x4600894d
6434 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6435 * rebar 0x50008844 0x40008844 0x50008845
6436 * pager 0x50000844 0x40000844 0x50008845
6437 * IC35mgr 0x5400084e **nochange**
6438 * on entry to _NCCREATE 0x5400084e
6439 * rowlist 0x5400004e **nochange**
6440 * on entry to _NCCREATE 0x5400004e
6444 /* I think the code below is a bug, but it is the way that the native
6445 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6446 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6447 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6448 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6449 * Somehow, the only cases of this seem to be MFC programs.
6451 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6452 * does not occur in the WM_STYLECHANGING routine.
6453 * (Guy Albertelli 9/2001)
6456 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6457 && !(cs->style & TBSTYLE_TRANSPARENT))
6458 styleadd |= TBSTYLE_TRANSPARENT;
6459 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6460 styleadd |= CCS_TOP; /* default to top */
6461 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6464 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6469 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6471 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6475 if (dwStyle & WS_MINIMIZE)
6476 return 0; /* Nothing to do */
6478 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6480 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6483 if (!(dwStyle & CCS_NODIVIDER))
6485 GetWindowRect (hwnd, &rcWindow);
6486 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6487 if( dwStyle & WS_BORDER )
6488 OffsetRect (&rcWindow, 1, 1);
6489 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6492 ReleaseDC( hwnd, hdc );
6498 /* handles requests from the tooltip control on what text to display */
6499 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6501 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6503 TRACE("button index = %d\n", index);
6505 Free (infoPtr->pszTooltipText);
6506 infoPtr->pszTooltipText = NULL;
6511 if (infoPtr->bUnicode)
6513 WCHAR wszBuffer[INFOTIPSIZE+1];
6514 NMTBGETINFOTIPW tbgit;
6515 unsigned int len; /* in chars */
6517 wszBuffer[0] = '\0';
6518 wszBuffer[INFOTIPSIZE] = '\0';
6520 tbgit.pszText = wszBuffer;
6521 tbgit.cchTextMax = INFOTIPSIZE;
6522 tbgit.iItem = lpnmtdi->hdr.idFrom;
6523 tbgit.lParam = infoPtr->buttons[index].dwData;
6525 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6527 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6529 len = strlenW(tbgit.pszText);
6530 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6532 /* need to allocate temporary buffer in infoPtr as there
6533 * isn't enough space in buffer passed to us by the
6534 * tooltip control */
6535 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6536 if (infoPtr->pszTooltipText)
6538 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6539 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6545 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6551 CHAR szBuffer[INFOTIPSIZE+1];
6552 NMTBGETINFOTIPA tbgit;
6553 unsigned int len; /* in chars */
6556 szBuffer[INFOTIPSIZE] = '\0';
6558 tbgit.pszText = szBuffer;
6559 tbgit.cchTextMax = INFOTIPSIZE;
6560 tbgit.iItem = lpnmtdi->hdr.idFrom;
6561 tbgit.lParam = infoPtr->buttons[index].dwData;
6563 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6565 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6567 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6568 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6570 /* need to allocate temporary buffer in infoPtr as there
6571 * isn't enough space in buffer passed to us by the
6572 * tooltip control */
6573 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6574 if (infoPtr->pszTooltipText)
6576 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6577 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6583 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6584 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6589 /* if button has text, but it is not shown then automatically
6590 * use that text as tooltip */
6591 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6592 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6594 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6595 unsigned int len = pszText ? strlenW(pszText) : 0;
6597 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6599 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6601 /* need to allocate temporary buffer in infoPtr as there
6602 * isn't enough space in buffer passed to us by the
6603 * tooltip control */
6604 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6605 if (infoPtr->pszTooltipText)
6607 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6608 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6614 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6619 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6621 /* last resort: send notification on to app */
6622 /* FIXME: find out what is really used here */
6623 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6627 inline static LRESULT
6628 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6631 LPNMHDR lpnmh = (LPNMHDR)lParam;
6633 switch (lpnmh->code)
6637 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6639 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6640 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6641 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6645 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6646 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6654 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6656 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6657 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6658 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6659 lppgs->iScroll, lppgs->iDir);
6663 case TTN_GETDISPINFOW:
6664 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6666 case TTN_GETDISPINFOA:
6667 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6677 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6681 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6683 if (lParam == NF_QUERY)
6686 if (lParam == NF_REQUERY) {
6687 format = SendMessageW(infoPtr->hwndNotify,
6688 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6689 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6690 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6701 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6707 /* fill ps.rcPaint with a default rect */
6708 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6710 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6712 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6713 ps.rcPaint.left, ps.rcPaint.top,
6714 ps.rcPaint.right, ps.rcPaint.bottom);
6716 TOOLBAR_Refresh (hwnd, hdc, &ps);
6717 if (!wParam) EndPaint (hwnd, &ps);
6724 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6726 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6728 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6730 /* make first item hot */
6731 if (infoPtr->nNumButtons > 0)
6732 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6739 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6740 /*****************************************************
6743 * Handles the WM_SETREDRAW message.
6746 * According to testing V4.71 of COMCTL32 returns the
6747 * *previous* status of the redraw flag (either 0 or 1)
6748 * instead of the MSDN documented value of 0 if handled.
6749 * (For laughs see the "consistency" with same function
6752 *****************************************************/
6754 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6755 BOOL oldredraw = infoPtr->bDoRedraw;
6757 TRACE("set to %s\n",
6758 (wParam) ? "TRUE" : "FALSE");
6759 infoPtr->bDoRedraw = (BOOL) wParam;
6761 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6763 return (oldredraw) ? 1 : 0;
6768 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6770 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6772 TRACE("sizing toolbar!\n");
6774 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6776 RECT delta_width, delta_height, client, dummy;
6777 DWORD min_x, max_x, min_y, max_y;
6778 TBUTTON_INFO *btnPtr;
6781 GetClientRect(hwnd, &client);
6782 if(client.right > infoPtr->client_rect.right)
6784 min_x = infoPtr->client_rect.right;
6785 max_x = client.right;
6789 max_x = infoPtr->client_rect.right;
6790 min_x = client.right;
6792 if(client.bottom > infoPtr->client_rect.bottom)
6794 min_y = infoPtr->client_rect.bottom;
6795 max_y = client.bottom;
6799 max_y = infoPtr->client_rect.bottom;
6800 min_y = client.bottom;
6803 SetRect(&delta_width, min_x, 0, max_x, min_y);
6804 SetRect(&delta_height, 0, min_y, max_x, max_y);
6806 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6807 btnPtr = infoPtr->buttons;
6808 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6809 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6810 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6811 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6813 GetClientRect(hwnd, &infoPtr->client_rect);
6814 TOOLBAR_AutoSize(hwnd);
6820 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6824 if (nType == GWL_STYLE)
6826 if (lpStyle->styleNew & TBSTYLE_LIST)
6827 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6829 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6831 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6833 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6835 infoPtr->dwStyle = lpStyle->styleNew;
6837 /* only resize if one of the CCS_* styles was changed */
6838 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6840 TOOLBAR_AutoSize (hwnd);
6842 InvalidateRect(hwnd, NULL, TRUE);
6851 TOOLBAR_SysColorChange (HWND hwnd)
6853 COMCTL32_RefreshSysColors();
6859 /* update theme after a WM_THEMECHANGED message */
6860 static LRESULT theme_changed (HWND hwnd)
6862 HTHEME theme = GetWindowTheme (hwnd);
6863 CloseThemeData (theme);
6864 OpenThemeData (hwnd, themeClass);
6869 static LRESULT WINAPI
6870 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6872 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6874 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6875 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6877 if (!infoPtr && (uMsg != WM_NCCREATE))
6878 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6883 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6885 case TB_ADDBUTTONSA:
6886 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6888 case TB_ADDBUTTONSW:
6889 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6892 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6895 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6898 return TOOLBAR_AutoSize (hwnd);
6900 case TB_BUTTONCOUNT:
6901 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6903 case TB_BUTTONSTRUCTSIZE:
6904 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6906 case TB_CHANGEBITMAP:
6907 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6909 case TB_CHECKBUTTON:
6910 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6912 case TB_COMMANDTOINDEX:
6913 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6916 return TOOLBAR_Customize (hwnd);
6918 case TB_DELETEBUTTON:
6919 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6921 case TB_ENABLEBUTTON:
6922 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6924 case TB_GETANCHORHIGHLIGHT:
6925 return TOOLBAR_GetAnchorHighlight (hwnd);
6928 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6930 case TB_GETBITMAPFLAGS:
6931 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6934 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6936 case TB_GETBUTTONINFOA:
6937 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6939 case TB_GETBUTTONINFOW:
6940 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6942 case TB_GETBUTTONSIZE:
6943 return TOOLBAR_GetButtonSize (hwnd);
6945 case TB_GETBUTTONTEXTA:
6946 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6948 case TB_GETBUTTONTEXTW:
6949 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6951 case TB_GETDISABLEDIMAGELIST:
6952 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6954 case TB_GETEXTENDEDSTYLE:
6955 return TOOLBAR_GetExtendedStyle (hwnd);
6957 case TB_GETHOTIMAGELIST:
6958 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6961 return TOOLBAR_GetHotItem (hwnd);
6963 case TB_GETIMAGELIST:
6964 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6966 case TB_GETINSERTMARK:
6967 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6969 case TB_GETINSERTMARKCOLOR:
6970 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6972 case TB_GETITEMRECT:
6973 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6976 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6978 /* case TB_GETOBJECT: */ /* 4.71 */
6981 return TOOLBAR_GetPadding (hwnd);
6984 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6987 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6990 return TOOLBAR_GetState (hwnd, wParam, lParam);
6993 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6996 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6999 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
7001 case TB_GETTEXTROWS:
7002 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
7004 case TB_GETTOOLTIPS:
7005 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
7007 case TB_GETUNICODEFORMAT:
7008 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
7011 return TOOLBAR_HideButton (hwnd, wParam, lParam);
7014 return TOOLBAR_HitTest (hwnd, wParam, lParam);
7016 case TB_INDETERMINATE:
7017 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
7019 case TB_INSERTBUTTONA:
7020 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
7022 case TB_INSERTBUTTONW:
7023 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
7025 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
7027 case TB_ISBUTTONCHECKED:
7028 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
7030 case TB_ISBUTTONENABLED:
7031 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
7033 case TB_ISBUTTONHIDDEN:
7034 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
7036 case TB_ISBUTTONHIGHLIGHTED:
7037 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
7039 case TB_ISBUTTONINDETERMINATE:
7040 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
7042 case TB_ISBUTTONPRESSED:
7043 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
7046 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
7048 case TB_MAPACCELERATORA:
7049 case TB_MAPACCELERATORW:
7050 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
7053 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7056 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7058 case TB_PRESSBUTTON:
7059 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7061 case TB_REPLACEBITMAP:
7062 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7064 case TB_SAVERESTOREA:
7065 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7067 case TB_SAVERESTOREW:
7068 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7070 case TB_SETANCHORHIGHLIGHT:
7071 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7073 case TB_SETBITMAPSIZE:
7074 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7076 case TB_SETBUTTONINFOA:
7077 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7079 case TB_SETBUTTONINFOW:
7080 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7082 case TB_SETBUTTONSIZE:
7083 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7085 case TB_SETBUTTONWIDTH:
7086 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7089 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7091 case TB_SETDISABLEDIMAGELIST:
7092 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7094 case TB_SETDRAWTEXTFLAGS:
7095 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7097 case TB_SETEXTENDEDSTYLE:
7098 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7100 case TB_SETHOTIMAGELIST:
7101 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7104 return TOOLBAR_SetHotItem (hwnd, wParam);
7106 case TB_SETIMAGELIST:
7107 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7110 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7112 case TB_SETINSERTMARK:
7113 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7115 case TB_SETINSERTMARKCOLOR:
7116 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7118 case TB_SETMAXTEXTROWS:
7119 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7122 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7125 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7128 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7131 return TOOLBAR_SetState (hwnd, wParam, lParam);
7134 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7136 case TB_SETTOOLTIPS:
7137 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7139 case TB_SETUNICODEFORMAT:
7140 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7143 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7146 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7149 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7152 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7155 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7158 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7160 /* Common Control Messages */
7162 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7163 case CCM_GETCOLORSCHEME:
7164 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7166 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7167 case CCM_SETCOLORSCHEME:
7168 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7170 case CCM_GETVERSION:
7171 return TOOLBAR_GetVersion (hwnd);
7173 case CCM_SETVERSION:
7174 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7180 return TOOLBAR_Create (hwnd, wParam, lParam);
7183 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7186 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7189 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7192 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7194 /* case WM_KILLFOCUS: */
7196 case WM_LBUTTONDBLCLK:
7197 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7199 case WM_LBUTTONDOWN:
7200 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7203 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7206 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7208 case WM_RBUTTONDBLCLK:
7209 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7212 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7215 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7217 case WM_CAPTURECHANGED:
7218 return TOOLBAR_CaptureChanged(hwnd);
7221 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7224 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7227 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7230 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7233 return TOOLBAR_Notify (hwnd, wParam, lParam);
7235 case WM_NOTIFYFORMAT:
7236 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7238 case WM_PRINTCLIENT:
7240 return TOOLBAR_Paint (hwnd, wParam);
7243 return TOOLBAR_SetFocus (hwnd, wParam);
7246 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7249 return TOOLBAR_Size (hwnd, wParam, lParam);
7251 case WM_STYLECHANGED:
7252 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7254 case WM_SYSCOLORCHANGE:
7255 return TOOLBAR_SysColorChange (hwnd);
7257 case WM_THEMECHANGED:
7258 return theme_changed (hwnd);
7260 /* case WM_WININICHANGE: */
7265 case WM_MEASUREITEM:
7267 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7269 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7270 case PGM_FORWARDMOUSE:
7271 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7274 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7275 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7276 uMsg, wParam, lParam);
7277 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7283 TOOLBAR_Register (void)
7287 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7288 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7289 wndClass.lpfnWndProc = ToolbarWindowProc;
7290 wndClass.cbClsExtra = 0;
7291 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7292 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7293 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7294 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7296 RegisterClassW (&wndClass);
7301 TOOLBAR_Unregister (void)
7303 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7306 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7311 /* Check if the entry already exists */
7312 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7314 /* If this is a new entry we must create it and insert into the array */
7319 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7322 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7323 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7338 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7342 for (i = 0; i < *cies; i++)
7352 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7360 for (i = 0; i < cies; i++)
7362 if (pies[i]->id == id)
7374 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7376 HIMAGELIST himlDef = 0;
7377 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7380 himlDef = pie->himl;
7386 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7388 if (infoPtr->bUnicode)
7389 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7396 nmtba.iItem = nmtb->iItem;
7397 nmtba.pszText = Buffer;
7398 nmtba.cchText = 256;
7399 ZeroMemory(nmtba.pszText, nmtba.cchText);
7401 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7403 int ccht = strlen(nmtba.pszText);
7405 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7406 nmtb->pszText, nmtb->cchText);
7408 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7417 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7418 int iItem, PCUSTOMBUTTON btnInfo)
7422 /* MSDN states that iItem is the index of the button, rather than the
7423 * command ID as used by every other NMTOOLBAR notification */
7425 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7427 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);