4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
38 * - TB_INSERTMARKHITTEST
46 * - Button wrapping (under construction).
48 * - iListGap custom draw support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
79 #include "wine/unicode.h"
85 #include "wine/debug.h"
87 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
89 static HCURSOR hCursorDrag = NULL;
98 BYTE bDropDownPressed;
103 INT cx; /* manually set size */
117 } IMLENTRY, *PIMLENTRY;
121 DWORD dwStructSize; /* size of TBBUTTON struct */
122 INT nWidth; /* width of the toolbar */
124 RECT rcBound; /* bounding rectangle */
130 INT nRows; /* number of button rows */
131 INT nMaxTextRows; /* maximum number of text rows */
132 INT cxMin; /* minimum button width */
133 INT cxMax; /* maximum button width */
134 INT nNumButtons; /* number of buttons */
135 INT nNumBitmaps; /* number of bitmaps */
136 INT nNumStrings; /* number of strings */
138 INT nButtonDown; /* toolbar button being pressed or -1 if none */
139 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
141 INT nHotItem; /* index of the "hot" item */
142 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
143 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
144 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
145 SIZE szPadding; /* padding values around button */
146 INT iListGap; /* default gap between text and image for toolbar with list style */
148 HFONT hFont; /* text font */
149 HIMAGELIST himlInt; /* image list created internally */
150 PIMLENTRY *himlDef; /* default image list array */
151 INT cimlDef; /* default image list array count */
152 PIMLENTRY *himlHot; /* hot image list array */
153 INT cimlHot; /* hot image list array count */
154 PIMLENTRY *himlDis; /* disabled image list array */
155 INT cimlDis; /* disabled image list array count */
156 HWND hwndToolTip; /* handle to tool tip control */
157 HWND hwndNotify; /* handle to the window that gets notifications */
158 HWND hwndSelf; /* my own handle */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bDoRedraw; /* Redraw status */
161 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
162 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
163 BOOL bCaptured; /* mouse captured? */
164 DWORD dwStyle; /* regular toolbar style */
165 DWORD dwExStyle; /* extended toolbar style */
166 DWORD dwDTFlags; /* DrawText flags */
168 COLORREF clrInsertMark; /* insert mark color */
169 COLORREF clrBtnHighlight; /* color for Flat Separator */
170 COLORREF clrBtnShadow; /* color for Flag Separator */
172 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
173 * for TTN_GETDISPINFOW notification */
174 TBINSERTMARK tbim; /* info on insertion mark */
175 TBUTTON_INFO *buttons; /* pointer to button array */
176 LPWSTR *strings; /* pointer to string array */
177 TBITMAP_INFO *bitmaps;
178 } TOOLBAR_INFO, *PTOOLBAR_INFO;
181 /* used by customization dialog */
184 PTOOLBAR_INFO tbInfo;
186 } CUSTDLG_INFO, *PCUSTDLG_INFO;
194 } CUSTOMBUTTON, *PCUSTOMBUTTON;
203 #define SEPARATOR_WIDTH 8
205 #define BOTTOM_BORDER 2
206 #define DDARROW_WIDTH 11
207 #define ARROW_HEIGHT 3
208 #define INSERTMARK_WIDTH 2
214 /* vertical padding used in list mode when image is present */
217 /* how wide to treat the bitmap if it isn't present */
218 #define NONLIST_NOTEXT_OFFSET 2
220 #define TOOLBAR_NOWHERE (-1)
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 /* Used to find undocumented extended styles */
227 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
228 TBSTYLE_EX_UNDOC1 | \
229 TBSTYLE_EX_MIXEDBUTTONS | \
230 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
232 /* all of the CCS_ styles */
233 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
234 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
236 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
237 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
238 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
239 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
240 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
242 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
252 static LRESULT TOOLBAR_AutoSize(HWND hwnd);
253 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
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 HTHEME theme = GetWindowTheme (hwnd);
826 CopyRect (&rcArrow, &rc);
828 /* get a pointer to the text */
829 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
831 if (hasDropDownArrow)
835 if (dwStyle & TBSTYLE_FLAT)
836 right = max(rc.left, rc.right - DDARROW_WIDTH);
838 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
840 if (drawSepDropDownArrow)
843 rcArrow.left = right;
846 /* copy text & bitmap rects after adjusting for drop-down arrow
847 * so that text & bitmap is centred in the rectangle not containing
849 CopyRect(&rcText, &rc);
850 CopyRect(&rcBitmap, &rc);
852 /* Center the bitmap horizontally and vertically */
853 if (dwStyle & TBSTYLE_LIST)
856 infoPtr->nMaxTextRows > 0 &&
857 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
858 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
859 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
861 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
864 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
866 rcBitmap.top += infoPtr->szPadding.cy / 2;
868 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
869 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
870 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
871 TRACE("Text=%s\n", debugstr_w(lpText));
872 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
874 /* calculate text position */
877 rcText.left += GetSystemMetrics(SM_CXEDGE);
878 rcText.right -= GetSystemMetrics(SM_CXEDGE);
879 if (dwStyle & TBSTYLE_LIST)
881 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
882 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
886 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
887 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
889 rcText.top += infoPtr->szPadding.cy/2 + 2;
893 /* Initialize fields in all cases, because we use these later
894 * NOTE: applications can and do alter these to customize their
896 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
897 tbcd.clrText = comctl32_color.clrBtnText;
898 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
899 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
900 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
901 tbcd.clrMark = comctl32_color.clrHighlight;
902 tbcd.clrHighlightHotTrack = 0;
903 tbcd.nStringBkMode = TRANSPARENT;
904 tbcd.nHLStringBkMode = OPAQUE;
905 /* MSDN says that this is the text rectangle.
906 * But (why always a but) tracing of v5.7 of native shows
907 * that this is really a *relative* rectangle based on the
908 * the nmcd.rc. Also the left and top are always 0 ignoring
909 * any bitmap that might be present. */
910 tbcd.rcText.left = 0;
912 tbcd.rcText.right = rcText.right - rc.left;
913 tbcd.rcText.bottom = rcText.bottom - rc.top;
914 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
917 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
919 /* FIXME: what are these used for? */
923 /* Issue Item Prepaint notify */
924 infoPtr->dwItemCustDraw = 0;
925 infoPtr->dwItemCDFlag = 0;
926 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
928 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
929 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
930 tbcd.nmcd.lItemlParam = btnPtr->dwData;
931 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
932 /* reset these fields so the user can't alter the behaviour like native */
936 infoPtr->dwItemCustDraw = ntfret & 0xffff;
937 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
938 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
940 /* save the only part of the rect that the user can change */
941 rcText.right = tbcd.rcText.right + rc.left;
942 rcText.bottom = tbcd.rcText.bottom + rc.top;
946 if (btnPtr->fsStyle & BTNS_SEP) {
949 DrawThemeBackground (theme, hdc,
950 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
951 &tbcd.nmcd.rc, NULL);
954 /* with the FLAT style, iBitmap is the width and has already */
955 /* been taken into consideration in calculating the width */
956 /* so now we need to draw the vertical separator */
957 /* empirical tests show that iBitmap can/will be non-zero */
958 /* when drawing the vertical bar... */
959 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
960 if (btnPtr->fsStyle & BTNS_DROPDOWN)
961 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
963 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
965 else if (btnPtr->fsStyle != BTNS_SEP) {
966 FIXME("Draw some kind of separator: fsStyle=%x\n",
972 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
973 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
974 OffsetRect(&rcText, 1, 1);
976 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
977 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
978 TOOLBAR_DrawPattern (&rc, &tbcd);
980 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
981 && (tbcd.nmcd.uItemState & CDIS_HOT))
983 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
987 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
988 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
989 if (hasDropDownArrow)
990 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
991 SetBkColor(hdc, oldclr);
997 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
998 int stateId = TS_NORMAL;
1000 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1001 stateId = TS_DISABLED;
1002 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1003 stateId = TS_PRESSED;
1004 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1005 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1006 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1007 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1010 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1013 TOOLBAR_DrawFrame(infoPtr, &tbcd);
1015 if (drawSepDropDownArrow)
1019 int stateId = TS_NORMAL;
1021 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1022 stateId = TS_DISABLED;
1023 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1024 stateId = TS_PRESSED;
1025 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1026 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1027 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1030 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1031 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1034 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1037 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1038 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1039 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1040 SetBkMode (hdc, oldBkMode);
1042 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1044 if (hasDropDownArrow && !drawSepDropDownArrow)
1046 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1048 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1051 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1053 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1054 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1061 if (infoPtr->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 /* Set the toolTip only for non-hidden, non-separator button */
1730 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1734 ZeroMemory (&ti, sizeof(ti));
1735 ti.cbSize = sizeof(ti);
1737 ti.uId = btnPtr->idCommand;
1738 ti.rect = btnPtr->rect;
1739 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1743 /* btnPtr->nRow is zero based. The space between the rows is */
1744 /* also considered as a row. */
1745 btnPtr->nRow = nRows + nSepRows;
1747 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1748 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1753 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1757 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1758 /* it is the actual width of the separator. This is used for */
1759 /* custom controls in toolbars. */
1760 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1761 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1762 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1766 /* nSepRows is used to calculate the extra height follwoing */
1770 x = infoPtr->nIndent;
1772 /* Increment row number unless this is the last button */
1773 /* and it has Wrap set. */
1774 if (i != infoPtr->nNumButtons-1)
1781 /* infoPtr->nRows is the number of rows on the toolbar */
1782 infoPtr->nRows = nRows + nSepRows + 1;
1784 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1789 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1792 TBUTTON_INFO *btnPtr;
1795 btnPtr = infoPtr->buttons;
1796 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1797 if (btnPtr->fsState & TBSTATE_HIDDEN)
1800 if (btnPtr->fsStyle & BTNS_SEP) {
1801 if (PtInRect (&btnPtr->rect, *lpPt)) {
1802 TRACE(" ON SEPARATOR %d!\n", i);
1807 if (PtInRect (&btnPtr->rect, *lpPt)) {
1808 TRACE(" ON BUTTON %d!\n", i);
1814 TRACE(" NOWHERE!\n");
1815 return TOOLBAR_NOWHERE;
1820 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1822 TBUTTON_INFO *btnPtr;
1825 if (CommandIsIndex) {
1826 TRACE("command is really index command=%d\n", idCommand);
1827 if (idCommand >= infoPtr->nNumButtons) return -1;
1830 btnPtr = infoPtr->buttons;
1831 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1832 if (btnPtr->idCommand == idCommand) {
1833 TRACE("command=%d index=%d\n", idCommand, i);
1837 TRACE("no index found for command=%d\n", idCommand);
1843 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1845 TBUTTON_INFO *btnPtr;
1848 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1851 /* check index button */
1852 btnPtr = &infoPtr->buttons[nIndex];
1853 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1854 if (btnPtr->fsState & TBSTATE_CHECKED)
1858 /* check previous buttons */
1859 nRunIndex = nIndex - 1;
1860 while (nRunIndex >= 0) {
1861 btnPtr = &infoPtr->buttons[nRunIndex];
1862 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1863 if (btnPtr->fsState & TBSTATE_CHECKED)
1871 /* check next buttons */
1872 nRunIndex = nIndex + 1;
1873 while (nRunIndex < infoPtr->nNumButtons) {
1874 btnPtr = &infoPtr->buttons[nRunIndex];
1875 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1876 if (btnPtr->fsState & TBSTATE_CHECKED)
1889 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1890 WPARAM wParam, LPARAM lParam)
1896 msg.wParam = wParam;
1897 msg.lParam = lParam;
1898 msg.time = GetMessageTime ();
1899 msg.pt.x = LOWORD(GetMessagePos ());
1900 msg.pt.y = HIWORD(GetMessagePos ());
1902 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1905 /* keeps available button list box sorted by button id */
1906 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1910 PCUSTOMBUTTON btnInfo;
1911 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1913 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1915 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1917 /* position 0 is always separator */
1918 for (i = 1; i < count; i++)
1920 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1921 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1923 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1924 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1928 /* id higher than all others add to end */
1929 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1930 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1933 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1937 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1939 if (nIndexFrom == nIndexTo)
1942 /* MSDN states that iItem is the index of the button, rather than the
1943 * command ID as used by every other NMTOOLBAR notification */
1944 nmtb.iItem = nIndexFrom;
1945 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1947 PCUSTOMBUTTON btnInfo;
1949 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1950 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1952 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1954 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1955 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1956 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1957 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1960 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1962 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1964 /* last item is always separator, so -2 instead of -1 */
1965 if (nIndexTo >= (count - 2))
1966 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1968 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1970 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1971 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1973 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1977 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1981 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1983 /* MSDN states that iItem is the index of the button, rather than the
1984 * command ID as used by every other NMTOOLBAR notification */
1985 nmtb.iItem = nIndexAvail;
1986 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1988 PCUSTOMBUTTON btnInfo;
1990 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1991 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1992 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1994 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1996 if (nIndexAvail != 0) /* index == 0 indicates separator */
1998 /* remove from 'available buttons' list */
1999 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2000 if (nIndexAvail == count-1)
2001 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2003 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2007 PCUSTOMBUTTON btnNew;
2009 /* duplicate 'separator' button */
2010 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2011 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2015 /* insert into 'toolbar button' list */
2016 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2017 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2019 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2021 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2025 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
2027 PCUSTOMBUTTON btnInfo;
2028 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2030 TRACE("Remove: index %d\n", index);
2032 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2034 /* send TBN_QUERYDELETE notification */
2035 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2039 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2040 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2042 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2044 /* insert into 'available button' list */
2045 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2046 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2050 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2054 /* drag list notification function for toolbar buttons list box */
2055 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2057 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2058 switch (pDLI->uNotification)
2062 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2063 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2064 /* no dragging for last item (separator) */
2065 if (nCurrentItem >= (nCount - 1)) return FALSE;
2070 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2071 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2072 /* no dragging past last item (separator) */
2073 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2075 DrawInsert(hwnd, hwndList, nCurrentItem);
2076 /* FIXME: native uses "move button" cursor */
2077 return DL_COPYCURSOR;
2080 /* not over toolbar buttons list */
2081 if (nCurrentItem < 0)
2083 POINT ptWindow = pDLI->ptCursor;
2084 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2085 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2086 /* over available buttons list? */
2087 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2088 /* FIXME: native uses "move button" cursor */
2089 return DL_COPYCURSOR;
2091 /* clear drag arrow */
2092 DrawInsert(hwnd, hwndList, -1);
2093 return DL_STOPCURSOR;
2097 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2098 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2099 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2100 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2102 /* clear drag arrow */
2103 DrawInsert(hwnd, hwndList, -1);
2105 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2107 /* not over toolbar buttons list */
2110 POINT ptWindow = pDLI->ptCursor;
2111 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2112 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2113 /* over available buttons list? */
2114 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2115 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2120 /* Clear drag arrow */
2121 DrawInsert(hwnd, hwndList, -1);
2128 /* drag list notification function for available buttons list box */
2129 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2131 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2132 switch (pDLI->uNotification)
2138 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2139 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2140 /* no dragging past last item (separator) */
2141 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2143 DrawInsert(hwnd, hwndList, nCurrentItem);
2144 /* FIXME: native uses "move button" cursor */
2145 return DL_COPYCURSOR;
2148 /* not over toolbar buttons list */
2149 if (nCurrentItem < 0)
2151 POINT ptWindow = pDLI->ptCursor;
2152 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2153 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2154 /* over available buttons list? */
2155 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2156 /* FIXME: native uses "move button" cursor */
2157 return DL_COPYCURSOR;
2159 /* clear drag arrow */
2160 DrawInsert(hwnd, hwndList, -1);
2161 return DL_STOPCURSOR;
2165 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2166 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2167 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2168 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2170 /* clear drag arrow */
2171 DrawInsert(hwnd, hwndList, -1);
2173 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2177 /* Clear drag arrow */
2178 DrawInsert(hwnd, hwndList, -1);
2184 extern UINT uDragListMessage;
2186 /***********************************************************************
2187 * TOOLBAR_CustomizeDialogProc
2188 * This function implements the toolbar customization dialog.
2190 static INT_PTR CALLBACK
2191 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2193 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2194 PCUSTOMBUTTON btnInfo;
2196 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2201 custInfo = (PCUSTDLG_INFO)lParam;
2202 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2209 NMTBINITCUSTOMIZE nmtbic;
2211 infoPtr = custInfo->tbInfo;
2213 /* send TBN_QUERYINSERT notification */
2214 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2216 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2219 nmtbic.hwndDialog = hwnd;
2220 /* Send TBN_INITCUSTOMIZE notification */
2221 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2224 TRACE("TBNRF_HIDEHELP requested\n");
2225 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2228 /* add items to 'toolbar buttons' list and check if removable */
2229 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2231 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2232 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2233 btnInfo->btn.fsStyle = BTNS_SEP;
2234 btnInfo->bVirtual = FALSE;
2235 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2237 /* send TBN_QUERYDELETE notification */
2238 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2240 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2241 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2244 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2246 /* insert separator button into 'available buttons' list */
2247 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2248 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2249 btnInfo->btn.fsStyle = BTNS_SEP;
2250 btnInfo->bVirtual = FALSE;
2251 btnInfo->bRemovable = TRUE;
2252 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2253 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2254 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2256 /* insert all buttons into dsa */
2259 /* send TBN_GETBUTTONINFO notification */
2262 nmtb.pszText = Buffer;
2265 /* Clear previous button's text */
2266 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2268 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2271 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2272 nmtb.tbButton.fsStyle, i,
2273 nmtb.tbButton.idCommand,
2274 nmtb.tbButton.iString,
2275 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2278 /* insert button into the apropriate list */
2279 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2282 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2283 btnInfo->bVirtual = FALSE;
2284 btnInfo->bRemovable = TRUE;
2288 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2289 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2292 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2293 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2295 if (lstrlenW(nmtb.pszText))
2296 lstrcpyW(btnInfo->text, nmtb.pszText);
2297 else if (nmtb.tbButton.iString >= 0 &&
2298 nmtb.tbButton.iString < infoPtr->nNumStrings)
2300 lstrcpyW(btnInfo->text,
2301 infoPtr->strings[nmtb.tbButton.iString]);
2306 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2309 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2311 /* select first item in the 'available' list */
2312 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2314 /* append 'virtual' separator button to the 'toolbar buttons' list */
2315 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2316 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2317 btnInfo->btn.fsStyle = BTNS_SEP;
2318 btnInfo->bVirtual = TRUE;
2319 btnInfo->bRemovable = FALSE;
2320 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2321 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2322 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2324 /* select last item in the 'toolbar' list */
2325 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2326 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2328 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2329 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2331 /* set focus and disable buttons */
2332 PostMessageW (hwnd, WM_USER, 0, 0);
2337 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2338 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2339 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2340 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2344 EndDialog(hwnd, FALSE);
2348 switch (LOWORD(wParam))
2350 case IDC_TOOLBARBTN_LBOX:
2351 if (HIWORD(wParam) == LBN_SELCHANGE)
2353 PCUSTOMBUTTON btnInfo;
2358 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2359 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2361 /* send TBN_QUERYINSERT notification */
2363 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2365 /* get list box item */
2366 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2368 if (index == (count - 1))
2370 /* last item (virtual separator) */
2371 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2372 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2374 else if (index == (count - 2))
2376 /* second last item (last non-virtual item) */
2377 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2378 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2380 else if (index == 0)
2383 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2384 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2388 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2389 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2392 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2396 case IDC_MOVEUP_BTN:
2398 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2399 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2403 case IDC_MOVEDN_BTN: /* move down */
2405 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2406 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2410 case IDC_REMOVE_BTN: /* remove button */
2412 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2414 if (LB_ERR == index)
2417 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2421 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2424 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2427 case IDOK: /* Add button */
2432 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2433 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2435 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2440 EndDialog(hwnd, FALSE);
2450 /* delete items from 'toolbar buttons' listbox*/
2451 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2452 for (i = 0; i < count; i++)
2454 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2456 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2458 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2461 /* delete items from 'available buttons' listbox*/
2462 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2463 for (i = 0; i < count; i++)
2465 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2467 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2469 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2474 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2476 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2481 COLORREF oldText = 0;
2485 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2486 if (btnInfo == NULL)
2488 FIXME("btnInfo invalid!\n");
2492 /* set colors and select objects */
2493 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2494 if (btnInfo->bVirtual)
2495 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2497 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2498 hPen = CreatePen( PS_SOLID, 1,
2499 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2500 hOldPen = SelectObject (lpdis->hDC, hPen );
2501 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2503 /* fill background rectangle */
2504 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2505 lpdis->rcItem.right, lpdis->rcItem.bottom);
2507 /* calculate button and text rectangles */
2508 CopyRect (&rcButton, &lpdis->rcItem);
2509 InflateRect (&rcButton, -1, -1);
2510 CopyRect (&rcText, &rcButton);
2511 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2512 rcText.left = rcButton.right + 2;
2514 /* draw focus rectangle */
2515 if (lpdis->itemState & ODS_FOCUS)
2516 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2519 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2520 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2522 /* draw image and text */
2523 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2524 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2525 btnInfo->btn.iBitmap));
2526 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2527 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2529 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2530 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2532 /* delete objects and reset colors */
2533 SelectObject (lpdis->hDC, hOldBrush);
2534 SelectObject (lpdis->hDC, hOldPen);
2535 SetBkColor (lpdis->hDC, oldBk);
2536 SetTextColor (lpdis->hDC, oldText);
2537 DeleteObject( hPen );
2542 case WM_MEASUREITEM:
2543 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2545 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2547 lpmis->itemHeight = 15 + 8; /* default height */
2554 if (uDragListMessage && (uMsg == uDragListMessage))
2556 if (wParam == IDC_TOOLBARBTN_LBOX)
2558 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2559 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2560 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2563 else if (wParam == IDC_AVAILBTN_LBOX)
2565 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2566 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2567 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2576 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2579 INT nCountBefore = ImageList_GetImageCount(himlDef);
2585 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2586 /* Add bitmaps to the default image list */
2587 if (bitmap->hInst == NULL) /* a handle was passed */
2590 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2591 HDC hdcImage, hdcBitmap;
2593 /* copy the bitmap before adding it so that the user's bitmap
2594 * doesn't get modified.
2596 GetObjectW ((HBITMAP)bitmap->nID, sizeof(BITMAP), (LPVOID)&bmp);
2598 hdcImage = CreateCompatibleDC(0);
2599 hdcBitmap = CreateCompatibleDC(0);
2601 /* create new bitmap */
2602 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2603 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)bitmap->nID);
2604 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2606 /* Copy the user's image */
2607 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2608 hdcBitmap, 0, 0, SRCCOPY);
2610 SelectObject (hdcImage, hOldBitmapLoad);
2611 SelectObject (hdcBitmap, hOldBitmapBitmap);
2612 DeleteDC (hdcImage);
2613 DeleteDC (hdcBitmap);
2616 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2618 /* enlarge the bitmap if needed */
2619 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2620 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2622 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2623 DeleteObject(hbmLoad);
2627 nCountAfter = ImageList_GetImageCount(himlDef);
2628 nAdded = nCountAfter - nCountBefore;
2629 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2631 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2632 } else if (nAdded > (INT)bitmap->nButtons) {
2633 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2634 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2637 infoPtr->nNumBitmaps += nAdded;
2642 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2649 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2650 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2652 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2654 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2657 TRACE("Update icon size: %dx%d -> %dx%d\n",
2658 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2660 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2661 ILC_COLORDDB|ILC_MASK, 8, 2);
2662 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2663 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2664 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2665 infoPtr->himlInt = himlNew;
2667 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2668 ImageList_Destroy(himlDef);
2671 /***********************************************************************
2672 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2676 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2679 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2684 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2688 if (lpAddBmp->hInst == HINST_COMMCTRL)
2690 info.hInst = COMCTL32_hModule;
2691 switch (lpAddBmp->nID)
2693 case IDB_STD_SMALL_COLOR:
2695 info.nID = IDB_STD_SMALL;
2697 case IDB_STD_LARGE_COLOR:
2699 info.nID = IDB_STD_LARGE;
2701 case IDB_VIEW_SMALL_COLOR:
2703 info.nID = IDB_VIEW_SMALL;
2705 case IDB_VIEW_LARGE_COLOR:
2707 info.nID = IDB_VIEW_LARGE;
2709 case IDB_HIST_SMALL_COLOR:
2711 info.nID = IDB_HIST_SMALL;
2713 case IDB_HIST_LARGE_COLOR:
2715 info.nID = IDB_HIST_LARGE;
2721 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2723 /* Windows resize all the buttons to the size of a newly added standard image */
2724 if (lpAddBmp->nID & 1)
2727 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2728 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2730 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2731 MAKELPARAM((WORD)24, (WORD)24));
2732 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2733 MAKELPARAM((WORD)31, (WORD)30));
2738 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2739 MAKELPARAM((WORD)16, (WORD)16));
2740 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2741 MAKELPARAM((WORD)22, (WORD)22));
2744 TOOLBAR_CalcToolbar (hwnd);
2748 info.nButtons = (INT)wParam;
2749 info.hInst = lpAddBmp->hInst;
2750 info.nID = lpAddBmp->nID;
2751 TRACE("adding %d bitmaps!\n", info.nButtons);
2754 /* check if the bitmap is already loaded and compute iSumButtons */
2756 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2758 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2759 infoPtr->bitmaps[i].nID == info.nID)
2761 iSumButtons += infoPtr->bitmaps[i].nButtons;
2764 if (!infoPtr->cimlDef) {
2765 /* create new default image list */
2766 TRACE ("creating default image list!\n");
2768 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2769 ILC_COLORDDB | ILC_MASK, info.nButtons, 2);
2770 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2771 infoPtr->himlInt = himlDef;
2774 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2778 WARN("No default image list available\n");
2782 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2785 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2786 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2787 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2788 infoPtr->nNumBitmapInfos++;
2789 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2791 InvalidateRect(hwnd, NULL, TRUE);
2797 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2801 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2803 TRACE("adding %d buttons!\n", wParam);
2805 nAddButtons = (UINT)wParam;
2806 nOldButtons = infoPtr->nNumButtons;
2807 nNewButtons = nOldButtons + nAddButtons;
2809 if (infoPtr->nNumButtons == 0) {
2811 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2814 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2816 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2817 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2818 nOldButtons * sizeof(TBUTTON_INFO));
2822 infoPtr->nNumButtons = nNewButtons;
2824 /* insert new button data */
2825 for (nCount = 0; nCount < nAddButtons; nCount++) {
2826 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2827 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2828 btnPtr->idCommand = lpTbb[nCount].idCommand;
2829 btnPtr->fsState = lpTbb[nCount].fsState;
2830 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2831 btnPtr->dwData = lpTbb[nCount].dwData;
2832 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2833 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2835 btnPtr->iString = lpTbb[nCount].iString;
2836 btnPtr->bHot = FALSE;
2838 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2841 ZeroMemory (&ti, sizeof(ti));
2842 ti.cbSize = sizeof(ti);
2844 ti.uId = btnPtr->idCommand;
2846 ti.lpszText = LPSTR_TEXTCALLBACKW;
2848 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2853 TOOLBAR_CalcToolbar (hwnd);
2854 TOOLBAR_AutoSize (hwnd);
2856 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2858 InvalidateRect(hwnd, NULL, TRUE);
2865 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2868 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2869 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2871 TRACE("adding %d buttons!\n", wParam);
2873 nAddButtons = (UINT)wParam;
2874 nOldButtons = infoPtr->nNumButtons;
2875 nNewButtons = nOldButtons + nAddButtons;
2877 if (infoPtr->nNumButtons == 0) {
2879 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2882 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2884 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2885 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2886 nOldButtons * sizeof(TBUTTON_INFO));
2890 infoPtr->nNumButtons = nNewButtons;
2892 /* insert new button data */
2893 for (nCount = 0; nCount < nAddButtons; nCount++) {
2894 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2895 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2896 btnPtr->idCommand = lpTbb[nCount].idCommand;
2897 btnPtr->fsState = lpTbb[nCount].fsState;
2898 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2899 btnPtr->dwData = lpTbb[nCount].dwData;
2900 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2901 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2903 btnPtr->iString = lpTbb[nCount].iString;
2904 btnPtr->bHot = FALSE;
2906 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2909 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2910 ti.cbSize = sizeof (TTTOOLINFOW);
2912 ti.uId = btnPtr->idCommand;
2914 ti.lpszText = LPSTR_TEXTCALLBACKW;
2917 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2922 TOOLBAR_CalcToolbar (hwnd);
2923 TOOLBAR_AutoSize (hwnd);
2925 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2927 InvalidateRect(hwnd, NULL, TRUE);
2934 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2936 #define MAX_RESOURCE_STRING_LENGTH 512
2937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2938 INT nIndex = infoPtr->nNumStrings;
2940 if ((wParam) && (HIWORD(lParam) == 0)) {
2941 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2946 TRACE("adding string from resource!\n");
2948 LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2949 szString, MAX_RESOURCE_STRING_LENGTH);
2950 len = lstrlenW(szString);
2952 TRACE("len=%d %s\n", len, debugstr_w(szString));
2953 if (len == 0 || len == 1)
2956 TRACE("Delimiter: 0x%x\n", *szString);
2957 delimiter = *szString;
2959 if (szString[len-1] == delimiter)
2960 szString[len-1] = 0;
2962 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2965 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2966 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2967 infoPtr->nNumStrings++;
2973 LPWSTR p = (LPWSTR)lParam;
2978 TRACE("adding string(s) from array!\n");
2982 TRACE("len=%d %s\n", len, debugstr_w(p));
2983 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2984 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2985 infoPtr->nNumStrings++;
2996 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2998 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3003 if ((wParam) && (HIWORD(lParam) == 0)) /* load from resources */
3004 return TOOLBAR_AddStringW(hwnd, wParam, lParam);
3010 TRACE("adding string(s) from array!\n");
3011 nIndex = infoPtr->nNumStrings;
3014 TRACE("len=%d \"%s\"\n", len, p);
3016 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3017 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3018 infoPtr->nNumStrings++;
3028 TOOLBAR_AutoSize (HWND hwnd)
3030 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3036 TRACE("auto sizing, style=%lx!\n", infoPtr->dwStyle);
3038 parent = GetParent (hwnd);
3040 if (!parent || !infoPtr->bDoRedraw)
3043 GetClientRect(parent, &parent_rect);
3045 x = parent_rect.left;
3046 y = parent_rect.top;
3048 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3050 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3051 cx = parent_rect.right - parent_rect.left;
3053 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
3055 TOOLBAR_CalcToolbar(hwnd);
3056 InvalidateRect( hwnd, NULL, TRUE );
3059 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3062 UINT uPosFlags = SWP_NOZORDER;
3064 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3066 GetWindowRect(hwnd, &window_rect);
3067 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3068 y = window_rect.top;
3070 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3072 GetWindowRect(hwnd, &window_rect);
3073 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3076 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3077 uPosFlags |= SWP_NOMOVE;
3079 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3080 cy += GetSystemMetrics(SM_CYEDGE);
3082 if (infoPtr->dwStyle & WS_BORDER)
3084 x = y = 1; /* FIXME: this looks wrong */
3085 cy += GetSystemMetrics(SM_CYEDGE);
3086 cx += GetSystemMetrics(SM_CXEDGE);
3089 SetWindowPos(hwnd, NULL, x, y, cx, cy, uPosFlags);
3097 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3099 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3101 return infoPtr->nNumButtons;
3106 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3110 infoPtr->dwStructSize = (DWORD)wParam;
3117 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3120 TBUTTON_INFO *btnPtr;
3123 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3125 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3129 btnPtr = &infoPtr->buttons[nIndex];
3130 btnPtr->iBitmap = LOWORD(lParam);
3132 /* we HAVE to erase the background, the new bitmap could be */
3134 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3141 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3144 TBUTTON_INFO *btnPtr;
3147 BOOL bChecked = FALSE;
3149 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3151 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3156 btnPtr = &infoPtr->buttons[nIndex];
3158 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3160 if (LOWORD(lParam) == FALSE)
3161 btnPtr->fsState &= ~TBSTATE_CHECKED;
3163 if (btnPtr->fsStyle & BTNS_GROUP) {
3165 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3166 if (nOldIndex == nIndex)
3168 if (nOldIndex != -1)
3169 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3171 btnPtr->fsState |= TBSTATE_CHECKED;
3174 if( bChecked != LOWORD(lParam) )
3176 if (nOldIndex != -1)
3177 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3178 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3181 /* FIXME: Send a WM_NOTIFY?? */
3188 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3192 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3197 TOOLBAR_Customize (HWND hwnd)
3199 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3200 CUSTDLG_INFO custInfo;
3206 custInfo.tbInfo = infoPtr;
3207 custInfo.tbHwnd = hwnd;
3209 /* send TBN_BEGINADJUST notification */
3210 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3212 if (!(hRes = FindResourceW (COMCTL32_hModule,
3213 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3214 (LPWSTR)RT_DIALOG)))
3217 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3220 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3221 (LPCDLGTEMPLATEW)template,
3223 TOOLBAR_CustomizeDialogProc,
3226 /* send TBN_ENDADJUST notification */
3227 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3234 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3237 INT nIndex = (INT)wParam;
3239 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3241 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3244 memset(&nmtb, 0, sizeof(nmtb));
3245 nmtb.iItem = btnPtr->idCommand;
3246 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3247 nmtb.tbButton.idCommand = btnPtr->idCommand;
3248 nmtb.tbButton.fsState = btnPtr->fsState;
3249 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3250 nmtb.tbButton.dwData = btnPtr->dwData;
3251 nmtb.tbButton.iString = btnPtr->iString;
3252 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3254 if ((infoPtr->hwndToolTip) &&
3255 !(btnPtr->fsStyle & BTNS_SEP)) {
3258 ZeroMemory (&ti, sizeof(ti));
3259 ti.cbSize = sizeof(ti);
3261 ti.uId = infoPtr->buttons[nIndex].idCommand;
3263 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3266 if (infoPtr->nNumButtons == 1) {
3267 TRACE(" simple delete!\n");
3268 Free (infoPtr->buttons);
3269 infoPtr->buttons = NULL;
3270 infoPtr->nNumButtons = 0;
3273 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3274 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3276 infoPtr->nNumButtons--;
3277 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3279 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3280 nIndex * sizeof(TBUTTON_INFO));
3283 if (nIndex < infoPtr->nNumButtons) {
3284 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3285 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3291 TOOLBAR_CalcToolbar (hwnd);
3293 InvalidateRect (hwnd, NULL, TRUE);
3300 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 TBUTTON_INFO *btnPtr;
3307 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3309 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3314 btnPtr = &infoPtr->buttons[nIndex];
3316 bState = btnPtr->fsState & TBSTATE_ENABLED;
3318 /* update the toolbar button state */
3319 if(LOWORD(lParam) == FALSE) {
3320 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3322 btnPtr->fsState |= TBSTATE_ENABLED;
3325 /* redraw the button only if the state of the button changed */
3326 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3327 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3333 static inline LRESULT
3334 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3336 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3338 return infoPtr->bAnchor;
3343 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3345 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3348 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3352 return infoPtr->buttons[nIndex].iBitmap;
3356 static inline LRESULT
3357 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3359 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3364 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3366 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3367 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3368 INT nIndex = (INT)wParam;
3369 TBUTTON_INFO *btnPtr;
3374 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3377 btnPtr = &infoPtr->buttons[nIndex];
3378 lpTbb->iBitmap = btnPtr->iBitmap;
3379 lpTbb->idCommand = btnPtr->idCommand;
3380 lpTbb->fsState = btnPtr->fsState;
3381 lpTbb->fsStyle = btnPtr->fsStyle;
3382 lpTbb->bReserved[0] = 0;
3383 lpTbb->bReserved[1] = 0;
3384 lpTbb->dwData = btnPtr->dwData;
3385 lpTbb->iString = btnPtr->iString;
3392 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3394 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3395 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3396 TBUTTON_INFO *btnPtr;
3399 if (lpTbInfo == NULL)
3401 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3404 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3405 lpTbInfo->dwMask & 0x80000000);
3409 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3411 if (lpTbInfo->dwMask & TBIF_COMMAND)
3412 lpTbInfo->idCommand = btnPtr->idCommand;
3413 if (lpTbInfo->dwMask & TBIF_IMAGE)
3414 lpTbInfo->iImage = btnPtr->iBitmap;
3415 if (lpTbInfo->dwMask & TBIF_LPARAM)
3416 lpTbInfo->lParam = btnPtr->dwData;
3417 if (lpTbInfo->dwMask & TBIF_SIZE)
3418 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3419 if (lpTbInfo->dwMask & TBIF_STATE)
3420 lpTbInfo->fsState = btnPtr->fsState;
3421 if (lpTbInfo->dwMask & TBIF_STYLE)
3422 lpTbInfo->fsStyle = btnPtr->fsStyle;
3423 if (lpTbInfo->dwMask & TBIF_TEXT) {
3424 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3425 can't use TOOLBAR_GetText here */
3427 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3428 lpText = (LPWSTR)btnPtr->iString;
3429 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3431 lpTbInfo->pszText[0] = '\0';
3438 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3441 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3442 TBUTTON_INFO *btnPtr;
3445 if (lpTbInfo == NULL)
3447 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3450 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3451 lpTbInfo->dwMask & 0x80000000);
3455 btnPtr = &infoPtr->buttons[nIndex];
3460 if (lpTbInfo->dwMask & TBIF_COMMAND)
3461 lpTbInfo->idCommand = btnPtr->idCommand;
3462 if (lpTbInfo->dwMask & TBIF_IMAGE)
3463 lpTbInfo->iImage = btnPtr->iBitmap;
3464 if (lpTbInfo->dwMask & TBIF_LPARAM)
3465 lpTbInfo->lParam = btnPtr->dwData;
3466 if (lpTbInfo->dwMask & TBIF_SIZE)
3467 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3468 if (lpTbInfo->dwMask & TBIF_STATE)
3469 lpTbInfo->fsState = btnPtr->fsState;
3470 if (lpTbInfo->dwMask & TBIF_STYLE)
3471 lpTbInfo->fsStyle = btnPtr->fsStyle;
3472 if (lpTbInfo->dwMask & TBIF_TEXT) {
3473 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3474 can't use TOOLBAR_GetText here */
3476 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3477 lpText = (LPWSTR)btnPtr->iString;
3478 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3480 lpTbInfo->pszText[0] = '\0';
3488 TOOLBAR_GetButtonSize (HWND hwnd)
3490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3492 if (infoPtr->nNumButtons > 0)
3493 return MAKELONG((WORD)infoPtr->nButtonWidth,
3494 (WORD)infoPtr->nButtonHeight);
3496 return MAKELONG(23,22);
3501 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3510 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3514 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3516 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3517 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3522 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3524 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3529 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3533 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3537 ret = strlenW (lpText);
3540 strcpyW ((LPWSTR)lParam, lpText);
3548 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3550 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3551 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3552 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3556 inline static LRESULT
3557 TOOLBAR_GetExtendedStyle (HWND hwnd)
3559 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3563 return infoPtr->dwExStyle;
3568 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3570 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3571 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3572 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3577 TOOLBAR_GetHotItem (HWND hwnd)
3579 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3581 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3584 if (infoPtr->nHotItem < 0)
3587 return (LRESULT)infoPtr->nHotItem;
3592 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3594 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3595 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3596 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3601 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3604 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3606 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3608 *lptbim = infoPtr->tbim;
3615 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3619 TRACE("hwnd = %p\n", hwnd);
3621 return (LRESULT)infoPtr->clrInsertMark;
3626 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3628 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3629 TBUTTON_INFO *btnPtr;
3633 nIndex = (INT)wParam;
3634 btnPtr = &infoPtr->buttons[nIndex];
3635 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3637 lpRect = (LPRECT)lParam;
3640 if (btnPtr->fsState & TBSTATE_HIDDEN)
3643 lpRect->left = btnPtr->rect.left;
3644 lpRect->right = btnPtr->rect.right;
3645 lpRect->bottom = btnPtr->rect.bottom;
3646 lpRect->top = btnPtr->rect.top;
3653 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3656 LPSIZE lpSize = (LPSIZE)lParam;
3661 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3662 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3664 TRACE("maximum size %ld x %ld\n",
3665 infoPtr->rcBound.right - infoPtr->rcBound.left,
3666 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3672 /* << TOOLBAR_GetObject >> */
3676 TOOLBAR_GetPadding (HWND hwnd)
3678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3681 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3682 return (LRESULT) oldPad;
3687 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3689 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3690 TBUTTON_INFO *btnPtr;
3694 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3695 btnPtr = &infoPtr->buttons[nIndex];
3696 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3698 lpRect = (LPRECT)lParam;
3702 lpRect->left = btnPtr->rect.left;
3703 lpRect->right = btnPtr->rect.right;
3704 lpRect->bottom = btnPtr->rect.bottom;
3705 lpRect->top = btnPtr->rect.top;
3712 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3714 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3716 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3717 return infoPtr->nRows;
3724 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3726 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3733 return infoPtr->buttons[nIndex].fsState;
3738 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3740 return GetWindowLongW(hwnd, GWL_STYLE);
3745 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3749 return infoPtr->nMaxTextRows;
3754 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3758 return (LRESULT)infoPtr->hwndToolTip;
3763 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3765 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3767 TRACE("%s hwnd=%p\n",
3768 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3770 return infoPtr->bUnicode;
3774 inline static LRESULT
3775 TOOLBAR_GetVersion (HWND hwnd)
3777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3778 return infoPtr->iVersion;
3783 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3785 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3786 TBUTTON_INFO *btnPtr;
3791 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3795 btnPtr = &infoPtr->buttons[nIndex];
3796 if (LOWORD(lParam) == FALSE)
3797 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3799 btnPtr->fsState |= TBSTATE_HIDDEN;
3801 TOOLBAR_CalcToolbar (hwnd);
3803 InvalidateRect (hwnd, NULL, TRUE);
3809 inline static LRESULT
3810 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3812 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3817 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3820 TBUTTON_INFO *btnPtr;
3824 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3828 btnPtr = &infoPtr->buttons[nIndex];
3829 oldState = btnPtr->fsState;
3830 if (LOWORD(lParam) == FALSE)
3831 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3833 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3835 if(oldState != btnPtr->fsState)
3836 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3843 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3845 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3846 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3847 INT nIndex = (INT)wParam;
3848 TBUTTON_INFO *oldButtons;
3853 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3856 /* EPP: this seems to be an undocumented call (from my IE4)
3857 * I assume in that case that:
3858 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3859 * - index of insertion is at the end of existing buttons
3860 * I only see this happen with nIndex == -1, but it could have a special
3861 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3863 nIndex = infoPtr->nNumButtons;
3865 } else if (nIndex < 0)
3868 /* If the string passed is not an index, assume address of string
3869 and do our own AddString */
3870 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3874 TRACE("string %s passed instead of index, adding string\n",
3875 debugstr_a((LPSTR)lpTbb->iString));
3876 len = strlen((LPSTR)lpTbb->iString) + 2;
3878 strcpy(ptr, (LPSTR)lpTbb->iString);
3879 ptr[len - 1] = 0; /* ended by two '\0' */
3880 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3884 TRACE("inserting button index=%d\n", nIndex);
3885 if (nIndex > infoPtr->nNumButtons) {
3886 nIndex = infoPtr->nNumButtons;
3887 TRACE("adjust index=%d\n", nIndex);
3890 oldButtons = infoPtr->buttons;
3891 infoPtr->nNumButtons++;
3892 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3893 /* pre insert copy */
3895 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3896 nIndex * sizeof(TBUTTON_INFO));
3899 /* insert new button */
3900 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3901 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3902 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3903 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3904 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3905 /* if passed string and not index, then add string */
3906 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3907 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3910 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3912 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3915 ZeroMemory (&ti, sizeof(ti));
3916 ti.cbSize = sizeof (ti);
3918 ti.uId = lpTbb->idCommand;
3920 ti.lpszText = LPSTR_TEXTCALLBACKW;
3922 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3926 /* post insert copy */
3927 if (nIndex < infoPtr->nNumButtons - 1) {
3928 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3929 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3934 TOOLBAR_CalcToolbar (hwnd);
3935 TOOLBAR_AutoSize (hwnd);
3937 InvalidateRect (hwnd, NULL, TRUE);
3944 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3947 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3948 INT nIndex = (INT)wParam;
3949 TBUTTON_INFO *oldButtons;
3954 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3957 /* EPP: this seems to be an undocumented call (from my IE4)
3958 * I assume in that case that:
3959 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3960 * - index of insertion is at the end of existing buttons
3961 * I only see this happen with nIndex == -1, but it could have a special
3962 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3964 nIndex = infoPtr->nNumButtons;
3966 } else if (nIndex < 0)
3969 /* If the string passed is not an index, assume address of string
3970 and do our own AddString */
3971 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3975 TRACE("string %s passed instead of index, adding string\n",
3976 debugstr_w((LPWSTR)lpTbb->iString));
3977 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3978 ptr = Alloc(len*sizeof(WCHAR));
3979 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3980 ptr[len - 1] = 0; /* ended by two '\0' */
3981 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3985 TRACE("inserting button index=%d\n", nIndex);
3986 if (nIndex > infoPtr->nNumButtons) {
3987 nIndex = infoPtr->nNumButtons;
3988 TRACE("adjust index=%d\n", nIndex);
3991 oldButtons = infoPtr->buttons;
3992 infoPtr->nNumButtons++;
3993 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3994 /* pre insert copy */
3996 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3997 nIndex * sizeof(TBUTTON_INFO));
4000 /* insert new button */
4001 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4002 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4003 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4004 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4005 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4006 /* if passed string and not index, then add string */
4007 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4008 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4011 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4013 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4016 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4017 ti.cbSize = sizeof (TTTOOLINFOW);
4019 ti.uId = lpTbb->idCommand;
4021 ti.lpszText = LPSTR_TEXTCALLBACKW;
4023 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4027 /* post insert copy */
4028 if (nIndex < infoPtr->nNumButtons - 1) {
4029 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4030 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4035 TOOLBAR_CalcToolbar (hwnd);
4036 TOOLBAR_AutoSize (hwnd);
4038 InvalidateRect (hwnd, NULL, TRUE);
4044 /* << TOOLBAR_InsertMarkHitTest >> */
4048 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4050 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4053 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4057 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4062 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4067 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4071 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4076 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4081 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4085 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4090 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4092 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4095 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4099 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4104 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4109 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4113 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4118 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4123 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4127 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4132 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4135 tbab.hInst = (HINSTANCE)lParam;
4136 tbab.nID = (UINT_PTR)wParam;
4138 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4140 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4145 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4148 WCHAR wAccel = (WCHAR)wParam;
4149 UINT* pIDButton = (UINT*)lParam;
4150 WCHAR wszAccel[] = {'&',wAccel,0};
4153 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4154 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4156 for (i = 0; i < infoPtr->nNumButtons; i++)
4158 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4159 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4160 !(btnPtr->fsState & TBSTATE_HIDDEN))
4162 int iLen = strlenW(wszAccel);
4163 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4170 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4175 if (!strncmpiW(lpszStr, wszAccel, iLen))
4177 *pIDButton = btnPtr->idCommand;
4189 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4194 TBUTTON_INFO *btnPtr;
4196 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4198 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4202 btnPtr = &infoPtr->buttons[nIndex];
4203 oldState = btnPtr->fsState;
4206 btnPtr->fsState |= TBSTATE_MARKED;
4208 btnPtr->fsState &= ~TBSTATE_MARKED;
4210 if(oldState != btnPtr->fsState)
4211 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4217 /* fixes up an index of a button affected by a move */
4218 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4222 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4224 else if (*pIndex == nIndex)
4225 *pIndex = nMoveIndex;
4229 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4231 else if (*pIndex == nIndex)
4232 *pIndex = nMoveIndex;
4238 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4243 INT nMoveIndex = (INT)lParam;
4244 TBUTTON_INFO button;
4246 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4248 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4249 if ((nIndex == -1) || (nMoveIndex < 0))
4252 if (nMoveIndex > infoPtr->nNumButtons - 1)
4253 nMoveIndex = infoPtr->nNumButtons - 1;
4255 button = infoPtr->buttons[nIndex];
4257 /* move button right */
4258 if (nIndex < nMoveIndex)
4260 nCount = nMoveIndex - nIndex;
4261 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4262 infoPtr->buttons[nMoveIndex] = button;
4264 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4265 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4266 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4267 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4269 else if (nIndex > nMoveIndex) /* move button left */
4271 nCount = nIndex - nMoveIndex;
4272 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4273 infoPtr->buttons[nMoveIndex] = button;
4275 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4276 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4277 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4278 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4281 TOOLBAR_CalcToolbar(hwnd);
4282 TOOLBAR_AutoSize(hwnd);
4283 InvalidateRect(hwnd, NULL, TRUE);
4290 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4293 TBUTTON_INFO *btnPtr;
4297 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4301 btnPtr = &infoPtr->buttons[nIndex];
4302 oldState = btnPtr->fsState;
4303 if (LOWORD(lParam) == FALSE)
4304 btnPtr->fsState &= ~TBSTATE_PRESSED;
4306 btnPtr->fsState |= TBSTATE_PRESSED;
4308 if(oldState != btnPtr->fsState)
4309 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4314 /* FIXME: there might still be some confusion her between number of buttons
4315 * and number of bitmaps */
4317 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4319 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4320 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4322 HBITMAP hbmLoad = NULL;
4323 int i = 0, nOldButtons = 0, pos = 0;
4324 int nOldBitmaps, nNewBitmaps = 0;
4325 HIMAGELIST himlDef = 0;
4327 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4328 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4329 lpReplace->nButtons);
4331 if (lpReplace->hInstOld == HINST_COMMCTRL)
4333 FIXME("changing standard bitmaps not implemented\n");
4336 else if (lpReplace->hInstOld != 0)
4337 FIXME("resources not in the current module not implemented\n");
4339 if (lpReplace->hInstNew)
4341 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4346 hBitmap = (HBITMAP) lpReplace->nIDNew;
4349 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4350 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4351 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4352 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4353 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4355 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4356 nOldButtons = tbi->nButtons;
4357 tbi->nButtons = lpReplace->nButtons;
4358 tbi->hInst = lpReplace->hInstNew;
4359 tbi->nID = lpReplace->nIDNew;
4360 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4363 pos += tbi->nButtons;
4366 if (nOldButtons == 0)
4368 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4370 DeleteObject (hbmLoad);
4374 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4375 nOldBitmaps = ImageList_GetImageCount(himlDef);
4377 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4379 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4380 ImageList_Remove(himlDef, i);
4385 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4386 HDC hdcImage, hdcBitmap;
4388 /* copy the bitmap before adding it so that the user's bitmap
4389 * doesn't get modified.
4391 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4393 hdcImage = CreateCompatibleDC(0);
4394 hdcBitmap = CreateCompatibleDC(0);
4396 /* create new bitmap */
4397 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4398 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4399 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4401 /* Copy the user's image */
4402 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4403 hdcBitmap, 0, 0, SRCCOPY);
4405 SelectObject (hdcImage, hOldBitmapLoad);
4406 SelectObject (hdcBitmap, hOldBitmapBitmap);
4407 DeleteDC (hdcImage);
4408 DeleteDC (hdcBitmap);
4410 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4411 nNewBitmaps = ImageList_GetImageCount(himlDef);
4412 DeleteObject (hbmLoad);
4415 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4417 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4418 pos, nOldBitmaps, nNewBitmaps);
4420 InvalidateRect(hwnd, NULL, TRUE);
4423 DeleteObject (hbmLoad);
4428 /* helper for TOOLBAR_SaveRestoreW */
4430 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4432 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4433 debugstr_w(lpSave->pszValueName));
4439 /* helper for TOOLBAR_Restore */
4441 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4446 ZeroMemory(&ti, sizeof(ti));
4447 ti.cbSize = sizeof(ti);
4448 ti.hwnd = infoPtr->hwndSelf;
4450 for (i = 0; i < infoPtr->nNumButtons; i++)
4452 if ((infoPtr->hwndToolTip) &&
4453 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4455 ti.uId = infoPtr->buttons[i].idCommand;
4456 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4460 Free(infoPtr->buttons);
4461 infoPtr->buttons = NULL;
4462 infoPtr->nNumButtons = 0;
4466 /* helper for TOOLBAR_SaveRestoreW */
4468 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4477 /* restore toolbar information */
4478 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4479 debugstr_w(lpSave->pszValueName));
4481 memset(&nmtbr, 0, sizeof(nmtbr));
4483 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4484 KEY_QUERY_VALUE, &hkey);
4486 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4488 if (!res && dwType != REG_BINARY)
4489 res = ERROR_FILE_NOT_FOUND;
4492 nmtbr.pData = Alloc(dwSize);
4493 nmtbr.cbData = (UINT)dwSize;
4494 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4497 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4498 (LPBYTE)nmtbr.pData, &dwSize);
4501 nmtbr.pCurrent = nmtbr.pData;
4503 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4504 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4506 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4510 /* remove all existing buttons as this function is designed to
4511 * restore the toolbar to a previously saved state */
4512 TOOLBAR_DeleteAllButtons(infoPtr);
4514 for (i = 0; i < nmtbr.cButtons; i++)
4517 nmtbr.tbButton.iBitmap = -1;
4518 nmtbr.tbButton.fsState = 0;
4519 nmtbr.tbButton.fsStyle = 0;
4520 nmtbr.tbButton.idCommand = 0;
4521 if (*nmtbr.pCurrent == (DWORD)-1)
4524 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4525 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4527 else if (*nmtbr.pCurrent == (DWORD)-2)
4529 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4531 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4535 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4537 /* can't contain real string as we don't know whether
4538 * the client put an ANSI or Unicode string in there */
4539 if (HIWORD(nmtbr.tbButton.iString))
4540 nmtbr.tbButton.iString = 0;
4542 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4543 (LPARAM)&nmtbr.tbButton);
4546 /* do legacy notifications */
4547 if (infoPtr->iVersion < 5)
4549 /* FIXME: send TBN_BEGINADJUST */
4550 FIXME("send TBN_GETBUTTONINFO for each button\n");
4551 /* FIXME: send TBN_ENDADJUST */
4554 /* remove all uninitialised buttons
4555 * note: loop backwards to avoid having to fixup i on a
4557 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4558 if (infoPtr->buttons[i].iBitmap == -1)
4559 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4561 /* only indicate success if at least one button survived */
4562 if (infoPtr->nNumButtons > 0) ret = TRUE;
4573 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4575 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4577 if (lpSave == NULL) return 0;
4580 return TOOLBAR_Save(infoPtr, lpSave);
4582 return TOOLBAR_Restore(infoPtr, lpSave);
4587 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4589 LPWSTR pszValueName = 0, pszSubKey = 0;
4590 TBSAVEPARAMSW SaveW;
4594 if (lpSave == NULL) return 0;
4596 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4597 pszSubKey = Alloc(len * sizeof(WCHAR));
4598 if (pszSubKey) goto exit;
4599 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4601 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4602 pszValueName = Alloc(len * sizeof(WCHAR));
4603 if (!pszValueName) goto exit;
4604 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4606 SaveW.pszValueName = pszValueName;
4607 SaveW.pszSubKey = pszSubKey;
4608 SaveW.hkr = lpSave->hkr;
4609 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4612 Free (pszValueName);
4620 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4622 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4623 BOOL bOldAnchor = infoPtr->bAnchor;
4625 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4627 infoPtr->bAnchor = (BOOL)wParam;
4629 /* Native does not remove the hot effect from an already hot button */
4631 return (LRESULT)bOldAnchor;
4636 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4639 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4641 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4644 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4646 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4647 lParam = MAKELPARAM(16, 15);
4649 if (infoPtr->nNumButtons > 0)
4650 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4651 infoPtr->nNumButtons,
4652 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4653 LOWORD(lParam), HIWORD(lParam));
4655 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4656 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4659 if ((himlDef == infoPtr->himlInt) &&
4660 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4662 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4663 infoPtr->nBitmapHeight);
4666 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4672 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4674 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4675 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4676 TBUTTON_INFO *btnPtr;
4682 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4685 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4686 lptbbi->dwMask & 0x80000000);
4690 btnPtr = &infoPtr->buttons[nIndex];
4691 if (lptbbi->dwMask & TBIF_COMMAND)
4692 btnPtr->idCommand = lptbbi->idCommand;
4693 if (lptbbi->dwMask & TBIF_IMAGE)
4694 btnPtr->iBitmap = lptbbi->iImage;
4695 if (lptbbi->dwMask & TBIF_LPARAM)
4696 btnPtr->dwData = lptbbi->lParam;
4697 if (lptbbi->dwMask & TBIF_SIZE)
4698 btnPtr->cx = lptbbi->cx;
4699 if (lptbbi->dwMask & TBIF_STATE)
4700 btnPtr->fsState = lptbbi->fsState;
4701 if (lptbbi->dwMask & TBIF_STYLE)
4702 btnPtr->fsStyle = lptbbi->fsStyle;
4704 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4705 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4706 /* iString is index, zero it to make Str_SetPtr succeed */
4709 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4712 /* save the button rect to see if we need to redraw the whole toolbar */
4713 oldBtnRect = btnPtr->rect;
4714 TOOLBAR_CalcToolbar(hwnd);
4716 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4717 InvalidateRect(hwnd, NULL, TRUE);
4719 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4726 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4729 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4730 TBUTTON_INFO *btnPtr;
4736 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4739 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4740 lptbbi->dwMask & 0x80000000);
4744 btnPtr = &infoPtr->buttons[nIndex];
4745 if (lptbbi->dwMask & TBIF_COMMAND)
4746 btnPtr->idCommand = lptbbi->idCommand;
4747 if (lptbbi->dwMask & TBIF_IMAGE)
4748 btnPtr->iBitmap = lptbbi->iImage;
4749 if (lptbbi->dwMask & TBIF_LPARAM)
4750 btnPtr->dwData = lptbbi->lParam;
4751 if (lptbbi->dwMask & TBIF_SIZE)
4752 btnPtr->cx = lptbbi->cx;
4753 if (lptbbi->dwMask & TBIF_STATE)
4754 btnPtr->fsState = lptbbi->fsState;
4755 if (lptbbi->dwMask & TBIF_STYLE)
4756 btnPtr->fsStyle = lptbbi->fsStyle;
4758 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4759 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4760 /* iString is index, zero it to make Str_SetPtr succeed */
4762 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4765 /* save the button rect to see if we need to redraw the whole toolbar */
4766 oldBtnRect = btnPtr->rect;
4767 TOOLBAR_CalcToolbar(hwnd);
4769 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4770 InvalidateRect(hwnd, NULL, TRUE);
4772 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4779 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4781 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4782 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4784 if ((cx < 0) || (cy < 0))
4786 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4790 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4792 /* The documentation claims you can only change the button size before
4793 * any button has been added. But this is wrong.
4794 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4795 * it to the toolbar, and it checks that the return value is nonzero - mjm
4796 * Further testing shows that we must actually perform the change too.
4799 * The documentation also does not mention that if 0 is supplied for
4800 * either size, the system changes it to the default of 24 wide and
4801 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4803 infoPtr->nButtonWidth = (cx) ? cx : 24;
4804 infoPtr->nButtonHeight = (cy) ? cy : 22;
4810 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4812 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4814 /* if setting to current values, ignore */
4815 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4816 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4817 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4818 infoPtr->cxMin, infoPtr->cxMax);
4822 /* save new values */
4823 infoPtr->cxMin = (INT)LOWORD(lParam);
4824 infoPtr->cxMax = (INT)HIWORD(lParam);
4826 /* otherwise we need to recalc the toolbar and in some cases
4827 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4828 which doesn't actually draw - GA). */
4829 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4830 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4832 TOOLBAR_CalcToolbar (hwnd);
4834 InvalidateRect (hwnd, NULL, TRUE);
4841 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4844 INT nIndex = (INT)wParam;
4846 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4849 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4851 if (infoPtr->hwndToolTip) {
4853 FIXME("change tool tip!\n");
4862 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4865 HIMAGELIST himl = (HIMAGELIST)lParam;
4866 HIMAGELIST himlTemp;
4869 if (infoPtr->iVersion >= 5)
4872 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4873 &infoPtr->cimlDis, himl, id);
4875 /* FIXME: redraw ? */
4877 return (LRESULT)himlTemp;
4882 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4887 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4889 dwTemp = infoPtr->dwDTFlags;
4890 infoPtr->dwDTFlags =
4891 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4893 return (LRESULT)dwTemp;
4896 /* This function differs a bit from what MSDN says it does:
4897 * 1. lParam contains extended style flags to OR with current style
4898 * (MSDN isn't clear on the OR bit)
4899 * 2. wParam appears to contain extended style flags to be reset
4900 * (MSDN says that this parameter is reserved)
4903 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4908 dwTemp = infoPtr->dwExStyle;
4909 infoPtr->dwExStyle &= ~wParam;
4910 infoPtr->dwExStyle |= (DWORD)lParam;
4912 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4914 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4915 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4916 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4918 TOOLBAR_CalcToolbar (hwnd);
4920 TOOLBAR_AutoSize(hwnd);
4922 InvalidateRect(hwnd, NULL, TRUE);
4924 return (LRESULT)dwTemp;
4929 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4932 HIMAGELIST himlTemp;
4933 HIMAGELIST himl = (HIMAGELIST)lParam;
4936 if (infoPtr->iVersion >= 5)
4939 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4941 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4942 &infoPtr->cimlHot, himl, id);
4944 /* FIXME: redraw ? */
4946 return (LRESULT)himlTemp;
4950 /* Makes previous hot button no longer hot, makes the specified
4951 * button hot and sends appropriate notifications. dwReason is one or
4952 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4953 * NOTE 1: this function does not validate nHit
4954 * NOTE 2: the name of this function is completely made up and
4955 * not based on any documentation from Microsoft. */
4957 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4959 if (infoPtr->nHotItem != nHit)
4961 NMTBHOTITEM nmhotitem;
4962 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4963 LRESULT no_highlight;
4965 /* Remove the effect of an old hot button if the button was
4966 drawn with the hot button effect */
4967 if(infoPtr->nHotItem >= 0)
4969 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4970 oldBtnPtr->bHot = FALSE;
4973 infoPtr->nHotItem = nHit;
4975 /* It's not a separator or in nowhere. It's a hot button. */
4977 btnPtr = &infoPtr->buttons[nHit];
4979 nmhotitem.dwFlags = dwReason;
4981 nmhotitem.idOld = oldBtnPtr->idCommand;
4983 nmhotitem.dwFlags |= HICF_ENTERING;
4985 nmhotitem.idNew = btnPtr->idCommand;
4987 nmhotitem.dwFlags |= HICF_LEAVING;
4989 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
4991 /* now invalidate the old and new buttons so they will be painted,
4992 * but only if they are enabled - disabled buttons cannot become hot */
4993 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
4994 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4995 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
4997 btnPtr->bHot = TRUE;
4998 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5004 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5007 INT nOldHotItem = infoPtr->nHotItem;
5009 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5011 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5014 /* NOTE: an application can still remove the hot item even if anchor
5015 * highlighting is enabled */
5017 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5018 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5020 if (nOldHotItem < 0)
5023 return (LRESULT)nOldHotItem;
5028 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5030 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5031 HIMAGELIST himlTemp;
5032 HIMAGELIST himl = (HIMAGELIST)lParam;
5035 if (infoPtr->iVersion >= 5)
5038 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5039 &infoPtr->cimlDef, himl, id);
5041 infoPtr->nNumBitmaps = 0;
5042 for (i = 0; i < infoPtr->cimlDef; i++)
5043 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5045 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5046 &infoPtr->nBitmapHeight))
5048 infoPtr->nBitmapWidth = 1;
5049 infoPtr->nBitmapHeight = 1;
5052 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5053 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5054 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5056 InvalidateRect(hwnd, NULL, TRUE);
5058 return (LRESULT)himlTemp;
5063 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5067 infoPtr->nIndent = (INT)wParam;
5071 /* process only on indent changing */
5072 if(infoPtr->nIndent != (INT)wParam)
5074 infoPtr->nIndent = (INT)wParam;
5075 TOOLBAR_CalcToolbar (hwnd);
5076 InvalidateRect(hwnd, NULL, FALSE);
5084 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5087 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5089 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5091 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5093 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5097 if ((lptbim->iButton == -1) ||
5098 ((lptbim->iButton < infoPtr->nNumButtons) &&
5099 (lptbim->iButton >= 0)))
5101 infoPtr->tbim = *lptbim;
5102 /* FIXME: don't need to update entire toolbar */
5103 InvalidateRect(hwnd, NULL, TRUE);
5106 ERR("Invalid button index %d\n", lptbim->iButton);
5113 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5117 infoPtr->clrInsertMark = (COLORREF)lParam;
5119 /* FIXME: don't need to update entire toolbar */
5120 InvalidateRect(hwnd, NULL, TRUE);
5127 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5131 infoPtr->nMaxTextRows = (INT)wParam;
5133 TOOLBAR_CalcToolbar(hwnd);
5138 /* MSDN gives slightly wrong info on padding.
5139 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5140 * 2. It is not used to create a blank area between the edge of the button
5141 * and the text or image if TBSTYLE_LIST is set. It is used to control
5142 * the gap between the image and text.
5143 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5144 * to control the bottom and right borders [with the border being
5145 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5146 * is shared evenly on both sides of the button.
5147 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5150 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5155 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5156 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5157 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5158 TRACE("cx=%ld, cy=%ld\n",
5159 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5160 return (LRESULT) oldPad;
5165 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5172 hwndOldNotify = infoPtr->hwndNotify;
5173 infoPtr->hwndNotify = (HWND)wParam;
5175 return (LRESULT)hwndOldNotify;
5180 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5183 LPRECT lprc = (LPRECT)lParam;
5187 if (LOWORD(wParam) > 1) {
5188 FIXME("multiple rows not supported!\n");
5191 if(infoPtr->nRows != LOWORD(wParam))
5193 infoPtr->nRows = LOWORD(wParam);
5195 /* recalculate toolbar */
5196 TOOLBAR_CalcToolbar (hwnd);
5198 /* repaint toolbar */
5199 InvalidateRect(hwnd, NULL, TRUE);
5202 /* return bounding rectangle */
5204 lprc->left = infoPtr->rcBound.left;
5205 lprc->right = infoPtr->rcBound.right;
5206 lprc->top = infoPtr->rcBound.top;
5207 lprc->bottom = infoPtr->rcBound.bottom;
5215 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5218 TBUTTON_INFO *btnPtr;
5221 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5225 btnPtr = &infoPtr->buttons[nIndex];
5227 /* if hidden state has changed the invalidate entire window and recalc */
5228 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5229 btnPtr->fsState = LOWORD(lParam);
5230 TOOLBAR_CalcToolbar (hwnd);
5231 InvalidateRect(hwnd, 0, TRUE);
5235 /* process state changing if current state doesn't match new state */
5236 if(btnPtr->fsState != LOWORD(lParam))
5238 btnPtr->fsState = LOWORD(lParam);
5239 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5247 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5249 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5255 inline static LRESULT
5256 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5260 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5262 infoPtr->hwndToolTip = (HWND)wParam;
5268 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5273 TRACE("%s hwnd=%p\n",
5274 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5276 bTemp = infoPtr->bUnicode;
5277 infoPtr->bUnicode = (BOOL)wParam;
5284 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5288 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5289 comctl32_color.clrBtnHighlight :
5290 infoPtr->clrBtnHighlight;
5291 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5292 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5298 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5302 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5303 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5304 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5306 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5307 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5308 InvalidateRect(hwnd, NULL, TRUE);
5314 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5317 INT iOldVersion = infoPtr->iVersion;
5319 infoPtr->iVersion = iVersion;
5321 if (infoPtr->iVersion >= 5)
5322 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5329 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5332 WORD iString = HIWORD(wParam);
5333 WORD buffersize = LOWORD(wParam);
5334 LPSTR str = (LPSTR)lParam;
5337 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5339 if (iString < infoPtr->nNumStrings)
5341 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5343 TRACE("returning %s\n", debugstr_a(str));
5346 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5353 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5356 WORD iString = HIWORD(wParam);
5357 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5358 LPWSTR str = (LPWSTR)lParam;
5361 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5363 if (iString < infoPtr->nNumStrings)
5365 len = min(len, strlenW(infoPtr->strings[iString]));
5366 ret = (len+1)*sizeof(WCHAR);
5367 memcpy(str, infoPtr->strings[iString], ret);
5370 TRACE("returning %s\n", debugstr_w(str));
5373 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5378 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5379 * is the maximum size of the toolbar? */
5380 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5382 SIZE * pSize = (SIZE*)lParam;
5383 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5388 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5389 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5390 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5393 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5396 INT nOldHotItem = infoPtr->nHotItem;
5398 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5399 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5401 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5404 /* NOTE: an application can still remove the hot item even if anchor
5405 * highlighting is enabled */
5407 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5411 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5414 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5415 * which controls the amount of spacing between the image and the text
5416 * of buttons for TBSTYLE_LIST toolbars. */
5417 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5421 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5424 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5426 infoPtr->iListGap = (INT)wParam;
5428 InvalidateRect(hwnd, NULL, TRUE);
5433 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5434 * of image lists associated with the various states. */
5435 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5439 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5441 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5445 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5448 LPSIZE lpsize = (LPSIZE)lParam;
5454 * Testing shows the following:
5455 * wParam = 0 adjust cx value
5456 * = 1 set cy value to max size.
5457 * lParam pointer to SIZE structure
5460 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5461 wParam, lParam, lpsize->cx, lpsize->cy);
5465 if (lpsize->cx == -1) {
5466 /* **** this is wrong, native measures each button and sets it */
5467 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5469 else if(HIWORD(lpsize->cx)) {
5471 HWND hwndParent = GetParent(hwnd);
5473 GetWindowRect(hwnd, &rc);
5474 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5475 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5476 rc.left, rc.top, rc.right, rc.bottom);
5477 lpsize->cx = max(rc.right-rc.left,
5478 infoPtr->rcBound.right - infoPtr->rcBound.left);
5481 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5485 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5488 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5492 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5493 lpsize->cx, lpsize->cy);
5497 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5499 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5501 InvalidateRect(hwnd, NULL, TRUE);
5507 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5509 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5510 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5513 TRACE("hwnd = %p\n", hwnd);
5515 /* initialize info structure */
5516 infoPtr->nButtonHeight = 22;
5517 infoPtr->nButtonWidth = 24;
5518 infoPtr->nBitmapHeight = 15;
5519 infoPtr->nBitmapWidth = 16;
5521 infoPtr->nMaxTextRows = 1;
5522 infoPtr->cxMin = -1;
5523 infoPtr->cxMax = -1;
5524 infoPtr->nNumBitmaps = 0;
5525 infoPtr->nNumStrings = 0;
5527 infoPtr->bCaptured = FALSE;
5528 infoPtr->nButtonDown = -1;
5529 infoPtr->nButtonDrag = -1;
5530 infoPtr->nOldHit = -1;
5531 infoPtr->nHotItem = -1;
5532 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5533 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5534 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5535 infoPtr->bDragOutSent = FALSE;
5536 infoPtr->iVersion = 0;
5537 infoPtr->hwndSelf = hwnd;
5538 infoPtr->bDoRedraw = TRUE;
5539 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5540 infoPtr->clrBtnShadow = CLR_DEFAULT;
5541 infoPtr->szPadding.cx = DEFPAD_CX;
5542 infoPtr->szPadding.cy = DEFPAD_CY;
5543 infoPtr->iListGap = DEFLISTGAP;
5544 infoPtr->dwStyle = dwStyle;
5545 infoPtr->tbim.iButton = -1;
5546 GetClientRect(hwnd, &infoPtr->client_rect);
5547 infoPtr->bUnicode = infoPtr->hwndNotify &&
5548 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5550 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5551 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5553 if (dwStyle & TBSTYLE_TOOLTIPS) {
5554 /* Create tooltip control */
5555 infoPtr->hwndToolTip =
5556 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5557 CW_USEDEFAULT, CW_USEDEFAULT,
5558 CW_USEDEFAULT, CW_USEDEFAULT,
5561 /* Send NM_TOOLTIPSCREATED notification */
5562 if (infoPtr->hwndToolTip)
5564 NMTOOLTIPSCREATED nmttc;
5566 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5568 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5572 OpenThemeData (hwnd, themeClass);
5574 TOOLBAR_CheckStyle (hwnd, dwStyle);
5576 TOOLBAR_CalcToolbar(hwnd);
5583 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5587 /* delete tooltip control */
5588 if (infoPtr->hwndToolTip)
5589 DestroyWindow (infoPtr->hwndToolTip);
5591 /* delete temporary buffer for tooltip text */
5592 Free (infoPtr->pszTooltipText);
5593 Free (infoPtr->bitmaps); /* bitmaps list */
5595 /* delete button data */
5596 if (infoPtr->buttons)
5597 Free (infoPtr->buttons);
5599 /* delete strings */
5600 if (infoPtr->strings) {
5602 for (i = 0; i < infoPtr->nNumStrings; i++)
5603 if (infoPtr->strings[i])
5604 Free (infoPtr->strings[i]);
5606 Free (infoPtr->strings);
5609 /* destroy internal image list */
5610 if (infoPtr->himlInt)
5611 ImageList_Destroy (infoPtr->himlInt);
5613 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5614 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5615 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5617 /* delete default font */
5619 DeleteObject (infoPtr->hDefaultFont);
5621 CloseThemeData (GetWindowTheme (hwnd));
5623 /* free toolbar info data */
5625 SetWindowLongPtrW (hwnd, 0, 0);
5632 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5635 NMTBCUSTOMDRAW tbcd;
5638 HTHEME theme = GetWindowTheme (hwnd);
5640 /* the app has told us not to redraw the toolbar */
5641 if (!infoPtr->bDoRedraw)
5644 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5645 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5646 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5647 tbcd.nmcd.hdc = (HDC)wParam;
5648 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5649 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5651 /* FIXME: in general the return flags *can* be or'ed together */
5652 switch (infoPtr->dwBaseCustDraw)
5654 case CDRF_DODEFAULT:
5656 case CDRF_SKIPDEFAULT:
5659 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5664 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5665 * to my parent for processing.
5667 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5669 HDC hdc = (HDC)wParam;
5674 parent = GetParent(hwnd);
5675 MapWindowPoints(hwnd, parent, &pt, 1);
5676 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5677 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5678 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5681 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5683 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5684 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5685 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5686 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5687 tbcd.nmcd.hdc = (HDC)wParam;
5688 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5689 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5690 switch (infoPtr->dwBaseCustDraw)
5692 case CDRF_DODEFAULT:
5694 case CDRF_SKIPDEFAULT:
5697 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5706 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5710 return (LRESULT)infoPtr->hFont;
5715 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5718 INT nNewHotItem = infoPtr->nHotItem;
5720 for (i = 0; i < infoPtr->nNumButtons; i++)
5723 if ((nNewHotItem + iDirection < 0) ||
5724 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5726 NMTBWRAPHOTITEM nmtbwhi;
5727 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5728 nmtbwhi.iDirection = iDirection;
5729 nmtbwhi.dwReason = dwReason;
5731 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5735 nNewHotItem += iDirection;
5736 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5738 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5739 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5741 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5748 TOOLBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5753 nmkey.nVKey = (UINT)wParam;
5754 nmkey.uFlags = HIWORD(lParam);
5756 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5757 return DefWindowProcW(hwnd, WM_KEYDOWN, wParam, lParam);
5759 switch ((UINT)wParam)
5763 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5767 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5771 if ((infoPtr->nHotItem >= 0) &&
5772 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5774 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5775 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5786 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5791 pt.x = (INT)LOWORD(lParam);
5792 pt.y = (INT)HIWORD(lParam);
5793 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5796 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5797 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5798 TOOLBAR_Customize (hwnd);
5805 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5807 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5808 TBUTTON_INFO *btnPtr;
5813 BOOL bDragKeyPressed;
5817 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5818 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5820 bDragKeyPressed = (wParam & MK_SHIFT);
5822 if (infoPtr->hwndToolTip)
5823 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5824 WM_LBUTTONDOWN, wParam, lParam);
5826 pt.x = (INT)LOWORD(lParam);
5827 pt.y = (INT)HIWORD(lParam);
5828 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5830 btnPtr = &infoPtr->buttons[nHit];
5832 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5834 infoPtr->nButtonDrag = nHit;
5837 /* If drag cursor has not been loaded, load it.
5838 * Note: it doesn't need to be freed */
5840 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5841 SetCursor(hCursorDrag);
5846 infoPtr->nOldHit = nHit;
5848 CopyRect(&arrowRect, &btnPtr->rect);
5849 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5851 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5852 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5853 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5854 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5855 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5856 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5860 /* draw in pressed state */
5861 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5862 btnPtr->fsState |= TBSTATE_PRESSED;
5864 btnPtr->bDropDownPressed = TRUE;
5865 RedrawWindow(hwnd,&btnPtr->rect,0,
5866 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5868 memset(&nmtb, 0, sizeof(nmtb));
5869 nmtb.iItem = btnPtr->idCommand;
5870 nmtb.rcButton = btnPtr->rect;
5871 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5873 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5875 if (res != TBDDRET_TREATPRESSED)
5879 /* redraw button in unpressed state */
5880 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5881 btnPtr->fsState &= ~TBSTATE_PRESSED;
5883 btnPtr->bDropDownPressed = FALSE;
5884 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5886 /* find and set hot item
5887 * NOTE: native doesn't do this, but that is a bug */
5889 ScreenToClient(hwnd, &pt);
5890 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5891 if (!infoPtr->bAnchor || (nHit >= 0))
5892 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5894 /* remove any left mouse button down or double-click messages
5895 * so that we can get a toggle effect on the button */
5896 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5897 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5902 /* otherwise drop through and process as pushed */
5904 infoPtr->bCaptured = TRUE;
5905 infoPtr->nButtonDown = nHit;
5906 infoPtr->bDragOutSent = FALSE;
5908 btnPtr->fsState |= TBSTATE_PRESSED;
5910 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5912 if (btnPtr->fsState & TBSTATE_ENABLED)
5913 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5920 memset(&nmtb, 0, sizeof(nmtb));
5921 nmtb.iItem = btnPtr->idCommand;
5922 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5925 nmmouse.dwHitInfo = nHit;
5927 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5929 nmmouse.dwItemSpec = -1;
5932 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5933 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5936 ClientToScreen(hwnd, &pt);
5939 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5940 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5946 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5948 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5949 TBUTTON_INFO *btnPtr;
5953 BOOL bSendMessage = TRUE;
5958 if (infoPtr->hwndToolTip)
5959 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5960 WM_LBUTTONUP, wParam, lParam);
5962 pt.x = (INT)LOWORD(lParam);
5963 pt.y = (INT)HIWORD(lParam);
5964 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5966 if (!infoPtr->bAnchor || (nHit >= 0))
5967 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5969 if (infoPtr->nButtonDrag >= 0) {
5973 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5976 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5978 GetClientRect(hwnd, &rcClient);
5979 if (PtInRect(&rcClient, pt))
5986 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5989 if (nButton == infoPtr->nButtonDrag)
5991 /* if the button is moved sightly left and we have a
5992 * separator there then remove it */
5993 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5995 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5996 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5998 else /* else insert a separator before the dragged button */
6001 memset(&tbb, 0, sizeof(tbb));
6002 tbb.fsStyle = BTNS_SEP;
6004 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
6011 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
6012 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
6014 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
6017 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6022 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6023 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6026 /* button under cursor changed so need to re-set hot item */
6027 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6028 infoPtr->nButtonDrag = -1;
6030 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6032 else if (infoPtr->nButtonDown >= 0) {
6033 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6034 btnPtr->fsState &= ~TBSTATE_PRESSED;
6036 if (btnPtr->fsStyle & BTNS_CHECK) {
6037 if (btnPtr->fsStyle & BTNS_GROUP) {
6038 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6040 if (nOldIndex == nHit)
6041 bSendMessage = FALSE;
6042 if ((nOldIndex != nHit) &&
6044 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6045 btnPtr->fsState |= TBSTATE_CHECKED;
6048 if (btnPtr->fsState & TBSTATE_CHECKED)
6049 btnPtr->fsState &= ~TBSTATE_CHECKED;
6051 btnPtr->fsState |= TBSTATE_CHECKED;
6055 if (nOldIndex != -1)
6056 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6059 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6060 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6061 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6063 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6065 infoPtr->nButtonDown = -1;
6067 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6068 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6069 NM_RELEASEDCAPTURE);
6071 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6074 memset(&nmtb, 0, sizeof(nmtb));
6075 nmtb.iItem = btnPtr->idCommand;
6076 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6079 if (btnPtr->fsState & TBSTATE_ENABLED)
6081 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6082 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)hwnd);
6086 /* !!! Undocumented - toolbar at 4.71 level and above sends
6087 * NM_CLICK with the NMMOUSE structure. */
6088 nmmouse.dwHitInfo = nHit;
6091 nmmouse.dwItemSpec = -1;
6094 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6095 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6098 ClientToScreen(hwnd, &pt);
6101 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6102 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6108 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6115 pt.x = LOWORD(lParam);
6116 pt.y = HIWORD(lParam);
6118 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6119 nmmouse.dwHitInfo = nHit;
6122 nmmouse.dwItemSpec = -1;
6124 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6125 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6128 ClientToScreen(hwnd, &pt);
6131 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6132 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6138 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6143 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6144 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6150 TOOLBAR_CaptureChanged(HWND hwnd)
6152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6153 TBUTTON_INFO *btnPtr;
6155 infoPtr->bCaptured = FALSE;
6157 if (infoPtr->nButtonDown >= 0)
6159 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6160 btnPtr->fsState &= ~TBSTATE_PRESSED;
6162 infoPtr->nOldHit = -1;
6164 if (btnPtr->fsState & TBSTATE_ENABLED)
6165 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6171 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6174 TBUTTON_INFO *hotBtnPtr;
6176 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6178 /* don't remove hot effects when in anchor highlighting mode or when a
6179 * drop-down button is pressed */
6180 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6181 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6183 if (infoPtr->nOldHit < 0)
6186 /* If the last button we were over is depressed then make it not */
6187 /* depressed and redraw it */
6188 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6190 TBUTTON_INFO *btnPtr;
6193 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6195 btnPtr->fsState &= ~TBSTATE_PRESSED;
6197 rc1 = hotBtnPtr->rect;
6198 InflateRect (&rc1, 1, 1);
6199 InvalidateRect (hwnd, &rc1, TRUE);
6202 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6205 ZeroMemory(&nmt, sizeof(nmt));
6206 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6207 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6208 infoPtr->bDragOutSent = TRUE;
6211 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6217 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6219 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6221 TRACKMOUSEEVENT trackinfo;
6223 TBUTTON_INFO *btnPtr;
6225 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
6226 /* fill in the TRACKMOUSEEVENT struct */
6227 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6228 trackinfo.dwFlags = TME_QUERY;
6230 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6231 _TrackMouseEvent(&trackinfo);
6233 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6234 if(trackinfo.hwndTrack != hwnd || !(trackinfo.dwFlags & TME_LEAVE)) {
6235 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6236 trackinfo.hwndTrack = hwnd;
6238 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6239 /* and can properly deactivate the hot toolbar button */
6240 _TrackMouseEvent(&trackinfo);
6244 if (infoPtr->hwndToolTip)
6245 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6246 WM_MOUSEMOVE, wParam, lParam);
6248 pt.x = (INT)LOWORD(lParam);
6249 pt.y = (INT)HIWORD(lParam);
6251 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6253 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6254 && (!infoPtr->bAnchor || (nHit >= 0)))
6255 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6257 if (infoPtr->nOldHit != nHit)
6259 if (infoPtr->bCaptured)
6261 if (!infoPtr->bDragOutSent)
6264 ZeroMemory(&nmt, sizeof(nmt));
6265 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6266 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6267 infoPtr->bDragOutSent = TRUE;
6270 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6271 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6272 btnPtr->fsState &= ~TBSTATE_PRESSED;
6273 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6275 else if (nHit == infoPtr->nButtonDown) {
6276 btnPtr->fsState |= TBSTATE_PRESSED;
6277 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6279 infoPtr->nOldHit = nHit;
6287 inline static LRESULT
6288 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6290 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6291 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6293 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6297 inline static LRESULT
6298 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6300 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6301 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6303 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6308 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6310 TOOLBAR_INFO *infoPtr;
6311 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6314 /* allocate memory for info structure */
6315 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6316 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6319 infoPtr->dwStructSize = sizeof(TBBUTTON);
6321 infoPtr->nWidth = 0;
6323 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6324 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6325 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6326 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6329 /* native control does:
6330 * Get a lot of colors and brushes
6332 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6333 * CreateFontIndirectW(adr1)
6334 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6335 * hdc = GetDC(toolbar)
6336 * GetSystemMetrics(0x48)
6337 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6338 * 0, 0, 0, 0, "MARLETT")
6339 * oldfnt = SelectObject(hdc, fnt2)
6340 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6341 * GetTextMetricsW(hdc, adr3)
6342 * SelectObject(hdc, oldfnt)
6343 * DeleteObject(fnt2)
6345 * InvalidateRect(toolbar, 0, 1)
6346 * SetWindowLongW(toolbar, 0, addr)
6347 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6350 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6351 * ie 2 0x4600094c 0x4600094c 0x4600894d
6352 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6353 * rebar 0x50008844 0x40008844 0x50008845
6354 * pager 0x50000844 0x40000844 0x50008845
6355 * IC35mgr 0x5400084e **nochange**
6356 * on entry to _NCCREATE 0x5400084e
6357 * rowlist 0x5400004e **nochange**
6358 * on entry to _NCCREATE 0x5400004e
6362 /* I think the code below is a bug, but it is the way that the native
6363 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6364 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6365 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6366 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6367 * Somehow, the only cases of this seem to be MFC programs.
6369 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6370 * does not occur in the WM_STYLECHANGING routine.
6371 * (Guy Albertelli 9/2001)
6374 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
6375 && !(cs->style & TBSTYLE_TRANSPARENT))
6376 styleadd |= TBSTYLE_TRANSPARENT;
6377 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6378 styleadd |= CCS_TOP; /* default to top */
6379 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6382 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6387 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6389 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6393 if (dwStyle & WS_MINIMIZE)
6394 return 0; /* Nothing to do */
6396 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6398 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6401 if (!(dwStyle & CCS_NODIVIDER))
6403 GetWindowRect (hwnd, &rcWindow);
6404 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6405 if( dwStyle & WS_BORDER )
6406 OffsetRect (&rcWindow, 1, 1);
6407 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6410 ReleaseDC( hwnd, hdc );
6416 /* handles requests from the tooltip control on what text to display */
6417 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6419 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6421 TRACE("button index = %d\n", index);
6423 Free (infoPtr->pszTooltipText);
6424 infoPtr->pszTooltipText = NULL;
6429 if (infoPtr->bUnicode)
6431 WCHAR wszBuffer[INFOTIPSIZE+1];
6432 NMTBGETINFOTIPW tbgit;
6433 unsigned int len; /* in chars */
6435 wszBuffer[0] = '\0';
6436 wszBuffer[INFOTIPSIZE] = '\0';
6438 tbgit.pszText = wszBuffer;
6439 tbgit.cchTextMax = INFOTIPSIZE;
6440 tbgit.iItem = lpnmtdi->hdr.idFrom;
6441 tbgit.lParam = infoPtr->buttons[index].dwData;
6443 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6445 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6447 len = strlenW(tbgit.pszText);
6448 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6450 /* need to allocate temporary buffer in infoPtr as there
6451 * isn't enough space in buffer passed to us by the
6452 * tooltip control */
6453 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6454 if (infoPtr->pszTooltipText)
6456 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6457 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6463 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6469 CHAR szBuffer[INFOTIPSIZE+1];
6470 NMTBGETINFOTIPA tbgit;
6471 unsigned int len; /* in chars */
6474 szBuffer[INFOTIPSIZE] = '\0';
6476 tbgit.pszText = szBuffer;
6477 tbgit.cchTextMax = INFOTIPSIZE;
6478 tbgit.iItem = lpnmtdi->hdr.idFrom;
6479 tbgit.lParam = infoPtr->buttons[index].dwData;
6481 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6483 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6485 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6486 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6488 /* need to allocate temporary buffer in infoPtr as there
6489 * isn't enough space in buffer passed to us by the
6490 * tooltip control */
6491 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6492 if (infoPtr->pszTooltipText)
6494 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6495 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6501 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6502 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6507 /* if button has text, but it is not shown then automatically
6508 * use that text as tooltip */
6509 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6510 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6512 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6513 unsigned int len = pszText ? strlenW(pszText) : 0;
6515 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6517 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6519 /* need to allocate temporary buffer in infoPtr as there
6520 * isn't enough space in buffer passed to us by the
6521 * tooltip control */
6522 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6523 if (infoPtr->pszTooltipText)
6525 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6526 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6532 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6537 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6539 /* last resort: send notification on to app */
6540 /* FIXME: find out what is really used here */
6541 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6545 inline static LRESULT
6546 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6549 LPNMHDR lpnmh = (LPNMHDR)lParam;
6551 switch (lpnmh->code)
6555 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6557 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6558 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6559 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6563 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6564 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6572 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6574 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6575 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6576 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6577 lppgs->iScroll, lppgs->iDir);
6581 case TTN_GETDISPINFOW:
6582 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6584 case TTN_GETDISPINFOA:
6585 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6595 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6599 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6601 if (lParam == NF_QUERY)
6604 if (lParam == NF_REQUERY) {
6605 format = SendMessageW(infoPtr->hwndNotify,
6606 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6607 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6608 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6619 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6625 /* fill ps.rcPaint with a default rect */
6626 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6628 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6630 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6631 ps.rcPaint.left, ps.rcPaint.top,
6632 ps.rcPaint.right, ps.rcPaint.bottom);
6634 TOOLBAR_Refresh (hwnd, hdc, &ps);
6635 if (!wParam) EndPaint (hwnd, &ps);
6642 TOOLBAR_SetFocus (HWND hwnd, WPARAM wParam)
6644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6646 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6648 /* make first item hot */
6649 if (infoPtr->nNumButtons > 0)
6650 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6657 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6658 /*****************************************************
6661 * Handles the WM_SETREDRAW message.
6664 * According to testing V4.71 of COMCTL32 returns the
6665 * *previous* status of the redraw flag (either 0 or 1)
6666 * instead of the MSDN documented value of 0 if handled.
6667 * (For laughs see the "consistency" with same function
6670 *****************************************************/
6672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6673 BOOL oldredraw = infoPtr->bDoRedraw;
6675 TRACE("set to %s\n",
6676 (wParam) ? "TRUE" : "FALSE");
6677 infoPtr->bDoRedraw = (BOOL) wParam;
6679 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6681 return (oldredraw) ? 1 : 0;
6686 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6688 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6690 TRACE("sizing toolbar!\n");
6692 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6694 RECT delta_width, delta_height, client, dummy;
6695 DWORD min_x, max_x, min_y, max_y;
6696 TBUTTON_INFO *btnPtr;
6699 GetClientRect(hwnd, &client);
6700 if(client.right > infoPtr->client_rect.right)
6702 min_x = infoPtr->client_rect.right;
6703 max_x = client.right;
6707 max_x = infoPtr->client_rect.right;
6708 min_x = client.right;
6710 if(client.bottom > infoPtr->client_rect.bottom)
6712 min_y = infoPtr->client_rect.bottom;
6713 max_y = client.bottom;
6717 max_y = infoPtr->client_rect.bottom;
6718 min_y = client.bottom;
6721 SetRect(&delta_width, min_x, 0, max_x, min_y);
6722 SetRect(&delta_height, 0, min_y, max_x, max_y);
6724 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6725 btnPtr = infoPtr->buttons;
6726 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6727 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6728 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6729 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6731 GetClientRect(hwnd, &infoPtr->client_rect);
6732 TOOLBAR_AutoSize(hwnd);
6738 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6740 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6742 if (nType == GWL_STYLE)
6744 if (lpStyle->styleNew & TBSTYLE_LIST)
6745 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6747 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6749 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6751 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6753 infoPtr->dwStyle = lpStyle->styleNew;
6755 /* only resize if one of the CCS_* styles was changed */
6756 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6758 TOOLBAR_AutoSize (hwnd);
6760 InvalidateRect(hwnd, NULL, TRUE);
6769 TOOLBAR_SysColorChange (HWND hwnd)
6771 COMCTL32_RefreshSysColors();
6777 /* update theme after a WM_THEMECHANGED message */
6778 static LRESULT theme_changed (HWND hwnd)
6780 HTHEME theme = GetWindowTheme (hwnd);
6781 CloseThemeData (theme);
6782 OpenThemeData (hwnd, themeClass);
6787 static LRESULT WINAPI
6788 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6790 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6792 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6793 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6795 if (!infoPtr && (uMsg != WM_NCCREATE))
6796 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6801 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6803 case TB_ADDBUTTONSA:
6804 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6806 case TB_ADDBUTTONSW:
6807 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6810 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6813 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6816 return TOOLBAR_AutoSize (hwnd);
6818 case TB_BUTTONCOUNT:
6819 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6821 case TB_BUTTONSTRUCTSIZE:
6822 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6824 case TB_CHANGEBITMAP:
6825 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6827 case TB_CHECKBUTTON:
6828 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6830 case TB_COMMANDTOINDEX:
6831 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6834 return TOOLBAR_Customize (hwnd);
6836 case TB_DELETEBUTTON:
6837 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6839 case TB_ENABLEBUTTON:
6840 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6842 case TB_GETANCHORHIGHLIGHT:
6843 return TOOLBAR_GetAnchorHighlight (hwnd);
6846 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6848 case TB_GETBITMAPFLAGS:
6849 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6852 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6854 case TB_GETBUTTONINFOA:
6855 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6857 case TB_GETBUTTONINFOW:
6858 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6860 case TB_GETBUTTONSIZE:
6861 return TOOLBAR_GetButtonSize (hwnd);
6863 case TB_GETBUTTONTEXTA:
6864 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6866 case TB_GETBUTTONTEXTW:
6867 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6869 case TB_GETDISABLEDIMAGELIST:
6870 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6872 case TB_GETEXTENDEDSTYLE:
6873 return TOOLBAR_GetExtendedStyle (hwnd);
6875 case TB_GETHOTIMAGELIST:
6876 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6879 return TOOLBAR_GetHotItem (hwnd);
6881 case TB_GETIMAGELIST:
6882 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6884 case TB_GETINSERTMARK:
6885 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6887 case TB_GETINSERTMARKCOLOR:
6888 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6890 case TB_GETITEMRECT:
6891 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6894 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6896 /* case TB_GETOBJECT: */ /* 4.71 */
6899 return TOOLBAR_GetPadding (hwnd);
6902 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6905 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6908 return TOOLBAR_GetState (hwnd, wParam, lParam);
6911 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6914 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6917 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6919 case TB_GETTEXTROWS:
6920 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6922 case TB_GETTOOLTIPS:
6923 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6925 case TB_GETUNICODEFORMAT:
6926 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6929 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6932 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6934 case TB_INDETERMINATE:
6935 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6937 case TB_INSERTBUTTONA:
6938 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6940 case TB_INSERTBUTTONW:
6941 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6943 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6945 case TB_ISBUTTONCHECKED:
6946 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6948 case TB_ISBUTTONENABLED:
6949 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6951 case TB_ISBUTTONHIDDEN:
6952 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6954 case TB_ISBUTTONHIGHLIGHTED:
6955 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6957 case TB_ISBUTTONINDETERMINATE:
6958 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6960 case TB_ISBUTTONPRESSED:
6961 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6964 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6966 case TB_MAPACCELERATORA:
6967 case TB_MAPACCELERATORW:
6968 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6971 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6974 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6976 case TB_PRESSBUTTON:
6977 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6979 case TB_REPLACEBITMAP:
6980 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6982 case TB_SAVERESTOREA:
6983 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6985 case TB_SAVERESTOREW:
6986 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6988 case TB_SETANCHORHIGHLIGHT:
6989 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6991 case TB_SETBITMAPSIZE:
6992 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6994 case TB_SETBUTTONINFOA:
6995 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6997 case TB_SETBUTTONINFOW:
6998 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7000 case TB_SETBUTTONSIZE:
7001 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7003 case TB_SETBUTTONWIDTH:
7004 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7007 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7009 case TB_SETDISABLEDIMAGELIST:
7010 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7012 case TB_SETDRAWTEXTFLAGS:
7013 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7015 case TB_SETEXTENDEDSTYLE:
7016 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7018 case TB_SETHOTIMAGELIST:
7019 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7022 return TOOLBAR_SetHotItem (hwnd, wParam);
7024 case TB_SETIMAGELIST:
7025 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7028 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7030 case TB_SETINSERTMARK:
7031 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7033 case TB_SETINSERTMARKCOLOR:
7034 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7036 case TB_SETMAXTEXTROWS:
7037 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7040 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7043 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7046 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7049 return TOOLBAR_SetState (hwnd, wParam, lParam);
7052 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7054 case TB_SETTOOLTIPS:
7055 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7057 case TB_SETUNICODEFORMAT:
7058 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7061 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7064 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7067 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7070 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7073 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7076 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7078 /* Common Control Messages */
7080 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7081 case CCM_GETCOLORSCHEME:
7082 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7084 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7085 case CCM_SETCOLORSCHEME:
7086 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7088 case CCM_GETVERSION:
7089 return TOOLBAR_GetVersion (hwnd);
7091 case CCM_SETVERSION:
7092 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7098 return TOOLBAR_Create (hwnd, wParam, lParam);
7101 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7104 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7107 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7110 return TOOLBAR_KeyDown (hwnd, wParam, lParam);
7112 /* case WM_KILLFOCUS: */
7114 case WM_LBUTTONDBLCLK:
7115 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7117 case WM_LBUTTONDOWN:
7118 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7121 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7124 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7126 case WM_RBUTTONDBLCLK:
7127 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7130 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7133 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7135 case WM_CAPTURECHANGED:
7136 return TOOLBAR_CaptureChanged(hwnd);
7139 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7142 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7145 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7148 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7151 return TOOLBAR_Notify (hwnd, wParam, lParam);
7153 case WM_NOTIFYFORMAT:
7154 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7156 case WM_PRINTCLIENT:
7158 return TOOLBAR_Paint (hwnd, wParam);
7161 return TOOLBAR_SetFocus (hwnd, wParam);
7164 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7167 return TOOLBAR_Size (hwnd, wParam, lParam);
7169 case WM_STYLECHANGED:
7170 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7172 case WM_SYSCOLORCHANGE:
7173 return TOOLBAR_SysColorChange (hwnd);
7175 case WM_THEMECHANGED:
7176 return theme_changed (hwnd);
7178 /* case WM_WININICHANGE: */
7183 case WM_MEASUREITEM:
7185 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7187 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7188 case PGM_FORWARDMOUSE:
7189 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7192 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7193 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7194 uMsg, wParam, lParam);
7195 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7201 TOOLBAR_Register (void)
7205 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7206 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7207 wndClass.lpfnWndProc = ToolbarWindowProc;
7208 wndClass.cbClsExtra = 0;
7209 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7210 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7211 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7212 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7214 RegisterClassW (&wndClass);
7219 TOOLBAR_Unregister (void)
7221 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7224 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7229 /* Check if the entry already exists */
7230 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7232 /* If this is a new entry we must create it and insert into the array */
7237 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7240 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7241 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7256 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7260 for (i = 0; i < *cies; i++)
7270 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7278 for (i = 0; i < cies; i++)
7280 if (pies[i]->id == id)
7292 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7294 HIMAGELIST himlDef = 0;
7295 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7298 himlDef = pie->himl;
7304 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7306 if (infoPtr->bUnicode)
7307 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7314 nmtba.iItem = nmtb->iItem;
7315 nmtba.pszText = Buffer;
7316 nmtba.cchText = 256;
7317 ZeroMemory(nmtba.pszText, nmtba.cchText);
7319 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7321 int ccht = strlen(nmtba.pszText);
7323 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7324 nmtb->pszText, nmtb->cchText);
7326 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7335 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7336 int iItem, PCUSTOMBUTTON btnInfo)
7340 /* MSDN states that iItem is the index of the button, rather than the
7341 * command ID as used by every other NMTOOLBAR notification */
7343 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7345 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);