4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
98 BYTE bDropDownPressed;
103 INT cx; /* manually set size */
117 } IMLENTRY, *PIMLENTRY;
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
124 RECT rcBound; /* bounding rectangle */
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nHotItem; /* index of the "hot" item */
142 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
144 SIZE szPadding; /* padding values around button */
145 INT iListGap; /* default gap between text and image for toolbar with list style */
147 HFONT hFont; /* text font */
148 HIMAGELIST himlInt; /* image list created internally */
149 PIMLENTRY *himlDef; /* default image list array */
150 INT cimlDef; /* default image list array count */
151 PIMLENTRY *himlHot; /* hot image list array */
152 INT cimlHot; /* hot image list array count */
153 PIMLENTRY *himlDis; /* disabled image list array */
154 INT cimlDis; /* disabled image list array count */
155 HWND hwndToolTip; /* handle to tool tip control */
156 HWND hwndNotify; /* handle to the window that gets notifications */
157 HWND hwndSelf; /* my own handle */
158 BOOL bAnchor; /* anchor highlight enabled */
159 BOOL bDoRedraw; /* Redraw status */
160 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
161 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
162 BOOL bCaptured; /* mouse captured? */
163 DWORD dwStyle; /* regular toolbar style */
164 DWORD dwExStyle; /* extended toolbar style */
165 DWORD dwDTFlags; /* DrawText flags */
167 COLORREF clrInsertMark; /* insert mark color */
168 COLORREF clrBtnHighlight; /* color for Flat Separator */
169 COLORREF clrBtnShadow; /* color for Flag Separator */
171 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
172 * for TTN_GETDISPINFOW notification */
173 TBINSERTMARK tbim; /* info on insertion mark */
174 TBUTTON_INFO *buttons; /* pointer to button array */
175 LPWSTR *strings; /* pointer to string array */
176 TBITMAP_INFO *bitmaps;
177 } TOOLBAR_INFO, *PTOOLBAR_INFO;
180 /* used by customization dialog */
183 PTOOLBAR_INFO tbInfo;
185 } CUSTDLG_INFO, *PCUSTDLG_INFO;
193 } CUSTOMBUTTON, *PCUSTOMBUTTON;
202 #define SEPARATOR_WIDTH 8
204 #define BOTTOM_BORDER 2
205 #define DDARROW_WIDTH 11
206 #define ARROW_HEIGHT 3
207 #define INSERTMARK_WIDTH 2
213 /* vertical padding used in list mode when image is present */
216 /* how wide to treat the bitmap if it isn't present */
217 #define NONLIST_NOTEXT_OFFSET 2
219 #define TOOLBAR_NOWHERE (-1)
221 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
222 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
223 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
225 /* Used to find undocumented extended styles */
226 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
227 TBSTYLE_EX_UNDOC1 | \
228 TBSTYLE_EX_MIXEDBUTTONS | \
229 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
231 /* all of the CCS_ styles */
232 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
233 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
235 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
236 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
237 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
238 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
239 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
241 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
250 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
251 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
252 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
253 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button);
256 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
260 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
262 LPWSTR lpText = NULL;
264 /* NOTE: iString == -1 is undocumented */
265 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
266 lpText = (LPWSTR)btnPtr->iString;
267 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
268 lpText = infoPtr->strings[btnPtr->iString];
274 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
276 if (TRACE_ON(toolbar)){
277 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
278 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
279 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
280 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
282 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
283 btn_num, bP->idCommand,
284 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
285 bP->rect.left, bP->rect.top,
286 bP->rect.right, bP->rect.bottom);
292 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
294 if (TRACE_ON(toolbar)) {
297 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
299 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
300 iP->nNumStrings, iP->dwStyle);
301 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
303 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
304 (iP->bDoRedraw) ? "TRUE" : "FALSE");
305 for(i=0; i<iP->nNumButtons; i++) {
306 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
312 /***********************************************************************
315 * This function validates that the styles set are implemented and
316 * issues FIXME's warning of possible problems. In a perfect world this
317 * function should be null.
320 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
322 if (dwStyle & TBSTYLE_REGISTERDROP)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
328 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
330 if(!IsWindow(infoPtr->hwndSelf))
331 return 0; /* we have just been destroyed */
333 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
334 nmhdr->hwndFrom = infoPtr->hwndSelf;
337 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
338 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
340 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
354 INT ret = btnPtr->iBitmap;
356 if (ret == I_IMAGECALLBACK)
358 /* issue TBN_GETDISPINFO */
361 memset(&nmgd, 0, sizeof(nmgd));
362 nmgd.idCommand = btnPtr->idCommand;
363 nmgd.lParam = btnPtr->dwData;
364 nmgd.dwMask = TBNF_IMAGE;
365 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
366 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
367 if (nmgd.dwMask & TBNF_DI_SETITEM)
368 btnPtr->iBitmap = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
398 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
400 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
401 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
412 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
416 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
417 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
418 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
419 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
423 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
424 if ((*index == I_IMAGECALLBACK) ||
425 (*index == I_IMAGENONE)) return NULL;
426 ERR("TBN_GETDISPINFO returned invalid index %d\n",
433 case IMAGE_LIST_DEFAULT:
434 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
437 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 case IMAGE_LIST_DISABLED:
440 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
444 FIXME("Shouldn't reach here\n");
448 TRACE("no image list\n");
455 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
458 COLORREF oldcolor, newcolor;
460 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
461 myrect.right = myrect.left + 1;
462 myrect.top = lpRect->top + 2;
463 myrect.bottom = lpRect->bottom - 2;
465 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
466 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
467 oldcolor = SetBkColor (hdc, newcolor);
468 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
470 myrect.left = myrect.right;
471 myrect.right = myrect.left + 1;
473 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
474 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
475 SetBkColor (hdc, newcolor);
476 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
478 SetBkColor (hdc, oldcolor);
482 /***********************************************************************
483 * TOOLBAR_DrawDDFlatSeparator
485 * This function draws the separator that was flagged as BTNS_DROPDOWN.
486 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
487 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
488 * are horizontal as opposed to the vertical separators for not dropdown
491 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
494 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
497 COLORREF oldcolor, newcolor;
499 myrect.left = lpRect->left;
500 myrect.right = lpRect->right;
501 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
502 myrect.bottom = myrect.top + 1;
504 InflateRect (&myrect, -2, 0);
506 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
507 myrect.left, myrect.top, myrect.right, myrect.bottom);
509 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
510 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
511 oldcolor = SetBkColor (hdc, newcolor);
512 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
514 myrect.top = myrect.bottom;
515 myrect.bottom = myrect.top + 1;
517 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
518 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
519 SetBkColor (hdc, newcolor);
520 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
522 SetBkColor (hdc, oldcolor);
527 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
532 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
533 hOldPen = SelectObject ( hdc, hPen );
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+5, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+3, y++); x++;
540 MoveToEx (hdc, x, y, NULL);
541 LineTo (hdc, x+1, y++);
542 SelectObject( hdc, hOldPen );
543 DeleteObject( hPen );
547 * Draw the text string for this button.
548 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
549 * is non-zero, so we can simply check himlDef to see if we have
553 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
554 NMTBCUSTOMDRAW *tbcd)
556 HDC hdc = tbcd->nmcd.hdc;
559 COLORREF clrOldBk = 0;
561 UINT state = tbcd->nmcd.uItemState;
565 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
566 rcText->left, rcText->top, rcText->right, rcText->bottom);
568 hOldFont = SelectObject (hdc, infoPtr->hFont);
569 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
570 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
572 else if (state & CDIS_DISABLED) {
573 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
574 OffsetRect (rcText, 1, 1);
575 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
576 SetTextColor (hdc, comctl32_color.clr3dShadow);
577 OffsetRect (rcText, -1, -1);
579 else if (state & CDIS_INDETERMINATE) {
580 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
582 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
583 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
584 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
585 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
588 clrOld = SetTextColor (hdc, tbcd->clrText);
591 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
592 SetTextColor (hdc, clrOld);
593 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
595 SetBkColor (hdc, clrOldBk);
596 SetBkMode (hdc, oldBkMode);
598 SelectObject (hdc, hOldFont);
604 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
606 HDC hdc = tbcd->nmcd.hdc;
607 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
610 INT cx = lpRect->right - lpRect->left;
611 INT cy = lpRect->bottom - lpRect->top;
612 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
613 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
614 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
615 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
616 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
617 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
618 SetBkColor(hdc, clrBkOld);
619 SetTextColor(hdc, clrTextOld);
620 SelectObject (hdc, hbr);
624 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
627 HBITMAP hbmMask, hbmImage;
628 HDC hdcMask, hdcImage;
630 ImageList_GetIconSize(himl, &cx, &cy);
632 /* Create src image */
633 hdcImage = CreateCompatibleDC(hdc);
634 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
635 SelectObject(hdcImage, hbmImage);
636 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
637 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
640 hdcMask = CreateCompatibleDC(0);
641 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
642 SelectObject(hdcMask, hbmMask);
644 /* Remove the background and all white pixels */
645 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
646 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
647 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
648 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
650 /* draw the new mask 'etched' to hdc */
651 SetBkColor(hdc, RGB(255, 255, 255));
652 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
653 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
654 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
655 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
656 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
659 DeleteObject(hbmImage);
661 DeleteObject (hbmMask);
667 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
671 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
672 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
673 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
674 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
675 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
676 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
677 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
681 /* draws the image on a toolbar button */
683 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
685 HIMAGELIST himl = NULL;
686 BOOL draw_masked = FALSE;
689 UINT draw_flags = ILD_TRANSPARENT;
691 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
693 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
696 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
700 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
701 ((tbcd->nmcd.uItemState & CDIS_HOT)
702 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
704 /* if hot, attempt to draw with hot image list, if fails,
705 use default image list */
706 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
708 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
711 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
716 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
717 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
720 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
721 (tbcd->nmcd.uItemState & CDIS_MARKED))
722 draw_flags |= ILD_BLEND50;
724 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
725 index, himl, left, top, offset);
728 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
730 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
733 /* draws a blank frame for a toolbar button */
735 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
737 HDC hdc = tbcd->nmcd.hdc;
738 RECT rc = tbcd->nmcd.rc;
739 /* if the state is disabled or indeterminate then the button
740 * cannot have an interactive look like pressed or hot */
741 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
742 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
743 BOOL pressed_look = !non_interactive_state &&
744 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
745 (tbcd->nmcd.uItemState & CDIS_CHECKED));
747 /* app don't want us to draw any edges */
748 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
751 if (infoPtr->dwStyle & TBSTYLE_FLAT)
754 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
755 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
756 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
761 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
763 DrawEdge (hdc, &rc, EDGE_RAISED,
764 BF_SOFT | BF_RECT | BF_MIDDLE);
769 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
771 HDC hdc = tbcd->nmcd.hdc;
773 BOOL pressed = bDropDownPressed ||
774 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
776 if (infoPtr->dwStyle & TBSTYLE_FLAT)
779 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
780 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
781 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
782 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
783 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
788 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
790 DrawEdge (hdc, rcArrow, EDGE_RAISED,
791 BF_SOFT | BF_RECT | BF_MIDDLE);
795 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
797 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
799 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
800 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
803 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
806 /* draws a complete toolbar button */
808 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
811 DWORD dwStyle = infoPtr->dwStyle;
812 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
813 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
814 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
815 BOOL drawSepDropDownArrow = hasDropDownArrow &&
816 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
817 RECT rc, rcArrow, rcBitmap, rcText;
818 LPWSTR lpText = NULL;
823 DWORD dwItemCustDraw;
824 HTHEME theme = GetWindowTheme (hwnd);
827 CopyRect (&rcArrow, &rc);
829 /* separator - doesn't send NM_CUSTOMDRAW */
830 if (btnPtr->fsStyle & BTNS_SEP) {
833 DrawThemeBackground (theme, hdc,
834 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
838 /* with the FLAT style, iBitmap is the width and has already */
839 /* been taken into consideration in calculating the width */
840 /* so now we need to draw the vertical separator */
841 /* empirical tests show that iBitmap can/will be non-zero */
842 /* when drawing the vertical bar... */
843 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
844 if (btnPtr->fsStyle & BTNS_DROPDOWN)
845 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
847 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
849 else if (btnPtr->fsStyle != BTNS_SEP) {
850 FIXME("Draw some kind of separator: fsStyle=%x\n",
856 /* get a pointer to the text */
857 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
859 if (hasDropDownArrow)
863 if (dwStyle & TBSTYLE_FLAT)
864 right = max(rc.left, rc.right - DDARROW_WIDTH);
866 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
868 if (drawSepDropDownArrow)
871 rcArrow.left = right;
874 /* copy text & bitmap rects after adjusting for drop-down arrow
875 * so that text & bitmap is centred in the rectangle not containing
877 CopyRect(&rcText, &rc);
878 CopyRect(&rcBitmap, &rc);
880 /* Center the bitmap horizontally and vertically */
881 if (dwStyle & TBSTYLE_LIST)
884 infoPtr->nMaxTextRows > 0 &&
885 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
886 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
887 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
889 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
892 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
894 rcBitmap.top += infoPtr->szPadding.cy / 2;
896 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
897 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
898 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
899 TRACE("Text=%s\n", debugstr_w(lpText));
900 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
902 /* calculate text position */
905 rcText.left += GetSystemMetrics(SM_CXEDGE);
906 rcText.right -= GetSystemMetrics(SM_CXEDGE);
907 if (dwStyle & TBSTYLE_LIST)
909 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
910 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
914 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
915 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
917 rcText.top += infoPtr->szPadding.cy/2 + 2;
921 /* Initialize fields in all cases, because we use these later
922 * NOTE: applications can and do alter these to customize their
924 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
925 tbcd.clrText = comctl32_color.clrBtnText;
926 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
927 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
928 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
929 tbcd.clrMark = comctl32_color.clrHighlight;
930 tbcd.clrHighlightHotTrack = 0;
931 tbcd.nStringBkMode = TRANSPARENT;
932 tbcd.nHLStringBkMode = OPAQUE;
933 /* MSDN says that this is the text rectangle.
934 * But (why always a but) tracing of v5.7 of native shows
935 * that this is really a *relative* rectangle based on the
936 * the nmcd.rc. Also the left and top are always 0 ignoring
937 * any bitmap that might be present. */
938 tbcd.rcText.left = 0;
940 tbcd.rcText.right = rcText.right - rc.left;
941 tbcd.rcText.bottom = rcText.bottom - rc.top;
942 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
945 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
947 /* FIXME: what are these used for? */
951 /* Issue Item Prepaint notify */
953 infoPtr->dwItemCDFlag = 0;
954 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
956 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
957 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
958 tbcd.nmcd.lItemlParam = btnPtr->dwData;
959 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
960 /* reset these fields so the user can't alter the behaviour like native */
964 dwItemCustDraw = ntfret & 0xffff;
965 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
966 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
968 /* save the only part of the rect that the user can change */
969 rcText.right = tbcd.rcText.right + rc.left;
970 rcText.bottom = tbcd.rcText.bottom + rc.top;
973 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
974 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
975 OffsetRect(&rcText, 1, 1);
977 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
978 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
979 TOOLBAR_DrawPattern (&rc, &tbcd);
981 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
982 && (tbcd.nmcd.uItemState & CDIS_HOT))
984 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
988 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
989 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
990 if (hasDropDownArrow)
991 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
992 SetBkColor(hdc, oldclr);
998 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
999 int stateId = TS_NORMAL;
1001 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1002 stateId = TS_DISABLED;
1003 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1004 stateId = TS_PRESSED;
1005 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1006 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1007 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1008 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1011 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1014 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1016 if (drawSepDropDownArrow)
1020 int stateId = TS_NORMAL;
1022 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1023 stateId = TS_DISABLED;
1024 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1025 stateId = TS_PRESSED;
1026 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1027 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1028 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1031 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1032 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1035 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1038 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1039 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1040 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1041 SetBkMode (hdc, oldBkMode);
1043 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1045 if (hasDropDownArrow && !drawSepDropDownArrow)
1047 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1050 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1052 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1054 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1055 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1058 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1061 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1063 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1064 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1071 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1074 TBUTTON_INFO *btnPtr;
1076 RECT rcTemp, rcClient;
1077 NMTBCUSTOMDRAW tbcd;
1080 /* the app has told us not to redraw the toolbar */
1081 if (!infoPtr->bDoRedraw)
1084 /* if imagelist belongs to the app, it can be changed
1085 by the app after setting it */
1086 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1088 infoPtr->nNumBitmaps = 0;
1089 for (i = 0; i < infoPtr->cimlDef; i++)
1090 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1093 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1095 /* change the imagelist icon size if we manage the list and it is necessary */
1096 TOOLBAR_CheckImageListIconSize(infoPtr);
1098 /* Send initial notify */
1099 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1100 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1101 tbcd.nmcd.hdc = hdc;
1102 tbcd.nmcd.rc = ps->rcPaint;
1103 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1104 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1106 GetClientRect(hwnd, &rcClient);
1108 /* redraw necessary buttons */
1109 btnPtr = infoPtr->buttons;
1110 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1113 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1115 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1116 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1120 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1121 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1123 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1126 /* draw insert mark if required */
1127 if (infoPtr->tbim.iButton != -1)
1129 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1131 rcInsertMark.top = rcButton.top;
1132 rcInsertMark.bottom = rcButton.bottom;
1133 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1134 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1136 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1137 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1140 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1142 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1143 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1144 tbcd.nmcd.hdc = hdc;
1145 tbcd.nmcd.rc = ps->rcPaint;
1146 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1150 /***********************************************************************
1151 * TOOLBAR_MeasureString
1153 * This function gets the width and height of a string in pixels. This
1154 * is done first by using GetTextExtentPoint to get the basic width
1155 * and height. The DrawText is called with DT_CALCRECT to get the exact
1156 * width. The reason is because the text may have more than one "&" (or
1157 * prefix characters as M$ likes to call them). The prefix character
1158 * indicates where the underline goes, except for the string "&&" which
1159 * is reduced to a single "&". GetTextExtentPoint does not process these
1160 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1163 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1164 HDC hdc, LPSIZE lpSize)
1171 if (infoPtr->nMaxTextRows > 0 &&
1172 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1173 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1174 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1176 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1178 if(lpText != NULL) {
1179 /* first get size of all the text */
1180 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1182 /* feed above size into the rectangle for DrawText */
1183 myrect.left = myrect.top = 0;
1184 myrect.right = lpSize->cx;
1185 myrect.bottom = lpSize->cy;
1187 /* Use DrawText to get true size as drawn (less pesky "&") */
1188 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1189 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1192 /* feed back to caller */
1193 lpSize->cx = myrect.right;
1194 lpSize->cy = myrect.bottom;
1198 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1201 /***********************************************************************
1202 * TOOLBAR_CalcStrings
1204 * This function walks through each string and measures it and returns
1205 * the largest height and width to caller.
1208 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1210 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1211 TBUTTON_INFO *btnPtr;
1220 if (infoPtr->nMaxTextRows == 0)
1224 hOldFont = SelectObject (hdc, infoPtr->hFont);
1226 if (infoPtr->nNumButtons == 0)
1230 GetTextMetricsW(hdc, &tm);
1231 lpSize->cy = tm.tmHeight;
1234 btnPtr = infoPtr->buttons;
1235 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1236 if(TOOLBAR_HasText(infoPtr, btnPtr))
1238 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1239 if (sz.cx > lpSize->cx)
1241 if (sz.cy > lpSize->cy)
1246 SelectObject (hdc, hOldFont);
1247 ReleaseDC (hwnd, hdc);
1249 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1252 /***********************************************************************
1253 * TOOLBAR_WrapToolbar
1255 * This function walks through the buttons and separators in the
1256 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1257 * wrapping should occur based on the width of the toolbar window.
1258 * It does *not* calculate button placement itself. That task
1259 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1260 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1261 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1263 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1264 * vertical toolbar lists.
1268 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1271 TBUTTON_INFO *btnPtr;
1274 BOOL bWrap, bButtonWrap;
1276 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1277 /* no layout is necessary. Applications may use this style */
1278 /* to perform their own layout on the toolbar. */
1279 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1280 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1282 btnPtr = infoPtr->buttons;
1283 x = infoPtr->nIndent;
1285 if (GetParent(hwnd))
1287 /* this can get the parents width, to know how far we can extend
1288 * this toolbar. We cannot use its height, as there may be multiple
1289 * toolbars in a rebar control
1291 GetClientRect( GetParent(hwnd), &rc );
1292 infoPtr->nWidth = rc.right - rc.left;
1296 GetWindowRect( hwnd, &rc );
1297 infoPtr->nWidth = rc.right - rc.left;
1300 bButtonWrap = FALSE;
1302 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1303 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1306 for (i = 0; i < infoPtr->nNumButtons; i++ )
1309 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1311 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1314 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1315 /* it is the actual width of the separator. This is used for */
1316 /* custom controls in toolbars. */
1318 /* BTNS_DROPDOWN separators are treated as buttons for */
1319 /* width. - GA 8/01 */
1320 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1321 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1322 cx = (btnPtr[i].iBitmap > 0) ?
1323 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1325 cx = infoPtr->nButtonWidth;
1327 /* Two or more adjacent separators form a separator group. */
1328 /* The first separator in a group should be wrapped to the */
1329 /* next row if the previous wrapping is on a button. */
1331 (btnPtr[i].fsStyle & BTNS_SEP) &&
1332 (i + 1 < infoPtr->nNumButtons ) &&
1333 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1335 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1336 btnPtr[i].fsState |= TBSTATE_WRAP;
1337 x = infoPtr->nIndent;
1339 bButtonWrap = FALSE;
1343 /* The layout makes sure the bitmap is visible, but not the button. */
1344 /* Test added to also wrap after a button that starts a row but */
1345 /* is bigger than the area. - GA 8/01 */
1346 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1347 > infoPtr->nWidth ) ||
1348 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1350 BOOL bFound = FALSE;
1352 /* If the current button is a separator and not hidden, */
1353 /* go to the next until it reaches a non separator. */
1354 /* Wrap the last separator if it is before a button. */
1355 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1356 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1357 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1358 i < infoPtr->nNumButtons )
1364 if( bFound && i < infoPtr->nNumButtons )
1367 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1368 i, btnPtr[i].fsStyle, x, cx);
1369 btnPtr[i].fsState |= TBSTATE_WRAP;
1370 x = infoPtr->nIndent;
1371 bButtonWrap = FALSE;
1374 else if ( i >= infoPtr->nNumButtons)
1377 /* If the current button is not a separator, find the last */
1378 /* separator and wrap it. */
1379 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1381 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1382 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1386 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1387 i, btnPtr[i].fsStyle, x, cx);
1388 x = infoPtr->nIndent;
1389 btnPtr[j].fsState |= TBSTATE_WRAP;
1390 bButtonWrap = FALSE;
1395 /* If no separator available for wrapping, wrap one of */
1396 /* non-hidden previous button. */
1400 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1402 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1407 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1408 i, btnPtr[i].fsStyle, x, cx);
1409 x = infoPtr->nIndent;
1410 btnPtr[j].fsState |= TBSTATE_WRAP;
1416 /* If all above failed, wrap the current button. */
1419 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1420 i, btnPtr[i].fsStyle, x, cx);
1421 btnPtr[i].fsState |= TBSTATE_WRAP;
1423 x = infoPtr->nIndent;
1424 if (btnPtr[i].fsStyle & BTNS_SEP )
1425 bButtonWrap = FALSE;
1431 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1432 i, btnPtr[i].fsStyle, x, cx);
1439 /***********************************************************************
1440 * TOOLBAR_MeasureButton
1442 * Calculates the width and height required for a button. Used in
1443 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1444 * the width of buttons that are autosized.
1446 * Note that it would have been rather elegant to use one piece of code for
1447 * both the laying out of the toolbar and for controlling where button parts
1448 * are drawn, but the native control has inconsistencies between the two that
1449 * prevent this from being effectively. These inconsistencies can be seen as
1450 * artefacts where parts of the button appear outside of the bounding button
1453 * There are several cases for the calculation of the button dimensions and
1454 * button part positioning:
1461 * +--------------------------------------------------------+ ^
1463 * | | pad.cy / 2 | centred | |
1464 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1465 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1466 * | |<------------>| | | | |
1467 * | +--------------+ +------------+ | |
1468 * |<-------------------------------------->| | |
1469 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1471 * +--------------------------------------------------------+ -
1472 * <-------------------------------------------------------->
1473 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1475 * Without Bitmap (I_IMAGENONE):
1477 * +-----------------------------------+ ^
1479 * | | centred | | LISTPAD_CY +
1480 * | +------------+ | | szText.cy
1483 * | +------------+ | |
1484 * |<----------------->| | |
1485 * | cxedge |<-----------> | |
1487 * +-----------------------------------+ -
1488 * <----------------------------------->
1489 * szText.cx + pad.cx
1493 * +--------------------------------------+ ^
1495 * | | padding.cy/2 | | DEFPAD_CY +
1496 * | +------------+ | | nBitmapHeight
1499 * | +------------+ | |
1500 * |<------------------->| | |
1501 * | cxedge + iListGap/2 |<-----------> | |
1502 * | nBitmapWidth | |
1503 * +--------------------------------------+ -
1504 * <-------------------------------------->
1505 * 2*cxedge + nBitmapWidth + iListGap
1512 * +-----------------------------------+ ^
1514 * | | pad.cy / 2 | | nBitmapHeight +
1515 * | - | | szText.cy +
1516 * | +------------+ | | DEFPAD_CY + 1
1517 * | centred | Bitmap | | |
1518 * |<----------------->| | | |
1519 * | +------------+ | |
1523 * | centred +---------------+ | |
1524 * |<--------------->| Text | | |
1525 * | +---------------+ | |
1526 * +-----------------------------------+ -
1527 * <----------------------------------->
1528 * pad.cx + max(nBitmapWidth, szText.cx)
1530 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1532 * +---------------------------------------+ ^
1534 * | | 2 + pad.cy / 2 | |
1535 * | - | | szText.cy +
1536 * | centred +-----------------+ | | pad.cy + 2
1537 * |<--------------->| Text | | |
1538 * | +-----------------+ | |
1540 * +---------------------------------------+ -
1541 * <--------------------------------------->
1542 * 2*cxedge + pad.cx + szText.cx
1545 * As for with bitmaps, but with szText.cx zero.
1547 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1550 if (infoPtr->dwStyle & TBSTYLE_LIST)
1552 /* set button height from bitmap / text height... */
1553 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1556 /* ... add on the necessary padding */
1557 if (bValidImageList)
1560 sizeButton.cy += DEFPAD_CY;
1562 sizeButton.cy += LISTPAD_CY;
1565 sizeButton.cy += infoPtr->szPadding.cy;
1567 /* calculate button width */
1570 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1571 infoPtr->nBitmapWidth + infoPtr->iListGap;
1572 if (sizeString.cx > 0)
1573 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1576 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1582 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1583 sizeString.cy + DEFPAD_CY;
1584 sizeButton.cx = infoPtr->szPadding.cx +
1585 max(sizeString.cx, infoPtr->nBitmapWidth);
1589 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1590 NONLIST_NOTEXT_OFFSET;
1591 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1592 infoPtr->szPadding.cx + sizeString.cx;
1599 /***********************************************************************
1600 * TOOLBAR_CalcToolbar
1602 * This function calculates button and separator placement. It first
1603 * calculates the button sizes, gets the toolbar window width and then
1604 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1605 * on. It assigns a new location to each item and sends this location to
1606 * the tooltip window if appropriate. Finally, it updates the rcBound
1607 * rect and calculates the new required toolbar window height.
1610 TOOLBAR_CalcToolbar (HWND hwnd)
1612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1613 DWORD dwStyle = infoPtr->dwStyle;
1614 TBUTTON_INFO *btnPtr;
1615 INT i, nRows, nSepRows;
1617 SIZE sizeString, sizeButton;
1619 BOOL validImageList = FALSE;
1620 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1622 TOOLBAR_CalcStrings (hwnd, &sizeString);
1624 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1626 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1627 validImageList = TRUE;
1628 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1629 infoPtr->nButtonWidth = sizeButton.cx;
1630 infoPtr->nButtonHeight = sizeButton.cy;
1632 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1633 infoPtr->nButtonWidth = infoPtr->cxMin;
1634 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1635 infoPtr->nButtonWidth = infoPtr->cxMax;
1637 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1639 x = infoPtr->nIndent;
1640 if (infoPtr->dwStyle & TBSTYLE_FLAT)
1645 /* from above, minimum is a button, and possible text */
1646 cx = infoPtr->nButtonWidth;
1647 cy = infoPtr->nButtonHeight;
1649 nRows = nSepRows = 0;
1651 infoPtr->rcBound.top = y;
1652 infoPtr->rcBound.left = x;
1653 infoPtr->rcBound.bottom = y + cy;
1654 infoPtr->rcBound.right = x;
1656 btnPtr = infoPtr->buttons;
1658 TRACE("cy=%d\n", cy);
1660 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1663 if (btnPtr->fsState & TBSTATE_HIDDEN)
1665 SetRectEmpty (&btnPtr->rect);
1669 cy = infoPtr->nButtonHeight;
1671 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1672 /* it is the actual width of the separator. This is used for */
1673 /* custom controls in toolbars. */
1674 if (btnPtr->fsStyle & BTNS_SEP) {
1675 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1676 cy = (btnPtr->iBitmap > 0) ?
1677 btnPtr->iBitmap : SEPARATOR_WIDTH;
1678 cx = infoPtr->nButtonWidth;
1681 cx = (btnPtr->iBitmap > 0) ?
1682 btnPtr->iBitmap : SEPARATOR_WIDTH;
1688 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1689 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1696 hOldFont = SelectObject (hdc, infoPtr->hFont);
1698 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1700 SelectObject (hdc, hOldFont);
1701 ReleaseDC (hwnd, hdc);
1703 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1704 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1709 cx = infoPtr->nButtonWidth;
1711 /* if size has been set manually then don't add on extra space
1712 * for the drop down arrow */
1713 if (!btnPtr->cx && hasDropDownArrows &&
1714 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1715 cx += DDARROW_WIDTH;
1717 if (btnPtr->fsState & TBSTATE_WRAP )
1720 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1722 if (infoPtr->rcBound.left > x)
1723 infoPtr->rcBound.left = x;
1724 if (infoPtr->rcBound.right < x + cx)
1725 infoPtr->rcBound.right = x + cx;
1726 if (infoPtr->rcBound.bottom < y + cy)
1727 infoPtr->rcBound.bottom = y + cy;
1729 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1731 /* btnPtr->nRow is zero based. The space between the rows is */
1732 /* also considered as a row. */
1733 btnPtr->nRow = nRows + nSepRows;
1735 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1736 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1741 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1745 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1746 /* it is the actual width of the separator. This is used for */
1747 /* custom controls in toolbars. */
1748 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1749 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1750 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1754 /* nSepRows is used to calculate the extra height follwoing */
1758 x = infoPtr->nIndent;
1760 /* Increment row number unless this is the last button */
1761 /* and it has Wrap set. */
1762 if (i != infoPtr->nNumButtons-1)
1769 /* infoPtr->nRows is the number of rows on the toolbar */
1770 infoPtr->nRows = nRows + nSepRows + 1;
1772 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1777 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
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;
1808 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1810 TBUTTON_INFO *btnPtr;
1813 if (CommandIsIndex) {
1814 TRACE("command is really index command=%d\n", idCommand);
1815 if (idCommand >= infoPtr->nNumButtons) return -1;
1818 btnPtr = infoPtr->buttons;
1819 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1820 if (btnPtr->idCommand == idCommand) {
1821 TRACE("command=%d index=%d\n", idCommand, i);
1825 TRACE("no index found for command=%d\n", idCommand);
1831 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1833 TBUTTON_INFO *btnPtr;
1836 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1839 /* check index button */
1840 btnPtr = &infoPtr->buttons[nIndex];
1841 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1842 if (btnPtr->fsState & TBSTATE_CHECKED)
1846 /* check previous buttons */
1847 nRunIndex = nIndex - 1;
1848 while (nRunIndex >= 0) {
1849 btnPtr = &infoPtr->buttons[nRunIndex];
1850 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1851 if (btnPtr->fsState & TBSTATE_CHECKED)
1859 /* check next buttons */
1860 nRunIndex = nIndex + 1;
1861 while (nRunIndex < infoPtr->nNumButtons) {
1862 btnPtr = &infoPtr->buttons[nRunIndex];
1863 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1864 if (btnPtr->fsState & TBSTATE_CHECKED)
1877 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1878 WPARAM wParam, LPARAM lParam)
1884 msg.wParam = wParam;
1885 msg.lParam = lParam;
1886 msg.time = GetMessageTime ();
1887 msg.pt.x = LOWORD(GetMessagePos ());
1888 msg.pt.y = HIWORD(GetMessagePos ());
1890 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1894 TOOLBAR_TooltipAddTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1896 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1899 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1900 ti.cbSize = sizeof (TTTOOLINFOW);
1901 ti.hwnd = infoPtr->hwndSelf;
1902 ti.uId = button->idCommand;
1904 ti.lpszText = LPSTR_TEXTCALLBACKW;
1905 /* ti.lParam = random value from the stack? */
1907 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1913 TOOLBAR_TooltipDelTool(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1915 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1918 ZeroMemory(&ti, sizeof(ti));
1919 ti.cbSize = sizeof(ti);
1920 ti.hwnd = infoPtr->hwndSelf;
1921 ti.uId = button->idCommand;
1923 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1927 static void TOOLBAR_TooltipSetRect(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *button)
1929 /* Set the toolTip only for non-hidden, non-separator button */
1930 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1934 ZeroMemory(&ti, sizeof(ti));
1935 ti.cbSize = sizeof(ti);
1936 ti.hwnd = infoPtr->hwndSelf;
1937 ti.uId = button->idCommand;
1938 ti.rect = button->rect;
1939 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1943 /* Creates the tooltip control */
1945 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1948 NMTOOLTIPSCREATED nmttc;
1950 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
1951 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1952 infoPtr->hwndSelf, 0, 0, 0);
1954 if (!infoPtr->hwndToolTip)
1957 /* Send NM_TOOLTIPSCREATED notification */
1958 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1959 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
1961 for (i = 0; i < infoPtr->nNumButtons; i++)
1963 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
1964 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
1968 /* keeps available button list box sorted by button id */
1969 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1973 PCUSTOMBUTTON btnInfo;
1974 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1976 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1978 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1980 /* position 0 is always separator */
1981 for (i = 1; i < count; i++)
1983 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1984 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1986 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1987 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1991 /* id higher than all others add to end */
1992 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1993 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1996 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2000 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2002 if (nIndexFrom == nIndexTo)
2005 /* MSDN states that iItem is the index of the button, rather than the
2006 * command ID as used by every other NMTOOLBAR notification */
2007 nmtb.iItem = nIndexFrom;
2008 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2010 PCUSTOMBUTTON btnInfo;
2012 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2013 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2015 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2017 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2018 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2019 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2020 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2023 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2025 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2027 /* last item is always separator, so -2 instead of -1 */
2028 if (nIndexTo >= (count - 2))
2029 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2031 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2033 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2034 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2036 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2040 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2044 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2046 /* MSDN states that iItem is the index of the button, rather than the
2047 * command ID as used by every other NMTOOLBAR notification */
2048 nmtb.iItem = nIndexAvail;
2049 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2051 PCUSTOMBUTTON btnInfo;
2053 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2054 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2055 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2057 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2059 if (nIndexAvail != 0) /* index == 0 indicates separator */
2061 /* remove from 'available buttons' list */
2062 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2063 if (nIndexAvail == count-1)
2064 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2066 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2070 PCUSTOMBUTTON btnNew;
2072 /* duplicate 'separator' button */
2073 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2074 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2078 /* insert into 'toolbar button' list */
2079 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2080 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2082 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2084 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2088 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2090 PCUSTOMBUTTON btnInfo;
2091 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2093 TRACE("Remove: index %d\n", index);
2095 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2097 /* send TBN_QUERYDELETE notification */
2098 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2102 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2103 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2105 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2107 /* insert into 'available button' list */
2108 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2109 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2113 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2117 /* drag list notification function for toolbar buttons list box */
2118 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2120 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2121 switch (pDLI->uNotification)
2125 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2126 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2127 /* no dragging for last item (separator) */
2128 if (nCurrentItem >= (nCount - 1)) return FALSE;
2133 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2134 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2135 /* no dragging past last item (separator) */
2136 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2138 DrawInsert(hwnd, hwndList, nCurrentItem);
2139 /* FIXME: native uses "move button" cursor */
2140 return DL_COPYCURSOR;
2143 /* not over toolbar buttons list */
2144 if (nCurrentItem < 0)
2146 POINT ptWindow = pDLI->ptCursor;
2147 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2148 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2149 /* over available buttons list? */
2150 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2151 /* FIXME: native uses "move button" cursor */
2152 return DL_COPYCURSOR;
2154 /* clear drag arrow */
2155 DrawInsert(hwnd, hwndList, -1);
2156 return DL_STOPCURSOR;
2160 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2161 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2162 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2163 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2165 /* clear drag arrow */
2166 DrawInsert(hwnd, hwndList, -1);
2168 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2170 /* not over toolbar buttons list */
2173 POINT ptWindow = pDLI->ptCursor;
2174 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2175 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2176 /* over available buttons list? */
2177 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2178 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2183 /* Clear drag arrow */
2184 DrawInsert(hwnd, hwndList, -1);
2191 /* drag list notification function for available buttons list box */
2192 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2194 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2195 switch (pDLI->uNotification)
2201 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2202 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2203 /* no dragging past last item (separator) */
2204 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2206 DrawInsert(hwnd, hwndList, nCurrentItem);
2207 /* FIXME: native uses "move button" cursor */
2208 return DL_COPYCURSOR;
2211 /* not over toolbar buttons list */
2212 if (nCurrentItem < 0)
2214 POINT ptWindow = pDLI->ptCursor;
2215 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2216 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2217 /* over available buttons list? */
2218 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2219 /* FIXME: native uses "move button" cursor */
2220 return DL_COPYCURSOR;
2222 /* clear drag arrow */
2223 DrawInsert(hwnd, hwndList, -1);
2224 return DL_STOPCURSOR;
2228 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2229 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2230 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2231 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2233 /* clear drag arrow */
2234 DrawInsert(hwnd, hwndList, -1);
2236 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2240 /* Clear drag arrow */
2241 DrawInsert(hwnd, hwndList, -1);
2247 extern UINT uDragListMessage;
2249 /***********************************************************************
2250 * TOOLBAR_CustomizeDialogProc
2251 * This function implements the toolbar customization dialog.
2253 static INT_PTR CALLBACK
2254 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2256 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2257 PCUSTOMBUTTON btnInfo;
2259 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2264 custInfo = (PCUSTDLG_INFO)lParam;
2265 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2272 NMTBINITCUSTOMIZE nmtbic;
2274 infoPtr = custInfo->tbInfo;
2276 /* send TBN_QUERYINSERT notification */
2277 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2279 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2282 nmtbic.hwndDialog = hwnd;
2283 /* Send TBN_INITCUSTOMIZE notification */
2284 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2287 TRACE("TBNRF_HIDEHELP requested\n");
2288 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2291 /* add items to 'toolbar buttons' list and check if removable */
2292 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2294 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2295 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2296 btnInfo->btn.fsStyle = BTNS_SEP;
2297 btnInfo->bVirtual = FALSE;
2298 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2300 /* send TBN_QUERYDELETE notification */
2301 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2303 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2304 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2307 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2309 /* insert separator button into 'available buttons' list */
2310 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2311 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2312 btnInfo->btn.fsStyle = BTNS_SEP;
2313 btnInfo->bVirtual = FALSE;
2314 btnInfo->bRemovable = TRUE;
2315 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2316 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2317 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2319 /* insert all buttons into dsa */
2322 /* send TBN_GETBUTTONINFO notification */
2325 nmtb.pszText = Buffer;
2328 /* Clear previous button's text */
2329 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2331 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2334 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2335 nmtb.tbButton.fsStyle, i,
2336 nmtb.tbButton.idCommand,
2337 nmtb.tbButton.iString,
2338 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2341 /* insert button into the apropriate list */
2342 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2345 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2346 btnInfo->bVirtual = FALSE;
2347 btnInfo->bRemovable = TRUE;
2351 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2352 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2355 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2356 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2358 if (lstrlenW(nmtb.pszText))
2359 lstrcpyW(btnInfo->text, nmtb.pszText);
2360 else if (nmtb.tbButton.iString >= 0 &&
2361 nmtb.tbButton.iString < infoPtr->nNumStrings)
2363 lstrcpyW(btnInfo->text,
2364 infoPtr->strings[nmtb.tbButton.iString]);
2369 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2372 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2374 /* select first item in the 'available' list */
2375 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2377 /* append 'virtual' separator button to the 'toolbar buttons' list */
2378 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2379 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2380 btnInfo->btn.fsStyle = BTNS_SEP;
2381 btnInfo->bVirtual = TRUE;
2382 btnInfo->bRemovable = FALSE;
2383 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2384 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2385 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2387 /* select last item in the 'toolbar' list */
2388 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2389 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2391 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2392 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2394 /* set focus and disable buttons */
2395 PostMessageW (hwnd, WM_USER, 0, 0);
2400 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2401 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2402 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2403 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2407 EndDialog(hwnd, FALSE);
2411 switch (LOWORD(wParam))
2413 case IDC_TOOLBARBTN_LBOX:
2414 if (HIWORD(wParam) == LBN_SELCHANGE)
2416 PCUSTOMBUTTON btnInfo;
2421 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2422 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2424 /* send TBN_QUERYINSERT notification */
2426 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2428 /* get list box item */
2429 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2431 if (index == (count - 1))
2433 /* last item (virtual separator) */
2434 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2435 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2437 else if (index == (count - 2))
2439 /* second last item (last non-virtual item) */
2440 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2441 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2443 else if (index == 0)
2446 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2447 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2451 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2455 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2459 case IDC_MOVEUP_BTN:
2461 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2462 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2466 case IDC_MOVEDN_BTN: /* move down */
2468 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2469 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2473 case IDC_REMOVE_BTN: /* remove button */
2475 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2477 if (LB_ERR == index)
2480 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2484 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2487 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2490 case IDOK: /* Add button */
2495 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2496 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2498 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2503 EndDialog(hwnd, FALSE);
2513 /* delete items from 'toolbar buttons' listbox*/
2514 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2515 for (i = 0; i < count; i++)
2517 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2519 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2521 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2524 /* delete items from 'available buttons' listbox*/
2525 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2526 for (i = 0; i < count; i++)
2528 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2530 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2532 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2537 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2539 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2544 COLORREF oldText = 0;
2548 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2549 if (btnInfo == NULL)
2551 FIXME("btnInfo invalid!\n");
2555 /* set colors and select objects */
2556 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2557 if (btnInfo->bVirtual)
2558 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2560 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2561 hPen = CreatePen( PS_SOLID, 1,
2562 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2563 hOldPen = SelectObject (lpdis->hDC, hPen );
2564 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2566 /* fill background rectangle */
2567 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2568 lpdis->rcItem.right, lpdis->rcItem.bottom);
2570 /* calculate button and text rectangles */
2571 CopyRect (&rcButton, &lpdis->rcItem);
2572 InflateRect (&rcButton, -1, -1);
2573 CopyRect (&rcText, &rcButton);
2574 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2575 rcText.left = rcButton.right + 2;
2577 /* draw focus rectangle */
2578 if (lpdis->itemState & ODS_FOCUS)
2579 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2582 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2583 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2585 /* draw image and text */
2586 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2587 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2588 btnInfo->btn.iBitmap));
2589 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2590 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2592 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2593 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2595 /* delete objects and reset colors */
2596 SelectObject (lpdis->hDC, hOldBrush);
2597 SelectObject (lpdis->hDC, hOldPen);
2598 SetBkColor (lpdis->hDC, oldBk);
2599 SetTextColor (lpdis->hDC, oldText);
2600 DeleteObject( hPen );
2605 case WM_MEASUREITEM:
2606 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2608 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2610 lpmis->itemHeight = 15 + 8; /* default height */
2617 if (uDragListMessage && (uMsg == uDragListMessage))
2619 if (wParam == IDC_TOOLBARBTN_LBOX)
2621 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2622 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2623 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2626 else if (wParam == IDC_AVAILBTN_LBOX)
2628 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2629 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2630 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2639 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2642 INT nCountBefore = ImageList_GetImageCount(himlDef);
2648 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2649 /* Add bitmaps to the default image list */
2650 if (bitmap->hInst == NULL) /* a handle was passed */
2653 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2654 HDC hdcImage, hdcBitmap;
2656 /* copy the bitmap before adding it so that the user's bitmap
2657 * doesn't get modified.
2659 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2661 hdcImage = CreateCompatibleDC(0);
2662 hdcBitmap = CreateCompatibleDC(0);
2664 /* create new bitmap */
2665 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2666 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2667 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2669 /* Copy the user's image */
2670 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2671 hdcBitmap, 0, 0, SRCCOPY);
2673 SelectObject (hdcImage, hOldBitmapLoad);
2674 SelectObject (hdcBitmap, hOldBitmapBitmap);
2675 DeleteDC (hdcImage);
2676 DeleteDC (hdcBitmap);
2679 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2681 /* enlarge the bitmap if needed */
2682 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2683 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2685 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2686 DeleteObject(hbmLoad);
2690 nCountAfter = ImageList_GetImageCount(himlDef);
2691 nAdded = nCountAfter - nCountBefore;
2692 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2694 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2695 } else if (nAdded > (INT)bitmap->nButtons) {
2696 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2697 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2700 infoPtr->nNumBitmaps += nAdded;
2705 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2712 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2713 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2715 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2717 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2720 TRACE("Update icon size: %dx%d -> %dx%d\n",
2721 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2723 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2724 ILC_COLORDDB|ILC_MASK, 8, 2);
2725 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2726 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2727 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2728 infoPtr->himlInt = himlNew;
2730 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2731 ImageList_Destroy(himlDef);
2734 /***********************************************************************
2735 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2739 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2741 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2742 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2747 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2751 if (lpAddBmp->hInst == HINST_COMMCTRL)
2753 info.hInst = COMCTL32_hModule;
2754 switch (lpAddBmp->nID)
2756 case IDB_STD_SMALL_COLOR:
2758 info.nID = IDB_STD_SMALL;
2760 case IDB_STD_LARGE_COLOR:
2762 info.nID = IDB_STD_LARGE;
2764 case IDB_VIEW_SMALL_COLOR:
2766 info.nID = IDB_VIEW_SMALL;
2768 case IDB_VIEW_LARGE_COLOR:
2770 info.nID = IDB_VIEW_LARGE;
2772 case IDB_HIST_SMALL_COLOR:
2774 info.nID = IDB_HIST_SMALL;
2776 case IDB_HIST_LARGE_COLOR:
2778 info.nID = IDB_HIST_LARGE;
2784 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2786 /* Windows resize all the buttons to the size of a newly added standard image */
2787 if (lpAddBmp->nID & 1)
2790 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2791 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2793 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2794 MAKELPARAM((WORD)24, (WORD)24));
2795 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2796 MAKELPARAM((WORD)31, (WORD)30));
2801 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2802 MAKELPARAM((WORD)16, (WORD)16));
2803 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2804 MAKELPARAM((WORD)22, (WORD)22));
2807 TOOLBAR_CalcToolbar (hwnd);
2811 info.nButtons = (INT)wParam;
2812 info.hInst = lpAddBmp->hInst;
2813 info.nID = lpAddBmp->nID;
2814 TRACE("adding %d bitmaps!\n", info.nButtons);
2817 /* check if the bitmap is already loaded and compute iSumButtons */
2819 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2821 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2822 infoPtr->bitmaps[i].nID == info.nID)
2824 iSumButtons += infoPtr->bitmaps[i].nButtons;
2827 if (!infoPtr->cimlDef) {
2828 /* create new default image list */
2829 TRACE ("creating default image list!\n");
2831 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2832 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2833 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2834 infoPtr->himlInt = himlDef;
2837 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2841 WARN("No default image list available\n");
2845 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2848 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2849 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2850 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2851 infoPtr->nNumBitmapInfos++;
2852 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2854 InvalidateRect(hwnd, NULL, TRUE);
2860 TOOLBAR_AddButtonsT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2863 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2864 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2866 TRACE("adding %d buttons (unicode=%d)!\n", wParam, fUnicode);
2868 nAddButtons = (UINT)wParam;
2869 nOldButtons = infoPtr->nNumButtons;
2870 nNewButtons = nOldButtons + nAddButtons;
2872 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
2873 infoPtr->nNumButtons = nNewButtons;
2875 /* insert new button data */
2876 for (nCount = 0; nCount < nAddButtons; nCount++) {
2877 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2878 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2879 btnPtr->idCommand = lpTbb[nCount].idCommand;
2880 btnPtr->fsState = lpTbb[nCount].fsState;
2881 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2882 btnPtr->dwData = lpTbb[nCount].dwData;
2883 btnPtr->bHot = FALSE;
2884 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2887 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2889 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString);
2892 btnPtr->iString = lpTbb[nCount].iString;
2894 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2897 TOOLBAR_CalcToolbar (hwnd);
2898 TOOLBAR_AutoSize (hwnd);
2900 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2902 InvalidateRect(hwnd, NULL, TRUE);
2909 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2911 #define MAX_RESOURCE_STRING_LENGTH 512
2912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2913 INT nIndex = infoPtr->nNumStrings;
2915 if ((wParam) && (HIWORD(lParam) == 0)) {
2916 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2921 TRACE("adding string from resource!\n");
2923 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2924 szString, MAX_RESOURCE_STRING_LENGTH);
2926 TRACE("len=%d %s\n", len, debugstr_w(szString));
2927 if (len == 0 || len == 1)
2930 TRACE("Delimiter: 0x%x\n", *szString);
2931 delimiter = *szString;
2934 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2936 if (next_delim + 1 >= szString + len)
2938 /* this may happen if delimiter == '\0' or if the last char is a
2939 * delimiter (then it is ignored like the native does) */
2943 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2944 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2945 infoPtr->nNumStrings++;
2951 LPWSTR p = (LPWSTR)lParam;
2956 TRACE("adding string(s) from array!\n");
2960 TRACE("len=%d %s\n", len, debugstr_w(p));
2961 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2962 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2963 infoPtr->nNumStrings++;
2974 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2981 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
2982 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
2988 TRACE("adding string(s) from array!\n");
2989 nIndex = infoPtr->nNumStrings;
2992 TRACE("len=%d \"%s\"\n", len, p);
2994 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2995 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2996 infoPtr->nNumStrings++;
3006 TOOLBAR_AutoSize (HWND hwnd)
3008 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3014 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3016 parent = GetParent (hwnd);
3018 if (!parent || !infoPtr->bDoRedraw)
3021 GetClientRect(parent, &parent_rect);
3023 x = parent_rect.left;
3024 y = parent_rect.top;
3026 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3028 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3029 cx = parent_rect.right - parent_rect.left;
3031 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3033 TOOLBAR_CalcToolbar(hwnd);
3034 InvalidateRect( hwnd, NULL, TRUE );
3037 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3040 UINT uPosFlags = SWP_NOZORDER;
3042 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3044 GetWindowRect(hwnd, &window_rect);
3045 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3046 y = window_rect.top;
3048 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3050 GetWindowRect(hwnd, &window_rect);
3051 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3054 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3055 uPosFlags |= SWP_NOMOVE;
3057 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3058 cy += GetSystemMetrics(SM_CYEDGE);
3060 if (infoPtr->dwStyle & WS_BORDER)
3062 x = y = 1; /* FIXME: this looks wrong */
3063 cy += GetSystemMetrics(SM_CYEDGE);
3064 cx += GetSystemMetrics(SM_CXEDGE);
3067 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3075 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3079 return infoPtr->nNumButtons;
3084 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3088 infoPtr->dwStructSize = (DWORD)wParam;
3095 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3098 TBUTTON_INFO *btnPtr;
3101 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3103 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3107 btnPtr = &infoPtr->buttons[nIndex];
3108 btnPtr->iBitmap = LOWORD(lParam);
3110 /* we HAVE to erase the background, the new bitmap could be */
3112 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3119 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3121 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3122 TBUTTON_INFO *btnPtr;
3125 BOOL bChecked = FALSE;
3127 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3129 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3134 btnPtr = &infoPtr->buttons[nIndex];
3136 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3138 if (LOWORD(lParam) == FALSE)
3139 btnPtr->fsState &= ~TBSTATE_CHECKED;
3141 if (btnPtr->fsStyle & BTNS_GROUP) {
3143 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3144 if (nOldIndex == nIndex)
3146 if (nOldIndex != -1)
3147 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3149 btnPtr->fsState |= TBSTATE_CHECKED;
3152 if( bChecked != LOWORD(lParam) )
3154 if (nOldIndex != -1)
3155 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3156 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3159 /* FIXME: Send a WM_NOTIFY?? */
3166 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3170 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3175 TOOLBAR_Customize (HWND hwnd)
3177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3178 CUSTDLG_INFO custInfo;
3184 custInfo.tbInfo = infoPtr;
3185 custInfo.tbHwnd = hwnd;
3187 /* send TBN_BEGINADJUST notification */
3188 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3190 if (!(hRes = FindResourceW (COMCTL32_hModule,
3191 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3192 (LPWSTR)RT_DIALOG)))
3195 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3198 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3199 (LPCDLGTEMPLATEW)template,
3201 TOOLBAR_CustomizeDialogProc,
3204 /* send TBN_ENDADJUST notification */
3205 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3212 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3215 INT nIndex = (INT)wParam;
3217 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3219 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3222 memset(&nmtb, 0, sizeof(nmtb));
3223 nmtb.iItem = btnPtr->idCommand;
3224 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3225 nmtb.tbButton.idCommand = btnPtr->idCommand;
3226 nmtb.tbButton.fsState = btnPtr->fsState;
3227 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3228 nmtb.tbButton.dwData = btnPtr->dwData;
3229 nmtb.tbButton.iString = btnPtr->iString;
3230 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3232 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3234 if (infoPtr->nNumButtons == 1) {
3235 TRACE(" simple delete!\n");
3236 Free (infoPtr->buttons);
3237 infoPtr->buttons = NULL;
3238 infoPtr->nNumButtons = 0;
3241 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3242 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3244 infoPtr->nNumButtons--;
3245 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3247 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3248 nIndex * sizeof(TBUTTON_INFO));
3251 if (nIndex < infoPtr->nNumButtons) {
3252 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3253 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3259 TOOLBAR_CalcToolbar (hwnd);
3261 InvalidateRect (hwnd, NULL, TRUE);
3268 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3271 TBUTTON_INFO *btnPtr;
3275 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3277 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3282 btnPtr = &infoPtr->buttons[nIndex];
3284 bState = btnPtr->fsState & TBSTATE_ENABLED;
3286 /* update the toolbar button state */
3287 if(LOWORD(lParam) == FALSE) {
3288 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3290 btnPtr->fsState |= TBSTATE_ENABLED;
3293 /* redraw the button only if the state of the button changed */
3294 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3295 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3301 static inline LRESULT
3302 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3306 return infoPtr->bAnchor;
3311 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3316 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3320 return infoPtr->buttons[nIndex].iBitmap;
3324 static inline LRESULT
3325 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3327 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3332 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3335 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3336 INT nIndex = (INT)wParam;
3337 TBUTTON_INFO *btnPtr;
3342 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3345 btnPtr = &infoPtr->buttons[nIndex];
3346 lpTbb->iBitmap = btnPtr->iBitmap;
3347 lpTbb->idCommand = btnPtr->idCommand;
3348 lpTbb->fsState = btnPtr->fsState;
3349 lpTbb->fsStyle = btnPtr->fsStyle;
3350 lpTbb->bReserved[0] = 0;
3351 lpTbb->bReserved[1] = 0;
3352 lpTbb->dwData = btnPtr->dwData;
3353 lpTbb->iString = btnPtr->iString;
3360 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3362 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3363 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3364 TBUTTON_INFO *btnPtr;
3367 if (lpTbInfo == NULL)
3369 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3372 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3373 lpTbInfo->dwMask & 0x80000000);
3377 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3379 if (lpTbInfo->dwMask & TBIF_COMMAND)
3380 lpTbInfo->idCommand = btnPtr->idCommand;
3381 if (lpTbInfo->dwMask & TBIF_IMAGE)
3382 lpTbInfo->iImage = btnPtr->iBitmap;
3383 if (lpTbInfo->dwMask & TBIF_LPARAM)
3384 lpTbInfo->lParam = btnPtr->dwData;
3385 if (lpTbInfo->dwMask & TBIF_SIZE)
3386 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3387 if (lpTbInfo->dwMask & TBIF_STATE)
3388 lpTbInfo->fsState = btnPtr->fsState;
3389 if (lpTbInfo->dwMask & TBIF_STYLE)
3390 lpTbInfo->fsStyle = btnPtr->fsStyle;
3391 if (lpTbInfo->dwMask & TBIF_TEXT) {
3392 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3393 can't use TOOLBAR_GetText here */
3395 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3396 lpText = (LPWSTR)btnPtr->iString;
3397 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3399 lpTbInfo->pszText[0] = '\0';
3406 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3409 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3410 TBUTTON_INFO *btnPtr;
3413 if (lpTbInfo == NULL)
3415 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3418 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3419 lpTbInfo->dwMask & 0x80000000);
3423 btnPtr = &infoPtr->buttons[nIndex];
3428 if (lpTbInfo->dwMask & TBIF_COMMAND)
3429 lpTbInfo->idCommand = btnPtr->idCommand;
3430 if (lpTbInfo->dwMask & TBIF_IMAGE)
3431 lpTbInfo->iImage = btnPtr->iBitmap;
3432 if (lpTbInfo->dwMask & TBIF_LPARAM)
3433 lpTbInfo->lParam = btnPtr->dwData;
3434 if (lpTbInfo->dwMask & TBIF_SIZE)
3435 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3436 if (lpTbInfo->dwMask & TBIF_STATE)
3437 lpTbInfo->fsState = btnPtr->fsState;
3438 if (lpTbInfo->dwMask & TBIF_STYLE)
3439 lpTbInfo->fsStyle = btnPtr->fsStyle;
3440 if (lpTbInfo->dwMask & TBIF_TEXT) {
3441 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3442 can't use TOOLBAR_GetText here */
3444 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3445 lpText = (LPWSTR)btnPtr->iString;
3446 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3448 lpTbInfo->pszText[0] = '\0';
3456 TOOLBAR_GetButtonSize (HWND hwnd)
3458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3460 if (infoPtr->nNumButtons > 0)
3461 return MAKELONG((WORD)infoPtr->nButtonWidth,
3462 (WORD)infoPtr->nButtonHeight);
3464 return MAKELONG(23,22);
3469 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3471 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3478 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3482 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3484 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3485 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3490 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3492 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3497 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3501 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3505 ret = strlenW (lpText);
3508 strcpyW ((LPWSTR)lParam, lpText);
3516 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3518 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3519 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3520 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3524 inline static LRESULT
3525 TOOLBAR_GetExtendedStyle (HWND hwnd)
3527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3531 return infoPtr->dwExStyle;
3536 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3538 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3539 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3540 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3545 TOOLBAR_GetHotItem (HWND hwnd)
3547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3549 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3552 if (infoPtr->nHotItem < 0)
3555 return (LRESULT)infoPtr->nHotItem;
3560 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3563 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3564 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3569 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3571 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3572 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3574 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3576 *lptbim = infoPtr->tbim;
3583 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3587 TRACE("hwnd = %p\n", hwnd);
3589 return (LRESULT)infoPtr->clrInsertMark;
3594 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3596 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3597 TBUTTON_INFO *btnPtr;
3601 nIndex = (INT)wParam;
3602 btnPtr = &infoPtr->buttons[nIndex];
3603 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3605 lpRect = (LPRECT)lParam;
3608 if (btnPtr->fsState & TBSTATE_HIDDEN)
3611 lpRect->left = btnPtr->rect.left;
3612 lpRect->right = btnPtr->rect.right;
3613 lpRect->bottom = btnPtr->rect.bottom;
3614 lpRect->top = btnPtr->rect.top;
3621 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3624 LPSIZE lpSize = (LPSIZE)lParam;
3629 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3630 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3632 TRACE("maximum size %ld x %ld\n",
3633 infoPtr->rcBound.right - infoPtr->rcBound.left,
3634 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3640 /* << TOOLBAR_GetObject >> */
3644 TOOLBAR_GetPadding (HWND hwnd)
3646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3649 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3650 return (LRESULT) oldPad;
3655 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3658 TBUTTON_INFO *btnPtr;
3662 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3663 btnPtr = &infoPtr->buttons[nIndex];
3664 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3666 lpRect = (LPRECT)lParam;
3670 lpRect->left = btnPtr->rect.left;
3671 lpRect->right = btnPtr->rect.right;
3672 lpRect->bottom = btnPtr->rect.bottom;
3673 lpRect->top = btnPtr->rect.top;
3680 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3685 return infoPtr->nRows;
3692 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3697 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3701 return infoPtr->buttons[nIndex].fsState;
3706 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 return GetWindowLongW(hwnd, GWL_STYLE);
3713 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3717 return infoPtr->nMaxTextRows;
3722 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3726 return (LRESULT)infoPtr->hwndToolTip;
3731 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3733 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3735 TRACE("%s hwnd=%p\n",
3736 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3738 return infoPtr->bUnicode;
3742 inline static LRESULT
3743 TOOLBAR_GetVersion (HWND hwnd)
3745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3746 return infoPtr->iVersion;
3751 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3754 TBUTTON_INFO *btnPtr;
3759 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3763 btnPtr = &infoPtr->buttons[nIndex];
3764 if (LOWORD(lParam) == FALSE)
3765 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3767 btnPtr->fsState |= TBSTATE_HIDDEN;
3769 TOOLBAR_CalcToolbar (hwnd);
3771 InvalidateRect (hwnd, NULL, TRUE);
3777 inline static LRESULT
3778 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3780 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3785 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3788 TBUTTON_INFO *btnPtr;
3792 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3796 btnPtr = &infoPtr->buttons[nIndex];
3797 oldState = btnPtr->fsState;
3798 if (LOWORD(lParam) == FALSE)
3799 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3801 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3803 if(oldState != btnPtr->fsState)
3804 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3811 TOOLBAR_InsertButtonT(HWND hwnd, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
3813 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3814 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3815 INT nIndex = (INT)wParam;
3820 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3823 /* EPP: this seems to be an undocumented call (from my IE4)
3824 * I assume in that case that:
3825 * - index of insertion is at the end of existing buttons
3826 * I only see this happen with nIndex == -1, but it could have a special
3827 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3829 nIndex = infoPtr->nNumButtons;
3831 } else if (nIndex < 0)
3834 TRACE("inserting button index=%d\n", nIndex);
3835 if (nIndex > infoPtr->nNumButtons) {
3836 nIndex = infoPtr->nNumButtons;
3837 TRACE("adjust index=%d\n", nIndex);
3840 infoPtr->nNumButtons++;
3841 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO) * infoPtr->nNumButtons);
3842 memmove(&infoPtr->buttons[nIndex+1], &infoPtr->buttons[nIndex],
3843 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3845 /* insert new button */
3846 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3847 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3848 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3849 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3850 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3851 /* if passed string and not index, then add string */
3852 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3854 Str_SetPtrW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3856 Str_SetPtrAtoW((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3859 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3861 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[nIndex]);
3863 TOOLBAR_CalcToolbar (hwnd);
3864 TOOLBAR_AutoSize (hwnd);
3866 InvalidateRect (hwnd, NULL, TRUE);
3871 /* << TOOLBAR_InsertMarkHitTest >> */
3875 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3877 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3880 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3884 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3889 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3894 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3898 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3903 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3908 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3912 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3917 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3919 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3922 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3926 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3931 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3936 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3940 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3945 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3950 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3954 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3959 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3962 tbab.hInst = (HINSTANCE)lParam;
3963 tbab.nID = (UINT_PTR)wParam;
3965 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3967 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3972 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3975 WCHAR wAccel = (WCHAR)wParam;
3976 UINT* pIDButton = (UINT*)lParam;
3977 WCHAR wszAccel[] = {'&',wAccel,0};
3980 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3981 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3983 for (i = 0; i < infoPtr->nNumButtons; i++)
3985 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3986 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3987 !(btnPtr->fsState & TBSTATE_HIDDEN))
3989 int iLen = strlenW(wszAccel);
3990 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3997 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4002 if (!strncmpiW(lpszStr, wszAccel, iLen))
4004 *pIDButton = btnPtr->idCommand;
4016 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4021 TBUTTON_INFO *btnPtr;
4023 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4025 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4029 btnPtr = &infoPtr->buttons[nIndex];
4030 oldState = btnPtr->fsState;
4033 btnPtr->fsState |= TBSTATE_MARKED;
4035 btnPtr->fsState &= ~TBSTATE_MARKED;
4037 if(oldState != btnPtr->fsState)
4038 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4044 /* fixes up an index of a button affected by a move */
4045 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4049 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4051 else if (*pIndex == nIndex)
4052 *pIndex = nMoveIndex;
4056 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4058 else if (*pIndex == nIndex)
4059 *pIndex = nMoveIndex;
4065 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4070 INT nMoveIndex = (INT)lParam;
4071 TBUTTON_INFO button;
4073 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4075 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4076 if ((nIndex == -1) || (nMoveIndex < 0))
4079 if (nMoveIndex > infoPtr->nNumButtons - 1)
4080 nMoveIndex = infoPtr->nNumButtons - 1;
4082 button = infoPtr->buttons[nIndex];
4084 /* move button right */
4085 if (nIndex < nMoveIndex)
4087 nCount = nMoveIndex - nIndex;
4088 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4089 infoPtr->buttons[nMoveIndex] = button;
4091 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4092 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4093 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4094 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4096 else if (nIndex > nMoveIndex) /* move button left */
4098 nCount = nIndex - nMoveIndex;
4099 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4100 infoPtr->buttons[nMoveIndex] = button;
4102 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4103 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4104 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4105 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4108 TOOLBAR_CalcToolbar(hwnd);
4109 TOOLBAR_AutoSize(hwnd);
4110 InvalidateRect(hwnd, NULL, TRUE);
4117 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4120 TBUTTON_INFO *btnPtr;
4124 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4128 btnPtr = &infoPtr->buttons[nIndex];
4129 oldState = btnPtr->fsState;
4130 if (LOWORD(lParam) == FALSE)
4131 btnPtr->fsState &= ~TBSTATE_PRESSED;
4133 btnPtr->fsState |= TBSTATE_PRESSED;
4135 if(oldState != btnPtr->fsState)
4136 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4141 /* FIXME: there might still be some confusion her between number of buttons
4142 * and number of bitmaps */
4144 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4146 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4147 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4149 HBITMAP hbmLoad = NULL;
4150 int i = 0, nOldButtons = 0, pos = 0;
4151 int nOldBitmaps, nNewBitmaps = 0;
4152 HIMAGELIST himlDef = 0;
4154 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4155 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4156 lpReplace->nButtons);
4158 if (lpReplace->hInstOld == HINST_COMMCTRL)
4160 FIXME("changing standard bitmaps not implemented\n");
4163 else if (lpReplace->hInstOld != 0)
4164 FIXME("resources not in the current module not implemented\n");
4166 if (lpReplace->hInstNew)
4168 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4173 hBitmap = (HBITMAP) lpReplace->nIDNew;
4176 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4177 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4178 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4179 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4180 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4182 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4183 nOldButtons = tbi->nButtons;
4184 tbi->nButtons = lpReplace->nButtons;
4185 tbi->hInst = lpReplace->hInstNew;
4186 tbi->nID = lpReplace->nIDNew;
4187 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4190 pos += tbi->nButtons;
4193 if (nOldButtons == 0)
4195 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4197 DeleteObject (hbmLoad);
4201 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4202 nOldBitmaps = ImageList_GetImageCount(himlDef);
4204 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4206 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4207 ImageList_Remove(himlDef, i);
4212 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4213 HDC hdcImage, hdcBitmap;
4215 /* copy the bitmap before adding it so that the user's bitmap
4216 * doesn't get modified.
4218 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4220 hdcImage = CreateCompatibleDC(0);
4221 hdcBitmap = CreateCompatibleDC(0);
4223 /* create new bitmap */
4224 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4225 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4226 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4228 /* Copy the user's image */
4229 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4230 hdcBitmap, 0, 0, SRCCOPY);
4232 SelectObject (hdcImage, hOldBitmapLoad);
4233 SelectObject (hdcBitmap, hOldBitmapBitmap);
4234 DeleteDC (hdcImage);
4235 DeleteDC (hdcBitmap);
4237 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4238 nNewBitmaps = ImageList_GetImageCount(himlDef);
4239 DeleteObject (hbmLoad);
4242 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4244 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4245 pos, nOldBitmaps, nNewBitmaps);
4247 InvalidateRect(hwnd, NULL, TRUE);
4250 DeleteObject (hbmLoad);
4255 /* helper for TOOLBAR_SaveRestoreW */
4257 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4259 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4260 debugstr_w(lpSave->pszValueName));
4266 /* helper for TOOLBAR_Restore */
4268 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4272 for (i = 0; i < infoPtr->nNumButtons; i++)
4274 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4277 Free(infoPtr->buttons);
4278 infoPtr->buttons = NULL;
4279 infoPtr->nNumButtons = 0;
4283 /* helper for TOOLBAR_SaveRestoreW */
4285 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4294 /* restore toolbar information */
4295 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4296 debugstr_w(lpSave->pszValueName));
4298 memset(&nmtbr, 0, sizeof(nmtbr));
4300 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4301 KEY_QUERY_VALUE, &hkey);
4303 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4305 if (!res && dwType != REG_BINARY)
4306 res = ERROR_FILE_NOT_FOUND;
4309 nmtbr.pData = Alloc(dwSize);
4310 nmtbr.cbData = (UINT)dwSize;
4311 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4314 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4315 (LPBYTE)nmtbr.pData, &dwSize);
4318 nmtbr.pCurrent = nmtbr.pData;
4320 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4321 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4323 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4327 /* remove all existing buttons as this function is designed to
4328 * restore the toolbar to a previously saved state */
4329 TOOLBAR_DeleteAllButtons(infoPtr);
4331 for (i = 0; i < nmtbr.cButtons; i++)
4334 nmtbr.tbButton.iBitmap = -1;
4335 nmtbr.tbButton.fsState = 0;
4336 nmtbr.tbButton.fsStyle = 0;
4337 nmtbr.tbButton.idCommand = 0;
4338 if (*nmtbr.pCurrent == (DWORD)-1)
4341 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4342 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4344 else if (*nmtbr.pCurrent == (DWORD)-2)
4346 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4348 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4352 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4354 /* can't contain real string as we don't know whether
4355 * the client put an ANSI or Unicode string in there */
4356 if (HIWORD(nmtbr.tbButton.iString))
4357 nmtbr.tbButton.iString = 0;
4359 TOOLBAR_InsertButtonT(infoPtr->hwndSelf, -1,
4360 (LPARAM)&nmtbr.tbButton, TRUE);
4363 /* do legacy notifications */
4364 if (infoPtr->iVersion < 5)
4366 /* FIXME: send TBN_BEGINADJUST */
4367 FIXME("send TBN_GETBUTTONINFO for each button\n");
4368 /* FIXME: send TBN_ENDADJUST */
4371 /* remove all uninitialised buttons
4372 * note: loop backwards to avoid having to fixup i on a
4374 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4375 if (infoPtr->buttons[i].iBitmap == -1)
4376 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4378 /* only indicate success if at least one button survived */
4379 if (infoPtr->nNumButtons > 0) ret = TRUE;
4390 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4394 if (lpSave == NULL) return 0;
4397 return TOOLBAR_Save(infoPtr, lpSave);
4399 return TOOLBAR_Restore(infoPtr, lpSave);
4404 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4406 LPWSTR pszValueName = 0, pszSubKey = 0;
4407 TBSAVEPARAMSW SaveW;
4411 if (lpSave == NULL) return 0;
4413 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4414 pszSubKey = Alloc(len * sizeof(WCHAR));
4415 if (pszSubKey) goto exit;
4416 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4418 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4419 pszValueName = Alloc(len * sizeof(WCHAR));
4420 if (!pszValueName) goto exit;
4421 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4423 SaveW.pszValueName = pszValueName;
4424 SaveW.pszSubKey = pszSubKey;
4425 SaveW.hkr = lpSave->hkr;
4426 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4429 Free (pszValueName);
4437 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4440 BOOL bOldAnchor = infoPtr->bAnchor;
4442 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4444 infoPtr->bAnchor = (BOOL)wParam;
4446 /* Native does not remove the hot effect from an already hot button */
4448 return (LRESULT)bOldAnchor;
4453 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4455 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4456 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4458 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4461 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4463 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4464 lParam = MAKELPARAM(16, 15);
4466 if (infoPtr->nNumButtons > 0)
4467 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4468 infoPtr->nNumButtons,
4469 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4470 LOWORD(lParam), HIWORD(lParam));
4472 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4473 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4476 if ((himlDef == infoPtr->himlInt) &&
4477 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4479 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4480 infoPtr->nBitmapHeight);
4483 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4489 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4491 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4492 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4493 TBUTTON_INFO *btnPtr;
4499 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4502 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4503 lptbbi->dwMask & 0x80000000);
4507 btnPtr = &infoPtr->buttons[nIndex];
4508 if (lptbbi->dwMask & TBIF_COMMAND)
4509 btnPtr->idCommand = lptbbi->idCommand;
4510 if (lptbbi->dwMask & TBIF_IMAGE)
4511 btnPtr->iBitmap = lptbbi->iImage;
4512 if (lptbbi->dwMask & TBIF_LPARAM)
4513 btnPtr->dwData = lptbbi->lParam;
4514 if (lptbbi->dwMask & TBIF_SIZE)
4515 btnPtr->cx = lptbbi->cx;
4516 if (lptbbi->dwMask & TBIF_STATE)
4517 btnPtr->fsState = lptbbi->fsState;
4518 if (lptbbi->dwMask & TBIF_STYLE)
4519 btnPtr->fsStyle = lptbbi->fsStyle;
4521 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4522 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4523 /* iString is index, zero it to make Str_SetPtr succeed */
4526 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4529 /* save the button rect to see if we need to redraw the whole toolbar */
4530 oldBtnRect = btnPtr->rect;
4531 TOOLBAR_CalcToolbar(hwnd);
4533 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4534 InvalidateRect(hwnd, NULL, TRUE);
4536 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4543 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4546 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4547 TBUTTON_INFO *btnPtr;
4553 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4556 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4557 lptbbi->dwMask & 0x80000000);
4561 btnPtr = &infoPtr->buttons[nIndex];
4562 if (lptbbi->dwMask & TBIF_COMMAND)
4563 btnPtr->idCommand = lptbbi->idCommand;
4564 if (lptbbi->dwMask & TBIF_IMAGE)
4565 btnPtr->iBitmap = lptbbi->iImage;
4566 if (lptbbi->dwMask & TBIF_LPARAM)
4567 btnPtr->dwData = lptbbi->lParam;
4568 if (lptbbi->dwMask & TBIF_SIZE)
4569 btnPtr->cx = lptbbi->cx;
4570 if (lptbbi->dwMask & TBIF_STATE)
4571 btnPtr->fsState = lptbbi->fsState;
4572 if (lptbbi->dwMask & TBIF_STYLE)
4573 btnPtr->fsStyle = lptbbi->fsStyle;
4575 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4576 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4577 /* iString is index, zero it to make Str_SetPtr succeed */
4579 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4582 /* save the button rect to see if we need to redraw the whole toolbar */
4583 oldBtnRect = btnPtr->rect;
4584 TOOLBAR_CalcToolbar(hwnd);
4586 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4587 InvalidateRect(hwnd, NULL, TRUE);
4589 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4596 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4599 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4601 if ((cx < 0) || (cy < 0))
4603 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4607 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4609 /* The documentation claims you can only change the button size before
4610 * any button has been added. But this is wrong.
4611 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4612 * it to the toolbar, and it checks that the return value is nonzero - mjm
4613 * Further testing shows that we must actually perform the change too.
4616 * The documentation also does not mention that if 0 is supplied for
4617 * either size, the system changes it to the default of 24 wide and
4618 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4620 infoPtr->nButtonWidth = (cx) ? cx : 24;
4621 infoPtr->nButtonHeight = (cy) ? cy : 22;
4627 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4629 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4631 /* if setting to current values, ignore */
4632 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4633 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4634 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4635 infoPtr->cxMin, infoPtr->cxMax);
4639 /* save new values */
4640 infoPtr->cxMin = (INT)LOWORD(lParam);
4641 infoPtr->cxMax = (INT)HIWORD(lParam);
4643 /* otherwise we need to recalc the toolbar and in some cases
4644 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4645 which doesn't actually draw - GA). */
4646 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4647 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4649 TOOLBAR_CalcToolbar (hwnd);
4651 InvalidateRect (hwnd, NULL, TRUE);
4658 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4661 INT nIndex = (INT)wParam;
4663 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4666 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4668 if (infoPtr->hwndToolTip) {
4670 FIXME("change tool tip!\n");
4679 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4682 HIMAGELIST himl = (HIMAGELIST)lParam;
4683 HIMAGELIST himlTemp;
4686 if (infoPtr->iVersion >= 5)
4689 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4690 &infoPtr->cimlDis, himl, id);
4692 /* FIXME: redraw ? */
4694 return (LRESULT)himlTemp;
4699 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4704 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4706 dwTemp = infoPtr->dwDTFlags;
4707 infoPtr->dwDTFlags =
4708 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4710 return (LRESULT)dwTemp;
4713 /* This function differs a bit from what MSDN says it does:
4714 * 1. lParam contains extended style flags to OR with current style
4715 * (MSDN isn't clear on the OR bit)
4716 * 2. wParam appears to contain extended style flags to be reset
4717 * (MSDN says that this parameter is reserved)
4720 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 dwTemp = infoPtr->dwExStyle;
4726 infoPtr->dwExStyle &= ~wParam;
4727 infoPtr->dwExStyle |= (DWORD)lParam;
4729 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4731 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4732 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4733 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4735 TOOLBAR_CalcToolbar (hwnd);
4737 TOOLBAR_AutoSize(hwnd);
4739 InvalidateRect(hwnd, NULL, TRUE);
4741 return (LRESULT)dwTemp;
4746 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4748 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4749 HIMAGELIST himlTemp;
4750 HIMAGELIST himl = (HIMAGELIST)lParam;
4753 if (infoPtr->iVersion >= 5)
4756 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4758 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4759 &infoPtr->cimlHot, himl, id);
4761 /* FIXME: redraw ? */
4763 return (LRESULT)himlTemp;
4767 /* Makes previous hot button no longer hot, makes the specified
4768 * button hot and sends appropriate notifications. dwReason is one or
4769 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4770 * NOTE 1: this function does not validate nHit
4771 * NOTE 2: the name of this function is completely made up and
4772 * not based on any documentation from Microsoft. */
4774 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4776 if (infoPtr->nHotItem != nHit)
4778 NMTBHOTITEM nmhotitem;
4779 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4780 LRESULT no_highlight;
4782 /* Remove the effect of an old hot button if the button was
4783 drawn with the hot button effect */
4784 if(infoPtr->nHotItem >= 0)
4786 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4787 oldBtnPtr->bHot = FALSE;
4790 infoPtr->nHotItem = nHit;
4792 /* It's not a separator or in nowhere. It's a hot button. */
4794 btnPtr = &infoPtr->buttons[nHit];
4796 nmhotitem.dwFlags = dwReason;
4798 nmhotitem.idOld = oldBtnPtr->idCommand;
4800 nmhotitem.dwFlags |= HICF_ENTERING;
4802 nmhotitem.idNew = btnPtr->idCommand;
4804 nmhotitem.dwFlags |= HICF_LEAVING;
4806 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
4808 /* now invalidate the old and new buttons so they will be painted,
4809 * but only if they are enabled - disabled buttons cannot become hot */
4810 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
4811 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4812 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
4814 btnPtr->bHot = TRUE;
4815 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4821 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4824 INT nOldHotItem = infoPtr->nHotItem;
4826 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4828 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4831 /* NOTE: an application can still remove the hot item even if anchor
4832 * highlighting is enabled */
4834 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
4835 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4837 if (nOldHotItem < 0)
4840 return (LRESULT)nOldHotItem;
4845 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4848 HIMAGELIST himlTemp;
4849 HIMAGELIST himl = (HIMAGELIST)lParam;
4852 if (infoPtr->iVersion >= 5)
4855 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4856 &infoPtr->cimlDef, himl, id);
4858 infoPtr->nNumBitmaps = 0;
4859 for (i = 0; i < infoPtr->cimlDef; i++)
4860 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4862 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4863 &infoPtr->nBitmapHeight))
4865 infoPtr->nBitmapWidth = 1;
4866 infoPtr->nBitmapHeight = 1;
4869 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4870 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4871 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4873 InvalidateRect(hwnd, NULL, TRUE);
4875 return (LRESULT)himlTemp;
4880 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4884 infoPtr->nIndent = (INT)wParam;
4888 /* process only on indent changing */
4889 if(infoPtr->nIndent != (INT)wParam)
4891 infoPtr->nIndent = (INT)wParam;
4892 TOOLBAR_CalcToolbar (hwnd);
4893 InvalidateRect(hwnd, NULL, FALSE);
4901 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4904 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4906 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4908 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4910 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4914 if ((lptbim->iButton == -1) ||
4915 ((lptbim->iButton < infoPtr->nNumButtons) &&
4916 (lptbim->iButton >= 0)))
4918 infoPtr->tbim = *lptbim;
4919 /* FIXME: don't need to update entire toolbar */
4920 InvalidateRect(hwnd, NULL, TRUE);
4923 ERR("Invalid button index %d\n", lptbim->iButton);
4930 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4934 infoPtr->clrInsertMark = (COLORREF)lParam;
4936 /* FIXME: don't need to update entire toolbar */
4937 InvalidateRect(hwnd, NULL, TRUE);
4944 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4948 infoPtr->nMaxTextRows = (INT)wParam;
4950 TOOLBAR_CalcToolbar(hwnd);
4955 /* MSDN gives slightly wrong info on padding.
4956 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4957 * 2. It is not used to create a blank area between the edge of the button
4958 * and the text or image if TBSTYLE_LIST is set. It is used to control
4959 * the gap between the image and text.
4960 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4961 * to control the bottom and right borders [with the border being
4962 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4963 * is shared evenly on both sides of the button.
4964 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4967 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4969 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4972 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4973 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4974 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4975 TRACE("cx=%ld, cy=%ld\n",
4976 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4977 return (LRESULT) oldPad;
4982 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4989 hwndOldNotify = infoPtr->hwndNotify;
4990 infoPtr->hwndNotify = (HWND)wParam;
4992 return (LRESULT)hwndOldNotify;
4997 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5000 LPRECT lprc = (LPRECT)lParam;
5004 if (LOWORD(wParam) > 1) {
5005 FIXME("multiple rows not supported!\n");
5008 if(infoPtr->nRows != LOWORD(wParam))
5010 infoPtr->nRows = LOWORD(wParam);
5012 /* recalculate toolbar */
5013 TOOLBAR_CalcToolbar (hwnd);
5015 /* repaint toolbar */
5016 InvalidateRect(hwnd, NULL, TRUE);
5019 /* return bounding rectangle */
5021 lprc->left = infoPtr->rcBound.left;
5022 lprc->right = infoPtr->rcBound.right;
5023 lprc->top = infoPtr->rcBound.top;
5024 lprc->bottom = infoPtr->rcBound.bottom;
5032 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5034 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5035 TBUTTON_INFO *btnPtr;
5038 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5042 btnPtr = &infoPtr->buttons[nIndex];
5044 /* if hidden state has changed the invalidate entire window and recalc */
5045 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5046 btnPtr->fsState = LOWORD(lParam);
5047 TOOLBAR_CalcToolbar (hwnd);
5048 InvalidateRect(hwnd, 0, TRUE);
5052 /* process state changing if current state doesn't match new state */
5053 if(btnPtr->fsState != LOWORD(lParam))
5055 btnPtr->fsState = LOWORD(lParam);
5056 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5064 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5066 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5072 inline static LRESULT
5073 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5077 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5079 infoPtr->hwndToolTip = (HWND)wParam;
5085 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5090 TRACE("%s hwnd=%p\n",
5091 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5093 bTemp = infoPtr->bUnicode;
5094 infoPtr->bUnicode = (BOOL)wParam;
5101 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5105 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5106 comctl32_color.clrBtnHighlight :
5107 infoPtr->clrBtnHighlight;
5108 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5109 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5115 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5119 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5120 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5121 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5123 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5124 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5125 InvalidateRect(hwnd, NULL, TRUE);
5131 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5134 INT iOldVersion = infoPtr->iVersion;
5136 infoPtr->iVersion = iVersion;
5138 if (infoPtr->iVersion >= 5)
5139 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5146 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5149 WORD iString = HIWORD(wParam);
5150 WORD buffersize = LOWORD(wParam);
5151 LPSTR str = (LPSTR)lParam;
5154 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5156 if (iString < infoPtr->nNumStrings)
5158 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5160 TRACE("returning %s\n", debugstr_a(str));
5163 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5170 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5173 WORD iString = HIWORD(wParam);
5174 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5175 LPWSTR str = (LPWSTR)lParam;
5178 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5180 if (iString < infoPtr->nNumStrings)
5182 len = min(len, strlenW(infoPtr->strings[iString]));
5183 ret = (len+1)*sizeof(WCHAR);
5184 memcpy(str, infoPtr->strings[iString], ret);
5187 TRACE("returning %s\n", debugstr_w(str));
5190 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5195 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5196 * is the maximum size of the toolbar? */
5197 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5199 SIZE * pSize = (SIZE*)lParam;
5200 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5205 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5206 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5207 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5210 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5213 INT nOldHotItem = infoPtr->nHotItem;
5215 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5216 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5218 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5221 /* NOTE: an application can still remove the hot item even if anchor
5222 * highlighting is enabled */
5224 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5228 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5231 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5232 * which controls the amount of spacing between the image and the text
5233 * of buttons for TBSTYLE_LIST toolbars. */
5234 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5238 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5241 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5243 infoPtr->iListGap = (INT)wParam;
5245 InvalidateRect(hwnd, NULL, TRUE);
5250 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5251 * of image lists associated with the various states. */
5252 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5254 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5256 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5258 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5262 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5265 LPSIZE lpsize = (LPSIZE)lParam;
5271 * Testing shows the following:
5272 * wParam = 0 adjust cx value
5273 * = 1 set cy value to max size.
5274 * lParam pointer to SIZE structure
5277 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5278 wParam, lParam, lpsize->cx, lpsize->cy);
5282 if (lpsize->cx == -1) {
5283 /* **** this is wrong, native measures each button and sets it */
5284 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5286 else if(HIWORD(lpsize->cx)) {
5288 HWND hwndParent = GetParent(hwnd);
5290 GetWindowRect(hwnd, &rc);
5291 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5292 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5293 rc.left, rc.top, rc.right, rc.bottom);
5294 lpsize->cx = max(rc.right-rc.left,
5295 infoPtr->rcBound.right - infoPtr->rcBound.left);
5298 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5302 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5305 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5309 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5310 lpsize->cx, lpsize->cy);
5314 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5316 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5318 InvalidateRect(hwnd, NULL, TRUE);
5324 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5326 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5327 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5330 TRACE("hwnd = %p\n", hwnd);
5332 /* initialize info structure */
5333 infoPtr->nButtonHeight = 22;
5334 infoPtr->nButtonWidth = 24;
5335 infoPtr->nBitmapHeight = 15;
5336 infoPtr->nBitmapWidth = 16;
5338 infoPtr->nMaxTextRows = 1;
5339 infoPtr->cxMin = -1;
5340 infoPtr->cxMax = -1;
5341 infoPtr->nNumBitmaps = 0;
5342 infoPtr->nNumStrings = 0;
5344 infoPtr->bCaptured = FALSE;
5345 infoPtr->nButtonDown = -1;
5346 infoPtr->nButtonDrag = -1;
5347 infoPtr->nOldHit = -1;
5348 infoPtr->nHotItem = -1;
5349 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5350 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5351 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5352 infoPtr->bDragOutSent = FALSE;
5353 infoPtr->iVersion = 0;
5354 infoPtr->hwndSelf = hwnd;
5355 infoPtr->bDoRedraw = TRUE;
5356 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5357 infoPtr->clrBtnShadow = CLR_DEFAULT;
5358 infoPtr->szPadding.cx = DEFPAD_CX;
5359 infoPtr->szPadding.cy = DEFPAD_CY;
5360 infoPtr->iListGap = DEFLISTGAP;
5361 infoPtr->dwStyle = dwStyle;
5362 infoPtr->tbim.iButton = -1;
5363 GetClientRect(hwnd, &infoPtr->client_rect);
5364 infoPtr->bUnicode = infoPtr->hwndNotify &&
5365 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5366 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5368 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5369 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5371 OpenThemeData (hwnd, themeClass);
5373 TOOLBAR_CheckStyle (hwnd, dwStyle);
5375 TOOLBAR_CalcToolbar(hwnd);
5382 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5384 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5386 /* delete tooltip control */
5387 if (infoPtr->hwndToolTip)
5388 DestroyWindow (infoPtr->hwndToolTip);
5390 /* delete temporary buffer for tooltip text */
5391 Free (infoPtr->pszTooltipText);
5392 Free (infoPtr->bitmaps); /* bitmaps list */
5394 /* delete button data */
5395 if (infoPtr->buttons)
5396 Free (infoPtr->buttons);
5398 /* delete strings */
5399 if (infoPtr->strings) {
5401 for (i = 0; i < infoPtr->nNumStrings; i++)
5402 if (infoPtr->strings[i])
5403 Free (infoPtr->strings[i]);
5405 Free (infoPtr->strings);
5408 /* destroy internal image list */
5409 if (infoPtr->himlInt)
5410 ImageList_Destroy (infoPtr->himlInt);
5412 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5413 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5414 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5416 /* delete default font */
5418 DeleteObject (infoPtr->hDefaultFont);
5420 CloseThemeData (GetWindowTheme (hwnd));
5422 /* free toolbar info data */
5424 SetWindowLongPtrW (hwnd, 0, 0);
5431 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5434 NMTBCUSTOMDRAW tbcd;
5437 HTHEME theme = GetWindowTheme (hwnd);
5439 /* the app has told us not to redraw the toolbar */
5440 if (!infoPtr->bDoRedraw)
5443 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5444 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5445 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5446 tbcd.nmcd.hdc = (HDC)wParam;
5447 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5448 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5450 /* FIXME: in general the return flags *can* be or'ed together */
5451 switch (infoPtr->dwBaseCustDraw)
5453 case CDRF_DODEFAULT:
5455 case CDRF_SKIPDEFAULT:
5458 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5463 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5464 * to my parent for processing.
5466 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5468 HDC hdc = (HDC)wParam;
5473 parent = GetParent(hwnd);
5474 MapWindowPoints(hwnd, parent, &pt, 1);
5475 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5476 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5477 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5480 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5482 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5483 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5484 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5485 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5486 tbcd.nmcd.hdc = (HDC)wParam;
5487 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5488 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5489 switch (infoPtr->dwBaseCustDraw)
5491 case CDRF_DODEFAULT:
5493 case CDRF_SKIPDEFAULT:
5496 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5505 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5509 return (LRESULT)infoPtr->hFont;
5514 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5517 INT nNewHotItem = infoPtr->nHotItem;
5519 for (i = 0; i < infoPtr->nNumButtons; i++)
5522 if ((nNewHotItem + iDirection < 0) ||
5523 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5525 NMTBWRAPHOTITEM nmtbwhi;
5526 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5527 nmtbwhi.iDirection = iDirection;
5528 nmtbwhi.dwReason = dwReason;
5530 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5534 nNewHotItem += iDirection;
5535 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5537 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5538 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5540 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5547 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5549 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5552 nmkey.nVKey = (UINT)wParam;
5553 nmkey.uFlags = HIWORD(lParam);
5555 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5556 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5558 switch ((UINT)wParam)
5562 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5566 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5570 if ((infoPtr->nHotItem >= 0) &&
5571 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5573 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5574 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5585 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5590 pt.x = (INT)LOWORD(lParam);
5591 pt.y = (INT)HIWORD(lParam);
5592 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5595 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5596 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5597 TOOLBAR_Customize (hwnd);
5604 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5607 TBUTTON_INFO *btnPtr;
5612 BOOL bDragKeyPressed;
5616 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5617 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5619 bDragKeyPressed = (wParam & MK_SHIFT);
5621 if (infoPtr->hwndToolTip)
5622 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5623 WM_LBUTTONDOWN, wParam, lParam);
5625 pt.x = (INT)LOWORD(lParam);
5626 pt.y = (INT)HIWORD(lParam);
5627 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5629 btnPtr = &infoPtr->buttons[nHit];
5631 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5633 infoPtr->nButtonDrag = nHit;
5636 /* If drag cursor has not been loaded, load it.
5637 * Note: it doesn't need to be freed */
5639 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5640 SetCursor(hCursorDrag);
5645 infoPtr->nOldHit = nHit;
5647 CopyRect(&arrowRect, &btnPtr->rect);
5648 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5650 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5651 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5652 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5653 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5654 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5655 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5659 /* draw in pressed state */
5660 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5661 btnPtr->fsState |= TBSTATE_PRESSED;
5663 btnPtr->bDropDownPressed = TRUE;
5664 RedrawWindow(hwnd,&btnPtr->rect,0,
5665 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5667 memset(&nmtb, 0, sizeof(nmtb));
5668 nmtb.iItem = btnPtr->idCommand;
5669 nmtb.rcButton = btnPtr->rect;
5670 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5672 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5674 if (res != TBDDRET_TREATPRESSED)
5678 /* redraw button in unpressed state */
5679 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5680 btnPtr->fsState &= ~TBSTATE_PRESSED;
5682 btnPtr->bDropDownPressed = FALSE;
5683 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5685 /* find and set hot item
5686 * NOTE: native doesn't do this, but that is a bug */
5688 ScreenToClient(hwnd, &pt);
5689 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5690 if (!infoPtr->bAnchor || (nHit >= 0))
5691 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5693 /* remove any left mouse button down or double-click messages
5694 * so that we can get a toggle effect on the button */
5695 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5696 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5701 /* otherwise drop through and process as pushed */
5703 infoPtr->bCaptured = TRUE;
5704 infoPtr->nButtonDown = nHit;
5705 infoPtr->bDragOutSent = FALSE;
5707 btnPtr->fsState |= TBSTATE_PRESSED;
5709 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5711 if (btnPtr->fsState & TBSTATE_ENABLED)
5712 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5719 memset(&nmtb, 0, sizeof(nmtb));
5720 nmtb.iItem = btnPtr->idCommand;
5721 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5724 nmmouse.dwHitInfo = nHit;
5726 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5728 nmmouse.dwItemSpec = -1;
5731 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5732 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5735 ClientToScreen(hwnd, &pt);
5738 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5739 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5745 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5748 TBUTTON_INFO *btnPtr;
5752 BOOL bSendMessage = TRUE;
5757 if (infoPtr->hwndToolTip)
5758 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5759 WM_LBUTTONUP, wParam, lParam);
5761 pt.x = (INT)LOWORD(lParam);
5762 pt.y = (INT)HIWORD(lParam);
5763 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5765 if (!infoPtr->bAnchor || (nHit >= 0))
5766 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5768 if (infoPtr->nButtonDrag >= 0) {
5772 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5775 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5777 GetClientRect(hwnd, &rcClient);
5778 if (PtInRect(&rcClient, pt))
5785 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5788 if (nButton == infoPtr->nButtonDrag)
5790 /* if the button is moved sightly left and we have a
5791 * separator there then remove it */
5792 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5794 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5795 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5797 else /* else insert a separator before the dragged button */
5800 memset(&tbb, 0, sizeof(tbb));
5801 tbb.fsStyle = BTNS_SEP;
5803 TOOLBAR_InsertButtonT(hwnd, nButton, (LPARAM)&tbb, TRUE);
5810 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5811 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5813 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5816 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5821 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5822 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5825 /* button under cursor changed so need to re-set hot item */
5826 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5827 infoPtr->nButtonDrag = -1;
5829 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5831 else if (infoPtr->nButtonDown >= 0) {
5832 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5833 btnPtr->fsState &= ~TBSTATE_PRESSED;
5835 if (btnPtr->fsStyle & BTNS_CHECK) {
5836 if (btnPtr->fsStyle & BTNS_GROUP) {
5837 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5839 if (nOldIndex == nHit)
5840 bSendMessage = FALSE;
5841 if ((nOldIndex != nHit) &&
5843 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5844 btnPtr->fsState |= TBSTATE_CHECKED;
5847 if (btnPtr->fsState & TBSTATE_CHECKED)
5848 btnPtr->fsState &= ~TBSTATE_CHECKED;
5850 btnPtr->fsState |= TBSTATE_CHECKED;
5854 if (nOldIndex != -1)
5855 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5858 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5859 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5860 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5862 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5864 infoPtr->nButtonDown = -1;
5866 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5867 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5868 NM_RELEASEDCAPTURE);
5870 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5873 memset(&nmtb, 0, sizeof(nmtb));
5874 nmtb.iItem = btnPtr->idCommand;
5875 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5878 if (btnPtr->fsState & TBSTATE_ENABLED)
5880 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5881 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
5885 /* !!! Undocumented - toolbar at 4.71 level and above sends
5886 * NM_CLICK with the NMMOUSE structure. */
5887 nmmouse.dwHitInfo = nHit;
5890 nmmouse.dwItemSpec = -1;
5893 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5894 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5897 ClientToScreen(hwnd, &pt);
5900 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5901 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5907 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5914 pt.x = LOWORD(lParam);
5915 pt.y = HIWORD(lParam);
5917 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5918 nmmouse.dwHitInfo = nHit;
5921 nmmouse.dwItemSpec = -1;
5923 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5924 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5927 ClientToScreen(hwnd, &pt);
5930 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5931 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5937 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5939 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5942 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5943 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5949 TOOLBAR_CaptureChanged(HWND hwnd)
5951 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5952 TBUTTON_INFO *btnPtr;
5954 infoPtr->bCaptured = FALSE;
5956 if (infoPtr->nButtonDown >= 0)
5958 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5959 btnPtr->fsState &= ~TBSTATE_PRESSED;
5961 infoPtr->nOldHit = -1;
5963 if (btnPtr->fsState & TBSTATE_ENABLED)
5964 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5970 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5972 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5973 TBUTTON_INFO *hotBtnPtr;
5975 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5977 /* don't remove hot effects when in anchor highlighting mode or when a
5978 * drop-down button is pressed */
5979 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
5980 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5982 if (infoPtr->nOldHit < 0)
5985 /* If the last button we were over is depressed then make it not */
5986 /* depressed and redraw it */
5987 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5989 TBUTTON_INFO *btnPtr;
5992 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5994 btnPtr->fsState &= ~TBSTATE_PRESSED;
5996 rc1 = hotBtnPtr->rect;
5997 InflateRect (&rc1, 1, 1);
5998 InvalidateRect (hwnd, &rc1, TRUE);
6001 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6004 ZeroMemory(&nmt, sizeof(nmt));
6005 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6006 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6007 infoPtr->bDragOutSent = TRUE;
6010 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6016 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6020 TRACKMOUSEEVENT trackinfo;
6022 TBUTTON_INFO *btnPtr;
6024 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
6025 TOOLBAR_TooltipCreateControl(infoPtr);
6027 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6028 /* fill in the TRACKMOUSEEVENT struct */
6029 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6030 trackinfo.dwFlags = TME_QUERY;
6032 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6033 _TrackMouseEvent(&trackinfo);
6035 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6036 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6037 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6038 trackinfo.hwndTrack = hwnd;
6040 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6041 /* and can properly deactivate the hot toolbar button */
6042 _TrackMouseEvent(&trackinfo);
6046 if (infoPtr->hwndToolTip)
6047 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6048 WM_MOUSEMOVE, wParam, lParam);
6050 pt.x = (INT)LOWORD(lParam);
6051 pt.y = (INT)HIWORD(lParam);
6053 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6055 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6056 && (!infoPtr->bAnchor || (nHit >= 0)))
6057 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6059 if (infoPtr->nOldHit != nHit)
6061 if (infoPtr->bCaptured)
6063 if (!infoPtr->bDragOutSent)
6066 ZeroMemory(&nmt, sizeof(nmt));
6067 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6068 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6069 infoPtr->bDragOutSent = TRUE;
6072 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6073 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6074 btnPtr->fsState &= ~TBSTATE_PRESSED;
6075 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6077 else if (nHit == infoPtr->nButtonDown) {
6078 btnPtr->fsState |= TBSTATE_PRESSED;
6079 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6081 infoPtr->nOldHit = nHit;
6089 inline static LRESULT
6090 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6092 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6093 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6095 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6099 inline static LRESULT
6100 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6102 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6103 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6105 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6110 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6112 TOOLBAR_INFO *infoPtr;
6113 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6116 /* allocate memory for info structure */
6117 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6118 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6121 infoPtr->dwStructSize = sizeof(TBBUTTON);
6123 infoPtr->nWidth = 0;
6125 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6126 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6127 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6128 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6131 /* native control does:
6132 * Get a lot of colors and brushes
6134 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6135 * CreateFontIndirectW(adr1)
6136 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6137 * hdc = GetDC(toolbar)
6138 * GetSystemMetrics(0x48)
6139 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6140 * 0, 0, 0, 0, "MARLETT")
6141 * oldfnt = SelectObject(hdc, fnt2)
6142 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6143 * GetTextMetricsW(hdc, adr3)
6144 * SelectObject(hdc, oldfnt)
6145 * DeleteObject(fnt2)
6147 * InvalidateRect(toolbar, 0, 1)
6148 * SetWindowLongW(toolbar, 0, addr)
6149 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6152 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6153 * ie 2 0x4600094c 0x4600094c 0x4600894d
6154 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6155 * rebar 0x50008844 0x40008844 0x50008845
6156 * pager 0x50000844 0x40000844 0x50008845
6157 * IC35mgr 0x5400084e **nochange**
6158 * on entry to _NCCREATE 0x5400084e
6159 * rowlist 0x5400004e **nochange**
6160 * on entry to _NCCREATE 0x5400004e
6164 /* I think the code below is a bug, but it is the way that the native
6165 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6166 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6167 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6168 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6169 * Somehow, the only cases of this seem to be MFC programs.
6171 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6172 * does not occur in the WM_STYLECHANGING routine.
6173 * (Guy Albertelli 9/2001)
6176 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6177 && !(cs->style & TBSTYLE_TRANSPARENT))
6178 styleadd |= TBSTYLE_TRANSPARENT;
6179 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6180 styleadd |= CCS_TOP; /* default to top */
6181 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6184 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6189 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6191 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6195 if (dwStyle & WS_MINIMIZE)
6196 return 0; /* Nothing to do */
6198 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6200 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6203 if (!(dwStyle & CCS_NODIVIDER))
6205 GetWindowRect (hwnd, &rcWindow);
6206 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6207 if( dwStyle & WS_BORDER )
6208 OffsetRect (&rcWindow, 1, 1);
6209 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6212 ReleaseDC( hwnd, hdc );
6218 /* handles requests from the tooltip control on what text to display */
6219 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6221 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6223 TRACE("button index = %d\n", index);
6225 Free (infoPtr->pszTooltipText);
6226 infoPtr->pszTooltipText = NULL;
6231 if (infoPtr->bUnicode)
6233 WCHAR wszBuffer[INFOTIPSIZE+1];
6234 NMTBGETINFOTIPW tbgit;
6235 unsigned int len; /* in chars */
6237 wszBuffer[0] = '\0';
6238 wszBuffer[INFOTIPSIZE] = '\0';
6240 tbgit.pszText = wszBuffer;
6241 tbgit.cchTextMax = INFOTIPSIZE;
6242 tbgit.iItem = lpnmtdi->hdr.idFrom;
6243 tbgit.lParam = infoPtr->buttons[index].dwData;
6245 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6247 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6249 len = strlenW(tbgit.pszText);
6250 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6252 /* need to allocate temporary buffer in infoPtr as there
6253 * isn't enough space in buffer passed to us by the
6254 * tooltip control */
6255 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6256 if (infoPtr->pszTooltipText)
6258 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6259 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6265 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6271 CHAR szBuffer[INFOTIPSIZE+1];
6272 NMTBGETINFOTIPA tbgit;
6273 unsigned int len; /* in chars */
6276 szBuffer[INFOTIPSIZE] = '\0';
6278 tbgit.pszText = szBuffer;
6279 tbgit.cchTextMax = INFOTIPSIZE;
6280 tbgit.iItem = lpnmtdi->hdr.idFrom;
6281 tbgit.lParam = infoPtr->buttons[index].dwData;
6283 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6285 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6287 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6288 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6290 /* need to allocate temporary buffer in infoPtr as there
6291 * isn't enough space in buffer passed to us by the
6292 * tooltip control */
6293 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6294 if (infoPtr->pszTooltipText)
6296 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6297 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6303 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6304 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6309 /* if button has text, but it is not shown then automatically
6310 * use that text as tooltip */
6311 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6312 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6314 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6315 unsigned int len = pszText ? strlenW(pszText) : 0;
6317 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6319 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6321 /* need to allocate temporary buffer in infoPtr as there
6322 * isn't enough space in buffer passed to us by the
6323 * tooltip control */
6324 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6325 if (infoPtr->pszTooltipText)
6327 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6328 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6334 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6339 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6341 /* last resort: send notification on to app */
6342 /* FIXME: find out what is really used here */
6343 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6347 inline static LRESULT
6348 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6351 LPNMHDR lpnmh = (LPNMHDR)lParam;
6353 switch (lpnmh->code)
6357 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6359 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6360 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6361 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6365 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6366 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6374 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6376 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6377 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6378 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6379 lppgs->iScroll, lppgs->iDir);
6383 case TTN_GETDISPINFOW:
6384 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6386 case TTN_GETDISPINFOA:
6387 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6397 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6401 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6403 if (lParam == NF_QUERY)
6406 if (lParam == NF_REQUERY) {
6407 format = SendMessageW(infoPtr->hwndNotify,
6408 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6409 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6410 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6421 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6427 /* fill ps.rcPaint with a default rect */
6428 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6430 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6432 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6433 ps.rcPaint.left, ps.rcPaint.top,
6434 ps.rcPaint.right, ps.rcPaint.bottom);
6436 TOOLBAR_Refresh (hwnd, hdc, &ps);
6437 if (!wParam) EndPaint (hwnd, &ps);
6444 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6446 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6448 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6450 /* make first item hot */
6451 if (infoPtr->nNumButtons > 0)
6452 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6459 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6460 /*****************************************************
6463 * Handles the WM_SETREDRAW message.
6466 * According to testing V4.71 of COMCTL32 returns the
6467 * *previous* status of the redraw flag (either 0 or 1)
6468 * instead of the MSDN documented value of 0 if handled.
6469 * (For laughs see the "consistency" with same function
6472 *****************************************************/
6474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6475 BOOL oldredraw = infoPtr->bDoRedraw;
6477 TRACE("set to %s\n",
6478 (wParam) ? "TRUE" : "FALSE");
6479 infoPtr->bDoRedraw = (BOOL) wParam;
6481 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6483 return (oldredraw) ? 1 : 0;
6488 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6492 TRACE("sizing toolbar!\n");
6494 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6496 RECT delta_width, delta_height, client, dummy;
6497 DWORD min_x, max_x, min_y, max_y;
6498 TBUTTON_INFO *btnPtr;
6501 GetClientRect(hwnd, &client);
6502 if(client.right > infoPtr->client_rect.right)
6504 min_x = infoPtr->client_rect.right;
6505 max_x = client.right;
6509 max_x = infoPtr->client_rect.right;
6510 min_x = client.right;
6512 if(client.bottom > infoPtr->client_rect.bottom)
6514 min_y = infoPtr->client_rect.bottom;
6515 max_y = client.bottom;
6519 max_y = infoPtr->client_rect.bottom;
6520 min_y = client.bottom;
6523 SetRect(&delta_width, min_x, 0, max_x, min_y);
6524 SetRect(&delta_height, 0, min_y, max_x, max_y);
6526 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6527 btnPtr = infoPtr->buttons;
6528 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6529 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6530 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6531 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6533 GetClientRect(hwnd, &infoPtr->client_rect);
6534 TOOLBAR_AutoSize(hwnd);
6540 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6544 if (nType == GWL_STYLE)
6546 DWORD dwOldStyle = infoPtr->dwStyle;
6548 if (lpStyle->styleNew & TBSTYLE_LIST)
6549 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6551 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6553 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6555 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6557 infoPtr->dwStyle = lpStyle->styleNew;
6559 /* only resize if one of the CCS_* styles was changed */
6560 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6562 TOOLBAR_AutoSize (hwnd);
6564 InvalidateRect(hwnd, NULL, TRUE);
6573 TOOLBAR_SysColorChange (HWND hwnd)
6575 COMCTL32_RefreshSysColors();
6581 /* update theme after a WM_THEMECHANGED message */
6582 static LRESULT theme_changed (HWND hwnd)
6584 HTHEME theme = GetWindowTheme (hwnd);
6585 CloseThemeData (theme);
6586 OpenThemeData (hwnd, themeClass);
6591 static LRESULT WINAPI
6592 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6594 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6596 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6597 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6599 if (!infoPtr && (uMsg != WM_NCCREATE))
6600 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6605 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6607 case TB_ADDBUTTONSA:
6608 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, FALSE);
6610 case TB_ADDBUTTONSW:
6611 return TOOLBAR_AddButtonsT(hwnd, wParam, lParam, TRUE);
6614 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6617 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6620 return TOOLBAR_AutoSize (hwnd);
6622 case TB_BUTTONCOUNT:
6623 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6625 case TB_BUTTONSTRUCTSIZE:
6626 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6628 case TB_CHANGEBITMAP:
6629 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6631 case TB_CHECKBUTTON:
6632 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6634 case TB_COMMANDTOINDEX:
6635 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6638 return TOOLBAR_Customize (hwnd);
6640 case TB_DELETEBUTTON:
6641 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6643 case TB_ENABLEBUTTON:
6644 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6646 case TB_GETANCHORHIGHLIGHT:
6647 return TOOLBAR_GetAnchorHighlight (hwnd);
6650 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6652 case TB_GETBITMAPFLAGS:
6653 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6656 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6658 case TB_GETBUTTONINFOA:
6659 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6661 case TB_GETBUTTONINFOW:
6662 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6664 case TB_GETBUTTONSIZE:
6665 return TOOLBAR_GetButtonSize (hwnd);
6667 case TB_GETBUTTONTEXTA:
6668 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6670 case TB_GETBUTTONTEXTW:
6671 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6673 case TB_GETDISABLEDIMAGELIST:
6674 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6676 case TB_GETEXTENDEDSTYLE:
6677 return TOOLBAR_GetExtendedStyle (hwnd);
6679 case TB_GETHOTIMAGELIST:
6680 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6683 return TOOLBAR_GetHotItem (hwnd);
6685 case TB_GETIMAGELIST:
6686 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6688 case TB_GETINSERTMARK:
6689 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6691 case TB_GETINSERTMARKCOLOR:
6692 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6694 case TB_GETITEMRECT:
6695 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6698 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6700 /* case TB_GETOBJECT: */ /* 4.71 */
6703 return TOOLBAR_GetPadding (hwnd);
6706 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6709 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6712 return TOOLBAR_GetState (hwnd, wParam, lParam);
6715 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6718 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6721 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6723 case TB_GETTEXTROWS:
6724 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6726 case TB_GETTOOLTIPS:
6727 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6729 case TB_GETUNICODEFORMAT:
6730 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6733 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6736 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6738 case TB_INDETERMINATE:
6739 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6741 case TB_INSERTBUTTONA:
6742 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, FALSE);
6744 case TB_INSERTBUTTONW:
6745 return TOOLBAR_InsertButtonT(hwnd, wParam, lParam, TRUE);
6747 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6749 case TB_ISBUTTONCHECKED:
6750 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6752 case TB_ISBUTTONENABLED:
6753 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6755 case TB_ISBUTTONHIDDEN:
6756 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6758 case TB_ISBUTTONHIGHLIGHTED:
6759 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6761 case TB_ISBUTTONINDETERMINATE:
6762 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6764 case TB_ISBUTTONPRESSED:
6765 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6768 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6770 case TB_MAPACCELERATORA:
6771 case TB_MAPACCELERATORW:
6772 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6775 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6778 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6780 case TB_PRESSBUTTON:
6781 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6783 case TB_REPLACEBITMAP:
6784 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6786 case TB_SAVERESTOREA:
6787 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6789 case TB_SAVERESTOREW:
6790 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6792 case TB_SETANCHORHIGHLIGHT:
6793 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6795 case TB_SETBITMAPSIZE:
6796 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6798 case TB_SETBUTTONINFOA:
6799 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6801 case TB_SETBUTTONINFOW:
6802 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6804 case TB_SETBUTTONSIZE:
6805 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6807 case TB_SETBUTTONWIDTH:
6808 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6811 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6813 case TB_SETDISABLEDIMAGELIST:
6814 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6816 case TB_SETDRAWTEXTFLAGS:
6817 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6819 case TB_SETEXTENDEDSTYLE:
6820 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6822 case TB_SETHOTIMAGELIST:
6823 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6826 return TOOLBAR_SetHotItem (hwnd, wParam);
6828 case TB_SETIMAGELIST:
6829 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6832 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6834 case TB_SETINSERTMARK:
6835 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6837 case TB_SETINSERTMARKCOLOR:
6838 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6840 case TB_SETMAXTEXTROWS:
6841 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6844 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6847 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6850 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6853 return TOOLBAR_SetState (hwnd, wParam, lParam);
6856 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6858 case TB_SETTOOLTIPS:
6859 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6861 case TB_SETUNICODEFORMAT:
6862 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6865 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6868 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6871 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6874 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6877 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6880 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6882 /* Common Control Messages */
6884 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6885 case CCM_GETCOLORSCHEME:
6886 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6888 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6889 case CCM_SETCOLORSCHEME:
6890 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6892 case CCM_GETVERSION:
6893 return TOOLBAR_GetVersion (hwnd);
6895 case CCM_SETVERSION:
6896 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6902 return TOOLBAR_Create (hwnd, wParam, lParam);
6905 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6908 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6911 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6914 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
6916 /* case WM_KILLFOCUS: */
6918 case WM_LBUTTONDBLCLK:
6919 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6921 case WM_LBUTTONDOWN:
6922 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6925 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6928 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6930 case WM_RBUTTONDBLCLK:
6931 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6934 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6937 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6939 case WM_CAPTURECHANGED:
6940 return TOOLBAR_CaptureChanged(hwnd);
6943 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6946 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6949 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6952 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6955 return TOOLBAR_Notify (hwnd, wParam, lParam);
6957 case WM_NOTIFYFORMAT:
6958 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6960 case WM_PRINTCLIENT:
6962 return TOOLBAR_Paint (hwnd, wParam);
6965 return TOOLBAR_SetFocus (hwnd, wParam);
6968 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6971 return TOOLBAR_Size (hwnd, wParam, lParam);
6973 case WM_STYLECHANGED:
6974 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6976 case WM_SYSCOLORCHANGE:
6977 return TOOLBAR_SysColorChange (hwnd);
6979 case WM_THEMECHANGED:
6980 return theme_changed (hwnd);
6982 /* case WM_WININICHANGE: */
6987 case WM_MEASUREITEM:
6989 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6991 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6992 case PGM_FORWARDMOUSE:
6993 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6996 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6997 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6998 uMsg, wParam, lParam);
6999 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7005 TOOLBAR_Register (void)
7009 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7010 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7011 wndClass.lpfnWndProc = ToolbarWindowProc;
7012 wndClass.cbClsExtra = 0;
7013 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7014 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7015 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7016 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7018 RegisterClassW (&wndClass);
7023 TOOLBAR_Unregister (void)
7025 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7028 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7033 /* Check if the entry already exists */
7034 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7036 /* If this is a new entry we must create it and insert into the array */
7041 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7044 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7045 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7060 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7064 for (i = 0; i < *cies; i++)
7074 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7082 for (i = 0; i < cies; i++)
7084 if (pies[i]->id == id)
7096 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7098 HIMAGELIST himlDef = 0;
7099 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7102 himlDef = pie->himl;
7108 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7110 if (infoPtr->bUnicode)
7111 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7118 nmtba.iItem = nmtb->iItem;
7119 nmtba.pszText = Buffer;
7120 nmtba.cchText = 256;
7121 ZeroMemory(nmtba.pszText, nmtba.cchText);
7123 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7125 int ccht = strlen(nmtba.pszText);
7127 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7128 nmtb->pszText, nmtb->cchText);
7130 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7139 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7140 int iItem, PCUSTOMBUTTON btnInfo)
7144 /* MSDN states that iItem is the index of the button, rather than the
7145 * command ID as used by every other NMTOOLBAR notification */
7147 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7149 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);