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_HOT)
700 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
702 /* if hot, attempt to draw with hot image list, if fails,
703 use default image list */
704 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
706 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
709 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
714 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
715 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
718 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
719 (tbcd->nmcd.uItemState & CDIS_MARKED))
720 draw_flags |= ILD_BLEND50;
722 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
723 index, himl, left, top, offset);
726 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
728 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
731 /* draws a blank frame for a toolbar button */
733 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
735 HDC hdc = tbcd->nmcd.hdc;
736 RECT rc = tbcd->nmcd.rc;
737 /* if the state is disabled or indeterminate then the button
738 * cannot have an interactive look like pressed or hot */
739 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
740 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
741 BOOL pressed_look = !non_interactive_state &&
742 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
743 (tbcd->nmcd.uItemState & CDIS_CHECKED));
745 /* app don't want us to draw any edges */
746 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
749 if (infoPtr->dwStyle & TBSTYLE_FLAT)
752 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
753 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
754 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
759 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
761 DrawEdge (hdc, &rc, EDGE_RAISED,
762 BF_SOFT | BF_RECT | BF_MIDDLE);
767 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
769 HDC hdc = tbcd->nmcd.hdc;
771 BOOL pressed = bDropDownPressed ||
772 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
774 if (infoPtr->dwStyle & TBSTYLE_FLAT)
777 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
778 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
779 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
780 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
781 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
786 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
788 DrawEdge (hdc, rcArrow, EDGE_RAISED,
789 BF_SOFT | BF_RECT | BF_MIDDLE);
793 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
795 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
797 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
798 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
801 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
804 /* draws a complete toolbar button */
806 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
808 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
809 DWORD dwStyle = infoPtr->dwStyle;
810 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
811 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
812 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
813 BOOL drawSepDropDownArrow = hasDropDownArrow &&
814 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
815 RECT rc, rcArrow, rcBitmap, rcText;
816 LPWSTR lpText = NULL;
821 HTHEME theme = GetWindowTheme (hwnd);
824 CopyRect (&rcArrow, &rc);
826 /* get a pointer to the text */
827 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
829 if (hasDropDownArrow)
833 if (dwStyle & TBSTYLE_FLAT)
834 right = max(rc.left, rc.right - DDARROW_WIDTH);
836 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
838 if (drawSepDropDownArrow)
841 rcArrow.left = right;
844 /* copy text & bitmap rects after adjusting for drop-down arrow
845 * so that text & bitmap is centred in the rectangle not containing
847 CopyRect(&rcText, &rc);
848 CopyRect(&rcBitmap, &rc);
850 /* Center the bitmap horizontally and vertically */
851 if (dwStyle & TBSTYLE_LIST)
854 infoPtr->nMaxTextRows > 0 &&
855 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
856 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
857 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
859 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
862 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
864 rcBitmap.top += infoPtr->szPadding.cy / 2;
866 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
867 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
868 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
869 TRACE("Text=%s\n", debugstr_w(lpText));
870 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
872 /* calculate text position */
875 rcText.left += GetSystemMetrics(SM_CXEDGE);
876 rcText.right -= GetSystemMetrics(SM_CXEDGE);
877 if (dwStyle & TBSTYLE_LIST)
879 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
880 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
884 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
885 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
887 rcText.top += infoPtr->szPadding.cy/2 + 2;
891 /* Initialize fields in all cases, because we use these later
892 * NOTE: applications can and do alter these to customize their
894 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
895 tbcd.clrText = comctl32_color.clrBtnText;
896 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
897 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
898 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
899 tbcd.clrMark = comctl32_color.clrHighlight;
900 tbcd.clrHighlightHotTrack = 0;
901 tbcd.nStringBkMode = TRANSPARENT;
902 tbcd.nHLStringBkMode = OPAQUE;
903 /* MSDN says that this is the text rectangle.
904 * But (why always a but) tracing of v5.7 of native shows
905 * that this is really a *relative* rectangle based on the
906 * the nmcd.rc. Also the left and top are always 0 ignoring
907 * any bitmap that might be present. */
908 tbcd.rcText.left = 0;
910 tbcd.rcText.right = rcText.right - rc.left;
911 tbcd.rcText.bottom = rcText.bottom - rc.top;
912 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
915 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
917 /* FIXME: what are these used for? */
921 /* Issue Item Prepaint notify */
922 infoPtr->dwItemCustDraw = 0;
923 infoPtr->dwItemCDFlag = 0;
924 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
926 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
927 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
928 tbcd.nmcd.lItemlParam = btnPtr->dwData;
929 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
930 /* reset these fields so the user can't alter the behaviour like native */
934 infoPtr->dwItemCustDraw = ntfret & 0xffff;
935 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
936 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
938 /* save the only part of the rect that the user can change */
939 rcText.right = tbcd.rcText.right + rc.left;
940 rcText.bottom = tbcd.rcText.bottom + rc.top;
944 if (btnPtr->fsStyle & BTNS_SEP) {
947 DrawThemeBackground (theme, hdc,
948 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
949 &tbcd.nmcd.rc, NULL);
952 /* with the FLAT style, iBitmap is the width and has already */
953 /* been taken into consideration in calculating the width */
954 /* so now we need to draw the vertical separator */
955 /* empirical tests show that iBitmap can/will be non-zero */
956 /* when drawing the vertical bar... */
957 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
958 if (btnPtr->fsStyle & BTNS_DROPDOWN)
959 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
961 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
963 else if (btnPtr->fsStyle != BTNS_SEP) {
964 FIXME("Draw some kind of separator: fsStyle=%x\n",
970 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
971 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
972 OffsetRect(&rcText, 1, 1);
974 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
975 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
976 TOOLBAR_DrawPattern (&rc, &tbcd);
978 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
979 && (tbcd.nmcd.uItemState & CDIS_HOT))
981 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
985 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
986 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
987 if (hasDropDownArrow)
988 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
989 SetBkColor(hdc, oldclr);
995 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
996 int stateId = TS_NORMAL;
998 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
999 stateId = TS_DISABLED;
1000 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1001 stateId = TS_PRESSED;
1002 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1003 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1004 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1005 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1008 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1011 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1013 if (drawSepDropDownArrow)
1017 int stateId = TS_NORMAL;
1019 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1020 stateId = TS_DISABLED;
1021 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1022 stateId = TS_PRESSED;
1023 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1024 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1025 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1028 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1029 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1032 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1035 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1036 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1037 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1038 SetBkMode (hdc, oldBkMode);
1040 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1042 if (hasDropDownArrow && !drawSepDropDownArrow)
1044 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1046 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1047 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1049 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1051 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1052 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1059 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1061 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1062 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1069 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1072 TBUTTON_INFO *btnPtr;
1074 RECT rcTemp, rcClient;
1075 NMTBCUSTOMDRAW tbcd;
1078 /* the app has told us not to redraw the toolbar */
1079 if (!infoPtr->bDoRedraw)
1082 /* if imagelist belongs to the app, it can be changed
1083 by the app after setting it */
1084 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1086 infoPtr->nNumBitmaps = 0;
1087 for (i = 0; i < infoPtr->cimlDef; i++)
1088 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1091 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1093 /* Send initial notify */
1094 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1095 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1096 tbcd.nmcd.hdc = hdc;
1097 tbcd.nmcd.rc = ps->rcPaint;
1098 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1099 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1101 GetClientRect(hwnd, &rcClient);
1103 /* redraw necessary buttons */
1104 btnPtr = infoPtr->buttons;
1105 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1108 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1110 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1111 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1115 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1116 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1118 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1121 /* draw insert mark if required */
1122 if (infoPtr->tbim.iButton != -1)
1124 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1126 rcInsertMark.top = rcButton.top;
1127 rcInsertMark.bottom = rcButton.bottom;
1128 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1129 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1131 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1132 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1135 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1137 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1138 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1139 tbcd.nmcd.hdc = hdc;
1140 tbcd.nmcd.rc = ps->rcPaint;
1141 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1145 /***********************************************************************
1146 * TOOLBAR_MeasureString
1148 * This function gets the width and height of a string in pixels. This
1149 * is done first by using GetTextExtentPoint to get the basic width
1150 * and height. The DrawText is called with DT_CALCRECT to get the exact
1151 * width. The reason is because the text may have more than one "&" (or
1152 * prefix characters as M$ likes to call them). The prefix character
1153 * indicates where the underline goes, except for the string "&&" which
1154 * is reduced to a single "&". GetTextExtentPoint does not process these
1155 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1158 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1159 HDC hdc, LPSIZE lpSize)
1166 if (infoPtr->nMaxTextRows > 0 &&
1167 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1168 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1169 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1171 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1173 if(lpText != NULL) {
1174 /* first get size of all the text */
1175 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1177 /* feed above size into the rectangle for DrawText */
1178 myrect.left = myrect.top = 0;
1179 myrect.right = lpSize->cx;
1180 myrect.bottom = lpSize->cy;
1182 /* Use DrawText to get true size as drawn (less pesky "&") */
1183 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1184 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1187 /* feed back to caller */
1188 lpSize->cx = myrect.right;
1189 lpSize->cy = myrect.bottom;
1193 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1196 /***********************************************************************
1197 * TOOLBAR_CalcStrings
1199 * This function walks through each string and measures it and returns
1200 * the largest height and width to caller.
1203 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1206 TBUTTON_INFO *btnPtr;
1215 if (infoPtr->nMaxTextRows == 0)
1219 hOldFont = SelectObject (hdc, infoPtr->hFont);
1221 if (infoPtr->nNumButtons == 0)
1225 GetTextMetricsW(hdc, &tm);
1226 lpSize->cy = tm.tmHeight;
1229 btnPtr = infoPtr->buttons;
1230 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1231 if(TOOLBAR_HasText(infoPtr, btnPtr))
1233 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1234 if (sz.cx > lpSize->cx)
1236 if (sz.cy > lpSize->cy)
1241 SelectObject (hdc, hOldFont);
1242 ReleaseDC (hwnd, hdc);
1244 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1247 /***********************************************************************
1248 * TOOLBAR_WrapToolbar
1250 * This function walks through the buttons and separators in the
1251 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1252 * wrapping should occur based on the width of the toolbar window.
1253 * It does *not* calculate button placement itself. That task
1254 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1255 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1256 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1258 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1259 * vertical toolbar lists.
1263 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1266 TBUTTON_INFO *btnPtr;
1269 BOOL bWrap, bButtonWrap;
1271 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1272 /* no layout is necessary. Applications may use this style */
1273 /* to perform their own layout on the toolbar. */
1274 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1275 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1277 btnPtr = infoPtr->buttons;
1278 x = infoPtr->nIndent;
1280 if (GetParent(hwnd))
1282 /* this can get the parents width, to know how far we can extend
1283 * this toolbar. We cannot use its height, as there may be multiple
1284 * toolbars in a rebar control
1286 GetClientRect( GetParent(hwnd), &rc );
1287 infoPtr->nWidth = rc.right - rc.left;
1291 GetWindowRect( hwnd, &rc );
1292 infoPtr->nWidth = rc.right - rc.left;
1295 bButtonWrap = FALSE;
1297 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1298 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1301 for (i = 0; i < infoPtr->nNumButtons; i++ )
1304 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1306 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1309 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1310 /* it is the actual width of the separator. This is used for */
1311 /* custom controls in toolbars. */
1313 /* BTNS_DROPDOWN separators are treated as buttons for */
1314 /* width. - GA 8/01 */
1315 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1316 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1317 cx = (btnPtr[i].iBitmap > 0) ?
1318 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1320 cx = infoPtr->nButtonWidth;
1322 /* Two or more adjacent separators form a separator group. */
1323 /* The first separator in a group should be wrapped to the */
1324 /* next row if the previous wrapping is on a button. */
1326 (btnPtr[i].fsStyle & BTNS_SEP) &&
1327 (i + 1 < infoPtr->nNumButtons ) &&
1328 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1330 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1331 btnPtr[i].fsState |= TBSTATE_WRAP;
1332 x = infoPtr->nIndent;
1334 bButtonWrap = FALSE;
1338 /* The layout makes sure the bitmap is visible, but not the button. */
1339 /* Test added to also wrap after a button that starts a row but */
1340 /* is bigger than the area. - GA 8/01 */
1341 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1342 > infoPtr->nWidth ) ||
1343 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1345 BOOL bFound = FALSE;
1347 /* If the current button is a separator and not hidden, */
1348 /* go to the next until it reaches a non separator. */
1349 /* Wrap the last separator if it is before a button. */
1350 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1351 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1352 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1353 i < infoPtr->nNumButtons )
1359 if( bFound && i < infoPtr->nNumButtons )
1362 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1363 i, btnPtr[i].fsStyle, x, cx);
1364 btnPtr[i].fsState |= TBSTATE_WRAP;
1365 x = infoPtr->nIndent;
1366 bButtonWrap = FALSE;
1369 else if ( i >= infoPtr->nNumButtons)
1372 /* If the current button is not a separator, find the last */
1373 /* separator and wrap it. */
1374 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1376 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1377 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1381 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1382 i, btnPtr[i].fsStyle, x, cx);
1383 x = infoPtr->nIndent;
1384 btnPtr[j].fsState |= TBSTATE_WRAP;
1385 bButtonWrap = FALSE;
1390 /* If no separator available for wrapping, wrap one of */
1391 /* non-hidden previous button. */
1395 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1397 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1402 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1403 i, btnPtr[i].fsStyle, x, cx);
1404 x = infoPtr->nIndent;
1405 btnPtr[j].fsState |= TBSTATE_WRAP;
1411 /* If all above failed, wrap the current button. */
1414 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1415 i, btnPtr[i].fsStyle, x, cx);
1416 btnPtr[i].fsState |= TBSTATE_WRAP;
1418 x = infoPtr->nIndent;
1419 if (btnPtr[i].fsStyle & BTNS_SEP )
1420 bButtonWrap = FALSE;
1426 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1427 i, btnPtr[i].fsStyle, x, cx);
1434 /***********************************************************************
1435 * TOOLBAR_MeasureButton
1437 * Calculates the width and height required for a button. Used in
1438 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1439 * the width of buttons that are autosized.
1441 * Note that it would have been rather elegant to use one piece of code for
1442 * both the laying out of the toolbar and for controlling where button parts
1443 * are drawn, but the native control has inconsistencies between the two that
1444 * prevent this from being effectively. These inconsistencies can be seen as
1445 * artefacts where parts of the button appear outside of the bounding button
1448 * There are several cases for the calculation of the button dimensions and
1449 * button part positioning:
1456 * +--------------------------------------------------------+ ^
1458 * | | pad.cy / 2 | centred | |
1459 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1460 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1461 * | |<------------>| | | | |
1462 * | +--------------+ +------------+ | |
1463 * |<-------------------------------------->| | |
1464 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1466 * +--------------------------------------------------------+ -
1467 * <-------------------------------------------------------->
1468 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1470 * Without Bitmap (I_IMAGENONE):
1472 * +-----------------------------------+ ^
1474 * | | centred | | LISTPAD_CY +
1475 * | +------------+ | | szText.cy
1478 * | +------------+ | |
1479 * |<----------------->| | |
1480 * | cxedge |<-----------> | |
1482 * +-----------------------------------+ -
1483 * <----------------------------------->
1484 * szText.cx + pad.cx
1488 * +--------------------------------------+ ^
1490 * | | padding.cy/2 | | DEFPAD_CY +
1491 * | +------------+ | | nBitmapHeight
1494 * | +------------+ | |
1495 * |<------------------->| | |
1496 * | cxedge + iListGap/2 |<-----------> | |
1497 * | nBitmapWidth | |
1498 * +--------------------------------------+ -
1499 * <-------------------------------------->
1500 * 2*cxedge + nBitmapWidth + iListGap
1507 * +-----------------------------------+ ^
1509 * | | pad.cy / 2 | | nBitmapHeight +
1510 * | - | | szText.cy +
1511 * | +------------+ | | DEFPAD_CY + 1
1512 * | centred | Bitmap | | |
1513 * |<----------------->| | | |
1514 * | +------------+ | |
1518 * | centred +---------------+ | |
1519 * |<--------------->| Text | | |
1520 * | +---------------+ | |
1521 * +-----------------------------------+ -
1522 * <----------------------------------->
1523 * pad.cx + max(nBitmapWidth, szText.cx)
1525 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1527 * +---------------------------------------+ ^
1529 * | | 2 + pad.cy / 2 | |
1530 * | - | | szText.cy +
1531 * | centred +-----------------+ | | pad.cy + 2
1532 * |<--------------->| Text | | |
1533 * | +-----------------+ | |
1535 * +---------------------------------------+ -
1536 * <--------------------------------------->
1537 * 2*cxedge + pad.cx + szText.cx
1540 * As for with bitmaps, but with szText.cx zero.
1542 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1545 if (infoPtr->dwStyle & TBSTYLE_LIST)
1547 /* set button height from bitmap / text height... */
1548 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1551 /* ... add on the necessary padding */
1552 if (bValidImageList)
1555 sizeButton.cy += DEFPAD_CY;
1557 sizeButton.cy += LISTPAD_CY;
1560 sizeButton.cy += infoPtr->szPadding.cy;
1562 /* calculate button width */
1565 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1566 infoPtr->nBitmapWidth + infoPtr->iListGap;
1567 if (sizeString.cx > 0)
1568 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1571 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1577 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1578 sizeString.cy + DEFPAD_CY;
1579 sizeButton.cx = infoPtr->szPadding.cx +
1580 max(sizeString.cx, infoPtr->nBitmapWidth);
1584 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1585 NONLIST_NOTEXT_OFFSET;
1586 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1587 infoPtr->szPadding.cx + sizeString.cx;
1594 /***********************************************************************
1595 * TOOLBAR_CalcToolbar
1597 * This function calculates button and separator placement. It first
1598 * calculates the button sizes, gets the toolbar window width and then
1599 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1600 * on. It assigns a new location to each item and sends this location to
1601 * the tooltip window if appropriate. Finally, it updates the rcBound
1602 * rect and calculates the new required toolbar window height.
1605 TOOLBAR_CalcToolbar (HWND hwnd)
1607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1608 DWORD dwStyle = infoPtr->dwStyle;
1609 TBUTTON_INFO *btnPtr;
1610 INT i, nRows, nSepRows;
1612 SIZE sizeString, sizeButton;
1614 BOOL validImageList = FALSE;
1615 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1617 TOOLBAR_CalcStrings (hwnd, &sizeString);
1619 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1621 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1622 validImageList = TRUE;
1623 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1624 infoPtr->nButtonWidth = sizeButton.cx;
1625 infoPtr->nButtonHeight = sizeButton.cy;
1627 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1628 infoPtr->nButtonWidth = infoPtr->cxMin;
1629 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1630 infoPtr->nButtonWidth = infoPtr->cxMax;
1632 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1634 x = infoPtr->nIndent;
1635 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1640 /* from above, minimum is a button, and possible text */
1641 cx = infoPtr->nButtonWidth;
1642 cy = infoPtr->nButtonHeight;
1644 nRows = nSepRows = 0;
1646 infoPtr->rcBound.top = y;
1647 infoPtr->rcBound.left = x;
1648 infoPtr->rcBound.bottom = y + cy;
1649 infoPtr->rcBound.right = x;
1651 btnPtr = infoPtr->buttons;
1653 TRACE("cy=%d\n", cy);
1655 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1658 if (btnPtr->fsState & TBSTATE_HIDDEN)
1660 SetRectEmpty (&btnPtr->rect);
1664 cy = infoPtr->nButtonHeight;
1666 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1667 /* it is the actual width of the separator. This is used for */
1668 /* custom controls in toolbars. */
1669 if (btnPtr->fsStyle & BTNS_SEP) {
1670 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1671 cy = (btnPtr->iBitmap > 0) ?
1672 btnPtr->iBitmap : SEPARATOR_WIDTH;
1673 cx = infoPtr->nButtonWidth;
1676 cx = (btnPtr->iBitmap > 0) ?
1677 btnPtr->iBitmap : SEPARATOR_WIDTH;
1683 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1684 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1691 hOldFont = SelectObject (hdc, infoPtr->hFont);
1693 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1695 SelectObject (hdc, hOldFont);
1696 ReleaseDC (hwnd, hdc);
1698 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1699 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1704 cx = infoPtr->nButtonWidth;
1706 /* if size has been set manually then don't add on extra space
1707 * for the drop down arrow */
1708 if (!btnPtr->cx && hasDropDownArrows &&
1709 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1710 cx += DDARROW_WIDTH;
1712 if (btnPtr->fsState & TBSTATE_WRAP )
1715 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1717 if (infoPtr->rcBound.left > x)
1718 infoPtr->rcBound.left = x;
1719 if (infoPtr->rcBound.right < x + cx)
1720 infoPtr->rcBound.right = x + cx;
1721 if (infoPtr->rcBound.bottom < y + cy)
1722 infoPtr->rcBound.bottom = y + cy;
1724 /* Set the toolTip only for non-hidden, non-separator button */
1725 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1729 ZeroMemory (&ti, sizeof(ti));
1730 ti.cbSize = sizeof(ti);
1732 ti.uId = btnPtr->idCommand;
1733 ti.rect = btnPtr->rect;
1734 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1738 /* btnPtr->nRow is zero based. The space between the rows is */
1739 /* also considered as a row. */
1740 btnPtr->nRow = nRows + nSepRows;
1742 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1743 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1748 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1752 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1753 /* it is the actual width of the separator. This is used for */
1754 /* custom controls in toolbars. */
1755 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1756 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1757 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1761 /* nSepRows is used to calculate the extra height follwoing */
1765 x = infoPtr->nIndent;
1767 /* Increment row number unless this is the last button */
1768 /* and it has Wrap set. */
1769 if (i != infoPtr->nNumButtons-1)
1776 /* infoPtr->nRows is the number of rows on the toolbar */
1777 infoPtr->nRows = nRows + nSepRows + 1;
1779 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1784 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1787 TBUTTON_INFO *btnPtr;
1790 btnPtr = infoPtr->buttons;
1791 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1792 if (btnPtr->fsState & TBSTATE_HIDDEN)
1795 if (btnPtr->fsStyle & BTNS_SEP) {
1796 if (PtInRect (&btnPtr->rect, *lpPt)) {
1797 TRACE(" ON SEPARATOR %d!\n", i);
1802 if (PtInRect (&btnPtr->rect, *lpPt)) {
1803 TRACE(" ON BUTTON %d!\n", i);
1809 TRACE(" NOWHERE!\n");
1810 return TOOLBAR_NOWHERE;
1815 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1817 TBUTTON_INFO *btnPtr;
1820 if (CommandIsIndex) {
1821 TRACE("command is really index command=%d\n", idCommand);
1822 if (idCommand >= infoPtr->nNumButtons) return -1;
1825 btnPtr = infoPtr->buttons;
1826 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1827 if (btnPtr->idCommand == idCommand) {
1828 TRACE("command=%d index=%d\n", idCommand, i);
1832 TRACE("no index found for command=%d\n", idCommand);
1838 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1840 TBUTTON_INFO *btnPtr;
1843 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1846 /* check index button */
1847 btnPtr = &infoPtr->buttons[nIndex];
1848 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1849 if (btnPtr->fsState & TBSTATE_CHECKED)
1853 /* check previous buttons */
1854 nRunIndex = nIndex - 1;
1855 while (nRunIndex >= 0) {
1856 btnPtr = &infoPtr->buttons[nRunIndex];
1857 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1858 if (btnPtr->fsState & TBSTATE_CHECKED)
1866 /* check next buttons */
1867 nRunIndex = nIndex + 1;
1868 while (nRunIndex < infoPtr->nNumButtons) {
1869 btnPtr = &infoPtr->buttons[nRunIndex];
1870 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1871 if (btnPtr->fsState & TBSTATE_CHECKED)
1884 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1885 WPARAM wParam, LPARAM lParam)
1891 msg.wParam = wParam;
1892 msg.lParam = lParam;
1893 msg.time = GetMessageTime ();
1894 msg.pt.x = LOWORD(GetMessagePos ());
1895 msg.pt.y = HIWORD(GetMessagePos ());
1897 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1900 /* keeps available button list box sorted by button id */
1901 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1905 PCUSTOMBUTTON btnInfo;
1906 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1908 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1910 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1912 /* position 0 is always separator */
1913 for (i = 1; i < count; i++)
1915 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1916 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1918 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1919 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1923 /* id higher than all others add to end */
1924 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1925 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1928 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1932 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1934 if (nIndexFrom == nIndexTo)
1937 /* MSDN states that iItem is the index of the button, rather than the
1938 * command ID as used by every other NMTOOLBAR notification */
1939 nmtb.iItem = nIndexFrom;
1940 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1942 PCUSTOMBUTTON btnInfo;
1944 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1945 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1947 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1949 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1950 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1951 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1952 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1955 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1957 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1959 /* last item is always separator, so -2 instead of -1 */
1960 if (nIndexTo >= (count - 2))
1961 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1963 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1965 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1966 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1968 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1972 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1976 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1978 /* MSDN states that iItem is the index of the button, rather than the
1979 * command ID as used by every other NMTOOLBAR notification */
1980 nmtb.iItem = nIndexAvail;
1981 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1983 PCUSTOMBUTTON btnInfo;
1985 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1986 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1987 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1989 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1991 if (nIndexAvail != 0) /* index == 0 indicates separator */
1993 /* remove from 'available buttons' list */
1994 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1995 if (nIndexAvail == count-1)
1996 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1998 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2002 PCUSTOMBUTTON btnNew;
2004 /* duplicate 'separator' button */
2005 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2006 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2010 /* insert into 'toolbar button' list */
2011 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2012 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2014 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2016 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2020 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2022 PCUSTOMBUTTON btnInfo;
2023 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2025 TRACE("Remove: index %d\n", index);
2027 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2029 /* send TBN_QUERYDELETE notification */
2030 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2034 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2035 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2037 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2039 /* insert into 'available button' list */
2040 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2041 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2045 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2049 /* drag list notification function for toolbar buttons list box */
2050 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2052 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2053 switch (pDLI->uNotification)
2057 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2058 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2059 /* no dragging for last item (separator) */
2060 if (nCurrentItem >= (nCount - 1)) return FALSE;
2065 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2066 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2067 /* no dragging past last item (separator) */
2068 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2070 DrawInsert(hwnd, hwndList, nCurrentItem);
2071 /* FIXME: native uses "move button" cursor */
2072 return DL_COPYCURSOR;
2075 /* not over toolbar buttons list */
2076 if (nCurrentItem < 0)
2078 POINT ptWindow = pDLI->ptCursor;
2079 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2080 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2081 /* over available buttons list? */
2082 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2083 /* FIXME: native uses "move button" cursor */
2084 return DL_COPYCURSOR;
2086 /* clear drag arrow */
2087 DrawInsert(hwnd, hwndList, -1);
2088 return DL_STOPCURSOR;
2092 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2093 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2094 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2095 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2097 /* clear drag arrow */
2098 DrawInsert(hwnd, hwndList, -1);
2100 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2102 /* not over toolbar buttons list */
2105 POINT ptWindow = pDLI->ptCursor;
2106 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2107 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2108 /* over available buttons list? */
2109 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2110 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2115 /* Clear drag arrow */
2116 DrawInsert(hwnd, hwndList, -1);
2123 /* drag list notification function for available buttons list box */
2124 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2126 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2127 switch (pDLI->uNotification)
2133 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2134 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2135 /* no dragging past last item (separator) */
2136 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2138 DrawInsert(hwnd, hwndList, nCurrentItem);
2139 /* FIXME: native uses "move button" cursor */
2140 return DL_COPYCURSOR;
2143 /* not over toolbar buttons list */
2144 if (nCurrentItem < 0)
2146 POINT ptWindow = pDLI->ptCursor;
2147 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2148 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2149 /* over available buttons list? */
2150 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2151 /* FIXME: native uses "move button" cursor */
2152 return DL_COPYCURSOR;
2154 /* clear drag arrow */
2155 DrawInsert(hwnd, hwndList, -1);
2156 return DL_STOPCURSOR;
2160 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2161 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2162 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2163 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2165 /* clear drag arrow */
2166 DrawInsert(hwnd, hwndList, -1);
2168 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2172 /* Clear drag arrow */
2173 DrawInsert(hwnd, hwndList, -1);
2179 extern UINT uDragListMessage;
2181 /***********************************************************************
2182 * TOOLBAR_CustomizeDialogProc
2183 * This function implements the toolbar customization dialog.
2185 static INT_PTR CALLBACK
2186 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2188 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2189 PCUSTOMBUTTON btnInfo;
2191 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2196 custInfo = (PCUSTDLG_INFO)lParam;
2197 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2204 NMTBINITCUSTOMIZE nmtbic;
2206 infoPtr = custInfo->tbInfo;
2208 /* send TBN_QUERYINSERT notification */
2209 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2211 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2214 nmtbic.hwndDialog = hwnd;
2215 /* Send TBN_INITCUSTOMIZE notification */
2216 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2219 TRACE("TBNRF_HIDEHELP requested\n");
2220 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2223 /* add items to 'toolbar buttons' list and check if removable */
2224 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2226 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2227 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2228 btnInfo->btn.fsStyle = BTNS_SEP;
2229 btnInfo->bVirtual = FALSE;
2230 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2232 /* send TBN_QUERYDELETE notification */
2233 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2235 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2236 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2239 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2241 /* insert separator button into 'available buttons' list */
2242 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2243 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2244 btnInfo->btn.fsStyle = BTNS_SEP;
2245 btnInfo->bVirtual = FALSE;
2246 btnInfo->bRemovable = TRUE;
2247 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2248 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2249 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2251 /* insert all buttons into dsa */
2254 /* send TBN_GETBUTTONINFO notification */
2257 nmtb.pszText = Buffer;
2260 /* Clear previous button's text */
2261 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2263 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2266 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2267 nmtb.tbButton.fsStyle, i,
2268 nmtb.tbButton.idCommand,
2269 nmtb.tbButton.iString,
2270 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2273 /* insert button into the apropriate list */
2274 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2277 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2278 btnInfo->bVirtual = FALSE;
2279 btnInfo->bRemovable = TRUE;
2283 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2284 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2287 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2288 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2290 if (lstrlenW(nmtb.pszText))
2291 lstrcpyW(btnInfo->text, nmtb.pszText);
2292 else if (nmtb.tbButton.iString >= 0 &&
2293 nmtb.tbButton.iString < infoPtr->nNumStrings)
2295 lstrcpyW(btnInfo->text,
2296 infoPtr->strings[nmtb.tbButton.iString]);
2301 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2304 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2306 /* select first item in the 'available' list */
2307 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2309 /* append 'virtual' separator button to the 'toolbar buttons' list */
2310 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2311 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2312 btnInfo->btn.fsStyle = BTNS_SEP;
2313 btnInfo->bVirtual = TRUE;
2314 btnInfo->bRemovable = FALSE;
2315 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2316 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2317 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2319 /* select last item in the 'toolbar' list */
2320 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2321 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2323 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2324 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2326 /* set focus and disable buttons */
2327 PostMessageW (hwnd, WM_USER, 0, 0);
2332 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2333 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2334 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2335 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2339 EndDialog(hwnd, FALSE);
2343 switch (LOWORD(wParam))
2345 case IDC_TOOLBARBTN_LBOX:
2346 if (HIWORD(wParam) == LBN_SELCHANGE)
2348 PCUSTOMBUTTON btnInfo;
2353 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2354 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2356 /* send TBN_QUERYINSERT notification */
2358 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2360 /* get list box item */
2361 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2363 if (index == (count - 1))
2365 /* last item (virtual separator) */
2366 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2367 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2369 else if (index == (count - 2))
2371 /* second last item (last non-virtual item) */
2372 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2373 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2375 else if (index == 0)
2378 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2379 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2383 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2384 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2387 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2391 case IDC_MOVEUP_BTN:
2393 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2394 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2398 case IDC_MOVEDN_BTN: /* move down */
2400 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2401 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2405 case IDC_REMOVE_BTN: /* remove button */
2407 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2409 if (LB_ERR == index)
2412 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2416 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2419 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2422 case IDOK: /* Add button */
2427 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2428 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2430 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2435 EndDialog(hwnd, FALSE);
2445 /* delete items from 'toolbar buttons' listbox*/
2446 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2447 for (i = 0; i < count; i++)
2449 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2451 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2453 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2456 /* delete items from 'available buttons' listbox*/
2457 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2458 for (i = 0; i < count; i++)
2460 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2462 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2464 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2469 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2471 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2476 COLORREF oldText = 0;
2480 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2481 if (btnInfo == NULL)
2483 FIXME("btnInfo invalid!\n");
2487 /* set colors and select objects */
2488 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2489 if (btnInfo->bVirtual)
2490 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2492 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2493 hPen = CreatePen( PS_SOLID, 1,
2494 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2495 hOldPen = SelectObject (lpdis->hDC, hPen );
2496 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2498 /* fill background rectangle */
2499 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2500 lpdis->rcItem.right, lpdis->rcItem.bottom);
2502 /* calculate button and text rectangles */
2503 CopyRect (&rcButton, &lpdis->rcItem);
2504 InflateRect (&rcButton, -1, -1);
2505 CopyRect (&rcText, &rcButton);
2506 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2507 rcText.left = rcButton.right + 2;
2509 /* draw focus rectangle */
2510 if (lpdis->itemState & ODS_FOCUS)
2511 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2514 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2515 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2517 /* draw image and text */
2518 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2519 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2520 btnInfo->btn.iBitmap));
2521 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2522 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2524 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2525 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2527 /* delete objects and reset colors */
2528 SelectObject (lpdis->hDC, hOldBrush);
2529 SelectObject (lpdis->hDC, hOldPen);
2530 SetBkColor (lpdis->hDC, oldBk);
2531 SetTextColor (lpdis->hDC, oldText);
2532 DeleteObject( hPen );
2537 case WM_MEASUREITEM:
2538 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2540 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2542 lpmis->itemHeight = 15 + 8; /* default height */
2549 if (uDragListMessage && (uMsg == uDragListMessage))
2551 if (wParam == IDC_TOOLBARBTN_LBOX)
2553 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2554 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2555 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2558 else if (wParam == IDC_AVAILBTN_LBOX)
2560 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2561 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2562 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2571 /***********************************************************************
2572 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2576 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2579 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2580 INT nIndex = 0, nButtons, nCount;
2584 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2588 if (lpAddBmp->hInst == HINST_COMMCTRL)
2590 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2592 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2594 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2599 TRACE ("adding %d internal bitmaps!\n", nButtons);
2601 /* Windows resize all the buttons to the size of a newly added standard image */
2602 if (lpAddBmp->nID & 1)
2605 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2606 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2608 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2609 MAKELPARAM((WORD)24, (WORD)24));
2610 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2611 MAKELPARAM((WORD)31, (WORD)30));
2616 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2617 MAKELPARAM((WORD)16, (WORD)16));
2618 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2619 MAKELPARAM((WORD)22, (WORD)22));
2622 TOOLBAR_CalcToolbar (hwnd);
2626 nButtons = (INT)wParam;
2630 TRACE ("adding %d bitmaps!\n", nButtons);
2633 if (!infoPtr->cimlDef) {
2634 /* create new default image list */
2635 TRACE ("creating default image list!\n");
2637 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2638 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2639 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2640 infoPtr->himlInt = himlDef;
2643 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2647 WARN("No default image list available\n");
2651 nCount = ImageList_GetImageCount(himlDef);
2653 /* Add bitmaps to the default image list */
2654 if (lpAddBmp->hInst == NULL)
2657 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2658 HDC hdcImage, hdcBitmap;
2660 /* copy the bitmap before adding it so that the user's bitmap
2661 * doesn't get modified.
2663 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2665 hdcImage = CreateCompatibleDC(0);
2666 hdcBitmap = CreateCompatibleDC(0);
2668 /* create new bitmap */
2669 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2670 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2671 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2673 /* Copy the user's image */
2674 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2675 hdcBitmap, 0, 0, SRCCOPY);
2677 SelectObject (hdcImage, hOldBitmapLoad);
2678 SelectObject (hdcBitmap, hOldBitmapBitmap);
2679 DeleteDC (hdcImage);
2680 DeleteDC (hdcBitmap);
2682 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2683 DeleteObject (hbmLoad);
2685 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2687 /* Add system bitmaps */
2688 switch (lpAddBmp->nID)
2690 case IDB_STD_SMALL_COLOR:
2691 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2692 MAKEINTRESOURCEW(IDB_STD_SMALL));
2693 nIndex = ImageList_AddMasked (himlDef,
2694 hbmLoad, comctl32_color.clrBtnFace);
2695 DeleteObject (hbmLoad);
2698 case IDB_STD_LARGE_COLOR:
2699 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2700 MAKEINTRESOURCEW(IDB_STD_LARGE));
2701 nIndex = ImageList_AddMasked (himlDef,
2702 hbmLoad, comctl32_color.clrBtnFace);
2703 DeleteObject (hbmLoad);
2706 case IDB_VIEW_SMALL_COLOR:
2707 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2708 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2709 nIndex = ImageList_AddMasked (himlDef,
2710 hbmLoad, comctl32_color.clrBtnFace);
2711 DeleteObject (hbmLoad);
2714 case IDB_VIEW_LARGE_COLOR:
2715 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2716 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2717 nIndex = ImageList_AddMasked (himlDef,
2718 hbmLoad, comctl32_color.clrBtnFace);
2719 DeleteObject (hbmLoad);
2722 case IDB_HIST_SMALL_COLOR:
2723 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2724 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2725 nIndex = ImageList_AddMasked (himlDef,
2726 hbmLoad, comctl32_color.clrBtnFace);
2727 DeleteObject (hbmLoad);
2730 case IDB_HIST_LARGE_COLOR:
2731 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2732 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2733 nIndex = ImageList_AddMasked (himlDef,
2734 hbmLoad, comctl32_color.clrBtnFace);
2735 DeleteObject (hbmLoad);
2739 nIndex = ImageList_GetImageCount (himlDef);
2740 ERR ("invalid imagelist!\n");
2746 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2747 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2748 DeleteObject (hbmLoad);
2751 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2753 if (infoPtr->nNumBitmapInfos == 0)
2755 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2759 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2760 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2761 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos * sizeof(TBITMAP_INFO));
2764 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2765 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2766 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2768 infoPtr->nNumBitmapInfos++;
2769 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2773 INT imagecount = ImageList_GetImageCount(himlDef);
2775 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2777 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",
2778 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2779 infoPtr->nNumBitmaps+nButtons,imagecount);
2781 infoPtr->nNumBitmaps = imagecount;
2784 infoPtr->nNumBitmaps += nButtons;
2787 InvalidateRect(hwnd, NULL, TRUE);
2794 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2797 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2798 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2800 TRACE("adding %d buttons!\n", wParam);
2802 nAddButtons = (UINT)wParam;
2803 nOldButtons = infoPtr->nNumButtons;
2804 nNewButtons = nOldButtons + nAddButtons;
2806 if (infoPtr->nNumButtons == 0) {
2808 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2811 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2813 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2814 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2815 nOldButtons * sizeof(TBUTTON_INFO));
2819 infoPtr->nNumButtons = nNewButtons;
2821 /* insert new button data */
2822 for (nCount = 0; nCount < nAddButtons; nCount++) {
2823 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2824 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2825 btnPtr->idCommand = lpTbb[nCount].idCommand;
2826 btnPtr->fsState = lpTbb[nCount].fsState;
2827 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2828 btnPtr->dwData = lpTbb[nCount].dwData;
2829 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2830 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2832 btnPtr->iString = lpTbb[nCount].iString;
2833 btnPtr->bHot = FALSE;
2835 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2838 ZeroMemory (&ti, sizeof(ti));
2839 ti.cbSize = sizeof(ti);
2841 ti.uId = btnPtr->idCommand;
2843 ti.lpszText = LPSTR_TEXTCALLBACKW;
2845 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2850 TOOLBAR_CalcToolbar (hwnd);
2851 TOOLBAR_AutoSize (hwnd);
2853 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2855 InvalidateRect(hwnd, NULL, TRUE);
2862 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2865 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2866 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2868 TRACE("adding %d buttons!\n", wParam);
2870 nAddButtons = (UINT)wParam;
2871 nOldButtons = infoPtr->nNumButtons;
2872 nNewButtons = nOldButtons + nAddButtons;
2874 if (infoPtr->nNumButtons == 0) {
2876 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2879 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2881 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2882 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2883 nOldButtons * sizeof(TBUTTON_INFO));
2887 infoPtr->nNumButtons = nNewButtons;
2889 /* insert new button data */
2890 for (nCount = 0; nCount < nAddButtons; nCount++) {
2891 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2892 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2893 btnPtr->idCommand = lpTbb[nCount].idCommand;
2894 btnPtr->fsState = lpTbb[nCount].fsState;
2895 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2896 btnPtr->dwData = lpTbb[nCount].dwData;
2897 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2898 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2900 btnPtr->iString = lpTbb[nCount].iString;
2901 btnPtr->bHot = FALSE;
2903 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2906 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2907 ti.cbSize = sizeof (TTTOOLINFOW);
2909 ti.uId = btnPtr->idCommand;
2911 ti.lpszText = LPSTR_TEXTCALLBACKW;
2914 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2919 TOOLBAR_CalcToolbar (hwnd);
2920 TOOLBAR_AutoSize (hwnd);
2922 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2924 InvalidateRect(hwnd, NULL, TRUE);
2931 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2936 if ((wParam) && (HIWORD(lParam) == 0)) {
2939 TRACE("adding string from resource!\n");
2941 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2943 TRACE("len=%d \"%s\"\n", len, szString);
2944 nIndex = infoPtr->nNumStrings;
2945 if (infoPtr->nNumStrings == 0) {
2947 Alloc (sizeof(LPWSTR));
2950 LPWSTR *oldStrings = infoPtr->strings;
2952 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2953 memcpy (&infoPtr->strings[0], &oldStrings[0],
2954 sizeof(LPWSTR) * infoPtr->nNumStrings);
2958 /*Alloc zeros out the allocated memory*/
2959 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2960 infoPtr->nNumStrings++;
2963 LPSTR p = (LPSTR)lParam;
2968 TRACE("adding string(s) from array!\n");
2970 nIndex = infoPtr->nNumStrings;
2973 TRACE("len=%d \"%s\"\n", len, p);
2975 if (infoPtr->nNumStrings == 0) {
2977 Alloc (sizeof(LPWSTR));
2980 LPWSTR *oldStrings = infoPtr->strings;
2982 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2983 memcpy (&infoPtr->strings[0], &oldStrings[0],
2984 sizeof(LPWSTR) * infoPtr->nNumStrings);
2988 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2989 infoPtr->nNumStrings++;
3000 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3002 #define MAX_RESOURCE_STRING_LENGTH 512
3003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3006 if ((wParam) && (HIWORD(lParam) == 0)) {
3007 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3009 TRACE("adding string from resource!\n");
3011 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
3012 szString, MAX_RESOURCE_STRING_LENGTH);
3014 TRACE("len=%d %s\n", len, debugstr_w(szString));
3015 TRACE("First char: 0x%x\n", *szString);
3016 if (szString[0] == L'|')
3018 PWSTR p = szString + 1;
3020 nIndex = infoPtr->nNumStrings;
3021 while (*p != L'|' && *p != L'\0') {
3024 if (infoPtr->nNumStrings == 0) {
3025 infoPtr->strings = Alloc (sizeof(LPWSTR));
3029 LPWSTR *oldStrings = infoPtr->strings;
3030 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3031 memcpy(&infoPtr->strings[0], &oldStrings[0],
3032 sizeof(LPWSTR) * infoPtr->nNumStrings);
3036 np=strchrW (p, '|');
3044 TRACE("len=%d %s\n", len, debugstr_w(p));
3045 infoPtr->strings[infoPtr->nNumStrings] =
3046 Alloc (sizeof(WCHAR)*(len+1));
3047 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3048 infoPtr->nNumStrings++;
3055 nIndex = infoPtr->nNumStrings;
3056 if (infoPtr->nNumStrings == 0) {
3058 Alloc (sizeof(LPWSTR));
3061 LPWSTR *oldStrings = infoPtr->strings;
3063 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3064 memcpy (&infoPtr->strings[0], &oldStrings[0],
3065 sizeof(LPWSTR) * infoPtr->nNumStrings);
3069 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3070 infoPtr->nNumStrings++;
3074 LPWSTR p = (LPWSTR)lParam;
3079 TRACE("adding string(s) from array!\n");
3080 nIndex = infoPtr->nNumStrings;
3084 TRACE("len=%d %s\n", len, debugstr_w(p));
3085 if (infoPtr->nNumStrings == 0) {
3087 Alloc (sizeof(LPWSTR));
3090 LPWSTR *oldStrings = infoPtr->strings;
3092 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3093 memcpy (&infoPtr->strings[0], &oldStrings[0],
3094 sizeof(LPWSTR) * infoPtr->nNumStrings);
3098 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3099 infoPtr->nNumStrings++;
3110 TOOLBAR_AutoSize (HWND hwnd)
3112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3118 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3120 parent = GetParent (hwnd);
3122 if (!parent || !infoPtr->bDoRedraw)
3125 GetClientRect(parent, &parent_rect);
3127 x = parent_rect.left;
3128 y = parent_rect.top;
3130 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3132 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3133 cx = parent_rect.right - parent_rect.left;
3135 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3137 TOOLBAR_CalcToolbar(hwnd);
3138 InvalidateRect( hwnd, NULL, TRUE );
3141 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3144 UINT uPosFlags = SWP_NOZORDER;
3146 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3148 GetWindowRect(hwnd, &window_rect);
3149 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3150 y = window_rect.top;
3152 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3154 GetWindowRect(hwnd, &window_rect);
3155 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3158 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3159 uPosFlags |= SWP_NOMOVE;
3161 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3162 cy += GetSystemMetrics(SM_CYEDGE);
3164 if (infoPtr->dwStyle & WS_BORDER)
3166 x = y = 1; /* FIXME: this looks wrong */
3167 cy += GetSystemMetrics(SM_CYEDGE);
3168 cx += GetSystemMetrics(SM_CXEDGE);
3171 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3179 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3181 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3183 return infoPtr->nNumButtons;
3188 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3192 infoPtr->dwStructSize = (DWORD)wParam;
3199 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3201 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3202 TBUTTON_INFO *btnPtr;
3205 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3207 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3211 btnPtr = &infoPtr->buttons[nIndex];
3212 btnPtr->iBitmap = LOWORD(lParam);
3214 /* we HAVE to erase the background, the new bitmap could be */
3216 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3223 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3226 TBUTTON_INFO *btnPtr;
3229 BOOL bChecked = FALSE;
3231 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3233 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3238 btnPtr = &infoPtr->buttons[nIndex];
3240 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3242 if (LOWORD(lParam) == FALSE)
3243 btnPtr->fsState &= ~TBSTATE_CHECKED;
3245 if (btnPtr->fsStyle & BTNS_GROUP) {
3247 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3248 if (nOldIndex == nIndex)
3250 if (nOldIndex != -1)
3251 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3253 btnPtr->fsState |= TBSTATE_CHECKED;
3256 if( bChecked != LOWORD(lParam) )
3258 if (nOldIndex != -1)
3259 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3260 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3263 /* FIXME: Send a WM_NOTIFY?? */
3270 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3272 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3274 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3279 TOOLBAR_Customize (HWND hwnd)
3281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3282 CUSTDLG_INFO custInfo;
3288 custInfo.tbInfo = infoPtr;
3289 custInfo.tbHwnd = hwnd;
3291 /* send TBN_BEGINADJUST notification */
3292 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3294 if (!(hRes = FindResourceW (COMCTL32_hModule,
3295 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3296 (LPWSTR)RT_DIALOG)))
3299 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3302 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3303 (LPDLGTEMPLATEW)template,
3305 TOOLBAR_CustomizeDialogProc,
3308 /* send TBN_ENDADJUST notification */
3309 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3316 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3318 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3319 INT nIndex = (INT)wParam;
3321 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3323 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3326 memset(&nmtb, 0, sizeof(nmtb));
3327 nmtb.iItem = btnPtr->idCommand;
3328 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3329 nmtb.tbButton.idCommand = btnPtr->idCommand;
3330 nmtb.tbButton.fsState = btnPtr->fsState;
3331 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3332 nmtb.tbButton.dwData = btnPtr->dwData;
3333 nmtb.tbButton.iString = btnPtr->iString;
3334 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3336 if ((infoPtr->hwndToolTip) &&
3337 !(btnPtr->fsStyle & BTNS_SEP)) {
3340 ZeroMemory (&ti, sizeof(ti));
3341 ti.cbSize = sizeof(ti);
3343 ti.uId = infoPtr->buttons[nIndex].idCommand;
3345 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3348 if (infoPtr->nNumButtons == 1) {
3349 TRACE(" simple delete!\n");
3350 Free (infoPtr->buttons);
3351 infoPtr->buttons = NULL;
3352 infoPtr->nNumButtons = 0;
3355 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3356 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3358 infoPtr->nNumButtons--;
3359 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3361 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3362 nIndex * sizeof(TBUTTON_INFO));
3365 if (nIndex < infoPtr->nNumButtons) {
3366 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3367 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3373 TOOLBAR_CalcToolbar (hwnd);
3375 InvalidateRect (hwnd, NULL, TRUE);
3382 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3384 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3385 TBUTTON_INFO *btnPtr;
3389 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3391 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3396 btnPtr = &infoPtr->buttons[nIndex];
3398 bState = btnPtr->fsState & TBSTATE_ENABLED;
3400 /* update the toolbar button state */
3401 if(LOWORD(lParam) == FALSE) {
3402 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3404 btnPtr->fsState |= TBSTATE_ENABLED;
3407 /* redraw the button only if the state of the button changed */
3408 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3409 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3415 static inline LRESULT
3416 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3420 return infoPtr->bAnchor;
3425 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3430 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3434 return infoPtr->buttons[nIndex].iBitmap;
3438 static inline LRESULT
3439 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3441 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3446 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3448 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3449 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3450 INT nIndex = (INT)wParam;
3451 TBUTTON_INFO *btnPtr;
3456 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3459 btnPtr = &infoPtr->buttons[nIndex];
3460 lpTbb->iBitmap = btnPtr->iBitmap;
3461 lpTbb->idCommand = btnPtr->idCommand;
3462 lpTbb->fsState = btnPtr->fsState;
3463 lpTbb->fsStyle = btnPtr->fsStyle;
3464 lpTbb->bReserved[0] = 0;
3465 lpTbb->bReserved[1] = 0;
3466 lpTbb->dwData = btnPtr->dwData;
3467 lpTbb->iString = btnPtr->iString;
3474 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3477 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3478 TBUTTON_INFO *btnPtr;
3481 if (lpTbInfo == NULL)
3483 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3487 lpTbInfo->dwMask & 0x80000000);
3491 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3493 if (lpTbInfo->dwMask & TBIF_COMMAND)
3494 lpTbInfo->idCommand = btnPtr->idCommand;
3495 if (lpTbInfo->dwMask & TBIF_IMAGE)
3496 lpTbInfo->iImage = btnPtr->iBitmap;
3497 if (lpTbInfo->dwMask & TBIF_LPARAM)
3498 lpTbInfo->lParam = btnPtr->dwData;
3499 if (lpTbInfo->dwMask & TBIF_SIZE)
3500 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3501 if (lpTbInfo->dwMask & TBIF_STATE)
3502 lpTbInfo->fsState = btnPtr->fsState;
3503 if (lpTbInfo->dwMask & TBIF_STYLE)
3504 lpTbInfo->fsStyle = btnPtr->fsStyle;
3505 if (lpTbInfo->dwMask & TBIF_TEXT) {
3506 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3507 can't use TOOLBAR_GetText here */
3509 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3510 lpText = (LPWSTR)btnPtr->iString;
3511 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3513 lpTbInfo->pszText[0] = '\0';
3520 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3522 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3523 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3524 TBUTTON_INFO *btnPtr;
3527 if (lpTbInfo == NULL)
3529 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3532 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3533 lpTbInfo->dwMask & 0x80000000);
3537 btnPtr = &infoPtr->buttons[nIndex];
3542 if (lpTbInfo->dwMask & TBIF_COMMAND)
3543 lpTbInfo->idCommand = btnPtr->idCommand;
3544 if (lpTbInfo->dwMask & TBIF_IMAGE)
3545 lpTbInfo->iImage = btnPtr->iBitmap;
3546 if (lpTbInfo->dwMask & TBIF_LPARAM)
3547 lpTbInfo->lParam = btnPtr->dwData;
3548 if (lpTbInfo->dwMask & TBIF_SIZE)
3549 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3550 if (lpTbInfo->dwMask & TBIF_STATE)
3551 lpTbInfo->fsState = btnPtr->fsState;
3552 if (lpTbInfo->dwMask & TBIF_STYLE)
3553 lpTbInfo->fsStyle = btnPtr->fsStyle;
3554 if (lpTbInfo->dwMask & TBIF_TEXT) {
3555 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3556 can't use TOOLBAR_GetText here */
3558 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3559 lpText = (LPWSTR)btnPtr->iString;
3560 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3562 lpTbInfo->pszText[0] = '\0';
3570 TOOLBAR_GetButtonSize (HWND hwnd)
3572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3574 if (infoPtr->nNumButtons > 0)
3575 return MAKELONG((WORD)infoPtr->nButtonWidth,
3576 (WORD)infoPtr->nButtonHeight);
3578 return MAKELONG(23,22);
3583 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3592 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3596 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3598 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3599 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3604 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3611 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3615 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3619 ret = strlenW (lpText);
3622 strcpyW ((LPWSTR)lParam, lpText);
3630 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3632 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3633 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3634 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3638 inline static LRESULT
3639 TOOLBAR_GetExtendedStyle (HWND hwnd)
3641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 return infoPtr->dwExStyle;
3650 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3652 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3653 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3654 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3659 TOOLBAR_GetHotItem (HWND hwnd)
3661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3663 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3666 if (infoPtr->nHotItem < 0)
3669 return (LRESULT)infoPtr->nHotItem;
3674 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3676 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3677 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3678 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3683 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3686 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3688 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3690 *lptbim = infoPtr->tbim;
3697 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3699 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3701 TRACE("hwnd = %p\n", hwnd);
3703 return (LRESULT)infoPtr->clrInsertMark;
3708 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3711 TBUTTON_INFO *btnPtr;
3715 nIndex = (INT)wParam;
3716 btnPtr = &infoPtr->buttons[nIndex];
3717 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3719 lpRect = (LPRECT)lParam;
3722 if (btnPtr->fsState & TBSTATE_HIDDEN)
3725 lpRect->left = btnPtr->rect.left;
3726 lpRect->right = btnPtr->rect.right;
3727 lpRect->bottom = btnPtr->rect.bottom;
3728 lpRect->top = btnPtr->rect.top;
3735 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3738 LPSIZE lpSize = (LPSIZE)lParam;
3743 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3744 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3746 TRACE("maximum size %ld x %ld\n",
3747 infoPtr->rcBound.right - infoPtr->rcBound.left,
3748 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3754 /* << TOOLBAR_GetObject >> */
3758 TOOLBAR_GetPadding (HWND hwnd)
3760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3763 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3764 return (LRESULT) oldPad;
3769 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3772 TBUTTON_INFO *btnPtr;
3776 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3777 btnPtr = &infoPtr->buttons[nIndex];
3778 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3780 lpRect = (LPRECT)lParam;
3784 lpRect->left = btnPtr->rect.left;
3785 lpRect->right = btnPtr->rect.right;
3786 lpRect->bottom = btnPtr->rect.bottom;
3787 lpRect->top = btnPtr->rect.top;
3794 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3798 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3799 return infoPtr->nRows;
3806 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3808 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3811 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3815 return infoPtr->buttons[nIndex].fsState;
3820 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3822 return GetWindowLongW(hwnd, GWL_STYLE);
3827 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3831 return infoPtr->nMaxTextRows;
3836 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 return (LRESULT)infoPtr->hwndToolTip;
3845 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3849 TRACE("%s hwnd=%p\n",
3850 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3852 return infoPtr->bUnicode;
3856 inline static LRESULT
3857 TOOLBAR_GetVersion (HWND hwnd)
3859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3860 return infoPtr->iVersion;
3865 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3868 TBUTTON_INFO *btnPtr;
3873 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3877 btnPtr = &infoPtr->buttons[nIndex];
3878 if (LOWORD(lParam) == FALSE)
3879 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3881 btnPtr->fsState |= TBSTATE_HIDDEN;
3883 TOOLBAR_CalcToolbar (hwnd);
3885 InvalidateRect (hwnd, NULL, TRUE);
3891 inline static LRESULT
3892 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3894 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3899 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3901 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3902 TBUTTON_INFO *btnPtr;
3906 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3910 btnPtr = &infoPtr->buttons[nIndex];
3911 oldState = btnPtr->fsState;
3912 if (LOWORD(lParam) == FALSE)
3913 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3915 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3917 if(oldState != btnPtr->fsState)
3918 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3925 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3928 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3929 INT nIndex = (INT)wParam;
3930 TBUTTON_INFO *oldButtons;
3935 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3938 /* EPP: this seems to be an undocumented call (from my IE4)
3939 * I assume in that case that:
3940 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3941 * - index of insertion is at the end of existing buttons
3942 * I only see this happen with nIndex == -1, but it could have a special
3943 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3945 nIndex = infoPtr->nNumButtons;
3947 } else if (nIndex < 0)
3950 /* If the string passed is not an index, assume address of string
3951 and do our own AddString */
3952 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3956 TRACE("string %s passed instead of index, adding string\n",
3957 debugstr_a((LPSTR)lpTbb->iString));
3958 len = strlen((LPSTR)lpTbb->iString) + 2;
3960 strcpy(ptr, (LPSTR)lpTbb->iString);
3961 ptr[len - 1] = 0; /* ended by two '\0' */
3962 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3966 TRACE("inserting button index=%d\n", nIndex);
3967 if (nIndex > infoPtr->nNumButtons) {
3968 nIndex = infoPtr->nNumButtons;
3969 TRACE("adjust index=%d\n", nIndex);
3972 oldButtons = infoPtr->buttons;
3973 infoPtr->nNumButtons++;
3974 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3975 /* pre insert copy */
3977 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3978 nIndex * sizeof(TBUTTON_INFO));
3981 /* insert new button */
3982 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3983 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3984 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3985 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3986 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3987 /* if passed string and not index, then add string */
3988 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3989 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3992 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3994 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3997 ZeroMemory (&ti, sizeof(ti));
3998 ti.cbSize = sizeof (ti);
4000 ti.uId = lpTbb->idCommand;
4002 ti.lpszText = LPSTR_TEXTCALLBACKW;
4004 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4008 /* post insert copy */
4009 if (nIndex < infoPtr->nNumButtons - 1) {
4010 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4011 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4016 TOOLBAR_CalcToolbar (hwnd);
4017 TOOLBAR_AutoSize (hwnd);
4019 InvalidateRect (hwnd, NULL, TRUE);
4026 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4029 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4030 INT nIndex = (INT)wParam;
4031 TBUTTON_INFO *oldButtons;
4036 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4039 /* EPP: this seems to be an undocumented call (from my IE4)
4040 * I assume in that case that:
4041 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4042 * - index of insertion is at the end of existing buttons
4043 * I only see this happen with nIndex == -1, but it could have a special
4044 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4046 nIndex = infoPtr->nNumButtons;
4048 } else if (nIndex < 0)
4051 /* If the string passed is not an index, assume address of string
4052 and do our own AddString */
4053 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4057 TRACE("string %s passed instead of index, adding string\n",
4058 debugstr_w((LPWSTR)lpTbb->iString));
4059 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4060 ptr = Alloc(len*sizeof(WCHAR));
4061 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4062 ptr[len - 1] = 0; /* ended by two '\0' */
4063 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4067 TRACE("inserting button index=%d\n", nIndex);
4068 if (nIndex > infoPtr->nNumButtons) {
4069 nIndex = infoPtr->nNumButtons;
4070 TRACE("adjust index=%d\n", nIndex);
4073 oldButtons = infoPtr->buttons;
4074 infoPtr->nNumButtons++;
4075 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4076 /* pre insert copy */
4078 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4079 nIndex * sizeof(TBUTTON_INFO));
4082 /* insert new button */
4083 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4084 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4085 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4086 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4087 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4088 /* if passed string and not index, then add string */
4089 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4090 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4093 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4095 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4098 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4099 ti.cbSize = sizeof (TTTOOLINFOW);
4101 ti.uId = lpTbb->idCommand;
4103 ti.lpszText = LPSTR_TEXTCALLBACKW;
4105 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4109 /* post insert copy */
4110 if (nIndex < infoPtr->nNumButtons - 1) {
4111 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4112 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4117 TOOLBAR_CalcToolbar (hwnd);
4118 TOOLBAR_AutoSize (hwnd);
4120 InvalidateRect (hwnd, NULL, TRUE);
4126 /* << TOOLBAR_InsertMarkHitTest >> */
4130 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4135 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4139 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4144 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4146 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4149 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4153 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4158 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4163 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4167 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4172 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4177 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4181 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4186 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4191 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4195 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4200 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4205 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4209 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4214 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4217 tbab.hInst = (HINSTANCE)lParam;
4218 tbab.nID = (UINT_PTR)wParam;
4220 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4222 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4227 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4229 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4230 WCHAR wAccel = (WCHAR)wParam;
4231 UINT* pIDButton = (UINT*)lParam;
4232 WCHAR wszAccel[] = {'&',wAccel,0};
4235 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4236 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4238 for (i = 0; i < infoPtr->nNumButtons; i++)
4240 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4241 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4242 !(btnPtr->fsState & TBSTATE_HIDDEN))
4244 int iLen = strlenW(wszAccel);
4245 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4252 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4257 if (!strncmpiW(lpszStr, wszAccel, iLen))
4259 *pIDButton = btnPtr->idCommand;
4271 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4276 TBUTTON_INFO *btnPtr;
4278 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4280 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4284 btnPtr = &infoPtr->buttons[nIndex];
4285 oldState = btnPtr->fsState;
4288 btnPtr->fsState |= TBSTATE_MARKED;
4290 btnPtr->fsState &= ~TBSTATE_MARKED;
4292 if(oldState != btnPtr->fsState)
4293 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4299 /* fixes up an index of a button affected by a move */
4300 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4304 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4306 else if (*pIndex == nIndex)
4307 *pIndex = nMoveIndex;
4311 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4313 else if (*pIndex == nIndex)
4314 *pIndex = nMoveIndex;
4320 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4322 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4325 INT nMoveIndex = (INT)lParam;
4326 TBUTTON_INFO button;
4328 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4330 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4331 if ((nIndex == -1) || (nMoveIndex < 0))
4334 if (nMoveIndex > infoPtr->nNumButtons - 1)
4335 nMoveIndex = infoPtr->nNumButtons - 1;
4337 button = infoPtr->buttons[nIndex];
4339 /* move button right */
4340 if (nIndex < nMoveIndex)
4342 nCount = nMoveIndex - nIndex;
4343 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4344 infoPtr->buttons[nMoveIndex] = button;
4346 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4347 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4348 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4349 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4351 else if (nIndex > nMoveIndex) /* move button left */
4353 nCount = nIndex - nMoveIndex;
4354 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4355 infoPtr->buttons[nMoveIndex] = button;
4357 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4358 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4359 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4360 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4363 TOOLBAR_CalcToolbar(hwnd);
4364 TOOLBAR_AutoSize(hwnd);
4365 InvalidateRect(hwnd, NULL, TRUE);
4372 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4374 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4375 TBUTTON_INFO *btnPtr;
4379 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4383 btnPtr = &infoPtr->buttons[nIndex];
4384 oldState = btnPtr->fsState;
4385 if (LOWORD(lParam) == FALSE)
4386 btnPtr->fsState &= ~TBSTATE_PRESSED;
4388 btnPtr->fsState |= TBSTATE_PRESSED;
4390 if(oldState != btnPtr->fsState)
4391 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4396 /* FIXME: there might still be some confusion her between number of buttons
4397 * and number of bitmaps */
4399 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4401 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4402 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4404 HBITMAP hbmLoad = NULL;
4405 int i = 0, nOldButtons = 0, pos = 0;
4406 int nOldBitmaps, nNewBitmaps = 0;
4407 HIMAGELIST himlDef = 0;
4409 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4410 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4411 lpReplace->nButtons);
4413 if (lpReplace->hInstOld == HINST_COMMCTRL)
4415 FIXME("changing standard bitmaps not implemented\n");
4418 else if (lpReplace->hInstOld != 0)
4419 FIXME("resources not in the current module not implemented\n");
4421 if (lpReplace->hInstNew)
4423 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4428 hBitmap = (HBITMAP) lpReplace->nIDNew;
4431 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4432 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4433 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4434 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4435 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4437 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4438 nOldButtons = tbi->nButtons;
4439 tbi->nButtons = lpReplace->nButtons;
4440 tbi->hInst = lpReplace->hInstNew;
4441 tbi->nID = lpReplace->nIDNew;
4442 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4445 pos += tbi->nButtons;
4448 if (nOldButtons == 0)
4450 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4452 DeleteObject (hbmLoad);
4456 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4457 nOldBitmaps = ImageList_GetImageCount(himlDef);
4459 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4461 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4462 ImageList_Remove(himlDef, i);
4467 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4468 HDC hdcImage, hdcBitmap;
4470 /* copy the bitmap before adding it so that the user's bitmap
4471 * doesn't get modified.
4473 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4475 hdcImage = CreateCompatibleDC(0);
4476 hdcBitmap = CreateCompatibleDC(0);
4478 /* create new bitmap */
4479 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4480 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4481 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4483 /* Copy the user's image */
4484 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4485 hdcBitmap, 0, 0, SRCCOPY);
4487 SelectObject (hdcImage, hOldBitmapLoad);
4488 SelectObject (hdcBitmap, hOldBitmapBitmap);
4489 DeleteDC (hdcImage);
4490 DeleteDC (hdcBitmap);
4492 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4493 nNewBitmaps = ImageList_GetImageCount(himlDef);
4494 DeleteObject (hbmLoad);
4497 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4499 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4500 pos, nOldBitmaps, nNewBitmaps);
4502 InvalidateRect(hwnd, NULL, TRUE);
4505 DeleteObject (hbmLoad);
4510 /* helper for TOOLBAR_SaveRestoreW */
4512 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4514 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4515 debugstr_w(lpSave->pszValueName));
4521 /* helper for TOOLBAR_Restore */
4523 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4528 ZeroMemory(&ti, sizeof(ti));
4529 ti.cbSize = sizeof(ti);
4530 ti.hwnd = infoPtr->hwndSelf;
4532 for (i = 0; i < infoPtr->nNumButtons; i++)
4534 if ((infoPtr->hwndToolTip) &&
4535 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4537 ti.uId = infoPtr->buttons[i].idCommand;
4538 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4542 Free(infoPtr->buttons);
4543 infoPtr->buttons = NULL;
4544 infoPtr->nNumButtons = 0;
4548 /* helper for TOOLBAR_SaveRestoreW */
4550 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4559 /* restore toolbar information */
4560 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4561 debugstr_w(lpSave->pszValueName));
4563 memset(&nmtbr, 0, sizeof(nmtbr));
4565 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4566 KEY_QUERY_VALUE, &hkey);
4568 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4570 if (!res && dwType != REG_BINARY)
4571 res = ERROR_FILE_NOT_FOUND;
4574 nmtbr.pData = Alloc(dwSize);
4575 nmtbr.cbData = (UINT)dwSize;
4576 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4579 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4580 (LPBYTE)nmtbr.pData, &dwSize);
4583 nmtbr.pCurrent = nmtbr.pData;
4585 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4586 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4588 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4592 /* remove all existing buttons as this function is designed to
4593 * restore the toolbar to a previously saved state */
4594 TOOLBAR_DeleteAllButtons(infoPtr);
4596 for (i = 0; i < nmtbr.cButtons; i++)
4599 nmtbr.tbButton.iBitmap = -1;
4600 nmtbr.tbButton.fsState = 0;
4601 nmtbr.tbButton.fsStyle = 0;
4602 nmtbr.tbButton.idCommand = 0;
4603 if (*nmtbr.pCurrent == (DWORD)-1)
4606 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4607 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4609 else if (*nmtbr.pCurrent == (DWORD)-2)
4611 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4613 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4617 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4619 /* can't contain real string as we don't know whether
4620 * the client put an ANSI or Unicode string in there */
4621 if (HIWORD(nmtbr.tbButton.iString))
4622 nmtbr.tbButton.iString = 0;
4624 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4625 (LPARAM)&nmtbr.tbButton);
4628 /* do legacy notifications */
4629 if (infoPtr->iVersion < 5)
4631 /* FIXME: send TBN_BEGINADJUST */
4632 FIXME("send TBN_GETBUTTONINFO for each button\n");
4633 /* FIXME: send TBN_ENDADJUST */
4636 /* remove all uninitialised buttons
4637 * note: loop backwards to avoid having to fixup i on a
4639 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4640 if (infoPtr->buttons[i].iBitmap == -1)
4641 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4643 /* only indicate success if at least one button survived */
4644 if (infoPtr->nNumButtons > 0) ret = TRUE;
4655 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4659 if (lpSave == NULL) return 0;
4662 return TOOLBAR_Save(infoPtr, lpSave);
4664 return TOOLBAR_Restore(infoPtr, lpSave);
4669 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4671 LPWSTR pszValueName = 0, pszSubKey = 0;
4672 TBSAVEPARAMSW SaveW;
4676 if (lpSave == NULL) return 0;
4678 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4679 pszSubKey = Alloc(len * sizeof(WCHAR));
4680 if (pszSubKey) goto exit;
4681 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4683 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4684 pszValueName = Alloc(len * sizeof(WCHAR));
4685 if (!pszValueName) goto exit;
4686 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4688 SaveW.pszValueName = pszValueName;
4689 SaveW.pszSubKey = pszSubKey;
4690 SaveW.hkr = lpSave->hkr;
4691 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4694 Free (pszValueName);
4702 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4705 BOOL bOldAnchor = infoPtr->bAnchor;
4707 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4709 infoPtr->bAnchor = (BOOL)wParam;
4711 /* Native does not remove the hot effect from an already hot button */
4713 return (LRESULT)bOldAnchor;
4718 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4720 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4721 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4723 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4726 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4728 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4729 lParam = MAKELPARAM(16, 15);
4731 if (infoPtr->nNumButtons > 0)
4732 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4733 infoPtr->nNumButtons,
4734 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4735 LOWORD(lParam), HIWORD(lParam));
4737 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4738 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4741 if ((himlDef == infoPtr->himlInt) &&
4742 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4744 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4745 infoPtr->nBitmapHeight);
4753 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4755 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4756 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4757 TBUTTON_INFO *btnPtr;
4763 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4766 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4767 lptbbi->dwMask & 0x80000000);
4771 btnPtr = &infoPtr->buttons[nIndex];
4772 if (lptbbi->dwMask & TBIF_COMMAND)
4773 btnPtr->idCommand = lptbbi->idCommand;
4774 if (lptbbi->dwMask & TBIF_IMAGE)
4775 btnPtr->iBitmap = lptbbi->iImage;
4776 if (lptbbi->dwMask & TBIF_LPARAM)
4777 btnPtr->dwData = lptbbi->lParam;
4778 if (lptbbi->dwMask & TBIF_SIZE)
4779 btnPtr->cx = lptbbi->cx;
4780 if (lptbbi->dwMask & TBIF_STATE)
4781 btnPtr->fsState = lptbbi->fsState;
4782 if (lptbbi->dwMask & TBIF_STYLE)
4783 btnPtr->fsStyle = lptbbi->fsStyle;
4785 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4786 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4787 /* iString is index, zero it to make Str_SetPtr succeed */
4790 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4793 /* save the button rect to see if we need to redraw the whole toolbar */
4794 oldBtnRect = btnPtr->rect;
4795 TOOLBAR_CalcToolbar(hwnd);
4797 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4798 InvalidateRect(hwnd, NULL, TRUE);
4800 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4807 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4810 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4811 TBUTTON_INFO *btnPtr;
4817 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4820 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4821 lptbbi->dwMask & 0x80000000);
4825 btnPtr = &infoPtr->buttons[nIndex];
4826 if (lptbbi->dwMask & TBIF_COMMAND)
4827 btnPtr->idCommand = lptbbi->idCommand;
4828 if (lptbbi->dwMask & TBIF_IMAGE)
4829 btnPtr->iBitmap = lptbbi->iImage;
4830 if (lptbbi->dwMask & TBIF_LPARAM)
4831 btnPtr->dwData = lptbbi->lParam;
4832 if (lptbbi->dwMask & TBIF_SIZE)
4833 btnPtr->cx = lptbbi->cx;
4834 if (lptbbi->dwMask & TBIF_STATE)
4835 btnPtr->fsState = lptbbi->fsState;
4836 if (lptbbi->dwMask & TBIF_STYLE)
4837 btnPtr->fsStyle = lptbbi->fsStyle;
4839 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4840 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4841 /* iString is index, zero it to make Str_SetPtr succeed */
4843 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4846 /* save the button rect to see if we need to redraw the whole toolbar */
4847 oldBtnRect = btnPtr->rect;
4848 TOOLBAR_CalcToolbar(hwnd);
4850 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4851 InvalidateRect(hwnd, NULL, TRUE);
4853 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4860 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4863 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4865 if ((cx < 0) || (cy < 0))
4867 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4871 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4873 /* The documentation claims you can only change the button size before
4874 * any button has been added. But this is wrong.
4875 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4876 * it to the toolbar, and it checks that the return value is nonzero - mjm
4877 * Further testing shows that we must actually perform the change too.
4880 * The documentation also does not mention that if 0 is supplied for
4881 * either size, the system changes it to the default of 24 wide and
4882 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4884 infoPtr->nButtonWidth = (cx) ? cx : 24;
4885 infoPtr->nButtonHeight = (cy) ? cy : 22;
4891 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4895 /* if setting to current values, ignore */
4896 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4897 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4898 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4899 infoPtr->cxMin, infoPtr->cxMax);
4903 /* save new values */
4904 infoPtr->cxMin = (INT)LOWORD(lParam);
4905 infoPtr->cxMax = (INT)HIWORD(lParam);
4907 /* otherwise we need to recalc the toolbar and in some cases
4908 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4909 which doesn't actually draw - GA). */
4910 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4911 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4913 TOOLBAR_CalcToolbar (hwnd);
4915 InvalidateRect (hwnd, NULL, TRUE);
4922 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4925 INT nIndex = (INT)wParam;
4927 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4930 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4932 if (infoPtr->hwndToolTip) {
4934 FIXME("change tool tip!\n");
4943 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4946 HIMAGELIST himl = (HIMAGELIST)lParam;
4947 HIMAGELIST himlTemp;
4950 if (infoPtr->iVersion >= 5)
4953 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4954 &infoPtr->cimlDis, himl, id);
4956 /* FIXME: redraw ? */
4958 return (LRESULT)himlTemp;
4963 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4968 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4970 dwTemp = infoPtr->dwDTFlags;
4971 infoPtr->dwDTFlags =
4972 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4974 return (LRESULT)dwTemp;
4977 /* This function differs a bit from what MSDN says it does:
4978 * 1. lParam contains extended style flags to OR with current style
4979 * (MSDN isn't clear on the OR bit)
4980 * 2. wParam appears to contain extended style flags to be reset
4981 * (MSDN says that this parameter is reserved)
4984 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4989 dwTemp = infoPtr->dwExStyle;
4990 infoPtr->dwExStyle &= ~wParam;
4991 infoPtr->dwExStyle |= (DWORD)lParam;
4993 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4995 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4996 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4997 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4999 TOOLBAR_CalcToolbar (hwnd);
5001 TOOLBAR_AutoSize(hwnd);
5003 InvalidateRect(hwnd, NULL, TRUE);
5005 return (LRESULT)dwTemp;
5010 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5013 HIMAGELIST himlTemp;
5014 HIMAGELIST himl = (HIMAGELIST)lParam;
5017 if (infoPtr->iVersion >= 5)
5020 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
5022 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
5023 &infoPtr->cimlHot, himl, id);
5025 /* FIXME: redraw ? */
5027 return (LRESULT)himlTemp;
5031 /* Makes previous hot button no longer hot, makes the specified
5032 * button hot and sends appropriate notifications. dwReason is one or
5033 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5034 * NOTE 1: this function does not validate nHit
5035 * NOTE 2: the name of this function is completely made up and
5036 * not based on any documentation from Microsoft. */
5038 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5040 if (infoPtr->nHotItem != nHit)
5042 NMTBHOTITEM nmhotitem;
5043 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5044 LRESULT no_highlight;
5046 /* Remove the effect of an old hot button if the button was
5047 drawn with the hot button effect */
5048 if(infoPtr->nHotItem >= 0)
5050 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5051 oldBtnPtr->bHot = FALSE;
5054 infoPtr->nHotItem = nHit;
5056 /* It's not a separator or in nowhere. It's a hot button. */
5058 btnPtr = &infoPtr->buttons[nHit];
5060 nmhotitem.dwFlags = dwReason;
5062 nmhotitem.idOld = oldBtnPtr->idCommand;
5064 nmhotitem.dwFlags |= HICF_ENTERING;
5066 nmhotitem.idNew = btnPtr->idCommand;
5068 nmhotitem.dwFlags |= HICF_LEAVING;
5070 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5072 /* now invalidate the old and new buttons so they will be painted,
5073 * but only if they are enabled - disabled buttons cannot become hot */
5074 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5075 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5076 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5078 btnPtr->bHot = TRUE;
5079 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5085 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5088 INT nOldHotItem = infoPtr->nHotItem;
5090 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5092 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5095 /* NOTE: an application can still remove the hot item even if anchor
5096 * highlighting is enabled */
5098 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5099 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5101 if (nOldHotItem < 0)
5104 return (LRESULT)nOldHotItem;
5109 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5112 HIMAGELIST himlTemp;
5113 HIMAGELIST himl = (HIMAGELIST)lParam;
5116 if (infoPtr->iVersion >= 5)
5119 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5120 &infoPtr->cimlDef, himl, id);
5122 infoPtr->nNumBitmaps = 0;
5123 for (i = 0; i < infoPtr->cimlDef; i++)
5124 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5126 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5127 &infoPtr->nBitmapHeight))
5129 infoPtr->nBitmapWidth = 1;
5130 infoPtr->nBitmapHeight = 1;
5133 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5134 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5135 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5137 InvalidateRect(hwnd, NULL, TRUE);
5139 return (LRESULT)himlTemp;
5144 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5146 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5148 infoPtr->nIndent = (INT)wParam;
5152 /* process only on indent changing */
5153 if(infoPtr->nIndent != (INT)wParam)
5155 infoPtr->nIndent = (INT)wParam;
5156 TOOLBAR_CalcToolbar (hwnd);
5157 InvalidateRect(hwnd, NULL, FALSE);
5165 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5168 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5170 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5172 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5174 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5178 if ((lptbim->iButton == -1) ||
5179 ((lptbim->iButton < infoPtr->nNumButtons) &&
5180 (lptbim->iButton >= 0)))
5182 infoPtr->tbim = *lptbim;
5183 /* FIXME: don't need to update entire toolbar */
5184 InvalidateRect(hwnd, NULL, TRUE);
5187 ERR("Invalid button index %d\n", lptbim->iButton);
5194 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5198 infoPtr->clrInsertMark = (COLORREF)lParam;
5200 /* FIXME: don't need to update entire toolbar */
5201 InvalidateRect(hwnd, NULL, TRUE);
5208 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5210 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5212 infoPtr->nMaxTextRows = (INT)wParam;
5214 TOOLBAR_CalcToolbar(hwnd);
5219 /* MSDN gives slightly wrong info on padding.
5220 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5221 * 2. It is not used to create a blank area between the edge of the button
5222 * and the text or image if TBSTYLE_LIST is set. It is used to control
5223 * the gap between the image and text.
5224 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5225 * to control the bottom and right borders [with the border being
5226 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5227 * is shared evenly on both sides of the button.
5228 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5231 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5236 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5237 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5238 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5239 TRACE("cx=%ld, cy=%ld\n",
5240 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5241 return (LRESULT) oldPad;
5246 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5248 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5253 hwndOldNotify = infoPtr->hwndNotify;
5254 infoPtr->hwndNotify = (HWND)wParam;
5256 return (LRESULT)hwndOldNotify;
5261 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5264 LPRECT lprc = (LPRECT)lParam;
5268 if (LOWORD(wParam) > 1) {
5269 FIXME("multiple rows not supported!\n");
5272 if(infoPtr->nRows != LOWORD(wParam))
5274 infoPtr->nRows = LOWORD(wParam);
5276 /* recalculate toolbar */
5277 TOOLBAR_CalcToolbar (hwnd);
5279 /* repaint toolbar */
5280 InvalidateRect(hwnd, NULL, TRUE);
5283 /* return bounding rectangle */
5285 lprc->left = infoPtr->rcBound.left;
5286 lprc->right = infoPtr->rcBound.right;
5287 lprc->top = infoPtr->rcBound.top;
5288 lprc->bottom = infoPtr->rcBound.bottom;
5296 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5298 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5299 TBUTTON_INFO *btnPtr;
5302 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5306 btnPtr = &infoPtr->buttons[nIndex];
5308 /* if hidden state has changed the invalidate entire window and recalc */
5309 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5310 btnPtr->fsState = LOWORD(lParam);
5311 TOOLBAR_CalcToolbar (hwnd);
5312 InvalidateRect(hwnd, 0, TRUE);
5316 /* process state changing if current state doesn't match new state */
5317 if(btnPtr->fsState != LOWORD(lParam))
5319 btnPtr->fsState = LOWORD(lParam);
5320 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5328 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5330 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5336 inline static LRESULT
5337 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5339 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5341 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5343 infoPtr->hwndToolTip = (HWND)wParam;
5349 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5354 TRACE("%s hwnd=%p\n",
5355 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5357 bTemp = infoPtr->bUnicode;
5358 infoPtr->bUnicode = (BOOL)wParam;
5365 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5367 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5369 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5370 comctl32_color.clrBtnHighlight :
5371 infoPtr->clrBtnHighlight;
5372 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5373 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5379 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5383 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5384 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5385 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5387 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5388 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5389 InvalidateRect(hwnd, NULL, TRUE);
5395 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5398 INT iOldVersion = infoPtr->iVersion;
5400 infoPtr->iVersion = iVersion;
5402 if (infoPtr->iVersion >= 5)
5403 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5410 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5413 WORD iString = HIWORD(wParam);
5414 WORD buffersize = LOWORD(wParam);
5415 LPSTR str = (LPSTR)lParam;
5418 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5420 if (iString < infoPtr->nNumStrings)
5422 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5424 TRACE("returning %s\n", debugstr_a(str));
5427 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5434 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5436 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5437 WORD iString = HIWORD(wParam);
5438 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5439 LPWSTR str = (LPWSTR)lParam;
5442 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5444 if (iString < infoPtr->nNumStrings)
5446 len = min(len, strlenW(infoPtr->strings[iString]));
5447 ret = (len+1)*sizeof(WCHAR);
5448 memcpy(str, infoPtr->strings[iString], ret);
5451 TRACE("returning %s\n", debugstr_w(str));
5454 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5459 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5460 * is the maximum size of the toolbar? */
5461 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5463 SIZE * pSize = (SIZE*)lParam;
5464 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5469 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5470 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5471 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5474 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5477 INT nOldHotItem = infoPtr->nHotItem;
5479 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5480 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5482 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5485 /* NOTE: an application can still remove the hot item even if anchor
5486 * highlighting is enabled */
5488 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5492 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5495 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5496 * which controls the amount of spacing between the image and the text
5497 * of buttons for TBSTYLE_LIST toolbars. */
5498 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5500 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5502 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5505 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5507 infoPtr->iListGap = (INT)wParam;
5509 InvalidateRect(hwnd, NULL, TRUE);
5514 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5515 * of image lists associated with the various states. */
5516 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5518 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5520 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5522 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5526 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5529 LPSIZE lpsize = (LPSIZE)lParam;
5535 * Testing shows the following:
5536 * wParam = 0 adjust cx value
5537 * = 1 set cy value to max size.
5538 * lParam pointer to SIZE structure
5541 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5542 wParam, lParam, lpsize->cx, lpsize->cy);
5546 if (lpsize->cx == -1) {
5547 /* **** this is wrong, native measures each button and sets it */
5548 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5550 else if(HIWORD(lpsize->cx)) {
5552 HWND hwndParent = GetParent(hwnd);
5554 GetWindowRect(hwnd, &rc);
5555 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5556 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5557 rc.left, rc.top, rc.right, rc.bottom);
5558 lpsize->cx = max(rc.right-rc.left,
5559 infoPtr->rcBound.right - infoPtr->rcBound.left);
5562 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5566 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5569 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5573 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5574 lpsize->cx, lpsize->cy);
5578 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5580 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5582 InvalidateRect(hwnd, NULL, TRUE);
5588 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5590 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5591 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5594 TRACE("hwnd = %p\n", hwnd);
5596 /* initialize info structure */
5597 infoPtr->nButtonHeight = 22;
5598 infoPtr->nButtonWidth = 24;
5599 infoPtr->nBitmapHeight = 15;
5600 infoPtr->nBitmapWidth = 16;
5602 infoPtr->nMaxTextRows = 1;
5603 infoPtr->cxMin = -1;
5604 infoPtr->cxMax = -1;
5605 infoPtr->nNumBitmaps = 0;
5606 infoPtr->nNumStrings = 0;
5608 infoPtr->bCaptured = FALSE;
5609 infoPtr->nButtonDown = -1;
5610 infoPtr->nButtonDrag = -1;
5611 infoPtr->nOldHit = -1;
5612 infoPtr->nHotItem = -1;
5613 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5614 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5615 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5616 infoPtr->bDragOutSent = FALSE;
5617 infoPtr->iVersion = 0;
5618 infoPtr->hwndSelf = hwnd;
5619 infoPtr->bDoRedraw = TRUE;
5620 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5621 infoPtr->clrBtnShadow = CLR_DEFAULT;
5622 infoPtr->szPadding.cx = DEFPAD_CX;
5623 infoPtr->szPadding.cy = DEFPAD_CY;
5624 infoPtr->iListGap = DEFLISTGAP;
5625 infoPtr->dwStyle = dwStyle;
5626 infoPtr->tbim.iButton = -1;
5627 GetClientRect(hwnd, &infoPtr->client_rect);
5628 infoPtr->bUnicode = infoPtr->hwndNotify &&
5629 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5631 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5632 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5634 if (dwStyle & TBSTYLE_TOOLTIPS) {
5635 /* Create tooltip control */
5636 infoPtr->hwndToolTip =
5637 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5638 CW_USEDEFAULT, CW_USEDEFAULT,
5639 CW_USEDEFAULT, CW_USEDEFAULT,
5642 /* Send NM_TOOLTIPSCREATED notification */
5643 if (infoPtr->hwndToolTip)
5645 NMTOOLTIPSCREATED nmttc;
5647 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5649 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5653 OpenThemeData (hwnd, themeClass);
5655 TOOLBAR_CheckStyle (hwnd, dwStyle);
5657 TOOLBAR_CalcToolbar(hwnd);
5664 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5668 /* delete tooltip control */
5669 if (infoPtr->hwndToolTip)
5670 DestroyWindow (infoPtr->hwndToolTip);
5672 /* delete temporary buffer for tooltip text */
5673 Free (infoPtr->pszTooltipText);
5675 /* delete button data */
5676 if (infoPtr->buttons)
5677 Free (infoPtr->buttons);
5679 /* delete strings */
5680 if (infoPtr->strings) {
5682 for (i = 0; i < infoPtr->nNumStrings; i++)
5683 if (infoPtr->strings[i])
5684 Free (infoPtr->strings[i]);
5686 Free (infoPtr->strings);
5689 /* destroy internal image list */
5690 if (infoPtr->himlInt)
5691 ImageList_Destroy (infoPtr->himlInt);
5693 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5694 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5695 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5697 /* delete default font */
5699 DeleteObject (infoPtr->hDefaultFont);
5701 CloseThemeData (GetWindowTheme (hwnd));
5703 /* free toolbar info data */
5705 SetWindowLongPtrW (hwnd, 0, 0);
5712 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5714 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5715 NMTBCUSTOMDRAW tbcd;
5718 HTHEME theme = GetWindowTheme (hwnd);
5720 /* the app has told us not to redraw the toolbar */
5721 if (!infoPtr->bDoRedraw)
5724 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5725 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5726 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5727 tbcd.nmcd.hdc = (HDC)wParam;
5728 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5729 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5731 /* FIXME: in general the return flags *can* be or'ed together */
5732 switch (infoPtr->dwBaseCustDraw)
5734 case CDRF_DODEFAULT:
5736 case CDRF_SKIPDEFAULT:
5739 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5744 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5745 * to my parent for processing.
5747 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5749 HDC hdc = (HDC)wParam;
5754 parent = GetParent(hwnd);
5755 MapWindowPoints(hwnd, parent, &pt, 1);
5756 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5757 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5758 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5761 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5763 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5764 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5765 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5766 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5767 tbcd.nmcd.hdc = (HDC)wParam;
5768 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5769 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5770 switch (infoPtr->dwBaseCustDraw)
5772 case CDRF_DODEFAULT:
5774 case CDRF_SKIPDEFAULT:
5777 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5786 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5790 return (LRESULT)infoPtr->hFont;
5795 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5798 INT nNewHotItem = infoPtr->nHotItem;
5800 for (i = 0; i < infoPtr->nNumButtons; i++)
5803 if ((nNewHotItem + iDirection < 0) ||
5804 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5806 NMTBWRAPHOTITEM nmtbwhi;
5807 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5808 nmtbwhi.iDirection = iDirection;
5809 nmtbwhi.dwReason = dwReason;
5811 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5815 nNewHotItem += iDirection;
5816 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5818 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5819 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5821 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5828 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5833 nmkey.nVKey = (UINT)wParam;
5834 nmkey.uFlags = HIWORD(lParam);
5836 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5837 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5839 switch ((UINT)wParam)
5843 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5847 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5851 if ((infoPtr->nHotItem >= 0) &&
5852 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5854 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5855 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5866 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5871 pt.x = (INT)LOWORD(lParam);
5872 pt.y = (INT)HIWORD(lParam);
5873 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5876 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5877 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5878 TOOLBAR_Customize (hwnd);
5885 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5887 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5888 TBUTTON_INFO *btnPtr;
5893 BOOL bDragKeyPressed;
5897 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5898 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5900 bDragKeyPressed = (wParam & MK_SHIFT);
5902 if (infoPtr->hwndToolTip)
5903 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5904 WM_LBUTTONDOWN, wParam, lParam);
5906 pt.x = (INT)LOWORD(lParam);
5907 pt.y = (INT)HIWORD(lParam);
5908 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5910 btnPtr = &infoPtr->buttons[nHit];
5912 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5914 infoPtr->nButtonDrag = nHit;
5917 /* If drag cursor has not been loaded, load it.
5918 * Note: it doesn't need to be freed */
5920 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5921 SetCursor(hCursorDrag);
5926 infoPtr->nOldHit = nHit;
5928 CopyRect(&arrowRect, &btnPtr->rect);
5929 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5931 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5932 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5933 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5934 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5935 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5936 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5940 /* draw in pressed state */
5941 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5942 btnPtr->fsState |= TBSTATE_PRESSED;
5944 btnPtr->bDropDownPressed = TRUE;
5945 RedrawWindow(hwnd,&btnPtr->rect,0,
5946 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5948 memset(&nmtb, 0, sizeof(nmtb));
5949 nmtb.iItem = btnPtr->idCommand;
5950 nmtb.rcButton = btnPtr->rect;
5951 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5953 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5955 if (res != TBDDRET_TREATPRESSED)
5959 /* redraw button in unpressed state */
5960 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5961 btnPtr->fsState &= ~TBSTATE_PRESSED;
5963 btnPtr->bDropDownPressed = FALSE;
5964 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5966 /* find and set hot item
5967 * NOTE: native doesn't do this, but that is a bug */
5969 ScreenToClient(hwnd, &pt);
5970 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5971 if (!infoPtr->bAnchor || (nHit >= 0))
5972 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5974 /* remove any left mouse button down or double-click messages
5975 * so that we can get a toggle effect on the button */
5976 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5977 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5982 /* otherwise drop through and process as pushed */
5984 infoPtr->bCaptured = TRUE;
5985 infoPtr->nButtonDown = nHit;
5986 infoPtr->bDragOutSent = FALSE;
5988 btnPtr->fsState |= TBSTATE_PRESSED;
5990 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5992 if (btnPtr->fsState & TBSTATE_ENABLED)
5993 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6000 memset(&nmtb, 0, sizeof(nmtb));
6001 nmtb.iItem = btnPtr->idCommand;
6002 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
6005 nmmouse.dwHitInfo = nHit;
6007 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
6009 nmmouse.dwItemSpec = -1;
6012 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6013 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6016 ClientToScreen(hwnd, &pt);
6019 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
6020 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
6026 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
6028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6029 TBUTTON_INFO *btnPtr;
6033 BOOL bSendMessage = TRUE;
6038 if (infoPtr->hwndToolTip)
6039 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6040 WM_LBUTTONUP, wParam, lParam);
6042 pt.x = (INT)LOWORD(lParam);
6043 pt.y = (INT)HIWORD(lParam);
6044 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6046 if (!infoPtr->bAnchor || (nHit >= 0))
6047 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6049 if (infoPtr->nButtonDrag >= 0) {
6053 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
6056 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
6058 GetClientRect(hwnd, &rcClient);
6059 if (PtInRect(&rcClient, pt))
6066 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
6069 if (nButton == infoPtr->nButtonDrag)
6071 /* if the button is moved sightly left and we have a
6072 * separator there then remove it */
6073 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
6075 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
6076 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
6078 else /* else insert a separator before the dragged button */
6081 memset(&tbb, 0, sizeof(tbb));
6082 tbb.fsStyle = BTNS_SEP;
6084 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6091 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6092 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6094 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6097 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6102 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6103 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6106 /* button under cursor changed so need to re-set hot item */
6107 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6108 infoPtr->nButtonDrag = -1;
6110 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6112 else if (infoPtr->nButtonDown >= 0) {
6113 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6114 btnPtr->fsState &= ~TBSTATE_PRESSED;
6116 if (btnPtr->fsStyle & BTNS_CHECK) {
6117 if (btnPtr->fsStyle & BTNS_GROUP) {
6118 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6120 if (nOldIndex == nHit)
6121 bSendMessage = FALSE;
6122 if ((nOldIndex != nHit) &&
6124 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6125 btnPtr->fsState |= TBSTATE_CHECKED;
6128 if (btnPtr->fsState & TBSTATE_CHECKED)
6129 btnPtr->fsState &= ~TBSTATE_CHECKED;
6131 btnPtr->fsState |= TBSTATE_CHECKED;
6135 if (nOldIndex != -1)
6136 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6139 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6140 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6141 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6143 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6145 infoPtr->nButtonDown = -1;
6147 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6148 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6149 NM_RELEASEDCAPTURE);
6151 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6154 memset(&nmtb, 0, sizeof(nmtb));
6155 nmtb.iItem = btnPtr->idCommand;
6156 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6159 if (btnPtr->fsState & TBSTATE_ENABLED)
6161 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6162 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6166 /* !!! Undocumented - toolbar at 4.71 level and above sends
6167 * NM_CLICK with the NMMOUSE structure. */
6168 nmmouse.dwHitInfo = nHit;
6171 nmmouse.dwItemSpec = -1;
6174 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6175 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6178 ClientToScreen(hwnd, &pt);
6181 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6182 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6188 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6195 pt.x = LOWORD(lParam);
6196 pt.y = HIWORD(lParam);
6198 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6199 nmmouse.dwHitInfo = nHit;
6202 nmmouse.dwItemSpec = -1;
6204 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6205 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6208 ClientToScreen(hwnd, &pt);
6211 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6212 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6218 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6223 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6224 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6230 TOOLBAR_CaptureChanged(HWND hwnd)
6232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6233 TBUTTON_INFO *btnPtr;
6235 infoPtr->bCaptured = FALSE;
6237 if (infoPtr->nButtonDown >= 0)
6239 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6240 btnPtr->fsState &= ~TBSTATE_PRESSED;
6242 infoPtr->nOldHit = -1;
6244 if (btnPtr->fsState & TBSTATE_ENABLED)
6245 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6251 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6253 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6254 TBUTTON_INFO *hotBtnPtr;
6256 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6258 /* don't remove hot effects when in anchor highlighting mode or when a
6259 * drop-down button is pressed */
6260 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6261 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6263 if (infoPtr->nOldHit < 0)
6266 /* If the last button we were over is depressed then make it not */
6267 /* depressed and redraw it */
6268 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6270 TBUTTON_INFO *btnPtr;
6273 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6275 btnPtr->fsState &= ~TBSTATE_PRESSED;
6277 rc1 = hotBtnPtr->rect;
6278 InflateRect (&rc1, 1, 1);
6279 InvalidateRect (hwnd, &rc1, TRUE);
6282 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6285 ZeroMemory(&nmt, sizeof(nmt));
6286 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6287 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6288 infoPtr->bDragOutSent = TRUE;
6291 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6297 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6301 TRACKMOUSEEVENT trackinfo;
6303 TBUTTON_INFO *btnPtr;
6305 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6306 /* fill in the TRACKMOUSEEVENT struct */
6307 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6308 trackinfo.dwFlags = TME_QUERY;
6309 trackinfo.hwndTrack = hwnd;
6310 trackinfo.dwHoverTime = HOVER_DEFAULT;
6312 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6313 _TrackMouseEvent(&trackinfo);
6315 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6316 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6317 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6319 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6320 /* and can properly deactivate the hot toolbar button */
6321 _TrackMouseEvent(&trackinfo);
6325 if (infoPtr->hwndToolTip)
6326 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6327 WM_MOUSEMOVE, wParam, lParam);
6329 pt.x = (INT)LOWORD(lParam);
6330 pt.y = (INT)HIWORD(lParam);
6332 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6334 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6335 && (!infoPtr->bAnchor || (nHit >= 0)))
6336 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6338 if (infoPtr->nOldHit != nHit)
6340 if (infoPtr->bCaptured)
6342 if (!infoPtr->bDragOutSent)
6345 ZeroMemory(&nmt, sizeof(nmt));
6346 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6347 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6348 infoPtr->bDragOutSent = TRUE;
6351 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6352 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6353 btnPtr->fsState &= ~TBSTATE_PRESSED;
6354 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6356 else if (nHit == infoPtr->nButtonDown) {
6357 btnPtr->fsState |= TBSTATE_PRESSED;
6358 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6360 infoPtr->nOldHit = nHit;
6368 inline static LRESULT
6369 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6371 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6372 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6374 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6378 inline static LRESULT
6379 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6381 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6382 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6384 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6389 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6391 TOOLBAR_INFO *infoPtr;
6392 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6395 /* allocate memory for info structure */
6396 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6397 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6400 infoPtr->dwStructSize = sizeof(TBBUTTON);
6402 infoPtr->nWidth = 0;
6404 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6405 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6406 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6407 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6410 /* native control does:
6411 * Get a lot of colors and brushes
6413 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6414 * CreateFontIndirectW(adr1)
6415 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6416 * hdc = GetDC(toolbar)
6417 * GetSystemMetrics(0x48)
6418 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6419 * 0, 0, 0, 0, "MARLETT")
6420 * oldfnt = SelectObject(hdc, fnt2)
6421 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6422 * GetTextMetricsW(hdc, adr3)
6423 * SelectObject(hdc, oldfnt)
6424 * DeleteObject(fnt2)
6426 * InvalidateRect(toolbar, 0, 1)
6427 * SetWindowLongW(toolbar, 0, addr)
6428 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6431 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6432 * ie 2 0x4600094c 0x4600094c 0x4600894d
6433 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6434 * rebar 0x50008844 0x40008844 0x50008845
6435 * pager 0x50000844 0x40000844 0x50008845
6436 * IC35mgr 0x5400084e **nochange**
6437 * on entry to _NCCREATE 0x5400084e
6438 * rowlist 0x5400004e **nochange**
6439 * on entry to _NCCREATE 0x5400004e
6443 /* I think the code below is a bug, but it is the way that the native
6444 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6445 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6446 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6447 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6448 * Somehow, the only cases of this seem to be MFC programs.
6450 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6451 * does not occur in the WM_STYLECHANGING routine.
6452 * (Guy Albertelli 9/2001)
6455 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6456 && !(cs->style & TBSTYLE_TRANSPARENT))
6457 styleadd |= TBSTYLE_TRANSPARENT;
6458 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6459 styleadd |= CCS_TOP; /* default to top */
6460 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6463 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6468 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6470 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6474 if (dwStyle & WS_MINIMIZE)
6475 return 0; /* Nothing to do */
6477 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6479 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6482 if (!(dwStyle & CCS_NODIVIDER))
6484 GetWindowRect (hwnd, &rcWindow);
6485 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6486 if( dwStyle & WS_BORDER )
6487 OffsetRect (&rcWindow, 1, 1);
6488 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6491 ReleaseDC( hwnd, hdc );
6497 /* handles requests from the tooltip control on what text to display */
6498 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6500 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6502 TRACE("button index = %d\n", index);
6504 Free (infoPtr->pszTooltipText);
6505 infoPtr->pszTooltipText = NULL;
6510 if (infoPtr->bUnicode)
6512 WCHAR wszBuffer[INFOTIPSIZE+1];
6513 NMTBGETINFOTIPW tbgit;
6514 unsigned int len; /* in chars */
6516 wszBuffer[0] = '\0';
6517 wszBuffer[INFOTIPSIZE] = '\0';
6519 tbgit.pszText = wszBuffer;
6520 tbgit.cchTextMax = INFOTIPSIZE;
6521 tbgit.iItem = lpnmtdi->hdr.idFrom;
6522 tbgit.lParam = infoPtr->buttons[index].dwData;
6524 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6526 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6528 len = strlenW(tbgit.pszText);
6529 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6531 /* need to allocate temporary buffer in infoPtr as there
6532 * isn't enough space in buffer passed to us by the
6533 * tooltip control */
6534 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6535 if (infoPtr->pszTooltipText)
6537 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6538 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6544 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6550 CHAR szBuffer[INFOTIPSIZE+1];
6551 NMTBGETINFOTIPA tbgit;
6552 unsigned int len; /* in chars */
6555 szBuffer[INFOTIPSIZE] = '\0';
6557 tbgit.pszText = szBuffer;
6558 tbgit.cchTextMax = INFOTIPSIZE;
6559 tbgit.iItem = lpnmtdi->hdr.idFrom;
6560 tbgit.lParam = infoPtr->buttons[index].dwData;
6562 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6564 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6566 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6567 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6569 /* need to allocate temporary buffer in infoPtr as there
6570 * isn't enough space in buffer passed to us by the
6571 * tooltip control */
6572 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6573 if (infoPtr->pszTooltipText)
6575 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6576 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6582 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6583 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6588 /* if button has text, but it is not shown then automatically
6589 * use that text as tooltip */
6590 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6591 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6593 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6594 unsigned int len = pszText ? strlenW(pszText) : 0;
6596 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6598 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6600 /* need to allocate temporary buffer in infoPtr as there
6601 * isn't enough space in buffer passed to us by the
6602 * tooltip control */
6603 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6604 if (infoPtr->pszTooltipText)
6606 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6607 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6613 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6618 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6620 /* last resort: send notification on to app */
6621 /* FIXME: find out what is really used here */
6622 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6626 inline static LRESULT
6627 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6629 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6630 LPNMHDR lpnmh = (LPNMHDR)lParam;
6632 switch (lpnmh->code)
6636 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6638 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6639 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6640 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6644 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6645 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6653 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6655 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6656 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6657 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6658 lppgs->iScroll, lppgs->iDir);
6662 case TTN_GETDISPINFOW:
6663 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6665 case TTN_GETDISPINFOA:
6666 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6676 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6680 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6682 if (lParam == NF_QUERY)
6685 if (lParam == NF_REQUERY) {
6686 format = SendMessageW(infoPtr->hwndNotify,
6687 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6688 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6689 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6700 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6706 /* fill ps.rcPaint with a default rect */
6707 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6709 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6711 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6712 ps.rcPaint.left, ps.rcPaint.top,
6713 ps.rcPaint.right, ps.rcPaint.bottom);
6715 TOOLBAR_Refresh (hwnd, hdc, &ps);
6716 if (!wParam) EndPaint (hwnd, &ps);
6723 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6727 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6729 /* make first item hot */
6730 if (infoPtr->nNumButtons > 0)
6731 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6738 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6739 /*****************************************************
6742 * Handles the WM_SETREDRAW message.
6745 * According to testing V4.71 of COMCTL32 returns the
6746 * *previous* status of the redraw flag (either 0 or 1)
6747 * instead of the MSDN documented value of 0 if handled.
6748 * (For laughs see the "consistency" with same function
6751 *****************************************************/
6753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6754 BOOL oldredraw = infoPtr->bDoRedraw;
6756 TRACE("set to %s\n",
6757 (wParam) ? "TRUE" : "FALSE");
6758 infoPtr->bDoRedraw = (BOOL) wParam;
6760 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6762 return (oldredraw) ? 1 : 0;
6767 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6771 TRACE("sizing toolbar!\n");
6773 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6775 RECT delta_width, delta_height, client, dummy;
6776 DWORD min_x, max_x, min_y, max_y;
6777 TBUTTON_INFO *btnPtr;
6780 GetClientRect(hwnd, &client);
6781 if(client.right > infoPtr->client_rect.right)
6783 min_x = infoPtr->client_rect.right;
6784 max_x = client.right;
6788 max_x = infoPtr->client_rect.right;
6789 min_x = client.right;
6791 if(client.bottom > infoPtr->client_rect.bottom)
6793 min_y = infoPtr->client_rect.bottom;
6794 max_y = client.bottom;
6798 max_y = infoPtr->client_rect.bottom;
6799 min_y = client.bottom;
6802 SetRect(&delta_width, min_x, 0, max_x, min_y);
6803 SetRect(&delta_height, 0, min_y, max_x, max_y);
6805 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6806 btnPtr = infoPtr->buttons;
6807 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6808 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6809 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6810 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6812 GetClientRect(hwnd, &infoPtr->client_rect);
6813 TOOLBAR_AutoSize(hwnd);
6819 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6823 if (nType == GWL_STYLE)
6825 if (lpStyle->styleNew & TBSTYLE_LIST)
6826 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6828 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6830 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6832 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6834 infoPtr->dwStyle = lpStyle->styleNew;
6836 /* only resize if one of the CCS_* styles was changed */
6837 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6839 TOOLBAR_AutoSize (hwnd);
6841 InvalidateRect(hwnd, NULL, TRUE);
6850 TOOLBAR_SysColorChange (HWND hwnd)
6852 COMCTL32_RefreshSysColors();
6858 /* update theme after a WM_THEMECHANGED message */
6859 static LRESULT theme_changed (HWND hwnd)
6861 HTHEME theme = GetWindowTheme (hwnd);
6862 CloseThemeData (theme);
6863 OpenThemeData (hwnd, themeClass);
6868 static LRESULT WINAPI
6869 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6873 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6874 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6876 if (!infoPtr && (uMsg != WM_NCCREATE))
6877 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6882 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6884 case TB_ADDBUTTONSA:
6885 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6887 case TB_ADDBUTTONSW:
6888 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6891 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6894 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6897 return TOOLBAR_AutoSize (hwnd);
6899 case TB_BUTTONCOUNT:
6900 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6902 case TB_BUTTONSTRUCTSIZE:
6903 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6905 case TB_CHANGEBITMAP:
6906 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6908 case TB_CHECKBUTTON:
6909 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6911 case TB_COMMANDTOINDEX:
6912 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6915 return TOOLBAR_Customize (hwnd);
6917 case TB_DELETEBUTTON:
6918 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6920 case TB_ENABLEBUTTON:
6921 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6923 case TB_GETANCHORHIGHLIGHT:
6924 return TOOLBAR_GetAnchorHighlight (hwnd);
6927 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6929 case TB_GETBITMAPFLAGS:
6930 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6933 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6935 case TB_GETBUTTONINFOA:
6936 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6938 case TB_GETBUTTONINFOW:
6939 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6941 case TB_GETBUTTONSIZE:
6942 return TOOLBAR_GetButtonSize (hwnd);
6944 case TB_GETBUTTONTEXTA:
6945 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6947 case TB_GETBUTTONTEXTW:
6948 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6950 case TB_GETDISABLEDIMAGELIST:
6951 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6953 case TB_GETEXTENDEDSTYLE:
6954 return TOOLBAR_GetExtendedStyle (hwnd);
6956 case TB_GETHOTIMAGELIST:
6957 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6960 return TOOLBAR_GetHotItem (hwnd);
6962 case TB_GETIMAGELIST:
6963 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6965 case TB_GETINSERTMARK:
6966 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6968 case TB_GETINSERTMARKCOLOR:
6969 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6971 case TB_GETITEMRECT:
6972 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6975 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6977 /* case TB_GETOBJECT: */ /* 4.71 */
6980 return TOOLBAR_GetPadding (hwnd);
6983 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6986 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6989 return TOOLBAR_GetState (hwnd, wParam, lParam);
6992 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6995 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6998 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
7000 case TB_GETTEXTROWS:
7001 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
7003 case TB_GETTOOLTIPS:
7004 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
7006 case TB_GETUNICODEFORMAT:
7007 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
7010 return TOOLBAR_HideButton (hwnd, wParam, lParam);
7013 return TOOLBAR_HitTest (hwnd, wParam, lParam);
7015 case TB_INDETERMINATE:
7016 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
7018 case TB_INSERTBUTTONA:
7019 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
7021 case TB_INSERTBUTTONW:
7022 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
7024 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
7026 case TB_ISBUTTONCHECKED:
7027 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
7029 case TB_ISBUTTONENABLED:
7030 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
7032 case TB_ISBUTTONHIDDEN:
7033 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
7035 case TB_ISBUTTONHIGHLIGHTED:
7036 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
7038 case TB_ISBUTTONINDETERMINATE:
7039 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
7041 case TB_ISBUTTONPRESSED:
7042 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
7045 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
7047 case TB_MAPACCELERATORA:
7048 case TB_MAPACCELERATORW:
7049 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
7052 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7055 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7057 case TB_PRESSBUTTON:
7058 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7060 case TB_REPLACEBITMAP:
7061 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7063 case TB_SAVERESTOREA:
7064 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7066 case TB_SAVERESTOREW:
7067 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7069 case TB_SETANCHORHIGHLIGHT:
7070 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7072 case TB_SETBITMAPSIZE:
7073 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7075 case TB_SETBUTTONINFOA:
7076 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7078 case TB_SETBUTTONINFOW:
7079 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7081 case TB_SETBUTTONSIZE:
7082 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7084 case TB_SETBUTTONWIDTH:
7085 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7088 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7090 case TB_SETDISABLEDIMAGELIST:
7091 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7093 case TB_SETDRAWTEXTFLAGS:
7094 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7096 case TB_SETEXTENDEDSTYLE:
7097 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7099 case TB_SETHOTIMAGELIST:
7100 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7103 return TOOLBAR_SetHotItem (hwnd, wParam);
7105 case TB_SETIMAGELIST:
7106 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7109 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7111 case TB_SETINSERTMARK:
7112 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7114 case TB_SETINSERTMARKCOLOR:
7115 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7117 case TB_SETMAXTEXTROWS:
7118 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7121 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7124 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7127 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7130 return TOOLBAR_SetState (hwnd, wParam, lParam);
7133 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7135 case TB_SETTOOLTIPS:
7136 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7138 case TB_SETUNICODEFORMAT:
7139 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7142 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7145 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7148 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7151 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7154 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7157 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7159 /* Common Control Messages */
7161 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7162 case CCM_GETCOLORSCHEME:
7163 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7165 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7166 case CCM_SETCOLORSCHEME:
7167 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7169 case CCM_GETVERSION:
7170 return TOOLBAR_GetVersion (hwnd);
7172 case CCM_SETVERSION:
7173 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7179 return TOOLBAR_Create (hwnd, wParam, lParam);
7182 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7185 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7188 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7191 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7193 /* case WM_KILLFOCUS: */
7195 case WM_LBUTTONDBLCLK:
7196 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7198 case WM_LBUTTONDOWN:
7199 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7202 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7205 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7207 case WM_RBUTTONDBLCLK:
7208 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7211 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7214 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7216 case WM_CAPTURECHANGED:
7217 return TOOLBAR_CaptureChanged(hwnd);
7220 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7223 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7226 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7229 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7232 return TOOLBAR_Notify (hwnd, wParam, lParam);
7234 case WM_NOTIFYFORMAT:
7235 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7237 case WM_PRINTCLIENT:
7239 return TOOLBAR_Paint (hwnd, wParam);
7242 return TOOLBAR_SetFocus (hwnd, wParam);
7245 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7248 return TOOLBAR_Size (hwnd, wParam, lParam);
7250 case WM_STYLECHANGED:
7251 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7253 case WM_SYSCOLORCHANGE:
7254 return TOOLBAR_SysColorChange (hwnd);
7256 case WM_THEMECHANGED:
7257 return theme_changed (hwnd);
7259 /* case WM_WININICHANGE: */
7264 case WM_MEASUREITEM:
7266 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7268 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7269 case PGM_FORWARDMOUSE:
7270 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7273 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7274 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7275 uMsg, wParam, lParam);
7276 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7282 TOOLBAR_Register (void)
7286 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7287 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7288 wndClass.lpfnWndProc = ToolbarWindowProc;
7289 wndClass.cbClsExtra = 0;
7290 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7291 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7292 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7293 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7295 RegisterClassW (&wndClass);
7300 TOOLBAR_Unregister (void)
7302 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7305 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7310 /* Check if the entry already exists */
7311 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7313 /* If this is a new entry we must create it and insert into the array */
7318 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7321 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7322 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7337 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7341 for (i = 0; i < *cies; i++)
7351 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7359 for (i = 0; i < cies; i++)
7361 if (pies[i]->id == id)
7373 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7375 HIMAGELIST himlDef = 0;
7376 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7379 himlDef = pie->himl;
7385 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7387 if (infoPtr->bUnicode)
7388 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7395 nmtba.iItem = nmtb->iItem;
7396 nmtba.pszText = Buffer;
7397 nmtba.cchText = 256;
7398 ZeroMemory(nmtba.pszText, nmtba.cchText);
7400 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7402 int ccht = strlen(nmtba.pszText);
7404 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7405 nmtb->pszText, nmtb->cchText);
7407 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7416 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7417 int iItem, PCUSTOMBUTTON btnInfo)
7421 /* MSDN states that iItem is the index of the button, rather than the
7422 * command ID as used by every other NMTOOLBAR notification */
7424 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7426 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);