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 iTopMargin; /* the top margin */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bAnchor; /* anchor highlight enabled */
158 BOOL bDoRedraw; /* Redraw status */
159 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
160 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
161 BOOL bCaptured; /* mouse captured? */
162 DWORD dwStyle; /* regular toolbar style */
163 DWORD dwExStyle; /* extended toolbar style */
164 DWORD dwDTFlags; /* DrawText flags */
166 COLORREF clrInsertMark; /* insert mark color */
167 COLORREF clrBtnHighlight; /* color for Flat Separator */
168 COLORREF clrBtnShadow; /* color for Flag Separator */
170 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
171 * for TTN_GETDISPINFOW notification */
172 TBINSERTMARK tbim; /* info on insertion mark */
173 TBUTTON_INFO *buttons; /* pointer to button array */
174 LPWSTR *strings; /* pointer to string array */
175 TBITMAP_INFO *bitmaps;
176 } TOOLBAR_INFO, *PTOOLBAR_INFO;
179 /* used by customization dialog */
182 PTOOLBAR_INFO tbInfo;
184 } CUSTDLG_INFO, *PCUSTDLG_INFO;
192 } CUSTOMBUTTON, *PCUSTOMBUTTON;
201 #define SEPARATOR_WIDTH 8
203 #define BOTTOM_BORDER 2
204 #define DDARROW_WIDTH 11
205 #define ARROW_HEIGHT 3
206 #define INSERTMARK_WIDTH 2
212 /* vertical padding used in list mode when image is present */
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
218 #define TOOLBAR_NOWHERE (-1)
220 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
221 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
222 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
224 /* Used to find undocumented extended styles */
225 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
226 TBSTYLE_EX_UNDOC1 | \
227 TBSTYLE_EX_MIXEDBUTTONS | \
228 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
230 /* all of the CCS_ styles */
231 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
232 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
242 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
246 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
247 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
248 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
250 static void TOOLBAR_LayoutToolbar(HWND hwnd);
251 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
253 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 static inline int default_top_margin(TOOLBAR_INFO *infoPtr)
260 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
264 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
266 LPWSTR lpText = NULL;
268 /* NOTE: iString == -1 is undocumented */
269 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
270 lpText = (LPWSTR)btnPtr->iString;
271 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
272 lpText = infoPtr->strings[btnPtr->iString];
278 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
280 if (TRACE_ON(toolbar)){
281 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
282 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
283 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
284 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
286 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
287 btn_num, bP->idCommand,
288 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
289 bP->rect.left, bP->rect.top,
290 bP->rect.right, bP->rect.bottom);
296 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
298 if (TRACE_ON(toolbar)) {
301 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
303 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
304 iP->nNumStrings, iP->dwStyle);
305 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
307 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
308 (iP->bDoRedraw) ? "TRUE" : "FALSE");
309 for(i=0; i<iP->nNumButtons; i++) {
310 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
316 /***********************************************************************
319 * This function validates that the styles set are implemented and
320 * issues FIXME's warning of possible problems. In a perfect world this
321 * function should be null.
324 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
326 if (dwStyle & TBSTYLE_REGISTERDROP)
327 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
332 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
334 if(!IsWindow(infoPtr->hwndSelf))
335 return 0; /* we have just been destroyed */
337 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
338 nmhdr->hwndFrom = infoPtr->hwndSelf;
341 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
342 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
344 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
345 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
348 /***********************************************************************
349 * TOOLBAR_GetBitmapIndex
351 * This function returns the bitmap index associated with a button.
352 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
353 * is issued to retrieve the index.
356 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
358 INT ret = btnPtr->iBitmap;
360 if (ret == I_IMAGECALLBACK)
362 /* issue TBN_GETDISPINFO */
365 memset(&nmgd, 0, sizeof(nmgd));
366 nmgd.idCommand = btnPtr->idCommand;
367 nmgd.lParam = btnPtr->dwData;
368 nmgd.dwMask = TBNF_IMAGE;
369 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
370 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
371 if (nmgd.dwMask & TBNF_DI_SETITEM)
372 btnPtr->iBitmap = nmgd.iImage;
374 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
375 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
378 if (ret != I_IMAGENONE)
379 ret = GETIBITMAP(infoPtr, ret);
386 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
389 INT id = GETHIMLID(infoPtr, index);
390 INT iBitmap = GETIBITMAP(infoPtr, index);
392 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
393 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
394 (index == I_IMAGECALLBACK))
402 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
404 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
405 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
409 /***********************************************************************
410 * TOOLBAR_GetImageListForDrawing
412 * This function validates the bitmap index (including I_IMAGECALLBACK
413 * functionality) and returns the corresponding image list.
416 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
420 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
421 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
422 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
423 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
427 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
428 if ((*index == I_IMAGECALLBACK) ||
429 (*index == I_IMAGENONE)) return NULL;
430 ERR("TBN_GETDISPINFO returned invalid index %d\n",
437 case IMAGE_LIST_DEFAULT:
438 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
441 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
443 case IMAGE_LIST_DISABLED:
444 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
448 FIXME("Shouldn't reach here\n");
452 TRACE("no image list\n");
459 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
462 COLORREF oldcolor, newcolor;
464 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
465 myrect.right = myrect.left + 1;
466 myrect.top = lpRect->top + 2;
467 myrect.bottom = lpRect->bottom - 2;
469 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
470 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
471 oldcolor = SetBkColor (hdc, newcolor);
472 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
474 myrect.left = myrect.right;
475 myrect.right = myrect.left + 1;
477 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
478 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
479 SetBkColor (hdc, newcolor);
480 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
482 SetBkColor (hdc, oldcolor);
486 /***********************************************************************
487 * TOOLBAR_DrawDDFlatSeparator
489 * This function draws the separator that was flagged as BTNS_DROPDOWN.
490 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
491 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
492 * are horizontal as opposed to the vertical separators for not dropdown
495 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
498 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
501 COLORREF oldcolor, newcolor;
503 myrect.left = lpRect->left;
504 myrect.right = lpRect->right;
505 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
506 myrect.bottom = myrect.top + 1;
508 InflateRect (&myrect, -2, 0);
510 TRACE("rect=(%d,%d)-(%d,%d)\n",
511 myrect.left, myrect.top, myrect.right, myrect.bottom);
513 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
514 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
515 oldcolor = SetBkColor (hdc, newcolor);
516 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
518 myrect.top = myrect.bottom;
519 myrect.bottom = myrect.top + 1;
521 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
522 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
523 SetBkColor (hdc, newcolor);
524 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
526 SetBkColor (hdc, oldcolor);
531 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
536 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
537 hOldPen = SelectObject ( hdc, hPen );
540 MoveToEx (hdc, x, y, NULL);
541 LineTo (hdc, x+5, y++); x++;
542 MoveToEx (hdc, x, y, NULL);
543 LineTo (hdc, x+3, y++); x++;
544 MoveToEx (hdc, x, y, NULL);
545 LineTo (hdc, x+1, y++);
546 SelectObject( hdc, hOldPen );
547 DeleteObject( hPen );
551 * Draw the text string for this button.
552 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
553 * is non-zero, so we can simply check himlDef to see if we have
557 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
558 NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
560 HDC hdc = tbcd->nmcd.hdc;
563 COLORREF clrOldBk = 0;
565 UINT state = tbcd->nmcd.uItemState;
569 TRACE("string=%s rect=(%d,%d)-(%d,%d)\n", debugstr_w(lpText),
570 rcText->left, rcText->top, rcText->right, rcText->bottom);
572 hOldFont = SelectObject (hdc, infoPtr->hFont);
573 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
574 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
576 else if (state & CDIS_DISABLED) {
577 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
578 OffsetRect (rcText, 1, 1);
579 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
580 SetTextColor (hdc, comctl32_color.clr3dShadow);
581 OffsetRect (rcText, -1, -1);
583 else if (state & CDIS_INDETERMINATE) {
584 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
586 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
587 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
588 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
589 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
592 clrOld = SetTextColor (hdc, tbcd->clrText);
595 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
596 SetTextColor (hdc, clrOld);
597 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
599 SetBkColor (hdc, clrOldBk);
600 SetBkMode (hdc, oldBkMode);
602 SelectObject (hdc, hOldFont);
608 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
610 HDC hdc = tbcd->nmcd.hdc;
611 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
614 INT cx = lpRect->right - lpRect->left;
615 INT cy = lpRect->bottom - lpRect->top;
616 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
617 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
618 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
619 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
620 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
621 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
622 SetBkColor(hdc, clrBkOld);
623 SetTextColor(hdc, clrTextOld);
624 SelectObject (hdc, hbr);
628 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
631 HBITMAP hbmMask, hbmImage;
632 HDC hdcMask, hdcImage;
634 ImageList_GetIconSize(himl, &cx, &cy);
636 /* Create src image */
637 hdcImage = CreateCompatibleDC(hdc);
638 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
639 SelectObject(hdcImage, hbmImage);
640 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
641 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
644 hdcMask = CreateCompatibleDC(0);
645 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
646 SelectObject(hdcMask, hbmMask);
648 /* Remove the background and all white pixels */
649 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
650 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
651 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
652 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
654 /* draw the new mask 'etched' to hdc */
655 SetBkColor(hdc, RGB(255, 255, 255));
656 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
657 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
658 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
659 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
660 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
663 DeleteObject(hbmImage);
665 DeleteObject (hbmMask);
671 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
675 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
676 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
678 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
679 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
680 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
681 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
685 /* draws the image on a toolbar button */
687 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
688 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
690 HIMAGELIST himl = NULL;
691 BOOL draw_masked = FALSE;
694 UINT draw_flags = ILD_TRANSPARENT;
696 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
698 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
701 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
705 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
706 ((tbcd->nmcd.uItemState & CDIS_HOT)
707 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
709 /* if hot, attempt to draw with hot image list, if fails,
710 use default image list */
711 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
713 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
716 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
721 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
722 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
725 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
726 (tbcd->nmcd.uItemState & CDIS_MARKED))
727 draw_flags |= ILD_BLEND50;
729 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
730 index, himl, left, top, offset);
733 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
735 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
738 /* draws a blank frame for a toolbar button */
740 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
742 HDC hdc = tbcd->nmcd.hdc;
743 RECT rc = tbcd->nmcd.rc;
744 /* if the state is disabled or indeterminate then the button
745 * cannot have an interactive look like pressed or hot */
746 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
747 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
748 BOOL pressed_look = !non_interactive_state &&
749 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
750 (tbcd->nmcd.uItemState & CDIS_CHECKED));
752 /* app don't want us to draw any edges */
753 if (dwItemCDFlag & TBCDRF_NOEDGES)
756 if (infoPtr->dwStyle & TBSTYLE_FLAT)
759 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
760 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
761 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
766 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
768 DrawEdge (hdc, &rc, EDGE_RAISED,
769 BF_SOFT | BF_RECT | BF_MIDDLE);
774 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
776 HDC hdc = tbcd->nmcd.hdc;
778 BOOL pressed = bDropDownPressed ||
779 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
781 if (infoPtr->dwStyle & TBSTYLE_FLAT)
784 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
785 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
786 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
787 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
788 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
793 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
795 DrawEdge (hdc, rcArrow, EDGE_RAISED,
796 BF_SOFT | BF_RECT | BF_MIDDLE);
800 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
802 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
804 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
805 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
808 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
811 /* draws a complete toolbar button */
813 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
815 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
816 DWORD dwStyle = infoPtr->dwStyle;
817 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
818 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
819 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
820 BOOL drawSepDropDownArrow = hasDropDownArrow &&
821 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
822 RECT rc, rcArrow, rcBitmap, rcText;
823 LPWSTR lpText = NULL;
828 DWORD dwItemCustDraw;
830 HTHEME theme = GetWindowTheme (hwnd);
833 CopyRect (&rcArrow, &rc);
835 /* separator - doesn't send NM_CUSTOMDRAW */
836 if (btnPtr->fsStyle & BTNS_SEP) {
839 DrawThemeBackground (theme, hdc,
840 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
844 /* with the FLAT style, iBitmap is the width and has already */
845 /* been taken into consideration in calculating the width */
846 /* so now we need to draw the vertical separator */
847 /* empirical tests show that iBitmap can/will be non-zero */
848 /* when drawing the vertical bar... */
849 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
850 if (btnPtr->fsStyle & BTNS_DROPDOWN)
851 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
853 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
855 else if (btnPtr->fsStyle != BTNS_SEP) {
856 FIXME("Draw some kind of separator: fsStyle=%x\n",
862 /* get a pointer to the text */
863 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
865 if (hasDropDownArrow)
869 if (dwStyle & TBSTYLE_FLAT)
870 right = max(rc.left, rc.right - DDARROW_WIDTH);
872 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
874 if (drawSepDropDownArrow)
877 rcArrow.left = right;
880 /* copy text & bitmap rects after adjusting for drop-down arrow
881 * so that text & bitmap is centred in the rectangle not containing
883 CopyRect(&rcText, &rc);
884 CopyRect(&rcBitmap, &rc);
886 /* Center the bitmap horizontally and vertically */
887 if (dwStyle & TBSTYLE_LIST)
890 infoPtr->nMaxTextRows > 0 &&
891 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
892 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
893 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
895 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
898 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
900 rcBitmap.top += infoPtr->szPadding.cy / 2;
902 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
903 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
904 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
905 TRACE("Text=%s\n", debugstr_w(lpText));
906 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
908 /* calculate text position */
911 rcText.left += GetSystemMetrics(SM_CXEDGE);
912 rcText.right -= GetSystemMetrics(SM_CXEDGE);
913 if (dwStyle & TBSTYLE_LIST)
915 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
916 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
920 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
921 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
923 rcText.top += infoPtr->szPadding.cy/2 + 2;
927 /* Initialize fields in all cases, because we use these later
928 * NOTE: applications can and do alter these to customize their
930 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
931 tbcd.clrText = comctl32_color.clrBtnText;
932 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
933 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
934 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
935 tbcd.clrMark = comctl32_color.clrHighlight;
936 tbcd.clrHighlightHotTrack = 0;
937 tbcd.nStringBkMode = TRANSPARENT;
938 tbcd.nHLStringBkMode = OPAQUE;
939 /* MSDN says that this is the text rectangle.
940 * But (why always a but) tracing of v5.7 of native shows
941 * that this is really a *relative* rectangle based on the
942 * the nmcd.rc. Also the left and top are always 0 ignoring
943 * any bitmap that might be present. */
944 tbcd.rcText.left = 0;
946 tbcd.rcText.right = rcText.right - rc.left;
947 tbcd.rcText.bottom = rcText.bottom - rc.top;
948 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
951 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
953 /* FIXME: what are these used for? */
957 /* Issue Item Prepaint notify */
960 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
962 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
963 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
964 tbcd.nmcd.lItemlParam = btnPtr->dwData;
965 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
966 /* reset these fields so the user can't alter the behaviour like native */
970 dwItemCustDraw = ntfret & 0xffff;
971 dwItemCDFlag = ntfret & 0xffff0000;
972 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
974 /* save the only part of the rect that the user can change */
975 rcText.right = tbcd.rcText.right + rc.left;
976 rcText.bottom = tbcd.rcText.bottom + rc.top;
979 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
980 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
981 OffsetRect(&rcText, 1, 1);
983 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
984 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
985 TOOLBAR_DrawPattern (&rc, &tbcd);
987 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
988 && (tbcd.nmcd.uItemState & CDIS_HOT))
990 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
994 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
995 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
996 if (hasDropDownArrow)
997 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
998 SetBkColor(hdc, oldclr);
1004 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1005 int stateId = TS_NORMAL;
1007 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1008 stateId = TS_DISABLED;
1009 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1010 stateId = TS_PRESSED;
1011 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1012 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1013 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1014 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1017 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1020 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1022 if (drawSepDropDownArrow)
1026 int stateId = TS_NORMAL;
1028 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1029 stateId = TS_DISABLED;
1030 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1031 stateId = TS_PRESSED;
1032 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1033 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1034 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1037 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1038 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1041 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1044 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1045 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1046 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1047 SetBkMode (hdc, oldBkMode);
1049 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1051 if (hasDropDownArrow && !drawSepDropDownArrow)
1053 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1056 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1058 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1060 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1061 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1064 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1067 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1069 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1070 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1077 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1080 TBUTTON_INFO *btnPtr;
1082 RECT rcTemp, rcClient;
1083 NMTBCUSTOMDRAW tbcd;
1085 DWORD dwBaseCustDraw;
1087 /* the app has told us not to redraw the toolbar */
1088 if (!infoPtr->bDoRedraw)
1091 /* if imagelist belongs to the app, it can be changed
1092 by the app after setting it */
1093 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1095 infoPtr->nNumBitmaps = 0;
1096 for (i = 0; i < infoPtr->cimlDef; i++)
1097 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1100 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1102 /* change the imagelist icon size if we manage the list and it is necessary */
1103 TOOLBAR_CheckImageListIconSize(infoPtr);
1105 /* Send initial notify */
1106 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1107 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1108 tbcd.nmcd.hdc = hdc;
1109 tbcd.nmcd.rc = ps->rcPaint;
1110 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1111 dwBaseCustDraw = ntfret & 0xffff;
1113 GetClientRect(hwnd, &rcClient);
1115 /* redraw necessary buttons */
1116 btnPtr = infoPtr->buttons;
1117 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1120 if (!RectVisible(hdc, &btnPtr->rect))
1122 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1124 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1125 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1129 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1130 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1132 TOOLBAR_DrawButton(hwnd, btnPtr, hdc, dwBaseCustDraw);
1135 /* draw insert mark if required */
1136 if (infoPtr->tbim.iButton != -1)
1138 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1140 rcInsertMark.top = rcButton.top;
1141 rcInsertMark.bottom = rcButton.bottom;
1142 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1143 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1145 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1146 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1149 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1151 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1152 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1153 tbcd.nmcd.hdc = hdc;
1154 tbcd.nmcd.rc = ps->rcPaint;
1155 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1159 /***********************************************************************
1160 * TOOLBAR_MeasureString
1162 * This function gets the width and height of a string in pixels. This
1163 * is done first by using GetTextExtentPoint to get the basic width
1164 * and height. The DrawText is called with DT_CALCRECT to get the exact
1165 * width. The reason is because the text may have more than one "&" (or
1166 * prefix characters as M$ likes to call them). The prefix character
1167 * indicates where the underline goes, except for the string "&&" which
1168 * is reduced to a single "&". GetTextExtentPoint does not process these
1169 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1172 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1173 HDC hdc, LPSIZE lpSize)
1180 if (infoPtr->nMaxTextRows > 0 &&
1181 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1182 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1183 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1185 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1187 if(lpText != NULL) {
1188 /* first get size of all the text */
1189 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1191 /* feed above size into the rectangle for DrawText */
1192 myrect.left = myrect.top = 0;
1193 myrect.right = lpSize->cx;
1194 myrect.bottom = lpSize->cy;
1196 /* Use DrawText to get true size as drawn (less pesky "&") */
1197 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1198 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1201 /* feed back to caller */
1202 lpSize->cx = myrect.right;
1203 lpSize->cy = myrect.bottom;
1207 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1210 /***********************************************************************
1211 * TOOLBAR_CalcStrings
1213 * This function walks through each string and measures it and returns
1214 * the largest height and width to caller.
1217 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1219 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1220 TBUTTON_INFO *btnPtr;
1229 if (infoPtr->nMaxTextRows == 0)
1233 hOldFont = SelectObject (hdc, infoPtr->hFont);
1235 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1239 GetTextMetricsW(hdc, &tm);
1240 lpSize->cy = tm.tmHeight;
1243 btnPtr = infoPtr->buttons;
1244 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1245 if(TOOLBAR_HasText(infoPtr, btnPtr))
1247 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1248 if (sz.cx > lpSize->cx)
1250 if (sz.cy > lpSize->cy)
1255 SelectObject (hdc, hOldFont);
1256 ReleaseDC (hwnd, hdc);
1258 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1261 /***********************************************************************
1262 * TOOLBAR_WrapToolbar
1264 * This function walks through the buttons and separators in the
1265 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1266 * wrapping should occur based on the width of the toolbar window.
1267 * It does *not* calculate button placement itself. That task
1268 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1269 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1270 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1272 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1273 * vertical toolbar lists.
1277 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1280 TBUTTON_INFO *btnPtr;
1283 BOOL bWrap, bButtonWrap;
1285 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1286 /* no layout is necessary. Applications may use this style */
1287 /* to perform their own layout on the toolbar. */
1288 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1289 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1291 btnPtr = infoPtr->buttons;
1292 x = infoPtr->nIndent;
1294 if (GetParent(hwnd))
1296 /* this can get the parents width, to know how far we can extend
1297 * this toolbar. We cannot use its height, as there may be multiple
1298 * toolbars in a rebar control
1300 GetClientRect( GetParent(hwnd), &rc );
1301 infoPtr->nWidth = rc.right - rc.left;
1305 GetWindowRect( hwnd, &rc );
1306 infoPtr->nWidth = rc.right - rc.left;
1309 bButtonWrap = FALSE;
1311 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1312 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1315 for (i = 0; i < infoPtr->nNumButtons; i++ )
1318 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1320 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1323 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1324 /* it is the actual width of the separator. This is used for */
1325 /* custom controls in toolbars. */
1327 /* BTNS_DROPDOWN separators are treated as buttons for */
1328 /* width. - GA 8/01 */
1329 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1330 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1331 cx = (btnPtr[i].iBitmap > 0) ?
1332 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1334 cx = infoPtr->nButtonWidth;
1336 /* Two or more adjacent separators form a separator group. */
1337 /* The first separator in a group should be wrapped to the */
1338 /* next row if the previous wrapping is on a button. */
1340 (btnPtr[i].fsStyle & BTNS_SEP) &&
1341 (i + 1 < infoPtr->nNumButtons ) &&
1342 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1344 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1345 btnPtr[i].fsState |= TBSTATE_WRAP;
1346 x = infoPtr->nIndent;
1348 bButtonWrap = FALSE;
1352 /* The layout makes sure the bitmap is visible, but not the button. */
1353 /* Test added to also wrap after a button that starts a row but */
1354 /* is bigger than the area. - GA 8/01 */
1355 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1356 > infoPtr->nWidth ) ||
1357 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1359 BOOL bFound = FALSE;
1361 /* If the current button is a separator and not hidden, */
1362 /* go to the next until it reaches a non separator. */
1363 /* Wrap the last separator if it is before a button. */
1364 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1365 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1366 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1367 i < infoPtr->nNumButtons )
1373 if( bFound && i < infoPtr->nNumButtons )
1376 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1378 btnPtr[i].fsState |= TBSTATE_WRAP;
1379 x = infoPtr->nIndent;
1380 bButtonWrap = FALSE;
1383 else if ( i >= infoPtr->nNumButtons)
1386 /* If the current button is not a separator, find the last */
1387 /* separator and wrap it. */
1388 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1390 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1391 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1395 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1396 i, btnPtr[i].fsStyle, x, cx);
1397 x = infoPtr->nIndent;
1398 btnPtr[j].fsState |= TBSTATE_WRAP;
1399 bButtonWrap = FALSE;
1404 /* If no separator available for wrapping, wrap one of */
1405 /* non-hidden previous button. */
1409 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1411 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1416 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1417 i, btnPtr[i].fsStyle, x, cx);
1418 x = infoPtr->nIndent;
1419 btnPtr[j].fsState |= TBSTATE_WRAP;
1425 /* If all above failed, wrap the current button. */
1428 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1429 i, btnPtr[i].fsStyle, x, cx);
1430 btnPtr[i].fsState |= TBSTATE_WRAP;
1432 x = infoPtr->nIndent;
1433 if (btnPtr[i].fsStyle & BTNS_SEP )
1434 bButtonWrap = FALSE;
1440 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1441 i, btnPtr[i].fsStyle, x, cx);
1448 /***********************************************************************
1449 * TOOLBAR_MeasureButton
1451 * Calculates the width and height required for a button. Used in
1452 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1453 * the width of buttons that are autosized.
1455 * Note that it would have been rather elegant to use one piece of code for
1456 * both the laying out of the toolbar and for controlling where button parts
1457 * are drawn, but the native control has inconsistencies between the two that
1458 * prevent this from being effectively. These inconsistencies can be seen as
1459 * artefacts where parts of the button appear outside of the bounding button
1462 * There are several cases for the calculation of the button dimensions and
1463 * button part positioning:
1470 * +--------------------------------------------------------+ ^
1472 * | | pad.cy / 2 | centred | |
1473 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1474 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1475 * | |<------------>| | | | |
1476 * | +--------------+ +------------+ | |
1477 * |<-------------------------------------->| | |
1478 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1480 * +--------------------------------------------------------+ -
1481 * <-------------------------------------------------------->
1482 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1484 * Without Bitmap (I_IMAGENONE):
1486 * +-----------------------------------+ ^
1488 * | | centred | | LISTPAD_CY +
1489 * | +------------+ | | szText.cy
1492 * | +------------+ | |
1493 * |<----------------->| | |
1494 * | cxedge |<-----------> | |
1496 * +-----------------------------------+ -
1497 * <----------------------------------->
1498 * szText.cx + pad.cx
1502 * +--------------------------------------+ ^
1504 * | | padding.cy/2 | | DEFPAD_CY +
1505 * | +------------+ | | nBitmapHeight
1508 * | +------------+ | |
1509 * |<------------------->| | |
1510 * | cxedge + iListGap/2 |<-----------> | |
1511 * | nBitmapWidth | |
1512 * +--------------------------------------+ -
1513 * <-------------------------------------->
1514 * 2*cxedge + nBitmapWidth + iListGap
1521 * +-----------------------------------+ ^
1523 * | | pad.cy / 2 | | nBitmapHeight +
1524 * | - | | szText.cy +
1525 * | +------------+ | | DEFPAD_CY + 1
1526 * | centred | Bitmap | | |
1527 * |<----------------->| | | |
1528 * | +------------+ | |
1532 * | centred +---------------+ | |
1533 * |<--------------->| Text | | |
1534 * | +---------------+ | |
1535 * +-----------------------------------+ -
1536 * <----------------------------------->
1537 * pad.cx + max(nBitmapWidth, szText.cx)
1539 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1541 * +---------------------------------------+ ^
1543 * | | 2 + pad.cy / 2 | |
1544 * | - | | szText.cy +
1545 * | centred +-----------------+ | | pad.cy + 2
1546 * |<--------------->| Text | | |
1547 * | +-----------------+ | |
1549 * +---------------------------------------+ -
1550 * <--------------------------------------->
1551 * 2*cxedge + pad.cx + szText.cx
1554 * As for with bitmaps, but with szText.cx zero.
1556 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1559 if (infoPtr->dwStyle & TBSTYLE_LIST)
1561 /* set button height from bitmap / text height... */
1562 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1565 /* ... add on the necessary padding */
1566 if (bValidImageList)
1569 sizeButton.cy += DEFPAD_CY;
1571 sizeButton.cy += LISTPAD_CY;
1574 sizeButton.cy += infoPtr->szPadding.cy;
1576 /* calculate button width */
1579 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1580 infoPtr->nBitmapWidth + infoPtr->iListGap;
1581 if (sizeString.cx > 0)
1582 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1585 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1591 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1592 if (sizeString.cy > 0)
1593 sizeButton.cy += 1 + sizeString.cy;
1594 sizeButton.cx = infoPtr->szPadding.cx +
1595 max(sizeString.cx, infoPtr->nBitmapWidth);
1599 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1600 NONLIST_NOTEXT_OFFSET;
1601 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1602 infoPtr->szPadding.cx + sizeString.cx;
1609 /***********************************************************************
1610 * TOOLBAR_CalcToolbar
1612 * This function calculates button and separator placement. It first
1613 * calculates the button sizes, gets the toolbar window width and then
1614 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1615 * on. It assigns a new location to each item and sends this location to
1616 * the tooltip window if appropriate. Finally, it updates the rcBound
1617 * rect and calculates the new required toolbar window height.
1620 TOOLBAR_CalcToolbar (HWND hwnd)
1622 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1623 SIZE sizeString, sizeButton;
1624 BOOL validImageList = FALSE;
1626 TOOLBAR_CalcStrings (hwnd, &sizeString);
1628 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1630 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1631 validImageList = TRUE;
1632 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1633 infoPtr->nButtonWidth = sizeButton.cx;
1634 infoPtr->nButtonHeight = sizeButton.cy;
1635 infoPtr->iTopMargin = default_top_margin(infoPtr);
1637 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1638 infoPtr->nButtonWidth = infoPtr->cxMin;
1639 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1640 infoPtr->nButtonWidth = infoPtr->cxMax;
1642 TOOLBAR_LayoutToolbar(hwnd);
1646 TOOLBAR_LayoutToolbar(HWND hwnd)
1648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1649 TBUTTON_INFO *btnPtr;
1651 INT i, nRows, nSepRows;
1654 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1655 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1657 TOOLBAR_WrapToolbar(hwnd, infoPtr->dwStyle);
1659 x = infoPtr->nIndent;
1660 y = infoPtr->iTopMargin;
1661 cx = infoPtr->nButtonWidth;
1662 cy = infoPtr->nButtonHeight;
1664 nRows = nSepRows = 0;
1666 infoPtr->rcBound.top = y;
1667 infoPtr->rcBound.left = x;
1668 infoPtr->rcBound.bottom = y + cy;
1669 infoPtr->rcBound.right = x;
1671 btnPtr = infoPtr->buttons;
1673 TRACE("cy=%d\n", cy);
1675 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1678 if (btnPtr->fsState & TBSTATE_HIDDEN)
1680 SetRectEmpty (&btnPtr->rect);
1684 cy = infoPtr->nButtonHeight;
1686 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1687 /* it is the actual width of the separator. This is used for */
1688 /* custom controls in toolbars. */
1689 if (btnPtr->fsStyle & BTNS_SEP) {
1690 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1691 cy = (btnPtr->iBitmap > 0) ?
1692 btnPtr->iBitmap : SEPARATOR_WIDTH;
1693 cx = infoPtr->nButtonWidth;
1696 cx = (btnPtr->iBitmap > 0) ?
1697 btnPtr->iBitmap : SEPARATOR_WIDTH;
1703 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1704 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1711 hOldFont = SelectObject (hdc, infoPtr->hFont);
1713 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1715 SelectObject (hdc, hOldFont);
1716 ReleaseDC (hwnd, hdc);
1718 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1719 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1724 cx = infoPtr->nButtonWidth;
1726 /* if size has been set manually then don't add on extra space
1727 * for the drop down arrow */
1728 if (!btnPtr->cx && hasDropDownArrows &&
1729 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1730 cx += DDARROW_WIDTH;
1732 if (btnPtr->fsState & TBSTATE_WRAP )
1735 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1737 if (infoPtr->rcBound.left > x)
1738 infoPtr->rcBound.left = x;
1739 if (infoPtr->rcBound.right < x + cx)
1740 infoPtr->rcBound.right = x + cx;
1741 if (infoPtr->rcBound.bottom < y + cy)
1742 infoPtr->rcBound.bottom = y + cy;
1744 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1746 /* btnPtr->nRow is zero based. The space between the rows is */
1747 /* also considered as a row. */
1748 btnPtr->nRow = nRows + nSepRows;
1750 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1751 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1756 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1760 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1761 /* it is the actual width of the separator. This is used for */
1762 /* custom controls in toolbars. */
1763 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1764 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1765 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1769 /* nSepRows is used to calculate the extra height follwoing */
1773 x = infoPtr->nIndent;
1775 /* Increment row number unless this is the last button */
1776 /* and it has Wrap set. */
1777 if (i != infoPtr->nNumButtons-1)
1784 /* infoPtr->nRows is the number of rows on the toolbar */
1785 infoPtr->nRows = nRows + nSepRows + 1;
1787 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1792 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1794 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1795 TBUTTON_INFO *btnPtr;
1798 btnPtr = infoPtr->buttons;
1799 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1800 if (btnPtr->fsState & TBSTATE_HIDDEN)
1803 if (btnPtr->fsStyle & BTNS_SEP) {
1804 if (PtInRect (&btnPtr->rect, *lpPt)) {
1805 TRACE(" ON SEPARATOR %d!\n", i);
1810 if (PtInRect (&btnPtr->rect, *lpPt)) {
1811 TRACE(" ON BUTTON %d!\n", i);
1817 TRACE(" NOWHERE!\n");
1818 return TOOLBAR_NOWHERE;
1823 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1825 TBUTTON_INFO *btnPtr;
1828 if (CommandIsIndex) {
1829 TRACE("command is really index command=%d\n", idCommand);
1830 if (idCommand >= infoPtr->nNumButtons) return -1;
1833 btnPtr = infoPtr->buttons;
1834 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1835 if (btnPtr->idCommand == idCommand) {
1836 TRACE("command=%d index=%d\n", idCommand, i);
1840 TRACE("no index found for command=%d\n", idCommand);
1846 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1848 TBUTTON_INFO *btnPtr;
1851 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1854 /* check index button */
1855 btnPtr = &infoPtr->buttons[nIndex];
1856 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1857 if (btnPtr->fsState & TBSTATE_CHECKED)
1861 /* check previous buttons */
1862 nRunIndex = nIndex - 1;
1863 while (nRunIndex >= 0) {
1864 btnPtr = &infoPtr->buttons[nRunIndex];
1865 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1866 if (btnPtr->fsState & TBSTATE_CHECKED)
1874 /* check next buttons */
1875 nRunIndex = nIndex + 1;
1876 while (nRunIndex < infoPtr->nNumButtons) {
1877 btnPtr = &infoPtr->buttons[nRunIndex];
1878 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1879 if (btnPtr->fsState & TBSTATE_CHECKED)
1892 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1893 WPARAM wParam, LPARAM lParam)
1899 msg.wParam = wParam;
1900 msg.lParam = lParam;
1901 msg.time = GetMessageTime ();
1902 msg.pt.x = (short)LOWORD(GetMessagePos ());
1903 msg.pt.y = (short)HIWORD(GetMessagePos ());
1905 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1909 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1911 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1914 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1915 ti.cbSize = sizeof (TTTOOLINFOW);
1916 ti.hwnd = infoPtr->hwndSelf;
1917 ti.uId = button->idCommand;
1919 ti.lpszText = LPSTR_TEXTCALLBACKW;
1920 /* ti.lParam = random value from the stack? */
1922 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1928 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1930 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1933 ZeroMemory(&ti, sizeof(ti));
1934 ti.cbSize = sizeof(ti);
1935 ti.hwnd = infoPtr->hwndSelf;
1936 ti.uId = button->idCommand;
1938 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1942 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1944 /* Set the toolTip only for non-hidden, non-separator button */
1945 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1949 ZeroMemory(&ti, sizeof(ti));
1950 ti.cbSize = sizeof(ti);
1951 ti.hwnd = infoPtr->hwndSelf;
1952 ti.uId = button->idCommand;
1953 ti.rect = button->rect;
1954 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1958 /* Creates the tooltip control */
1960 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1963 NMTOOLTIPSCREATED nmttc;
1965 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
1966 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1967 infoPtr->hwndSelf, 0, 0, 0);
1969 if (!infoPtr->hwndToolTip)
1972 /* Send NM_TOOLTIPSCREATED notification */
1973 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1974 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1976 for (i = 0; i < infoPtr->nNumButtons; i++)
1978 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1979 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1983 /* keeps available button list box sorted by button id */
1984 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1988 PCUSTOMBUTTON btnInfo;
1989 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1991 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1993 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1995 /* position 0 is always separator */
1996 for (i = 1; i < count; i++)
1998 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1999 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2001 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2002 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2006 /* id higher than all others add to end */
2007 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2008 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2011 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2015 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2017 if (nIndexFrom == nIndexTo)
2020 /* MSDN states that iItem is the index of the button, rather than the
2021 * command ID as used by every other NMTOOLBAR notification */
2022 nmtb.iItem = nIndexFrom;
2023 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2025 PCUSTOMBUTTON btnInfo;
2027 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2028 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2030 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2032 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2033 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2034 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2035 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2038 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2040 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2042 /* last item is always separator, so -2 instead of -1 */
2043 if (nIndexTo >= (count - 2))
2044 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2046 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2048 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2049 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2051 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2055 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2059 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2061 /* MSDN states that iItem is the index of the button, rather than the
2062 * command ID as used by every other NMTOOLBAR notification */
2063 nmtb.iItem = nIndexAvail;
2064 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2066 PCUSTOMBUTTON btnInfo;
2068 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2069 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2070 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2072 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2074 if (nIndexAvail != 0) /* index == 0 indicates separator */
2076 /* remove from 'available buttons' list */
2077 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2078 if (nIndexAvail == count-1)
2079 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2081 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2085 PCUSTOMBUTTON btnNew;
2087 /* duplicate 'separator' button */
2088 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2089 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2093 /* insert into 'toolbar button' list */
2094 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2095 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2097 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2099 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2103 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2105 PCUSTOMBUTTON btnInfo;
2106 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2108 TRACE("Remove: index %d\n", index);
2110 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2112 /* send TBN_QUERYDELETE notification */
2113 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2117 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2118 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2120 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2122 /* insert into 'available button' list */
2123 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2124 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2128 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2132 /* drag list notification function for toolbar buttons list box */
2133 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2135 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2136 switch (pDLI->uNotification)
2140 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2141 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2142 /* no dragging for last item (separator) */
2143 if (nCurrentItem >= (nCount - 1)) return FALSE;
2148 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2149 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2150 /* no dragging past last item (separator) */
2151 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2153 DrawInsert(hwnd, hwndList, nCurrentItem);
2154 /* FIXME: native uses "move button" cursor */
2155 return DL_COPYCURSOR;
2158 /* not over toolbar buttons list */
2159 if (nCurrentItem < 0)
2161 POINT ptWindow = pDLI->ptCursor;
2162 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2163 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2164 /* over available buttons list? */
2165 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2166 /* FIXME: native uses "move button" cursor */
2167 return DL_COPYCURSOR;
2169 /* clear drag arrow */
2170 DrawInsert(hwnd, hwndList, -1);
2171 return DL_STOPCURSOR;
2175 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2176 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2177 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2178 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2180 /* clear drag arrow */
2181 DrawInsert(hwnd, hwndList, -1);
2183 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2185 /* not over toolbar buttons list */
2188 POINT ptWindow = pDLI->ptCursor;
2189 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2190 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2191 /* over available buttons list? */
2192 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2193 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2198 /* Clear drag arrow */
2199 DrawInsert(hwnd, hwndList, -1);
2206 /* drag list notification function for available buttons list box */
2207 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2209 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2210 switch (pDLI->uNotification)
2216 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2217 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2218 /* no dragging past last item (separator) */
2219 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2221 DrawInsert(hwnd, hwndList, nCurrentItem);
2222 /* FIXME: native uses "move button" cursor */
2223 return DL_COPYCURSOR;
2226 /* not over toolbar buttons list */
2227 if (nCurrentItem < 0)
2229 POINT ptWindow = pDLI->ptCursor;
2230 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2231 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2232 /* over available buttons list? */
2233 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2234 /* FIXME: native uses "move button" cursor */
2235 return DL_COPYCURSOR;
2237 /* clear drag arrow */
2238 DrawInsert(hwnd, hwndList, -1);
2239 return DL_STOPCURSOR;
2243 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2244 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2245 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2246 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2248 /* clear drag arrow */
2249 DrawInsert(hwnd, hwndList, -1);
2251 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2255 /* Clear drag arrow */
2256 DrawInsert(hwnd, hwndList, -1);
2262 extern UINT uDragListMessage;
2264 /***********************************************************************
2265 * TOOLBAR_CustomizeDialogProc
2266 * This function implements the toolbar customization dialog.
2268 static INT_PTR CALLBACK
2269 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2271 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2272 PCUSTOMBUTTON btnInfo;
2274 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2279 custInfo = (PCUSTDLG_INFO)lParam;
2280 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2287 NMTBINITCUSTOMIZE nmtbic;
2289 infoPtr = custInfo->tbInfo;
2291 /* send TBN_QUERYINSERT notification */
2292 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2294 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2297 nmtbic.hwndDialog = hwnd;
2298 /* Send TBN_INITCUSTOMIZE notification */
2299 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2302 TRACE("TBNRF_HIDEHELP requested\n");
2303 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2306 /* add items to 'toolbar buttons' list and check if removable */
2307 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2309 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2310 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2311 btnInfo->btn.fsStyle = BTNS_SEP;
2312 btnInfo->bVirtual = FALSE;
2313 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2315 /* send TBN_QUERYDELETE notification */
2316 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2318 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2324 /* insert separator button into 'available buttons' list */
2325 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2326 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2327 btnInfo->btn.fsStyle = BTNS_SEP;
2328 btnInfo->bVirtual = FALSE;
2329 btnInfo->bRemovable = TRUE;
2330 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2331 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2332 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2334 /* insert all buttons into dsa */
2337 /* send TBN_GETBUTTONINFO notification */
2340 nmtb.pszText = Buffer;
2343 /* Clear previous button's text */
2344 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2346 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2349 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2350 nmtb.tbButton.fsStyle, i,
2351 nmtb.tbButton.idCommand,
2352 nmtb.tbButton.iString,
2353 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2356 /* insert button into the apropriate list */
2357 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2360 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2361 btnInfo->bVirtual = FALSE;
2362 btnInfo->bRemovable = TRUE;
2366 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2367 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2370 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2371 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2373 if (lstrlenW(nmtb.pszText))
2374 lstrcpyW(btnInfo->text, nmtb.pszText);
2375 else if (nmtb.tbButton.iString >= 0 &&
2376 nmtb.tbButton.iString < infoPtr->nNumStrings)
2378 lstrcpyW(btnInfo->text,
2379 infoPtr->strings[nmtb.tbButton.iString]);
2384 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2387 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2389 /* select first item in the 'available' list */
2390 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2392 /* append 'virtual' separator button to the 'toolbar buttons' list */
2393 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2394 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2395 btnInfo->btn.fsStyle = BTNS_SEP;
2396 btnInfo->bVirtual = TRUE;
2397 btnInfo->bRemovable = FALSE;
2398 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2399 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2400 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2402 /* select last item in the 'toolbar' list */
2403 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2404 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2406 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2407 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2409 /* set focus and disable buttons */
2410 PostMessageW (hwnd, WM_USER, 0, 0);
2415 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2416 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2417 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2418 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2422 EndDialog(hwnd, FALSE);
2426 switch (LOWORD(wParam))
2428 case IDC_TOOLBARBTN_LBOX:
2429 if (HIWORD(wParam) == LBN_SELCHANGE)
2431 PCUSTOMBUTTON btnInfo;
2436 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2437 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2439 /* send TBN_QUERYINSERT notification */
2441 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2443 /* get list box item */
2444 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2446 if (index == (count - 1))
2448 /* last item (virtual separator) */
2449 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2450 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2452 else if (index == (count - 2))
2454 /* second last item (last non-virtual item) */
2455 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2456 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2458 else if (index == 0)
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2466 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2467 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2470 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2474 case IDC_MOVEUP_BTN:
2476 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2477 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2481 case IDC_MOVEDN_BTN: /* move down */
2483 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2484 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2488 case IDC_REMOVE_BTN: /* remove button */
2490 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2492 if (LB_ERR == index)
2495 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2499 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2502 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2505 case IDOK: /* Add button */
2510 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2511 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2513 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2518 EndDialog(hwnd, FALSE);
2528 /* delete items from 'toolbar buttons' listbox*/
2529 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2530 for (i = 0; i < count; i++)
2532 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2534 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2536 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2539 /* delete items from 'available buttons' listbox*/
2540 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2541 for (i = 0; i < count; i++)
2543 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2545 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2547 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2552 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2554 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2559 COLORREF oldText = 0;
2563 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2564 if (btnInfo == NULL)
2566 FIXME("btnInfo invalid!\n");
2570 /* set colors and select objects */
2571 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2572 if (btnInfo->bVirtual)
2573 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2575 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2576 hPen = CreatePen( PS_SOLID, 1,
2577 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2578 hOldPen = SelectObject (lpdis->hDC, hPen );
2579 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2581 /* fill background rectangle */
2582 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2583 lpdis->rcItem.right, lpdis->rcItem.bottom);
2585 /* calculate button and text rectangles */
2586 CopyRect (&rcButton, &lpdis->rcItem);
2587 InflateRect (&rcButton, -1, -1);
2588 CopyRect (&rcText, &rcButton);
2589 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2590 rcText.left = rcButton.right + 2;
2592 /* draw focus rectangle */
2593 if (lpdis->itemState & ODS_FOCUS)
2594 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2597 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2598 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2600 /* draw image and text */
2601 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2602 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2603 btnInfo->btn.iBitmap));
2604 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2605 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2607 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2608 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2610 /* delete objects and reset colors */
2611 SelectObject (lpdis->hDC, hOldBrush);
2612 SelectObject (lpdis->hDC, hOldPen);
2613 SetBkColor (lpdis->hDC, oldBk);
2614 SetTextColor (lpdis->hDC, oldText);
2615 DeleteObject( hPen );
2620 case WM_MEASUREITEM:
2621 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2623 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2625 lpmis->itemHeight = 15 + 8; /* default height */
2632 if (uDragListMessage && (uMsg == uDragListMessage))
2634 if (wParam == IDC_TOOLBARBTN_LBOX)
2636 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2637 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2638 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2641 else if (wParam == IDC_AVAILBTN_LBOX)
2643 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2644 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2645 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2654 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2657 INT nCountBefore = ImageList_GetImageCount(himlDef);
2663 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2664 /* Add bitmaps to the default image list */
2665 if (bitmap->hInst == NULL) /* a handle was passed */
2666 hbmLoad = (HBITMAP)CopyImage((HBITMAP)bitmap->nID, IMAGE_BITMAP, 0, 0, 0);
2668 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2670 /* enlarge the bitmap if needed */
2671 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2672 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2674 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2675 DeleteObject(hbmLoad);
2679 nCountAfter = ImageList_GetImageCount(himlDef);
2680 nAdded = nCountAfter - nCountBefore;
2681 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2683 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2684 } else if (nAdded > (INT)bitmap->nButtons) {
2685 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2686 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2689 infoPtr->nNumBitmaps += nAdded;
2694 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2701 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2702 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2704 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2706 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2709 TRACE("Update icon size: %dx%d -> %dx%d\n",
2710 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2712 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2713 ILC_COLORDDB|ILC_MASK, 8, 2);
2714 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2715 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2716 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2717 infoPtr->himlInt = himlNew;
2719 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2720 ImageList_Destroy(himlDef);
2723 /***********************************************************************
2724 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2728 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2731 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2736 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2740 if (lpAddBmp->hInst == HINST_COMMCTRL)
2742 info.hInst = COMCTL32_hModule;
2743 switch (lpAddBmp->nID)
2745 case IDB_STD_SMALL_COLOR:
2747 info.nID = IDB_STD_SMALL;
2749 case IDB_STD_LARGE_COLOR:
2751 info.nID = IDB_STD_LARGE;
2753 case IDB_VIEW_SMALL_COLOR:
2755 info.nID = IDB_VIEW_SMALL;
2757 case IDB_VIEW_LARGE_COLOR:
2759 info.nID = IDB_VIEW_LARGE;
2761 case IDB_HIST_SMALL_COLOR:
2763 info.nID = IDB_HIST_SMALL;
2765 case IDB_HIST_LARGE_COLOR:
2767 info.nID = IDB_HIST_LARGE;
2773 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2775 /* Windows resize all the buttons to the size of a newly added standard image */
2776 if (lpAddBmp->nID & 1)
2778 /* large icons: 24x24. Will make the button 31x30 */
2779 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2783 /* small icons: 16x16. Will make the buttons 23x22 */
2784 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2787 TOOLBAR_CalcToolbar (hwnd);
2791 info.nButtons = (INT)wParam;
2792 info.hInst = lpAddBmp->hInst;
2793 info.nID = lpAddBmp->nID;
2794 TRACE("adding %d bitmaps!\n", info.nButtons);
2797 /* check if the bitmap is already loaded and compute iSumButtons */
2799 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2801 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2802 infoPtr->bitmaps[i].nID == info.nID)
2804 iSumButtons += infoPtr->bitmaps[i].nButtons;
2807 if (!infoPtr->cimlDef) {
2808 /* create new default image list */
2809 TRACE ("creating default image list!\n");
2811 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2812 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2813 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2814 infoPtr->himlInt = himlDef;
2817 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2821 WARN("No default image list available\n");
2825 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2828 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2829 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2830 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2831 infoPtr->nNumBitmapInfos++;
2832 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2834 InvalidateRect(hwnd, NULL, TRUE);
2840 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2842 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2843 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2844 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2845 BOOL fHasString = FALSE;
2847 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2849 nAddButtons = (UINT)wParam;
2850 nOldButtons = infoPtr->nNumButtons;
2851 nNewButtons = nOldButtons + nAddButtons;
2853 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2854 infoPtr->nNumButtons = nNewButtons;
2856 /* insert new button data */
2857 for (nCount = 0; nCount < nAddButtons; nCount++) {
2858 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2859 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2860 btnPtr->idCommand = lpTbb[nCount].idCommand;
2861 btnPtr->fsState = lpTbb[nCount].fsState;
2862 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2863 btnPtr->dwData = lpTbb[nCount].dwData;
2864 btnPtr->bHot = FALSE;
2865 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2868 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2870 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2874 btnPtr->iString = lpTbb[nCount].iString;
2876 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2879 if (infoPtr->nNumStrings > 0 || fHasString)
2880 TOOLBAR_CalcToolbar(hwnd);
2882 TOOLBAR_LayoutToolbar(hwnd);
2883 TOOLBAR_AutoSize (hwnd);
2885 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2887 InvalidateRect(hwnd, NULL, TRUE);
2894 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2896 #define MAX_RESOURCE_STRING_LENGTH 512
2897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2898 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2899 INT nIndex = infoPtr->nNumStrings;
2901 if ((wParam) && (HIWORD(lParam) == 0)) {
2902 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2907 TRACE("adding string from resource!\n");
2909 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2910 szString, MAX_RESOURCE_STRING_LENGTH);
2912 TRACE("len=%d %s\n", len, debugstr_w(szString));
2913 if (len == 0 || len == 1)
2916 TRACE("Delimiter: 0x%x\n", *szString);
2917 delimiter = *szString;
2920 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2922 if (next_delim + 1 >= szString + len)
2924 /* this may happen if delimiter == '\0' or if the last char is a
2925 * delimiter (then it is ignored like the native does) */
2929 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2930 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2931 infoPtr->nNumStrings++;
2937 LPWSTR p = (LPWSTR)lParam;
2942 TRACE("adding string(s) from array!\n");
2946 TRACE("len=%d %s\n", len, debugstr_w(p));
2947 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2948 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2949 infoPtr->nNumStrings++;
2956 TOOLBAR_CalcToolbar(hwnd);
2962 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2964 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2965 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2970 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2971 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2977 TRACE("adding string(s) from array!\n");
2978 nIndex = infoPtr->nNumStrings;
2981 TRACE("len=%d \"%s\"\n", len, p);
2983 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2984 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2985 infoPtr->nNumStrings++;
2991 TOOLBAR_CalcToolbar(hwnd);
2997 TOOLBAR_AutoSize (HWND hwnd)
2999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3005 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3007 parent = GetParent (hwnd);
3009 if (!parent || !infoPtr->bDoRedraw)
3012 GetClientRect(parent, &parent_rect);
3014 x = parent_rect.left;
3015 y = parent_rect.top;
3017 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3019 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3020 cx = parent_rect.right - parent_rect.left;
3022 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3024 TOOLBAR_LayoutToolbar(hwnd);
3025 InvalidateRect( hwnd, NULL, TRUE );
3028 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3031 UINT uPosFlags = SWP_NOZORDER;
3033 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3035 GetWindowRect(hwnd, &window_rect);
3036 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3037 y = window_rect.top;
3039 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3041 GetWindowRect(hwnd, &window_rect);
3042 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3045 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3046 uPosFlags |= SWP_NOMOVE;
3048 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3049 cy += GetSystemMetrics(SM_CYEDGE);
3051 if (infoPtr->dwStyle & WS_BORDER)
3053 x = y = 1; /* FIXME: this looks wrong */
3054 cy += GetSystemMetrics(SM_CYEDGE);
3055 cx += GetSystemMetrics(SM_CXEDGE);
3058 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3066 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3070 return infoPtr->nNumButtons;
3075 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3079 infoPtr->dwStructSize = (DWORD)wParam;
3086 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 TBUTTON_INFO *btnPtr;
3092 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3094 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3098 btnPtr = &infoPtr->buttons[nIndex];
3099 btnPtr->iBitmap = LOWORD(lParam);
3101 /* we HAVE to erase the background, the new bitmap could be */
3103 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3110 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3113 TBUTTON_INFO *btnPtr;
3116 BOOL bChecked = FALSE;
3118 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3120 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3125 btnPtr = &infoPtr->buttons[nIndex];
3127 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3129 if (LOWORD(lParam) == FALSE)
3130 btnPtr->fsState &= ~TBSTATE_CHECKED;
3132 if (btnPtr->fsStyle & BTNS_GROUP) {
3134 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3135 if (nOldIndex == nIndex)
3137 if (nOldIndex != -1)
3138 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3140 btnPtr->fsState |= TBSTATE_CHECKED;
3143 if( bChecked != LOWORD(lParam) )
3145 if (nOldIndex != -1)
3146 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3147 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3150 /* FIXME: Send a WM_NOTIFY?? */
3157 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3161 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3166 TOOLBAR_Customize (HWND hwnd)
3168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3169 CUSTDLG_INFO custInfo;
3175 custInfo.tbInfo = infoPtr;
3176 custInfo.tbHwnd = hwnd;
3178 /* send TBN_BEGINADJUST notification */
3179 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3181 if (!(hRes = FindResourceW (COMCTL32_hModule,
3182 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3183 (LPWSTR)RT_DIALOG)))
3186 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3189 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3190 (LPCDLGTEMPLATEW)template,
3192 TOOLBAR_CustomizeDialogProc,
3195 /* send TBN_ENDADJUST notification */
3196 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3203 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3206 INT nIndex = (INT)wParam;
3208 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3210 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3213 memset(&nmtb, 0, sizeof(nmtb));
3214 nmtb.iItem = btnPtr->idCommand;
3215 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3216 nmtb.tbButton.idCommand = btnPtr->idCommand;
3217 nmtb.tbButton.fsState = btnPtr->fsState;
3218 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3219 nmtb.tbButton.dwData = btnPtr->dwData;
3220 nmtb.tbButton.iString = btnPtr->iString;
3221 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3223 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3225 if (infoPtr->nNumButtons == 1) {
3226 TRACE(" simple delete!\n");
3227 Free (infoPtr->buttons);
3228 infoPtr->buttons = NULL;
3229 infoPtr->nNumButtons = 0;
3232 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3233 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3235 infoPtr->nNumButtons--;
3236 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3238 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3239 nIndex * sizeof(TBUTTON_INFO));
3242 if (nIndex < infoPtr->nNumButtons) {
3243 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3244 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3250 TOOLBAR_LayoutToolbar(hwnd);
3252 InvalidateRect (hwnd, NULL, TRUE);
3259 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3261 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3262 TBUTTON_INFO *btnPtr;
3266 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3268 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3273 btnPtr = &infoPtr->buttons[nIndex];
3275 bState = btnPtr->fsState & TBSTATE_ENABLED;
3277 /* update the toolbar button state */
3278 if(LOWORD(lParam) == FALSE) {
3279 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3281 btnPtr->fsState |= TBSTATE_ENABLED;
3284 /* redraw the button only if the state of the button changed */
3285 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3286 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3292 static inline LRESULT
3293 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3295 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3297 return infoPtr->bAnchor;
3302 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3307 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3311 return infoPtr->buttons[nIndex].iBitmap;
3315 static inline LRESULT
3316 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3318 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3323 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3326 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3327 INT nIndex = (INT)wParam;
3328 TBUTTON_INFO *btnPtr;
3333 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3336 btnPtr = &infoPtr->buttons[nIndex];
3337 lpTbb->iBitmap = btnPtr->iBitmap;
3338 lpTbb->idCommand = btnPtr->idCommand;
3339 lpTbb->fsState = btnPtr->fsState;
3340 lpTbb->fsStyle = btnPtr->fsStyle;
3341 lpTbb->bReserved[0] = 0;
3342 lpTbb->bReserved[1] = 0;
3343 lpTbb->dwData = btnPtr->dwData;
3344 lpTbb->iString = btnPtr->iString;
3351 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3354 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3355 TBUTTON_INFO *btnPtr;
3358 if (lpTbInfo == NULL)
3360 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3363 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3364 lpTbInfo->dwMask & 0x80000000);
3368 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3370 if (lpTbInfo->dwMask & TBIF_COMMAND)
3371 lpTbInfo->idCommand = btnPtr->idCommand;
3372 if (lpTbInfo->dwMask & TBIF_IMAGE)
3373 lpTbInfo->iImage = btnPtr->iBitmap;
3374 if (lpTbInfo->dwMask & TBIF_LPARAM)
3375 lpTbInfo->lParam = btnPtr->dwData;
3376 if (lpTbInfo->dwMask & TBIF_SIZE)
3377 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3378 if (lpTbInfo->dwMask & TBIF_STATE)
3379 lpTbInfo->fsState = btnPtr->fsState;
3380 if (lpTbInfo->dwMask & TBIF_STYLE)
3381 lpTbInfo->fsStyle = btnPtr->fsStyle;
3382 if (lpTbInfo->dwMask & TBIF_TEXT) {
3383 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3384 can't use TOOLBAR_GetText here */
3386 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3387 lpText = (LPWSTR)btnPtr->iString;
3388 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3390 lpTbInfo->pszText[0] = '\0';
3397 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3399 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3400 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3401 TBUTTON_INFO *btnPtr;
3404 if (lpTbInfo == NULL)
3406 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3409 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3410 lpTbInfo->dwMask & 0x80000000);
3414 btnPtr = &infoPtr->buttons[nIndex];
3419 if (lpTbInfo->dwMask & TBIF_COMMAND)
3420 lpTbInfo->idCommand = btnPtr->idCommand;
3421 if (lpTbInfo->dwMask & TBIF_IMAGE)
3422 lpTbInfo->iImage = btnPtr->iBitmap;
3423 if (lpTbInfo->dwMask & TBIF_LPARAM)
3424 lpTbInfo->lParam = btnPtr->dwData;
3425 if (lpTbInfo->dwMask & TBIF_SIZE)
3426 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3427 if (lpTbInfo->dwMask & TBIF_STATE)
3428 lpTbInfo->fsState = btnPtr->fsState;
3429 if (lpTbInfo->dwMask & TBIF_STYLE)
3430 lpTbInfo->fsStyle = btnPtr->fsStyle;
3431 if (lpTbInfo->dwMask & TBIF_TEXT) {
3432 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3433 can't use TOOLBAR_GetText here */
3435 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3436 lpText = (LPWSTR)btnPtr->iString;
3437 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3439 lpTbInfo->pszText[0] = '\0';
3447 TOOLBAR_GetButtonSize (HWND hwnd)
3449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3451 return MAKELONG((WORD)infoPtr->nButtonWidth,
3452 (WORD)infoPtr->nButtonHeight);
3457 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3466 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3470 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3472 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3473 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3478 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3485 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3489 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3493 ret = strlenW (lpText);
3496 strcpyW ((LPWSTR)lParam, lpText);
3504 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3506 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3507 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3508 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3512 static inline LRESULT
3513 TOOLBAR_GetExtendedStyle (HWND hwnd)
3515 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3519 return infoPtr->dwExStyle;
3524 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3526 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3527 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3528 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3533 TOOLBAR_GetHotItem (HWND hwnd)
3535 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3537 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3540 if (infoPtr->nHotItem < 0)
3543 return (LRESULT)infoPtr->nHotItem;
3548 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3550 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3551 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3552 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3557 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3559 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3560 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3562 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3564 *lptbim = infoPtr->tbim;
3571 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3573 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3575 TRACE("hwnd = %p\n", hwnd);
3577 return (LRESULT)infoPtr->clrInsertMark;
3582 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 TBUTTON_INFO *btnPtr;
3589 nIndex = (INT)wParam;
3590 btnPtr = &infoPtr->buttons[nIndex];
3591 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3593 lpRect = (LPRECT)lParam;
3596 if (btnPtr->fsState & TBSTATE_HIDDEN)
3599 lpRect->left = btnPtr->rect.left;
3600 lpRect->right = btnPtr->rect.right;
3601 lpRect->bottom = btnPtr->rect.bottom;
3602 lpRect->top = btnPtr->rect.top;
3609 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3611 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3612 LPSIZE lpSize = (LPSIZE)lParam;
3617 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3618 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3620 TRACE("maximum size %d x %d\n",
3621 infoPtr->rcBound.right - infoPtr->rcBound.left,
3622 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3628 /* << TOOLBAR_GetObject >> */
3632 TOOLBAR_GetPadding (HWND hwnd)
3634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3637 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3638 return (LRESULT) oldPad;
3643 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3645 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3646 TBUTTON_INFO *btnPtr;
3650 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3651 btnPtr = &infoPtr->buttons[nIndex];
3652 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3654 lpRect = (LPRECT)lParam;
3658 lpRect->left = btnPtr->rect.left;
3659 lpRect->right = btnPtr->rect.right;
3660 lpRect->bottom = btnPtr->rect.bottom;
3661 lpRect->top = btnPtr->rect.top;
3668 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3672 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3673 return infoPtr->nRows;
3680 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3685 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3689 return infoPtr->buttons[nIndex].fsState;
3694 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3696 return GetWindowLongW(hwnd, GWL_STYLE);
3701 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3705 return infoPtr->nMaxTextRows;
3710 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3712 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3714 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3715 TOOLBAR_TooltipCreateControl(infoPtr);
3716 return (LRESULT)infoPtr->hwndToolTip;
3721 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3725 TRACE("%s hwnd=%p\n",
3726 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3728 return infoPtr->bUnicode;
3732 static inline LRESULT
3733 TOOLBAR_GetVersion (HWND hwnd)
3735 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3736 return infoPtr->iVersion;
3741 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3744 TBUTTON_INFO *btnPtr;
3749 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3753 btnPtr = &infoPtr->buttons[nIndex];
3754 if (LOWORD(lParam) == FALSE)
3755 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3757 btnPtr->fsState |= TBSTATE_HIDDEN;
3759 TOOLBAR_CalcToolbar (hwnd);
3761 InvalidateRect (hwnd, NULL, TRUE);
3767 static inline LRESULT
3768 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3770 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3775 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3778 TBUTTON_INFO *btnPtr;
3782 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3786 btnPtr = &infoPtr->buttons[nIndex];
3787 oldState = btnPtr->fsState;
3788 if (LOWORD(lParam) == FALSE)
3789 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3791 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3793 if(oldState != btnPtr->fsState)
3794 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3801 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3803 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3804 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3805 INT nIndex = (INT)wParam;
3810 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3813 /* EPP: this seems to be an undocumented call (from my IE4)
3814 * I assume in that case that:
3815 * - index of insertion is at the end of existing buttons
3816 * I only see this happen with nIndex == -1, but it could have a special
3817 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3819 nIndex = infoPtr->nNumButtons;
3821 } else if (nIndex < 0)
3824 TRACE("inserting button index=%d\n", nIndex);
3825 if (nIndex > infoPtr->nNumButtons) {
3826 nIndex = infoPtr->nNumButtons;
3827 TRACE("adjust index=%d\n", nIndex);
3830 infoPtr->nNumButtons++;
3831 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3832 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3833 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3835 /* insert new button */
3836 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3837 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3838 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3839 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3840 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3841 /* if passed string and not index, then add string */
3842 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3844 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3846 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3849 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3851 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3853 if (infoPtr->nNumStrings > 0)
3854 TOOLBAR_CalcToolbar(hwnd);
3856 TOOLBAR_LayoutToolbar(hwnd);
3857 TOOLBAR_AutoSize (hwnd);
3859 InvalidateRect (hwnd, NULL, TRUE);
3864 /* << TOOLBAR_InsertMarkHitTest >> */
3868 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3873 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3877 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3882 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3887 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3891 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3896 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3901 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3905 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3910 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3915 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3919 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3924 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3926 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3929 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3933 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3938 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3943 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3947 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3952 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3955 tbab.hInst = (HINSTANCE)lParam;
3956 tbab.nID = (UINT_PTR)wParam;
3958 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3960 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3965 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3967 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3968 WCHAR wAccel = (WCHAR)wParam;
3969 UINT* pIDButton = (UINT*)lParam;
3970 WCHAR wszAccel[] = {'&',wAccel,0};
3973 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3974 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3976 for (i = 0; i < infoPtr->nNumButtons; i++)
3978 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3979 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3980 !(btnPtr->fsState & TBSTATE_HIDDEN))
3982 int iLen = strlenW(wszAccel);
3983 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3990 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3995 if (!strncmpiW(lpszStr, wszAccel, iLen))
3997 *pIDButton = btnPtr->idCommand;
4009 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4014 TBUTTON_INFO *btnPtr;
4016 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4018 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4022 btnPtr = &infoPtr->buttons[nIndex];
4023 oldState = btnPtr->fsState;
4026 btnPtr->fsState |= TBSTATE_MARKED;
4028 btnPtr->fsState &= ~TBSTATE_MARKED;
4030 if(oldState != btnPtr->fsState)
4031 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4037 /* fixes up an index of a button affected by a move */
4038 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4042 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4044 else if (*pIndex == nIndex)
4045 *pIndex = nMoveIndex;
4049 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4051 else if (*pIndex == nIndex)
4052 *pIndex = nMoveIndex;
4058 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4060 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4063 INT nMoveIndex = (INT)lParam;
4064 TBUTTON_INFO button;
4066 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4068 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4069 if ((nIndex == -1) || (nMoveIndex < 0))
4072 if (nMoveIndex > infoPtr->nNumButtons - 1)
4073 nMoveIndex = infoPtr->nNumButtons - 1;
4075 button = infoPtr->buttons[nIndex];
4077 /* move button right */
4078 if (nIndex < nMoveIndex)
4080 nCount = nMoveIndex - nIndex;
4081 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4082 infoPtr->buttons[nMoveIndex] = button;
4084 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4085 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4086 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4087 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4089 else if (nIndex > nMoveIndex) /* move button left */
4091 nCount = nIndex - nMoveIndex;
4092 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4093 infoPtr->buttons[nMoveIndex] = button;
4095 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4096 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4097 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4098 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4101 TOOLBAR_CalcToolbar(hwnd);
4102 TOOLBAR_AutoSize(hwnd);
4103 InvalidateRect(hwnd, NULL, TRUE);
4110 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4113 TBUTTON_INFO *btnPtr;
4117 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4121 btnPtr = &infoPtr->buttons[nIndex];
4122 oldState = btnPtr->fsState;
4123 if (LOWORD(lParam) == FALSE)
4124 btnPtr->fsState &= ~TBSTATE_PRESSED;
4126 btnPtr->fsState |= TBSTATE_PRESSED;
4128 if(oldState != btnPtr->fsState)
4129 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4134 /* FIXME: there might still be some confusion her between number of buttons
4135 * and number of bitmaps */
4137 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4139 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4140 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4142 int i = 0, nOldButtons = 0, pos = 0;
4143 int nOldBitmaps, nNewBitmaps = 0;
4144 HIMAGELIST himlDef = 0;
4146 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4147 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4148 lpReplace->nButtons);
4150 if (lpReplace->hInstOld == HINST_COMMCTRL)
4152 FIXME("changing standard bitmaps not implemented\n");
4155 else if (lpReplace->hInstOld != 0)
4156 FIXME("resources not in the current module not implemented\n");
4158 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4159 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4160 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4161 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4162 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4164 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4165 nOldButtons = tbi->nButtons;
4166 tbi->nButtons = lpReplace->nButtons;
4167 tbi->hInst = lpReplace->hInstNew;
4168 tbi->nID = lpReplace->nIDNew;
4169 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4172 pos += tbi->nButtons;
4175 if (nOldButtons == 0)
4177 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4181 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4184 if (lpReplace->hInstNew)
4185 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4187 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4189 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4190 nOldBitmaps = ImageList_GetImageCount(himlDef);
4192 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4194 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4195 ImageList_Remove(himlDef, i);
4199 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4200 nNewBitmaps = ImageList_GetImageCount(himlDef);
4201 DeleteObject(hBitmap);
4204 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4206 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4207 pos, nOldBitmaps, nNewBitmaps);
4209 InvalidateRect(hwnd, NULL, TRUE);
4214 /* helper for TOOLBAR_SaveRestoreW */
4216 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4218 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4219 debugstr_w(lpSave->pszValueName));
4225 /* helper for TOOLBAR_Restore */
4227 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4231 for (i = 0; i < infoPtr->nNumButtons; i++)
4233 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4236 Free(infoPtr->buttons);
4237 infoPtr->buttons = NULL;
4238 infoPtr->nNumButtons = 0;
4242 /* helper for TOOLBAR_SaveRestoreW */
4244 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4253 /* restore toolbar information */
4254 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4255 debugstr_w(lpSave->pszValueName));
4257 memset(&nmtbr, 0, sizeof(nmtbr));
4259 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4260 KEY_QUERY_VALUE, &hkey);
4262 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4264 if (!res && dwType != REG_BINARY)
4265 res = ERROR_FILE_NOT_FOUND;
4268 nmtbr.pData = Alloc(dwSize);
4269 nmtbr.cbData = (UINT)dwSize;
4270 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4273 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4274 (LPBYTE)nmtbr.pData, &dwSize);
4277 nmtbr.pCurrent = nmtbr.pData;
4279 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4280 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4282 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4286 /* remove all existing buttons as this function is designed to
4287 * restore the toolbar to a previously saved state */
4288 TOOLBAR_DeleteAllButtons(infoPtr);
4290 for (i = 0; i < nmtbr.cButtons; i++)
4293 nmtbr.tbButton.iBitmap = -1;
4294 nmtbr.tbButton.fsState = 0;
4295 nmtbr.tbButton.fsStyle = 0;
4296 nmtbr.tbButton.idCommand = 0;
4297 if (*nmtbr.pCurrent == (DWORD)-1)
4300 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4301 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4303 else if (*nmtbr.pCurrent == (DWORD)-2)
4305 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4307 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4311 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4313 /* can't contain real string as we don't know whether
4314 * the client put an ANSI or Unicode string in there */
4315 if (HIWORD(nmtbr.tbButton.iString))
4316 nmtbr.tbButton.iString = 0;
4318 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4319 (LPARAM)&nmtbr.tbButton, TRUE);
4322 /* do legacy notifications */
4323 if (infoPtr->iVersion < 5)
4325 /* FIXME: send TBN_BEGINADJUST */
4326 FIXME("send TBN_GETBUTTONINFO for each button\n");
4327 /* FIXME: send TBN_ENDADJUST */
4330 /* remove all uninitialised buttons
4331 * note: loop backwards to avoid having to fixup i on a
4333 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4334 if (infoPtr->buttons[i].iBitmap == -1)
4335 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4337 /* only indicate success if at least one button survived */
4338 if (infoPtr->nNumButtons > 0) ret = TRUE;
4349 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4353 if (lpSave == NULL) return 0;
4356 return TOOLBAR_Save(infoPtr, lpSave);
4358 return TOOLBAR_Restore(infoPtr, lpSave);
4363 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4365 LPWSTR pszValueName = 0, pszSubKey = 0;
4366 TBSAVEPARAMSW SaveW;
4370 if (lpSave == NULL) return 0;
4372 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4373 pszSubKey = Alloc(len * sizeof(WCHAR));
4374 if (pszSubKey) goto exit;
4375 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4377 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4378 pszValueName = Alloc(len * sizeof(WCHAR));
4379 if (!pszValueName) goto exit;
4380 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4382 SaveW.pszValueName = pszValueName;
4383 SaveW.pszSubKey = pszSubKey;
4384 SaveW.hkr = lpSave->hkr;
4385 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4388 Free (pszValueName);
4396 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4398 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4399 BOOL bOldAnchor = infoPtr->bAnchor;
4401 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4403 infoPtr->bAnchor = (BOOL)wParam;
4405 /* Native does not remove the hot effect from an already hot button */
4407 return (LRESULT)bOldAnchor;
4412 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4415 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4417 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4420 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4422 if (LOWORD(lParam) == 0)
4423 lParam = MAKELPARAM(1, HIWORD(lParam));
4425 if (HIWORD(lParam)==0)
4426 lParam = MAKELPARAM(LOWORD(lParam), 1);
4428 if (infoPtr->nNumButtons > 0)
4429 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4430 infoPtr->nNumButtons,
4431 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4432 LOWORD(lParam), HIWORD(lParam));
4434 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4435 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4437 if ((himlDef == infoPtr->himlInt) &&
4438 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4440 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4441 infoPtr->nBitmapHeight);
4444 TOOLBAR_CalcToolbar(hwnd);
4445 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4451 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4454 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4455 TBUTTON_INFO *btnPtr;
4461 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4464 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4465 lptbbi->dwMask & 0x80000000);
4469 btnPtr = &infoPtr->buttons[nIndex];
4470 if (lptbbi->dwMask & TBIF_COMMAND)
4471 btnPtr->idCommand = lptbbi->idCommand;
4472 if (lptbbi->dwMask & TBIF_IMAGE)
4473 btnPtr->iBitmap = lptbbi->iImage;
4474 if (lptbbi->dwMask & TBIF_LPARAM)
4475 btnPtr->dwData = lptbbi->lParam;
4476 if (lptbbi->dwMask & TBIF_SIZE)
4477 btnPtr->cx = lptbbi->cx;
4478 if (lptbbi->dwMask & TBIF_STATE)
4479 btnPtr->fsState = lptbbi->fsState;
4480 if (lptbbi->dwMask & TBIF_STYLE)
4481 btnPtr->fsStyle = lptbbi->fsStyle;
4483 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4484 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4485 /* iString is index, zero it to make Str_SetPtr succeed */
4488 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4491 /* save the button rect to see if we need to redraw the whole toolbar */
4492 oldBtnRect = btnPtr->rect;
4493 TOOLBAR_CalcToolbar(hwnd);
4495 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4496 InvalidateRect(hwnd, NULL, TRUE);
4498 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4505 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4508 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4509 TBUTTON_INFO *btnPtr;
4515 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4518 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4519 lptbbi->dwMask & 0x80000000);
4523 btnPtr = &infoPtr->buttons[nIndex];
4524 if (lptbbi->dwMask & TBIF_COMMAND)
4525 btnPtr->idCommand = lptbbi->idCommand;
4526 if (lptbbi->dwMask & TBIF_IMAGE)
4527 btnPtr->iBitmap = lptbbi->iImage;
4528 if (lptbbi->dwMask & TBIF_LPARAM)
4529 btnPtr->dwData = lptbbi->lParam;
4530 if (lptbbi->dwMask & TBIF_SIZE)
4531 btnPtr->cx = lptbbi->cx;
4532 if (lptbbi->dwMask & TBIF_STATE)
4533 btnPtr->fsState = lptbbi->fsState;
4534 if (lptbbi->dwMask & TBIF_STYLE)
4535 btnPtr->fsStyle = lptbbi->fsStyle;
4537 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4538 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4539 /* iString is index, zero it to make Str_SetPtr succeed */
4541 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4544 /* save the button rect to see if we need to redraw the whole toolbar */
4545 oldBtnRect = btnPtr->rect;
4546 TOOLBAR_CalcToolbar(hwnd);
4548 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4549 InvalidateRect(hwnd, NULL, TRUE);
4551 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4558 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4560 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4561 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4563 if ((cx < 0) || (cy < 0))
4565 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4569 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4571 /* The documentation claims you can only change the button size before
4572 * any button has been added. But this is wrong.
4573 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4574 * it to the toolbar, and it checks that the return value is nonzero - mjm
4575 * Further testing shows that we must actually perform the change too.
4578 * The documentation also does not mention that if 0 is supplied for
4579 * either size, the system changes it to the default of 24 wide and
4580 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4582 if (cx == 0) cx = 24;
4583 if (cy == 0) cx = 22;
4585 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4586 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4588 infoPtr->nButtonWidth = cx;
4589 infoPtr->nButtonHeight = cy;
4591 infoPtr->iTopMargin = default_top_margin(infoPtr);
4592 TOOLBAR_LayoutToolbar(hwnd);
4598 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4600 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4602 /* if setting to current values, ignore */
4603 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4604 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4605 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4606 infoPtr->cxMin, infoPtr->cxMax);
4610 /* save new values */
4611 infoPtr->cxMin = (short)LOWORD(lParam);
4612 infoPtr->cxMax = (short)HIWORD(lParam);
4614 /* otherwise we need to recalc the toolbar and in some cases
4615 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4616 which doesn't actually draw - GA). */
4617 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4618 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4620 TOOLBAR_CalcToolbar (hwnd);
4622 InvalidateRect (hwnd, NULL, TRUE);
4629 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4632 INT nIndex = (INT)wParam;
4634 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4637 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4639 if (infoPtr->hwndToolTip) {
4641 FIXME("change tool tip!\n");
4650 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4653 HIMAGELIST himl = (HIMAGELIST)lParam;
4654 HIMAGELIST himlTemp;
4657 if (infoPtr->iVersion >= 5)
4660 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4661 &infoPtr->cimlDis, himl, id);
4663 /* FIXME: redraw ? */
4665 return (LRESULT)himlTemp;
4670 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4675 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4677 dwTemp = infoPtr->dwDTFlags;
4678 infoPtr->dwDTFlags =
4679 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4681 return (LRESULT)dwTemp;
4684 /* This function differs a bit from what MSDN says it does:
4685 * 1. lParam contains extended style flags to OR with current style
4686 * (MSDN isn't clear on the OR bit)
4687 * 2. wParam appears to contain extended style flags to be reset
4688 * (MSDN says that this parameter is reserved)
4691 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4696 dwTemp = infoPtr->dwExStyle;
4697 infoPtr->dwExStyle &= ~wParam;
4698 infoPtr->dwExStyle |= (DWORD)lParam;
4700 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4702 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4703 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4704 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4706 TOOLBAR_CalcToolbar (hwnd);
4708 TOOLBAR_AutoSize(hwnd);
4710 InvalidateRect(hwnd, NULL, TRUE);
4712 return (LRESULT)dwTemp;
4717 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4719 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4720 HIMAGELIST himlTemp;
4721 HIMAGELIST himl = (HIMAGELIST)lParam;
4724 if (infoPtr->iVersion >= 5)
4727 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4729 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4730 &infoPtr->cimlHot, himl, id);
4732 /* FIXME: redraw ? */
4734 return (LRESULT)himlTemp;
4738 /* Makes previous hot button no longer hot, makes the specified
4739 * button hot and sends appropriate notifications. dwReason is one or
4740 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4741 * NOTE 1: this function does not validate nHit
4742 * NOTE 2: the name of this function is completely made up and
4743 * not based on any documentation from Microsoft. */
4745 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4747 if (infoPtr->nHotItem != nHit)
4749 NMTBHOTITEM nmhotitem;
4750 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4752 nmhotitem.dwFlags = dwReason;
4753 if(infoPtr->nHotItem >= 0)
4755 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4756 nmhotitem.idOld = oldBtnPtr->idCommand;
4760 nmhotitem.dwFlags |= HICF_ENTERING;
4761 nmhotitem.idOld = 0;
4766 btnPtr = &infoPtr->buttons[nHit];
4767 nmhotitem.idNew = btnPtr->idCommand;
4771 nmhotitem.dwFlags |= HICF_LEAVING;
4772 nmhotitem.idNew = 0;
4775 /* now change the hot and invalidate the old and new buttons - if the
4777 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4780 oldBtnPtr->bHot = FALSE;
4781 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4783 /* setting disabled buttons as hot fails even if the notify contains the button id */
4784 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4785 btnPtr->bHot = TRUE;
4786 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4787 infoPtr->nHotItem = nHit;
4790 infoPtr->nHotItem = -1;
4796 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4798 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4799 INT nOldHotItem = infoPtr->nHotItem;
4801 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4803 if ((INT)wParam > infoPtr->nNumButtons)
4804 return infoPtr->nHotItem;
4806 if ((INT)wParam < 0)
4809 /* NOTE: an application can still remove the hot item even if anchor
4810 * highlighting is enabled */
4812 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4814 if (nOldHotItem < 0)
4817 return (LRESULT)nOldHotItem;
4822 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4824 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4825 HIMAGELIST himlTemp;
4826 HIMAGELIST himl = (HIMAGELIST)lParam;
4829 if (infoPtr->iVersion >= 5)
4832 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4833 &infoPtr->cimlDef, himl, id);
4835 infoPtr->nNumBitmaps = 0;
4836 for (i = 0; i < infoPtr->cimlDef; i++)
4837 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4839 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4840 &infoPtr->nBitmapHeight))
4842 infoPtr->nBitmapWidth = 1;
4843 infoPtr->nBitmapHeight = 1;
4845 TOOLBAR_CalcToolbar(hwnd);
4847 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4848 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4849 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4851 InvalidateRect(hwnd, NULL, TRUE);
4853 return (LRESULT)himlTemp;
4858 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4862 infoPtr->nIndent = (INT)wParam;
4866 /* process only on indent changing */
4867 if(infoPtr->nIndent != (INT)wParam)
4869 infoPtr->nIndent = (INT)wParam;
4870 TOOLBAR_CalcToolbar (hwnd);
4871 InvalidateRect(hwnd, NULL, FALSE);
4879 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4882 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4884 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4886 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4888 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4892 if ((lptbim->iButton == -1) ||
4893 ((lptbim->iButton < infoPtr->nNumButtons) &&
4894 (lptbim->iButton >= 0)))
4896 infoPtr->tbim = *lptbim;
4897 /* FIXME: don't need to update entire toolbar */
4898 InvalidateRect(hwnd, NULL, TRUE);
4901 ERR("Invalid button index %d\n", lptbim->iButton);
4908 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4910 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4912 infoPtr->clrInsertMark = (COLORREF)lParam;
4914 /* FIXME: don't need to update entire toolbar */
4915 InvalidateRect(hwnd, NULL, TRUE);
4922 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4926 infoPtr->nMaxTextRows = (INT)wParam;
4928 TOOLBAR_CalcToolbar(hwnd);
4933 /* MSDN gives slightly wrong info on padding.
4934 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4935 * 2. It is not used to create a blank area between the edge of the button
4936 * and the text or image if TBSTYLE_LIST is set. It is used to control
4937 * the gap between the image and text.
4938 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4939 * to control the bottom and right borders [with the border being
4940 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4941 * is shared evenly on both sides of the button.
4942 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4945 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4950 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4951 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4952 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4953 TRACE("cx=%d, cy=%d\n",
4954 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4955 return (LRESULT) oldPad;
4960 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4967 hwndOldNotify = infoPtr->hwndNotify;
4968 infoPtr->hwndNotify = (HWND)wParam;
4970 return (LRESULT)hwndOldNotify;
4975 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4978 LPRECT lprc = (LPRECT)lParam;
4982 if (LOWORD(wParam) > 1) {
4983 FIXME("multiple rows not supported!\n");
4986 if(infoPtr->nRows != LOWORD(wParam))
4988 infoPtr->nRows = LOWORD(wParam);
4990 /* recalculate toolbar */
4991 TOOLBAR_CalcToolbar (hwnd);
4993 /* repaint toolbar */
4994 InvalidateRect(hwnd, NULL, TRUE);
4997 /* return bounding rectangle */
4999 lprc->left = infoPtr->rcBound.left;
5000 lprc->right = infoPtr->rcBound.right;
5001 lprc->top = infoPtr->rcBound.top;
5002 lprc->bottom = infoPtr->rcBound.bottom;
5010 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5013 TBUTTON_INFO *btnPtr;
5016 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5020 btnPtr = &infoPtr->buttons[nIndex];
5022 /* if hidden state has changed the invalidate entire window and recalc */
5023 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5024 btnPtr->fsState = LOWORD(lParam);
5025 TOOLBAR_CalcToolbar (hwnd);
5026 InvalidateRect(hwnd, 0, TRUE);
5030 /* process state changing if current state doesn't match new state */
5031 if(btnPtr->fsState != LOWORD(lParam))
5033 btnPtr->fsState = LOWORD(lParam);
5034 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5042 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5044 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5050 static inline LRESULT
5051 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5055 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5057 infoPtr->hwndToolTip = (HWND)wParam;
5063 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5068 TRACE("%s hwnd=%p\n",
5069 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5071 bTemp = infoPtr->bUnicode;
5072 infoPtr->bUnicode = (BOOL)wParam;
5079 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5083 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5084 comctl32_color.clrBtnHighlight :
5085 infoPtr->clrBtnHighlight;
5086 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5087 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5093 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5097 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
5098 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5099 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5101 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5102 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5103 InvalidateRect(hwnd, NULL, TRUE);
5109 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5112 INT iOldVersion = infoPtr->iVersion;
5114 infoPtr->iVersion = iVersion;
5116 if (infoPtr->iVersion >= 5)
5117 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5124 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5126 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5127 WORD iString = HIWORD(wParam);
5128 WORD buffersize = LOWORD(wParam);
5129 LPSTR str = (LPSTR)lParam;
5132 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5134 if (iString < infoPtr->nNumStrings)
5136 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5138 TRACE("returning %s\n", debugstr_a(str));
5141 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5148 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5151 WORD iString = HIWORD(wParam);
5152 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5153 LPWSTR str = (LPWSTR)lParam;
5156 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5158 if (iString < infoPtr->nNumStrings)
5160 len = min(len, strlenW(infoPtr->strings[iString]));
5161 ret = (len+1)*sizeof(WCHAR);
5162 memcpy(str, infoPtr->strings[iString], ret);
5165 TRACE("returning %s\n", debugstr_w(str));
5168 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5173 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5174 * is the maximum size of the toolbar? */
5175 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5177 SIZE * pSize = (SIZE*)lParam;
5178 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5183 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5184 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5185 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5188 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5191 INT nOldHotItem = infoPtr->nHotItem;
5193 TRACE("old item=%d, new item=%d, flags=%08x\n",
5194 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5196 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5199 /* NOTE: an application can still remove the hot item even if anchor
5200 * highlighting is enabled */
5202 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5206 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5209 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5210 * which controls the amount of spacing between the image and the text
5211 * of buttons for TBSTYLE_LIST toolbars. */
5212 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5216 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5219 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5221 infoPtr->iListGap = (INT)wParam;
5223 InvalidateRect(hwnd, NULL, TRUE);
5228 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5229 * of image lists associated with the various states. */
5230 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5234 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5236 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5240 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5243 LPSIZE lpsize = (LPSIZE)lParam;
5249 * Testing shows the following:
5250 * wParam = 0 adjust cx value
5251 * = 1 set cy value to max size.
5252 * lParam pointer to SIZE structure
5255 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5256 wParam, lParam, lpsize->cx, lpsize->cy);
5260 if (lpsize->cx == -1) {
5261 /* **** this is wrong, native measures each button and sets it */
5262 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5264 else if(HIWORD(lpsize->cx)) {
5266 HWND hwndParent = GetParent(hwnd);
5268 GetWindowRect(hwnd, &rc);
5269 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5270 TRACE("mapped to (%d,%d)-(%d,%d)\n",
5271 rc.left, rc.top, rc.right, rc.bottom);
5272 lpsize->cx = max(rc.right-rc.left,
5273 infoPtr->rcBound.right - infoPtr->rcBound.left);
5276 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5280 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5283 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5287 TRACE("[0463] set to -> 0x%08x 0x%08x\n",
5288 lpsize->cx, lpsize->cy);
5292 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5296 InvalidateRect(hwnd, NULL, TRUE);
5302 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5305 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5308 TRACE("hwnd = %p\n", hwnd);
5310 /* initialize info structure */
5311 infoPtr->nButtonWidth = 23;
5312 infoPtr->nButtonHeight = 22;
5313 infoPtr->nBitmapHeight = 16;
5314 infoPtr->nBitmapWidth = 16;
5316 infoPtr->nMaxTextRows = 1;
5317 infoPtr->cxMin = -1;
5318 infoPtr->cxMax = -1;
5319 infoPtr->nNumBitmaps = 0;
5320 infoPtr->nNumStrings = 0;
5322 infoPtr->bCaptured = FALSE;
5323 infoPtr->nButtonDown = -1;
5324 infoPtr->nButtonDrag = -1;
5325 infoPtr->nOldHit = -1;
5326 infoPtr->nHotItem = -1;
5327 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5328 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5329 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5330 infoPtr->bDragOutSent = FALSE;
5331 infoPtr->iVersion = 0;
5332 infoPtr->hwndSelf = hwnd;
5333 infoPtr->bDoRedraw = TRUE;
5334 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5335 infoPtr->clrBtnShadow = CLR_DEFAULT;
5336 infoPtr->szPadding.cx = DEFPAD_CX;
5337 infoPtr->szPadding.cy = DEFPAD_CY;
5338 infoPtr->iListGap = DEFLISTGAP;
5339 infoPtr->iTopMargin = default_top_margin(infoPtr);
5340 infoPtr->dwStyle = dwStyle;
5341 infoPtr->tbim.iButton = -1;
5342 GetClientRect(hwnd, &infoPtr->client_rect);
5343 infoPtr->bUnicode = infoPtr->hwndNotify &&
5344 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5345 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5347 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5348 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5350 OpenThemeData (hwnd, themeClass);
5352 TOOLBAR_CheckStyle (hwnd, dwStyle);
5359 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5363 /* delete tooltip control */
5364 if (infoPtr->hwndToolTip)
5365 DestroyWindow (infoPtr->hwndToolTip);
5367 /* delete temporary buffer for tooltip text */
5368 Free (infoPtr->pszTooltipText);
5369 Free (infoPtr->bitmaps); /* bitmaps list */
5371 /* delete button data */
5372 Free (infoPtr->buttons);
5374 /* delete strings */
5375 if (infoPtr->strings) {
5377 for (i = 0; i < infoPtr->nNumStrings; i++)
5378 if (infoPtr->strings[i])
5379 Free (infoPtr->strings[i]);
5381 Free (infoPtr->strings);
5384 /* destroy internal image list */
5385 if (infoPtr->himlInt)
5386 ImageList_Destroy (infoPtr->himlInt);
5388 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5389 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5390 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5392 /* delete default font */
5393 DeleteObject (infoPtr->hDefaultFont);
5395 CloseThemeData (GetWindowTheme (hwnd));
5397 /* free toolbar info data */
5399 SetWindowLongPtrW (hwnd, 0, 0);
5406 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5409 NMTBCUSTOMDRAW tbcd;
5412 HTHEME theme = GetWindowTheme (hwnd);
5413 DWORD dwEraseCustDraw = 0;
5415 /* the app has told us not to redraw the toolbar */
5416 if (!infoPtr->bDoRedraw)
5419 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5420 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5421 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5422 tbcd.nmcd.hdc = (HDC)wParam;
5423 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5424 dwEraseCustDraw = ntfret & 0xffff;
5426 /* FIXME: in general the return flags *can* be or'ed together */
5427 switch (dwEraseCustDraw)
5429 case CDRF_DODEFAULT:
5431 case CDRF_SKIPDEFAULT:
5434 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5439 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5440 * to my parent for processing.
5442 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5444 HDC hdc = (HDC)wParam;
5449 parent = GetParent(hwnd);
5450 MapWindowPoints(hwnd, parent, &pt, 1);
5451 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5452 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5453 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5456 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5458 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5459 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5460 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5461 tbcd.nmcd.hdc = (HDC)wParam;
5462 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5463 dwEraseCustDraw = ntfret & 0xffff;
5464 switch (dwEraseCustDraw)
5466 case CDRF_DODEFAULT:
5468 case CDRF_SKIPDEFAULT:
5471 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5480 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5482 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5484 return (LRESULT)infoPtr->hFont;
5489 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5492 INT nNewHotItem = infoPtr->nHotItem;
5494 for (i = 0; i < infoPtr->nNumButtons; i++)
5497 if ((nNewHotItem + iDirection < 0) ||
5498 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5500 NMTBWRAPHOTITEM nmtbwhi;
5501 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5502 nmtbwhi.iDirection = iDirection;
5503 nmtbwhi.dwReason = dwReason;
5505 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5509 nNewHotItem += iDirection;
5510 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5512 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5513 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5515 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5522 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5524 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5527 nmkey.nVKey = (UINT)wParam;
5528 nmkey.uFlags = HIWORD(lParam);
5530 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5531 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5533 switch ((UINT)wParam)
5537 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5541 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5545 if ((infoPtr->nHotItem >= 0) &&
5546 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5548 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5549 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5560 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5565 pt.x = (short)LOWORD(lParam);
5566 pt.y = (short)HIWORD(lParam);
5567 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5570 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5571 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5572 TOOLBAR_Customize (hwnd);
5579 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5582 TBUTTON_INFO *btnPtr;
5587 BOOL bDragKeyPressed;
5591 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5592 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5594 bDragKeyPressed = (wParam & MK_SHIFT);
5596 if (infoPtr->hwndToolTip)
5597 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5598 WM_LBUTTONDOWN, wParam, lParam);
5600 pt.x = (short)LOWORD(lParam);
5601 pt.y = (short)HIWORD(lParam);
5602 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5604 btnPtr = &infoPtr->buttons[nHit];
5606 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5608 infoPtr->nButtonDrag = nHit;
5611 /* If drag cursor has not been loaded, load it.
5612 * Note: it doesn't need to be freed */
5614 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5615 SetCursor(hCursorDrag);
5620 infoPtr->nOldHit = nHit;
5622 CopyRect(&arrowRect, &btnPtr->rect);
5623 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5625 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5626 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5627 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5628 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5629 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5630 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5634 /* draw in pressed state */
5635 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5636 btnPtr->fsState |= TBSTATE_PRESSED;
5638 btnPtr->bDropDownPressed = TRUE;
5639 RedrawWindow(hwnd,&btnPtr->rect,0,
5640 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5642 memset(&nmtb, 0, sizeof(nmtb));
5643 nmtb.iItem = btnPtr->idCommand;
5644 nmtb.rcButton = btnPtr->rect;
5645 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5647 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5649 if (res != TBDDRET_TREATPRESSED)
5653 /* redraw button in unpressed state */
5654 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5655 btnPtr->fsState &= ~TBSTATE_PRESSED;
5657 btnPtr->bDropDownPressed = FALSE;
5658 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5660 /* find and set hot item
5661 * NOTE: native doesn't do this, but that is a bug */
5663 ScreenToClient(hwnd, &pt);
5664 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5665 if (!infoPtr->bAnchor || (nHit >= 0))
5666 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5668 /* remove any left mouse button down or double-click messages
5669 * so that we can get a toggle effect on the button */
5670 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5671 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5676 /* otherwise drop through and process as pushed */
5678 infoPtr->bCaptured = TRUE;
5679 infoPtr->nButtonDown = nHit;
5680 infoPtr->bDragOutSent = FALSE;
5682 btnPtr->fsState |= TBSTATE_PRESSED;
5684 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5686 if (btnPtr->fsState & TBSTATE_ENABLED)
5687 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5694 memset(&nmtb, 0, sizeof(nmtb));
5695 nmtb.iItem = btnPtr->idCommand;
5696 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5699 nmmouse.dwHitInfo = nHit;
5701 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5703 nmmouse.dwItemSpec = -1;
5706 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5707 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5710 ClientToScreen(hwnd, &pt);
5713 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5714 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5720 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5723 TBUTTON_INFO *btnPtr;
5727 BOOL bSendMessage = TRUE;
5732 if (infoPtr->hwndToolTip)
5733 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5734 WM_LBUTTONUP, wParam, lParam);
5736 pt.x = (short)LOWORD(lParam);
5737 pt.y = (short)HIWORD(lParam);
5738 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5740 if (!infoPtr->bAnchor || (nHit >= 0))
5741 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5743 if (infoPtr->nButtonDrag >= 0) {
5747 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5750 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5752 GetClientRect(hwnd, &rcClient);
5753 if (PtInRect(&rcClient, pt))
5760 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5763 if (nButton == infoPtr->nButtonDrag)
5765 /* if the button is moved sightly left and we have a
5766 * separator there then remove it */
5767 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5769 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5770 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5772 else /* else insert a separator before the dragged button */
5775 memset(&tbb, 0, sizeof(tbb));
5776 tbb.fsStyle = BTNS_SEP;
5778 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5785 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5786 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5788 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5791 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5796 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5797 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5800 /* button under cursor changed so need to re-set hot item */
5801 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5802 infoPtr->nButtonDrag = -1;
5804 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5806 else if (infoPtr->nButtonDown >= 0) {
5807 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5808 btnPtr->fsState &= ~TBSTATE_PRESSED;
5810 if (btnPtr->fsStyle & BTNS_CHECK) {
5811 if (btnPtr->fsStyle & BTNS_GROUP) {
5812 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5814 if (nOldIndex == nHit)
5815 bSendMessage = FALSE;
5816 if ((nOldIndex != nHit) &&
5818 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5819 btnPtr->fsState |= TBSTATE_CHECKED;
5822 if (btnPtr->fsState & TBSTATE_CHECKED)
5823 btnPtr->fsState &= ~TBSTATE_CHECKED;
5825 btnPtr->fsState |= TBSTATE_CHECKED;
5829 if (nOldIndex != -1)
5830 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5833 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5834 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5835 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5837 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5839 infoPtr->nButtonDown = -1;
5841 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5842 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5843 NM_RELEASEDCAPTURE);
5845 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5848 memset(&nmtb, 0, sizeof(nmtb));
5849 nmtb.iItem = btnPtr->idCommand;
5850 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5853 if (btnPtr->fsState & TBSTATE_ENABLED)
5855 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5856 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5860 /* !!! Undocumented - toolbar at 4.71 level and above sends
5861 * NM_CLICK with the NMMOUSE structure. */
5862 nmmouse.dwHitInfo = nHit;
5865 nmmouse.dwItemSpec = -1;
5868 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5869 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5872 ClientToScreen(hwnd, &pt);
5875 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5876 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5882 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5889 pt.x = (short)LOWORD(lParam);
5890 pt.y = (short)HIWORD(lParam);
5892 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5893 nmmouse.dwHitInfo = nHit;
5896 nmmouse.dwItemSpec = -1;
5898 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5899 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5902 ClientToScreen(hwnd, &pt);
5905 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5906 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5912 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5914 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5917 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5918 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5924 TOOLBAR_CaptureChanged(HWND hwnd)
5926 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5927 TBUTTON_INFO *btnPtr;
5929 infoPtr->bCaptured = FALSE;
5931 if (infoPtr->nButtonDown >= 0)
5933 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5934 btnPtr->fsState &= ~TBSTATE_PRESSED;
5936 infoPtr->nOldHit = -1;
5938 if (btnPtr->fsState & TBSTATE_ENABLED)
5939 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5945 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5949 /* don't remove hot effects when in anchor highlighting mode or when a
5950 * drop-down button is pressed */
5951 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5953 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5954 if (!hotBtnPtr->bDropDownPressed)
5955 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5958 if (infoPtr->nOldHit < 0)
5961 /* If the last button we were over is depressed then make it not */
5962 /* depressed and redraw it */
5963 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5965 TBUTTON_INFO *btnPtr;
5968 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5970 btnPtr->fsState &= ~TBSTATE_PRESSED;
5973 InflateRect (&rc1, 1, 1);
5974 InvalidateRect (hwnd, &rc1, TRUE);
5977 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5980 ZeroMemory(&nmt, sizeof(nmt));
5981 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5982 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5983 infoPtr->bDragOutSent = TRUE;
5986 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5992 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5994 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5996 TRACKMOUSEEVENT trackinfo;
5998 TBUTTON_INFO *btnPtr;
6000 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6001 TOOLBAR_TooltipCreateControl(infoPtr);
6003 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6004 /* fill in the TRACKMOUSEEVENT struct */
6005 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6006 trackinfo.dwFlags = TME_QUERY;
6008 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6009 _TrackMouseEvent(&trackinfo);
6011 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6012 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6013 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6014 trackinfo.hwndTrack = hwnd;
6016 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6017 /* and can properly deactivate the hot toolbar button */
6018 _TrackMouseEvent(&trackinfo);
6022 if (infoPtr->hwndToolTip)
6023 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6024 WM_MOUSEMOVE, wParam, lParam);
6026 pt.x = (short)LOWORD(lParam);
6027 pt.y = (short)HIWORD(lParam);
6029 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6031 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6032 && (!infoPtr->bAnchor || (nHit >= 0)))
6033 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6035 if (infoPtr->nOldHit != nHit)
6037 if (infoPtr->bCaptured)
6039 if (!infoPtr->bDragOutSent)
6042 ZeroMemory(&nmt, sizeof(nmt));
6043 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6044 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6045 infoPtr->bDragOutSent = TRUE;
6048 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6049 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6050 btnPtr->fsState &= ~TBSTATE_PRESSED;
6051 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6053 else if (nHit == infoPtr->nButtonDown) {
6054 btnPtr->fsState |= TBSTATE_PRESSED;
6055 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6057 infoPtr->nOldHit = nHit;
6065 static inline LRESULT
6066 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6068 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6069 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6071 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6075 static inline LRESULT
6076 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6078 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6079 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6081 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6086 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6088 TOOLBAR_INFO *infoPtr;
6089 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6092 /* allocate memory for info structure */
6093 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6094 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6097 infoPtr->dwStructSize = sizeof(TBBUTTON);
6099 infoPtr->nWidth = 0;
6101 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6102 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6103 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6104 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6107 /* native control does:
6108 * Get a lot of colors and brushes
6110 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6111 * CreateFontIndirectW(adr1)
6112 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6113 * hdc = GetDC(toolbar)
6114 * GetSystemMetrics(0x48)
6115 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6116 * 0, 0, 0, 0, "MARLETT")
6117 * oldfnt = SelectObject(hdc, fnt2)
6118 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6119 * GetTextMetricsW(hdc, adr3)
6120 * SelectObject(hdc, oldfnt)
6121 * DeleteObject(fnt2)
6123 * InvalidateRect(toolbar, 0, 1)
6124 * SetWindowLongW(toolbar, 0, addr)
6125 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6128 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6129 * ie 2 0x4600094c 0x4600094c 0x4600894d
6130 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6131 * rebar 0x50008844 0x40008844 0x50008845
6132 * pager 0x50000844 0x40000844 0x50008845
6133 * IC35mgr 0x5400084e **nochange**
6134 * on entry to _NCCREATE 0x5400084e
6135 * rowlist 0x5400004e **nochange**
6136 * on entry to _NCCREATE 0x5400004e
6140 /* I think the code below is a bug, but it is the way that the native
6141 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6142 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6143 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6144 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6145 * Somehow, the only cases of this seem to be MFC programs.
6147 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6148 * does not occur in the WM_STYLECHANGING routine.
6149 * (Guy Albertelli 9/2001)
6152 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6153 && !(cs->style & TBSTYLE_TRANSPARENT))
6154 styleadd |= TBSTYLE_TRANSPARENT;
6155 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6156 styleadd |= CCS_TOP; /* default to top */
6157 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6160 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6165 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6167 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6171 if (dwStyle & WS_MINIMIZE)
6172 return 0; /* Nothing to do */
6174 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6176 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6179 if (!(dwStyle & CCS_NODIVIDER))
6181 GetWindowRect (hwnd, &rcWindow);
6182 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6183 if( dwStyle & WS_BORDER )
6184 OffsetRect (&rcWindow, 1, 1);
6185 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6188 ReleaseDC( hwnd, hdc );
6194 /* handles requests from the tooltip control on what text to display */
6195 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6197 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6199 TRACE("button index = %d\n", index);
6201 Free (infoPtr->pszTooltipText);
6202 infoPtr->pszTooltipText = NULL;
6207 if (infoPtr->bUnicode)
6209 WCHAR wszBuffer[INFOTIPSIZE+1];
6210 NMTBGETINFOTIPW tbgit;
6211 unsigned int len; /* in chars */
6213 wszBuffer[0] = '\0';
6214 wszBuffer[INFOTIPSIZE] = '\0';
6216 tbgit.pszText = wszBuffer;
6217 tbgit.cchTextMax = INFOTIPSIZE;
6218 tbgit.iItem = lpnmtdi->hdr.idFrom;
6219 tbgit.lParam = infoPtr->buttons[index].dwData;
6221 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6223 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6225 len = strlenW(tbgit.pszText);
6226 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6228 /* need to allocate temporary buffer in infoPtr as there
6229 * isn't enough space in buffer passed to us by the
6230 * tooltip control */
6231 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6232 if (infoPtr->pszTooltipText)
6234 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6235 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6241 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6247 CHAR szBuffer[INFOTIPSIZE+1];
6248 NMTBGETINFOTIPA tbgit;
6249 unsigned int len; /* in chars */
6252 szBuffer[INFOTIPSIZE] = '\0';
6254 tbgit.pszText = szBuffer;
6255 tbgit.cchTextMax = INFOTIPSIZE;
6256 tbgit.iItem = lpnmtdi->hdr.idFrom;
6257 tbgit.lParam = infoPtr->buttons[index].dwData;
6259 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6261 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6263 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6264 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6266 /* need to allocate temporary buffer in infoPtr as there
6267 * isn't enough space in buffer passed to us by the
6268 * tooltip control */
6269 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6270 if (infoPtr->pszTooltipText)
6272 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6273 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6279 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6280 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6285 /* if button has text, but it is not shown then automatically
6286 * use that text as tooltip */
6287 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6288 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6290 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6291 unsigned int len = pszText ? strlenW(pszText) : 0;
6293 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6295 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
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+1)*sizeof(WCHAR));
6301 if (infoPtr->pszTooltipText)
6303 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6304 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6310 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6315 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6317 /* last resort: send notification on to app */
6318 /* FIXME: find out what is really used here */
6319 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6323 static inline LRESULT
6324 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6326 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6327 LPNMHDR lpnmh = (LPNMHDR)lParam;
6329 switch (lpnmh->code)
6333 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6335 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6336 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6337 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6341 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6342 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6350 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6352 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6353 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6354 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6355 lppgs->iScroll, lppgs->iDir);
6359 case TTN_GETDISPINFOW:
6360 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6362 case TTN_GETDISPINFOA:
6363 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6373 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6377 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6379 if (lParam == NF_QUERY)
6382 if (lParam == NF_REQUERY) {
6383 format = SendMessageW(infoPtr->hwndNotify,
6384 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6385 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6386 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6397 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6399 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6403 /* fill ps.rcPaint with a default rect */
6404 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6406 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6408 TRACE("psrect=(%d,%d)-(%d,%d)\n",
6409 ps.rcPaint.left, ps.rcPaint.top,
6410 ps.rcPaint.right, ps.rcPaint.bottom);
6412 TOOLBAR_Refresh (hwnd, hdc, &ps);
6413 if (!wParam) EndPaint (hwnd, &ps);
6420 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6424 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6426 /* make first item hot */
6427 if (infoPtr->nNumButtons > 0)
6428 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6434 TOOLBAR_SetFont(HWND hwnd, WPARAM wParam, LPARAM lParam)
6436 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6438 TRACE("font=%p redraw=%ld\n", (HFONT)wParam, lParam);
6441 infoPtr->hFont = infoPtr->hDefaultFont;
6443 infoPtr->hFont = (HFONT)wParam;
6445 TOOLBAR_CalcToolbar(hwnd);
6448 InvalidateRect(hwnd, NULL, TRUE);
6453 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6454 /*****************************************************
6457 * Handles the WM_SETREDRAW message.
6460 * According to testing V4.71 of COMCTL32 returns the
6461 * *previous* status of the redraw flag (either 0 or 1)
6462 * instead of the MSDN documented value of 0 if handled.
6463 * (For laughs see the "consistency" with same function
6466 *****************************************************/
6468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6469 BOOL oldredraw = infoPtr->bDoRedraw;
6471 TRACE("set to %s\n",
6472 (wParam) ? "TRUE" : "FALSE");
6473 infoPtr->bDoRedraw = (BOOL) wParam;
6475 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6477 return (oldredraw) ? 1 : 0;
6482 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6486 TRACE("sizing toolbar!\n");
6488 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6490 RECT delta_width, delta_height, client, dummy;
6491 DWORD min_x, max_x, min_y, max_y;
6492 TBUTTON_INFO *btnPtr;
6495 GetClientRect(hwnd, &client);
6496 if(client.right > infoPtr->client_rect.right)
6498 min_x = infoPtr->client_rect.right;
6499 max_x = client.right;
6503 max_x = infoPtr->client_rect.right;
6504 min_x = client.right;
6506 if(client.bottom > infoPtr->client_rect.bottom)
6508 min_y = infoPtr->client_rect.bottom;
6509 max_y = client.bottom;
6513 max_y = infoPtr->client_rect.bottom;
6514 min_y = client.bottom;
6517 SetRect(&delta_width, min_x, 0, max_x, min_y);
6518 SetRect(&delta_height, 0, min_y, max_x, max_y);
6520 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6521 btnPtr = infoPtr->buttons;
6522 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6523 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6524 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6525 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6527 GetClientRect(hwnd, &infoPtr->client_rect);
6528 TOOLBAR_AutoSize(hwnd);
6534 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6536 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6538 if (nType == GWL_STYLE)
6540 DWORD dwOldStyle = infoPtr->dwStyle;
6542 if (lpStyle->styleNew & TBSTYLE_LIST)
6543 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6545 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6547 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6549 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6551 infoPtr->dwStyle = lpStyle->styleNew;
6553 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6554 TOOLBAR_LayoutToolbar(hwnd);
6556 /* only resize if one of the CCS_* styles was changed */
6557 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6559 TOOLBAR_AutoSize (hwnd);
6561 InvalidateRect(hwnd, NULL, TRUE);
6570 TOOLBAR_SysColorChange (HWND hwnd)
6572 COMCTL32_RefreshSysColors();
6578 /* update theme after a WM_THEMECHANGED message */
6579 static LRESULT theme_changed (HWND hwnd)
6581 HTHEME theme = GetWindowTheme (hwnd);
6582 CloseThemeData (theme);
6583 OpenThemeData (hwnd, themeClass);
6588 static LRESULT WINAPI
6589 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6591 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6593 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6594 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6596 if (!infoPtr && (uMsg != WM_NCCREATE))
6597 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6602 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6604 case TB_ADDBUTTONSA:
6605 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6607 case TB_ADDBUTTONSW:
6608 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6611 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6614 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6617 return TOOLBAR_AutoSize (hwnd);
6619 case TB_BUTTONCOUNT:
6620 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6622 case TB_BUTTONSTRUCTSIZE:
6623 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6625 case TB_CHANGEBITMAP:
6626 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6628 case TB_CHECKBUTTON:
6629 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6631 case TB_COMMANDTOINDEX:
6632 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6635 return TOOLBAR_Customize (hwnd);
6637 case TB_DELETEBUTTON:
6638 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6640 case TB_ENABLEBUTTON:
6641 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6643 case TB_GETANCHORHIGHLIGHT:
6644 return TOOLBAR_GetAnchorHighlight (hwnd);
6647 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6649 case TB_GETBITMAPFLAGS:
6650 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6653 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6655 case TB_GETBUTTONINFOA:
6656 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6658 case TB_GETBUTTONINFOW:
6659 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6661 case TB_GETBUTTONSIZE:
6662 return TOOLBAR_GetButtonSize (hwnd);
6664 case TB_GETBUTTONTEXTA:
6665 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6667 case TB_GETBUTTONTEXTW:
6668 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6670 case TB_GETDISABLEDIMAGELIST:
6671 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6673 case TB_GETEXTENDEDSTYLE:
6674 return TOOLBAR_GetExtendedStyle (hwnd);
6676 case TB_GETHOTIMAGELIST:
6677 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6680 return TOOLBAR_GetHotItem (hwnd);
6682 case TB_GETIMAGELIST:
6683 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6685 case TB_GETINSERTMARK:
6686 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6688 case TB_GETINSERTMARKCOLOR:
6689 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6691 case TB_GETITEMRECT:
6692 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6695 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6697 /* case TB_GETOBJECT: */ /* 4.71 */
6700 return TOOLBAR_GetPadding (hwnd);
6703 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6706 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6709 return TOOLBAR_GetState (hwnd, wParam, lParam);
6712 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6715 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6718 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6720 case TB_GETTEXTROWS:
6721 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6723 case TB_GETTOOLTIPS:
6724 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6726 case TB_GETUNICODEFORMAT:
6727 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6730 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6733 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6735 case TB_INDETERMINATE:
6736 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6738 case TB_INSERTBUTTONA:
6739 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6741 case TB_INSERTBUTTONW:
6742 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6744 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6746 case TB_ISBUTTONCHECKED:
6747 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6749 case TB_ISBUTTONENABLED:
6750 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6752 case TB_ISBUTTONHIDDEN:
6753 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6755 case TB_ISBUTTONHIGHLIGHTED:
6756 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6758 case TB_ISBUTTONINDETERMINATE:
6759 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6761 case TB_ISBUTTONPRESSED:
6762 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6765 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6767 case TB_MAPACCELERATORA:
6768 case TB_MAPACCELERATORW:
6769 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6772 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6775 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6777 case TB_PRESSBUTTON:
6778 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6780 case TB_REPLACEBITMAP:
6781 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6783 case TB_SAVERESTOREA:
6784 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6786 case TB_SAVERESTOREW:
6787 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6789 case TB_SETANCHORHIGHLIGHT:
6790 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6792 case TB_SETBITMAPSIZE:
6793 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6795 case TB_SETBUTTONINFOA:
6796 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6798 case TB_SETBUTTONINFOW:
6799 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6801 case TB_SETBUTTONSIZE:
6802 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6804 case TB_SETBUTTONWIDTH:
6805 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6808 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6810 case TB_SETDISABLEDIMAGELIST:
6811 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6813 case TB_SETDRAWTEXTFLAGS:
6814 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6816 case TB_SETEXTENDEDSTYLE:
6817 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6819 case TB_SETHOTIMAGELIST:
6820 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6823 return TOOLBAR_SetHotItem (hwnd, wParam);
6825 case TB_SETIMAGELIST:
6826 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6829 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6831 case TB_SETINSERTMARK:
6832 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6834 case TB_SETINSERTMARKCOLOR:
6835 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6837 case TB_SETMAXTEXTROWS:
6838 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6841 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6844 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6847 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6850 return TOOLBAR_SetState (hwnd, wParam, lParam);
6853 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6855 case TB_SETTOOLTIPS:
6856 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6858 case TB_SETUNICODEFORMAT:
6859 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6862 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6865 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6868 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6871 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6874 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6877 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6879 /* Common Control Messages */
6881 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6882 case CCM_GETCOLORSCHEME:
6883 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6885 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6886 case CCM_SETCOLORSCHEME:
6887 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6889 case CCM_GETVERSION:
6890 return TOOLBAR_GetVersion (hwnd);
6892 case CCM_SETVERSION:
6893 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6899 return TOOLBAR_Create (hwnd, wParam, lParam);
6902 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6905 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6908 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6911 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6913 /* case WM_KILLFOCUS: */
6915 case WM_LBUTTONDBLCLK:
6916 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6918 case WM_LBUTTONDOWN:
6919 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6922 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6925 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6927 case WM_RBUTTONDBLCLK:
6928 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6931 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6934 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6936 case WM_CAPTURECHANGED:
6937 return TOOLBAR_CaptureChanged(hwnd);
6940 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6943 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6946 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6949 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6952 return TOOLBAR_Notify (hwnd, wParam, lParam);
6954 case WM_NOTIFYFORMAT:
6955 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6957 case WM_PRINTCLIENT:
6959 return TOOLBAR_Paint (hwnd, wParam);
6962 return TOOLBAR_SetFocus (hwnd, wParam);
6965 return TOOLBAR_SetFont(hwnd, wParam, lParam);
6968 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6971 return TOOLBAR_Size (hwnd, wParam, lParam);
6973 case WM_STYLECHANGED:
6974 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6976 case WM_SYSCOLORCHANGE:
6977 return TOOLBAR_SysColorChange (hwnd);
6979 case WM_THEMECHANGED:
6980 return theme_changed (hwnd);
6982 /* case WM_WININICHANGE: */
6987 case WM_MEASUREITEM:
6989 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6991 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6992 case PGM_FORWARDMOUSE:
6993 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6996 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6997 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6998 uMsg, wParam, lParam);
6999 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7005 TOOLBAR_Register (void)
7009 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7010 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7011 wndClass.lpfnWndProc = ToolbarWindowProc;
7012 wndClass.cbClsExtra = 0;
7013 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7014 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7015 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7016 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7018 RegisterClassW (&wndClass);
7023 TOOLBAR_Unregister (void)
7025 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7028 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7033 /* Check if the entry already exists */
7034 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7036 /* If this is a new entry we must create it and insert into the array */
7041 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7044 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7045 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7060 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7064 for (i = 0; i < *cies; i++)
7074 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7082 for (i = 0; i < cies; i++)
7084 if (pies[i]->id == id)
7096 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7098 HIMAGELIST himlDef = 0;
7099 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7102 himlDef = pie->himl;
7108 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7110 if (infoPtr->bUnicode)
7111 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7118 nmtba.iItem = nmtb->iItem;
7119 nmtba.pszText = Buffer;
7120 nmtba.cchText = 256;
7121 ZeroMemory(nmtba.pszText, nmtba.cchText);
7123 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7125 int ccht = strlen(nmtba.pszText);
7127 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7128 nmtb->pszText, nmtb->cchText);
7130 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7139 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7140 int iItem, PCUSTOMBUTTON btnInfo)
7144 /* MSDN states that iItem is the index of the button, rather than the
7145 * command ID as used by every other NMTOOLBAR notification */
7147 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7149 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);