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).
47 * - Fix TB_SETROWS and Separators.
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_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 /* Used to find undocumented extended styles */
224 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
225 TBSTYLE_EX_UNDOC1 | \
226 TBSTYLE_EX_MIXEDBUTTONS | \
227 TBSTYLE_EX_DOUBLEBUFFER | \
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(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
243 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
244 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
245 static PIMLENTRY TOOLBAR_GetImageListEntry(const 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(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
249 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
250 static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
251 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
252 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
253 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
256 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
258 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
262 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
264 LPWSTR lpText = NULL;
266 /* NOTE: iString == -1 is undocumented */
267 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
268 lpText = (LPWSTR)btnPtr->iString;
269 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
270 lpText = infoPtr->strings[btnPtr->iString];
276 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
278 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
279 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
280 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
284 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
286 if (TRACE_ON(toolbar)){
287 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
288 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
289 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
290 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
291 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
292 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
293 wine_dbgstr_rect(&bP->rect));
299 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
301 if (TRACE_ON(toolbar)) {
304 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
306 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
307 iP->nNumStrings, iP->dwStyle);
308 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
310 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
311 (iP->bDoRedraw) ? "TRUE" : "FALSE");
312 for(i=0; i<iP->nNumButtons; i++) {
313 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
319 TOOLBAR_ButtonHasString(const TBUTTON_INFO *btnPtr)
321 return HIWORD(btnPtr->iString) && btnPtr->iString != -1;
324 /***********************************************************************
327 * This function validates that the styles set are implemented and
328 * issues FIXME's warning of possible problems. In a perfect world this
329 * function should be null.
332 TOOLBAR_CheckStyle (const TOOLBAR_INFO *infoPtr, DWORD dwStyle)
334 if (dwStyle & TBSTYLE_REGISTERDROP)
335 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr->hwndSelf);
340 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
342 if(!IsWindow(infoPtr->hwndSelf))
343 return 0; /* we have just been destroyed */
345 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
346 nmhdr->hwndFrom = infoPtr->hwndSelf;
349 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
350 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
352 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
355 /***********************************************************************
356 * TOOLBAR_GetBitmapIndex
358 * This function returns the bitmap index associated with a button.
359 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
360 * is issued to retrieve the index.
363 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
365 INT ret = btnPtr->iBitmap;
367 if (ret == I_IMAGECALLBACK)
369 /* issue TBN_GETDISPINFO */
372 memset(&nmgd, 0, sizeof(nmgd));
373 nmgd.idCommand = btnPtr->idCommand;
374 nmgd.lParam = btnPtr->dwData;
375 nmgd.dwMask = TBNF_IMAGE;
377 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
378 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
379 if (nmgd.dwMask & TBNF_DI_SETITEM)
380 btnPtr->iBitmap = nmgd.iImage;
382 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
383 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
386 if (ret != I_IMAGENONE)
387 ret = GETIBITMAP(infoPtr, ret);
394 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
397 INT id = GETHIMLID(infoPtr, index);
398 INT iBitmap = GETIBITMAP(infoPtr, index);
400 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
401 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
402 (index == I_IMAGECALLBACK))
410 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
412 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
413 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
417 /***********************************************************************
418 * TOOLBAR_GetImageListForDrawing
420 * This function validates the bitmap index (including I_IMAGECALLBACK
421 * functionality) and returns the corresponding image list.
424 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
425 IMAGE_LIST_TYPE imagelist, INT * index)
429 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
430 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
431 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
432 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
436 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
437 if ((*index == I_IMAGECALLBACK) ||
438 (*index == I_IMAGENONE)) return NULL;
439 ERR("TBN_GETDISPINFO returned invalid index %d\n",
446 case IMAGE_LIST_DEFAULT:
447 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
450 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
452 case IMAGE_LIST_DISABLED:
453 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
457 FIXME("Shouldn't reach here\n");
461 TRACE("no image list\n");
468 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
471 COLORREF oldcolor, newcolor;
473 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
474 myrect.right = myrect.left + 1;
475 myrect.top = lpRect->top + 2;
476 myrect.bottom = lpRect->bottom - 2;
478 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
479 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
480 oldcolor = SetBkColor (hdc, newcolor);
481 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
483 myrect.left = myrect.right;
484 myrect.right = myrect.left + 1;
486 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
487 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
488 SetBkColor (hdc, newcolor);
489 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
491 SetBkColor (hdc, oldcolor);
495 /***********************************************************************
496 * TOOLBAR_DrawFlatHorizontalSeparator
498 * This function draws horizontal separator for toolbars having CCS_VERT style.
499 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
500 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
501 * are horizontal as opposed to the vertical separators for not dropdown
504 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
507 TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
508 const TOOLBAR_INFO *infoPtr)
511 COLORREF oldcolor, newcolor;
513 myrect.left = lpRect->left;
514 myrect.right = lpRect->right;
515 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
516 myrect.bottom = myrect.top + 1;
518 InflateRect (&myrect, -2, 0);
520 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
522 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
523 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
524 oldcolor = SetBkColor (hdc, newcolor);
525 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
527 myrect.top = myrect.bottom;
528 myrect.bottom = myrect.top + 1;
530 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
531 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
532 SetBkColor (hdc, newcolor);
533 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
535 SetBkColor (hdc, oldcolor);
540 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
545 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
546 hOldPen = SelectObject ( hdc, hPen );
549 MoveToEx (hdc, x, y, NULL);
550 LineTo (hdc, x+5, y++); x++;
551 MoveToEx (hdc, x, y, NULL);
552 LineTo (hdc, x+3, y++); x++;
553 MoveToEx (hdc, x, y, NULL);
554 LineTo (hdc, x+1, y);
555 SelectObject( hdc, hOldPen );
556 DeleteObject( hPen );
560 * Draw the text string for this button.
561 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
562 * is non-zero, so we can simply check himlDef to see if we have
566 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
567 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
569 HDC hdc = tbcd->nmcd.hdc;
572 COLORREF clrOldBk = 0;
574 UINT state = tbcd->nmcd.uItemState;
578 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
579 wine_dbgstr_rect(rcText));
581 hOldFont = SelectObject (hdc, infoPtr->hFont);
582 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
583 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
585 else if (state & CDIS_DISABLED) {
586 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
587 OffsetRect (rcText, 1, 1);
588 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
589 SetTextColor (hdc, comctl32_color.clr3dShadow);
590 OffsetRect (rcText, -1, -1);
592 else if (state & CDIS_INDETERMINATE) {
593 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
595 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
596 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
597 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
598 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
601 clrOld = SetTextColor (hdc, tbcd->clrText);
604 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
605 SetTextColor (hdc, clrOld);
606 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
608 SetBkColor (hdc, clrOldBk);
609 SetBkMode (hdc, oldBkMode);
611 SelectObject (hdc, hOldFont);
617 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
619 HDC hdc = tbcd->nmcd.hdc;
620 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
623 INT cx = lpRect->right - lpRect->left;
624 INT cy = lpRect->bottom - lpRect->top;
625 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
626 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
627 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
628 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
629 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
630 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
631 SetBkColor(hdc, clrBkOld);
632 SetTextColor(hdc, clrTextOld);
633 SelectObject (hdc, hbr);
637 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
640 HBITMAP hbmMask, hbmImage;
641 HDC hdcMask, hdcImage;
643 ImageList_GetIconSize(himl, &cx, &cy);
645 /* Create src image */
646 hdcImage = CreateCompatibleDC(hdc);
647 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
648 SelectObject(hdcImage, hbmImage);
649 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
650 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
653 hdcMask = CreateCompatibleDC(0);
654 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
655 SelectObject(hdcMask, hbmMask);
657 /* Remove the background and all white pixels */
658 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
659 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
660 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
661 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
663 /* draw the new mask 'etched' to hdc */
664 SetBkColor(hdc, RGB(255, 255, 255));
665 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
666 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
667 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
668 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
669 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
672 DeleteObject(hbmImage);
674 DeleteObject (hbmMask);
680 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
684 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
685 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
686 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
687 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
688 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
689 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
690 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
694 /* draws the image on a toolbar button */
696 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
697 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
699 HIMAGELIST himl = NULL;
700 BOOL draw_masked = FALSE;
703 UINT draw_flags = ILD_TRANSPARENT;
705 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
714 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
715 ((tbcd->nmcd.uItemState & CDIS_HOT)
716 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
718 /* if hot, attempt to draw with hot image list, if fails,
719 use default image list */
720 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
722 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
725 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
730 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
731 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
734 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
735 (tbcd->nmcd.uItemState & CDIS_MARKED))
736 draw_flags |= ILD_BLEND50;
738 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
739 index, himl, left, top, offset);
742 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
744 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
747 /* draws a blank frame for a toolbar button */
749 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
751 HDC hdc = tbcd->nmcd.hdc;
752 RECT rc = tbcd->nmcd.rc;
753 /* if the state is disabled or indeterminate then the button
754 * cannot have an interactive look like pressed or hot */
755 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
756 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
757 BOOL pressed_look = !non_interactive_state &&
758 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
759 (tbcd->nmcd.uItemState & CDIS_CHECKED));
761 /* app don't want us to draw any edges */
762 if (dwItemCDFlag & TBCDRF_NOEDGES)
765 if (infoPtr->dwStyle & TBSTYLE_FLAT)
768 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
769 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
770 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
775 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
777 DrawEdge (hdc, &rc, EDGE_RAISED,
778 BF_SOFT | BF_RECT | BF_MIDDLE);
783 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
785 HDC hdc = tbcd->nmcd.hdc;
787 BOOL pressed = bDropDownPressed ||
788 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
790 if (infoPtr->dwStyle & TBSTYLE_FLAT)
793 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
794 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
795 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
796 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
797 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
802 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
804 DrawEdge (hdc, rcArrow, EDGE_RAISED,
805 BF_SOFT | BF_RECT | BF_MIDDLE);
809 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
811 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
813 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
814 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
817 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
820 /* draws a complete toolbar button */
822 TOOLBAR_DrawButton (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
824 DWORD dwStyle = infoPtr->dwStyle;
825 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
826 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
827 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
828 BOOL drawSepDropDownArrow = hasDropDownArrow &&
829 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
830 RECT rc, rcArrow, rcBitmap, rcText;
831 LPWSTR lpText = NULL;
836 DWORD dwItemCustDraw;
838 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
841 CopyRect (&rcArrow, &rc);
843 /* separator - doesn't send NM_CUSTOMDRAW */
844 if (btnPtr->fsStyle & BTNS_SEP) {
847 DrawThemeBackground (theme, hdc,
848 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
852 /* with the FLAT style, iBitmap is the width and has already */
853 /* been taken into consideration in calculating the width */
854 /* so now we need to draw the vertical separator */
855 /* empirical tests show that iBitmap can/will be non-zero */
856 /* when drawing the vertical bar... */
857 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
858 if (dwStyle & CCS_VERT)
859 TOOLBAR_DrawFlatHorizontalSeparator (&rc, hdc, infoPtr);
861 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
863 else if (btnPtr->fsStyle != BTNS_SEP) {
864 FIXME("Draw some kind of separator: fsStyle=%x\n",
870 /* get a pointer to the text */
871 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
873 if (hasDropDownArrow)
877 if (dwStyle & TBSTYLE_FLAT)
878 right = max(rc.left, rc.right - DDARROW_WIDTH);
880 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
882 if (drawSepDropDownArrow)
885 rcArrow.left = right;
888 /* copy text & bitmap rects after adjusting for drop-down arrow
889 * so that text & bitmap is centered in the rectangle not containing
891 CopyRect(&rcText, &rc);
892 CopyRect(&rcBitmap, &rc);
894 /* Center the bitmap horizontally and vertically */
895 if (dwStyle & TBSTYLE_LIST)
898 infoPtr->nMaxTextRows > 0 &&
899 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
900 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
901 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
903 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
906 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
908 rcBitmap.top += infoPtr->szPadding.cy / 2;
910 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
911 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
912 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
913 TRACE("Text=%s\n", debugstr_w(lpText));
914 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
916 /* calculate text position */
919 rcText.left += GetSystemMetrics(SM_CXEDGE);
920 rcText.right -= GetSystemMetrics(SM_CXEDGE);
921 if (dwStyle & TBSTYLE_LIST)
923 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
927 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
928 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
930 rcText.top += infoPtr->szPadding.cy/2 + 2;
934 /* Initialize fields in all cases, because we use these later
935 * NOTE: applications can and do alter these to customize their
937 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
938 tbcd.clrText = comctl32_color.clrBtnText;
939 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
940 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
941 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
942 tbcd.clrMark = comctl32_color.clrHighlight;
943 tbcd.clrHighlightHotTrack = 0;
944 tbcd.nStringBkMode = TRANSPARENT;
945 tbcd.nHLStringBkMode = OPAQUE;
946 /* MSDN says that this is the text rectangle.
947 * But (why always a but) tracing of v5.7 of native shows
948 * that this is really a *relative* rectangle based on the
949 * the nmcd.rc. Also the left and top are always 0 ignoring
950 * any bitmap that might be present. */
951 tbcd.rcText.left = 0;
953 tbcd.rcText.right = rcText.right - rc.left;
954 tbcd.rcText.bottom = rcText.bottom - rc.top;
955 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
958 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
960 /* FIXME: what are these used for? */
964 /* Issue Item Prepaint notify */
967 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
969 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
970 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
971 tbcd.nmcd.lItemlParam = btnPtr->dwData;
972 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
973 /* reset these fields so the user can't alter the behaviour like native */
977 dwItemCustDraw = ntfret & 0xffff;
978 dwItemCDFlag = ntfret & 0xffff0000;
979 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
981 /* save the only part of the rect that the user can change */
982 rcText.right = tbcd.rcText.right + rc.left;
983 rcText.bottom = tbcd.rcText.bottom + rc.top;
986 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
987 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
988 OffsetRect(&rcText, 1, 1);
990 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
991 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
992 TOOLBAR_DrawPattern (&rc, &tbcd);
994 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
995 && (tbcd.nmcd.uItemState & CDIS_HOT))
997 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
1001 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1002 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1003 if (hasDropDownArrow)
1004 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1005 SetBkColor(hdc, oldclr);
1011 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1012 int stateId = TS_NORMAL;
1014 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1015 stateId = TS_DISABLED;
1016 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1017 stateId = TS_PRESSED;
1018 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1019 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1020 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1021 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1024 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1027 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1029 if (drawSepDropDownArrow)
1033 int stateId = TS_NORMAL;
1035 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1036 stateId = TS_DISABLED;
1037 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1038 stateId = TS_PRESSED;
1039 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1040 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1041 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1044 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1045 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1048 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1051 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1052 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1053 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1054 SetBkMode (hdc, oldBkMode);
1056 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1058 if (hasDropDownArrow && !drawSepDropDownArrow)
1060 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1062 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1063 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1065 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1067 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1068 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1071 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1074 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1076 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1077 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1084 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1086 TBUTTON_INFO *btnPtr;
1088 RECT rcTemp, rcClient;
1089 NMTBCUSTOMDRAW tbcd;
1091 DWORD dwBaseCustDraw;
1093 /* the app has told us not to redraw the toolbar */
1094 if (!infoPtr->bDoRedraw)
1097 /* if imagelist belongs to the app, it can be changed
1098 by the app after setting it */
1099 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1101 infoPtr->nNumBitmaps = 0;
1102 for (i = 0; i < infoPtr->cimlDef; i++)
1103 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1106 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1108 /* change the imagelist icon size if we manage the list and it is necessary */
1109 TOOLBAR_CheckImageListIconSize(infoPtr);
1111 /* Send initial notify */
1112 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1113 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1114 tbcd.nmcd.hdc = hdc;
1115 tbcd.nmcd.rc = ps->rcPaint;
1116 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1117 dwBaseCustDraw = ntfret & 0xffff;
1119 GetClientRect(infoPtr->hwndSelf, &rcClient);
1121 /* redraw necessary buttons */
1122 btnPtr = infoPtr->buttons;
1123 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1126 if (!RectVisible(hdc, &btnPtr->rect))
1128 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1130 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1131 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1135 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1136 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1138 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1141 /* draw insert mark if required */
1142 if (infoPtr->tbim.iButton != -1)
1144 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1146 rcInsertMark.top = rcButton.top;
1147 rcInsertMark.bottom = rcButton.bottom;
1148 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1149 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1151 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1152 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1155 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1157 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1158 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1159 tbcd.nmcd.hdc = hdc;
1160 tbcd.nmcd.rc = ps->rcPaint;
1161 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1165 /***********************************************************************
1166 * TOOLBAR_MeasureString
1168 * This function gets the width and height of a string in pixels. This
1169 * is done first by using GetTextExtentPoint to get the basic width
1170 * and height. The DrawText is called with DT_CALCRECT to get the exact
1171 * width. The reason is because the text may have more than one "&" (or
1172 * prefix characters as M$ likes to call them). The prefix character
1173 * indicates where the underline goes, except for the string "&&" which
1174 * is reduced to a single "&". GetTextExtentPoint does not process these
1175 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1178 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1179 HDC hdc, LPSIZE lpSize)
1186 if (infoPtr->nMaxTextRows > 0 &&
1187 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1188 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1189 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1191 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1193 if(lpText != NULL) {
1194 /* first get size of all the text */
1195 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1197 /* feed above size into the rectangle for DrawText */
1198 myrect.left = myrect.top = 0;
1199 myrect.right = lpSize->cx;
1200 myrect.bottom = lpSize->cy;
1202 /* Use DrawText to get true size as drawn (less pesky "&") */
1203 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1204 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1207 /* feed back to caller */
1208 lpSize->cx = myrect.right;
1209 lpSize->cy = myrect.bottom;
1213 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1216 /***********************************************************************
1217 * TOOLBAR_CalcStrings
1219 * This function walks through each string and measures it and returns
1220 * the largest height and width to caller.
1223 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1225 TBUTTON_INFO *btnPtr;
1234 if (infoPtr->nMaxTextRows == 0)
1237 hdc = GetDC (infoPtr->hwndSelf);
1238 hOldFont = SelectObject (hdc, infoPtr->hFont);
1240 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1244 GetTextMetricsW(hdc, &tm);
1245 lpSize->cy = tm.tmHeight;
1248 btnPtr = infoPtr->buttons;
1249 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1250 if(TOOLBAR_HasText(infoPtr, btnPtr))
1252 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1253 if (sz.cx > lpSize->cx)
1255 if (sz.cy > lpSize->cy)
1260 SelectObject (hdc, hOldFont);
1261 ReleaseDC (infoPtr->hwndSelf, hdc);
1263 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1266 /***********************************************************************
1267 * TOOLBAR_WrapToolbar
1269 * This function walks through the buttons and separators in the
1270 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1271 * wrapping should occur based on the width of the toolbar window.
1272 * It does *not* calculate button placement itself. That task
1273 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1274 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1275 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1277 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1278 * vertical toolbar lists.
1282 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1284 TBUTTON_INFO *btnPtr;
1289 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1290 /* no layout is necessary. Applications may use this style */
1291 /* to perform their own layout on the toolbar. */
1292 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1293 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1295 btnPtr = infoPtr->buttons;
1296 x = infoPtr->nIndent;
1298 if (GetParent(infoPtr->hwndSelf))
1300 /* this can get the parents width, to know how far we can extend
1301 * this toolbar. We cannot use its height, as there may be multiple
1302 * toolbars in a rebar control
1304 GetClientRect( GetParent(infoPtr->hwndSelf), &rc );
1305 infoPtr->nWidth = rc.right - rc.left;
1309 GetWindowRect( infoPtr->hwndSelf, &rc );
1310 infoPtr->nWidth = rc.right - rc.left;
1313 bButtonWrap = FALSE;
1315 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1316 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1319 for (i = 0; i < infoPtr->nNumButtons; i++ )
1321 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1323 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1326 if (btnPtr[i].cx > 0)
1328 /* horizontal separators are treated as buttons for width */
1329 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1330 !(infoPtr->dwStyle & CCS_VERT))
1331 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1333 cx = infoPtr->nButtonWidth;
1335 /* Two or more adjacent separators form a separator group. */
1336 /* The first separator in a group should be wrapped to the */
1337 /* next row if the previous wrapping is on a button. */
1339 (btnPtr[i].fsStyle & BTNS_SEP) &&
1340 (i + 1 < infoPtr->nNumButtons ) &&
1341 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1343 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1344 btnPtr[i].fsState |= TBSTATE_WRAP;
1345 x = infoPtr->nIndent;
1347 bButtonWrap = FALSE;
1351 /* The layout makes sure the bitmap is visible, but not the button. */
1352 /* Test added to also wrap after a button that starts a row but */
1353 /* is bigger than the area. - GA 8/01 */
1354 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1355 > infoPtr->nWidth ) ||
1356 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1358 BOOL bFound = FALSE;
1360 /* If the current button is a separator and not hidden, */
1361 /* go to the next until it reaches a non separator. */
1362 /* Wrap the last separator if it is before a button. */
1363 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1364 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1365 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1366 i < infoPtr->nNumButtons )
1372 if( bFound && i < infoPtr->nNumButtons )
1375 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1376 i, btnPtr[i].fsStyle, x, cx);
1377 btnPtr[i].fsState |= TBSTATE_WRAP;
1378 x = infoPtr->nIndent;
1379 bButtonWrap = FALSE;
1382 else if ( i >= infoPtr->nNumButtons)
1385 /* If the current button is not a separator, find the last */
1386 /* separator and wrap it. */
1387 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1389 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1390 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1394 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1395 i, btnPtr[i].fsStyle, x, cx);
1396 x = infoPtr->nIndent;
1397 btnPtr[j].fsState |= TBSTATE_WRAP;
1398 bButtonWrap = FALSE;
1403 /* If no separator available for wrapping, wrap one of */
1404 /* non-hidden previous button. */
1408 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1410 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1415 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1416 i, btnPtr[i].fsStyle, x, cx);
1417 x = infoPtr->nIndent;
1418 btnPtr[j].fsState |= TBSTATE_WRAP;
1424 /* If all above failed, wrap the current button. */
1427 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1428 i, btnPtr[i].fsStyle, x, cx);
1429 btnPtr[i].fsState |= TBSTATE_WRAP;
1430 x = infoPtr->nIndent;
1431 if (btnPtr[i].fsStyle & BTNS_SEP )
1432 bButtonWrap = FALSE;
1438 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1439 i, btnPtr[i].fsStyle, x, cx);
1446 /***********************************************************************
1447 * TOOLBAR_MeasureButton
1449 * Calculates the width and height required for a button. Used in
1450 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1451 * the width of buttons that are autosized.
1453 * Note that it would have been rather elegant to use one piece of code for
1454 * both the laying out of the toolbar and for controlling where button parts
1455 * are drawn, but the native control has inconsistencies between the two that
1456 * prevent this from being effectively. These inconsistencies can be seen as
1457 * artefacts where parts of the button appear outside of the bounding button
1460 * There are several cases for the calculation of the button dimensions and
1461 * button part positioning:
1468 * +--------------------------------------------------------+ ^
1470 * | | pad.cy / 2 | centred | |
1471 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1472 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1473 * | |<------------>| | | | |
1474 * | +--------------+ +------------+ | |
1475 * |<-------------------------------------->| | |
1476 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1478 * +--------------------------------------------------------+ -
1479 * <-------------------------------------------------------->
1480 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1482 * Without Bitmap (I_IMAGENONE):
1484 * +-----------------------------------+ ^
1486 * | | centred | | LISTPAD_CY +
1487 * | +------------+ | | szText.cy
1490 * | +------------+ | |
1491 * |<----------------->| | |
1492 * | cxedge |<-----------> | |
1494 * +-----------------------------------+ -
1495 * <----------------------------------->
1496 * szText.cx + pad.cx
1500 * +--------------------------------------+ ^
1502 * | | padding.cy/2 | | DEFPAD_CY +
1503 * | +------------+ | | nBitmapHeight
1506 * | +------------+ | |
1507 * |<------------------->| | |
1508 * | cxedge + iListGap/2 |<-----------> | |
1509 * | nBitmapWidth | |
1510 * +--------------------------------------+ -
1511 * <-------------------------------------->
1512 * 2*cxedge + nBitmapWidth + iListGap
1519 * +-----------------------------------+ ^
1521 * | | pad.cy / 2 | | nBitmapHeight +
1522 * | - | | szText.cy +
1523 * | +------------+ | | DEFPAD_CY + 1
1524 * | centred | Bitmap | | |
1525 * |<----------------->| | | |
1526 * | +------------+ | |
1530 * | centred +---------------+ | |
1531 * |<--------------->| Text | | |
1532 * | +---------------+ | |
1533 * +-----------------------------------+ -
1534 * <----------------------------------->
1535 * pad.cx + max(nBitmapWidth, szText.cx)
1537 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1539 * +---------------------------------------+ ^
1541 * | | 2 + pad.cy / 2 | |
1542 * | - | | szText.cy +
1543 * | centred +-----------------+ | | pad.cy + 2
1544 * |<--------------->| Text | | |
1545 * | +-----------------+ | |
1547 * +---------------------------------------+ -
1548 * <--------------------------------------->
1549 * 2*cxedge + pad.cx + szText.cx
1552 * As for with bitmaps, but with szText.cx zero.
1554 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1555 BOOL bHasBitmap, BOOL bValidImageList)
1558 if (infoPtr->dwStyle & TBSTYLE_LIST)
1560 /* set button height from bitmap / text height... */
1561 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1564 /* ... add on the necessary padding */
1565 if (bValidImageList)
1568 sizeButton.cy += DEFPAD_CY;
1570 sizeButton.cy += LISTPAD_CY;
1573 sizeButton.cy += infoPtr->szPadding.cy;
1575 /* calculate button width */
1576 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1577 infoPtr->nBitmapWidth + infoPtr->iListGap;
1578 if (sizeString.cx > 0)
1579 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1586 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1587 if (sizeString.cy > 0)
1588 sizeButton.cy += 1 + sizeString.cy;
1589 sizeButton.cx = infoPtr->szPadding.cx +
1590 max(sizeString.cx, infoPtr->nBitmapWidth);
1594 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1595 NONLIST_NOTEXT_OFFSET;
1596 sizeButton.cx = infoPtr->szPadding.cx +
1597 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1604 /***********************************************************************
1605 * TOOLBAR_CalcToolbar
1607 * This function calculates button and separator placement. It first
1608 * calculates the button sizes, gets the toolbar window width and then
1609 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1610 * on. It assigns a new location to each item and sends this location to
1611 * the tooltip window if appropriate. Finally, it updates the rcBound
1612 * rect and calculates the new required toolbar window height.
1615 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1617 SIZE sizeString, sizeButton;
1618 BOOL validImageList = FALSE;
1620 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1622 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1624 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1625 validImageList = TRUE;
1626 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1627 infoPtr->nButtonWidth = sizeButton.cx;
1628 infoPtr->nButtonHeight = sizeButton.cy;
1629 infoPtr->iTopMargin = default_top_margin(infoPtr);
1631 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1632 infoPtr->nButtonWidth = infoPtr->cxMin;
1633 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1634 infoPtr->nButtonWidth = infoPtr->cxMax;
1636 TOOLBAR_LayoutToolbar(infoPtr);
1640 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1642 TBUTTON_INFO *btnPtr;
1644 INT i, nRows, nSepRows;
1647 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1648 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1650 TOOLBAR_WrapToolbar(infoPtr);
1652 x = infoPtr->nIndent;
1653 y = infoPtr->iTopMargin;
1654 cx = infoPtr->nButtonWidth;
1655 cy = infoPtr->nButtonHeight;
1657 nRows = nSepRows = 0;
1659 infoPtr->rcBound.top = y;
1660 infoPtr->rcBound.left = x;
1661 infoPtr->rcBound.bottom = y + cy;
1662 infoPtr->rcBound.right = x;
1664 btnPtr = infoPtr->buttons;
1666 TRACE("cy=%d\n", cy);
1668 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1671 if (btnPtr->fsState & TBSTATE_HIDDEN)
1673 SetRectEmpty (&btnPtr->rect);
1677 cy = infoPtr->nButtonHeight;
1679 if (btnPtr->fsStyle & BTNS_SEP) {
1680 if (infoPtr->dwStyle & CCS_VERT) {
1681 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1682 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nWidth;
1685 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1686 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1692 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1693 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1699 hdc = GetDC (infoPtr->hwndSelf);
1700 hOldFont = SelectObject (hdc, infoPtr->hFont);
1702 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1704 SelectObject (hdc, hOldFont);
1705 ReleaseDC (infoPtr->hwndSelf, hdc);
1707 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1708 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1713 cx = infoPtr->nButtonWidth;
1715 /* if size has been set manually then don't add on extra space
1716 * for the drop down arrow */
1717 if (!btnPtr->cx && hasDropDownArrows &&
1718 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1719 cx += DDARROW_WIDTH;
1721 if (btnPtr->fsState & TBSTATE_WRAP )
1724 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1726 if (infoPtr->rcBound.left > x)
1727 infoPtr->rcBound.left = x;
1728 if (infoPtr->rcBound.right < x + cx)
1729 infoPtr->rcBound.right = x + cx;
1730 if (infoPtr->rcBound.bottom < y + cy)
1731 infoPtr->rcBound.bottom = y + cy;
1733 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1735 /* btnPtr->nRow is zero based. The space between the rows is */
1736 /* also considered as a row. */
1737 btnPtr->nRow = nRows + nSepRows;
1739 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1740 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1745 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1749 if ( !(infoPtr->dwStyle & CCS_VERT))
1750 y += cy + ( (btnPtr->cx > 0 ) ?
1751 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1755 /* nSepRows is used to calculate the extra height following */
1759 x = infoPtr->nIndent;
1761 /* Increment row number unless this is the last button */
1762 /* and it has Wrap set. */
1763 if (i != infoPtr->nNumButtons-1)
1770 /* infoPtr->nRows is the number of rows on the toolbar */
1771 infoPtr->nRows = nRows + nSepRows + 1;
1773 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1778 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt)
1780 TBUTTON_INFO *btnPtr;
1783 btnPtr = infoPtr->buttons;
1784 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1785 if (btnPtr->fsState & TBSTATE_HIDDEN)
1788 if (btnPtr->fsStyle & BTNS_SEP) {
1789 if (PtInRect (&btnPtr->rect, *lpPt)) {
1790 TRACE(" ON SEPARATOR %d!\n", i);
1795 if (PtInRect (&btnPtr->rect, *lpPt)) {
1796 TRACE(" ON BUTTON %d!\n", i);
1802 TRACE(" NOWHERE!\n");
1803 return TOOLBAR_NOWHERE;
1807 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1809 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1811 INT nOldButtons, nNewButtons, iButton;
1812 BOOL fHasString = FALSE;
1814 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1815 iIndex = infoPtr->nNumButtons;
1817 nOldButtons = infoPtr->nNumButtons;
1818 nNewButtons = nOldButtons + nAddButtons;
1820 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1821 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1822 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1823 infoPtr->nNumButtons += nAddButtons;
1825 /* insert new buttons data */
1826 for (iButton = 0; iButton < nAddButtons; iButton++) {
1827 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1829 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1831 ZeroMemory(btnPtr, sizeof(*btnPtr));
1833 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1834 btnPtr->idCommand = lpTbb[iButton].idCommand;
1835 btnPtr->fsState = lpTbb[iButton].fsState;
1836 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1837 btnPtr->dwData = lpTbb[iButton].dwData;
1838 if (btnPtr->fsStyle & BTNS_SEP)
1839 btnPtr->iString = -1;
1840 else if(HIWORD(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1843 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1845 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1849 btnPtr->iString = lpTbb[iButton].iString;
1851 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1854 if (infoPtr->nNumStrings > 0 || fHasString)
1855 TOOLBAR_CalcToolbar(infoPtr);
1857 TOOLBAR_LayoutToolbar(infoPtr);
1858 TOOLBAR_AutoSize(infoPtr);
1860 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1861 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1867 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1869 TBUTTON_INFO *btnPtr;
1872 if (CommandIsIndex) {
1873 TRACE("command is really index command=%d\n", idCommand);
1874 if (idCommand >= infoPtr->nNumButtons) return -1;
1877 btnPtr = infoPtr->buttons;
1878 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1879 if (btnPtr->idCommand == idCommand) {
1880 TRACE("command=%d index=%d\n", idCommand, i);
1884 TRACE("no index found for command=%d\n", idCommand);
1890 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1892 TBUTTON_INFO *btnPtr;
1895 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1898 /* check index button */
1899 btnPtr = &infoPtr->buttons[nIndex];
1900 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1901 if (btnPtr->fsState & TBSTATE_CHECKED)
1905 /* check previous buttons */
1906 nRunIndex = nIndex - 1;
1907 while (nRunIndex >= 0) {
1908 btnPtr = &infoPtr->buttons[nRunIndex];
1909 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1910 if (btnPtr->fsState & TBSTATE_CHECKED)
1918 /* check next buttons */
1919 nRunIndex = nIndex + 1;
1920 while (nRunIndex < infoPtr->nNumButtons) {
1921 btnPtr = &infoPtr->buttons[nRunIndex];
1922 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1923 if (btnPtr->fsState & TBSTATE_CHECKED)
1936 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1937 WPARAM wParam, LPARAM lParam)
1943 msg.wParam = wParam;
1944 msg.lParam = lParam;
1945 msg.time = GetMessageTime ();
1946 msg.pt.x = (short)LOWORD(GetMessagePos ());
1947 msg.pt.y = (short)HIWORD(GetMessagePos ());
1949 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1953 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1955 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1958 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1959 ti.cbSize = sizeof (TTTOOLINFOW);
1960 ti.hwnd = infoPtr->hwndSelf;
1961 ti.uId = button->idCommand;
1963 ti.lpszText = LPSTR_TEXTCALLBACKW;
1964 /* ti.lParam = random value from the stack? */
1966 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1972 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1974 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1977 ZeroMemory(&ti, sizeof(ti));
1978 ti.cbSize = sizeof(ti);
1979 ti.hwnd = infoPtr->hwndSelf;
1980 ti.uId = button->idCommand;
1982 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1986 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1988 /* Set the toolTip only for non-hidden, non-separator button */
1989 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1993 ZeroMemory(&ti, sizeof(ti));
1994 ti.cbSize = sizeof(ti);
1995 ti.hwnd = infoPtr->hwndSelf;
1996 ti.uId = button->idCommand;
1997 ti.rect = button->rect;
1998 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2002 /* Creates the tooltip control */
2004 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2007 NMTOOLTIPSCREATED nmttc;
2009 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2010 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2011 infoPtr->hwndSelf, 0, 0, 0);
2013 if (!infoPtr->hwndToolTip)
2016 /* Send NM_TOOLTIPSCREATED notification */
2017 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2018 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2020 for (i = 0; i < infoPtr->nNumButtons; i++)
2022 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2023 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2027 /* keeps available button list box sorted by button id */
2028 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2032 PCUSTOMBUTTON btnInfo;
2033 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2035 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2037 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2039 /* position 0 is always separator */
2040 for (i = 1; i < count; i++)
2042 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2043 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2045 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2046 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2050 /* id higher than all others add to end */
2051 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2052 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2055 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2059 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2061 if (nIndexFrom == nIndexTo)
2064 /* MSDN states that iItem is the index of the button, rather than the
2065 * command ID as used by every other NMTOOLBAR notification */
2066 nmtb.iItem = nIndexFrom;
2067 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2069 PCUSTOMBUTTON btnInfo;
2071 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2072 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2074 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2076 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2077 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2078 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2079 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2082 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2084 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2086 /* last item is always separator, so -2 instead of -1 */
2087 if (nIndexTo >= (count - 2))
2088 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2090 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2092 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2093 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2095 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2099 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2103 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2105 /* MSDN states that iItem is the index of the button, rather than the
2106 * command ID as used by every other NMTOOLBAR notification */
2107 nmtb.iItem = nIndexAvail;
2108 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2110 PCUSTOMBUTTON btnInfo;
2112 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2113 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2114 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2116 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2118 if (nIndexAvail != 0) /* index == 0 indicates separator */
2120 /* remove from 'available buttons' list */
2121 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2122 if (nIndexAvail == count-1)
2123 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2125 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2129 PCUSTOMBUTTON btnNew;
2131 /* duplicate 'separator' button */
2132 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2137 /* insert into 'toolbar button' list */
2138 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2139 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2141 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2143 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2147 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2149 PCUSTOMBUTTON btnInfo;
2150 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2152 TRACE("Remove: index %d\n", index);
2154 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2156 /* send TBN_QUERYDELETE notification */
2157 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2161 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2162 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2164 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2166 /* insert into 'available button' list */
2167 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2168 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2172 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2176 /* drag list notification function for toolbar buttons list box */
2177 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2178 const DRAGLISTINFO *pDLI)
2180 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2181 switch (pDLI->uNotification)
2185 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2186 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2187 /* no dragging for last item (separator) */
2188 if (nCurrentItem >= (nCount - 1)) return FALSE;
2193 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2194 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2195 /* no dragging past last item (separator) */
2196 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2198 DrawInsert(hwnd, hwndList, nCurrentItem);
2199 /* FIXME: native uses "move button" cursor */
2200 return DL_COPYCURSOR;
2203 /* not over toolbar buttons list */
2204 if (nCurrentItem < 0)
2206 POINT ptWindow = pDLI->ptCursor;
2207 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2208 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2209 /* over available buttons list? */
2210 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2211 /* FIXME: native uses "move button" cursor */
2212 return DL_COPYCURSOR;
2214 /* clear drag arrow */
2215 DrawInsert(hwnd, hwndList, -1);
2216 return DL_STOPCURSOR;
2220 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2221 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2222 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2223 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2225 /* clear drag arrow */
2226 DrawInsert(hwnd, hwndList, -1);
2228 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2230 /* not over toolbar buttons list */
2233 POINT ptWindow = pDLI->ptCursor;
2234 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2235 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2236 /* over available buttons list? */
2237 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2238 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2243 /* Clear drag arrow */
2244 DrawInsert(hwnd, hwndList, -1);
2251 /* drag list notification function for available buttons list box */
2252 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2253 const DRAGLISTINFO *pDLI)
2255 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2256 switch (pDLI->uNotification)
2262 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2263 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2264 /* no dragging past last item (separator) */
2265 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2267 DrawInsert(hwnd, hwndList, nCurrentItem);
2268 /* FIXME: native uses "move button" cursor */
2269 return DL_COPYCURSOR;
2272 /* not over toolbar buttons list */
2273 if (nCurrentItem < 0)
2275 POINT ptWindow = pDLI->ptCursor;
2276 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2277 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2278 /* over available buttons list? */
2279 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2280 /* FIXME: native uses "move button" cursor */
2281 return DL_COPYCURSOR;
2283 /* clear drag arrow */
2284 DrawInsert(hwnd, hwndList, -1);
2285 return DL_STOPCURSOR;
2289 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2290 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2291 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2292 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2294 /* clear drag arrow */
2295 DrawInsert(hwnd, hwndList, -1);
2297 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2301 /* Clear drag arrow */
2302 DrawInsert(hwnd, hwndList, -1);
2308 extern UINT uDragListMessage;
2310 /***********************************************************************
2311 * TOOLBAR_CustomizeDialogProc
2312 * This function implements the toolbar customization dialog.
2314 static INT_PTR CALLBACK
2315 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2317 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2318 PCUSTOMBUTTON btnInfo;
2320 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2325 custInfo = (PCUSTDLG_INFO)lParam;
2326 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2333 NMTBINITCUSTOMIZE nmtbic;
2335 infoPtr = custInfo->tbInfo;
2337 /* send TBN_QUERYINSERT notification */
2338 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2340 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2343 nmtbic.hwndDialog = hwnd;
2344 /* Send TBN_INITCUSTOMIZE notification */
2345 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2348 TRACE("TBNRF_HIDEHELP requested\n");
2349 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2352 /* add items to 'toolbar buttons' list and check if removable */
2353 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2355 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2356 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2357 btnInfo->btn.fsStyle = BTNS_SEP;
2358 btnInfo->bVirtual = FALSE;
2359 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2361 /* send TBN_QUERYDELETE notification */
2362 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2364 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2365 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2368 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2370 /* insert separator button into 'available buttons' list */
2371 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2372 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2373 btnInfo->btn.fsStyle = BTNS_SEP;
2374 btnInfo->bVirtual = FALSE;
2375 btnInfo->bRemovable = TRUE;
2376 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2377 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2378 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2380 /* insert all buttons into dsa */
2383 /* send TBN_GETBUTTONINFO notification */
2386 nmtb.pszText = Buffer;
2389 /* Clear previous button's text */
2390 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2392 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2395 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2396 nmtb.tbButton.fsStyle, i,
2397 nmtb.tbButton.idCommand,
2398 nmtb.tbButton.iString,
2399 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2402 /* insert button into the apropriate list */
2403 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2406 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2407 btnInfo->bVirtual = FALSE;
2408 btnInfo->bRemovable = TRUE;
2412 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2413 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2416 btnInfo->btn = nmtb.tbButton;
2417 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2419 if (lstrlenW(nmtb.pszText))
2420 lstrcpyW(btnInfo->text, nmtb.pszText);
2421 else if (nmtb.tbButton.iString >= 0 &&
2422 nmtb.tbButton.iString < infoPtr->nNumStrings)
2424 lstrcpyW(btnInfo->text,
2425 infoPtr->strings[nmtb.tbButton.iString]);
2430 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2433 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2435 /* select first item in the 'available' list */
2436 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2438 /* append 'virtual' separator button to the 'toolbar buttons' list */
2439 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2440 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2441 btnInfo->btn.fsStyle = BTNS_SEP;
2442 btnInfo->bVirtual = TRUE;
2443 btnInfo->bRemovable = FALSE;
2444 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2445 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2446 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2448 /* select last item in the 'toolbar' list */
2449 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2450 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2452 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2453 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2455 /* set focus and disable buttons */
2456 PostMessageW (hwnd, WM_USER, 0, 0);
2461 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2462 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2463 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2464 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2468 EndDialog(hwnd, FALSE);
2472 switch (LOWORD(wParam))
2474 case IDC_TOOLBARBTN_LBOX:
2475 if (HIWORD(wParam) == LBN_SELCHANGE)
2477 PCUSTOMBUTTON btnInfo;
2482 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2483 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2485 /* send TBN_QUERYINSERT notification */
2487 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2489 /* get list box item */
2490 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2492 if (index == (count - 1))
2494 /* last item (virtual separator) */
2495 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2496 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2498 else if (index == (count - 2))
2500 /* second last item (last non-virtual item) */
2501 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2502 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2504 else if (index == 0)
2507 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2508 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2512 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2513 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2516 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2520 case IDC_MOVEUP_BTN:
2522 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2523 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2527 case IDC_MOVEDN_BTN: /* move down */
2529 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2530 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2534 case IDC_REMOVE_BTN: /* remove button */
2536 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2538 if (LB_ERR == index)
2541 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2545 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2548 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2551 case IDOK: /* Add button */
2556 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2557 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2559 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2564 EndDialog(hwnd, FALSE);
2574 /* delete items from 'toolbar buttons' listbox*/
2575 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2576 for (i = 0; i < count; i++)
2578 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2580 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2582 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2585 /* delete items from 'available buttons' listbox*/
2586 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2587 for (i = 0; i < count; i++)
2589 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2591 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2593 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2598 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2600 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2605 COLORREF oldText = 0;
2609 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2610 if (btnInfo == NULL)
2612 FIXME("btnInfo invalid!\n");
2616 /* set colors and select objects */
2617 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2618 if (btnInfo->bVirtual)
2619 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2621 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2622 hPen = CreatePen( PS_SOLID, 1,
2623 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2624 hOldPen = SelectObject (lpdis->hDC, hPen );
2625 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2627 /* fill background rectangle */
2628 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2629 lpdis->rcItem.right, lpdis->rcItem.bottom);
2631 /* calculate button and text rectangles */
2632 CopyRect (&rcButton, &lpdis->rcItem);
2633 InflateRect (&rcButton, -1, -1);
2634 CopyRect (&rcText, &rcButton);
2635 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2636 rcText.left = rcButton.right + 2;
2638 /* draw focus rectangle */
2639 if (lpdis->itemState & ODS_FOCUS)
2640 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2643 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2644 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2646 /* draw image and text */
2647 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2648 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2649 btnInfo->btn.iBitmap));
2650 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2651 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2653 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2654 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2656 /* delete objects and reset colors */
2657 SelectObject (lpdis->hDC, hOldBrush);
2658 SelectObject (lpdis->hDC, hOldPen);
2659 SetBkColor (lpdis->hDC, oldBk);
2660 SetTextColor (lpdis->hDC, oldText);
2661 DeleteObject( hPen );
2666 case WM_MEASUREITEM:
2667 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2669 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2671 lpmis->itemHeight = 15 + 8; /* default height */
2678 if (uDragListMessage && (uMsg == uDragListMessage))
2680 if (wParam == IDC_TOOLBARBTN_LBOX)
2682 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2683 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2684 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2687 else if (wParam == IDC_AVAILBTN_LBOX)
2689 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2690 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2691 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2700 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2703 INT nCountBefore = ImageList_GetImageCount(himlDef);
2709 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2710 /* Add bitmaps to the default image list */
2711 if (bitmap->hInst == NULL) /* a handle was passed */
2712 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2714 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2716 /* enlarge the bitmap if needed */
2717 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2718 if (bitmap->hInst != COMCTL32_hModule)
2719 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2721 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2722 DeleteObject(hbmLoad);
2726 nCountAfter = ImageList_GetImageCount(himlDef);
2727 nAdded = nCountAfter - nCountBefore;
2728 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2730 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2731 } else if (nAdded > (INT)bitmap->nButtons) {
2732 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2733 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2736 infoPtr->nNumBitmaps += nAdded;
2741 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2748 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2749 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2751 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2753 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2756 TRACE("Update icon size: %dx%d -> %dx%d\n",
2757 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2759 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2760 ILC_COLORDDB|ILC_MASK, 8, 2);
2761 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2762 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2763 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2764 infoPtr->himlInt = himlNew;
2766 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2767 ImageList_Destroy(himlDef);
2770 /***********************************************************************
2771 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2775 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2781 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2785 if (lpAddBmp->hInst == HINST_COMMCTRL)
2787 info.hInst = COMCTL32_hModule;
2788 switch (lpAddBmp->nID)
2790 case IDB_STD_SMALL_COLOR:
2792 info.nID = IDB_STD_SMALL;
2794 case IDB_STD_LARGE_COLOR:
2796 info.nID = IDB_STD_LARGE;
2798 case IDB_VIEW_SMALL_COLOR:
2800 info.nID = IDB_VIEW_SMALL;
2802 case IDB_VIEW_LARGE_COLOR:
2804 info.nID = IDB_VIEW_LARGE;
2806 case IDB_HIST_SMALL_COLOR:
2808 info.nID = IDB_HIST_SMALL;
2810 case IDB_HIST_LARGE_COLOR:
2812 info.nID = IDB_HIST_LARGE;
2818 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2820 /* Windows resize all the buttons to the size of a newly added standard image */
2821 if (lpAddBmp->nID & 1)
2823 /* large icons: 24x24. Will make the button 31x30 */
2824 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2828 /* small icons: 16x16. Will make the buttons 23x22 */
2829 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2832 TOOLBAR_CalcToolbar (infoPtr);
2836 info.nButtons = count;
2837 info.hInst = lpAddBmp->hInst;
2838 info.nID = lpAddBmp->nID;
2839 TRACE("adding %d bitmaps!\n", info.nButtons);
2842 /* check if the bitmap is already loaded and compute iSumButtons */
2844 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2846 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2847 infoPtr->bitmaps[i].nID == info.nID)
2849 iSumButtons += infoPtr->bitmaps[i].nButtons;
2852 if (!infoPtr->cimlDef) {
2853 /* create new default image list */
2854 TRACE ("creating default image list!\n");
2856 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2857 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2858 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2859 infoPtr->himlInt = himlDef;
2862 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2866 WARN("No default image list available\n");
2870 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2873 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2874 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2875 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2876 infoPtr->nNumBitmapInfos++;
2877 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2879 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2885 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
2887 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
2889 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2894 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2896 #define MAX_RESOURCE_STRING_LENGTH 512
2897 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2898 INT nIndex = infoPtr->nNumStrings;
2900 if (hInstance && (HIWORD(lParam) == 0)) {
2901 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2906 TRACE("adding string from resource!\n");
2908 len = LoadStringW (hInstance, (UINT)lParam,
2909 szString, MAX_RESOURCE_STRING_LENGTH);
2911 TRACE("len=%d %s\n", len, debugstr_w(szString));
2912 if (len == 0 || len == 1)
2915 TRACE("Delimiter: 0x%x\n", *szString);
2916 delimiter = *szString;
2919 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2921 if (next_delim + 1 >= szString + len)
2923 /* this may happen if delimiter == '\0' or if the last char is a
2924 * delimiter (then it is ignored like the native does) */
2928 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2929 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2930 infoPtr->nNumStrings++;
2936 LPWSTR p = (LPWSTR)lParam;
2941 TRACE("adding string(s) from array!\n");
2945 TRACE("len=%d %s\n", len, debugstr_w(p));
2946 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2947 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2948 infoPtr->nNumStrings++;
2955 TOOLBAR_CalcToolbar(infoPtr);
2961 TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2963 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2968 if (hInstance && (HIWORD(lParam) == 0)) /* load from resources */
2969 return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
2975 TRACE("adding string(s) from array!\n");
2976 nIndex = infoPtr->nNumStrings;
2979 TRACE("len=%d \"%s\"\n", len, p);
2981 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2982 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2983 infoPtr->nNumStrings++;
2989 TOOLBAR_CalcToolbar(infoPtr);
2995 TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
3002 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3004 parent = GetParent (infoPtr->hwndSelf);
3006 if (!parent || !infoPtr->bDoRedraw)
3009 GetClientRect(parent, &parent_rect);
3011 x = parent_rect.left;
3012 y = parent_rect.top;
3014 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3016 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3017 cx = parent_rect.right - parent_rect.left;
3019 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3021 TOOLBAR_LayoutToolbar(infoPtr);
3022 InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
3025 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3028 UINT uPosFlags = SWP_NOZORDER;
3030 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3032 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3033 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3034 y = window_rect.top;
3036 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3038 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3039 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3042 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3043 uPosFlags |= SWP_NOMOVE;
3045 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3046 cy += GetSystemMetrics(SM_CYEDGE);
3048 if (infoPtr->dwStyle & WS_BORDER)
3050 x = y = 1; /* FIXME: this looks wrong */
3051 cy += GetSystemMetrics(SM_CYEDGE);
3052 cx += GetSystemMetrics(SM_CXEDGE);
3055 SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
3062 static inline LRESULT
3063 TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
3065 return infoPtr->nNumButtons;
3069 static inline LRESULT
3070 TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
3072 infoPtr->dwStructSize = Size;
3079 TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
3081 TBUTTON_INFO *btnPtr;
3084 TRACE("button %d, iBitmap now %d\n", Id, Index);
3086 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3090 btnPtr = &infoPtr->buttons[nIndex];
3091 btnPtr->iBitmap = Index;
3093 /* we HAVE to erase the background, the new bitmap could be */
3095 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3102 TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3104 TBUTTON_INFO *btnPtr;
3107 BOOL bChecked = FALSE;
3109 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3111 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
3116 btnPtr = &infoPtr->buttons[nIndex];
3118 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3120 if (LOWORD(lParam) == FALSE)
3121 btnPtr->fsState &= ~TBSTATE_CHECKED;
3123 if (btnPtr->fsStyle & BTNS_GROUP) {
3125 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3126 if (nOldIndex == nIndex)
3128 if (nOldIndex != -1)
3129 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3131 btnPtr->fsState |= TBSTATE_CHECKED;
3134 if( bChecked != LOWORD(lParam) )
3136 if (nOldIndex != -1)
3137 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
3138 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3141 /* FIXME: Send a WM_NOTIFY?? */
3148 TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
3150 return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3155 TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
3157 CUSTDLG_INFO custInfo;
3163 custInfo.tbInfo = infoPtr;
3164 custInfo.tbHwnd = infoPtr->hwndSelf;
3166 /* send TBN_BEGINADJUST notification */
3167 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3169 if (!(hRes = FindResourceW (COMCTL32_hModule,
3170 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3171 (LPWSTR)RT_DIALOG)))
3174 if(!(template = LoadResource (COMCTL32_hModule, hRes)))
3177 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_HINSTANCE),
3178 template, infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc,
3181 /* send TBN_ENDADJUST notification */
3182 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3189 TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
3192 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3194 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3197 memset(&nmtb, 0, sizeof(nmtb));
3198 nmtb.iItem = btnPtr->idCommand;
3199 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3200 nmtb.tbButton.idCommand = btnPtr->idCommand;
3201 nmtb.tbButton.fsState = btnPtr->fsState;
3202 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3203 nmtb.tbButton.dwData = btnPtr->dwData;
3204 nmtb.tbButton.iString = btnPtr->iString;
3205 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3207 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3209 if (infoPtr->nNumButtons == 1) {
3210 TRACE(" simple delete!\n");
3211 if (TOOLBAR_ButtonHasString(infoPtr->buttons))
3212 Free((LPWSTR)infoPtr->buttons[0].iString);
3213 Free (infoPtr->buttons);
3214 infoPtr->buttons = NULL;
3215 infoPtr->nNumButtons = 0;
3218 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3219 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3221 infoPtr->nNumButtons--;
3222 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3224 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3225 nIndex * sizeof(TBUTTON_INFO));
3228 if (nIndex < infoPtr->nNumButtons) {
3229 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3230 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3233 if (TOOLBAR_ButtonHasString(&oldButtons[nIndex]))
3234 Free((LPWSTR)oldButtons[nIndex].iString);
3238 TOOLBAR_LayoutToolbar(infoPtr);
3240 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3247 TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3249 TBUTTON_INFO *btnPtr;
3253 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3255 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
3260 btnPtr = &infoPtr->buttons[nIndex];
3262 bState = btnPtr->fsState & TBSTATE_ENABLED;
3264 /* update the toolbar button state */
3265 if(LOWORD(lParam) == FALSE) {
3266 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3268 btnPtr->fsState |= TBSTATE_ENABLED;
3271 /* redraw the button only if the state of the button changed */
3272 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3273 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3279 static inline LRESULT
3280 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
3282 return infoPtr->bAnchor;
3287 TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
3291 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3295 return infoPtr->buttons[nIndex].iBitmap;
3299 static inline LRESULT
3300 TOOLBAR_GetBitmapFlags (void)
3302 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3307 TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
3309 TBUTTON_INFO *btnPtr;
3314 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3317 btnPtr = &infoPtr->buttons[nIndex];
3318 lpTbb->iBitmap = btnPtr->iBitmap;
3319 lpTbb->idCommand = btnPtr->idCommand;
3320 lpTbb->fsState = btnPtr->fsState;
3321 lpTbb->fsStyle = btnPtr->fsStyle;
3322 lpTbb->bReserved[0] = 0;
3323 lpTbb->bReserved[1] = 0;
3324 lpTbb->dwData = btnPtr->dwData;
3325 lpTbb->iString = btnPtr->iString;
3332 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
3334 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3335 TBUTTON_INFO *btnPtr;
3338 if (lpTbInfo == NULL)
3341 /* MSDN documents a iImageLabel field added in Vista but it is not present in
3342 * the headers and tests shows that even with comctl 6 Vista accepts only the
3343 * original TBBUTTONINFO size
3345 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3347 WARN("Invalid button size\n");
3351 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
3355 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3357 if (lpTbInfo->dwMask & TBIF_COMMAND)
3358 lpTbInfo->idCommand = btnPtr->idCommand;
3359 if (lpTbInfo->dwMask & TBIF_IMAGE)
3360 lpTbInfo->iImage = btnPtr->iBitmap;
3361 if (lpTbInfo->dwMask & TBIF_LPARAM)
3362 lpTbInfo->lParam = btnPtr->dwData;
3363 if (lpTbInfo->dwMask & TBIF_SIZE)
3364 /* tests show that for separators TBIF_SIZE returns not calculated width,
3365 but cx property, that differs from 0 only if application have
3366 specifically set it */
3367 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3368 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3369 if (lpTbInfo->dwMask & TBIF_STATE)
3370 lpTbInfo->fsState = btnPtr->fsState;
3371 if (lpTbInfo->dwMask & TBIF_STYLE)
3372 lpTbInfo->fsStyle = btnPtr->fsStyle;
3373 if (lpTbInfo->dwMask & TBIF_TEXT) {
3374 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3375 can't use TOOLBAR_GetText here */
3376 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3377 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3379 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3381 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3383 lpTbInfo->pszText[0] = '\0';
3389 static inline LRESULT
3390 TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
3392 return MAKELONG((WORD)infoPtr->nButtonWidth,
3393 (WORD)infoPtr->nButtonHeight);
3398 TOOLBAR_GetButtonText (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr, BOOL isW)
3404 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3408 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3414 ret = strlenW (lpText);
3415 if (lpStr) strcpyW (lpStr, lpText);
3419 ret = WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3420 (LPSTR)lpStr, lpStr ? 0x7fffffff : 0, NULL, NULL ) - 1;
3426 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3428 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3429 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3430 return (LRESULT)GETDISIMAGELIST(infoPtr, wParam);
3434 static inline LRESULT
3435 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO *infoPtr)
3439 return infoPtr->dwExStyle;
3444 TOOLBAR_GetHotImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3446 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3447 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3448 return (LRESULT)GETHOTIMAGELIST(infoPtr, wParam);
3453 TOOLBAR_GetHotItem (const TOOLBAR_INFO *infoPtr)
3455 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3458 if (infoPtr->nHotItem < 0)
3461 return (LRESULT)infoPtr->nHotItem;
3466 TOOLBAR_GetDefImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3468 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3469 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3470 return (LRESULT) GETDEFIMAGELIST(infoPtr, wParam);
3475 TOOLBAR_GetInsertMark (const TOOLBAR_INFO *infoPtr, TBINSERTMARK *lptbim)
3477 TRACE("hwnd = %p, lptbim = %p\n", infoPtr->hwndSelf, lptbim);
3479 *lptbim = infoPtr->tbim;
3485 static inline LRESULT
3486 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO *infoPtr)
3488 TRACE("hwnd = %p\n", infoPtr->hwndSelf);
3490 return (LRESULT)infoPtr->clrInsertMark;
3495 TOOLBAR_GetItemRect (const TOOLBAR_INFO *infoPtr, INT nIndex, LPRECT lpRect)
3497 TBUTTON_INFO *btnPtr;
3499 btnPtr = &infoPtr->buttons[nIndex];
3500 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3505 if (btnPtr->fsState & TBSTATE_HIDDEN)
3508 lpRect->left = btnPtr->rect.left;
3509 lpRect->right = btnPtr->rect.right;
3510 lpRect->bottom = btnPtr->rect.bottom;
3511 lpRect->top = btnPtr->rect.top;
3518 TOOLBAR_GetMaxSize (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
3523 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3524 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3526 TRACE("maximum size %d x %d\n",
3527 infoPtr->rcBound.right - infoPtr->rcBound.left,
3528 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3534 /* << TOOLBAR_GetObject >> */
3537 static inline LRESULT
3538 TOOLBAR_GetPadding (const TOOLBAR_INFO *infoPtr)
3540 return MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3545 TOOLBAR_GetRect (const TOOLBAR_INFO *infoPtr, INT Id, LPRECT lpRect)
3547 TBUTTON_INFO *btnPtr;
3550 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3551 btnPtr = &infoPtr->buttons[nIndex];
3552 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3558 lpRect->left = btnPtr->rect.left;
3559 lpRect->right = btnPtr->rect.right;
3560 lpRect->bottom = btnPtr->rect.bottom;
3561 lpRect->top = btnPtr->rect.top;
3567 static inline LRESULT
3568 TOOLBAR_GetRows (const TOOLBAR_INFO *infoPtr)
3570 return infoPtr->nRows;
3575 TOOLBAR_GetState (const TOOLBAR_INFO *infoPtr, INT Id)
3579 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3583 return infoPtr->buttons[nIndex].fsState;
3587 static inline LRESULT
3588 TOOLBAR_GetStyle (const TOOLBAR_INFO *infoPtr)
3590 return infoPtr->dwStyle;
3594 static inline LRESULT
3595 TOOLBAR_GetTextRows (const TOOLBAR_INFO *infoPtr)
3597 return infoPtr->nMaxTextRows;
3602 TOOLBAR_GetToolTips (TOOLBAR_INFO *infoPtr)
3604 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3605 TOOLBAR_TooltipCreateControl(infoPtr);
3606 return (LRESULT)infoPtr->hwndToolTip;
3611 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO *infoPtr)
3613 TRACE("%s hwnd=%p\n",
3614 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
3616 return infoPtr->bUnicode;
3620 static inline LRESULT
3621 TOOLBAR_GetVersion (const TOOLBAR_INFO *infoPtr)
3623 return infoPtr->iVersion;
3628 TOOLBAR_HideButton (TOOLBAR_INFO *infoPtr, INT Id, BOOL fHide)
3630 TBUTTON_INFO *btnPtr;
3636 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3640 btnPtr = &infoPtr->buttons[nIndex];
3641 oldState = btnPtr->fsState;
3644 btnPtr->fsState |= TBSTATE_HIDDEN;
3646 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3648 if (oldState != btnPtr->fsState) {
3649 TOOLBAR_LayoutToolbar (infoPtr);
3650 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3657 static inline LRESULT
3658 TOOLBAR_HitTest (const TOOLBAR_INFO *infoPtr, const POINT* lpPt)
3660 return TOOLBAR_InternalHitTest (infoPtr, lpPt);
3665 TOOLBAR_Indeterminate (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fIndeterminate)
3667 TBUTTON_INFO *btnPtr;
3671 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3675 btnPtr = &infoPtr->buttons[nIndex];
3676 oldState = btnPtr->fsState;
3679 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3681 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3683 if(oldState != btnPtr->fsState)
3684 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3691 TOOLBAR_InsertButtonT(TOOLBAR_INFO *infoPtr, INT nIndex, const TBBUTTON *lpTbb, BOOL fUnicode)
3697 /* EPP: this seems to be an undocumented call (from my IE4)
3698 * I assume in that case that:
3699 * - index of insertion is at the end of existing buttons
3700 * I only see this happen with nIndex == -1, but it could have a special
3701 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3703 nIndex = infoPtr->nNumButtons;
3705 } else if (nIndex < 0)
3708 TRACE("inserting button index=%d\n", nIndex);
3709 if (nIndex > infoPtr->nNumButtons) {
3710 nIndex = infoPtr->nNumButtons;
3711 TRACE("adjust index=%d\n", nIndex);
3714 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3717 /* << TOOLBAR_InsertMarkHitTest >> */
3721 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO *infoPtr, INT Id)
3725 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3729 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3734 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO *infoPtr, INT Id)
3738 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3742 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3747 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO *infoPtr, INT Id)
3751 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3755 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3760 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO *infoPtr, INT Id)
3764 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3768 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3773 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO *infoPtr, INT Id)
3777 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3781 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3786 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO *infoPtr, INT Id)
3790 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3794 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3799 TOOLBAR_LoadImages (TOOLBAR_INFO *infoPtr, WPARAM wParam, HINSTANCE hInstance)
3802 tbab.hInst = hInstance;
3805 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr->hwndSelf, tbab.hInst, tbab.nID);
3807 return TOOLBAR_AddBitmap(infoPtr, 0, &tbab);
3812 TOOLBAR_MapAccelerator (const TOOLBAR_INFO *infoPtr, WCHAR wAccel, UINT *pIDButton)
3814 WCHAR wszAccel[] = {'&',wAccel,0};
3817 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3818 infoPtr->hwndSelf, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3820 for (i = 0; i < infoPtr->nNumButtons; i++)
3822 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3823 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3824 !(btnPtr->fsState & TBSTATE_HIDDEN))
3826 int iLen = strlenW(wszAccel);
3827 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3834 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3839 if (!strncmpiW(lpszStr, wszAccel, iLen))
3841 *pIDButton = btnPtr->idCommand;
3853 TOOLBAR_MarkButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fMark)
3857 TBUTTON_INFO *btnPtr;
3859 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr->hwndSelf, Id, fMark);
3861 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3865 btnPtr = &infoPtr->buttons[nIndex];
3866 oldState = btnPtr->fsState;
3869 btnPtr->fsState |= TBSTATE_MARKED;
3871 btnPtr->fsState &= ~TBSTATE_MARKED;
3873 if(oldState != btnPtr->fsState)
3874 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3880 /* fixes up an index of a button affected by a move */
3881 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3885 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3887 else if (*pIndex == nIndex)
3888 *pIndex = nMoveIndex;
3892 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3894 else if (*pIndex == nIndex)
3895 *pIndex = nMoveIndex;
3901 TOOLBAR_MoveButton (TOOLBAR_INFO *infoPtr, INT Id, INT nMoveIndex)
3905 TBUTTON_INFO button;
3907 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr->hwndSelf, Id, nMoveIndex);
3909 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, TRUE);
3910 if ((nIndex == -1) || (nMoveIndex < 0))
3913 if (nMoveIndex > infoPtr->nNumButtons - 1)
3914 nMoveIndex = infoPtr->nNumButtons - 1;
3916 button = infoPtr->buttons[nIndex];
3918 /* move button right */
3919 if (nIndex < nMoveIndex)
3921 nCount = nMoveIndex - nIndex;
3922 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
3923 infoPtr->buttons[nMoveIndex] = button;
3925 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
3926 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
3927 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
3928 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
3930 else if (nIndex > nMoveIndex) /* move button left */
3932 nCount = nIndex - nMoveIndex;
3933 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
3934 infoPtr->buttons[nMoveIndex] = button;
3936 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
3937 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
3938 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
3939 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
3942 TOOLBAR_LayoutToolbar(infoPtr);
3943 TOOLBAR_AutoSize(infoPtr);
3944 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3951 TOOLBAR_PressButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fPress)
3953 TBUTTON_INFO *btnPtr;
3957 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3961 btnPtr = &infoPtr->buttons[nIndex];
3962 oldState = btnPtr->fsState;
3965 btnPtr->fsState |= TBSTATE_PRESSED;
3967 btnPtr->fsState &= ~TBSTATE_PRESSED;
3969 if(oldState != btnPtr->fsState)
3970 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3975 /* FIXME: there might still be some confusion her between number of buttons
3976 * and number of bitmaps */
3978 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO *infoPtr, const TBREPLACEBITMAP *lpReplace)
3981 int i = 0, nOldButtons = 0, pos = 0;
3982 int nOldBitmaps, nNewBitmaps = 0;
3983 HIMAGELIST himlDef = 0;
3985 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3986 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3987 lpReplace->nButtons);
3989 if (lpReplace->hInstOld == HINST_COMMCTRL)
3991 FIXME("changing standard bitmaps not implemented\n");
3994 else if (lpReplace->hInstOld != 0)
3995 FIXME("resources not in the current module not implemented\n");
3997 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
3998 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3999 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4000 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4001 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4003 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4004 nOldButtons = tbi->nButtons;
4005 tbi->nButtons = lpReplace->nButtons;
4006 tbi->hInst = lpReplace->hInstNew;
4007 tbi->nID = lpReplace->nIDNew;
4008 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4011 pos += tbi->nButtons;
4014 if (nOldButtons == 0)
4016 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4020 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4023 if (lpReplace->hInstNew)
4024 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4026 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4028 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4029 nOldBitmaps = ImageList_GetImageCount(himlDef);
4031 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4033 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4034 ImageList_Remove(himlDef, i);
4038 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4039 nNewBitmaps = ImageList_GetImageCount(himlDef);
4040 DeleteObject(hBitmap);
4043 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4045 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4046 pos, nOldBitmaps, nNewBitmaps);
4048 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4053 /* helper for TOOLBAR_SaveRestoreW */
4055 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4057 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4058 debugstr_w(lpSave->pszValueName));
4064 /* helper for TOOLBAR_Restore */
4066 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4070 for (i = 0; i < infoPtr->nNumButtons; i++)
4072 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4075 Free(infoPtr->buttons);
4076 infoPtr->buttons = NULL;
4077 infoPtr->nNumButtons = 0;
4081 /* helper for TOOLBAR_SaveRestoreW */
4083 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4092 /* restore toolbar information */
4093 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4094 debugstr_w(lpSave->pszValueName));
4096 memset(&nmtbr, 0, sizeof(nmtbr));
4098 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4099 KEY_QUERY_VALUE, &hkey);
4101 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4103 if (!res && dwType != REG_BINARY)
4104 res = ERROR_FILE_NOT_FOUND;
4107 nmtbr.pData = Alloc(dwSize);
4108 nmtbr.cbData = dwSize;
4109 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4112 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4113 (LPBYTE)nmtbr.pData, &dwSize);
4116 nmtbr.pCurrent = nmtbr.pData;
4118 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4119 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4121 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4125 /* remove all existing buttons as this function is designed to
4126 * restore the toolbar to a previously saved state */
4127 TOOLBAR_DeleteAllButtons(infoPtr);
4129 for (i = 0; i < nmtbr.cButtons; i++)
4132 nmtbr.tbButton.iBitmap = -1;
4133 nmtbr.tbButton.fsState = 0;
4134 nmtbr.tbButton.fsStyle = 0;
4135 nmtbr.tbButton.idCommand = 0;
4136 if (*nmtbr.pCurrent == (DWORD)-1)
4139 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4140 /* when inserting separators, iBitmap controls it's size.
4141 0 sets default size (width) */
4142 nmtbr.tbButton.iBitmap = 0;
4144 else if (*nmtbr.pCurrent == (DWORD)-2)
4146 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4148 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4152 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4154 /* can't contain real string as we don't know whether
4155 * the client put an ANSI or Unicode string in there */
4156 if (HIWORD(nmtbr.tbButton.iString))
4157 nmtbr.tbButton.iString = 0;
4159 TOOLBAR_InsertButtonT(infoPtr, -1, &nmtbr.tbButton, TRUE);
4162 /* do legacy notifications */
4163 if (infoPtr->iVersion < 5)
4165 /* FIXME: send TBN_BEGINADJUST */
4166 FIXME("send TBN_GETBUTTONINFO for each button\n");
4167 /* FIXME: send TBN_ENDADJUST */
4170 /* remove all uninitialised buttons
4171 * note: loop backwards to avoid having to fixup i on a
4173 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4174 if (infoPtr->buttons[i].iBitmap == -1)
4175 TOOLBAR_DeleteButton(infoPtr, i);
4177 /* only indicate success if at least one button survived */
4178 if (infoPtr->nNumButtons > 0) ret = TRUE;
4189 TOOLBAR_SaveRestoreW (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4191 if (lpSave == NULL) return 0;
4194 return TOOLBAR_Save(lpSave);
4196 return TOOLBAR_Restore(infoPtr, lpSave);
4201 TOOLBAR_SaveRestoreA (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4203 LPWSTR pszValueName = 0, pszSubKey = 0;
4204 TBSAVEPARAMSW SaveW;
4208 if (lpSave == NULL) return 0;
4210 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4211 pszSubKey = Alloc(len * sizeof(WCHAR));
4212 if (pszSubKey) goto exit;
4213 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4215 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4216 pszValueName = Alloc(len * sizeof(WCHAR));
4217 if (!pszValueName) goto exit;
4218 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4220 SaveW.pszValueName = pszValueName;
4221 SaveW.pszSubKey = pszSubKey;
4222 SaveW.hkr = lpSave->hkr;
4223 result = TOOLBAR_SaveRestoreW(infoPtr, wParam, &SaveW);
4226 Free (pszValueName);
4234 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO *infoPtr, BOOL bAnchor)
4236 BOOL bOldAnchor = infoPtr->bAnchor;
4238 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr->hwndSelf, bAnchor ? "TRUE" : "FALSE");
4240 infoPtr->bAnchor = bAnchor;
4242 /* Native does not remove the hot effect from an already hot button */
4244 return (LRESULT)bOldAnchor;
4249 TOOLBAR_SetBitmapSize (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4251 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4252 short width = (short)LOWORD(lParam);
4253 short height = (short)HIWORD(lParam);
4255 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr->hwndSelf, wParam, lParam);
4258 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4260 /* 0 width or height is changed to 1 */
4266 if (infoPtr->nNumButtons > 0)
4267 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4268 infoPtr->nNumButtons,
4269 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4271 if (width < -1 || height < -1)
4273 /* Windows destroys the imagelist and seems to actually use negative
4274 * values to compute button sizes */
4275 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4279 /* width or height of -1 means no change */
4281 infoPtr->nBitmapWidth = width;
4283 infoPtr->nBitmapHeight = height;
4285 if ((himlDef == infoPtr->himlInt) &&
4286 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4288 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4289 infoPtr->nBitmapHeight);
4292 TOOLBAR_CalcToolbar(infoPtr);
4293 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4299 TOOLBAR_SetButtonInfo (TOOLBAR_INFO *infoPtr, INT Id,
4300 const TBBUTTONINFOW *lptbbi, BOOL isW)
4302 TBUTTON_INFO *btnPtr;
4308 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4311 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lptbbi->dwMask & TBIF_BYINDEX);
4315 btnPtr = &infoPtr->buttons[nIndex];
4316 if (lptbbi->dwMask & TBIF_COMMAND)
4317 btnPtr->idCommand = lptbbi->idCommand;
4318 if (lptbbi->dwMask & TBIF_IMAGE)
4319 btnPtr->iBitmap = lptbbi->iImage;
4320 if (lptbbi->dwMask & TBIF_LPARAM)
4321 btnPtr->dwData = lptbbi->lParam;
4322 if (lptbbi->dwMask & TBIF_SIZE)
4323 btnPtr->cx = lptbbi->cx;
4324 if (lptbbi->dwMask & TBIF_STATE)
4325 btnPtr->fsState = lptbbi->fsState;
4326 if (lptbbi->dwMask & TBIF_STYLE)
4327 btnPtr->fsStyle = lptbbi->fsStyle;
4329 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4330 /* iString is index, zero it to make Str_SetPtr succeed */
4331 if (!TOOLBAR_ButtonHasString(btnPtr)) btnPtr->iString = 0;
4334 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4336 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, (LPSTR)lptbbi->pszText);
4339 /* save the button rect to see if we need to redraw the whole toolbar */
4340 oldBtnRect = btnPtr->rect;
4341 TOOLBAR_LayoutToolbar(infoPtr);
4343 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4344 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4346 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4353 TOOLBAR_SetButtonSize (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4355 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4357 if ((cx < 0) || (cy < 0))
4359 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4363 TRACE("%p, cx = %d, cy = %d\n", infoPtr->hwndSelf, cx, cy);
4365 /* The documentation claims you can only change the button size before
4366 * any button has been added. But this is wrong.
4367 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4368 * it to the toolbar, and it checks that the return value is nonzero - mjm
4369 * Further testing shows that we must actually perform the change too.
4372 * The documentation also does not mention that if 0 is supplied for
4373 * either size, the system changes it to the default of 24 wide and
4374 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4376 if (cx == 0) cx = 24;
4377 if (cy == 0) cy = 22;
4379 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4380 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4382 infoPtr->nButtonWidth = cx;
4383 infoPtr->nButtonHeight = cy;
4385 infoPtr->iTopMargin = default_top_margin(infoPtr);
4386 TOOLBAR_LayoutToolbar(infoPtr);
4392 TOOLBAR_SetButtonWidth (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4394 /* if setting to current values, ignore */
4395 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4396 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4397 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4398 infoPtr->cxMin, infoPtr->cxMax);
4402 /* save new values */
4403 infoPtr->cxMin = (short)LOWORD(lParam);
4404 infoPtr->cxMax = (short)HIWORD(lParam);
4406 /* otherwise we need to recalc the toolbar and in some cases
4407 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4408 which doesn't actually draw - GA). */
4409 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4410 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4412 TOOLBAR_CalcToolbar (infoPtr);
4414 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
4421 TOOLBAR_SetCmdId (TOOLBAR_INFO *infoPtr, INT nIndex, INT nId)
4423 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4426 infoPtr->buttons[nIndex].idCommand = nId;
4428 if (infoPtr->hwndToolTip) {
4430 FIXME("change tool tip!\n");
4439 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4441 HIMAGELIST himlTemp;
4444 if (infoPtr->iVersion >= 5)
4447 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4448 &infoPtr->cimlDis, himl, id);
4450 /* FIXME: redraw ? */
4452 return (LRESULT)himlTemp;
4457 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4461 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr->hwndSelf, (DWORD)wParam, (DWORD)lParam);
4463 dwTemp = infoPtr->dwDTFlags;
4464 infoPtr->dwDTFlags =
4465 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4467 return (LRESULT)dwTemp;
4470 /* This function differs a bit from what MSDN says it does:
4471 * 1. lParam contains extended style flags to OR with current style
4472 * (MSDN isn't clear on the OR bit)
4473 * 2. wParam appears to contain extended style flags to be reset
4474 * (MSDN says that this parameter is reserved)
4477 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4481 dwOldStyle = infoPtr->dwExStyle;
4482 infoPtr->dwExStyle = (DWORD)lParam;
4484 TRACE("new style 0x%08x\n", infoPtr->dwExStyle);
4486 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4487 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4488 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4490 if ((dwOldStyle ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4491 TOOLBAR_CalcToolbar(infoPtr);
4493 TOOLBAR_LayoutToolbar(infoPtr);
4495 TOOLBAR_AutoSize(infoPtr);
4496 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4498 return (LRESULT)dwOldStyle;
4503 TOOLBAR_SetHotImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4505 HIMAGELIST himlTemp;
4508 if (infoPtr->iVersion >= 5)
4511 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr->hwndSelf, himl, id);
4513 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4514 &infoPtr->cimlHot, himl, id);
4516 /* FIXME: redraw ? */
4518 return (LRESULT)himlTemp;
4522 /* Makes previous hot button no longer hot, makes the specified
4523 * button hot and sends appropriate notifications. dwReason is one or
4524 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4525 * NOTE 1: this function does not validate nHit
4526 * NOTE 2: the name of this function is completely made up and
4527 * not based on any documentation from Microsoft. */
4529 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4531 if (infoPtr->nHotItem != nHit)
4533 NMTBHOTITEM nmhotitem;
4534 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4536 nmhotitem.dwFlags = dwReason;
4537 if(infoPtr->nHotItem >= 0)
4539 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4540 nmhotitem.idOld = oldBtnPtr->idCommand;
4544 nmhotitem.dwFlags |= HICF_ENTERING;
4545 nmhotitem.idOld = 0;
4550 btnPtr = &infoPtr->buttons[nHit];
4551 nmhotitem.idNew = btnPtr->idCommand;
4555 nmhotitem.dwFlags |= HICF_LEAVING;
4556 nmhotitem.idNew = 0;
4559 /* now change the hot and invalidate the old and new buttons - if the
4561 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4564 oldBtnPtr->bHot = FALSE;
4565 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4567 /* setting disabled buttons as hot fails even if the notify contains the button id */
4568 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4569 btnPtr->bHot = TRUE;
4570 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4571 infoPtr->nHotItem = nHit;
4574 infoPtr->nHotItem = -1;
4580 TOOLBAR_SetHotItem (TOOLBAR_INFO *infoPtr, INT nHotItem)
4582 INT nOldHotItem = infoPtr->nHotItem;
4584 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr->hwndSelf, nHotItem);
4586 if (nHotItem >= infoPtr->nNumButtons)
4587 return infoPtr->nHotItem;
4592 /* NOTE: an application can still remove the hot item even if anchor
4593 * highlighting is enabled */
4595 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, HICF_OTHER);
4597 if (nOldHotItem < 0)
4600 return (LRESULT)nOldHotItem;
4605 TOOLBAR_SetImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4607 HIMAGELIST himlTemp;
4608 INT oldButtonWidth = infoPtr->nButtonWidth;
4609 INT oldBitmapWidth = infoPtr->nBitmapWidth;
4610 INT oldBitmapHeight = infoPtr->nBitmapHeight;
4613 if (infoPtr->iVersion >= 5)
4616 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4617 &infoPtr->cimlDef, himl, id);
4619 infoPtr->nNumBitmaps = 0;
4620 for (i = 0; i < infoPtr->cimlDef; i++)
4621 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4623 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4624 &infoPtr->nBitmapHeight))
4626 infoPtr->nBitmapWidth = 1;
4627 infoPtr->nBitmapHeight = 1;
4629 if ((oldBitmapWidth != infoPtr->nBitmapWidth) || (oldBitmapHeight != infoPtr->nBitmapHeight))
4631 TOOLBAR_CalcToolbar(infoPtr);
4632 if (infoPtr->nButtonWidth < oldButtonWidth)
4633 TOOLBAR_SetButtonSize(infoPtr, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4636 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4637 infoPtr->hwndSelf, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4638 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4640 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4642 return (LRESULT)himlTemp;
4647 TOOLBAR_SetIndent (TOOLBAR_INFO *infoPtr, INT nIndent)
4649 infoPtr->nIndent = nIndent;
4653 /* process only on indent changing */
4654 if(infoPtr->nIndent != nIndent)
4656 infoPtr->nIndent = nIndent;
4657 TOOLBAR_CalcToolbar (infoPtr);
4658 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4666 TOOLBAR_SetInsertMark (TOOLBAR_INFO *infoPtr, const TBINSERTMARK *lptbim)
4668 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr->hwndSelf, lptbim->iButton, lptbim->dwFlags);
4670 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4672 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4676 if ((lptbim->iButton == -1) ||
4677 ((lptbim->iButton < infoPtr->nNumButtons) &&
4678 (lptbim->iButton >= 0)))
4680 infoPtr->tbim = *lptbim;
4681 /* FIXME: don't need to update entire toolbar */
4682 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4685 ERR("Invalid button index %d\n", lptbim->iButton);
4692 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO *infoPtr, COLORREF clr)
4694 infoPtr->clrInsertMark = clr;
4696 /* FIXME: don't need to update entire toolbar */
4697 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4704 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO *infoPtr, INT nMaxRows)
4706 infoPtr->nMaxTextRows = nMaxRows;
4708 TOOLBAR_CalcToolbar(infoPtr);
4713 /* MSDN gives slightly wrong info on padding.
4714 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4715 * 2. It is not used to create a blank area between the edge of the button
4716 * and the text or image if TBSTYLE_LIST is set. It is used to control
4717 * the gap between the image and text.
4718 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4719 * to control the bottom and right borders [with the border being
4720 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4721 * is shared evenly on both sides of the button.
4722 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4725 TOOLBAR_SetPadding (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4729 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4730 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4731 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4732 TRACE("cx=%d, cy=%d\n",
4733 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4734 return (LRESULT) oldPad;
4739 TOOLBAR_SetParent (TOOLBAR_INFO *infoPtr, HWND hParent)
4745 hwndOldNotify = infoPtr->hwndNotify;
4746 infoPtr->hwndNotify = hParent;
4748 return (LRESULT)hwndOldNotify;
4753 TOOLBAR_SetRows (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPRECT lprc)
4755 int rows = LOWORD(wParam);
4756 BOOL bLarger = HIWORD(wParam);
4760 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4762 if(infoPtr->nRows != rows)
4764 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4765 int curColumn = 0; /* Current column */
4766 int curRow = 0; /* Current row */
4767 int hidden = 0; /* Number of hidden buttons */
4768 int seps = 0; /* Number of separators */
4769 int idealWrap = 0; /* Ideal wrap point */
4774 Calculate new size and wrap points - Under windows, setrows will
4775 change the dimensions if needed to show the number of requested
4776 rows (if CCS_NORESIZE is set), or will take up the whole window
4777 (if no CCS_NORESIZE).
4779 Basic algorithm - If N buttons, and y rows requested, each row
4780 contains N/y buttons.
4782 FIXME: Handling of separators not obvious from testing results
4783 FIXME: Take width of window into account?
4786 /* Loop through the buttons one by one counting key items */
4787 for (i = 0; i < infoPtr->nNumButtons; i++ )
4789 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4790 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4792 else if (btnPtr[i].fsStyle & BTNS_SEP)
4796 /* FIXME: Separators make this quite complex */
4797 if (seps) FIXME("Separators unhandled\n");
4799 /* Round up so more per line, i.e., less rows */
4800 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / (rows ? rows : 1);
4802 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4803 achieve the requested number of rows. */
4804 if (bLarger && idealWrap > 1)
4806 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4807 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4809 if (resRows < rows && moreRows > rows)
4812 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
4816 curColumn = curRow = 0;
4818 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
4819 infoPtr->nNumButtons, hidden, rows);
4821 for (i = 0; i < infoPtr->nNumButtons; i++ )
4823 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4826 /* Step on, wrap if necessary or flag next to wrap */
4835 if (curColumn > (idealWrap-1)) {
4837 btnPtr[i].fsState |= TBSTATE_WRAP;
4841 TRACE("Result - %d rows\n", curRow + 1);
4843 /* recalculate toolbar */
4844 TOOLBAR_CalcToolbar (infoPtr);
4846 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4847 if NORESIZE is NOT set, then the toolbar will always be resized to
4848 take up the whole window. With it set, sizing needs to be manual. */
4849 if (infoPtr->dwStyle & CCS_NORESIZE) {
4850 SetWindowPos(infoPtr->hwndSelf, NULL, 0, 0,
4851 infoPtr->rcBound.right - infoPtr->rcBound.left,
4852 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
4856 /* repaint toolbar */
4857 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4860 /* return bounding rectangle */
4862 lprc->left = infoPtr->rcBound.left;
4863 lprc->right = infoPtr->rcBound.right;
4864 lprc->top = infoPtr->rcBound.top;
4865 lprc->bottom = infoPtr->rcBound.bottom;
4873 TOOLBAR_SetState (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
4875 TBUTTON_INFO *btnPtr;
4878 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
4882 btnPtr = &infoPtr->buttons[nIndex];
4884 /* if hidden state has changed the invalidate entire window and recalc */
4885 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4886 btnPtr->fsState = LOWORD(lParam);
4887 TOOLBAR_CalcToolbar (infoPtr);
4888 InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
4892 /* process state changing if current state doesn't match new state */
4893 if(btnPtr->fsState != LOWORD(lParam))
4895 btnPtr->fsState = LOWORD(lParam);
4896 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4904 TOOLBAR_SetStyle (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4906 SetWindowLongW(infoPtr->hwndSelf, GWL_STYLE, lParam);
4912 static inline LRESULT
4913 TOOLBAR_SetToolTips (TOOLBAR_INFO *infoPtr, HWND hwndTooltip)
4915 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr->hwndSelf, hwndTooltip);
4917 infoPtr->hwndToolTip = hwndTooltip;
4923 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO *infoPtr, WPARAM wParam)
4927 TRACE("%s hwnd=%p\n",
4928 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf);
4930 bTemp = infoPtr->bUnicode;
4931 infoPtr->bUnicode = (BOOL)wParam;
4938 TOOLBAR_GetColorScheme (const TOOLBAR_INFO *infoPtr, LPCOLORSCHEME lParam)
4940 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4941 comctl32_color.clrBtnHighlight :
4942 infoPtr->clrBtnHighlight;
4943 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4944 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4950 TOOLBAR_SetColorScheme (TOOLBAR_INFO *infoPtr, const COLORSCHEME *lParam)
4952 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4953 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4954 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4956 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4957 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4958 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4964 TOOLBAR_SetVersion (TOOLBAR_INFO *infoPtr, INT iVersion)
4966 INT iOldVersion = infoPtr->iVersion;
4968 infoPtr->iVersion = iVersion;
4970 if (infoPtr->iVersion >= 5)
4971 TOOLBAR_SetUnicodeFormat(infoPtr, TRUE);
4978 TOOLBAR_GetStringA (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPSTR str)
4980 WORD iString = HIWORD(wParam);
4981 WORD buffersize = LOWORD(wParam);
4984 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, buffersize, str);
4986 if (iString < infoPtr->nNumStrings)
4988 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4991 TRACE("returning %s\n", debugstr_a(str));
4994 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5001 TOOLBAR_GetStringW (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPWSTR str)
5003 WORD iString = HIWORD(wParam);
5004 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5007 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, LOWORD(wParam), str);
5009 if (iString < infoPtr->nNumStrings)
5011 len = min(len, strlenW(infoPtr->strings[iString]));
5012 ret = (len+1)*sizeof(WCHAR);
5015 memcpy(str, infoPtr->strings[iString], ret);
5020 TRACE("returning %s\n", debugstr_w(str));
5023 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5028 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5029 * is the maximum size of the toolbar? */
5030 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5032 SIZE * pSize = (SIZE*)lParam;
5033 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5038 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5039 * caller to specify a reason why the hot item changed (rather than just the
5040 * HICF_OTHER that TB_SETHOTITEM sends). */
5042 TOOLBAR_SetHotItem2 (TOOLBAR_INFO *infoPtr, INT nHotItem, LPARAM lParam)
5044 INT nOldHotItem = infoPtr->nHotItem;
5046 TRACE("old item=%d, new item=%d, flags=%08x\n",
5047 nOldHotItem, nHotItem, (DWORD)lParam);
5049 if (nHotItem < 0 || nHotItem > infoPtr->nNumButtons)
5052 /* NOTE: an application can still remove the hot item even if anchor
5053 * highlighting is enabled */
5055 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, lParam);
5059 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5062 /* Sets the toolbar global iListGap parameter which controls the amount of
5063 * spacing between the image and the text of buttons for TBSTYLE_LIST
5065 static LRESULT TOOLBAR_SetListGap(TOOLBAR_INFO *infoPtr, INT iListGap)
5067 TRACE("hwnd=%p iListGap=%d\n", infoPtr->hwndSelf, iListGap);
5069 infoPtr->iListGap = iListGap;
5071 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
5076 /* Returns the number of maximum number of image lists associated with the
5077 * various states. */
5078 static LRESULT TOOLBAR_GetImageListCount(const TOOLBAR_INFO *infoPtr)
5080 TRACE("hwnd=%p\n", infoPtr->hwndSelf);
5082 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5086 TOOLBAR_GetIdealSize (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5088 LPSIZE lpsize = (LPSIZE)lParam;
5094 * Testing shows the following:
5095 * wParam = 0 adjust cx value
5096 * = 1 set cy value to max size.
5097 * lParam pointer to SIZE structure
5100 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5101 wParam, lParam, lpsize->cx, lpsize->cy);
5105 if (lpsize->cx == -1) {
5106 /* **** this is wrong, native measures each button and sets it */
5107 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5109 else if(HIWORD(lpsize->cx)) {
5111 HWND hwndParent = GetParent(infoPtr->hwndSelf);
5113 GetWindowRect(infoPtr->hwndSelf, &rc);
5114 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5115 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5116 lpsize->cx = max(rc.right-rc.left,
5117 infoPtr->rcBound.right - infoPtr->rcBound.left);
5120 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5124 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5127 FIXME("Unknown wParam %ld\n", wParam);
5130 TRACE("set to -> 0x%08x 0x%08x\n",
5131 lpsize->cx, lpsize->cy);
5135 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5137 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5139 InvalidateRect(hwnd, NULL, TRUE);
5145 TOOLBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
5147 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
5148 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5151 TRACE("hwnd = %p\n", hwnd);
5153 infoPtr->dwStyle = dwStyle;
5154 GetClientRect(hwnd, &infoPtr->client_rect);
5155 infoPtr->bUnicode = infoPtr->hwndNotify &&
5156 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5157 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5159 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5160 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5162 OpenThemeData (hwnd, themeClass);
5164 TOOLBAR_CheckStyle (infoPtr, dwStyle);
5171 TOOLBAR_Destroy (TOOLBAR_INFO *infoPtr)
5175 /* delete tooltip control */
5176 if (infoPtr->hwndToolTip)
5177 DestroyWindow (infoPtr->hwndToolTip);
5179 /* delete temporary buffer for tooltip text */
5180 Free (infoPtr->pszTooltipText);
5181 Free (infoPtr->bitmaps); /* bitmaps list */
5183 /* delete button data */
5184 for (i = 0; i < infoPtr->nNumButtons; i++)
5185 if (TOOLBAR_ButtonHasString(&infoPtr->buttons[i]))
5186 Free ((LPWSTR)infoPtr->buttons[i].iString);
5187 Free (infoPtr->buttons);
5189 /* delete strings */
5190 if (infoPtr->strings) {
5191 for (i = 0; i < infoPtr->nNumStrings; i++)
5192 Free (infoPtr->strings[i]);
5194 Free (infoPtr->strings);
5197 /* destroy internal image list */
5198 if (infoPtr->himlInt)
5199 ImageList_Destroy (infoPtr->himlInt);
5201 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5202 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5203 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5205 /* delete default font */
5206 DeleteObject (infoPtr->hDefaultFont);
5208 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
5210 /* free toolbar info data */
5211 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
5219 TOOLBAR_EraseBackground (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5221 NMTBCUSTOMDRAW tbcd;
5224 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
5225 DWORD dwEraseCustDraw = 0;
5227 /* the app has told us not to redraw the toolbar */
5228 if (!infoPtr->bDoRedraw)
5231 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5232 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5233 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5234 tbcd.nmcd.hdc = (HDC)wParam;
5235 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5236 dwEraseCustDraw = ntfret & 0xffff;
5238 /* FIXME: in general the return flags *can* be or'ed together */
5239 switch (dwEraseCustDraw)
5241 case CDRF_DODEFAULT:
5243 case CDRF_SKIPDEFAULT:
5246 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5247 infoPtr->hwndSelf, ntfret);
5251 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5252 * to my parent for processing.
5254 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5256 HDC hdc = (HDC)wParam;
5261 parent = GetParent(infoPtr->hwndSelf);
5262 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
5263 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5264 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5265 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5268 ret = DefWindowProcW (infoPtr->hwndSelf, WM_ERASEBKGND, wParam, lParam);
5270 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5271 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5272 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5273 tbcd.nmcd.hdc = (HDC)wParam;
5274 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5275 dwEraseCustDraw = ntfret & 0xffff;
5276 switch (dwEraseCustDraw)
5278 case CDRF_DODEFAULT:
5280 case CDRF_SKIPDEFAULT:
5283 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5284 infoPtr->hwndSelf, ntfret);
5291 static inline LRESULT
5292 TOOLBAR_GetFont (const TOOLBAR_INFO *infoPtr)
5294 return (LRESULT)infoPtr->hFont;
5299 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5302 INT nNewHotItem = infoPtr->nHotItem;
5304 for (i = 0; i < infoPtr->nNumButtons; i++)
5307 if ((nNewHotItem + iDirection < 0) ||
5308 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5310 NMTBWRAPHOTITEM nmtbwhi;
5311 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5312 nmtbwhi.iDirection = iDirection;
5313 nmtbwhi.dwReason = dwReason;
5315 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5319 nNewHotItem += iDirection;
5320 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5322 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5323 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5325 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5332 TOOLBAR_KeyDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5336 nmkey.nVKey = (UINT)wParam;
5337 nmkey.uFlags = HIWORD(lParam);
5339 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5340 return DefWindowProcW(infoPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
5342 switch ((UINT)wParam)
5346 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5350 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5354 if ((infoPtr->nHotItem >= 0) &&
5355 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5357 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5358 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5359 (LPARAM)infoPtr->hwndSelf);
5369 TOOLBAR_LButtonDblClk (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5374 pt.x = (short)LOWORD(lParam);
5375 pt.y = (short)HIWORD(lParam);
5376 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5379 TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
5380 else if (infoPtr->dwStyle & CCS_ADJUSTABLE)
5381 TOOLBAR_Customize (infoPtr);
5388 TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5390 TBUTTON_INFO *btnPtr;
5395 BOOL bDragKeyPressed;
5399 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5400 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5402 bDragKeyPressed = (wParam & MK_SHIFT);
5404 if (infoPtr->hwndToolTip)
5405 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5406 WM_LBUTTONDOWN, wParam, lParam);
5408 pt.x = (short)LOWORD(lParam);
5409 pt.y = (short)HIWORD(lParam);
5410 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5412 btnPtr = &infoPtr->buttons[nHit];
5414 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5416 infoPtr->nButtonDrag = nHit;
5417 SetCapture (infoPtr->hwndSelf);
5419 /* If drag cursor has not been loaded, load it.
5420 * Note: it doesn't need to be freed */
5422 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5423 SetCursor(hCursorDrag);
5428 infoPtr->nOldHit = nHit;
5430 CopyRect(&arrowRect, &btnPtr->rect);
5431 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5433 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5434 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5435 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5436 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5437 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5438 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5442 /* draw in pressed state */
5443 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5444 btnPtr->fsState |= TBSTATE_PRESSED;
5446 btnPtr->bDropDownPressed = TRUE;
5447 RedrawWindow(infoPtr->hwndSelf,&btnPtr->rect,0,
5448 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5450 memset(&nmtb, 0, sizeof(nmtb));
5451 nmtb.iItem = btnPtr->idCommand;
5452 nmtb.rcButton = btnPtr->rect;
5453 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5455 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5457 if (res != TBDDRET_TREATPRESSED)
5461 /* redraw button in unpressed state */
5462 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5463 btnPtr->fsState &= ~TBSTATE_PRESSED;
5465 btnPtr->bDropDownPressed = FALSE;
5466 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5468 /* find and set hot item
5469 * NOTE: native doesn't do this, but that is a bug */
5471 ScreenToClient(infoPtr->hwndSelf, &pt);
5472 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
5473 if (!infoPtr->bAnchor || (nHit >= 0))
5474 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5476 /* remove any left mouse button down or double-click messages
5477 * so that we can get a toggle effect on the button */
5478 while (PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5479 PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5484 /* otherwise drop through and process as pushed */
5486 infoPtr->bCaptured = TRUE;
5487 infoPtr->nButtonDown = nHit;
5488 infoPtr->bDragOutSent = FALSE;
5490 btnPtr->fsState |= TBSTATE_PRESSED;
5492 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5494 if (btnPtr->fsState & TBSTATE_ENABLED)
5495 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5496 UpdateWindow(infoPtr->hwndSelf);
5497 SetCapture (infoPtr->hwndSelf);
5502 memset(&nmtb, 0, sizeof(nmtb));
5503 nmtb.iItem = btnPtr->idCommand;
5504 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5507 nmmouse.dwHitInfo = nHit;
5509 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5511 nmmouse.dwItemSpec = -1;
5514 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5515 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5518 ClientToScreen(infoPtr->hwndSelf, &pt);
5521 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5522 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONDOWN, wParam, lParam);
5528 TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5530 TBUTTON_INFO *btnPtr;
5538 if (infoPtr->hwndToolTip)
5539 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5540 WM_LBUTTONUP, wParam, lParam);
5542 pt.x = (short)LOWORD(lParam);
5543 pt.y = (short)HIWORD(lParam);
5544 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5546 if (!infoPtr->bAnchor || (nHit >= 0))
5547 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5549 if (infoPtr->nButtonDrag >= 0) {
5553 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5556 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5558 GetClientRect(infoPtr->hwndSelf, &rcClient);
5559 if (PtInRect(&rcClient, pt))
5566 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5569 if (nButton == infoPtr->nButtonDrag)
5571 /* if the button is moved sightly left and we have a
5572 * separator there then remove it */
5573 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5575 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5576 TOOLBAR_DeleteButton(infoPtr, nButton - 1);
5578 else /* else insert a separator before the dragged button */
5581 memset(&tbb, 0, sizeof(tbb));
5582 tbb.fsStyle = BTNS_SEP;
5584 TOOLBAR_InsertButtonT(infoPtr, nButton, &tbb, TRUE);
5591 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5592 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, 0);
5594 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5597 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, nButton);
5602 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5603 TOOLBAR_DeleteButton(infoPtr, (WPARAM)infoPtr->nButtonDrag);
5606 /* button under cursor changed so need to re-set hot item */
5607 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5608 infoPtr->nButtonDrag = -1;
5610 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5612 else if (infoPtr->nButtonDown >= 0) {
5613 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5614 btnPtr->fsState &= ~TBSTATE_PRESSED;
5616 if (btnPtr->fsStyle & BTNS_CHECK) {
5617 if (btnPtr->fsStyle & BTNS_GROUP) {
5618 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5620 if ((nOldIndex != nHit) &&
5622 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5623 btnPtr->fsState |= TBSTATE_CHECKED;
5626 if (btnPtr->fsState & TBSTATE_CHECKED)
5627 btnPtr->fsState &= ~TBSTATE_CHECKED;
5629 btnPtr->fsState |= TBSTATE_CHECKED;
5633 if (nOldIndex != -1)
5634 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
5637 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5638 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5639 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5641 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5643 infoPtr->nButtonDown = -1;
5645 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5646 TOOLBAR_SendNotify (&hdr, infoPtr,
5647 NM_RELEASEDCAPTURE);
5649 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5652 memset(&nmtb, 0, sizeof(nmtb));
5653 nmtb.iItem = btnPtr->idCommand;
5654 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5657 if (btnPtr->fsState & TBSTATE_ENABLED)
5659 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5660 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)infoPtr->hwndSelf);
5662 /* In case we have just been destroyed... */
5663 if(!IsWindow(infoPtr->hwndSelf))
5668 /* !!! Undocumented - toolbar at 4.71 level and above sends
5669 * NM_CLICK with the NMMOUSE structure. */
5670 nmmouse.dwHitInfo = nHit;
5673 nmmouse.dwItemSpec = -1;
5676 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5677 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5680 ClientToScreen(infoPtr->hwndSelf, &pt);
5683 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5684 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONUP, wParam, lParam);
5690 TOOLBAR_RButtonUp(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5696 pt.x = (short)LOWORD(lParam);
5697 pt.y = (short)HIWORD(lParam);
5699 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt);
5700 nmmouse.dwHitInfo = nHit;
5703 nmmouse.dwItemSpec = -1;
5705 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5706 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5709 ClientToScreen(infoPtr->hwndSelf, &pt);
5712 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5713 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONUP, wParam, lParam);
5719 TOOLBAR_RButtonDblClk( TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5723 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5724 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONDBLCLK, wParam, lParam);
5730 TOOLBAR_CaptureChanged(TOOLBAR_INFO *infoPtr)
5732 TBUTTON_INFO *btnPtr;
5734 infoPtr->bCaptured = FALSE;
5736 if (infoPtr->nButtonDown >= 0)
5738 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5739 btnPtr->fsState &= ~TBSTATE_PRESSED;
5741 infoPtr->nOldHit = -1;
5743 if (btnPtr->fsState & TBSTATE_ENABLED)
5744 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5750 TOOLBAR_MouseLeave (TOOLBAR_INFO *infoPtr)
5752 /* don't remove hot effects when in anchor highlighting mode or when a
5753 * drop-down button is pressed */
5754 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5756 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5757 if (!hotBtnPtr->bDropDownPressed)
5758 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5761 if (infoPtr->nOldHit < 0)
5764 /* If the last button we were over is depressed then make it not */
5765 /* depressed and redraw it */
5766 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5768 TBUTTON_INFO *btnPtr;
5771 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5773 btnPtr->fsState &= ~TBSTATE_PRESSED;
5776 InflateRect (&rc1, 1, 1);
5777 InvalidateRect (infoPtr->hwndSelf, &rc1, TRUE);
5780 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5783 ZeroMemory(&nmt, sizeof(nmt));
5784 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5785 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5786 infoPtr->bDragOutSent = TRUE;
5789 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5795 TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5798 TRACKMOUSEEVENT trackinfo;
5800 TBUTTON_INFO *btnPtr;
5802 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
5803 TOOLBAR_TooltipCreateControl(infoPtr);
5805 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
5806 /* fill in the TRACKMOUSEEVENT struct */
5807 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5808 trackinfo.dwFlags = TME_QUERY;
5810 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5811 _TrackMouseEvent(&trackinfo);
5813 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5814 if(trackinfo.hwndTrack != infoPtr->hwndSelf || !(trackinfo.dwFlags & TME_LEAVE)) {
5815 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5816 trackinfo.hwndTrack = infoPtr->hwndSelf;
5818 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5819 /* and can properly deactivate the hot toolbar button */
5820 _TrackMouseEvent(&trackinfo);
5824 if (infoPtr->hwndToolTip)
5825 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5826 WM_MOUSEMOVE, wParam, lParam);
5828 pt.x = (short)LOWORD(lParam);
5829 pt.y = (short)HIWORD(lParam);
5831 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt);
5833 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5834 && (!infoPtr->bAnchor || (nHit >= 0)))
5835 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5837 if (infoPtr->nOldHit != nHit)
5839 if (infoPtr->bCaptured)
5841 if (!infoPtr->bDragOutSent)
5844 ZeroMemory(&nmt, sizeof(nmt));
5845 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5846 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5847 infoPtr->bDragOutSent = TRUE;
5850 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5851 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5852 btnPtr->fsState &= ~TBSTATE_PRESSED;
5853 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5855 else if (nHit == infoPtr->nButtonDown) {
5856 btnPtr->fsState |= TBSTATE_PRESSED;
5857 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5859 infoPtr->nOldHit = nHit;
5867 static inline LRESULT
5868 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5870 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5871 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
5873 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5877 static inline LRESULT
5878 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5880 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5881 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5883 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
5888 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, const CREATESTRUCTW *lpcs)
5890 TOOLBAR_INFO *infoPtr;
5893 /* allocate memory for info structure */
5894 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
5895 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5898 infoPtr->dwStructSize = sizeof(TBBUTTON);
5900 infoPtr->nWidth = 0;
5902 /* initialize info structure */
5903 infoPtr->nButtonWidth = 23;
5904 infoPtr->nButtonHeight = 22;
5905 infoPtr->nBitmapHeight = 16;
5906 infoPtr->nBitmapWidth = 16;
5908 infoPtr->nMaxTextRows = 1;
5909 infoPtr->cxMin = -1;
5910 infoPtr->cxMax = -1;
5911 infoPtr->nNumBitmaps = 0;
5912 infoPtr->nNumStrings = 0;
5914 infoPtr->bCaptured = FALSE;
5915 infoPtr->nButtonDown = -1;
5916 infoPtr->nButtonDrag = -1;
5917 infoPtr->nOldHit = -1;
5918 infoPtr->nHotItem = -1;
5919 infoPtr->hwndNotify = lpcs->hwndParent;
5920 infoPtr->dwDTFlags = (lpcs->style & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5921 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5922 infoPtr->bDragOutSent = FALSE;
5923 infoPtr->iVersion = 0;
5924 infoPtr->hwndSelf = hwnd;
5925 infoPtr->bDoRedraw = TRUE;
5926 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5927 infoPtr->clrBtnShadow = CLR_DEFAULT;
5928 infoPtr->szPadding.cx = DEFPAD_CX;
5929 infoPtr->szPadding.cy = DEFPAD_CY;
5930 infoPtr->iListGap = DEFLISTGAP;
5931 infoPtr->iTopMargin = default_top_margin(infoPtr);
5932 infoPtr->dwStyle = lpcs->style;
5933 infoPtr->tbim.iButton = -1;
5935 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5936 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5937 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5938 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5941 /* native control does:
5942 * Get a lot of colors and brushes
5944 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
5945 * CreateFontIndirectW(adr1)
5946 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5947 * hdc = GetDC(toolbar)
5948 * GetSystemMetrics(0x48)
5949 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5950 * 0, 0, 0, 0, "MARLETT")
5951 * oldfnt = SelectObject(hdc, fnt2)
5952 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
5953 * GetTextMetricsW(hdc, adr3)
5954 * SelectObject(hdc, oldfnt)
5955 * DeleteObject(fnt2)
5957 * InvalidateRect(toolbar, 0, 1)
5958 * SetWindowLongW(toolbar, 0, addr)
5959 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
5962 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5963 * ie 2 0x4600094c 0x4600094c 0x4600894d
5964 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5965 * rebar 0x50008844 0x40008844 0x50008845
5966 * pager 0x50000844 0x40000844 0x50008845
5967 * IC35mgr 0x5400084e **nochange**
5968 * on entry to _NCCREATE 0x5400084e
5969 * rowlist 0x5400004e **nochange**
5970 * on entry to _NCCREATE 0x5400004e
5974 /* I think the code below is a bug, but it is the way that the native
5975 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5976 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5977 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5978 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5979 * Somehow, the only cases of this seem to be MFC programs.
5981 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5982 * does not occur in the WM_STYLECHANGING routine.
5983 * (Guy Albertelli 9/2001)
5986 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5987 && !(lpcs->style & TBSTYLE_TRANSPARENT))
5988 styleadd |= TBSTYLE_TRANSPARENT;
5989 if (!(lpcs->style & (CCS_TOP | CCS_NOMOVEY))) {
5990 styleadd |= CCS_TOP; /* default to top */
5991 SetWindowLongW (hwnd, GWL_STYLE, lpcs->style | styleadd);
5994 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, (LPARAM)lpcs);
5999 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6001 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6005 if (dwStyle & WS_MINIMIZE)
6006 return 0; /* Nothing to do */
6008 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6010 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6013 if (!(dwStyle & CCS_NODIVIDER))
6015 GetWindowRect (hwnd, &rcWindow);
6016 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6017 if( dwStyle & WS_BORDER )
6018 OffsetRect (&rcWindow, 1, 1);
6019 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6022 ReleaseDC( hwnd, hdc );
6028 /* handles requests from the tooltip control on what text to display */
6029 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6031 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6033 TRACE("button index = %d\n", index);
6035 Free (infoPtr->pszTooltipText);
6036 infoPtr->pszTooltipText = NULL;
6041 if (infoPtr->bUnicode)
6043 WCHAR wszBuffer[INFOTIPSIZE+1];
6044 NMTBGETINFOTIPW tbgit;
6045 unsigned int len; /* in chars */
6047 wszBuffer[0] = '\0';
6048 wszBuffer[INFOTIPSIZE] = '\0';
6050 tbgit.pszText = wszBuffer;
6051 tbgit.cchTextMax = INFOTIPSIZE;
6052 tbgit.iItem = lpnmtdi->hdr.idFrom;
6053 tbgit.lParam = infoPtr->buttons[index].dwData;
6055 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6057 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6059 len = strlenW(tbgit.pszText);
6060 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6062 /* need to allocate temporary buffer in infoPtr as there
6063 * isn't enough space in buffer passed to us by the
6064 * tooltip control */
6065 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6066 if (infoPtr->pszTooltipText)
6068 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6069 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6075 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6081 CHAR szBuffer[INFOTIPSIZE+1];
6082 NMTBGETINFOTIPA tbgit;
6083 unsigned int len; /* in chars */
6086 szBuffer[INFOTIPSIZE] = '\0';
6088 tbgit.pszText = szBuffer;
6089 tbgit.cchTextMax = INFOTIPSIZE;
6090 tbgit.iItem = lpnmtdi->hdr.idFrom;
6091 tbgit.lParam = infoPtr->buttons[index].dwData;
6093 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6095 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6097 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6098 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6100 /* need to allocate temporary buffer in infoPtr as there
6101 * isn't enough space in buffer passed to us by the
6102 * tooltip control */
6103 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6104 if (infoPtr->pszTooltipText)
6106 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6107 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6111 else if (tbgit.pszText[0])
6113 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6114 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6119 /* if button has text, but it is not shown then automatically
6120 * use that text as tooltip */
6121 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6122 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6124 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6125 unsigned int len = pszText ? strlenW(pszText) : 0;
6127 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6129 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6131 /* need to allocate temporary buffer in infoPtr as there
6132 * isn't enough space in buffer passed to us by the
6133 * tooltip control */
6134 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6135 if (infoPtr->pszTooltipText)
6137 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6138 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6144 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6149 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6151 /* last resort: send notification on to app */
6152 /* FIXME: find out what is really used here */
6153 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6157 static inline LRESULT
6158 TOOLBAR_Notify (TOOLBAR_INFO *infoPtr, LPNMHDR lpnmh)
6160 switch (lpnmh->code)
6164 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lpnmh;
6166 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6167 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6168 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6172 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6173 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6181 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lpnmh;
6183 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6184 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6185 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6186 lppgs->iScroll, lppgs->iDir);
6190 case TTN_GETDISPINFOW:
6191 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lpnmh);
6193 case TTN_GETDISPINFOA:
6194 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6204 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6208 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6210 if (lParam == NF_QUERY)
6213 if (lParam == NF_REQUERY) {
6214 format = SendMessageW(infoPtr->hwndNotify,
6215 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6216 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6217 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6228 TOOLBAR_Paint (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6233 /* fill ps.rcPaint with a default rect */
6234 ps.rcPaint = infoPtr->rcBound;
6236 hdc = wParam==0 ? BeginPaint(infoPtr->hwndSelf, &ps) : (HDC)wParam;
6238 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6240 TOOLBAR_Refresh (infoPtr, hdc, &ps);
6241 if (!wParam) EndPaint (infoPtr->hwndSelf, &ps);
6248 TOOLBAR_SetFocus (TOOLBAR_INFO *infoPtr)
6250 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6252 /* make first item hot */
6253 if (infoPtr->nNumButtons > 0)
6254 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6260 TOOLBAR_SetFont(TOOLBAR_INFO *infoPtr, HFONT hFont, WORD Redraw)
6262 TRACE("font=%p redraw=%d\n", hFont, Redraw);
6265 infoPtr->hFont = infoPtr->hDefaultFont;
6267 infoPtr->hFont = hFont;
6269 TOOLBAR_CalcToolbar(infoPtr);
6272 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6277 TOOLBAR_SetRedraw (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6278 /*****************************************************
6281 * Handles the WM_SETREDRAW message.
6284 * According to testing V4.71 of COMCTL32 returns the
6285 * *previous* status of the redraw flag (either 0 or 1)
6286 * instead of the MSDN documented value of 0 if handled.
6287 * (For laughs see the "consistency" with same function
6290 *****************************************************/
6292 BOOL oldredraw = infoPtr->bDoRedraw;
6294 TRACE("set to %s\n",
6295 (wParam) ? "TRUE" : "FALSE");
6296 infoPtr->bDoRedraw = (BOOL) wParam;
6298 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6300 return (oldredraw) ? 1 : 0;
6305 TOOLBAR_Size (TOOLBAR_INFO *infoPtr)
6307 TRACE("sizing toolbar!\n");
6309 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6311 RECT delta_width, delta_height, client, dummy;
6312 DWORD min_x, max_x, min_y, max_y;
6313 TBUTTON_INFO *btnPtr;
6316 GetClientRect(infoPtr->hwndSelf, &client);
6317 if(client.right > infoPtr->client_rect.right)
6319 min_x = infoPtr->client_rect.right;
6320 max_x = client.right;
6324 max_x = infoPtr->client_rect.right;
6325 min_x = client.right;
6327 if(client.bottom > infoPtr->client_rect.bottom)
6329 min_y = infoPtr->client_rect.bottom;
6330 max_y = client.bottom;
6334 max_y = infoPtr->client_rect.bottom;
6335 min_y = client.bottom;
6338 SetRect(&delta_width, min_x, 0, max_x, min_y);
6339 SetRect(&delta_height, 0, min_y, max_x, max_y);
6341 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6342 btnPtr = infoPtr->buttons;
6343 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6344 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6345 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6346 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
6348 GetClientRect(infoPtr->hwndSelf, &infoPtr->client_rect);
6349 TOOLBAR_AutoSize(infoPtr);
6355 TOOLBAR_StyleChanged (TOOLBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
6357 if (nType == GWL_STYLE)
6359 DWORD dwOldStyle = infoPtr->dwStyle;
6361 if (lpStyle->styleNew & TBSTYLE_LIST)
6362 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6364 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6366 TOOLBAR_CheckStyle (infoPtr, lpStyle->styleNew);
6368 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6370 infoPtr->dwStyle = lpStyle->styleNew;
6372 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6373 TOOLBAR_LayoutToolbar(infoPtr);
6375 /* only resize if one of the CCS_* styles was changed */
6376 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6378 TOOLBAR_AutoSize (infoPtr);
6380 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6389 TOOLBAR_SysColorChange (void)
6391 COMCTL32_RefreshSysColors();
6397 /* update theme after a WM_THEMECHANGED message */
6398 static LRESULT theme_changed (HWND hwnd)
6400 HTHEME theme = GetWindowTheme (hwnd);
6401 CloseThemeData (theme);
6402 OpenThemeData (hwnd, themeClass);
6407 static LRESULT WINAPI
6408 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6410 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
6412 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6413 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6415 if (!infoPtr && (uMsg != WM_NCCREATE))
6416 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6421 return TOOLBAR_AddBitmap (infoPtr, (INT)wParam, (TBADDBITMAP*)lParam);
6423 case TB_ADDBUTTONSA:
6424 case TB_ADDBUTTONSW:
6425 return TOOLBAR_AddButtonsT (infoPtr, wParam, (LPTBBUTTON)lParam,
6426 uMsg == TB_ADDBUTTONSW);
6428 return TOOLBAR_AddStringA (infoPtr, (HINSTANCE)wParam, lParam);
6431 return TOOLBAR_AddStringW (infoPtr, (HINSTANCE)wParam, lParam);
6434 return TOOLBAR_AutoSize (infoPtr);
6436 case TB_BUTTONCOUNT:
6437 return TOOLBAR_ButtonCount (infoPtr);
6439 case TB_BUTTONSTRUCTSIZE:
6440 return TOOLBAR_ButtonStructSize (infoPtr, wParam);
6442 case TB_CHANGEBITMAP:
6443 return TOOLBAR_ChangeBitmap (infoPtr, wParam, LOWORD(lParam));
6445 case TB_CHECKBUTTON:
6446 return TOOLBAR_CheckButton (infoPtr, wParam, lParam);
6448 case TB_COMMANDTOINDEX:
6449 return TOOLBAR_CommandToIndex (infoPtr, wParam);
6452 return TOOLBAR_Customize (infoPtr);
6454 case TB_DELETEBUTTON:
6455 return TOOLBAR_DeleteButton (infoPtr, wParam);
6457 case TB_ENABLEBUTTON:
6458 return TOOLBAR_EnableButton (infoPtr, wParam, lParam);
6460 case TB_GETANCHORHIGHLIGHT:
6461 return TOOLBAR_GetAnchorHighlight (infoPtr);
6464 return TOOLBAR_GetBitmap (infoPtr, wParam);
6466 case TB_GETBITMAPFLAGS:
6467 return TOOLBAR_GetBitmapFlags ();
6470 return TOOLBAR_GetButton (infoPtr, wParam, (TBBUTTON*)lParam);
6472 case TB_GETBUTTONINFOA:
6473 case TB_GETBUTTONINFOW:
6474 return TOOLBAR_GetButtonInfoT (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
6475 uMsg == TB_GETBUTTONINFOW);
6476 case TB_GETBUTTONSIZE:
6477 return TOOLBAR_GetButtonSize (infoPtr);
6479 case TB_GETBUTTONTEXTA:
6480 case TB_GETBUTTONTEXTW:
6481 return TOOLBAR_GetButtonText (infoPtr, wParam, (LPWSTR)lParam,
6482 uMsg == TB_GETBUTTONTEXTW);
6484 case TB_GETDISABLEDIMAGELIST:
6485 return TOOLBAR_GetDisabledImageList (infoPtr, wParam);
6487 case TB_GETEXTENDEDSTYLE:
6488 return TOOLBAR_GetExtendedStyle (infoPtr);
6490 case TB_GETHOTIMAGELIST:
6491 return TOOLBAR_GetHotImageList (infoPtr, wParam);
6494 return TOOLBAR_GetHotItem (infoPtr);
6496 case TB_GETIMAGELIST:
6497 return TOOLBAR_GetDefImageList (infoPtr, wParam);
6499 case TB_GETINSERTMARK:
6500 return TOOLBAR_GetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6502 case TB_GETINSERTMARKCOLOR:
6503 return TOOLBAR_GetInsertMarkColor (infoPtr);
6505 case TB_GETITEMRECT:
6506 return TOOLBAR_GetItemRect (infoPtr, wParam, (LPRECT)lParam);
6509 return TOOLBAR_GetMaxSize (infoPtr, (LPSIZE)lParam);
6511 /* case TB_GETOBJECT: */ /* 4.71 */
6514 return TOOLBAR_GetPadding (infoPtr);
6517 return TOOLBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
6520 return TOOLBAR_GetRows (infoPtr);
6523 return TOOLBAR_GetState (infoPtr, wParam);
6526 return TOOLBAR_GetStringA (infoPtr, wParam, (LPSTR)lParam);
6529 return TOOLBAR_GetStringW (infoPtr, wParam, (LPWSTR)lParam);
6532 return TOOLBAR_GetStyle (infoPtr);
6534 case TB_GETTEXTROWS:
6535 return TOOLBAR_GetTextRows (infoPtr);
6537 case TB_GETTOOLTIPS:
6538 return TOOLBAR_GetToolTips (infoPtr);
6540 case TB_GETUNICODEFORMAT:
6541 return TOOLBAR_GetUnicodeFormat (infoPtr);
6544 return TOOLBAR_HideButton (infoPtr, wParam, LOWORD(lParam));
6547 return TOOLBAR_HitTest (infoPtr, (LPPOINT)lParam);
6549 case TB_INDETERMINATE:
6550 return TOOLBAR_Indeterminate (infoPtr, wParam, LOWORD(lParam));
6552 case TB_INSERTBUTTONA:
6553 case TB_INSERTBUTTONW:
6554 return TOOLBAR_InsertButtonT(infoPtr, wParam, (TBBUTTON*)lParam,
6555 uMsg == TB_INSERTBUTTONW);
6557 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6559 case TB_ISBUTTONCHECKED:
6560 return TOOLBAR_IsButtonChecked (infoPtr, wParam);
6562 case TB_ISBUTTONENABLED:
6563 return TOOLBAR_IsButtonEnabled (infoPtr, wParam);
6565 case TB_ISBUTTONHIDDEN:
6566 return TOOLBAR_IsButtonHidden (infoPtr, wParam);
6568 case TB_ISBUTTONHIGHLIGHTED:
6569 return TOOLBAR_IsButtonHighlighted (infoPtr, wParam);
6571 case TB_ISBUTTONINDETERMINATE:
6572 return TOOLBAR_IsButtonIndeterminate (infoPtr, wParam);
6574 case TB_ISBUTTONPRESSED:
6575 return TOOLBAR_IsButtonPressed (infoPtr, wParam);
6578 return TOOLBAR_LoadImages (infoPtr, wParam, (HINSTANCE)lParam);
6580 case TB_MAPACCELERATORA:
6581 case TB_MAPACCELERATORW:
6582 return TOOLBAR_MapAccelerator (infoPtr, wParam, (UINT*)lParam);
6585 return TOOLBAR_MarkButton (infoPtr, wParam, LOWORD(lParam));
6588 return TOOLBAR_MoveButton (infoPtr, wParam, lParam);
6590 case TB_PRESSBUTTON:
6591 return TOOLBAR_PressButton (infoPtr, wParam, LOWORD(lParam));
6593 case TB_REPLACEBITMAP:
6594 return TOOLBAR_ReplaceBitmap (infoPtr, (LPTBREPLACEBITMAP)lParam);
6596 case TB_SAVERESTOREA:
6597 return TOOLBAR_SaveRestoreA (infoPtr, wParam, (LPTBSAVEPARAMSA)lParam);
6599 case TB_SAVERESTOREW:
6600 return TOOLBAR_SaveRestoreW (infoPtr, wParam, (LPTBSAVEPARAMSW)lParam);
6602 case TB_SETANCHORHIGHLIGHT:
6603 return TOOLBAR_SetAnchorHighlight (infoPtr, (BOOL)wParam);
6605 case TB_SETBITMAPSIZE:
6606 return TOOLBAR_SetBitmapSize (infoPtr, wParam, lParam);
6608 case TB_SETBUTTONINFOA:
6609 case TB_SETBUTTONINFOW:
6610 return TOOLBAR_SetButtonInfo (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
6611 uMsg == TB_SETBUTTONINFOW);
6612 case TB_SETBUTTONSIZE:
6613 return TOOLBAR_SetButtonSize (infoPtr, lParam);
6615 case TB_SETBUTTONWIDTH:
6616 return TOOLBAR_SetButtonWidth (infoPtr, lParam);
6619 return TOOLBAR_SetCmdId (infoPtr, wParam, lParam);
6621 case TB_SETDISABLEDIMAGELIST:
6622 return TOOLBAR_SetDisabledImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6624 case TB_SETDRAWTEXTFLAGS:
6625 return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
6627 case TB_SETEXTENDEDSTYLE:
6628 return TOOLBAR_SetExtendedStyle (infoPtr, lParam);
6630 case TB_SETHOTIMAGELIST:
6631 return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6634 return TOOLBAR_SetHotItem (infoPtr, wParam);
6636 case TB_SETIMAGELIST:
6637 return TOOLBAR_SetImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6640 return TOOLBAR_SetIndent (infoPtr, wParam);
6642 case TB_SETINSERTMARK:
6643 return TOOLBAR_SetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6645 case TB_SETINSERTMARKCOLOR:
6646 return TOOLBAR_SetInsertMarkColor (infoPtr, lParam);
6648 case TB_SETMAXTEXTROWS:
6649 return TOOLBAR_SetMaxTextRows (infoPtr, wParam);
6652 return TOOLBAR_SetPadding (infoPtr, lParam);
6655 return TOOLBAR_SetParent (infoPtr, (HWND)wParam);
6658 return TOOLBAR_SetRows (infoPtr, wParam, (LPRECT)lParam);
6661 return TOOLBAR_SetState (infoPtr, wParam, lParam);
6664 return TOOLBAR_SetStyle (infoPtr, lParam);
6666 case TB_SETTOOLTIPS:
6667 return TOOLBAR_SetToolTips (infoPtr, (HWND)wParam);
6669 case TB_SETUNICODEFORMAT:
6670 return TOOLBAR_SetUnicodeFormat (infoPtr, wParam);
6673 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6675 case TB_SETHOTITEM2:
6676 return TOOLBAR_SetHotItem2 (infoPtr, wParam, lParam);
6679 return TOOLBAR_SetListGap(infoPtr, wParam);
6681 case TB_GETIMAGELISTCOUNT:
6682 return TOOLBAR_GetImageListCount(infoPtr);
6684 case TB_GETIDEALSIZE:
6685 return TOOLBAR_GetIdealSize (infoPtr, wParam, lParam);
6688 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6690 /* Common Control Messages */
6692 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6693 case CCM_GETCOLORSCHEME:
6694 return TOOLBAR_GetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6696 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6697 case CCM_SETCOLORSCHEME:
6698 return TOOLBAR_SetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6700 case CCM_GETVERSION:
6701 return TOOLBAR_GetVersion (infoPtr);
6703 case CCM_SETVERSION:
6704 return TOOLBAR_SetVersion (infoPtr, (INT)wParam);
6710 return TOOLBAR_Create (hwnd, (CREATESTRUCTW*)lParam);
6713 return TOOLBAR_Destroy (infoPtr);
6716 return TOOLBAR_EraseBackground (infoPtr, wParam, lParam);
6719 return TOOLBAR_GetFont (infoPtr);
6722 return TOOLBAR_KeyDown (infoPtr, wParam, lParam);
6724 /* case WM_KILLFOCUS: */
6726 case WM_LBUTTONDBLCLK:
6727 return TOOLBAR_LButtonDblClk (infoPtr, wParam, lParam);
6729 case WM_LBUTTONDOWN:
6730 return TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
6733 return TOOLBAR_LButtonUp (infoPtr, wParam, lParam);
6736 return TOOLBAR_RButtonUp (infoPtr, wParam, lParam);
6738 case WM_RBUTTONDBLCLK:
6739 return TOOLBAR_RButtonDblClk (infoPtr, wParam, lParam);
6742 return TOOLBAR_MouseMove (infoPtr, wParam, lParam);
6745 return TOOLBAR_MouseLeave (infoPtr);
6747 case WM_CAPTURECHANGED:
6748 return TOOLBAR_CaptureChanged(infoPtr);
6751 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6754 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6757 return TOOLBAR_NCCreate (hwnd, wParam, (CREATESTRUCTW*)lParam);
6760 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6763 return TOOLBAR_Notify (infoPtr, (LPNMHDR)lParam);
6765 case WM_NOTIFYFORMAT:
6766 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6768 case WM_PRINTCLIENT:
6770 return TOOLBAR_Paint (infoPtr, wParam);
6773 return TOOLBAR_SetFocus (infoPtr);
6776 return TOOLBAR_SetFont(infoPtr, (HFONT)wParam, (WORD)lParam);
6779 return TOOLBAR_SetRedraw (infoPtr, wParam);
6782 return TOOLBAR_Size (infoPtr);
6784 case WM_STYLECHANGED:
6785 return TOOLBAR_StyleChanged (infoPtr, (INT)wParam, (LPSTYLESTRUCT)lParam);
6787 case WM_SYSCOLORCHANGE:
6788 return TOOLBAR_SysColorChange ();
6790 case WM_THEMECHANGED:
6791 return theme_changed (hwnd);
6793 /* case WM_WININICHANGE: */
6798 case WM_MEASUREITEM:
6800 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6802 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6803 case PGM_FORWARDMOUSE:
6804 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6807 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
6808 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6809 uMsg, wParam, lParam);
6810 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6816 TOOLBAR_Register (void)
6820 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
6821 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6822 wndClass.lpfnWndProc = ToolbarWindowProc;
6823 wndClass.cbClsExtra = 0;
6824 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6825 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
6826 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
6827 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
6829 RegisterClassW (&wndClass);
6834 TOOLBAR_Unregister (void)
6836 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
6839 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6844 /* Check if the entry already exists */
6845 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6847 /* If this is a new entry we must create it and insert into the array */
6852 c = Alloc(sizeof(IMLENTRY));
6855 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6856 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6871 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6875 for (i = 0; i < *cies; i++)
6885 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
6893 for (i = 0; i < cies; i++)
6895 if (pies[i]->id == id)
6907 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
6909 HIMAGELIST himlDef = 0;
6910 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6913 himlDef = pie->himl;
6919 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6921 if (infoPtr->bUnicode)
6922 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
6929 nmtba.iItem = nmtb->iItem;
6930 nmtba.pszText = Buffer;
6931 nmtba.cchText = 256;
6932 ZeroMemory(nmtba.pszText, nmtba.cchText);
6934 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
6936 int ccht = strlen(nmtba.pszText);
6938 MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
6939 nmtb->pszText, nmtb->cchText);
6941 nmtb->tbButton = nmtba.tbButton;
6950 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo)
6954 /* MSDN states that iItem is the index of the button, rather than the
6955 * command ID as used by every other NMTOOLBAR notification */
6957 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6959 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);