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 SIZE szPadding; /* padding values around button */
143 INT iListGap; /* default gap between text and image for toolbar with list style */
145 HFONT hFont; /* text font */
146 HIMAGELIST himlInt; /* image list created internally */
147 PIMLENTRY *himlDef; /* default image list array */
148 INT cimlDef; /* default image list array count */
149 PIMLENTRY *himlHot; /* hot image list array */
150 INT cimlHot; /* hot image list array count */
151 PIMLENTRY *himlDis; /* disabled image list array */
152 INT cimlDis; /* disabled image list array count */
153 HWND hwndToolTip; /* handle to tool tip control */
154 HWND hwndNotify; /* handle to the window that gets notifications */
155 HWND hwndSelf; /* my own handle */
156 BOOL bAnchor; /* anchor highlight enabled */
157 BOOL bDoRedraw; /* Redraw status */
158 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
159 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
160 BOOL bCaptured; /* mouse captured? */
161 DWORD dwStyle; /* regular toolbar style */
162 DWORD dwExStyle; /* extended toolbar style */
163 DWORD dwDTFlags; /* DrawText flags */
165 COLORREF clrInsertMark; /* insert mark color */
166 COLORREF clrBtnHighlight; /* color for Flat Separator */
167 COLORREF clrBtnShadow; /* color for Flag Separator */
169 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
170 * for TTN_GETDISPINFOW notification */
171 TBINSERTMARK tbim; /* info on insertion mark */
172 TBUTTON_INFO *buttons; /* pointer to button array */
173 LPWSTR *strings; /* pointer to string array */
174 TBITMAP_INFO *bitmaps;
175 } TOOLBAR_INFO, *PTOOLBAR_INFO;
178 /* used by customization dialog */
181 PTOOLBAR_INFO tbInfo;
183 } CUSTDLG_INFO, *PCUSTDLG_INFO;
191 } CUSTOMBUTTON, *PCUSTOMBUTTON;
200 #define SEPARATOR_WIDTH 8
202 #define BOTTOM_BORDER 2
203 #define DDARROW_WIDTH 11
204 #define ARROW_HEIGHT 3
205 #define INSERTMARK_WIDTH 2
211 /* vertical padding used in list mode when image is present */
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
217 #define TOOLBAR_NOWHERE (-1)
219 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 /* Used to find undocumented extended styles */
224 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
225 TBSTYLE_EX_UNDOC1 | \
226 TBSTYLE_EX_MIXEDBUTTONS | \
227 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
229 /* all of the CCS_ styles */
230 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
231 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
233 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
234 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
235 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
236 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
237 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
239 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
241 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
242 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
243 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
244 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
245 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
246 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
247 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
248 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
249 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
250 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
251 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
295 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
338 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK)
356 /* issue TBN_GETDISPINFO */
359 memset(&nmgd, 0, sizeof(nmgd));
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
364 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
365 if (nmgd.dwMask & TBNF_DI_SETITEM)
366 btnPtr->iBitmap = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
396 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
398 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
399 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
415 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
416 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
417 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
421 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
422 if ((*index == I_IMAGECALLBACK) ||
423 (*index == I_IMAGENONE)) return NULL;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
431 case IMAGE_LIST_DEFAULT:
432 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
437 case IMAGE_LIST_DISABLED:
438 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
442 FIXME("Shouldn't reach here\n");
446 TRACE("no image list\n");
453 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
456 COLORREF oldcolor, newcolor;
458 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
459 myrect.right = myrect.left + 1;
460 myrect.top = lpRect->top + 2;
461 myrect.bottom = lpRect->bottom - 2;
463 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
464 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
465 oldcolor = SetBkColor (hdc, newcolor);
466 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
468 myrect.left = myrect.right;
469 myrect.right = myrect.left + 1;
471 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
472 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
473 SetBkColor (hdc, newcolor);
474 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 SetBkColor (hdc, oldcolor);
480 /***********************************************************************
481 * TOOLBAR_DrawDDFlatSeparator
483 * This function draws the separator that was flagged as BTNS_DROPDOWN.
484 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
485 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
486 * are horizontal as opposed to the vertical separators for not dropdown
489 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
492 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
495 COLORREF oldcolor, newcolor;
497 myrect.left = lpRect->left;
498 myrect.right = lpRect->right;
499 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
500 myrect.bottom = myrect.top + 1;
502 InflateRect (&myrect, -2, 0);
504 TRACE("rect=(%d,%d)-(%d,%d)\n",
505 myrect.left, myrect.top, myrect.right, myrect.bottom);
507 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
508 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
509 oldcolor = SetBkColor (hdc, newcolor);
510 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
512 myrect.top = myrect.bottom;
513 myrect.bottom = myrect.top + 1;
515 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
516 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
517 SetBkColor (hdc, newcolor);
518 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 SetBkColor (hdc, oldcolor);
525 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
530 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
531 hOldPen = SelectObject ( hdc, hPen );
534 MoveToEx (hdc, x, y, NULL);
535 LineTo (hdc, x+5, y++); x++;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+3, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+1, y++);
540 SelectObject( hdc, hOldPen );
541 DeleteObject( hPen );
545 * Draw the text string for this button.
546 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
547 * is non-zero, so we can simply check himlDef to see if we have
551 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
552 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
554 HDC hdc = tbcd->nmcd.hdc;
557 COLORREF clrOldBk = 0;
559 UINT state = tbcd->nmcd.uItemState;
563 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
564 rcText->left, rcText->top, rcText->right, rcText->bottom);
566 hOldFont = SelectObject (hdc, infoPtr->hFont);
567 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
568 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
570 else if (state & CDIS_DISABLED) {
571 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
572 OffsetRect (rcText, 1, 1);
573 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
574 SetTextColor (hdc, comctl32_color.clr3dShadow);
575 OffsetRect (rcText, -1, -1);
577 else if (state & CDIS_INDETERMINATE) {
578 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
580 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
581 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
582 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
583 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
586 clrOld = SetTextColor (hdc, tbcd->clrText);
589 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
590 SetTextColor (hdc, clrOld);
591 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
593 SetBkColor (hdc, clrOldBk);
594 SetBkMode (hdc, oldBkMode);
596 SelectObject (hdc, hOldFont);
602 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
604 HDC hdc = tbcd->nmcd.hdc;
605 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
608 INT cx = lpRect->right - lpRect->left;
609 INT cy = lpRect->bottom - lpRect->top;
610 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
611 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
612 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
613 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
614 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
615 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
616 SetBkColor(hdc, clrBkOld);
617 SetTextColor(hdc, clrTextOld);
618 SelectObject (hdc, hbr);
622 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
625 HBITMAP hbmMask, hbmImage;
626 HDC hdcMask, hdcImage;
628 ImageList_GetIconSize(himl, &cx, &cy);
630 /* Create src image */
631 hdcImage = CreateCompatibleDC(hdc);
632 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
633 SelectObject(hdcImage, hbmImage);
634 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
635 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
638 hdcMask = CreateCompatibleDC(0);
639 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
640 SelectObject(hdcMask, hbmMask);
642 /* Remove the background and all white pixels */
643 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
645 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
646 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
648 /* draw the new mask 'etched' to hdc */
649 SetBkColor(hdc, RGB(255, 255, 255));
650 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
651 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
652 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
654 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
657 DeleteObject(hbmImage);
659 DeleteObject (hbmMask);
665 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
669 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
670 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
671 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
672 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
673 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
674 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
675 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
679 /* draws the image on a toolbar button */
681 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
682 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
684 HIMAGELIST himl = NULL;
685 BOOL draw_masked = FALSE;
688 UINT draw_flags = ILD_TRANSPARENT;
690 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
692 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
695 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
699 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
700 ((tbcd->nmcd.uItemState & CDIS_HOT)
701 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
703 /* if hot, attempt to draw with hot image list, if fails,
704 use default image list */
705 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
715 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
716 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
719 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
720 (tbcd->nmcd.uItemState & CDIS_MARKED))
721 draw_flags |= ILD_BLEND50;
723 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
724 index, himl, left, top, offset);
727 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
729 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
732 /* draws a blank frame for a toolbar button */
734 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
736 HDC hdc = tbcd->nmcd.hdc;
737 RECT rc = tbcd->nmcd.rc;
738 /* if the state is disabled or indeterminate then the button
739 * cannot have an interactive look like pressed or hot */
740 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
741 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
742 BOOL pressed_look = !non_interactive_state &&
743 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
744 (tbcd->nmcd.uItemState & CDIS_CHECKED));
746 /* app don't want us to draw any edges */
747 if (dwItemCDFlag & TBCDRF_NOEDGES)
750 if (infoPtr->dwStyle & TBSTYLE_FLAT)
753 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
754 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
755 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
760 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE);
768 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
770 HDC hdc = tbcd->nmcd.hdc;
772 BOOL pressed = bDropDownPressed ||
773 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
775 if (infoPtr->dwStyle & TBSTYLE_FLAT)
778 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
779 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
780 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
781 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
782 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
787 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
789 DrawEdge (hdc, rcArrow, EDGE_RAISED,
790 BF_SOFT | BF_RECT | BF_MIDDLE);
794 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
796 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
798 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
799 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
802 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
805 /* draws a complete toolbar button */
807 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
810 DWORD dwStyle = infoPtr->dwStyle;
811 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
812 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
813 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
814 BOOL drawSepDropDownArrow = hasDropDownArrow &&
815 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
816 RECT rc, rcArrow, rcBitmap, rcText;
817 LPWSTR lpText = NULL;
822 DWORD dwItemCustDraw;
824 HTHEME theme = GetWindowTheme (hwnd);
827 CopyRect (&rcArrow, &rc);
829 /* separator - doesn't send NM_CUSTOMDRAW */
830 if (btnPtr->fsStyle & BTNS_SEP) {
833 DrawThemeBackground (theme, hdc,
834 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
838 /* with the FLAT style, iBitmap is the width and has already */
839 /* been taken into consideration in calculating the width */
840 /* so now we need to draw the vertical separator */
841 /* empirical tests show that iBitmap can/will be non-zero */
842 /* when drawing the vertical bar... */
843 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
844 if (btnPtr->fsStyle & BTNS_DROPDOWN)
845 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
847 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
849 else if (btnPtr->fsStyle != BTNS_SEP) {
850 FIXME("Draw some kind of separator: fsStyle=%x\n",
856 /* get a pointer to the text */
857 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
859 if (hasDropDownArrow)
863 if (dwStyle & TBSTYLE_FLAT)
864 right = max(rc.left, rc.right - DDARROW_WIDTH);
866 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
868 if (drawSepDropDownArrow)
871 rcArrow.left = right;
874 /* copy text & bitmap rects after adjusting for drop-down arrow
875 * so that text & bitmap is centred in the rectangle not containing
877 CopyRect(&rcText, &rc);
878 CopyRect(&rcBitmap, &rc);
880 /* Center the bitmap horizontally and vertically */
881 if (dwStyle & TBSTYLE_LIST)
884 infoPtr->nMaxTextRows > 0 &&
885 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
886 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
887 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
889 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
892 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
894 rcBitmap.top += infoPtr->szPadding.cy / 2;
896 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
897 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
898 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
899 TRACE("Text=%s\n", debugstr_w(lpText));
900 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
902 /* calculate text position */
905 rcText.left += GetSystemMetrics(SM_CXEDGE);
906 rcText.right -= GetSystemMetrics(SM_CXEDGE);
907 if (dwStyle & TBSTYLE_LIST)
909 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
910 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
914 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
915 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
917 rcText.top += infoPtr->szPadding.cy/2 + 2;
921 /* Initialize fields in all cases, because we use these later
922 * NOTE: applications can and do alter these to customize their
924 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
925 tbcd.clrText = comctl32_color.clrBtnText;
926 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
927 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
928 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
929 tbcd.clrMark = comctl32_color.clrHighlight;
930 tbcd.clrHighlightHotTrack = 0;
931 tbcd.nStringBkMode = TRANSPARENT;
932 tbcd.nHLStringBkMode = OPAQUE;
933 /* MSDN says that this is the text rectangle.
934 * But (why always a but) tracing of v5.7 of native shows
935 * that this is really a *relative* rectangle based on the
936 * the nmcd.rc. Also the left and top are always 0 ignoring
937 * any bitmap that might be present. */
938 tbcd.rcText.left = 0;
940 tbcd.rcText.right = rcText.right - rc.left;
941 tbcd.rcText.bottom = rcText.bottom - rc.top;
942 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
945 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
947 /* FIXME: what are these used for? */
951 /* Issue Item Prepaint notify */
954 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
956 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
957 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
958 tbcd.nmcd.lItemlParam = btnPtr->dwData;
959 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
960 /* reset these fields so the user can't alter the behaviour like native */
964 dwItemCustDraw = ntfret & 0xffff;
965 dwItemCDFlag = ntfret & 0xffff0000;
966 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
968 /* save the only part of the rect that the user can change */
969 rcText.right = tbcd.rcText.right + rc.left;
970 rcText.bottom = tbcd.rcText.bottom + rc.top;
973 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
974 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
975 OffsetRect(&rcText, 1, 1);
977 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
978 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
979 TOOLBAR_DrawPattern (&rc, &tbcd);
981 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
982 && (tbcd.nmcd.uItemState & CDIS_HOT))
984 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
989 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
990 if (hasDropDownArrow)
991 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
992 SetBkColor(hdc, oldclr);
998 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
999 int stateId = TS_NORMAL;
1001 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1002 stateId = TS_DISABLED;
1003 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1004 stateId = TS_PRESSED;
1005 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1006 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1007 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1008 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1011 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1014 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1016 if (drawSepDropDownArrow)
1020 int stateId = TS_NORMAL;
1022 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1023 stateId = TS_DISABLED;
1024 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1025 stateId = TS_PRESSED;
1026 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1027 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1028 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1031 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1032 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1035 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1038 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1039 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1040 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1041 SetBkMode (hdc, oldBkMode);
1043 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1045 if (hasDropDownArrow && !drawSepDropDownArrow)
1047 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1050 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1052 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1054 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1061 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1063 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1064 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1071 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1074 TBUTTON_INFO *btnPtr;
1076 RECT rcTemp, rcClient;
1077 NMTBCUSTOMDRAW tbcd;
1079 DWORD dwBaseCustDraw;
1081 /* the app has told us not to redraw the toolbar */
1082 if (!infoPtr->bDoRedraw)
1085 /* if imagelist belongs to the app, it can be changed
1086 by the app after setting it */
1087 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1089 infoPtr->nNumBitmaps = 0;
1090 for (i = 0; i < infoPtr->cimlDef; i++)
1091 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1094 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1096 /* change the imagelist icon size if we manage the list and it is necessary */
1097 TOOLBAR_CheckImageListIconSize(infoPtr);
1099 /* Send initial notify */
1100 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1101 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1102 tbcd.nmcd.hdc = hdc;
1103 tbcd.nmcd.rc = ps->rcPaint;
1104 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1105 dwBaseCustDraw = ntfret & 0xffff;
1107 GetClientRect(hwnd, &rcClient);
1109 /* redraw necessary buttons */
1110 btnPtr = infoPtr->buttons;
1111 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1114 if (!RectVisible(hdc, &btnPtr->rect))
1116 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1118 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1119 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1123 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1124 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1126 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1129 /* draw insert mark if required */
1130 if (infoPtr->tbim.iButton != -1)
1132 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1134 rcInsertMark.top = rcButton.top;
1135 rcInsertMark.bottom = rcButton.bottom;
1136 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1137 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1139 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1140 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1143 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1145 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1146 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1147 tbcd.nmcd.hdc = hdc;
1148 tbcd.nmcd.rc = ps->rcPaint;
1149 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1153 /***********************************************************************
1154 * TOOLBAR_MeasureString
1156 * This function gets the width and height of a string in pixels. This
1157 * is done first by using GetTextExtentPoint to get the basic width
1158 * and height. The DrawText is called with DT_CALCRECT to get the exact
1159 * width. The reason is because the text may have more than one "&" (or
1160 * prefix characters as M$ likes to call them). The prefix character
1161 * indicates where the underline goes, except for the string "&&" which
1162 * is reduced to a single "&". GetTextExtentPoint does not process these
1163 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1166 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1167 HDC hdc, LPSIZE lpSize)
1174 if (infoPtr->nMaxTextRows > 0 &&
1175 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1176 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1177 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1179 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1181 if(lpText != NULL) {
1182 /* first get size of all the text */
1183 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1185 /* feed above size into the rectangle for DrawText */
1186 myrect.left = myrect.top = 0;
1187 myrect.right = lpSize->cx;
1188 myrect.bottom = lpSize->cy;
1190 /* Use DrawText to get true size as drawn (less pesky "&") */
1191 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1192 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1195 /* feed back to caller */
1196 lpSize->cx = myrect.right;
1197 lpSize->cy = myrect.bottom;
1201 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1204 /***********************************************************************
1205 * TOOLBAR_CalcStrings
1207 * This function walks through each string and measures it and returns
1208 * the largest height and width to caller.
1211 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1213 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1214 TBUTTON_INFO *btnPtr;
1223 if (infoPtr->nMaxTextRows == 0)
1227 hOldFont = SelectObject (hdc, infoPtr->hFont);
1229 if (infoPtr->nNumButtons == 0)
1233 GetTextMetricsW(hdc, &tm);
1234 lpSize->cy = tm.tmHeight;
1237 btnPtr = infoPtr->buttons;
1238 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1239 if(TOOLBAR_HasText(infoPtr, btnPtr))
1241 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1242 if (sz.cx > lpSize->cx)
1244 if (sz.cy > lpSize->cy)
1249 SelectObject (hdc, hOldFont);
1250 ReleaseDC (hwnd, hdc);
1252 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1255 /***********************************************************************
1256 * TOOLBAR_WrapToolbar
1258 * This function walks through the buttons and separators in the
1259 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1260 * wrapping should occur based on the width of the toolbar window.
1261 * It does *not* calculate button placement itself. That task
1262 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1263 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1264 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1266 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1267 * vertical toolbar lists.
1271 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1274 TBUTTON_INFO *btnPtr;
1277 BOOL bWrap, bButtonWrap;
1279 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1280 /* no layout is necessary. Applications may use this style */
1281 /* to perform their own layout on the toolbar. */
1282 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1283 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1285 btnPtr = infoPtr->buttons;
1286 x = infoPtr->nIndent;
1288 if (GetParent(hwnd))
1290 /* this can get the parents width, to know how far we can extend
1291 * this toolbar. We cannot use its height, as there may be multiple
1292 * toolbars in a rebar control
1294 GetClientRect( GetParent(hwnd), &rc );
1295 infoPtr->nWidth = rc.right - rc.left;
1299 GetWindowRect( hwnd, &rc );
1300 infoPtr->nWidth = rc.right - rc.left;
1303 bButtonWrap = FALSE;
1305 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1306 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1309 for (i = 0; i < infoPtr->nNumButtons; i++ )
1312 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1314 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1317 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1318 /* it is the actual width of the separator. This is used for */
1319 /* custom controls in toolbars. */
1321 /* BTNS_DROPDOWN separators are treated as buttons for */
1322 /* width. - GA 8/01 */
1323 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1324 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1325 cx = (btnPtr[i].iBitmap > 0) ?
1326 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1328 cx = infoPtr->nButtonWidth;
1330 /* Two or more adjacent separators form a separator group. */
1331 /* The first separator in a group should be wrapped to the */
1332 /* next row if the previous wrapping is on a button. */
1334 (btnPtr[i].fsStyle & BTNS_SEP) &&
1335 (i + 1 < infoPtr->nNumButtons ) &&
1336 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1338 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1339 btnPtr[i].fsState |= TBSTATE_WRAP;
1340 x = infoPtr->nIndent;
1342 bButtonWrap = FALSE;
1346 /* The layout makes sure the bitmap is visible, but not the button. */
1347 /* Test added to also wrap after a button that starts a row but */
1348 /* is bigger than the area. - GA 8/01 */
1349 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1350 > infoPtr->nWidth ) ||
1351 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1353 BOOL bFound = FALSE;
1355 /* If the current button is a separator and not hidden, */
1356 /* go to the next until it reaches a non separator. */
1357 /* Wrap the last separator if it is before a button. */
1358 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1359 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1360 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1361 i < infoPtr->nNumButtons )
1367 if( bFound && i < infoPtr->nNumButtons )
1370 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1371 i, btnPtr[i].fsStyle, x, cx);
1372 btnPtr[i].fsState |= TBSTATE_WRAP;
1373 x = infoPtr->nIndent;
1374 bButtonWrap = FALSE;
1377 else if ( i >= infoPtr->nNumButtons)
1380 /* If the current button is not a separator, find the last */
1381 /* separator and wrap it. */
1382 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1384 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1385 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1389 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1390 i, btnPtr[i].fsStyle, x, cx);
1391 x = infoPtr->nIndent;
1392 btnPtr[j].fsState |= TBSTATE_WRAP;
1393 bButtonWrap = FALSE;
1398 /* If no separator available for wrapping, wrap one of */
1399 /* non-hidden previous button. */
1403 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1405 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1410 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1411 i, btnPtr[i].fsStyle, x, cx);
1412 x = infoPtr->nIndent;
1413 btnPtr[j].fsState |= TBSTATE_WRAP;
1419 /* If all above failed, wrap the current button. */
1422 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1423 i, btnPtr[i].fsStyle, x, cx);
1424 btnPtr[i].fsState |= TBSTATE_WRAP;
1426 x = infoPtr->nIndent;
1427 if (btnPtr[i].fsStyle & BTNS_SEP )
1428 bButtonWrap = FALSE;
1434 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1435 i, btnPtr[i].fsStyle, x, cx);
1442 /***********************************************************************
1443 * TOOLBAR_MeasureButton
1445 * Calculates the width and height required for a button. Used in
1446 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1447 * the width of buttons that are autosized.
1449 * Note that it would have been rather elegant to use one piece of code for
1450 * both the laying out of the toolbar and for controlling where button parts
1451 * are drawn, but the native control has inconsistencies between the two that
1452 * prevent this from being effectively. These inconsistencies can be seen as
1453 * artefacts where parts of the button appear outside of the bounding button
1456 * There are several cases for the calculation of the button dimensions and
1457 * button part positioning:
1464 * +--------------------------------------------------------+ ^
1466 * | | pad.cy / 2 | centred | |
1467 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1468 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1469 * | |<------------>| | | | |
1470 * | +--------------+ +------------+ | |
1471 * |<-------------------------------------->| | |
1472 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1474 * +--------------------------------------------------------+ -
1475 * <-------------------------------------------------------->
1476 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1478 * Without Bitmap (I_IMAGENONE):
1480 * +-----------------------------------+ ^
1482 * | | centred | | LISTPAD_CY +
1483 * | +------------+ | | szText.cy
1486 * | +------------+ | |
1487 * |<----------------->| | |
1488 * | cxedge |<-----------> | |
1490 * +-----------------------------------+ -
1491 * <----------------------------------->
1492 * szText.cx + pad.cx
1496 * +--------------------------------------+ ^
1498 * | | padding.cy/2 | | DEFPAD_CY +
1499 * | +------------+ | | nBitmapHeight
1502 * | +------------+ | |
1503 * |<------------------->| | |
1504 * | cxedge + iListGap/2 |<-----------> | |
1505 * | nBitmapWidth | |
1506 * +--------------------------------------+ -
1507 * <-------------------------------------->
1508 * 2*cxedge + nBitmapWidth + iListGap
1515 * +-----------------------------------+ ^
1517 * | | pad.cy / 2 | | nBitmapHeight +
1518 * | - | | szText.cy +
1519 * | +------------+ | | DEFPAD_CY + 1
1520 * | centred | Bitmap | | |
1521 * |<----------------->| | | |
1522 * | +------------+ | |
1526 * | centred +---------------+ | |
1527 * |<--------------->| Text | | |
1528 * | +---------------+ | |
1529 * +-----------------------------------+ -
1530 * <----------------------------------->
1531 * pad.cx + max(nBitmapWidth, szText.cx)
1533 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1535 * +---------------------------------------+ ^
1537 * | | 2 + pad.cy / 2 | |
1538 * | - | | szText.cy +
1539 * | centred +-----------------+ | | pad.cy + 2
1540 * |<--------------->| Text | | |
1541 * | +-----------------+ | |
1543 * +---------------------------------------+ -
1544 * <--------------------------------------->
1545 * 2*cxedge + pad.cx + szText.cx
1548 * As for with bitmaps, but with szText.cx zero.
1550 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1553 if (infoPtr->dwStyle & TBSTYLE_LIST)
1555 /* set button height from bitmap / text height... */
1556 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1559 /* ... add on the necessary padding */
1560 if (bValidImageList)
1563 sizeButton.cy += DEFPAD_CY;
1565 sizeButton.cy += LISTPAD_CY;
1568 sizeButton.cy += infoPtr->szPadding.cy;
1570 /* calculate button width */
1573 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1574 infoPtr->nBitmapWidth + infoPtr->iListGap;
1575 if (sizeString.cx > 0)
1576 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1579 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1585 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1586 sizeString.cy + DEFPAD_CY;
1587 sizeButton.cx = infoPtr->szPadding.cx +
1588 max(sizeString.cx, infoPtr->nBitmapWidth);
1592 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1593 NONLIST_NOTEXT_OFFSET;
1594 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1595 infoPtr->szPadding.cx + sizeString.cx;
1602 /***********************************************************************
1603 * TOOLBAR_CalcToolbar
1605 * This function calculates button and separator placement. It first
1606 * calculates the button sizes, gets the toolbar window width and then
1607 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1608 * on. It assigns a new location to each item and sends this location to
1609 * the tooltip window if appropriate. Finally, it updates the rcBound
1610 * rect and calculates the new required toolbar window height.
1613 TOOLBAR_CalcToolbar (HWND hwnd)
1615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1616 DWORD dwStyle = infoPtr->dwStyle;
1617 TBUTTON_INFO *btnPtr;
1618 INT i, nRows, nSepRows;
1620 SIZE sizeString, sizeButton;
1622 BOOL validImageList = FALSE;
1623 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1625 TOOLBAR_CalcStrings (hwnd, &sizeString);
1627 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1629 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1630 validImageList = TRUE;
1631 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1632 infoPtr->nButtonWidth = sizeButton.cx;
1633 infoPtr->nButtonHeight = sizeButton.cy;
1635 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1636 infoPtr->nButtonWidth = infoPtr->cxMin;
1637 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1638 infoPtr->nButtonWidth = infoPtr->cxMax;
1640 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1642 x = infoPtr->nIndent;
1643 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1648 /* from above, minimum is a button, and possible text */
1649 cx = infoPtr->nButtonWidth;
1650 cy = infoPtr->nButtonHeight;
1652 nRows = nSepRows = 0;
1654 infoPtr->rcBound.top = y;
1655 infoPtr->rcBound.left = x;
1656 infoPtr->rcBound.bottom = y + cy;
1657 infoPtr->rcBound.right = x;
1659 btnPtr = infoPtr->buttons;
1661 TRACE("cy=%d\n", cy);
1663 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1666 if (btnPtr->fsState & TBSTATE_HIDDEN)
1668 SetRectEmpty (&btnPtr->rect);
1672 cy = infoPtr->nButtonHeight;
1674 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1675 /* it is the actual width of the separator. This is used for */
1676 /* custom controls in toolbars. */
1677 if (btnPtr->fsStyle & BTNS_SEP) {
1678 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1679 cy = (btnPtr->iBitmap > 0) ?
1680 btnPtr->iBitmap : SEPARATOR_WIDTH;
1681 cx = infoPtr->nButtonWidth;
1684 cx = (btnPtr->iBitmap > 0) ?
1685 btnPtr->iBitmap : SEPARATOR_WIDTH;
1691 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1692 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1699 hOldFont = SelectObject (hdc, infoPtr->hFont);
1701 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1703 SelectObject (hdc, hOldFont);
1704 ReleaseDC (hwnd, hdc);
1706 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1707 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1712 cx = infoPtr->nButtonWidth;
1714 /* if size has been set manually then don't add on extra space
1715 * for the drop down arrow */
1716 if (!btnPtr->cx && hasDropDownArrows &&
1717 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1718 cx += DDARROW_WIDTH;
1720 if (btnPtr->fsState & TBSTATE_WRAP )
1723 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1725 if (infoPtr->rcBound.left > x)
1726 infoPtr->rcBound.left = x;
1727 if (infoPtr->rcBound.right < x + cx)
1728 infoPtr->rcBound.right = x + cx;
1729 if (infoPtr->rcBound.bottom < y + cy)
1730 infoPtr->rcBound.bottom = y + cy;
1732 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1734 /* btnPtr->nRow is zero based. The space between the rows is */
1735 /* also considered as a row. */
1736 btnPtr->nRow = nRows + nSepRows;
1738 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1739 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1744 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1748 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1749 /* it is the actual width of the separator. This is used for */
1750 /* custom controls in toolbars. */
1751 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1752 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1753 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1757 /* nSepRows is used to calculate the extra height follwoing */
1761 x = infoPtr->nIndent;
1763 /* Increment row number unless this is the last button */
1764 /* and it has Wrap set. */
1765 if (i != infoPtr->nNumButtons-1)
1772 /* infoPtr->nRows is the number of rows on the toolbar */
1773 infoPtr->nRows = nRows + nSepRows + 1;
1775 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1780 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1783 TBUTTON_INFO *btnPtr;
1786 btnPtr = infoPtr->buttons;
1787 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1788 if (btnPtr->fsState & TBSTATE_HIDDEN)
1791 if (btnPtr->fsStyle & BTNS_SEP) {
1792 if (PtInRect (&btnPtr->rect, *lpPt)) {
1793 TRACE(" ON SEPARATOR %d!\n", i);
1798 if (PtInRect (&btnPtr->rect, *lpPt)) {
1799 TRACE(" ON BUTTON %d!\n", i);
1805 TRACE(" NOWHERE!\n");
1806 return TOOLBAR_NOWHERE;
1811 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1813 TBUTTON_INFO *btnPtr;
1816 if (CommandIsIndex) {
1817 TRACE("command is really index command=%d\n", idCommand);
1818 if (idCommand >= infoPtr->nNumButtons) return -1;
1821 btnPtr = infoPtr->buttons;
1822 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1823 if (btnPtr->idCommand == idCommand) {
1824 TRACE("command=%d index=%d\n", idCommand, i);
1828 TRACE("no index found for command=%d\n", idCommand);
1834 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1836 TBUTTON_INFO *btnPtr;
1839 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1842 /* check index button */
1843 btnPtr = &infoPtr->buttons[nIndex];
1844 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1845 if (btnPtr->fsState & TBSTATE_CHECKED)
1849 /* check previous buttons */
1850 nRunIndex = nIndex - 1;
1851 while (nRunIndex >= 0) {
1852 btnPtr = &infoPtr->buttons[nRunIndex];
1853 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1854 if (btnPtr->fsState & TBSTATE_CHECKED)
1862 /* check next buttons */
1863 nRunIndex = nIndex + 1;
1864 while (nRunIndex < infoPtr->nNumButtons) {
1865 btnPtr = &infoPtr->buttons[nRunIndex];
1866 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1867 if (btnPtr->fsState & TBSTATE_CHECKED)
1880 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1881 WPARAM wParam, LPARAM lParam)
1887 msg.wParam = wParam;
1888 msg.lParam = lParam;
1889 msg.time = GetMessageTime ();
1890 msg.pt.x = LOWORD(GetMessagePos ());
1891 msg.pt.y = HIWORD(GetMessagePos ());
1893 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1897 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1899 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1902 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1903 ti.cbSize = sizeof (TTTOOLINFOW);
1904 ti.hwnd = infoPtr->hwndSelf;
1905 ti.uId = button->idCommand;
1907 ti.lpszText = LPSTR_TEXTCALLBACKW;
1908 /* ti.lParam = random value from the stack? */
1910 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1916 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1918 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1921 ZeroMemory(&ti, sizeof(ti));
1922 ti.cbSize = sizeof(ti);
1923 ti.hwnd = infoPtr->hwndSelf;
1924 ti.uId = button->idCommand;
1926 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1930 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1932 /* Set the toolTip only for non-hidden, non-separator button */
1933 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1937 ZeroMemory(&ti, sizeof(ti));
1938 ti.cbSize = sizeof(ti);
1939 ti.hwnd = infoPtr->hwndSelf;
1940 ti.uId = button->idCommand;
1941 ti.rect = button->rect;
1942 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1946 /* Creates the tooltip control */
1948 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1951 NMTOOLTIPSCREATED nmttc;
1953 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
1954 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1955 infoPtr->hwndSelf, 0, 0, 0);
1957 if (!infoPtr->hwndToolTip)
1960 /* Send NM_TOOLTIPSCREATED notification */
1961 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1962 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1964 for (i = 0; i < infoPtr->nNumButtons; i++)
1966 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1967 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1971 /* keeps available button list box sorted by button id */
1972 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1976 PCUSTOMBUTTON btnInfo;
1977 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1979 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1981 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1983 /* position 0 is always separator */
1984 for (i = 1; i < count; i++)
1986 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1987 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1989 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1990 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1994 /* id higher than all others add to end */
1995 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1996 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1999 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2003 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2005 if (nIndexFrom == nIndexTo)
2008 /* MSDN states that iItem is the index of the button, rather than the
2009 * command ID as used by every other NMTOOLBAR notification */
2010 nmtb.iItem = nIndexFrom;
2011 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2013 PCUSTOMBUTTON btnInfo;
2015 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2016 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2018 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2020 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2021 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2022 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2023 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2026 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2028 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2030 /* last item is always separator, so -2 instead of -1 */
2031 if (nIndexTo >= (count - 2))
2032 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2034 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2036 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2037 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2039 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2043 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2047 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2049 /* MSDN states that iItem is the index of the button, rather than the
2050 * command ID as used by every other NMTOOLBAR notification */
2051 nmtb.iItem = nIndexAvail;
2052 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2054 PCUSTOMBUTTON btnInfo;
2056 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2057 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2058 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2060 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2062 if (nIndexAvail != 0) /* index == 0 indicates separator */
2064 /* remove from 'available buttons' list */
2065 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2066 if (nIndexAvail == count-1)
2067 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2069 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2073 PCUSTOMBUTTON btnNew;
2075 /* duplicate 'separator' button */
2076 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2077 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2081 /* insert into 'toolbar button' list */
2082 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2083 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2085 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2087 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2091 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2093 PCUSTOMBUTTON btnInfo;
2094 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2096 TRACE("Remove: index %d\n", index);
2098 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2100 /* send TBN_QUERYDELETE notification */
2101 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2105 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2106 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2108 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2110 /* insert into 'available button' list */
2111 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2112 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2116 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2120 /* drag list notification function for toolbar buttons list box */
2121 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2123 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2124 switch (pDLI->uNotification)
2128 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2129 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2130 /* no dragging for last item (separator) */
2131 if (nCurrentItem >= (nCount - 1)) return FALSE;
2136 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2137 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2138 /* no dragging past last item (separator) */
2139 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2141 DrawInsert(hwnd, hwndList, nCurrentItem);
2142 /* FIXME: native uses "move button" cursor */
2143 return DL_COPYCURSOR;
2146 /* not over toolbar buttons list */
2147 if (nCurrentItem < 0)
2149 POINT ptWindow = pDLI->ptCursor;
2150 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2151 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2152 /* over available buttons list? */
2153 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2154 /* FIXME: native uses "move button" cursor */
2155 return DL_COPYCURSOR;
2157 /* clear drag arrow */
2158 DrawInsert(hwnd, hwndList, -1);
2159 return DL_STOPCURSOR;
2163 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2164 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2165 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2166 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2168 /* clear drag arrow */
2169 DrawInsert(hwnd, hwndList, -1);
2171 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2173 /* not over toolbar buttons list */
2176 POINT ptWindow = pDLI->ptCursor;
2177 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2178 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2179 /* over available buttons list? */
2180 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2181 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2186 /* Clear drag arrow */
2187 DrawInsert(hwnd, hwndList, -1);
2194 /* drag list notification function for available buttons list box */
2195 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2197 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2198 switch (pDLI->uNotification)
2204 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2205 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2206 /* no dragging past last item (separator) */
2207 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2209 DrawInsert(hwnd, hwndList, nCurrentItem);
2210 /* FIXME: native uses "move button" cursor */
2211 return DL_COPYCURSOR;
2214 /* not over toolbar buttons list */
2215 if (nCurrentItem < 0)
2217 POINT ptWindow = pDLI->ptCursor;
2218 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2219 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2220 /* over available buttons list? */
2221 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2222 /* FIXME: native uses "move button" cursor */
2223 return DL_COPYCURSOR;
2225 /* clear drag arrow */
2226 DrawInsert(hwnd, hwndList, -1);
2227 return DL_STOPCURSOR;
2231 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2232 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2233 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2234 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2236 /* clear drag arrow */
2237 DrawInsert(hwnd, hwndList, -1);
2239 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2243 /* Clear drag arrow */
2244 DrawInsert(hwnd, hwndList, -1);
2250 extern UINT uDragListMessage;
2252 /***********************************************************************
2253 * TOOLBAR_CustomizeDialogProc
2254 * This function implements the toolbar customization dialog.
2256 static INT_PTR CALLBACK
2257 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2259 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2260 PCUSTOMBUTTON btnInfo;
2262 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2267 custInfo = (PCUSTDLG_INFO)lParam;
2268 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2275 NMTBINITCUSTOMIZE nmtbic;
2277 infoPtr = custInfo->tbInfo;
2279 /* send TBN_QUERYINSERT notification */
2280 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2282 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2285 nmtbic.hwndDialog = hwnd;
2286 /* Send TBN_INITCUSTOMIZE notification */
2287 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2290 TRACE("TBNRF_HIDEHELP requested\n");
2291 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2294 /* add items to 'toolbar buttons' list and check if removable */
2295 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2297 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2298 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2299 btnInfo->btn.fsStyle = BTNS_SEP;
2300 btnInfo->bVirtual = FALSE;
2301 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2303 /* send TBN_QUERYDELETE notification */
2304 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2306 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2307 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2310 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2312 /* insert separator button into 'available buttons' list */
2313 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2314 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2315 btnInfo->btn.fsStyle = BTNS_SEP;
2316 btnInfo->bVirtual = FALSE;
2317 btnInfo->bRemovable = TRUE;
2318 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2319 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2320 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2322 /* insert all buttons into dsa */
2325 /* send TBN_GETBUTTONINFO notification */
2328 nmtb.pszText = Buffer;
2331 /* Clear previous button's text */
2332 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2334 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2337 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2338 nmtb.tbButton.fsStyle, i,
2339 nmtb.tbButton.idCommand,
2340 nmtb.tbButton.iString,
2341 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2344 /* insert button into the apropriate list */
2345 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2348 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2349 btnInfo->bVirtual = FALSE;
2350 btnInfo->bRemovable = TRUE;
2354 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2355 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2358 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2359 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2361 if (lstrlenW(nmtb.pszText))
2362 lstrcpyW(btnInfo->text, nmtb.pszText);
2363 else if (nmtb.tbButton.iString >= 0 &&
2364 nmtb.tbButton.iString < infoPtr->nNumStrings)
2366 lstrcpyW(btnInfo->text,
2367 infoPtr->strings[nmtb.tbButton.iString]);
2372 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2375 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2377 /* select first item in the 'available' list */
2378 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2380 /* append 'virtual' separator button to the 'toolbar buttons' list */
2381 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2382 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2383 btnInfo->btn.fsStyle = BTNS_SEP;
2384 btnInfo->bVirtual = TRUE;
2385 btnInfo->bRemovable = FALSE;
2386 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2387 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2388 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2390 /* select last item in the 'toolbar' list */
2391 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2392 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2394 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2395 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2397 /* set focus and disable buttons */
2398 PostMessageW (hwnd, WM_USER, 0, 0);
2403 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2404 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2405 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2406 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2410 EndDialog(hwnd, FALSE);
2414 switch (LOWORD(wParam))
2416 case IDC_TOOLBARBTN_LBOX:
2417 if (HIWORD(wParam) == LBN_SELCHANGE)
2419 PCUSTOMBUTTON btnInfo;
2424 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2425 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2427 /* send TBN_QUERYINSERT notification */
2429 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2431 /* get list box item */
2432 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2434 if (index == (count - 1))
2436 /* last item (virtual separator) */
2437 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2438 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2440 else if (index == (count - 2))
2442 /* second last item (last non-virtual item) */
2443 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2444 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2446 else if (index == 0)
2449 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2454 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2458 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2462 case IDC_MOVEUP_BTN:
2464 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2465 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2469 case IDC_MOVEDN_BTN: /* move down */
2471 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2472 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2476 case IDC_REMOVE_BTN: /* remove button */
2478 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2480 if (LB_ERR == index)
2483 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2487 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2490 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2493 case IDOK: /* Add button */
2498 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2499 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2501 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2506 EndDialog(hwnd, FALSE);
2516 /* delete items from 'toolbar buttons' listbox*/
2517 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2518 for (i = 0; i < count; i++)
2520 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2522 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2524 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2527 /* delete items from 'available buttons' listbox*/
2528 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2529 for (i = 0; i < count; i++)
2531 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2533 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2535 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2540 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2542 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2547 COLORREF oldText = 0;
2551 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2552 if (btnInfo == NULL)
2554 FIXME("btnInfo invalid!\n");
2558 /* set colors and select objects */
2559 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2560 if (btnInfo->bVirtual)
2561 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2563 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2564 hPen = CreatePen( PS_SOLID, 1,
2565 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2566 hOldPen = SelectObject (lpdis->hDC, hPen );
2567 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2569 /* fill background rectangle */
2570 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2571 lpdis->rcItem.right, lpdis->rcItem.bottom);
2573 /* calculate button and text rectangles */
2574 CopyRect (&rcButton, &lpdis->rcItem);
2575 InflateRect (&rcButton, -1, -1);
2576 CopyRect (&rcText, &rcButton);
2577 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2578 rcText.left = rcButton.right + 2;
2580 /* draw focus rectangle */
2581 if (lpdis->itemState & ODS_FOCUS)
2582 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2585 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2586 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2588 /* draw image and text */
2589 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2590 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2591 btnInfo->btn.iBitmap));
2592 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2593 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2595 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2596 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2598 /* delete objects and reset colors */
2599 SelectObject (lpdis->hDC, hOldBrush);
2600 SelectObject (lpdis->hDC, hOldPen);
2601 SetBkColor (lpdis->hDC, oldBk);
2602 SetTextColor (lpdis->hDC, oldText);
2603 DeleteObject( hPen );
2608 case WM_MEASUREITEM:
2609 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2611 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2613 lpmis->itemHeight = 15 + 8; /* default height */
2620 if (uDragListMessage && (uMsg == uDragListMessage))
2622 if (wParam == IDC_TOOLBARBTN_LBOX)
2624 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2625 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2626 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2629 else if (wParam == IDC_AVAILBTN_LBOX)
2631 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2632 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2633 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2642 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2645 INT nCountBefore = ImageList_GetImageCount(himlDef);
2651 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2652 /* Add bitmaps to the default image list */
2653 if (bitmap->hInst == NULL) /* a handle was passed */
2656 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2657 HDC hdcImage, hdcBitmap;
2659 /* copy the bitmap before adding it so that the user's bitmap
2660 * doesn't get modified.
2662 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2664 hdcImage = CreateCompatibleDC(0);
2665 hdcBitmap = CreateCompatibleDC(0);
2667 /* create new bitmap */
2668 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2669 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2670 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2672 /* Copy the user's image */
2673 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2674 hdcBitmap, 0, 0, SRCCOPY);
2676 SelectObject (hdcImage, hOldBitmapLoad);
2677 SelectObject (hdcBitmap, hOldBitmapBitmap);
2678 DeleteDC (hdcImage);
2679 DeleteDC (hdcBitmap);
2682 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2684 /* enlarge the bitmap if needed */
2685 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2686 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2688 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2689 DeleteObject(hbmLoad);
2693 nCountAfter = ImageList_GetImageCount(himlDef);
2694 nAdded = nCountAfter - nCountBefore;
2695 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2697 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2698 } else if (nAdded > (INT)bitmap->nButtons) {
2699 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2700 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2703 infoPtr->nNumBitmaps += nAdded;
2708 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2715 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2716 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2718 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2720 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2723 TRACE("Update icon size: %dx%d -> %dx%d\n",
2724 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2726 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2727 ILC_COLORDDB|ILC_MASK, 8, 2);
2728 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2729 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2730 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2731 infoPtr->himlInt = himlNew;
2733 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2734 ImageList_Destroy(himlDef);
2737 /***********************************************************************
2738 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2742 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2745 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2750 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2754 if (lpAddBmp->hInst == HINST_COMMCTRL)
2756 info.hInst = COMCTL32_hModule;
2757 switch (lpAddBmp->nID)
2759 case IDB_STD_SMALL_COLOR:
2761 info.nID = IDB_STD_SMALL;
2763 case IDB_STD_LARGE_COLOR:
2765 info.nID = IDB_STD_LARGE;
2767 case IDB_VIEW_SMALL_COLOR:
2769 info.nID = IDB_VIEW_SMALL;
2771 case IDB_VIEW_LARGE_COLOR:
2773 info.nID = IDB_VIEW_LARGE;
2775 case IDB_HIST_SMALL_COLOR:
2777 info.nID = IDB_HIST_SMALL;
2779 case IDB_HIST_LARGE_COLOR:
2781 info.nID = IDB_HIST_LARGE;
2787 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2789 /* Windows resize all the buttons to the size of a newly added standard image */
2790 if (lpAddBmp->nID & 1)
2793 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2794 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2796 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2797 MAKELPARAM((WORD)24, (WORD)24));
2798 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2799 MAKELPARAM((WORD)31, (WORD)30));
2804 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2805 MAKELPARAM((WORD)16, (WORD)16));
2806 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2807 MAKELPARAM((WORD)22, (WORD)22));
2810 TOOLBAR_CalcToolbar (hwnd);
2814 info.nButtons = (INT)wParam;
2815 info.hInst = lpAddBmp->hInst;
2816 info.nID = lpAddBmp->nID;
2817 TRACE("adding %d bitmaps!\n", info.nButtons);
2820 /* check if the bitmap is already loaded and compute iSumButtons */
2822 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2824 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2825 infoPtr->bitmaps[i].nID == info.nID)
2827 iSumButtons += infoPtr->bitmaps[i].nButtons;
2830 if (!infoPtr->cimlDef) {
2831 /* create new default image list */
2832 TRACE ("creating default image list!\n");
2834 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2835 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2836 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2837 infoPtr->himlInt = himlDef;
2840 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2844 WARN("No default image list available\n");
2848 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2851 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2852 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2853 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2854 infoPtr->nNumBitmapInfos++;
2855 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2857 InvalidateRect(hwnd, NULL, TRUE);
2863 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2866 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2867 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2869 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2871 nAddButtons = (UINT)wParam;
2872 nOldButtons = infoPtr->nNumButtons;
2873 nNewButtons = nOldButtons + nAddButtons;
2875 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2876 infoPtr->nNumButtons = nNewButtons;
2878 /* insert new button data */
2879 for (nCount = 0; nCount < nAddButtons; nCount++) {
2880 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2881 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2882 btnPtr->idCommand = lpTbb[nCount].idCommand;
2883 btnPtr->fsState = lpTbb[nCount].fsState;
2884 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2885 btnPtr->dwData = lpTbb[nCount].dwData;
2886 btnPtr->bHot = FALSE;
2887 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2890 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2892 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2895 btnPtr->iString = lpTbb[nCount].iString;
2897 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2900 TOOLBAR_CalcToolbar (hwnd);
2901 TOOLBAR_AutoSize (hwnd);
2903 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2905 InvalidateRect(hwnd, NULL, TRUE);
2912 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2914 #define MAX_RESOURCE_STRING_LENGTH 512
2915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2916 INT nIndex = infoPtr->nNumStrings;
2918 if ((wParam) && (HIWORD(lParam) == 0)) {
2919 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2924 TRACE("adding string from resource!\n");
2926 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2927 szString, MAX_RESOURCE_STRING_LENGTH);
2929 TRACE("len=%d %s\n", len, debugstr_w(szString));
2930 if (len == 0 || len == 1)
2933 TRACE("Delimiter: 0x%x\n", *szString);
2934 delimiter = *szString;
2937 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2939 if (next_delim + 1 >= szString + len)
2941 /* this may happen if delimiter == '\0' or if the last char is a
2942 * delimiter (then it is ignored like the native does) */
2946 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2947 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2948 infoPtr->nNumStrings++;
2954 LPWSTR p = (LPWSTR)lParam;
2959 TRACE("adding string(s) from array!\n");
2963 TRACE("len=%d %s\n", len, debugstr_w(p));
2964 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2965 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2966 infoPtr->nNumStrings++;
2977 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2984 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2985 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2991 TRACE("adding string(s) from array!\n");
2992 nIndex = infoPtr->nNumStrings;
2995 TRACE("len=%d \"%s\"\n", len, p);
2997 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2998 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2999 infoPtr->nNumStrings++;
3009 TOOLBAR_AutoSize (HWND hwnd)
3011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3017 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3019 parent = GetParent (hwnd);
3021 if (!parent || !infoPtr->bDoRedraw)
3024 GetClientRect(parent, &parent_rect);
3026 x = parent_rect.left;
3027 y = parent_rect.top;
3029 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3031 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3032 cx = parent_rect.right - parent_rect.left;
3034 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3036 TOOLBAR_CalcToolbar(hwnd);
3037 InvalidateRect( hwnd, NULL, TRUE );
3040 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3043 UINT uPosFlags = SWP_NOZORDER;
3045 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3047 GetWindowRect(hwnd, &window_rect);
3048 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3049 y = window_rect.top;
3051 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3053 GetWindowRect(hwnd, &window_rect);
3054 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3057 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3058 uPosFlags |= SWP_NOMOVE;
3060 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3061 cy += GetSystemMetrics(SM_CYEDGE);
3063 if (infoPtr->dwStyle & WS_BORDER)
3065 x = y = 1; /* FIXME: this looks wrong */
3066 cy += GetSystemMetrics(SM_CYEDGE);
3067 cx += GetSystemMetrics(SM_CXEDGE);
3070 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3078 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3082 return infoPtr->nNumButtons;
3087 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3091 infoPtr->dwStructSize = (DWORD)wParam;
3098 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3100 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3101 TBUTTON_INFO *btnPtr;
3104 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3106 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3110 btnPtr = &infoPtr->buttons[nIndex];
3111 btnPtr->iBitmap = LOWORD(lParam);
3113 /* we HAVE to erase the background, the new bitmap could be */
3115 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3122 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 TBUTTON_INFO *btnPtr;
3128 BOOL bChecked = FALSE;
3130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3132 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3137 btnPtr = &infoPtr->buttons[nIndex];
3139 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3141 if (LOWORD(lParam) == FALSE)
3142 btnPtr->fsState &= ~TBSTATE_CHECKED;
3144 if (btnPtr->fsStyle & BTNS_GROUP) {
3146 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3147 if (nOldIndex == nIndex)
3149 if (nOldIndex != -1)
3150 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3152 btnPtr->fsState |= TBSTATE_CHECKED;
3155 if( bChecked != LOWORD(lParam) )
3157 if (nOldIndex != -1)
3158 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3159 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3162 /* FIXME: Send a WM_NOTIFY?? */
3169 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3178 TOOLBAR_Customize (HWND hwnd)
3180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3181 CUSTDLG_INFO custInfo;
3187 custInfo.tbInfo = infoPtr;
3188 custInfo.tbHwnd = hwnd;
3190 /* send TBN_BEGINADJUST notification */
3191 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3193 if (!(hRes = FindResourceW (COMCTL32_hModule,
3194 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3195 (LPWSTR)RT_DIALOG)))
3198 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3201 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3202 (LPCDLGTEMPLATEW)template,
3204 TOOLBAR_CustomizeDialogProc,
3207 /* send TBN_ENDADJUST notification */
3208 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3215 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3218 INT nIndex = (INT)wParam;
3220 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3222 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3225 memset(&nmtb, 0, sizeof(nmtb));
3226 nmtb.iItem = btnPtr->idCommand;
3227 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3228 nmtb.tbButton.idCommand = btnPtr->idCommand;
3229 nmtb.tbButton.fsState = btnPtr->fsState;
3230 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3231 nmtb.tbButton.dwData = btnPtr->dwData;
3232 nmtb.tbButton.iString = btnPtr->iString;
3233 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3235 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3237 if (infoPtr->nNumButtons == 1) {
3238 TRACE(" simple delete!\n");
3239 Free (infoPtr->buttons);
3240 infoPtr->buttons = NULL;
3241 infoPtr->nNumButtons = 0;
3244 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3245 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3247 infoPtr->nNumButtons--;
3248 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3250 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3251 nIndex * sizeof(TBUTTON_INFO));
3254 if (nIndex < infoPtr->nNumButtons) {
3255 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3256 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3262 TOOLBAR_CalcToolbar (hwnd);
3264 InvalidateRect (hwnd, NULL, TRUE);
3271 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3274 TBUTTON_INFO *btnPtr;
3278 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3280 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3285 btnPtr = &infoPtr->buttons[nIndex];
3287 bState = btnPtr->fsState & TBSTATE_ENABLED;
3289 /* update the toolbar button state */
3290 if(LOWORD(lParam) == FALSE) {
3291 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3293 btnPtr->fsState |= TBSTATE_ENABLED;
3296 /* redraw the button only if the state of the button changed */
3297 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3298 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3304 static inline LRESULT
3305 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3307 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3309 return infoPtr->bAnchor;
3314 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3319 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3323 return infoPtr->buttons[nIndex].iBitmap;
3327 static inline LRESULT
3328 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3330 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3335 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3338 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3339 INT nIndex = (INT)wParam;
3340 TBUTTON_INFO *btnPtr;
3345 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3348 btnPtr = &infoPtr->buttons[nIndex];
3349 lpTbb->iBitmap = btnPtr->iBitmap;
3350 lpTbb->idCommand = btnPtr->idCommand;
3351 lpTbb->fsState = btnPtr->fsState;
3352 lpTbb->fsStyle = btnPtr->fsStyle;
3353 lpTbb->bReserved[0] = 0;
3354 lpTbb->bReserved[1] = 0;
3355 lpTbb->dwData = btnPtr->dwData;
3356 lpTbb->iString = btnPtr->iString;
3363 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3366 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3367 TBUTTON_INFO *btnPtr;
3370 if (lpTbInfo == NULL)
3372 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3375 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3376 lpTbInfo->dwMask & 0x80000000);
3380 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3382 if (lpTbInfo->dwMask & TBIF_COMMAND)
3383 lpTbInfo->idCommand = btnPtr->idCommand;
3384 if (lpTbInfo->dwMask & TBIF_IMAGE)
3385 lpTbInfo->iImage = btnPtr->iBitmap;
3386 if (lpTbInfo->dwMask & TBIF_LPARAM)
3387 lpTbInfo->lParam = btnPtr->dwData;
3388 if (lpTbInfo->dwMask & TBIF_SIZE)
3389 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3390 if (lpTbInfo->dwMask & TBIF_STATE)
3391 lpTbInfo->fsState = btnPtr->fsState;
3392 if (lpTbInfo->dwMask & TBIF_STYLE)
3393 lpTbInfo->fsStyle = btnPtr->fsStyle;
3394 if (lpTbInfo->dwMask & TBIF_TEXT) {
3395 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3396 can't use TOOLBAR_GetText here */
3398 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3399 lpText = (LPWSTR)btnPtr->iString;
3400 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3402 lpTbInfo->pszText[0] = '\0';
3409 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3411 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3412 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3413 TBUTTON_INFO *btnPtr;
3416 if (lpTbInfo == NULL)
3418 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3421 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3422 lpTbInfo->dwMask & 0x80000000);
3426 btnPtr = &infoPtr->buttons[nIndex];
3431 if (lpTbInfo->dwMask & TBIF_COMMAND)
3432 lpTbInfo->idCommand = btnPtr->idCommand;
3433 if (lpTbInfo->dwMask & TBIF_IMAGE)
3434 lpTbInfo->iImage = btnPtr->iBitmap;
3435 if (lpTbInfo->dwMask & TBIF_LPARAM)
3436 lpTbInfo->lParam = btnPtr->dwData;
3437 if (lpTbInfo->dwMask & TBIF_SIZE)
3438 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3439 if (lpTbInfo->dwMask & TBIF_STATE)
3440 lpTbInfo->fsState = btnPtr->fsState;
3441 if (lpTbInfo->dwMask & TBIF_STYLE)
3442 lpTbInfo->fsStyle = btnPtr->fsStyle;
3443 if (lpTbInfo->dwMask & TBIF_TEXT) {
3444 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3445 can't use TOOLBAR_GetText here */
3447 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3448 lpText = (LPWSTR)btnPtr->iString;
3449 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3451 lpTbInfo->pszText[0] = '\0';
3459 TOOLBAR_GetButtonSize (HWND hwnd)
3461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3463 if (infoPtr->nNumButtons > 0)
3464 return MAKELONG((WORD)infoPtr->nButtonWidth,
3465 (WORD)infoPtr->nButtonHeight);
3467 return MAKELONG(23,22);
3472 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3481 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3485 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3487 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3488 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3493 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3500 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3504 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3508 ret = strlenW (lpText);
3511 strcpyW ((LPWSTR)lParam, lpText);
3519 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3521 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3522 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3523 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3527 inline static LRESULT
3528 TOOLBAR_GetExtendedStyle (HWND hwnd)
3530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3534 return infoPtr->dwExStyle;
3539 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3542 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3543 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3548 TOOLBAR_GetHotItem (HWND hwnd)
3550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3552 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3555 if (infoPtr->nHotItem < 0)
3558 return (LRESULT)infoPtr->nHotItem;
3563 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3565 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3566 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3567 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3572 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3575 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3577 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3579 *lptbim = infoPtr->tbim;
3586 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3590 TRACE("hwnd = %p\n", hwnd);
3592 return (LRESULT)infoPtr->clrInsertMark;
3597 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3600 TBUTTON_INFO *btnPtr;
3604 nIndex = (INT)wParam;
3605 btnPtr = &infoPtr->buttons[nIndex];
3606 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3608 lpRect = (LPRECT)lParam;
3611 if (btnPtr->fsState & TBSTATE_HIDDEN)
3614 lpRect->left = btnPtr->rect.left;
3615 lpRect->right = btnPtr->rect.right;
3616 lpRect->bottom = btnPtr->rect.bottom;
3617 lpRect->top = btnPtr->rect.top;
3624 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3627 LPSIZE lpSize = (LPSIZE)lParam;
3632 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3633 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3635 TRACE("maximum size %d x %d\n",
3636 infoPtr->rcBound.right - infoPtr->rcBound.left,
3637 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3643 /* << TOOLBAR_GetObject >> */
3647 TOOLBAR_GetPadding (HWND hwnd)
3649 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3652 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3653 return (LRESULT) oldPad;
3658 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3661 TBUTTON_INFO *btnPtr;
3665 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3666 btnPtr = &infoPtr->buttons[nIndex];
3667 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3669 lpRect = (LPRECT)lParam;
3673 lpRect->left = btnPtr->rect.left;
3674 lpRect->right = btnPtr->rect.right;
3675 lpRect->bottom = btnPtr->rect.bottom;
3676 lpRect->top = btnPtr->rect.top;
3683 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3687 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3688 return infoPtr->nRows;
3695 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3697 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3700 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3704 return infoPtr->buttons[nIndex].fsState;
3709 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3711 return GetWindowLongW(hwnd, GWL_STYLE);
3716 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3720 return infoPtr->nMaxTextRows;
3725 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3730 TOOLBAR_TooltipCreateControl(infoPtr);
3731 return (LRESULT)infoPtr->hwndToolTip;
3736 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3740 TRACE("%s hwnd=%p\n",
3741 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3743 return infoPtr->bUnicode;
3747 inline static LRESULT
3748 TOOLBAR_GetVersion (HWND hwnd)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3751 return infoPtr->iVersion;
3756 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3759 TBUTTON_INFO *btnPtr;
3764 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3768 btnPtr = &infoPtr->buttons[nIndex];
3769 if (LOWORD(lParam) == FALSE)
3770 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3772 btnPtr->fsState |= TBSTATE_HIDDEN;
3774 TOOLBAR_CalcToolbar (hwnd);
3776 InvalidateRect (hwnd, NULL, TRUE);
3782 inline static LRESULT
3783 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3785 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3790 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3792 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3793 TBUTTON_INFO *btnPtr;
3797 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3801 btnPtr = &infoPtr->buttons[nIndex];
3802 oldState = btnPtr->fsState;
3803 if (LOWORD(lParam) == FALSE)
3804 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3806 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3808 if(oldState != btnPtr->fsState)
3809 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3816 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3819 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3820 INT nIndex = (INT)wParam;
3825 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3828 /* EPP: this seems to be an undocumented call (from my IE4)
3829 * I assume in that case that:
3830 * - index of insertion is at the end of existing buttons
3831 * I only see this happen with nIndex == -1, but it could have a special
3832 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3834 nIndex = infoPtr->nNumButtons;
3836 } else if (nIndex < 0)
3839 TRACE("inserting button index=%d\n", nIndex);
3840 if (nIndex > infoPtr->nNumButtons) {
3841 nIndex = infoPtr->nNumButtons;
3842 TRACE("adjust index=%d\n", nIndex);
3845 infoPtr->nNumButtons++;
3846 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3847 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3848 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3850 /* insert new button */
3851 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3852 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3853 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3854 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3855 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3856 /* if passed string and not index, then add string */
3857 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3859 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3861 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3864 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3866 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3868 TOOLBAR_CalcToolbar (hwnd);
3869 TOOLBAR_AutoSize (hwnd);
3871 InvalidateRect (hwnd, NULL, TRUE);
3876 /* << TOOLBAR_InsertMarkHitTest >> */
3880 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3885 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3889 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3894 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3899 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3903 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3908 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3910 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3913 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3917 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3922 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3927 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3931 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3936 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3938 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3941 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3945 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3950 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3952 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3955 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3959 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3964 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3967 tbab.hInst = (HINSTANCE)lParam;
3968 tbab.nID = (UINT_PTR)wParam;
3970 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3972 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3977 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3980 WCHAR wAccel = (WCHAR)wParam;
3981 UINT* pIDButton = (UINT*)lParam;
3982 WCHAR wszAccel[] = {'&',wAccel,0};
3985 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3986 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3988 for (i = 0; i < infoPtr->nNumButtons; i++)
3990 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3991 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3992 !(btnPtr->fsState & TBSTATE_HIDDEN))
3994 int iLen = strlenW(wszAccel);
3995 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4002 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4007 if (!strncmpiW(lpszStr, wszAccel, iLen))
4009 *pIDButton = btnPtr->idCommand;
4021 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4026 TBUTTON_INFO *btnPtr;
4028 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4030 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4034 btnPtr = &infoPtr->buttons[nIndex];
4035 oldState = btnPtr->fsState;
4038 btnPtr->fsState |= TBSTATE_MARKED;
4040 btnPtr->fsState &= ~TBSTATE_MARKED;
4042 if(oldState != btnPtr->fsState)
4043 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4049 /* fixes up an index of a button affected by a move */
4050 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4054 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4056 else if (*pIndex == nIndex)
4057 *pIndex = nMoveIndex;
4061 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4063 else if (*pIndex == nIndex)
4064 *pIndex = nMoveIndex;
4070 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4075 INT nMoveIndex = (INT)lParam;
4076 TBUTTON_INFO button;
4078 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4080 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4081 if ((nIndex == -1) || (nMoveIndex < 0))
4084 if (nMoveIndex > infoPtr->nNumButtons - 1)
4085 nMoveIndex = infoPtr->nNumButtons - 1;
4087 button = infoPtr->buttons[nIndex];
4089 /* move button right */
4090 if (nIndex < nMoveIndex)
4092 nCount = nMoveIndex - nIndex;
4093 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4094 infoPtr->buttons[nMoveIndex] = button;
4096 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4097 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4098 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4099 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4101 else if (nIndex > nMoveIndex) /* move button left */
4103 nCount = nIndex - nMoveIndex;
4104 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4105 infoPtr->buttons[nMoveIndex] = button;
4107 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4108 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4109 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4110 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4113 TOOLBAR_CalcToolbar(hwnd);
4114 TOOLBAR_AutoSize(hwnd);
4115 InvalidateRect(hwnd, NULL, TRUE);
4122 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4125 TBUTTON_INFO *btnPtr;
4129 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4133 btnPtr = &infoPtr->buttons[nIndex];
4134 oldState = btnPtr->fsState;
4135 if (LOWORD(lParam) == FALSE)
4136 btnPtr->fsState &= ~TBSTATE_PRESSED;
4138 btnPtr->fsState |= TBSTATE_PRESSED;
4140 if(oldState != btnPtr->fsState)
4141 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4146 /* FIXME: there might still be some confusion her between number of buttons
4147 * and number of bitmaps */
4149 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4152 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4154 HBITMAP hbmLoad = NULL;
4155 int i = 0, nOldButtons = 0, pos = 0;
4156 int nOldBitmaps, nNewBitmaps = 0;
4157 HIMAGELIST himlDef = 0;
4159 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4160 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4161 lpReplace->nButtons);
4163 if (lpReplace->hInstOld == HINST_COMMCTRL)
4165 FIXME("changing standard bitmaps not implemented\n");
4168 else if (lpReplace->hInstOld != 0)
4169 FIXME("resources not in the current module not implemented\n");
4171 if (lpReplace->hInstNew)
4173 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4178 hBitmap = (HBITMAP) lpReplace->nIDNew;
4181 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4182 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4183 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4184 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4185 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4187 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4188 nOldButtons = tbi->nButtons;
4189 tbi->nButtons = lpReplace->nButtons;
4190 tbi->hInst = lpReplace->hInstNew;
4191 tbi->nID = lpReplace->nIDNew;
4192 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4195 pos += tbi->nButtons;
4198 if (nOldButtons == 0)
4200 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4202 DeleteObject (hbmLoad);
4206 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4207 nOldBitmaps = ImageList_GetImageCount(himlDef);
4209 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4211 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4212 ImageList_Remove(himlDef, i);
4217 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4218 HDC hdcImage, hdcBitmap;
4220 /* copy the bitmap before adding it so that the user's bitmap
4221 * doesn't get modified.
4223 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4225 hdcImage = CreateCompatibleDC(0);
4226 hdcBitmap = CreateCompatibleDC(0);
4228 /* create new bitmap */
4229 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4230 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4231 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4233 /* Copy the user's image */
4234 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4235 hdcBitmap, 0, 0, SRCCOPY);
4237 SelectObject (hdcImage, hOldBitmapLoad);
4238 SelectObject (hdcBitmap, hOldBitmapBitmap);
4239 DeleteDC (hdcImage);
4240 DeleteDC (hdcBitmap);
4242 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4243 nNewBitmaps = ImageList_GetImageCount(himlDef);
4244 DeleteObject (hbmLoad);
4247 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4249 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4250 pos, nOldBitmaps, nNewBitmaps);
4252 InvalidateRect(hwnd, NULL, TRUE);
4255 DeleteObject (hbmLoad);
4260 /* helper for TOOLBAR_SaveRestoreW */
4262 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4264 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4265 debugstr_w(lpSave->pszValueName));
4271 /* helper for TOOLBAR_Restore */
4273 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4277 for (i = 0; i < infoPtr->nNumButtons; i++)
4279 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4282 Free(infoPtr->buttons);
4283 infoPtr->buttons = NULL;
4284 infoPtr->nNumButtons = 0;
4288 /* helper for TOOLBAR_SaveRestoreW */
4290 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4299 /* restore toolbar information */
4300 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4301 debugstr_w(lpSave->pszValueName));
4303 memset(&nmtbr, 0, sizeof(nmtbr));
4305 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4306 KEY_QUERY_VALUE, &hkey);
4308 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4310 if (!res && dwType != REG_BINARY)
4311 res = ERROR_FILE_NOT_FOUND;
4314 nmtbr.pData = Alloc(dwSize);
4315 nmtbr.cbData = (UINT)dwSize;
4316 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4319 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4320 (LPBYTE)nmtbr.pData, &dwSize);
4323 nmtbr.pCurrent = nmtbr.pData;
4325 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4326 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4328 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4332 /* remove all existing buttons as this function is designed to
4333 * restore the toolbar to a previously saved state */
4334 TOOLBAR_DeleteAllButtons(infoPtr);
4336 for (i = 0; i < nmtbr.cButtons; i++)
4339 nmtbr.tbButton.iBitmap = -1;
4340 nmtbr.tbButton.fsState = 0;
4341 nmtbr.tbButton.fsStyle = 0;
4342 nmtbr.tbButton.idCommand = 0;
4343 if (*nmtbr.pCurrent == (DWORD)-1)
4346 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4347 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4349 else if (*nmtbr.pCurrent == (DWORD)-2)
4351 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4353 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4357 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4359 /* can't contain real string as we don't know whether
4360 * the client put an ANSI or Unicode string in there */
4361 if (HIWORD(nmtbr.tbButton.iString))
4362 nmtbr.tbButton.iString = 0;
4364 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4365 (LPARAM)&nmtbr.tbButton, TRUE);
4368 /* do legacy notifications */
4369 if (infoPtr->iVersion < 5)
4371 /* FIXME: send TBN_BEGINADJUST */
4372 FIXME("send TBN_GETBUTTONINFO for each button\n");
4373 /* FIXME: send TBN_ENDADJUST */
4376 /* remove all uninitialised buttons
4377 * note: loop backwards to avoid having to fixup i on a
4379 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4380 if (infoPtr->buttons[i].iBitmap == -1)
4381 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4383 /* only indicate success if at least one button survived */
4384 if (infoPtr->nNumButtons > 0) ret = TRUE;
4395 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4399 if (lpSave == NULL) return 0;
4402 return TOOLBAR_Save(infoPtr, lpSave);
4404 return TOOLBAR_Restore(infoPtr, lpSave);
4409 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4411 LPWSTR pszValueName = 0, pszSubKey = 0;
4412 TBSAVEPARAMSW SaveW;
4416 if (lpSave == NULL) return 0;
4418 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4419 pszSubKey = Alloc(len * sizeof(WCHAR));
4420 if (pszSubKey) goto exit;
4421 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4423 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4424 pszValueName = Alloc(len * sizeof(WCHAR));
4425 if (!pszValueName) goto exit;
4426 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4428 SaveW.pszValueName = pszValueName;
4429 SaveW.pszSubKey = pszSubKey;
4430 SaveW.hkr = lpSave->hkr;
4431 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4434 Free (pszValueName);
4442 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4445 BOOL bOldAnchor = infoPtr->bAnchor;
4447 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4449 infoPtr->bAnchor = (BOOL)wParam;
4451 /* Native does not remove the hot effect from an already hot button */
4453 return (LRESULT)bOldAnchor;
4458 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4460 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4461 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4463 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4466 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4468 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4469 lParam = MAKELPARAM(16, 15);
4471 if (infoPtr->nNumButtons > 0)
4472 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4473 infoPtr->nNumButtons,
4474 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4475 LOWORD(lParam), HIWORD(lParam));
4477 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4478 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4481 if ((himlDef == infoPtr->himlInt) &&
4482 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4484 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4485 infoPtr->nBitmapHeight);
4488 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4494 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4497 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4498 TBUTTON_INFO *btnPtr;
4504 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4507 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4508 lptbbi->dwMask & 0x80000000);
4512 btnPtr = &infoPtr->buttons[nIndex];
4513 if (lptbbi->dwMask & TBIF_COMMAND)
4514 btnPtr->idCommand = lptbbi->idCommand;
4515 if (lptbbi->dwMask & TBIF_IMAGE)
4516 btnPtr->iBitmap = lptbbi->iImage;
4517 if (lptbbi->dwMask & TBIF_LPARAM)
4518 btnPtr->dwData = lptbbi->lParam;
4519 if (lptbbi->dwMask & TBIF_SIZE)
4520 btnPtr->cx = lptbbi->cx;
4521 if (lptbbi->dwMask & TBIF_STATE)
4522 btnPtr->fsState = lptbbi->fsState;
4523 if (lptbbi->dwMask & TBIF_STYLE)
4524 btnPtr->fsStyle = lptbbi->fsStyle;
4526 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4527 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4528 /* iString is index, zero it to make Str_SetPtr succeed */
4531 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4534 /* save the button rect to see if we need to redraw the whole toolbar */
4535 oldBtnRect = btnPtr->rect;
4536 TOOLBAR_CalcToolbar(hwnd);
4538 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4539 InvalidateRect(hwnd, NULL, TRUE);
4541 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4548 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4551 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4552 TBUTTON_INFO *btnPtr;
4558 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4561 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4562 lptbbi->dwMask & 0x80000000);
4566 btnPtr = &infoPtr->buttons[nIndex];
4567 if (lptbbi->dwMask & TBIF_COMMAND)
4568 btnPtr->idCommand = lptbbi->idCommand;
4569 if (lptbbi->dwMask & TBIF_IMAGE)
4570 btnPtr->iBitmap = lptbbi->iImage;
4571 if (lptbbi->dwMask & TBIF_LPARAM)
4572 btnPtr->dwData = lptbbi->lParam;
4573 if (lptbbi->dwMask & TBIF_SIZE)
4574 btnPtr->cx = lptbbi->cx;
4575 if (lptbbi->dwMask & TBIF_STATE)
4576 btnPtr->fsState = lptbbi->fsState;
4577 if (lptbbi->dwMask & TBIF_STYLE)
4578 btnPtr->fsStyle = lptbbi->fsStyle;
4580 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4581 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4582 /* iString is index, zero it to make Str_SetPtr succeed */
4584 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4587 /* save the button rect to see if we need to redraw the whole toolbar */
4588 oldBtnRect = btnPtr->rect;
4589 TOOLBAR_CalcToolbar(hwnd);
4591 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4592 InvalidateRect(hwnd, NULL, TRUE);
4594 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4601 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4604 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4606 if ((cx < 0) || (cy < 0))
4608 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4612 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4614 /* The documentation claims you can only change the button size before
4615 * any button has been added. But this is wrong.
4616 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4617 * it to the toolbar, and it checks that the return value is nonzero - mjm
4618 * Further testing shows that we must actually perform the change too.
4621 * The documentation also does not mention that if 0 is supplied for
4622 * either size, the system changes it to the default of 24 wide and
4623 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4625 infoPtr->nButtonWidth = (cx) ? cx : 24;
4626 infoPtr->nButtonHeight = (cy) ? cy : 22;
4632 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4636 /* if setting to current values, ignore */
4637 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4638 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4639 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4640 infoPtr->cxMin, infoPtr->cxMax);
4644 /* save new values */
4645 infoPtr->cxMin = (INT)LOWORD(lParam);
4646 infoPtr->cxMax = (INT)HIWORD(lParam);
4648 /* otherwise we need to recalc the toolbar and in some cases
4649 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4650 which doesn't actually draw - GA). */
4651 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4652 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4654 TOOLBAR_CalcToolbar (hwnd);
4656 InvalidateRect (hwnd, NULL, TRUE);
4663 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4665 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4666 INT nIndex = (INT)wParam;
4668 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4671 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4673 if (infoPtr->hwndToolTip) {
4675 FIXME("change tool tip!\n");
4684 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4687 HIMAGELIST himl = (HIMAGELIST)lParam;
4688 HIMAGELIST himlTemp;
4691 if (infoPtr->iVersion >= 5)
4694 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4695 &infoPtr->cimlDis, himl, id);
4697 /* FIXME: redraw ? */
4699 return (LRESULT)himlTemp;
4704 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4709 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4711 dwTemp = infoPtr->dwDTFlags;
4712 infoPtr->dwDTFlags =
4713 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4715 return (LRESULT)dwTemp;
4718 /* This function differs a bit from what MSDN says it does:
4719 * 1. lParam contains extended style flags to OR with current style
4720 * (MSDN isn't clear on the OR bit)
4721 * 2. wParam appears to contain extended style flags to be reset
4722 * (MSDN says that this parameter is reserved)
4725 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4730 dwTemp = infoPtr->dwExStyle;
4731 infoPtr->dwExStyle &= ~wParam;
4732 infoPtr->dwExStyle |= (DWORD)lParam;
4734 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4736 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4737 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4738 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4740 TOOLBAR_CalcToolbar (hwnd);
4742 TOOLBAR_AutoSize(hwnd);
4744 InvalidateRect(hwnd, NULL, TRUE);
4746 return (LRESULT)dwTemp;
4751 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4754 HIMAGELIST himlTemp;
4755 HIMAGELIST himl = (HIMAGELIST)lParam;
4758 if (infoPtr->iVersion >= 5)
4761 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4763 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4764 &infoPtr->cimlHot, himl, id);
4766 /* FIXME: redraw ? */
4768 return (LRESULT)himlTemp;
4772 /* Makes previous hot button no longer hot, makes the specified
4773 * button hot and sends appropriate notifications. dwReason is one or
4774 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4775 * NOTE 1: this function does not validate nHit
4776 * NOTE 2: the name of this function is completely made up and
4777 * not based on any documentation from Microsoft. */
4779 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4781 if (infoPtr->nHotItem != nHit)
4783 NMTBHOTITEM nmhotitem;
4784 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4786 if(infoPtr->nHotItem >= 0)
4788 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4789 nmhotitem.idOld = oldBtnPtr->idCommand;
4792 nmhotitem.dwFlags |= HICF_ENTERING;
4796 btnPtr = &infoPtr->buttons[nHit];
4797 nmhotitem.idNew = btnPtr->idCommand;
4798 /* setting disabled buttons as hot fails */
4799 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4803 nmhotitem.dwFlags |= HICF_LEAVING;
4805 nmhotitem.dwFlags = dwReason;
4807 /* now change the hot and invalidate the old and new buttons - if the
4809 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4811 infoPtr->nHotItem = nHit;
4813 btnPtr->bHot = TRUE;
4814 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4817 oldBtnPtr->bHot = FALSE;
4818 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4825 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4828 INT nOldHotItem = infoPtr->nHotItem;
4830 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4832 if ((INT)wParam > infoPtr->nNumButtons)
4833 return infoPtr->nHotItem;
4835 if ((INT)wParam < 0)
4838 /* NOTE: an application can still remove the hot item even if anchor
4839 * highlighting is enabled */
4841 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4843 if (nOldHotItem < 0)
4846 return (LRESULT)nOldHotItem;
4851 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4854 HIMAGELIST himlTemp;
4855 HIMAGELIST himl = (HIMAGELIST)lParam;
4858 if (infoPtr->iVersion >= 5)
4861 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4862 &infoPtr->cimlDef, himl, id);
4864 infoPtr->nNumBitmaps = 0;
4865 for (i = 0; i < infoPtr->cimlDef; i++)
4866 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4868 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4869 &infoPtr->nBitmapHeight))
4871 infoPtr->nBitmapWidth = 1;
4872 infoPtr->nBitmapHeight = 1;
4875 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4876 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4877 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4879 InvalidateRect(hwnd, NULL, TRUE);
4881 return (LRESULT)himlTemp;
4886 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4890 infoPtr->nIndent = (INT)wParam;
4894 /* process only on indent changing */
4895 if(infoPtr->nIndent != (INT)wParam)
4897 infoPtr->nIndent = (INT)wParam;
4898 TOOLBAR_CalcToolbar (hwnd);
4899 InvalidateRect(hwnd, NULL, FALSE);
4907 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4910 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4912 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4914 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4916 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4920 if ((lptbim->iButton == -1) ||
4921 ((lptbim->iButton < infoPtr->nNumButtons) &&
4922 (lptbim->iButton >= 0)))
4924 infoPtr->tbim = *lptbim;
4925 /* FIXME: don't need to update entire toolbar */
4926 InvalidateRect(hwnd, NULL, TRUE);
4929 ERR("Invalid button index %d\n", lptbim->iButton);
4936 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4938 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4940 infoPtr->clrInsertMark = (COLORREF)lParam;
4942 /* FIXME: don't need to update entire toolbar */
4943 InvalidateRect(hwnd, NULL, TRUE);
4950 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4952 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4954 infoPtr->nMaxTextRows = (INT)wParam;
4956 TOOLBAR_CalcToolbar(hwnd);
4961 /* MSDN gives slightly wrong info on padding.
4962 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4963 * 2. It is not used to create a blank area between the edge of the button
4964 * and the text or image if TBSTYLE_LIST is set. It is used to control
4965 * the gap between the image and text.
4966 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4967 * to control the bottom and right borders [with the border being
4968 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4969 * is shared evenly on both sides of the button.
4970 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4973 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4978 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4979 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4980 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4981 TRACE("cx=%d, cy=%d\n",
4982 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4983 return (LRESULT) oldPad;
4988 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4990 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4995 hwndOldNotify = infoPtr->hwndNotify;
4996 infoPtr->hwndNotify = (HWND)wParam;
4998 return (LRESULT)hwndOldNotify;
5003 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5006 LPRECT lprc = (LPRECT)lParam;
5010 if (LOWORD(wParam) > 1) {
5011 FIXME("multiple rows not supported!\n");
5014 if(infoPtr->nRows != LOWORD(wParam))
5016 infoPtr->nRows = LOWORD(wParam);
5018 /* recalculate toolbar */
5019 TOOLBAR_CalcToolbar (hwnd);
5021 /* repaint toolbar */
5022 InvalidateRect(hwnd, NULL, TRUE);
5025 /* return bounding rectangle */
5027 lprc->left = infoPtr->rcBound.left;
5028 lprc->right = infoPtr->rcBound.right;
5029 lprc->top = infoPtr->rcBound.top;
5030 lprc->bottom = infoPtr->rcBound.bottom;
5038 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5040 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5041 TBUTTON_INFO *btnPtr;
5044 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5048 btnPtr = &infoPtr->buttons[nIndex];
5050 /* if hidden state has changed the invalidate entire window and recalc */
5051 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5052 btnPtr->fsState = LOWORD(lParam);
5053 TOOLBAR_CalcToolbar (hwnd);
5054 InvalidateRect(hwnd, 0, TRUE);
5058 /* process state changing if current state doesn't match new state */
5059 if(btnPtr->fsState != LOWORD(lParam))
5061 btnPtr->fsState = LOWORD(lParam);
5062 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5070 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5072 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5078 inline static LRESULT
5079 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5083 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5085 infoPtr->hwndToolTip = (HWND)wParam;
5091 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5093 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5096 TRACE("%s hwnd=%p\n",
5097 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5099 bTemp = infoPtr->bUnicode;
5100 infoPtr->bUnicode = (BOOL)wParam;
5107 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5109 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5111 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5112 comctl32_color.clrBtnHighlight :
5113 infoPtr->clrBtnHighlight;
5114 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5115 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5121 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5123 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5125 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5126 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5127 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5129 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5130 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5131 InvalidateRect(hwnd, NULL, TRUE);
5137 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5139 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 INT iOldVersion = infoPtr->iVersion;
5142 infoPtr->iVersion = iVersion;
5144 if (infoPtr->iVersion >= 5)
5145 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5152 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5155 WORD iString = HIWORD(wParam);
5156 WORD buffersize = LOWORD(wParam);
5157 LPSTR str = (LPSTR)lParam;
5160 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5162 if (iString < infoPtr->nNumStrings)
5164 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5166 TRACE("returning %s\n", debugstr_a(str));
5169 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5176 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5179 WORD iString = HIWORD(wParam);
5180 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5181 LPWSTR str = (LPWSTR)lParam;
5184 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5186 if (iString < infoPtr->nNumStrings)
5188 len = min(len, strlenW(infoPtr->strings[iString]));
5189 ret = (len+1)*sizeof(WCHAR);
5190 memcpy(str, infoPtr->strings[iString], ret);
5193 TRACE("returning %s\n", debugstr_w(str));
5196 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5201 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5202 * is the maximum size of the toolbar? */
5203 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5205 SIZE * pSize = (SIZE*)lParam;
5206 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5211 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5212 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5213 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5216 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5218 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5219 INT nOldHotItem = infoPtr->nHotItem;
5221 TRACE("old item=%d, new item=%d, flags=%08x\n",
5222 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5224 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5227 /* NOTE: an application can still remove the hot item even if anchor
5228 * highlighting is enabled */
5230 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5234 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5237 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5238 * which controls the amount of spacing between the image and the text
5239 * of buttons for TBSTYLE_LIST toolbars. */
5240 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5244 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5247 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5249 infoPtr->iListGap = (INT)wParam;
5251 InvalidateRect(hwnd, NULL, TRUE);
5256 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5257 * of image lists associated with the various states. */
5258 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5260 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5262 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5264 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5268 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5271 LPSIZE lpsize = (LPSIZE)lParam;
5277 * Testing shows the following:
5278 * wParam = 0 adjust cx value
5279 * = 1 set cy value to max size.
5280 * lParam pointer to SIZE structure
5283 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5284 wParam, lParam, lpsize->cx, lpsize->cy);
5288 if (lpsize->cx == -1) {
5289 /* **** this is wrong, native measures each button and sets it */
5290 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5292 else if(HIWORD(lpsize->cx)) {
5294 HWND hwndParent = GetParent(hwnd);
5296 GetWindowRect(hwnd, &rc);
5297 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5298 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5299 rc.left, rc.top, rc.right, rc.bottom);
5300 lpsize->cx = max(rc.right-rc.left,
5301 infoPtr->rcBound.right - infoPtr->rcBound.left);
5304 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5308 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5311 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5315 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5316 lpsize->cx, lpsize->cy);
5320 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5322 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5324 InvalidateRect(hwnd, NULL, TRUE);
5330 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5332 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5333 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5336 TRACE("hwnd = %p\n", hwnd);
5338 /* initialize info structure */
5339 infoPtr->nButtonHeight = 22;
5340 infoPtr->nButtonWidth = 24;
5341 infoPtr->nBitmapHeight = 15;
5342 infoPtr->nBitmapWidth = 16;
5344 infoPtr->nMaxTextRows = 1;
5345 infoPtr->cxMin = -1;
5346 infoPtr->cxMax = -1;
5347 infoPtr->nNumBitmaps = 0;
5348 infoPtr->nNumStrings = 0;
5350 infoPtr->bCaptured = FALSE;
5351 infoPtr->nButtonDown = -1;
5352 infoPtr->nButtonDrag = -1;
5353 infoPtr->nOldHit = -1;
5354 infoPtr->nHotItem = -1;
5355 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5356 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5357 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5358 infoPtr->bDragOutSent = FALSE;
5359 infoPtr->iVersion = 0;
5360 infoPtr->hwndSelf = hwnd;
5361 infoPtr->bDoRedraw = TRUE;
5362 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5363 infoPtr->clrBtnShadow = CLR_DEFAULT;
5364 infoPtr->szPadding.cx = DEFPAD_CX;
5365 infoPtr->szPadding.cy = DEFPAD_CY;
5366 infoPtr->iListGap = DEFLISTGAP;
5367 infoPtr->dwStyle = dwStyle;
5368 infoPtr->tbim.iButton = -1;
5369 GetClientRect(hwnd, &infoPtr->client_rect);
5370 infoPtr->bUnicode = infoPtr->hwndNotify &&
5371 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5372 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5374 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5375 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5377 OpenThemeData (hwnd, themeClass);
5379 TOOLBAR_CheckStyle (hwnd, dwStyle);
5381 TOOLBAR_CalcToolbar(hwnd);
5388 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5392 /* delete tooltip control */
5393 if (infoPtr->hwndToolTip)
5394 DestroyWindow (infoPtr->hwndToolTip);
5396 /* delete temporary buffer for tooltip text */
5397 Free (infoPtr->pszTooltipText);
5398 Free (infoPtr->bitmaps); /* bitmaps list */
5400 /* delete button data */
5401 if (infoPtr->buttons)
5402 Free (infoPtr->buttons);
5404 /* delete strings */
5405 if (infoPtr->strings) {
5407 for (i = 0; i < infoPtr->nNumStrings; i++)
5408 if (infoPtr->strings[i])
5409 Free (infoPtr->strings[i]);
5411 Free (infoPtr->strings);
5414 /* destroy internal image list */
5415 if (infoPtr->himlInt)
5416 ImageList_Destroy (infoPtr->himlInt);
5418 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5419 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5420 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5422 /* delete default font */
5424 DeleteObject (infoPtr->hDefaultFont);
5426 CloseThemeData (GetWindowTheme (hwnd));
5428 /* free toolbar info data */
5430 SetWindowLongPtrW (hwnd, 0, 0);
5437 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5440 NMTBCUSTOMDRAW tbcd;
5443 HTHEME theme = GetWindowTheme (hwnd);
5444 DWORD dwEraseCustDraw = 0;
5446 /* the app has told us not to redraw the toolbar */
5447 if (!infoPtr->bDoRedraw)
5450 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5451 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5452 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5453 tbcd.nmcd.hdc = (HDC)wParam;
5454 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5455 dwEraseCustDraw = ntfret & 0xffff;
5457 /* FIXME: in general the return flags *can* be or'ed together */
5458 switch (dwEraseCustDraw)
5460 case CDRF_DODEFAULT:
5462 case CDRF_SKIPDEFAULT:
5465 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5470 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5471 * to my parent for processing.
5473 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5475 HDC hdc = (HDC)wParam;
5480 parent = GetParent(hwnd);
5481 MapWindowPoints(hwnd, parent, &pt, 1);
5482 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5483 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5484 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5487 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5489 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5490 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5491 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5492 tbcd.nmcd.hdc = (HDC)wParam;
5493 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5494 dwEraseCustDraw = ntfret & 0xffff;
5495 switch (dwEraseCustDraw)
5497 case CDRF_DODEFAULT:
5499 case CDRF_SKIPDEFAULT:
5502 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5511 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5515 return (LRESULT)infoPtr->hFont;
5520 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5523 INT nNewHotItem = infoPtr->nHotItem;
5525 for (i = 0; i < infoPtr->nNumButtons; i++)
5528 if ((nNewHotItem + iDirection < 0) ||
5529 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5531 NMTBWRAPHOTITEM nmtbwhi;
5532 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5533 nmtbwhi.iDirection = iDirection;
5534 nmtbwhi.dwReason = dwReason;
5536 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5540 nNewHotItem += iDirection;
5541 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5543 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5544 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5546 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5553 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5555 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5558 nmkey.nVKey = (UINT)wParam;
5559 nmkey.uFlags = HIWORD(lParam);
5561 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5562 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5564 switch ((UINT)wParam)
5568 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5572 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5576 if ((infoPtr->nHotItem >= 0) &&
5577 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5579 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5580 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5591 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5596 pt.x = (INT)LOWORD(lParam);
5597 pt.y = (INT)HIWORD(lParam);
5598 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5601 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5602 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5603 TOOLBAR_Customize (hwnd);
5610 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5613 TBUTTON_INFO *btnPtr;
5618 BOOL bDragKeyPressed;
5622 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5623 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5625 bDragKeyPressed = (wParam & MK_SHIFT);
5627 if (infoPtr->hwndToolTip)
5628 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5629 WM_LBUTTONDOWN, wParam, lParam);
5631 pt.x = (INT)LOWORD(lParam);
5632 pt.y = (INT)HIWORD(lParam);
5633 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5635 btnPtr = &infoPtr->buttons[nHit];
5637 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5639 infoPtr->nButtonDrag = nHit;
5642 /* If drag cursor has not been loaded, load it.
5643 * Note: it doesn't need to be freed */
5645 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5646 SetCursor(hCursorDrag);
5651 infoPtr->nOldHit = nHit;
5653 CopyRect(&arrowRect, &btnPtr->rect);
5654 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5656 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5657 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5658 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5659 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5660 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5661 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5665 /* draw in pressed state */
5666 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5667 btnPtr->fsState |= TBSTATE_PRESSED;
5669 btnPtr->bDropDownPressed = TRUE;
5670 RedrawWindow(hwnd,&btnPtr->rect,0,
5671 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5673 memset(&nmtb, 0, sizeof(nmtb));
5674 nmtb.iItem = btnPtr->idCommand;
5675 nmtb.rcButton = btnPtr->rect;
5676 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5678 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5680 if (res != TBDDRET_TREATPRESSED)
5684 /* redraw button in unpressed state */
5685 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5686 btnPtr->fsState &= ~TBSTATE_PRESSED;
5688 btnPtr->bDropDownPressed = FALSE;
5689 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5691 /* find and set hot item
5692 * NOTE: native doesn't do this, but that is a bug */
5694 ScreenToClient(hwnd, &pt);
5695 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5696 if (!infoPtr->bAnchor || (nHit >= 0))
5697 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5699 /* remove any left mouse button down or double-click messages
5700 * so that we can get a toggle effect on the button */
5701 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5702 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5707 /* otherwise drop through and process as pushed */
5709 infoPtr->bCaptured = TRUE;
5710 infoPtr->nButtonDown = nHit;
5711 infoPtr->bDragOutSent = FALSE;
5713 btnPtr->fsState |= TBSTATE_PRESSED;
5715 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5717 if (btnPtr->fsState & TBSTATE_ENABLED)
5718 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5725 memset(&nmtb, 0, sizeof(nmtb));
5726 nmtb.iItem = btnPtr->idCommand;
5727 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5730 nmmouse.dwHitInfo = nHit;
5732 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5734 nmmouse.dwItemSpec = -1;
5737 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5738 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5741 ClientToScreen(hwnd, &pt);
5744 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5745 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5751 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5754 TBUTTON_INFO *btnPtr;
5758 BOOL bSendMessage = TRUE;
5763 if (infoPtr->hwndToolTip)
5764 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5765 WM_LBUTTONUP, wParam, lParam);
5767 pt.x = (INT)LOWORD(lParam);
5768 pt.y = (INT)HIWORD(lParam);
5769 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5771 if (!infoPtr->bAnchor || (nHit >= 0))
5772 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5774 if (infoPtr->nButtonDrag >= 0) {
5778 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5781 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5783 GetClientRect(hwnd, &rcClient);
5784 if (PtInRect(&rcClient, pt))
5791 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5794 if (nButton == infoPtr->nButtonDrag)
5796 /* if the button is moved sightly left and we have a
5797 * separator there then remove it */
5798 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5800 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5801 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5803 else /* else insert a separator before the dragged button */
5806 memset(&tbb, 0, sizeof(tbb));
5807 tbb.fsStyle = BTNS_SEP;
5809 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5816 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5817 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5819 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5822 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5827 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5828 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5831 /* button under cursor changed so need to re-set hot item */
5832 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5833 infoPtr->nButtonDrag = -1;
5835 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5837 else if (infoPtr->nButtonDown >= 0) {
5838 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5839 btnPtr->fsState &= ~TBSTATE_PRESSED;
5841 if (btnPtr->fsStyle & BTNS_CHECK) {
5842 if (btnPtr->fsStyle & BTNS_GROUP) {
5843 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5845 if (nOldIndex == nHit)
5846 bSendMessage = FALSE;
5847 if ((nOldIndex != nHit) &&
5849 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5850 btnPtr->fsState |= TBSTATE_CHECKED;
5853 if (btnPtr->fsState & TBSTATE_CHECKED)
5854 btnPtr->fsState &= ~TBSTATE_CHECKED;
5856 btnPtr->fsState |= TBSTATE_CHECKED;
5860 if (nOldIndex != -1)
5861 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5864 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5865 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5866 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5868 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5870 infoPtr->nButtonDown = -1;
5872 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5873 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5874 NM_RELEASEDCAPTURE);
5876 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5879 memset(&nmtb, 0, sizeof(nmtb));
5880 nmtb.iItem = btnPtr->idCommand;
5881 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5884 if (btnPtr->fsState & TBSTATE_ENABLED)
5886 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5887 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5891 /* !!! Undocumented - toolbar at 4.71 level and above sends
5892 * NM_CLICK with the NMMOUSE structure. */
5893 nmmouse.dwHitInfo = nHit;
5896 nmmouse.dwItemSpec = -1;
5899 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5900 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5903 ClientToScreen(hwnd, &pt);
5906 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5907 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5913 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5920 pt.x = LOWORD(lParam);
5921 pt.y = HIWORD(lParam);
5923 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5924 nmmouse.dwHitInfo = nHit;
5927 nmmouse.dwItemSpec = -1;
5929 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5930 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5933 ClientToScreen(hwnd, &pt);
5936 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5937 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5943 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5948 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5949 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5955 TOOLBAR_CaptureChanged(HWND hwnd)
5957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5958 TBUTTON_INFO *btnPtr;
5960 infoPtr->bCaptured = FALSE;
5962 if (infoPtr->nButtonDown >= 0)
5964 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5965 btnPtr->fsState &= ~TBSTATE_PRESSED;
5967 infoPtr->nOldHit = -1;
5969 if (btnPtr->fsState & TBSTATE_ENABLED)
5970 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5976 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5980 /* don't remove hot effects when in anchor highlighting mode or when a
5981 * drop-down button is pressed */
5982 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5984 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5985 if (!hotBtnPtr->bDropDownPressed)
5986 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5989 if (infoPtr->nOldHit < 0)
5992 /* If the last button we were over is depressed then make it not */
5993 /* depressed and redraw it */
5994 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5996 TBUTTON_INFO *btnPtr;
5999 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6001 btnPtr->fsState &= ~TBSTATE_PRESSED;
6004 InflateRect (&rc1, 1, 1);
6005 InvalidateRect (hwnd, &rc1, TRUE);
6008 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6011 ZeroMemory(&nmt, sizeof(nmt));
6012 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6013 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6014 infoPtr->bDragOutSent = TRUE;
6017 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6023 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6027 TRACKMOUSEEVENT trackinfo;
6029 TBUTTON_INFO *btnPtr;
6031 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6032 TOOLBAR_TooltipCreateControl(infoPtr);
6034 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6035 /* fill in the TRACKMOUSEEVENT struct */
6036 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6037 trackinfo.dwFlags = TME_QUERY;
6039 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6040 _TrackMouseEvent(&trackinfo);
6042 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6043 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6044 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6045 trackinfo.hwndTrack = hwnd;
6047 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6048 /* and can properly deactivate the hot toolbar button */
6049 _TrackMouseEvent(&trackinfo);
6053 if (infoPtr->hwndToolTip)
6054 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6055 WM_MOUSEMOVE, wParam, lParam);
6057 pt.x = (INT)LOWORD(lParam);
6058 pt.y = (INT)HIWORD(lParam);
6060 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6062 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6063 && (!infoPtr->bAnchor || (nHit >= 0)))
6064 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6066 if (infoPtr->nOldHit != nHit)
6068 if (infoPtr->bCaptured)
6070 if (!infoPtr->bDragOutSent)
6073 ZeroMemory(&nmt, sizeof(nmt));
6074 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6075 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6076 infoPtr->bDragOutSent = TRUE;
6079 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6080 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6081 btnPtr->fsState &= ~TBSTATE_PRESSED;
6082 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6084 else if (nHit == infoPtr->nButtonDown) {
6085 btnPtr->fsState |= TBSTATE_PRESSED;
6086 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6088 infoPtr->nOldHit = nHit;
6096 inline static LRESULT
6097 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6099 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6100 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6102 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6106 inline static LRESULT
6107 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6109 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6110 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6112 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6117 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6119 TOOLBAR_INFO *infoPtr;
6120 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6123 /* allocate memory for info structure */
6124 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6125 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6128 infoPtr->dwStructSize = sizeof(TBBUTTON);
6130 infoPtr->nWidth = 0;
6132 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6133 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6134 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6135 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6138 /* native control does:
6139 * Get a lot of colors and brushes
6141 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6142 * CreateFontIndirectW(adr1)
6143 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6144 * hdc = GetDC(toolbar)
6145 * GetSystemMetrics(0x48)
6146 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6147 * 0, 0, 0, 0, "MARLETT")
6148 * oldfnt = SelectObject(hdc, fnt2)
6149 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6150 * GetTextMetricsW(hdc, adr3)
6151 * SelectObject(hdc, oldfnt)
6152 * DeleteObject(fnt2)
6154 * InvalidateRect(toolbar, 0, 1)
6155 * SetWindowLongW(toolbar, 0, addr)
6156 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6159 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6160 * ie 2 0x4600094c 0x4600094c 0x4600894d
6161 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6162 * rebar 0x50008844 0x40008844 0x50008845
6163 * pager 0x50000844 0x40000844 0x50008845
6164 * IC35mgr 0x5400084e **nochange**
6165 * on entry to _NCCREATE 0x5400084e
6166 * rowlist 0x5400004e **nochange**
6167 * on entry to _NCCREATE 0x5400004e
6171 /* I think the code below is a bug, but it is the way that the native
6172 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6173 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6174 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6175 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6176 * Somehow, the only cases of this seem to be MFC programs.
6178 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6179 * does not occur in the WM_STYLECHANGING routine.
6180 * (Guy Albertelli 9/2001)
6183 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6184 && !(cs->style & TBSTYLE_TRANSPARENT))
6185 styleadd |= TBSTYLE_TRANSPARENT;
6186 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6187 styleadd |= CCS_TOP; /* default to top */
6188 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6191 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6196 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6198 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6202 if (dwStyle & WS_MINIMIZE)
6203 return 0; /* Nothing to do */
6205 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6207 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6210 if (!(dwStyle & CCS_NODIVIDER))
6212 GetWindowRect (hwnd, &rcWindow);
6213 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6214 if( dwStyle & WS_BORDER )
6215 OffsetRect (&rcWindow, 1, 1);
6216 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6219 ReleaseDC( hwnd, hdc );
6225 /* handles requests from the tooltip control on what text to display */
6226 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6228 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6230 TRACE("button index = %d\n", index);
6232 Free (infoPtr->pszTooltipText);
6233 infoPtr->pszTooltipText = NULL;
6238 if (infoPtr->bUnicode)
6240 WCHAR wszBuffer[INFOTIPSIZE+1];
6241 NMTBGETINFOTIPW tbgit;
6242 unsigned int len; /* in chars */
6244 wszBuffer[0] = '\0';
6245 wszBuffer[INFOTIPSIZE] = '\0';
6247 tbgit.pszText = wszBuffer;
6248 tbgit.cchTextMax = INFOTIPSIZE;
6249 tbgit.iItem = lpnmtdi->hdr.idFrom;
6250 tbgit.lParam = infoPtr->buttons[index].dwData;
6252 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6254 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6256 len = strlenW(tbgit.pszText);
6257 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6259 /* need to allocate temporary buffer in infoPtr as there
6260 * isn't enough space in buffer passed to us by the
6261 * tooltip control */
6262 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6263 if (infoPtr->pszTooltipText)
6265 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6266 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6272 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6278 CHAR szBuffer[INFOTIPSIZE+1];
6279 NMTBGETINFOTIPA tbgit;
6280 unsigned int len; /* in chars */
6283 szBuffer[INFOTIPSIZE] = '\0';
6285 tbgit.pszText = szBuffer;
6286 tbgit.cchTextMax = INFOTIPSIZE;
6287 tbgit.iItem = lpnmtdi->hdr.idFrom;
6288 tbgit.lParam = infoPtr->buttons[index].dwData;
6290 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6292 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6294 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6295 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6297 /* need to allocate temporary buffer in infoPtr as there
6298 * isn't enough space in buffer passed to us by the
6299 * tooltip control */
6300 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6301 if (infoPtr->pszTooltipText)
6303 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6304 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6310 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6311 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6316 /* if button has text, but it is not shown then automatically
6317 * use that text as tooltip */
6318 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6319 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6321 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6322 unsigned int len = pszText ? strlenW(pszText) : 0;
6324 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6326 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6328 /* need to allocate temporary buffer in infoPtr as there
6329 * isn't enough space in buffer passed to us by the
6330 * tooltip control */
6331 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6332 if (infoPtr->pszTooltipText)
6334 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6335 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6341 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6346 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6348 /* last resort: send notification on to app */
6349 /* FIXME: find out what is really used here */
6350 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6354 inline static LRESULT
6355 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6357 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6358 LPNMHDR lpnmh = (LPNMHDR)lParam;
6360 switch (lpnmh->code)
6364 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6366 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6367 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6368 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6372 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6373 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6381 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6383 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6384 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6385 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6386 lppgs->iScroll, lppgs->iDir);
6390 case TTN_GETDISPINFOW:
6391 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6393 case TTN_GETDISPINFOA:
6394 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6404 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6408 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6410 if (lParam == NF_QUERY)
6413 if (lParam == NF_REQUERY) {
6414 format = SendMessageW(infoPtr->hwndNotify,
6415 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6416 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6417 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6428 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6430 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6434 /* fill ps.rcPaint with a default rect */
6435 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6437 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6439 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6440 ps.rcPaint.left, ps.rcPaint.top,
6441 ps.rcPaint.right, ps.rcPaint.bottom);
6443 TOOLBAR_Refresh (hwnd, hdc, &ps);
6444 if (!wParam) EndPaint (hwnd, &ps);
6451 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6455 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6457 /* make first item hot */
6458 if (infoPtr->nNumButtons > 0)
6459 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6466 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6467 /*****************************************************
6470 * Handles the WM_SETREDRAW message.
6473 * According to testing V4.71 of COMCTL32 returns the
6474 * *previous* status of the redraw flag (either 0 or 1)
6475 * instead of the MSDN documented value of 0 if handled.
6476 * (For laughs see the "consistency" with same function
6479 *****************************************************/
6481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6482 BOOL oldredraw = infoPtr->bDoRedraw;
6484 TRACE("set to %s\n",
6485 (wParam) ? "TRUE" : "FALSE");
6486 infoPtr->bDoRedraw = (BOOL) wParam;
6488 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6490 return (oldredraw) ? 1 : 0;
6495 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6497 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6499 TRACE("sizing toolbar!\n");
6501 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6503 RECT delta_width, delta_height, client, dummy;
6504 DWORD min_x, max_x, min_y, max_y;
6505 TBUTTON_INFO *btnPtr;
6508 GetClientRect(hwnd, &client);
6509 if(client.right > infoPtr->client_rect.right)
6511 min_x = infoPtr->client_rect.right;
6512 max_x = client.right;
6516 max_x = infoPtr->client_rect.right;
6517 min_x = client.right;
6519 if(client.bottom > infoPtr->client_rect.bottom)
6521 min_y = infoPtr->client_rect.bottom;
6522 max_y = client.bottom;
6526 max_y = infoPtr->client_rect.bottom;
6527 min_y = client.bottom;
6530 SetRect(&delta_width, min_x, 0, max_x, min_y);
6531 SetRect(&delta_height, 0, min_y, max_x, max_y);
6533 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6534 btnPtr = infoPtr->buttons;
6535 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6536 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6537 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6538 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6540 GetClientRect(hwnd, &infoPtr->client_rect);
6541 TOOLBAR_AutoSize(hwnd);
6547 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6549 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6551 if (nType == GWL_STYLE)
6553 DWORD dwOldStyle = infoPtr->dwStyle;
6555 if (lpStyle->styleNew & TBSTYLE_LIST)
6556 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6558 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6560 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6562 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6564 infoPtr->dwStyle = lpStyle->styleNew;
6566 /* only resize if one of the CCS_* styles was changed */
6567 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6569 TOOLBAR_AutoSize (hwnd);
6571 InvalidateRect(hwnd, NULL, TRUE);
6580 TOOLBAR_SysColorChange (HWND hwnd)
6582 COMCTL32_RefreshSysColors();
6588 /* update theme after a WM_THEMECHANGED message */
6589 static LRESULT theme_changed (HWND hwnd)
6591 HTHEME theme = GetWindowTheme (hwnd);
6592 CloseThemeData (theme);
6593 OpenThemeData (hwnd, themeClass);
6598 static LRESULT WINAPI
6599 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6603 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6604 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6606 if (!infoPtr && (uMsg != WM_NCCREATE))
6607 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6612 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6614 case TB_ADDBUTTONSA:
6615 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6617 case TB_ADDBUTTONSW:
6618 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6621 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6624 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6627 return TOOLBAR_AutoSize (hwnd);
6629 case TB_BUTTONCOUNT:
6630 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6632 case TB_BUTTONSTRUCTSIZE:
6633 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6635 case TB_CHANGEBITMAP:
6636 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6638 case TB_CHECKBUTTON:
6639 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6641 case TB_COMMANDTOINDEX:
6642 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6645 return TOOLBAR_Customize (hwnd);
6647 case TB_DELETEBUTTON:
6648 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6650 case TB_ENABLEBUTTON:
6651 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6653 case TB_GETANCHORHIGHLIGHT:
6654 return TOOLBAR_GetAnchorHighlight (hwnd);
6657 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6659 case TB_GETBITMAPFLAGS:
6660 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6663 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6665 case TB_GETBUTTONINFOA:
6666 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6668 case TB_GETBUTTONINFOW:
6669 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6671 case TB_GETBUTTONSIZE:
6672 return TOOLBAR_GetButtonSize (hwnd);
6674 case TB_GETBUTTONTEXTA:
6675 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6677 case TB_GETBUTTONTEXTW:
6678 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6680 case TB_GETDISABLEDIMAGELIST:
6681 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6683 case TB_GETEXTENDEDSTYLE:
6684 return TOOLBAR_GetExtendedStyle (hwnd);
6686 case TB_GETHOTIMAGELIST:
6687 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6690 return TOOLBAR_GetHotItem (hwnd);
6692 case TB_GETIMAGELIST:
6693 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6695 case TB_GETINSERTMARK:
6696 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6698 case TB_GETINSERTMARKCOLOR:
6699 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6701 case TB_GETITEMRECT:
6702 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6705 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6707 /* case TB_GETOBJECT: */ /* 4.71 */
6710 return TOOLBAR_GetPadding (hwnd);
6713 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6716 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6719 return TOOLBAR_GetState (hwnd, wParam, lParam);
6722 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6725 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6728 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6730 case TB_GETTEXTROWS:
6731 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6733 case TB_GETTOOLTIPS:
6734 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6736 case TB_GETUNICODEFORMAT:
6737 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6740 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6743 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6745 case TB_INDETERMINATE:
6746 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6748 case TB_INSERTBUTTONA:
6749 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6751 case TB_INSERTBUTTONW:
6752 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6754 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6756 case TB_ISBUTTONCHECKED:
6757 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6759 case TB_ISBUTTONENABLED:
6760 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6762 case TB_ISBUTTONHIDDEN:
6763 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6765 case TB_ISBUTTONHIGHLIGHTED:
6766 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6768 case TB_ISBUTTONINDETERMINATE:
6769 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6771 case TB_ISBUTTONPRESSED:
6772 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6775 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6777 case TB_MAPACCELERATORA:
6778 case TB_MAPACCELERATORW:
6779 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6782 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6785 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6787 case TB_PRESSBUTTON:
6788 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6790 case TB_REPLACEBITMAP:
6791 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6793 case TB_SAVERESTOREA:
6794 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6796 case TB_SAVERESTOREW:
6797 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6799 case TB_SETANCHORHIGHLIGHT:
6800 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6802 case TB_SETBITMAPSIZE:
6803 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6805 case TB_SETBUTTONINFOA:
6806 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6808 case TB_SETBUTTONINFOW:
6809 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6811 case TB_SETBUTTONSIZE:
6812 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6814 case TB_SETBUTTONWIDTH:
6815 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6818 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6820 case TB_SETDISABLEDIMAGELIST:
6821 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6823 case TB_SETDRAWTEXTFLAGS:
6824 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6826 case TB_SETEXTENDEDSTYLE:
6827 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6829 case TB_SETHOTIMAGELIST:
6830 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6833 return TOOLBAR_SetHotItem (hwnd, wParam);
6835 case TB_SETIMAGELIST:
6836 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6839 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6841 case TB_SETINSERTMARK:
6842 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6844 case TB_SETINSERTMARKCOLOR:
6845 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6847 case TB_SETMAXTEXTROWS:
6848 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6851 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6854 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6857 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6860 return TOOLBAR_SetState (hwnd, wParam, lParam);
6863 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6865 case TB_SETTOOLTIPS:
6866 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6868 case TB_SETUNICODEFORMAT:
6869 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6872 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6875 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6878 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6881 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6884 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6887 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6889 /* Common Control Messages */
6891 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6892 case CCM_GETCOLORSCHEME:
6893 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6895 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6896 case CCM_SETCOLORSCHEME:
6897 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6899 case CCM_GETVERSION:
6900 return TOOLBAR_GetVersion (hwnd);
6902 case CCM_SETVERSION:
6903 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6909 return TOOLBAR_Create (hwnd, wParam, lParam);
6912 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6915 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6918 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6921 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6923 /* case WM_KILLFOCUS: */
6925 case WM_LBUTTONDBLCLK:
6926 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6928 case WM_LBUTTONDOWN:
6929 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6932 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6935 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6937 case WM_RBUTTONDBLCLK:
6938 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6941 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6944 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6946 case WM_CAPTURECHANGED:
6947 return TOOLBAR_CaptureChanged(hwnd);
6950 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6953 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6956 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6959 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6962 return TOOLBAR_Notify (hwnd, wParam, lParam);
6964 case WM_NOTIFYFORMAT:
6965 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6967 case WM_PRINTCLIENT:
6969 return TOOLBAR_Paint (hwnd, wParam);
6972 return TOOLBAR_SetFocus (hwnd, wParam);
6975 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6978 return TOOLBAR_Size (hwnd, wParam, lParam);
6980 case WM_STYLECHANGED:
6981 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6983 case WM_SYSCOLORCHANGE:
6984 return TOOLBAR_SysColorChange (hwnd);
6986 case WM_THEMECHANGED:
6987 return theme_changed (hwnd);
6989 /* case WM_WININICHANGE: */
6994 case WM_MEASUREITEM:
6996 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6998 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6999 case PGM_FORWARDMOUSE:
7000 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7003 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7004 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7005 uMsg, wParam, lParam);
7006 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7012 TOOLBAR_Register (void)
7016 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7017 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7018 wndClass.lpfnWndProc = ToolbarWindowProc;
7019 wndClass.cbClsExtra = 0;
7020 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7021 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7022 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7023 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7025 RegisterClassW (&wndClass);
7030 TOOLBAR_Unregister (void)
7032 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7035 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7040 /* Check if the entry already exists */
7041 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7043 /* If this is a new entry we must create it and insert into the array */
7048 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7051 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7052 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7067 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7071 for (i = 0; i < *cies; i++)
7081 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7089 for (i = 0; i < cies; i++)
7091 if (pies[i]->id == id)
7103 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7105 HIMAGELIST himlDef = 0;
7106 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7109 himlDef = pie->himl;
7115 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7117 if (infoPtr->bUnicode)
7118 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7125 nmtba.iItem = nmtb->iItem;
7126 nmtba.pszText = Buffer;
7127 nmtba.cchText = 256;
7128 ZeroMemory(nmtba.pszText, nmtba.cchText);
7130 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7132 int ccht = strlen(nmtba.pszText);
7134 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7135 nmtb->pszText, nmtb->cchText);
7137 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7146 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7147 int iItem, PCUSTOMBUTTON btnInfo)
7151 /* MSDN states that iItem is the index of the button, rather than the
7152 * command ID as used by every other NMTOOLBAR notification */
7154 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7156 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);