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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
47 * - Button wrapping (under construction).
49 * - iListGap custom draw support.
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsoft's controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
61 * Differences between MSDN and actual native control operation:
62 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
63 * to the right of the bitmap. Otherwise, this style is
64 * identical to TBSTYLE_FLAT."
65 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
66 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
67 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
68 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
80 #include "wine/unicode.h"
84 #include "wine/debug.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
88 static HCURSOR hCursorDrag = NULL;
97 BYTE bDropDownPressed;
102 INT cx; /* manually set size */
116 } IMLENTRY, *PIMLENTRY;
120 DWORD dwStructSize; /* size of TBBUTTON struct */
121 INT nHeight; /* height of the toolbar */
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 bBtnTranspnt; /* button transparency flag */
160 BOOL bAutoSize; /* auto size deadlock indicator */
161 BOOL bAnchor; /* anchor highlight enabled */
162 BOOL bDoRedraw; /* Redraw status */
163 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
164 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
165 BOOL bCaptured; /* mouse captured? */
166 DWORD dwStyle; /* regular toolbar style */
167 DWORD dwExStyle; /* extended toolbar style */
168 DWORD dwDTFlags; /* DrawText flags */
170 COLORREF clrInsertMark; /* insert mark color */
171 COLORREF clrBtnHighlight; /* color for Flat Separator */
172 COLORREF clrBtnShadow; /* color for Flag Separator */
174 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
175 * for TTN_GETDISPINFOW notification */
176 TBINSERTMARK tbim; /* info on insertion mark */
177 TBUTTON_INFO *buttons; /* pointer to button array */
178 LPWSTR *strings; /* pointer to string array */
179 TBITMAP_INFO *bitmaps;
180 } TOOLBAR_INFO, *PTOOLBAR_INFO;
183 /* used by customization dialog */
186 PTOOLBAR_INFO tbInfo;
188 } CUSTDLG_INFO, *PCUSTDLG_INFO;
196 } CUSTOMBUTTON, *PCUSTOMBUTTON;
205 #define SEPARATOR_WIDTH 8
207 #define BOTTOM_BORDER 2
208 #define DDARROW_WIDTH 11
209 #define ARROW_HEIGHT 3
210 #define INSERTMARK_WIDTH 2
216 /* vertical padding used in list mode when image is present */
219 /* how wide to treat the bitmap if it isn't present */
220 #define NONLIST_NOTEXT_OFFSET 2
222 #define TOOLBAR_NOWHERE (-1)
224 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
225 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
226 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
228 /* Used to find undocumented extended styles */
229 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
230 TBSTYLE_EX_UNDOC1 | \
231 TBSTYLE_EX_MIXEDBUTTONS | \
232 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
234 /* all of the CCS_ styles */
235 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
236 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
238 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
239 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
240 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
241 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
242 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
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);
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
295 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
338 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK)
356 /* issue TBN_GETDISPINFO */
359 memset(&nmgd, 0, sizeof(nmgd));
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
364 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
365 if (nmgd.dwMask & TBNF_DI_SETITEM)
366 btnPtr->iBitmap = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
396 TOOLBAR_IsValidImageList(TOOLBAR_INFO *infoPtr, INT index)
398 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
399 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
403 /***********************************************************************
404 * TOOLBAR_GetImageListForDrawing
406 * This function validates the bitmap index (including I_IMAGECALLBACK
407 * functionality) and returns the corresponding image list.
410 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
414 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
415 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
416 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
417 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
421 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
422 if ((*index == I_IMAGECALLBACK) ||
423 (*index == I_IMAGENONE)) return NULL;
424 ERR("TBN_GETDISPINFO returned invalid index %d\n",
431 case IMAGE_LIST_DEFAULT:
432 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
435 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
437 case IMAGE_LIST_DISABLED:
438 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
442 FIXME("Shouldn't reach here\n");
446 TRACE("no image list\n");
453 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
456 COLORREF oldcolor, newcolor;
458 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
459 myrect.right = myrect.left + 1;
460 myrect.top = lpRect->top + 2;
461 myrect.bottom = lpRect->bottom - 2;
463 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
464 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
465 oldcolor = SetBkColor (hdc, newcolor);
466 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
468 myrect.left = myrect.right;
469 myrect.right = myrect.left + 1;
471 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
472 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
473 SetBkColor (hdc, newcolor);
474 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 SetBkColor (hdc, oldcolor);
480 /***********************************************************************
481 * TOOLBAR_DrawDDFlatSeparator
483 * This function draws the separator that was flagged as BTNS_DROPDOWN.
484 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
485 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
486 * are horizontal as opposed to the vertical separators for not dropdown
489 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
492 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
495 COLORREF oldcolor, newcolor;
497 myrect.left = lpRect->left;
498 myrect.right = lpRect->right;
499 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
500 myrect.bottom = myrect.top + 1;
502 InflateRect (&myrect, -2, 0);
504 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
505 myrect.left, myrect.top, myrect.right, myrect.bottom);
507 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
508 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
509 oldcolor = SetBkColor (hdc, newcolor);
510 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
512 myrect.top = myrect.bottom;
513 myrect.bottom = myrect.top + 1;
515 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
516 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
517 SetBkColor (hdc, newcolor);
518 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 SetBkColor (hdc, oldcolor);
525 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
530 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
531 hOldPen = SelectObject ( hdc, hPen );
534 MoveToEx (hdc, x, y, NULL);
535 LineTo (hdc, x+5, y++); x++;
536 MoveToEx (hdc, x, y, NULL);
537 LineTo (hdc, x+3, y++); x++;
538 MoveToEx (hdc, x, y, NULL);
539 LineTo (hdc, x+1, y++);
540 SelectObject( hdc, hOldPen );
541 DeleteObject( hPen );
545 * Draw the text string for this button.
546 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
547 * is non-zero, so we can simply check himlDef to see if we have
551 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
552 NMTBCUSTOMDRAW *tbcd)
554 HDC hdc = tbcd->nmcd.hdc;
557 COLORREF clrOldBk = 0;
559 UINT state = tbcd->nmcd.uItemState;
563 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
564 rcText->left, rcText->top, rcText->right, rcText->bottom);
566 hOldFont = SelectObject (hdc, infoPtr->hFont);
567 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
568 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
570 else if (state & CDIS_DISABLED) {
571 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
572 OffsetRect (rcText, 1, 1);
573 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
574 SetTextColor (hdc, comctl32_color.clr3dShadow);
575 OffsetRect (rcText, -1, -1);
577 else if (state & CDIS_INDETERMINATE) {
578 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
580 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
581 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
582 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
583 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
586 clrOld = SetTextColor (hdc, tbcd->clrText);
589 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
590 SetTextColor (hdc, clrOld);
591 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
593 SetBkColor (hdc, clrOldBk);
594 SetBkMode (hdc, oldBkMode);
596 SelectObject (hdc, hOldFont);
602 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
604 HDC hdc = tbcd->nmcd.hdc;
605 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
608 INT cx = lpRect->right - lpRect->left;
609 INT cy = lpRect->bottom - lpRect->top;
610 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
611 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
612 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
613 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
614 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
615 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
616 SetBkColor(hdc, clrBkOld);
617 SetTextColor(hdc, clrTextOld);
618 SelectObject (hdc, hbr);
622 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
625 HBITMAP hbmMask, hbmImage;
626 HDC hdcMask, hdcImage;
628 ImageList_GetIconSize(himl, &cx, &cy);
630 /* Create src image */
631 hdcImage = CreateCompatibleDC(hdc);
632 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
633 SelectObject(hdcImage, hbmImage);
634 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
635 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
638 hdcMask = CreateCompatibleDC(0);
639 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
640 SelectObject(hdcMask, hbmMask);
642 /* Remove the background and all white pixels */
643 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
644 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
645 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
646 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
648 /* draw the new mask 'etched' to hdc */
649 SetBkColor(hdc, RGB(255, 255, 255));
650 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
651 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
652 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
654 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
657 DeleteObject(hbmImage);
659 DeleteObject (hbmMask);
665 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
669 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
670 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
671 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
672 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
673 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
674 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
675 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
679 /* draws the image on a toolbar button */
681 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
683 HIMAGELIST himl = NULL;
684 BOOL draw_masked = FALSE;
687 UINT draw_flags = ILD_TRANSPARENT;
689 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
691 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
694 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
698 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
700 /* if hot, attempt to draw with hot image list, if fails,
701 use default image list */
702 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
704 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
707 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
712 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
713 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
716 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
717 (tbcd->nmcd.uItemState & CDIS_MARKED))
718 draw_flags |= ILD_BLEND50;
720 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
721 index, himl, left, top, offset);
724 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
726 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
729 /* draws a blank frame for a toolbar button */
731 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd)
733 HDC hdc = tbcd->nmcd.hdc;
734 RECT rc = tbcd->nmcd.rc;
735 /* if the state is disabled or indeterminate then the button
736 * cannot have an interactive look like pressed or hot */
737 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
738 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
739 BOOL pressed_look = !non_interactive_state &&
740 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
741 (tbcd->nmcd.uItemState & CDIS_CHECKED));
743 /* app don't want us to draw any edges */
744 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
747 if (infoPtr->dwStyle & TBSTYLE_FLAT)
750 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
751 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
752 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
757 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
759 DrawEdge (hdc, &rc, EDGE_RAISED,
760 BF_SOFT | BF_RECT | BF_MIDDLE);
765 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
767 HDC hdc = tbcd->nmcd.hdc;
769 BOOL pressed = bDropDownPressed ||
770 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
772 if (infoPtr->dwStyle & TBSTYLE_FLAT)
775 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
776 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
777 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
778 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
779 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
784 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
786 DrawEdge (hdc, rcArrow, EDGE_RAISED,
787 BF_SOFT | BF_RECT | BF_MIDDLE);
791 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
793 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
795 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
796 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
799 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
802 /* draws a complete toolbar button */
804 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
806 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
807 DWORD dwStyle = infoPtr->dwStyle;
808 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
809 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
810 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
811 BOOL drawSepDropDownArrow = hasDropDownArrow &&
812 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
813 RECT rc, rcArrow, rcBitmap, rcText;
814 LPWSTR lpText = NULL;
820 CopyRect (&rcArrow, &rc);
822 /* get a pointer to the text */
823 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
825 if (hasDropDownArrow)
829 if (dwStyle & TBSTYLE_FLAT)
830 right = max(rc.left, rc.right - DDARROW_WIDTH);
832 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
834 if (drawSepDropDownArrow)
837 rcArrow.left = right;
840 /* copy text & bitmap rects after adjusting for drop-down arrow
841 * so that text & bitmap is centred in the rectangle not containing
843 CopyRect(&rcText, &rc);
844 CopyRect(&rcBitmap, &rc);
846 /* Center the bitmap horizontally and vertically */
847 if (dwStyle & TBSTYLE_LIST)
850 infoPtr->nMaxTextRows > 0 &&
851 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
852 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
853 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
855 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
858 rcBitmap.left += (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
860 rcBitmap.top += infoPtr->szPadding.cy / 2;
862 TRACE("iBitmap=%d, start=(%ld,%ld) w=%d, h=%d\n",
863 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
864 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
865 TRACE("Text=%s\n", debugstr_w(lpText));
866 TRACE("iListGap=%d, padding = { %ld, %ld }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
868 /* calculate text position */
871 rcText.left += GetSystemMetrics(SM_CXEDGE);
872 rcText.right -= GetSystemMetrics(SM_CXEDGE);
873 if (dwStyle & TBSTYLE_LIST)
875 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
876 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
880 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
881 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
883 rcText.top += infoPtr->szPadding.cy/2 + 2;
887 /* Initialize fields in all cases, because we use these later
888 * NOTE: applications can and do alter these to customize their
890 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
891 tbcd.clrText = comctl32_color.clrBtnText;
892 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
893 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
894 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
895 tbcd.clrMark = comctl32_color.clrHighlight;
896 tbcd.clrHighlightHotTrack = 0;
897 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
898 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
899 /* MSDN says that this is the text rectangle.
900 * But (why always a but) tracing of v5.7 of native shows
901 * that this is really a *relative* rectangle based on the
902 * the nmcd.rc. Also the left and top are always 0 ignoring
903 * any bitmap that might be present. */
904 tbcd.rcText.left = 0;
906 tbcd.rcText.right = rcText.right - rc.left;
907 tbcd.rcText.bottom = rcText.bottom - rc.top;
908 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
911 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
913 /* FIXME: what are these used for? */
917 /* Issue Item Prepaint notify */
918 infoPtr->dwItemCustDraw = 0;
919 infoPtr->dwItemCDFlag = 0;
920 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
922 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
923 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
924 tbcd.nmcd.lItemlParam = btnPtr->dwData;
925 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
926 /* reset these fields so the user can't alter the behaviour like native */
930 infoPtr->dwItemCustDraw = ntfret & 0xffff;
931 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
932 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
934 /* save the only part of the rect that the user can change */
935 rcText.right = tbcd.rcText.right + rc.left;
936 rcText.bottom = tbcd.rcText.bottom + rc.top;
940 if (btnPtr->fsStyle & BTNS_SEP) {
941 /* with the FLAT style, iBitmap is the width and has already */
942 /* been taken into consideration in calculating the width */
943 /* so now we need to draw the vertical separator */
944 /* empirical tests show that iBitmap can/will be non-zero */
945 /* when drawing the vertical bar... */
946 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
947 if (btnPtr->fsStyle & BTNS_DROPDOWN)
948 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
950 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
952 else if (btnPtr->fsStyle != BTNS_SEP) {
953 FIXME("Draw some kind of separator: fsStyle=%x\n",
959 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
960 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
961 OffsetRect(&rcText, 1, 1);
963 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
964 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
965 TOOLBAR_DrawPattern (&rc, &tbcd);
967 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
969 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
973 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
974 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
975 if (hasDropDownArrow)
976 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
977 SetBkColor(hdc, oldclr);
981 TOOLBAR_DrawFrame(infoPtr, &tbcd);
983 if (drawSepDropDownArrow)
984 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
986 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
987 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
989 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
991 if (hasDropDownArrow && !drawSepDropDownArrow)
993 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
995 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
996 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
998 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1000 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1001 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1004 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1008 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1010 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1011 tbcd.nmcd.hdc = hdc;
1013 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1014 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1015 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1016 tbcd.rcText = rcText;
1017 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1018 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1019 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1026 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1029 TBUTTON_INFO *btnPtr;
1030 INT i, oldBKmode = 0;
1031 RECT rcTemp, rcClient;
1032 NMTBCUSTOMDRAW tbcd;
1035 /* the app has told us not to redraw the toolbar */
1036 if (!infoPtr->bDoRedraw)
1039 /* if imagelist belongs to the app, it can be changed
1040 by the app after setting it */
1041 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1043 infoPtr->nNumBitmaps = 0;
1044 for (i = 0; i < infoPtr->cimlDef; i++)
1045 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1048 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1050 /* Send initial notify */
1051 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1052 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1053 tbcd.nmcd.hdc = hdc;
1054 tbcd.nmcd.rc = ps->rcPaint;
1055 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1056 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1058 if (infoPtr->bBtnTranspnt)
1059 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1061 GetClientRect(hwnd, &rcClient);
1063 /* redraw necessary buttons */
1064 btnPtr = infoPtr->buttons;
1065 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1068 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1070 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1071 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1075 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1076 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1078 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1081 /* draw insert mark if required */
1082 if (infoPtr->tbim.iButton != -1)
1084 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1086 rcInsertMark.top = rcButton.top;
1087 rcInsertMark.bottom = rcButton.bottom;
1088 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1089 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1091 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1092 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1095 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1096 SetBkMode (hdc, oldBKmode);
1098 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1100 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1101 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1102 tbcd.nmcd.hdc = hdc;
1103 tbcd.nmcd.rc = ps->rcPaint;
1104 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1108 /***********************************************************************
1109 * TOOLBAR_MeasureString
1111 * This function gets the width and height of a string in pixels. This
1112 * is done first by using GetTextExtentPoint to get the basic width
1113 * and height. The DrawText is called with DT_CALCRECT to get the exact
1114 * width. The reason is because the text may have more than one "&" (or
1115 * prefix characters as M$ likes to call them). The prefix character
1116 * indicates where the underline goes, except for the string "&&" which
1117 * is reduced to a single "&". GetTextExtentPoint does not process these
1118 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1121 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1122 HDC hdc, LPSIZE lpSize)
1129 if (infoPtr->nMaxTextRows > 0 &&
1130 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1131 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1132 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1134 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1136 if(lpText != NULL) {
1137 /* first get size of all the text */
1138 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1140 /* feed above size into the rectangle for DrawText */
1141 myrect.left = myrect.top = 0;
1142 myrect.right = lpSize->cx;
1143 myrect.bottom = lpSize->cy;
1145 /* Use DrawText to get true size as drawn (less pesky "&") */
1146 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1147 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1150 /* feed back to caller */
1151 lpSize->cx = myrect.right;
1152 lpSize->cy = myrect.bottom;
1156 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1159 /***********************************************************************
1160 * TOOLBAR_CalcStrings
1162 * This function walks through each string and measures it and returns
1163 * the largest height and width to caller.
1166 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1168 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1169 TBUTTON_INFO *btnPtr;
1178 if(infoPtr->nMaxTextRows == 0)
1182 hOldFont = SelectObject (hdc, infoPtr->hFont);
1184 btnPtr = infoPtr->buttons;
1185 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1186 if(TOOLBAR_HasText(infoPtr, btnPtr))
1188 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1189 if (sz.cx > lpSize->cx)
1191 if (sz.cy > lpSize->cy)
1196 SelectObject (hdc, hOldFont);
1197 ReleaseDC (hwnd, hdc);
1199 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1202 /***********************************************************************
1203 * TOOLBAR_WrapToolbar
1205 * This function walks through the buttons and separators in the
1206 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1207 * wrapping should occur based on the width of the toolbar window.
1208 * It does *not* calculate button placement itself. That task
1209 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1210 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1211 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1213 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1214 * vertical toolbar lists.
1218 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1221 TBUTTON_INFO *btnPtr;
1224 BOOL bWrap, bButtonWrap;
1226 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1227 /* no layout is necessary. Applications may use this style */
1228 /* to perform their own layout on the toolbar. */
1229 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1230 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1232 btnPtr = infoPtr->buttons;
1233 x = infoPtr->nIndent;
1235 /* this can get the parents width, to know how far we can extend
1236 * this toolbar. We cannot use its height, as there may be multiple
1237 * toolbars in a rebar control
1239 GetClientRect( GetParent(hwnd), &rc );
1240 infoPtr->nWidth = rc.right - rc.left;
1241 bButtonWrap = FALSE;
1243 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1244 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1247 for (i = 0; i < infoPtr->nNumButtons; i++ )
1250 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1252 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1255 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1256 /* it is the actual width of the separator. This is used for */
1257 /* custom controls in toolbars. */
1259 /* BTNS_DROPDOWN separators are treated as buttons for */
1260 /* width. - GA 8/01 */
1261 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1262 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1263 cx = (btnPtr[i].iBitmap > 0) ?
1264 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1266 cx = infoPtr->nButtonWidth;
1268 /* Two or more adjacent separators form a separator group. */
1269 /* The first separator in a group should be wrapped to the */
1270 /* next row if the previous wrapping is on a button. */
1272 (btnPtr[i].fsStyle & BTNS_SEP) &&
1273 (i + 1 < infoPtr->nNumButtons ) &&
1274 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1276 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1277 btnPtr[i].fsState |= TBSTATE_WRAP;
1278 x = infoPtr->nIndent;
1280 bButtonWrap = FALSE;
1284 /* The layout makes sure the bitmap is visible, but not the button. */
1285 /* Test added to also wrap after a button that starts a row but */
1286 /* is bigger than the area. - GA 8/01 */
1287 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1288 > infoPtr->nWidth ) ||
1289 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1291 BOOL bFound = FALSE;
1293 /* If the current button is a separator and not hidden, */
1294 /* go to the next until it reaches a non separator. */
1295 /* Wrap the last separator if it is before a button. */
1296 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1297 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1298 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1299 i < infoPtr->nNumButtons )
1305 if( bFound && i < infoPtr->nNumButtons )
1308 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1309 i, btnPtr[i].fsStyle, x, cx);
1310 btnPtr[i].fsState |= TBSTATE_WRAP;
1311 x = infoPtr->nIndent;
1312 bButtonWrap = FALSE;
1315 else if ( i >= infoPtr->nNumButtons)
1318 /* If the current button is not a separator, find the last */
1319 /* separator and wrap it. */
1320 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1322 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1323 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1327 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1328 i, btnPtr[i].fsStyle, x, cx);
1329 x = infoPtr->nIndent;
1330 btnPtr[j].fsState |= TBSTATE_WRAP;
1331 bButtonWrap = FALSE;
1336 /* If no separator available for wrapping, wrap one of */
1337 /* non-hidden previous button. */
1341 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1343 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1348 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1349 i, btnPtr[i].fsStyle, x, cx);
1350 x = infoPtr->nIndent;
1351 btnPtr[j].fsState |= TBSTATE_WRAP;
1357 /* If all above failed, wrap the current button. */
1360 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1361 i, btnPtr[i].fsStyle, x, cx);
1362 btnPtr[i].fsState |= TBSTATE_WRAP;
1364 x = infoPtr->nIndent;
1365 if (btnPtr[i].fsStyle & BTNS_SEP )
1366 bButtonWrap = FALSE;
1372 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1373 i, btnPtr[i].fsStyle, x, cx);
1380 /***********************************************************************
1381 * TOOLBAR_MeasureButton
1383 * Calculates the width and height required for a button. Used in
1384 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1385 * the width of buttons that are autosized.
1387 * Note that it would have been rather elegant to use one piece of code for
1388 * both the laying out of the toolbar and for controlling where button parts
1389 * are drawn, but the native control has inconsistencies between the two that
1390 * prevent this from being effectively. These inconsistencies can be seen as
1391 * artefacts where parts of the button appear outside of the bounding button
1394 * There are several cases for the calculation of the button dimensions and
1395 * button part positioning:
1402 * +--------------------------------------------------------+ ^
1404 * | | pad.cy / 2 | centred | |
1405 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1406 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1407 * | |<------------>| | | | |
1408 * | +--------------+ +------------+ | |
1409 * |<-------------------------------------->| | |
1410 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1412 * +--------------------------------------------------------+ -
1413 * <-------------------------------------------------------->
1414 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1416 * Without Bitmap (I_IMAGENONE):
1418 * +-----------------------------------+ ^
1420 * | | centred | | LISTPAD_CY +
1421 * | +------------+ | | szText.cy
1424 * | +------------+ | |
1425 * |<----------------->| | |
1426 * | cxedge |<-----------> | |
1428 * +-----------------------------------+ -
1429 * <----------------------------------->
1430 * szText.cx + pad.cx
1434 * +--------------------------------------+ ^
1436 * | | padding.cy/2 | | DEFPAD_CY +
1437 * | +------------+ | | nBitmapHeight
1440 * | +------------+ | |
1441 * |<------------------->| | |
1442 * | cxedge + iListGap/2 |<-----------> | |
1443 * | nBitmapWidth | |
1444 * +--------------------------------------+ -
1445 * <-------------------------------------->
1446 * 2*cxedge + nBitmapWidth + iListGap
1453 * +-----------------------------------+ ^
1455 * | | pad.cy / 2 | | nBitmapHeight +
1456 * | - | | szText.cy +
1457 * | +------------+ | | DEFPAD_CY + 1
1458 * | centred | Bitmap | | |
1459 * |<----------------->| | | |
1460 * | +------------+ | |
1464 * | centred +---------------+ | |
1465 * |<--------------->| Text | | |
1466 * | +---------------+ | |
1467 * +-----------------------------------+ -
1468 * <----------------------------------->
1469 * pad.cx + max(nBitmapWidth, szText.cx)
1471 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1473 * +---------------------------------------+ ^
1475 * | | 2 + pad.cy / 2 | |
1476 * | - | | szText.cy +
1477 * | centred +-----------------+ | | pad.cy + 2
1478 * |<--------------->| Text | | |
1479 * | +-----------------+ | |
1481 * +---------------------------------------+ -
1482 * <--------------------------------------->
1483 * 2*cxedge + pad.cx + szText.cx
1486 * As for with bitmaps, but with szText.cx zero.
1488 static inline SIZE TOOLBAR_MeasureButton(TOOLBAR_INFO *infoPtr, SIZE sizeString, BOOL bHasBitmap, BOOL bValidImageList)
1491 if (infoPtr->dwStyle & TBSTYLE_LIST)
1493 /* set button height from bitmap / text height... */
1494 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1497 /* ... add on the necessary padding */
1498 if (bValidImageList)
1501 sizeButton.cy += DEFPAD_CY;
1503 sizeButton.cy += LISTPAD_CY;
1506 sizeButton.cy += infoPtr->szPadding.cy;
1508 /* calculate button width */
1511 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1512 infoPtr->nBitmapWidth + infoPtr->iListGap;
1513 if (sizeString.cx > 0)
1514 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1517 sizeButton.cx = sizeString.cx + infoPtr->szPadding.cx;
1523 sizeButton.cy = infoPtr->nBitmapHeight + 1 +
1524 sizeString.cy + DEFPAD_CY;
1525 sizeButton.cx = infoPtr->szPadding.cx +
1526 max(sizeString.cx, infoPtr->nBitmapWidth);
1530 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1531 NONLIST_NOTEXT_OFFSET;
1532 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1533 infoPtr->szPadding.cx + sizeString.cx;
1540 /***********************************************************************
1541 * TOOLBAR_CalcToolbar
1543 * This function calculates button and separator placement. It first
1544 * calculates the button sizes, gets the toolbar window width and then
1545 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1546 * on. It assigns a new location to each item and sends this location to
1547 * the tooltip window if appropriate. Finally, it updates the rcBound
1548 * rect and calculates the new required toolbar window height.
1551 TOOLBAR_CalcToolbar (HWND hwnd)
1553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1554 DWORD dwStyle = infoPtr->dwStyle;
1555 TBUTTON_INFO *btnPtr;
1556 INT i, nRows, nSepRows;
1558 SIZE sizeString, sizeButton;
1560 BOOL usesBitmaps = FALSE;
1561 BOOL validImageList = FALSE;
1562 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1564 TOOLBAR_CalcStrings (hwnd, &sizeString);
1566 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1568 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1570 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1573 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1574 validImageList = TRUE;
1575 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, usesBitmaps, validImageList);
1576 infoPtr->nButtonWidth = sizeButton.cx;
1577 infoPtr->nButtonHeight = sizeButton.cy;
1579 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1580 infoPtr->nButtonWidth = infoPtr->cxMin;
1581 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1582 infoPtr->nButtonWidth = infoPtr->cxMax;
1584 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1586 x = infoPtr->nIndent;
1589 /* from above, minimum is a button, and possible text */
1590 cx = infoPtr->nButtonWidth;
1592 infoPtr->nHeight = infoPtr->nButtonHeight;
1594 cy = infoPtr->nHeight;
1596 nRows = nSepRows = 0;
1598 infoPtr->rcBound.top = y;
1599 infoPtr->rcBound.left = x;
1600 infoPtr->rcBound.bottom = y + cy;
1601 infoPtr->rcBound.right = x;
1603 btnPtr = infoPtr->buttons;
1605 TRACE("cy=%d\n", cy);
1607 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1610 if (btnPtr->fsState & TBSTATE_HIDDEN)
1612 SetRectEmpty (&btnPtr->rect);
1616 cy = infoPtr->nHeight;
1618 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1619 /* it is the actual width of the separator. This is used for */
1620 /* custom controls in toolbars. */
1621 if (btnPtr->fsStyle & BTNS_SEP) {
1622 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1623 cy = (btnPtr->iBitmap > 0) ?
1624 btnPtr->iBitmap : SEPARATOR_WIDTH;
1625 cx = infoPtr->nButtonWidth;
1628 cx = (btnPtr->iBitmap > 0) ?
1629 btnPtr->iBitmap : SEPARATOR_WIDTH;
1635 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1636 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1643 hOldFont = SelectObject (hdc, infoPtr->hFont);
1645 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1647 SelectObject (hdc, hOldFont);
1648 ReleaseDC (hwnd, hdc);
1650 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1651 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1656 cx = infoPtr->nButtonWidth;
1658 /* if size has been set manually then don't add on extra space
1659 * for the drop down arrow */
1660 if (!btnPtr->cx && hasDropDownArrows &&
1661 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1662 cx += DDARROW_WIDTH;
1664 if (btnPtr->fsState & TBSTATE_WRAP )
1667 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1669 if (infoPtr->rcBound.left > x)
1670 infoPtr->rcBound.left = x;
1671 if (infoPtr->rcBound.right < x + cx)
1672 infoPtr->rcBound.right = x + cx;
1673 if (infoPtr->rcBound.bottom < y + cy)
1674 infoPtr->rcBound.bottom = y + cy;
1676 /* Set the toolTip only for non-hidden, non-separator button */
1677 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1681 ZeroMemory (&ti, sizeof(ti));
1682 ti.cbSize = sizeof(ti);
1684 ti.uId = btnPtr->idCommand;
1685 ti.rect = btnPtr->rect;
1686 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1690 /* btnPtr->nRow is zero based. The space between the rows is */
1691 /* also considered as a row. */
1692 btnPtr->nRow = nRows + nSepRows;
1694 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1695 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1700 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1704 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1705 /* it is the actual width of the separator. This is used for */
1706 /* custom controls in toolbars. */
1707 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1708 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1709 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1713 /* nSepRows is used to calculate the extra height follwoing */
1717 x = infoPtr->nIndent;
1719 /* Increment row number unless this is the last button */
1720 /* and it has Wrap set. */
1721 if (i != infoPtr->nNumButtons-1)
1728 /* infoPtr->nRows is the number of rows on the toolbar */
1729 infoPtr->nRows = nRows + nSepRows + 1;
1732 /********************************************************************
1733 * The following while interesting, does not match the values *
1734 * created above for the button rectangles, nor the rcBound rect. *
1735 * We will comment it out and remove it later. *
1737 * The problem showed up as heights in the pager control that was *
1739 ********************************************************************/
1741 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1743 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1744 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1745 nSepRows * (infoPtr->nBitmapHeight + 1) +
1749 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1751 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1756 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1759 TBUTTON_INFO *btnPtr;
1762 btnPtr = infoPtr->buttons;
1763 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1764 if (btnPtr->fsState & TBSTATE_HIDDEN)
1767 if (btnPtr->fsStyle & BTNS_SEP) {
1768 if (PtInRect (&btnPtr->rect, *lpPt)) {
1769 TRACE(" ON SEPARATOR %d!\n", i);
1774 if (PtInRect (&btnPtr->rect, *lpPt)) {
1775 TRACE(" ON BUTTON %d!\n", i);
1781 TRACE(" NOWHERE!\n");
1782 return TOOLBAR_NOWHERE;
1787 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1789 TBUTTON_INFO *btnPtr;
1792 if (CommandIsIndex) {
1793 TRACE("command is really index command=%d\n", idCommand);
1794 if (idCommand >= infoPtr->nNumButtons) return -1;
1797 btnPtr = infoPtr->buttons;
1798 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1799 if (btnPtr->idCommand == idCommand) {
1800 TRACE("command=%d index=%d\n", idCommand, i);
1804 TRACE("no index found for command=%d\n", idCommand);
1810 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1812 TBUTTON_INFO *btnPtr;
1815 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1818 /* check index button */
1819 btnPtr = &infoPtr->buttons[nIndex];
1820 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1821 if (btnPtr->fsState & TBSTATE_CHECKED)
1825 /* check previous buttons */
1826 nRunIndex = nIndex - 1;
1827 while (nRunIndex >= 0) {
1828 btnPtr = &infoPtr->buttons[nRunIndex];
1829 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1830 if (btnPtr->fsState & TBSTATE_CHECKED)
1838 /* check next buttons */
1839 nRunIndex = nIndex + 1;
1840 while (nRunIndex < infoPtr->nNumButtons) {
1841 btnPtr = &infoPtr->buttons[nRunIndex];
1842 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1843 if (btnPtr->fsState & TBSTATE_CHECKED)
1856 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1857 WPARAM wParam, LPARAM lParam)
1863 msg.wParam = wParam;
1864 msg.lParam = lParam;
1865 msg.time = GetMessageTime ();
1866 msg.pt.x = LOWORD(GetMessagePos ());
1867 msg.pt.y = HIWORD(GetMessagePos ());
1869 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1872 /* keeps available button list box sorted by button id */
1873 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1877 PCUSTOMBUTTON btnInfo;
1878 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1880 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1882 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1884 /* position 0 is always separator */
1885 for (i = 1; i < count; i++)
1887 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1888 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1890 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1891 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1895 /* id higher than all others add to end */
1896 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1897 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1900 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1904 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1906 if (nIndexFrom == nIndexTo)
1909 /* MSDN states that iItem is the index of the button, rather than the
1910 * command ID as used by every other NMTOOLBAR notification */
1911 nmtb.iItem = nIndexFrom;
1912 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1914 PCUSTOMBUTTON btnInfo;
1916 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1917 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1919 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1921 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1922 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1923 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1924 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1927 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1929 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1931 /* last item is always separator, so -2 instead of -1 */
1932 if (nIndexTo >= (count - 2))
1933 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1935 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1937 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1938 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1940 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1944 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1948 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1950 /* MSDN states that iItem is the index of the button, rather than the
1951 * command ID as used by every other NMTOOLBAR notification */
1952 nmtb.iItem = nIndexAvail;
1953 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1955 PCUSTOMBUTTON btnInfo;
1957 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1958 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1959 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1961 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1963 if (nIndexAvail != 0) /* index == 0 indicates separator */
1965 /* remove from 'available buttons' list */
1966 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1967 if (nIndexAvail == count-1)
1968 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1970 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1974 PCUSTOMBUTTON btnNew;
1976 /* duplicate 'separator' button */
1977 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1978 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1982 /* insert into 'toolbar button' list */
1983 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1984 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1986 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1988 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1992 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1994 PCUSTOMBUTTON btnInfo;
1995 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1997 TRACE("Remove: index %d\n", index);
1999 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2001 /* send TBN_QUERYDELETE notification */
2002 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2006 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2007 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2009 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2011 /* insert into 'available button' list */
2012 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2013 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2017 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2021 /* drag list notification function for toolbar buttons list box */
2022 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2024 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2025 switch (pDLI->uNotification)
2029 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2030 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2031 /* no dragging for last item (separator) */
2032 if (nCurrentItem >= (nCount - 1)) return FALSE;
2037 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2038 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2039 /* no dragging past last item (separator) */
2040 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2042 DrawInsert(hwnd, hwndList, nCurrentItem);
2043 /* FIXME: native uses "move button" cursor */
2044 return DL_COPYCURSOR;
2047 /* not over toolbar buttons list */
2048 if (nCurrentItem < 0)
2050 POINT ptWindow = pDLI->ptCursor;
2051 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2052 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2053 /* over available buttons list? */
2054 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2055 /* FIXME: native uses "move button" cursor */
2056 return DL_COPYCURSOR;
2058 /* clear drag arrow */
2059 DrawInsert(hwnd, hwndList, -1);
2060 return DL_STOPCURSOR;
2064 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2065 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2066 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2067 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2069 /* clear drag arrow */
2070 DrawInsert(hwnd, hwndList, -1);
2072 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2074 /* not over toolbar buttons list */
2077 POINT ptWindow = pDLI->ptCursor;
2078 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2079 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2080 /* over available buttons list? */
2081 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2082 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2087 /* Clear drag arrow */
2088 DrawInsert(hwnd, hwndList, -1);
2095 /* drag list notification function for available buttons list box */
2096 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
2098 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2099 switch (pDLI->uNotification)
2105 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2106 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2107 /* no dragging past last item (separator) */
2108 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2110 DrawInsert(hwnd, hwndList, nCurrentItem);
2111 /* FIXME: native uses "move button" cursor */
2112 return DL_COPYCURSOR;
2115 /* not over toolbar buttons list */
2116 if (nCurrentItem < 0)
2118 POINT ptWindow = pDLI->ptCursor;
2119 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2120 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2121 /* over available buttons list? */
2122 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2123 /* FIXME: native uses "move button" cursor */
2124 return DL_COPYCURSOR;
2126 /* clear drag arrow */
2127 DrawInsert(hwnd, hwndList, -1);
2128 return DL_STOPCURSOR;
2132 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2133 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2134 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2135 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2137 /* clear drag arrow */
2138 DrawInsert(hwnd, hwndList, -1);
2140 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2144 /* Clear drag arrow */
2145 DrawInsert(hwnd, hwndList, -1);
2151 extern UINT uDragListMessage;
2153 /***********************************************************************
2154 * TOOLBAR_CustomizeDialogProc
2155 * This function implements the toolbar customization dialog.
2157 static INT_PTR CALLBACK
2158 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2160 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2161 PCUSTOMBUTTON btnInfo;
2163 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2168 custInfo = (PCUSTDLG_INFO)lParam;
2169 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2177 infoPtr = custInfo->tbInfo;
2179 /* send TBN_QUERYINSERT notification */
2180 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2182 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2185 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2186 /* FIXME: this hack won't work on 64-bit - we need to declare a structure for this */
2187 nmtb.iItem = (int)hwnd;
2188 /* Send TBN_INITCUSTOMIZE notification */
2189 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2192 TRACE("TBNRF_HIDEHELP requested\n");
2193 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2196 /* add items to 'toolbar buttons' list and check if removable */
2197 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2199 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2200 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2201 btnInfo->btn.fsStyle = BTNS_SEP;
2202 btnInfo->bVirtual = FALSE;
2203 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2205 /* send TBN_QUERYDELETE notification */
2206 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2208 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2209 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2212 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2214 /* insert separator button into 'available buttons' list */
2215 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2216 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2217 btnInfo->btn.fsStyle = BTNS_SEP;
2218 btnInfo->bVirtual = FALSE;
2219 btnInfo->bRemovable = TRUE;
2220 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2221 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2222 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2224 /* insert all buttons into dsa */
2227 /* send TBN_GETBUTTONINFO notification */
2230 nmtb.pszText = Buffer;
2233 /* Clear previous button's text */
2234 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2236 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2239 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2240 nmtb.tbButton.fsStyle, i,
2241 nmtb.tbButton.idCommand,
2242 nmtb.tbButton.iString,
2243 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2246 /* insert button into the apropriate list */
2247 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2250 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2251 btnInfo->bVirtual = FALSE;
2252 btnInfo->bRemovable = TRUE;
2256 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2257 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2260 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2261 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2263 if (lstrlenW(nmtb.pszText))
2264 lstrcpyW(btnInfo->text, nmtb.pszText);
2265 else if (nmtb.tbButton.iString >= 0 &&
2266 nmtb.tbButton.iString < infoPtr->nNumStrings)
2268 lstrcpyW(btnInfo->text,
2269 infoPtr->strings[nmtb.tbButton.iString]);
2274 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2277 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2279 /* select first item in the 'available' list */
2280 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2282 /* append 'virtual' separator button to the 'toolbar buttons' list */
2283 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2284 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2285 btnInfo->btn.fsStyle = BTNS_SEP;
2286 btnInfo->bVirtual = TRUE;
2287 btnInfo->bRemovable = FALSE;
2288 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2289 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2290 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2292 /* select last item in the 'toolbar' list */
2293 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2294 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2296 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2297 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2299 /* set focus and disable buttons */
2300 PostMessageW (hwnd, WM_USER, 0, 0);
2305 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2306 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2307 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2308 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2312 EndDialog(hwnd, FALSE);
2316 switch (LOWORD(wParam))
2318 case IDC_TOOLBARBTN_LBOX:
2319 if (HIWORD(wParam) == LBN_SELCHANGE)
2321 PCUSTOMBUTTON btnInfo;
2326 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2327 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2329 /* send TBN_QUERYINSERT notification */
2331 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2333 /* get list box item */
2334 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2336 if (index == (count - 1))
2338 /* last item (virtual separator) */
2339 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2340 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2342 else if (index == (count - 2))
2344 /* second last item (last non-virtual item) */
2345 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2346 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2348 else if (index == 0)
2351 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2352 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2356 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2357 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2360 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2364 case IDC_MOVEUP_BTN:
2366 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2367 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2371 case IDC_MOVEDN_BTN: /* move down */
2373 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2374 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2378 case IDC_REMOVE_BTN: /* remove button */
2380 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2382 if (LB_ERR == index)
2385 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2389 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2392 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2395 case IDOK: /* Add button */
2400 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2401 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2403 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2408 EndDialog(hwnd, FALSE);
2418 /* delete items from 'toolbar buttons' listbox*/
2419 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2420 for (i = 0; i < count; i++)
2422 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2424 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2426 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2429 /* delete items from 'available buttons' listbox*/
2430 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2431 for (i = 0; i < count; i++)
2433 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2435 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2437 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2442 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2444 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2449 COLORREF oldText = 0;
2453 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2454 if (btnInfo == NULL)
2456 FIXME("btnInfo invalid!\n");
2460 /* set colors and select objects */
2461 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2462 if (btnInfo->bVirtual)
2463 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2465 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2466 hPen = CreatePen( PS_SOLID, 1,
2467 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2468 hOldPen = SelectObject (lpdis->hDC, hPen );
2469 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2471 /* fill background rectangle */
2472 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2473 lpdis->rcItem.right, lpdis->rcItem.bottom);
2475 /* calculate button and text rectangles */
2476 CopyRect (&rcButton, &lpdis->rcItem);
2477 InflateRect (&rcButton, -1, -1);
2478 CopyRect (&rcText, &rcButton);
2479 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2480 rcText.left = rcButton.right + 2;
2482 /* draw focus rectangle */
2483 if (lpdis->itemState & ODS_FOCUS)
2484 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2487 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2488 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2490 /* draw image and text */
2491 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2492 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2493 btnInfo->btn.iBitmap));
2494 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2495 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2497 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2498 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2500 /* delete objects and reset colors */
2501 SelectObject (lpdis->hDC, hOldBrush);
2502 SelectObject (lpdis->hDC, hOldPen);
2503 SetBkColor (lpdis->hDC, oldBk);
2504 SetTextColor (lpdis->hDC, oldText);
2505 DeleteObject( hPen );
2510 case WM_MEASUREITEM:
2511 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2513 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2515 lpmis->itemHeight = 15 + 8; /* default height */
2522 if (uDragListMessage && (uMsg == uDragListMessage))
2524 if (wParam == IDC_TOOLBARBTN_LBOX)
2526 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2527 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2528 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2531 else if (wParam == IDC_AVAILBTN_LBOX)
2533 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2534 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2535 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2544 /***********************************************************************
2545 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2549 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2552 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2553 INT nIndex = 0, nButtons, nCount;
2557 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2561 if (lpAddBmp->hInst == HINST_COMMCTRL)
2563 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2565 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2567 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2572 TRACE ("adding %d internal bitmaps!\n", nButtons);
2574 /* Windows resize all the buttons to the size of a newly added standard image */
2575 if (lpAddBmp->nID & 1)
2578 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2579 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2581 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2582 MAKELPARAM((WORD)24, (WORD)24));
2583 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2584 MAKELPARAM((WORD)31, (WORD)30));
2589 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2590 MAKELPARAM((WORD)16, (WORD)16));
2591 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2592 MAKELPARAM((WORD)22, (WORD)22));
2595 TOOLBAR_CalcToolbar (hwnd);
2599 nButtons = (INT)wParam;
2603 TRACE ("adding %d bitmaps!\n", nButtons);
2606 if (!infoPtr->cimlDef) {
2607 /* create new default image list */
2608 TRACE ("creating default image list!\n");
2610 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2611 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2612 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2613 infoPtr->himlInt = himlDef;
2616 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2620 WARN("No default image list available\n");
2624 nCount = ImageList_GetImageCount(himlDef);
2626 /* Add bitmaps to the default image list */
2627 if (lpAddBmp->hInst == NULL)
2630 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2631 HDC hdcImage, hdcBitmap;
2633 /* copy the bitmap before adding it so that the user's bitmap
2634 * doesn't get modified.
2636 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2638 hdcImage = CreateCompatibleDC(0);
2639 hdcBitmap = CreateCompatibleDC(0);
2641 /* create new bitmap */
2642 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2643 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2644 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2646 /* Copy the user's image */
2647 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2648 hdcBitmap, 0, 0, SRCCOPY);
2650 SelectObject (hdcImage, hOldBitmapLoad);
2651 SelectObject (hdcBitmap, hOldBitmapBitmap);
2652 DeleteDC (hdcImage);
2653 DeleteDC (hdcBitmap);
2655 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2656 DeleteObject (hbmLoad);
2658 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2660 /* Add system bitmaps */
2661 switch (lpAddBmp->nID)
2663 case IDB_STD_SMALL_COLOR:
2664 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2665 MAKEINTRESOURCEW(IDB_STD_SMALL));
2666 nIndex = ImageList_AddMasked (himlDef,
2667 hbmLoad, comctl32_color.clrBtnFace);
2668 DeleteObject (hbmLoad);
2671 case IDB_STD_LARGE_COLOR:
2672 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2673 MAKEINTRESOURCEW(IDB_STD_LARGE));
2674 nIndex = ImageList_AddMasked (himlDef,
2675 hbmLoad, comctl32_color.clrBtnFace);
2676 DeleteObject (hbmLoad);
2679 case IDB_VIEW_SMALL_COLOR:
2680 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2681 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2682 nIndex = ImageList_AddMasked (himlDef,
2683 hbmLoad, comctl32_color.clrBtnFace);
2684 DeleteObject (hbmLoad);
2687 case IDB_VIEW_LARGE_COLOR:
2688 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2689 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2690 nIndex = ImageList_AddMasked (himlDef,
2691 hbmLoad, comctl32_color.clrBtnFace);
2692 DeleteObject (hbmLoad);
2695 case IDB_HIST_SMALL_COLOR:
2696 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2697 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2698 nIndex = ImageList_AddMasked (himlDef,
2699 hbmLoad, comctl32_color.clrBtnFace);
2700 DeleteObject (hbmLoad);
2703 case IDB_HIST_LARGE_COLOR:
2704 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2705 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2706 nIndex = ImageList_AddMasked (himlDef,
2707 hbmLoad, comctl32_color.clrBtnFace);
2708 DeleteObject (hbmLoad);
2712 nIndex = ImageList_GetImageCount (himlDef);
2713 ERR ("invalid imagelist!\n");
2719 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2720 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2721 DeleteObject (hbmLoad);
2724 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2726 if (infoPtr->nNumBitmapInfos == 0)
2728 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2732 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2733 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2734 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos * sizeof(TBITMAP_INFO));
2737 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2738 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2739 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2741 infoPtr->nNumBitmapInfos++;
2742 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2746 INT imagecount = ImageList_GetImageCount(himlDef);
2748 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2750 WARN("Desired images do not match received images : Previous image number %i Previous images in list %i added %i expecting total %i, Images in list %i\n",
2751 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2752 infoPtr->nNumBitmaps+nButtons,imagecount);
2754 infoPtr->nNumBitmaps = imagecount;
2757 infoPtr->nNumBitmaps += nButtons;
2760 InvalidateRect(hwnd, NULL, TRUE);
2767 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2770 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2771 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2773 TRACE("adding %d buttons!\n", wParam);
2775 nAddButtons = (UINT)wParam;
2776 nOldButtons = infoPtr->nNumButtons;
2777 nNewButtons = nOldButtons + nAddButtons;
2779 if (infoPtr->nNumButtons == 0) {
2781 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2784 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2786 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2787 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2788 nOldButtons * sizeof(TBUTTON_INFO));
2792 infoPtr->nNumButtons = nNewButtons;
2794 /* insert new button data */
2795 for (nCount = 0; nCount < nAddButtons; nCount++) {
2796 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2797 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2798 btnPtr->idCommand = lpTbb[nCount].idCommand;
2799 btnPtr->fsState = lpTbb[nCount].fsState;
2800 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2801 btnPtr->dwData = lpTbb[nCount].dwData;
2802 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2803 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2805 btnPtr->iString = lpTbb[nCount].iString;
2806 btnPtr->bHot = FALSE;
2808 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2811 ZeroMemory (&ti, sizeof(ti));
2812 ti.cbSize = sizeof(ti);
2814 ti.uId = btnPtr->idCommand;
2816 ti.lpszText = LPSTR_TEXTCALLBACKW;
2818 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2823 TOOLBAR_CalcToolbar (hwnd);
2825 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2827 InvalidateRect(hwnd, NULL, TRUE);
2834 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2836 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2837 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2838 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2840 TRACE("adding %d buttons!\n", wParam);
2842 nAddButtons = (UINT)wParam;
2843 nOldButtons = infoPtr->nNumButtons;
2844 nNewButtons = nOldButtons + nAddButtons;
2846 if (infoPtr->nNumButtons == 0) {
2848 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2851 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2853 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2854 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2855 nOldButtons * sizeof(TBUTTON_INFO));
2859 infoPtr->nNumButtons = nNewButtons;
2861 /* insert new button data */
2862 for (nCount = 0; nCount < nAddButtons; nCount++) {
2863 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2864 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2865 btnPtr->idCommand = lpTbb[nCount].idCommand;
2866 btnPtr->fsState = lpTbb[nCount].fsState;
2867 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2868 btnPtr->dwData = lpTbb[nCount].dwData;
2869 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2870 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2872 btnPtr->iString = lpTbb[nCount].iString;
2873 btnPtr->bHot = FALSE;
2875 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2878 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2879 ti.cbSize = sizeof (TTTOOLINFOW);
2881 ti.uId = btnPtr->idCommand;
2883 ti.lpszText = LPSTR_TEXTCALLBACKW;
2886 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2891 TOOLBAR_CalcToolbar (hwnd);
2893 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2895 InvalidateRect(hwnd, NULL, TRUE);
2902 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2907 if ((wParam) && (HIWORD(lParam) == 0)) {
2910 TRACE("adding string from resource!\n");
2912 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2914 TRACE("len=%d \"%s\"\n", len, szString);
2915 nIndex = infoPtr->nNumStrings;
2916 if (infoPtr->nNumStrings == 0) {
2918 Alloc (sizeof(LPWSTR));
2921 LPWSTR *oldStrings = infoPtr->strings;
2923 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2924 memcpy (&infoPtr->strings[0], &oldStrings[0],
2925 sizeof(LPWSTR) * infoPtr->nNumStrings);
2929 /*Alloc zeros out the allocated memory*/
2930 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2931 infoPtr->nNumStrings++;
2934 LPSTR p = (LPSTR)lParam;
2939 TRACE("adding string(s) from array!\n");
2941 nIndex = infoPtr->nNumStrings;
2944 TRACE("len=%d \"%s\"\n", len, p);
2946 if (infoPtr->nNumStrings == 0) {
2948 Alloc (sizeof(LPWSTR));
2951 LPWSTR *oldStrings = infoPtr->strings;
2953 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2954 memcpy (&infoPtr->strings[0], &oldStrings[0],
2955 sizeof(LPWSTR) * infoPtr->nNumStrings);
2959 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2960 infoPtr->nNumStrings++;
2971 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2973 #define MAX_RESOURCE_STRING_LENGTH 512
2974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2977 if ((wParam) && (HIWORD(lParam) == 0)) {
2978 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2980 TRACE("adding string from resource!\n");
2982 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2983 szString, MAX_RESOURCE_STRING_LENGTH);
2985 TRACE("len=%d %s\n", len, debugstr_w(szString));
2986 TRACE("First char: 0x%x\n", *szString);
2987 if (szString[0] == L'|')
2989 PWSTR p = szString + 1;
2991 nIndex = infoPtr->nNumStrings;
2992 while (*p != L'|' && *p != L'\0') {
2995 if (infoPtr->nNumStrings == 0) {
2996 infoPtr->strings = Alloc (sizeof(LPWSTR));
3000 LPWSTR *oldStrings = infoPtr->strings;
3001 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3002 memcpy(&infoPtr->strings[0], &oldStrings[0],
3003 sizeof(LPWSTR) * infoPtr->nNumStrings);
3007 np=strchrW (p, '|');
3015 TRACE("len=%d %s\n", len, debugstr_w(p));
3016 infoPtr->strings[infoPtr->nNumStrings] =
3017 Alloc (sizeof(WCHAR)*(len+1));
3018 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
3019 infoPtr->nNumStrings++;
3026 nIndex = infoPtr->nNumStrings;
3027 if (infoPtr->nNumStrings == 0) {
3029 Alloc (sizeof(LPWSTR));
3032 LPWSTR *oldStrings = infoPtr->strings;
3034 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3035 memcpy (&infoPtr->strings[0], &oldStrings[0],
3036 sizeof(LPWSTR) * infoPtr->nNumStrings);
3040 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
3041 infoPtr->nNumStrings++;
3045 LPWSTR p = (LPWSTR)lParam;
3050 TRACE("adding string(s) from array!\n");
3051 nIndex = infoPtr->nNumStrings;
3055 TRACE("len=%d %s\n", len, debugstr_w(p));
3056 if (infoPtr->nNumStrings == 0) {
3058 Alloc (sizeof(LPWSTR));
3061 LPWSTR *oldStrings = infoPtr->strings;
3063 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
3064 memcpy (&infoPtr->strings[0], &oldStrings[0],
3065 sizeof(LPWSTR) * infoPtr->nNumStrings);
3069 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3070 infoPtr->nNumStrings++;
3081 TOOLBAR_AutoSize (HWND hwnd)
3083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3089 UINT uPosFlags = SWP_NOZORDER;
3091 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
3093 parent = GetParent (hwnd);
3094 GetClientRect(parent, &parent_rect);
3096 x = parent_rect.left;
3097 y = parent_rect.top;
3099 /* FIXME: we should be able to early out if nothing */
3100 /* has changed with nWidth != parent_rect width */
3102 if (infoPtr->dwStyle & CCS_NORESIZE) {
3103 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3106 TOOLBAR_CalcToolbar (hwnd);
3109 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3110 TOOLBAR_CalcToolbar (hwnd);
3111 InvalidateRect( hwnd, NULL, TRUE );
3112 cy = infoPtr->nHeight;
3113 cx = infoPtr->nWidth;
3115 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3116 GetWindowRect(hwnd, &window_rect);
3117 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3118 y = window_rect.top;
3120 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3121 GetWindowRect(hwnd, &window_rect);
3122 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3126 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3127 uPosFlags |= SWP_NOMOVE;
3129 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3130 cy += GetSystemMetrics(SM_CYEDGE);
3132 if (infoPtr->dwStyle & WS_BORDER)
3135 cy += GetSystemMetrics(SM_CYEDGE);
3136 cx += GetSystemMetrics(SM_CXEDGE);
3139 infoPtr->bAutoSize = TRUE;
3140 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3141 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3142 * after the setwindowpos calls */
3143 infoPtr->bAutoSize = FALSE;
3150 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3154 return infoPtr->nNumButtons;
3159 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3163 infoPtr->dwStructSize = (DWORD)wParam;
3170 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 TBUTTON_INFO *btnPtr;
3176 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3178 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3182 btnPtr = &infoPtr->buttons[nIndex];
3183 btnPtr->iBitmap = LOWORD(lParam);
3185 /* we HAVE to erase the background, the new bitmap could be */
3187 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3194 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3197 TBUTTON_INFO *btnPtr;
3200 BOOL bChecked = FALSE;
3202 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3204 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3209 btnPtr = &infoPtr->buttons[nIndex];
3211 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3213 if (LOWORD(lParam) == FALSE)
3214 btnPtr->fsState &= ~TBSTATE_CHECKED;
3216 if (btnPtr->fsStyle & BTNS_GROUP) {
3218 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3219 if (nOldIndex == nIndex)
3221 if (nOldIndex != -1)
3222 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3224 btnPtr->fsState |= TBSTATE_CHECKED;
3227 if( bChecked != LOWORD(lParam) )
3229 if (nOldIndex != -1)
3230 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3231 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3234 /* FIXME: Send a WM_NOTIFY?? */
3241 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3243 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3245 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3250 TOOLBAR_Customize (HWND hwnd)
3252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3253 CUSTDLG_INFO custInfo;
3259 custInfo.tbInfo = infoPtr;
3260 custInfo.tbHwnd = hwnd;
3262 /* send TBN_BEGINADJUST notification */
3263 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3265 if (!(hRes = FindResourceW (COMCTL32_hModule,
3266 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3267 (LPWSTR)RT_DIALOG)))
3270 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3273 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3274 (LPDLGTEMPLATEW)template,
3276 TOOLBAR_CustomizeDialogProc,
3279 /* send TBN_ENDADJUST notification */
3280 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3287 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3290 INT nIndex = (INT)wParam;
3292 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3294 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3297 memset(&nmtb, 0, sizeof(nmtb));
3298 nmtb.iItem = btnPtr->idCommand;
3299 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3300 nmtb.tbButton.idCommand = btnPtr->idCommand;
3301 nmtb.tbButton.fsState = btnPtr->fsState;
3302 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3303 nmtb.tbButton.dwData = btnPtr->dwData;
3304 nmtb.tbButton.iString = btnPtr->iString;
3305 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3307 if ((infoPtr->hwndToolTip) &&
3308 !(btnPtr->fsStyle & BTNS_SEP)) {
3311 ZeroMemory (&ti, sizeof(ti));
3312 ti.cbSize = sizeof(ti);
3314 ti.uId = infoPtr->buttons[nIndex].idCommand;
3316 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3319 if (infoPtr->nNumButtons == 1) {
3320 TRACE(" simple delete!\n");
3321 Free (infoPtr->buttons);
3322 infoPtr->buttons = NULL;
3323 infoPtr->nNumButtons = 0;
3326 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3327 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3329 infoPtr->nNumButtons--;
3330 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3332 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3333 nIndex * sizeof(TBUTTON_INFO));
3336 if (nIndex < infoPtr->nNumButtons) {
3337 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3338 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3344 TOOLBAR_CalcToolbar (hwnd);
3346 InvalidateRect (hwnd, NULL, TRUE);
3353 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3356 TBUTTON_INFO *btnPtr;
3360 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3362 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3367 btnPtr = &infoPtr->buttons[nIndex];
3369 bState = btnPtr->fsState & TBSTATE_ENABLED;
3371 /* update the toolbar button state */
3372 if(LOWORD(lParam) == FALSE) {
3373 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3375 btnPtr->fsState |= TBSTATE_ENABLED;
3378 /* redraw the button only if the state of the button changed */
3379 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3380 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3386 static inline LRESULT
3387 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3391 return infoPtr->bAnchor;
3396 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3398 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3401 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3405 return infoPtr->buttons[nIndex].iBitmap;
3409 static inline LRESULT
3410 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3412 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3417 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3420 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3421 INT nIndex = (INT)wParam;
3422 TBUTTON_INFO *btnPtr;
3427 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3430 btnPtr = &infoPtr->buttons[nIndex];
3431 lpTbb->iBitmap = btnPtr->iBitmap;
3432 lpTbb->idCommand = btnPtr->idCommand;
3433 lpTbb->fsState = btnPtr->fsState;
3434 lpTbb->fsStyle = btnPtr->fsStyle;
3435 lpTbb->bReserved[0] = 0;
3436 lpTbb->bReserved[1] = 0;
3437 lpTbb->dwData = btnPtr->dwData;
3438 lpTbb->iString = btnPtr->iString;
3445 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3448 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3449 TBUTTON_INFO *btnPtr;
3452 if (lpTbInfo == NULL)
3454 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3457 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3458 lpTbInfo->dwMask & 0x80000000);
3462 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3464 if (lpTbInfo->dwMask & TBIF_COMMAND)
3465 lpTbInfo->idCommand = btnPtr->idCommand;
3466 if (lpTbInfo->dwMask & TBIF_IMAGE)
3467 lpTbInfo->iImage = btnPtr->iBitmap;
3468 if (lpTbInfo->dwMask & TBIF_LPARAM)
3469 lpTbInfo->lParam = btnPtr->dwData;
3470 if (lpTbInfo->dwMask & TBIF_SIZE)
3471 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3472 if (lpTbInfo->dwMask & TBIF_STATE)
3473 lpTbInfo->fsState = btnPtr->fsState;
3474 if (lpTbInfo->dwMask & TBIF_STYLE)
3475 lpTbInfo->fsStyle = btnPtr->fsStyle;
3476 if (lpTbInfo->dwMask & TBIF_TEXT) {
3477 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3478 can't use TOOLBAR_GetText here */
3480 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3481 lpText = (LPWSTR)btnPtr->iString;
3482 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3484 lpTbInfo->pszText[0] = '\0';
3491 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3494 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3495 TBUTTON_INFO *btnPtr;
3498 if (lpTbInfo == NULL)
3500 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3503 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3504 lpTbInfo->dwMask & 0x80000000);
3508 btnPtr = &infoPtr->buttons[nIndex];
3513 if (lpTbInfo->dwMask & TBIF_COMMAND)
3514 lpTbInfo->idCommand = btnPtr->idCommand;
3515 if (lpTbInfo->dwMask & TBIF_IMAGE)
3516 lpTbInfo->iImage = btnPtr->iBitmap;
3517 if (lpTbInfo->dwMask & TBIF_LPARAM)
3518 lpTbInfo->lParam = btnPtr->dwData;
3519 if (lpTbInfo->dwMask & TBIF_SIZE)
3520 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3521 if (lpTbInfo->dwMask & TBIF_STATE)
3522 lpTbInfo->fsState = btnPtr->fsState;
3523 if (lpTbInfo->dwMask & TBIF_STYLE)
3524 lpTbInfo->fsStyle = btnPtr->fsStyle;
3525 if (lpTbInfo->dwMask & TBIF_TEXT) {
3526 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3527 can't use TOOLBAR_GetText here */
3529 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3530 lpText = (LPWSTR)btnPtr->iString;
3531 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3533 lpTbInfo->pszText[0] = '\0';
3541 TOOLBAR_GetButtonSize (HWND hwnd)
3543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3545 if (infoPtr->nNumButtons > 0)
3546 return MAKELONG((WORD)infoPtr->nButtonWidth,
3547 (WORD)infoPtr->nButtonHeight);
3549 return MAKELONG(23,22);
3554 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3556 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3563 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3567 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3569 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3570 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3575 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3582 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3586 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3590 ret = strlenW (lpText);
3593 strcpyW ((LPWSTR)lParam, lpText);
3601 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3604 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3605 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3609 inline static LRESULT
3610 TOOLBAR_GetExtendedStyle (HWND hwnd)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3616 return infoPtr->dwExStyle;
3621 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3623 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3624 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3625 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3630 TOOLBAR_GetHotItem (HWND hwnd)
3632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3634 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3637 if (infoPtr->nHotItem < 0)
3640 return (LRESULT)infoPtr->nHotItem;
3645 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3647 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3648 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3649 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3654 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3656 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3657 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3659 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3661 *lptbim = infoPtr->tbim;
3668 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3672 TRACE("hwnd = %p\n", hwnd);
3674 return (LRESULT)infoPtr->clrInsertMark;
3679 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3682 TBUTTON_INFO *btnPtr;
3686 nIndex = (INT)wParam;
3687 btnPtr = &infoPtr->buttons[nIndex];
3688 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3690 lpRect = (LPRECT)lParam;
3693 if (btnPtr->fsState & TBSTATE_HIDDEN)
3696 lpRect->left = btnPtr->rect.left;
3697 lpRect->right = btnPtr->rect.right;
3698 lpRect->bottom = btnPtr->rect.bottom;
3699 lpRect->top = btnPtr->rect.top;
3706 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3709 LPSIZE lpSize = (LPSIZE)lParam;
3714 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3715 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3717 TRACE("maximum size %ld x %ld\n",
3718 infoPtr->rcBound.right - infoPtr->rcBound.left,
3719 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3725 /* << TOOLBAR_GetObject >> */
3729 TOOLBAR_GetPadding (HWND hwnd)
3731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3734 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3735 return (LRESULT) oldPad;
3740 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3743 TBUTTON_INFO *btnPtr;
3747 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3748 btnPtr = &infoPtr->buttons[nIndex];
3749 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3751 lpRect = (LPRECT)lParam;
3755 lpRect->left = btnPtr->rect.left;
3756 lpRect->right = btnPtr->rect.right;
3757 lpRect->bottom = btnPtr->rect.bottom;
3758 lpRect->top = btnPtr->rect.top;
3765 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3767 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3769 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3770 return infoPtr->nRows;
3777 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3782 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3786 return infoPtr->buttons[nIndex].fsState;
3791 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3793 return GetWindowLongW(hwnd, GWL_STYLE);
3798 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3802 return infoPtr->nMaxTextRows;
3807 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3811 return (LRESULT)infoPtr->hwndToolTip;
3816 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3820 TRACE("%s hwnd=%p\n",
3821 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3823 return infoPtr->bUnicode;
3827 inline static LRESULT
3828 TOOLBAR_GetVersion (HWND hwnd)
3830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3831 return infoPtr->iVersion;
3836 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3839 TBUTTON_INFO *btnPtr;
3844 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3848 btnPtr = &infoPtr->buttons[nIndex];
3849 if (LOWORD(lParam) == FALSE)
3850 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3852 btnPtr->fsState |= TBSTATE_HIDDEN;
3854 TOOLBAR_CalcToolbar (hwnd);
3856 InvalidateRect (hwnd, NULL, TRUE);
3862 inline static LRESULT
3863 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3865 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3870 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3872 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3873 TBUTTON_INFO *btnPtr;
3877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3881 btnPtr = &infoPtr->buttons[nIndex];
3882 oldState = btnPtr->fsState;
3883 if (LOWORD(lParam) == FALSE)
3884 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3886 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3888 if(oldState != btnPtr->fsState)
3889 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3896 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3899 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3900 INT nIndex = (INT)wParam;
3901 TBUTTON_INFO *oldButtons;
3906 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3909 /* EPP: this seems to be an undocumented call (from my IE4)
3910 * I assume in that case that:
3911 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3912 * - index of insertion is at the end of existing buttons
3913 * I only see this happen with nIndex == -1, but it could have a special
3914 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3916 nIndex = infoPtr->nNumButtons;
3918 } else if (nIndex < 0)
3921 /* If the string passed is not an index, assume address of string
3922 and do our own AddString */
3923 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3927 TRACE("string %s passed instead of index, adding string\n",
3928 debugstr_a((LPSTR)lpTbb->iString));
3929 len = strlen((LPSTR)lpTbb->iString) + 2;
3931 strcpy(ptr, (LPSTR)lpTbb->iString);
3932 ptr[len - 1] = 0; /* ended by two '\0' */
3933 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3937 TRACE("inserting button index=%d\n", nIndex);
3938 if (nIndex > infoPtr->nNumButtons) {
3939 nIndex = infoPtr->nNumButtons;
3940 TRACE("adjust index=%d\n", nIndex);
3943 oldButtons = infoPtr->buttons;
3944 infoPtr->nNumButtons++;
3945 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3946 /* pre insert copy */
3948 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3949 nIndex * sizeof(TBUTTON_INFO));
3952 /* insert new button */
3953 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3954 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3955 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3956 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3957 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3958 /* if passed string and not index, then add string */
3959 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3960 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3963 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3965 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3968 ZeroMemory (&ti, sizeof(ti));
3969 ti.cbSize = sizeof (ti);
3971 ti.uId = lpTbb->idCommand;
3973 ti.lpszText = LPSTR_TEXTCALLBACKW;
3975 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3979 /* post insert copy */
3980 if (nIndex < infoPtr->nNumButtons - 1) {
3981 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3982 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3987 TOOLBAR_CalcToolbar (hwnd);
3989 InvalidateRect (hwnd, NULL, TRUE);
3996 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3998 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3999 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
4000 INT nIndex = (INT)wParam;
4001 TBUTTON_INFO *oldButtons;
4006 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
4009 /* EPP: this seems to be an undocumented call (from my IE4)
4010 * I assume in that case that:
4011 * - lpTbb->iString is a string pointer (not a string index in strings[] table
4012 * - index of insertion is at the end of existing buttons
4013 * I only see this happen with nIndex == -1, but it could have a special
4014 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
4016 nIndex = infoPtr->nNumButtons;
4018 } else if (nIndex < 0)
4021 /* If the string passed is not an index, assume address of string
4022 and do our own AddString */
4023 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
4027 TRACE("string %s passed instead of index, adding string\n",
4028 debugstr_w((LPWSTR)lpTbb->iString));
4029 len = strlenW((LPWSTR)lpTbb->iString) + 2;
4030 ptr = Alloc(len*sizeof(WCHAR));
4031 strcpyW(ptr, (LPWSTR)lpTbb->iString);
4032 ptr[len - 1] = 0; /* ended by two '\0' */
4033 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
4037 TRACE("inserting button index=%d\n", nIndex);
4038 if (nIndex > infoPtr->nNumButtons) {
4039 nIndex = infoPtr->nNumButtons;
4040 TRACE("adjust index=%d\n", nIndex);
4043 oldButtons = infoPtr->buttons;
4044 infoPtr->nNumButtons++;
4045 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
4046 /* pre insert copy */
4048 memcpy (&infoPtr->buttons[0], &oldButtons[0],
4049 nIndex * sizeof(TBUTTON_INFO));
4052 /* insert new button */
4053 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
4054 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
4055 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
4056 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
4057 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
4058 /* if passed string and not index, then add string */
4059 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
4060 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
4063 infoPtr->buttons[nIndex].iString = lpTbb->iString;
4065 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
4068 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
4069 ti.cbSize = sizeof (TTTOOLINFOW);
4071 ti.uId = lpTbb->idCommand;
4073 ti.lpszText = LPSTR_TEXTCALLBACKW;
4075 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
4079 /* post insert copy */
4080 if (nIndex < infoPtr->nNumButtons - 1) {
4081 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4082 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4087 TOOLBAR_CalcToolbar (hwnd);
4089 InvalidateRect (hwnd, NULL, TRUE);
4095 /* << TOOLBAR_InsertMarkHitTest >> */
4099 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4108 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4113 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4118 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4122 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4127 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4132 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4136 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4141 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4146 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4150 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4155 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4157 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4160 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4164 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4169 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4174 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4178 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4183 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4186 tbab.hInst = (HINSTANCE)lParam;
4187 tbab.nID = (UINT_PTR)wParam;
4189 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4191 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4196 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4198 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4199 WCHAR wAccel = (WCHAR)wParam;
4200 UINT* pIDButton = (UINT*)lParam;
4201 WCHAR wszAccel[] = {'&',wAccel,0};
4204 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4205 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4207 for (i = 0; i < infoPtr->nNumButtons; i++)
4209 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4210 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4211 !(btnPtr->fsState & TBSTATE_HIDDEN))
4213 int iLen = strlenW(wszAccel);
4214 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4221 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4226 if (!strncmpiW(lpszStr, wszAccel, iLen))
4228 *pIDButton = btnPtr->idCommand;
4240 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4245 TBUTTON_INFO *btnPtr;
4247 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4249 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4253 btnPtr = &infoPtr->buttons[nIndex];
4254 oldState = btnPtr->fsState;
4257 btnPtr->fsState |= TBSTATE_MARKED;
4259 btnPtr->fsState &= ~TBSTATE_MARKED;
4261 if(oldState != btnPtr->fsState)
4262 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4268 /* fixes up an index of a button affected by a move */
4269 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4273 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4275 else if (*pIndex == nIndex)
4276 *pIndex = nMoveIndex;
4280 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4282 else if (*pIndex == nIndex)
4283 *pIndex = nMoveIndex;
4289 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4294 INT nMoveIndex = (INT)lParam;
4295 TBUTTON_INFO button;
4297 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4299 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4300 if ((nIndex == -1) || (nMoveIndex < 0))
4303 if (nMoveIndex > infoPtr->nNumButtons - 1)
4304 nMoveIndex = infoPtr->nNumButtons - 1;
4306 button = infoPtr->buttons[nIndex];
4308 /* move button right */
4309 if (nIndex < nMoveIndex)
4311 nCount = nMoveIndex - nIndex;
4312 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4313 infoPtr->buttons[nMoveIndex] = button;
4315 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4316 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4317 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4318 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4320 else if (nIndex > nMoveIndex) /* move button left */
4322 nCount = nIndex - nMoveIndex;
4323 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4324 infoPtr->buttons[nMoveIndex] = button;
4326 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4327 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4328 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4329 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4332 TOOLBAR_CalcToolbar(hwnd);
4333 InvalidateRect(hwnd, NULL, TRUE);
4340 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4343 TBUTTON_INFO *btnPtr;
4347 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4351 btnPtr = &infoPtr->buttons[nIndex];
4352 oldState = btnPtr->fsState;
4353 if (LOWORD(lParam) == FALSE)
4354 btnPtr->fsState &= ~TBSTATE_PRESSED;
4356 btnPtr->fsState |= TBSTATE_PRESSED;
4358 if(oldState != btnPtr->fsState)
4359 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4364 /* FIXME: there might still be some confusion her between number of buttons
4365 * and number of bitmaps */
4367 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4370 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4372 HBITMAP hbmLoad = NULL;
4373 int i = 0, nOldButtons = 0, pos = 0;
4374 int nOldBitmaps, nNewBitmaps = 0;
4375 HIMAGELIST himlDef = 0;
4377 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4378 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4379 lpReplace->nButtons);
4381 if (lpReplace->hInstOld == HINST_COMMCTRL)
4383 FIXME("changing standard bitmaps not implemented\n");
4386 else if (lpReplace->hInstOld != 0)
4387 FIXME("resources not in the current module not implemented\n");
4389 if (lpReplace->hInstNew)
4391 hbmLoad = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4396 hBitmap = (HBITMAP) lpReplace->nIDNew;
4399 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4400 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4401 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4402 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4403 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4405 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4406 nOldButtons = tbi->nButtons;
4407 tbi->nButtons = lpReplace->nButtons;
4408 tbi->hInst = lpReplace->hInstNew;
4409 tbi->nID = lpReplace->nIDNew;
4410 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4413 pos += tbi->nButtons;
4416 if (nOldButtons == 0)
4418 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4420 DeleteObject (hbmLoad);
4424 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4425 nOldBitmaps = ImageList_GetImageCount(himlDef);
4427 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4429 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4430 ImageList_Remove(himlDef, i);
4435 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4436 HDC hdcImage, hdcBitmap;
4438 /* copy the bitmap before adding it so that the user's bitmap
4439 * doesn't get modified.
4441 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4443 hdcImage = CreateCompatibleDC(0);
4444 hdcBitmap = CreateCompatibleDC(0);
4446 /* create new bitmap */
4447 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4448 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4449 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4451 /* Copy the user's image */
4452 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4453 hdcBitmap, 0, 0, SRCCOPY);
4455 SelectObject (hdcImage, hOldBitmapLoad);
4456 SelectObject (hdcBitmap, hOldBitmapBitmap);
4457 DeleteDC (hdcImage);
4458 DeleteDC (hdcBitmap);
4460 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4461 nNewBitmaps = ImageList_GetImageCount(himlDef);
4462 DeleteObject (hbmLoad);
4465 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4467 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4468 pos, nOldBitmaps, nNewBitmaps);
4470 InvalidateRect(hwnd, NULL, TRUE);
4473 DeleteObject (hbmLoad);
4478 /* helper for TOOLBAR_SaveRestoreW */
4480 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4482 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4483 debugstr_w(lpSave->pszValueName));
4489 /* helper for TOOLBAR_Restore */
4491 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4496 ZeroMemory(&ti, sizeof(ti));
4497 ti.cbSize = sizeof(ti);
4498 ti.hwnd = infoPtr->hwndSelf;
4500 for (i = 0; i < infoPtr->nNumButtons; i++)
4502 if ((infoPtr->hwndToolTip) &&
4503 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4505 ti.uId = infoPtr->buttons[i].idCommand;
4506 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4510 Free(infoPtr->buttons);
4511 infoPtr->buttons = NULL;
4512 infoPtr->nNumButtons = 0;
4516 /* helper for TOOLBAR_SaveRestoreW */
4518 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4527 /* restore toolbar information */
4528 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4529 debugstr_w(lpSave->pszValueName));
4531 memset(&nmtbr, 0, sizeof(nmtbr));
4533 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4534 KEY_QUERY_VALUE, &hkey);
4536 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4538 if (!res && dwType != REG_BINARY)
4539 res = ERROR_FILE_NOT_FOUND;
4542 nmtbr.pData = Alloc(dwSize);
4543 nmtbr.cbData = (UINT)dwSize;
4544 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4547 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4548 (LPBYTE)nmtbr.pData, &dwSize);
4551 nmtbr.pCurrent = nmtbr.pData;
4553 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4554 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4556 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4560 /* remove all existing buttons as this function is designed to
4561 * restore the toolbar to a previously saved state */
4562 TOOLBAR_DeleteAllButtons(infoPtr);
4564 for (i = 0; i < nmtbr.cButtons; i++)
4567 nmtbr.tbButton.iBitmap = -1;
4568 nmtbr.tbButton.fsState = 0;
4569 nmtbr.tbButton.fsStyle = 0;
4570 nmtbr.tbButton.idCommand = 0;
4571 if (*nmtbr.pCurrent == (DWORD)-1)
4574 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4575 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4577 else if (*nmtbr.pCurrent == (DWORD)-2)
4579 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4581 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4585 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4587 /* can't contain real string as we don't know whether
4588 * the client put an ANSI or Unicode string in there */
4589 if (HIWORD(nmtbr.tbButton.iString))
4590 nmtbr.tbButton.iString = 0;
4592 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4593 (LPARAM)&nmtbr.tbButton);
4596 /* do legacy notifications */
4597 if (infoPtr->iVersion < 5)
4599 /* FIXME: send TBN_BEGINADJUST */
4600 FIXME("send TBN_GETBUTTONINFO for each button\n");
4601 /* FIXME: send TBN_ENDADJUST */
4604 /* remove all uninitialised buttons
4605 * note: loop backwards to avoid having to fixup i on a
4607 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4608 if (infoPtr->buttons[i].iBitmap == -1)
4609 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4611 /* only indicate success if at least one button survived */
4612 if (infoPtr->nNumButtons > 0) ret = TRUE;
4623 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4627 if (lpSave == NULL) return 0;
4630 return TOOLBAR_Save(infoPtr, lpSave);
4632 return TOOLBAR_Restore(infoPtr, lpSave);
4637 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4639 LPWSTR pszValueName = 0, pszSubKey = 0;
4640 TBSAVEPARAMSW SaveW;
4644 if (lpSave == NULL) return 0;
4646 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4647 pszSubKey = Alloc(len * sizeof(WCHAR));
4648 if (pszSubKey) goto exit;
4649 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4651 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4652 pszValueName = Alloc(len * sizeof(WCHAR));
4653 if (!pszValueName) goto exit;
4654 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4656 SaveW.pszValueName = pszValueName;
4657 SaveW.pszSubKey = pszSubKey;
4658 SaveW.hkr = lpSave->hkr;
4659 result = TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4662 Free (pszValueName);
4670 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4673 BOOL bOldAnchor = infoPtr->bAnchor;
4675 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4677 infoPtr->bAnchor = (BOOL)wParam;
4679 /* Native does not remove the hot effect from an already hot button */
4681 return (LRESULT)bOldAnchor;
4686 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4688 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4689 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4691 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4694 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4696 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4699 if (infoPtr->nNumButtons > 0)
4700 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4701 infoPtr->nNumButtons,
4702 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4703 LOWORD(lParam), HIWORD(lParam));
4705 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4706 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4709 if ((himlDef == infoPtr->himlInt) &&
4710 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4712 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4713 infoPtr->nBitmapHeight);
4721 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4724 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4725 TBUTTON_INFO *btnPtr;
4731 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4734 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4735 lptbbi->dwMask & 0x80000000);
4739 btnPtr = &infoPtr->buttons[nIndex];
4740 if (lptbbi->dwMask & TBIF_COMMAND)
4741 btnPtr->idCommand = lptbbi->idCommand;
4742 if (lptbbi->dwMask & TBIF_IMAGE)
4743 btnPtr->iBitmap = lptbbi->iImage;
4744 if (lptbbi->dwMask & TBIF_LPARAM)
4745 btnPtr->dwData = lptbbi->lParam;
4746 if (lptbbi->dwMask & TBIF_SIZE)
4747 btnPtr->cx = lptbbi->cx;
4748 if (lptbbi->dwMask & TBIF_STATE)
4749 btnPtr->fsState = lptbbi->fsState;
4750 if (lptbbi->dwMask & TBIF_STYLE)
4751 btnPtr->fsStyle = lptbbi->fsStyle;
4753 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4754 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4755 /* iString is index, zero it to make Str_SetPtr succeed */
4758 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4761 /* save the button rect to see if we need to redraw the whole toolbar */
4762 oldBtnRect = btnPtr->rect;
4763 TOOLBAR_CalcToolbar(hwnd);
4765 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4766 InvalidateRect(hwnd, NULL, TRUE);
4768 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4775 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4778 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4779 TBUTTON_INFO *btnPtr;
4785 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4788 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4789 lptbbi->dwMask & 0x80000000);
4793 btnPtr = &infoPtr->buttons[nIndex];
4794 if (lptbbi->dwMask & TBIF_COMMAND)
4795 btnPtr->idCommand = lptbbi->idCommand;
4796 if (lptbbi->dwMask & TBIF_IMAGE)
4797 btnPtr->iBitmap = lptbbi->iImage;
4798 if (lptbbi->dwMask & TBIF_LPARAM)
4799 btnPtr->dwData = lptbbi->lParam;
4800 if (lptbbi->dwMask & TBIF_SIZE)
4801 btnPtr->cx = lptbbi->cx;
4802 if (lptbbi->dwMask & TBIF_STATE)
4803 btnPtr->fsState = lptbbi->fsState;
4804 if (lptbbi->dwMask & TBIF_STYLE)
4805 btnPtr->fsStyle = lptbbi->fsStyle;
4807 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4808 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4809 /* iString is index, zero it to make Str_SetPtr succeed */
4811 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4814 /* save the button rect to see if we need to redraw the whole toolbar */
4815 oldBtnRect = btnPtr->rect;
4816 TOOLBAR_CalcToolbar(hwnd);
4818 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4819 InvalidateRect(hwnd, NULL, TRUE);
4821 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4828 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4831 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4833 if ((cx < 0) || (cy < 0))
4835 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4839 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4841 /* The documentation claims you can only change the button size before
4842 * any button has been added. But this is wrong.
4843 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4844 * it to the toolbar, and it checks that the return value is nonzero - mjm
4845 * Further testing shows that we must actually perform the change too.
4848 * The documentation also does not mention that if 0 is supplied for
4849 * either size, the system changes it to the default of 24 wide and
4850 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4852 infoPtr->nButtonWidth = (cx) ? cx : 24;
4853 infoPtr->nButtonHeight = (cy) ? cy : 22;
4859 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4863 /* if setting to current values, ignore */
4864 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4865 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4866 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4867 infoPtr->cxMin, infoPtr->cxMax);
4871 /* save new values */
4872 infoPtr->cxMin = (INT)LOWORD(lParam);
4873 infoPtr->cxMax = (INT)HIWORD(lParam);
4875 /* if both values are 0 then we are done */
4877 TRACE("setting both min and max to 0, norecalc\n");
4881 /* otherwise we need to recalc the toolbar and in some cases
4882 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4883 which doesn't actually draw - GA). */
4884 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4885 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4887 TOOLBAR_CalcToolbar (hwnd);
4889 InvalidateRect (hwnd, NULL, TRUE);
4896 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4899 INT nIndex = (INT)wParam;
4901 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4904 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4906 if (infoPtr->hwndToolTip) {
4908 FIXME("change tool tip!\n");
4917 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4919 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4920 HIMAGELIST himl = (HIMAGELIST)lParam;
4921 HIMAGELIST himlTemp;
4924 if (infoPtr->iVersion >= 5)
4927 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4928 &infoPtr->cimlDis, himl, id);
4930 /* FIXME: redraw ? */
4932 return (LRESULT)himlTemp;
4937 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4939 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4942 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4944 dwTemp = infoPtr->dwDTFlags;
4945 infoPtr->dwDTFlags =
4946 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4948 return (LRESULT)dwTemp;
4951 /* This function differs a bit from what MSDN says it does:
4952 * 1. lParam contains extended style flags to OR with current style
4953 * (MSDN isn't clear on the OR bit)
4954 * 2. wParam appears to contain extended style flags to be reset
4955 * (MSDN says that this parameter is reserved)
4958 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4963 dwTemp = infoPtr->dwExStyle;
4964 infoPtr->dwExStyle &= ~wParam;
4965 infoPtr->dwExStyle |= (DWORD)lParam;
4967 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4969 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4970 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4971 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4973 TOOLBAR_CalcToolbar (hwnd);
4975 TOOLBAR_AutoSize(hwnd);
4977 InvalidateRect(hwnd, NULL, TRUE);
4979 return (LRESULT)dwTemp;
4984 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4987 HIMAGELIST himlTemp;
4988 HIMAGELIST himl = (HIMAGELIST)lParam;
4991 if (infoPtr->iVersion >= 5)
4994 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4996 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4997 &infoPtr->cimlHot, himl, id);
4999 /* FIXME: redraw ? */
5001 return (LRESULT)himlTemp;
5005 /* Makes previous hot button no longer hot, makes the specified
5006 * button hot and sends appropriate notifications. dwReason is one or
5007 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
5008 * NOTE 1: this function does not validate nHit
5009 * NOTE 2: the name of this function is completely made up and
5010 * not based on any documentation from Microsoft. */
5012 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
5014 if (infoPtr->nHotItem != nHit)
5016 NMTBHOTITEM nmhotitem;
5017 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5018 LRESULT no_highlight;
5020 /* Remove the effect of an old hot button if the button was
5021 drawn with the hot button effect */
5022 if(infoPtr->nHotItem >= 0)
5024 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5025 oldBtnPtr->bHot = FALSE;
5028 infoPtr->nHotItem = nHit;
5030 /* It's not a separator or in nowhere. It's a hot button. */
5032 btnPtr = &infoPtr->buttons[nHit];
5034 nmhotitem.dwFlags = dwReason;
5036 nmhotitem.idOld = oldBtnPtr->idCommand;
5038 nmhotitem.dwFlags |= HICF_ENTERING;
5040 nmhotitem.idNew = btnPtr->idCommand;
5042 nmhotitem.dwFlags |= HICF_LEAVING;
5044 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
5046 /* now invalidate the old and new buttons so they will be painted,
5047 * but only if they are enabled - disabled buttons cannot become hot */
5048 if (oldBtnPtr && (oldBtnPtr->fsState & TBSTATE_ENABLED))
5049 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
5050 if (btnPtr && !no_highlight && (btnPtr->fsState & TBSTATE_ENABLED))
5052 btnPtr->bHot = TRUE;
5053 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5059 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
5061 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5062 INT nOldHotItem = infoPtr->nHotItem;
5064 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
5066 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5069 /* NOTE: an application can still remove the hot item even if anchor
5070 * highlighting is enabled */
5072 if (infoPtr->dwStyle & TBSTYLE_FLAT)
5073 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
5075 if (nOldHotItem < 0)
5078 return (LRESULT)nOldHotItem;
5083 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
5085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5086 HIMAGELIST himlTemp;
5087 HIMAGELIST himl = (HIMAGELIST)lParam;
5090 if (infoPtr->iVersion >= 5)
5093 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
5094 &infoPtr->cimlDef, himl, id);
5096 infoPtr->nNumBitmaps = 0;
5097 for (i = 0; i < infoPtr->cimlDef; i++)
5098 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
5100 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
5101 &infoPtr->nBitmapHeight))
5103 infoPtr->nBitmapWidth = 1;
5104 infoPtr->nBitmapHeight = 1;
5107 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
5108 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
5109 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
5111 InvalidateRect(hwnd, NULL, TRUE);
5113 return (LRESULT)himlTemp;
5118 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5122 infoPtr->nIndent = (INT)wParam;
5126 /* process only on indent changing */
5127 if(infoPtr->nIndent != (INT)wParam)
5129 infoPtr->nIndent = (INT)wParam;
5130 TOOLBAR_CalcToolbar (hwnd);
5131 InvalidateRect(hwnd, NULL, FALSE);
5139 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5141 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5142 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5144 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5146 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5148 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5152 if ((lptbim->iButton == -1) ||
5153 ((lptbim->iButton < infoPtr->nNumButtons) &&
5154 (lptbim->iButton >= 0)))
5156 infoPtr->tbim = *lptbim;
5157 /* FIXME: don't need to update entire toolbar */
5158 InvalidateRect(hwnd, NULL, TRUE);
5161 ERR("Invalid button index %d\n", lptbim->iButton);
5168 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5170 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5172 infoPtr->clrInsertMark = (COLORREF)lParam;
5174 /* FIXME: don't need to update entire toolbar */
5175 InvalidateRect(hwnd, NULL, TRUE);
5182 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5186 infoPtr->nMaxTextRows = (INT)wParam;
5188 TOOLBAR_CalcToolbar(hwnd);
5193 /* MSDN gives slightly wrong info on padding.
5194 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5195 * 2. It is not used to create a blank area between the edge of the button
5196 * and the text or image if TBSTYLE_LIST is set. It is used to control
5197 * the gap between the image and text.
5198 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5199 * to control the bottom and right borders [with the border being
5200 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5201 * is shared evenly on both sides of the button.
5202 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
5205 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5210 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5211 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
5212 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
5213 TRACE("cx=%ld, cy=%ld\n",
5214 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5215 return (LRESULT) oldPad;
5220 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5227 hwndOldNotify = infoPtr->hwndNotify;
5228 infoPtr->hwndNotify = (HWND)wParam;
5230 return (LRESULT)hwndOldNotify;
5235 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5238 LPRECT lprc = (LPRECT)lParam;
5242 if (LOWORD(wParam) > 1) {
5243 FIXME("multiple rows not supported!\n");
5246 if(infoPtr->nRows != LOWORD(wParam))
5248 infoPtr->nRows = LOWORD(wParam);
5250 /* recalculate toolbar */
5251 TOOLBAR_CalcToolbar (hwnd);
5253 /* repaint toolbar */
5254 InvalidateRect(hwnd, NULL, TRUE);
5257 /* return bounding rectangle */
5259 lprc->left = infoPtr->rcBound.left;
5260 lprc->right = infoPtr->rcBound.right;
5261 lprc->top = infoPtr->rcBound.top;
5262 lprc->bottom = infoPtr->rcBound.bottom;
5270 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5272 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5273 TBUTTON_INFO *btnPtr;
5276 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5280 btnPtr = &infoPtr->buttons[nIndex];
5282 /* if hidden state has changed the invalidate entire window and recalc */
5283 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5284 btnPtr->fsState = LOWORD(lParam);
5285 TOOLBAR_CalcToolbar (hwnd);
5286 InvalidateRect(hwnd, 0, TRUE);
5290 /* process state changing if current state doesn't match new state */
5291 if(btnPtr->fsState != LOWORD(lParam))
5293 btnPtr->fsState = LOWORD(lParam);
5294 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5302 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5304 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5310 inline static LRESULT
5311 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5315 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5317 infoPtr->hwndToolTip = (HWND)wParam;
5323 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5328 TRACE("%s hwnd=%p\n",
5329 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5331 bTemp = infoPtr->bUnicode;
5332 infoPtr->bUnicode = (BOOL)wParam;
5339 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5341 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5343 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5344 comctl32_color.clrBtnHighlight :
5345 infoPtr->clrBtnHighlight;
5346 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5347 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5353 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5357 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5358 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5359 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5361 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5362 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5363 InvalidateRect(hwnd, NULL, TRUE);
5369 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5372 INT iOldVersion = infoPtr->iVersion;
5374 infoPtr->iVersion = iVersion;
5376 if (infoPtr->iVersion >= 5)
5377 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5384 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5386 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5387 WORD iString = HIWORD(wParam);
5388 WORD buffersize = LOWORD(wParam);
5389 LPSTR str = (LPSTR)lParam;
5392 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5394 if (iString < infoPtr->nNumStrings)
5396 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5398 TRACE("returning %s\n", debugstr_a(str));
5401 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5408 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5411 WORD iString = HIWORD(wParam);
5412 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5413 LPWSTR str = (LPWSTR)lParam;
5416 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5418 if (iString < infoPtr->nNumStrings)
5420 len = min(len, strlenW(infoPtr->strings[iString]));
5421 ret = (len+1)*sizeof(WCHAR);
5422 memcpy(str, infoPtr->strings[iString], ret);
5425 TRACE("returning %s\n", debugstr_w(str));
5428 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5433 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5434 * is the maximum size of the toolbar? */
5435 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5437 SIZE * pSize = (SIZE*)lParam;
5438 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5443 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5444 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5445 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5448 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5451 INT nOldHotItem = infoPtr->nHotItem;
5453 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5454 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5456 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5459 /* NOTE: an application can still remove the hot item even if anchor
5460 * highlighting is enabled */
5462 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5466 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5469 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5470 * which controls the amount of spacing between the image and the text
5471 * of buttons for TBSTYLE_LIST toolbars. */
5472 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5476 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5479 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5481 infoPtr->iListGap = (INT)wParam;
5483 InvalidateRect(hwnd, NULL, TRUE);
5488 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5489 * of image lists associated with the various states. */
5490 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5492 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5494 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5496 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5500 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5503 LPSIZE lpsize = (LPSIZE)lParam;
5509 * Testing shows the following:
5510 * wParam = 0 adjust cx value
5511 * = 1 set cy value to max size.
5512 * lParam pointer to SIZE structure
5515 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5516 wParam, lParam, lpsize->cx, lpsize->cy);
5520 if (lpsize->cx == -1) {
5521 /* **** this is wrong, native measures each button and sets it */
5522 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5524 else if(HIWORD(lpsize->cx)) {
5526 HWND hwndParent = GetParent(hwnd);
5528 GetWindowRect(hwnd, &rc);
5529 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5530 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5531 rc.left, rc.top, rc.right, rc.bottom);
5532 lpsize->cx = max(rc.right-rc.left,
5533 infoPtr->rcBound.right - infoPtr->rcBound.left);
5536 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5540 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5541 /* lpsize->cy = infoPtr->nHeight; */
5544 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5548 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5549 lpsize->cx, lpsize->cy);
5553 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5555 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5557 InvalidateRect(hwnd, NULL, TRUE);
5563 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5566 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5569 TRACE("hwnd = %p\n", hwnd);
5571 /* initialize info structure */
5572 infoPtr->nButtonHeight = 22;
5573 infoPtr->nButtonWidth = 24;
5574 infoPtr->nBitmapHeight = 15;
5575 infoPtr->nBitmapWidth = 16;
5577 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5578 infoPtr->nMaxTextRows = 1;
5579 infoPtr->cxMin = -1;
5580 infoPtr->cxMax = -1;
5581 infoPtr->nNumBitmaps = 0;
5582 infoPtr->nNumStrings = 0;
5584 infoPtr->bCaptured = FALSE;
5585 infoPtr->nButtonDown = -1;
5586 infoPtr->nButtonDrag = -1;
5587 infoPtr->nOldHit = -1;
5588 infoPtr->nHotItem = -1;
5589 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5590 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5591 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5592 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5593 infoPtr->bDragOutSent = FALSE;
5594 infoPtr->iVersion = 0;
5595 infoPtr->hwndSelf = hwnd;
5596 infoPtr->bDoRedraw = TRUE;
5597 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5598 infoPtr->clrBtnShadow = CLR_DEFAULT;
5599 infoPtr->szPadding.cx = DEFPAD_CX;
5600 infoPtr->szPadding.cy = DEFPAD_CY;
5601 infoPtr->iListGap = DEFLISTGAP;
5602 infoPtr->dwStyle = dwStyle;
5603 infoPtr->tbim.iButton = -1;
5604 GetClientRect(hwnd, &infoPtr->client_rect);
5605 infoPtr->bUnicode = infoPtr->hwndNotify &&
5606 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5608 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5609 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5611 if (dwStyle & TBSTYLE_TOOLTIPS) {
5612 /* Create tooltip control */
5613 infoPtr->hwndToolTip =
5614 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5615 CW_USEDEFAULT, CW_USEDEFAULT,
5616 CW_USEDEFAULT, CW_USEDEFAULT,
5619 /* Send NM_TOOLTIPSCREATED notification */
5620 if (infoPtr->hwndToolTip)
5622 NMTOOLTIPSCREATED nmttc;
5624 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5626 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5630 TOOLBAR_CheckStyle (hwnd, dwStyle);
5632 TOOLBAR_CalcToolbar(hwnd);
5639 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5643 /* delete tooltip control */
5644 if (infoPtr->hwndToolTip)
5645 DestroyWindow (infoPtr->hwndToolTip);
5647 /* delete temporary buffer for tooltip text */
5648 Free (infoPtr->pszTooltipText);
5650 /* delete button data */
5651 if (infoPtr->buttons)
5652 Free (infoPtr->buttons);
5654 /* delete strings */
5655 if (infoPtr->strings) {
5657 for (i = 0; i < infoPtr->nNumStrings; i++)
5658 if (infoPtr->strings[i])
5659 Free (infoPtr->strings[i]);
5661 Free (infoPtr->strings);
5664 /* destroy internal image list */
5665 if (infoPtr->himlInt)
5666 ImageList_Destroy (infoPtr->himlInt);
5668 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5669 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5670 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5672 /* delete default font */
5674 DeleteObject (infoPtr->hDefaultFont);
5676 /* free toolbar info data */
5678 SetWindowLongPtrW (hwnd, 0, 0);
5685 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5688 NMTBCUSTOMDRAW tbcd;
5692 /* the app has told us not to redraw the toolbar */
5693 if (!infoPtr->bDoRedraw)
5696 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5697 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5698 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5699 tbcd.nmcd.hdc = (HDC)wParam;
5700 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5701 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5703 /* FIXME: in general the return flags *can* be or'ed together */
5704 switch (infoPtr->dwBaseCustDraw)
5706 case CDRF_DODEFAULT:
5708 case CDRF_SKIPDEFAULT:
5711 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5716 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5717 * to my parent for processing.
5719 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5721 HDC hdc = (HDC)wParam;
5726 parent = GetParent(hwnd);
5727 MapWindowPoints(hwnd, parent, &pt, 1);
5728 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5729 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5730 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5733 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5735 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5736 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5737 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5738 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5739 tbcd.nmcd.hdc = (HDC)wParam;
5740 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5741 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5742 switch (infoPtr->dwBaseCustDraw)
5744 case CDRF_DODEFAULT:
5746 case CDRF_SKIPDEFAULT:
5749 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5758 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5762 return (LRESULT)infoPtr->hFont;
5767 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5772 pt.x = (INT)LOWORD(lParam);
5773 pt.y = (INT)HIWORD(lParam);
5774 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5777 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5778 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5779 TOOLBAR_Customize (hwnd);
5786 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5788 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5789 TBUTTON_INFO *btnPtr;
5794 BOOL bDragKeyPressed;
5798 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5799 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5801 bDragKeyPressed = (wParam & MK_SHIFT);
5803 if (infoPtr->hwndToolTip)
5804 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5805 WM_LBUTTONDOWN, wParam, lParam);
5807 pt.x = (INT)LOWORD(lParam);
5808 pt.y = (INT)HIWORD(lParam);
5809 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5811 btnPtr = &infoPtr->buttons[nHit];
5813 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5815 infoPtr->nButtonDrag = nHit;
5818 /* If drag cursor has not been loaded, load it.
5819 * Note: it doesn't need to be freed */
5821 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5822 SetCursor(hCursorDrag);
5827 infoPtr->nOldHit = nHit;
5829 CopyRect(&arrowRect, &btnPtr->rect);
5830 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5832 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5833 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5834 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5835 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5836 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5837 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5841 /* draw in pressed state */
5842 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5843 btnPtr->fsState |= TBSTATE_PRESSED;
5845 btnPtr->bDropDownPressed = TRUE;
5846 RedrawWindow(hwnd,&btnPtr->rect,0,
5847 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5849 memset(&nmtb, 0, sizeof(nmtb));
5850 nmtb.iItem = btnPtr->idCommand;
5851 nmtb.rcButton = btnPtr->rect;
5852 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5854 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5856 if (res != TBDDRET_TREATPRESSED)
5860 /* redraw button in unpressed state */
5861 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5862 btnPtr->fsState &= ~TBSTATE_PRESSED;
5864 btnPtr->bDropDownPressed = FALSE;
5865 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5867 /* find and set hot item
5868 * NOTE: native doesn't do this, but that is a bug */
5870 ScreenToClient(hwnd, &pt);
5871 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5872 if (!infoPtr->bAnchor || (nHit >= 0))
5873 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5875 /* remove any left mouse button down or double-click messages
5876 * so that we can get a toggle effect on the button */
5877 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5878 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5883 /* otherwise drop through and process as pushed */
5885 infoPtr->bCaptured = TRUE;
5886 infoPtr->nButtonDown = nHit;
5887 infoPtr->bDragOutSent = FALSE;
5889 btnPtr->fsState |= TBSTATE_PRESSED;
5891 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5893 if (btnPtr->fsState & TBSTATE_ENABLED)
5894 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5901 memset(&nmtb, 0, sizeof(nmtb));
5902 nmtb.iItem = btnPtr->idCommand;
5903 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5906 nmmouse.dwHitInfo = nHit;
5908 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5910 nmmouse.dwItemSpec = -1;
5913 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5914 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5917 ClientToScreen(hwnd, &pt);
5920 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5921 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5927 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5929 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5930 TBUTTON_INFO *btnPtr;
5934 BOOL bSendMessage = TRUE;
5939 if (infoPtr->hwndToolTip)
5940 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5941 WM_LBUTTONUP, wParam, lParam);
5943 pt.x = (INT)LOWORD(lParam);
5944 pt.y = (INT)HIWORD(lParam);
5945 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5947 if (!infoPtr->bAnchor || (nHit >= 0))
5948 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5950 if (infoPtr->nButtonDrag >= 0) {
5954 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5957 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5959 GetClientRect(hwnd, &rcClient);
5960 if (PtInRect(&rcClient, pt))
5967 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5970 if (nButton == infoPtr->nButtonDrag)
5972 /* if the button is moved sightly left and we have a
5973 * separator there then remove it */
5974 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5976 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5977 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5979 else /* else insert a separator before the dragged button */
5982 memset(&tbb, 0, sizeof(tbb));
5983 tbb.fsStyle = BTNS_SEP;
5985 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5992 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5993 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5995 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5998 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
6003 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
6004 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
6007 /* button under cursor changed so need to re-set hot item */
6008 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
6009 infoPtr->nButtonDrag = -1;
6011 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
6013 else if (infoPtr->nButtonDown >= 0) {
6014 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6015 btnPtr->fsState &= ~TBSTATE_PRESSED;
6017 if (btnPtr->fsStyle & BTNS_CHECK) {
6018 if (btnPtr->fsStyle & BTNS_GROUP) {
6019 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
6021 if (nOldIndex == nHit)
6022 bSendMessage = FALSE;
6023 if ((nOldIndex != nHit) &&
6025 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
6026 btnPtr->fsState |= TBSTATE_CHECKED;
6029 if (btnPtr->fsState & TBSTATE_CHECKED)
6030 btnPtr->fsState &= ~TBSTATE_CHECKED;
6032 btnPtr->fsState |= TBSTATE_CHECKED;
6036 if (nOldIndex != -1)
6037 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
6040 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
6041 * that resets bCaptured and btn TBSTATE_PRESSED flags,
6042 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
6044 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
6046 infoPtr->nButtonDown = -1;
6048 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
6049 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
6050 NM_RELEASEDCAPTURE);
6052 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
6055 memset(&nmtb, 0, sizeof(nmtb));
6056 nmtb.iItem = btnPtr->idCommand;
6057 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
6060 if (btnPtr->fsState & TBSTATE_ENABLED)
6062 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
6063 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
6067 /* !!! Undocumented - toolbar at 4.71 level and above sends
6068 * NM_CLICK with the NMMOUSE structure. */
6069 nmmouse.dwHitInfo = nHit;
6071 if (nmmouse.dwHitInfo < 0)
6072 nmmouse.dwItemSpec = -1;
6075 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6076 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6079 ClientToScreen(hwnd, &pt);
6082 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
6083 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
6089 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
6091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6096 pt.x = LOWORD(lParam);
6097 pt.y = HIWORD(lParam);
6099 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
6100 nmmouse.dwHitInfo = nHit;
6103 nmmouse.dwItemSpec = -1;
6105 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
6106 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
6109 ClientToScreen(hwnd, &pt);
6112 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
6113 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
6119 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6121 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6124 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6125 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6131 TOOLBAR_CaptureChanged(HWND hwnd)
6133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6134 TBUTTON_INFO *btnPtr;
6136 infoPtr->bCaptured = FALSE;
6138 if (infoPtr->nButtonDown >= 0)
6140 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6141 btnPtr->fsState &= ~TBSTATE_PRESSED;
6143 infoPtr->nOldHit = -1;
6145 if (btnPtr->fsState & TBSTATE_ENABLED)
6146 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6152 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6155 TBUTTON_INFO *hotBtnPtr;
6157 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6159 /* don't remove hot effects when in anchor highlighting mode or when a
6160 * drop-down button is pressed */
6161 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6162 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6164 if (infoPtr->nOldHit < 0)
6167 /* If the last button we were over is depressed then make it not */
6168 /* depressed and redraw it */
6169 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6171 TBUTTON_INFO *btnPtr;
6174 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6176 btnPtr->fsState &= ~TBSTATE_PRESSED;
6178 rc1 = hotBtnPtr->rect;
6179 InflateRect (&rc1, 1, 1);
6180 InvalidateRect (hwnd, &rc1, TRUE);
6183 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6186 ZeroMemory(&nmt, sizeof(nmt));
6187 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6188 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6189 infoPtr->bDragOutSent = TRUE;
6192 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6198 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6200 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6202 TRACKMOUSEEVENT trackinfo;
6204 TBUTTON_INFO *btnPtr;
6206 if (infoPtr->dwStyle & TBSTYLE_FLAT) {
6207 /* fill in the TRACKMOUSEEVENT struct */
6208 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6209 trackinfo.dwFlags = TME_QUERY;
6210 trackinfo.hwndTrack = hwnd;
6211 trackinfo.dwHoverTime = HOVER_DEFAULT;
6213 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6214 _TrackMouseEvent(&trackinfo);
6216 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6217 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6218 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6220 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6221 /* and can properly deactivate the hot toolbar button */
6222 _TrackMouseEvent(&trackinfo);
6226 if (infoPtr->hwndToolTip)
6227 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6228 WM_MOUSEMOVE, wParam, lParam);
6230 pt.x = (INT)LOWORD(lParam);
6231 pt.y = (INT)HIWORD(lParam);
6233 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6235 if ((infoPtr->dwStyle & TBSTYLE_FLAT) && (!infoPtr->bAnchor || (nHit >= 0)))
6236 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6238 if (infoPtr->nOldHit != nHit)
6240 if (infoPtr->bCaptured)
6242 if (!infoPtr->bDragOutSent)
6245 ZeroMemory(&nmt, sizeof(nmt));
6246 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6247 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6248 infoPtr->bDragOutSent = TRUE;
6251 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6252 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6253 btnPtr->fsState &= ~TBSTATE_PRESSED;
6254 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6256 else if (nHit == infoPtr->nButtonDown) {
6257 btnPtr->fsState |= TBSTATE_PRESSED;
6258 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6260 infoPtr->nOldHit = nHit;
6268 inline static LRESULT
6269 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6271 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6272 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6274 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6278 inline static LRESULT
6279 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6281 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6282 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6284 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6289 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6291 TOOLBAR_INFO *infoPtr;
6292 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6295 /* allocate memory for info structure */
6296 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6297 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6300 infoPtr->dwStructSize = sizeof(TBBUTTON);
6303 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6304 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6305 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6306 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6309 /* native control does:
6310 * Get a lot of colors and brushes
6312 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6313 * CreateFontIndirectW(adr1)
6314 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6315 * hdc = GetDC(toolbar)
6316 * GetSystemMetrics(0x48)
6317 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6318 * 0, 0, 0, 0, "MARLETT")
6319 * oldfnt = SelectObject(hdc, fnt2)
6320 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6321 * GetTextMetricsW(hdc, adr3)
6322 * SelectObject(hdc, oldfnt)
6323 * DeleteObject(fnt2)
6325 * InvalidateRect(toolbar, 0, 1)
6326 * SetWindowLongW(toolbar, 0, addr)
6327 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6330 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6331 * ie 2 0x4600094c 0x4600094c 0x4600894d
6332 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6333 * rebar 0x50008844 0x40008844 0x50008845
6334 * pager 0x50000844 0x40000844 0x50008845
6335 * IC35mgr 0x5400084e **nochange**
6336 * on entry to _NCCREATE 0x5400084e
6337 * rowlist 0x5400004e **nochange**
6338 * on entry to _NCCREATE 0x5400004e
6342 /* I think the code below is a bug, but it is the way that the native
6343 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6344 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6345 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6346 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6347 * Somehow, the only cases of this seem to be MFC programs.
6349 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6350 * does not occur in the WM_STYLECHANGING routine.
6351 * (Guy Albertelli 9/2001)
6354 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6355 styleadd |= TBSTYLE_TRANSPARENT;
6356 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6357 styleadd |= CCS_TOP; /* default to top */
6358 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6361 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6366 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6368 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6372 if (dwStyle & WS_MINIMIZE)
6373 return 0; /* Nothing to do */
6375 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6377 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6380 if (!(dwStyle & CCS_NODIVIDER))
6382 GetWindowRect (hwnd, &rcWindow);
6383 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6384 if( dwStyle & WS_BORDER )
6385 OffsetRect (&rcWindow, 1, 1);
6386 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6389 ReleaseDC( hwnd, hdc );
6395 /* handles requests from the tooltip control on what text to display */
6396 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6398 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6400 TRACE("button index = %d\n", index);
6402 Free (infoPtr->pszTooltipText);
6403 infoPtr->pszTooltipText = NULL;
6408 if (infoPtr->bUnicode)
6410 WCHAR wszBuffer[INFOTIPSIZE+1];
6411 NMTBGETINFOTIPW tbgit;
6412 unsigned int len; /* in chars */
6414 wszBuffer[0] = '\0';
6415 wszBuffer[INFOTIPSIZE] = '\0';
6417 tbgit.pszText = wszBuffer;
6418 tbgit.cchTextMax = INFOTIPSIZE;
6419 tbgit.iItem = lpnmtdi->hdr.idFrom;
6420 tbgit.lParam = infoPtr->buttons[index].dwData;
6422 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6424 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6426 len = strlenW(tbgit.pszText);
6427 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6429 /* need to allocate temporary buffer in infoPtr as there
6430 * isn't enough space in buffer passed to us by the
6431 * tooltip control */
6432 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6433 if (infoPtr->pszTooltipText)
6435 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6436 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6442 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6448 CHAR szBuffer[INFOTIPSIZE+1];
6449 NMTBGETINFOTIPA tbgit;
6450 unsigned int len; /* in chars */
6453 szBuffer[INFOTIPSIZE] = '\0';
6455 tbgit.pszText = szBuffer;
6456 tbgit.cchTextMax = INFOTIPSIZE;
6457 tbgit.iItem = lpnmtdi->hdr.idFrom;
6458 tbgit.lParam = infoPtr->buttons[index].dwData;
6460 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6462 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6464 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6465 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6467 /* need to allocate temporary buffer in infoPtr as there
6468 * isn't enough space in buffer passed to us by the
6469 * tooltip control */
6470 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6471 if (infoPtr->pszTooltipText)
6473 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6474 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6480 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6485 /* if button has text, but it is not shown then automatically
6486 * use that text as tooltip */
6487 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6488 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6490 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6491 unsigned int len = pszText ? strlenW(pszText) : 0;
6493 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6495 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6497 /* need to allocate temporary buffer in infoPtr as there
6498 * isn't enough space in buffer passed to us by the
6499 * tooltip control */
6500 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6501 if (infoPtr->pszTooltipText)
6503 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6504 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6510 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6515 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6517 /* last resort: send notification on to app */
6518 /* FIXME: find out what is really used here */
6519 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6523 inline static LRESULT
6524 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6527 LPNMHDR lpnmh = (LPNMHDR)lParam;
6529 switch (lpnmh->code)
6533 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6535 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6536 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6537 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6541 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6542 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6550 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6552 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6553 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6554 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6555 lppgs->iScroll, lppgs->iDir);
6559 case TTN_GETDISPINFOW:
6560 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6562 case TTN_GETDISPINFOA:
6563 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6573 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6577 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6579 if (lParam == NF_QUERY)
6582 if (lParam == NF_REQUERY) {
6583 format = SendMessageW(infoPtr->hwndNotify,
6584 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6585 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6586 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6597 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6603 /* fill ps.rcPaint with a default rect */
6604 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6606 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6608 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6609 ps.rcPaint.left, ps.rcPaint.top,
6610 ps.rcPaint.right, ps.rcPaint.bottom);
6612 TOOLBAR_Refresh (hwnd, hdc, &ps);
6613 if (!wParam) EndPaint (hwnd, &ps);
6620 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6621 /*****************************************************
6624 * Handles the WM_SETREDRAW message.
6627 * According to testing V4.71 of COMCTL32 returns the
6628 * *previous* status of the redraw flag (either 0 or 1)
6629 * instead of the MSDN documented value of 0 if handled.
6630 * (For laughs see the "consistency" with same function
6633 *****************************************************/
6635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6636 BOOL oldredraw = infoPtr->bDoRedraw;
6638 TRACE("set to %s\n",
6639 (wParam) ? "TRUE" : "FALSE");
6640 infoPtr->bDoRedraw = (BOOL) wParam;
6642 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6644 return (oldredraw) ? 1 : 0;
6649 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6651 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6652 DWORD dwStyle = infoPtr->dwStyle;
6661 /* Resize deadlock check */
6662 if (infoPtr->bAutoSize) {
6663 infoPtr->bAutoSize = FALSE;
6667 /* FIXME: optimize to only update size if the new size doesn't */
6668 /* match the current size */
6670 flags = (INT) wParam;
6672 /* FIXME for flags =
6673 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6676 TRACE("sizing toolbar!\n");
6678 if (flags == SIZE_RESTORED) {
6679 /* width and height don't apply */
6680 parent = GetParent (hwnd);
6681 GetClientRect(parent, &parent_rect);
6682 x = parent_rect.left;
6683 y = parent_rect.top;
6685 if (dwStyle & CCS_NORESIZE) {
6686 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6689 * this sets the working width of the toolbar, and
6690 * Calc Toolbar will not adjust it, only the height
6692 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6693 cy = infoPtr->nHeight;
6694 cx = infoPtr->nWidth;
6695 TOOLBAR_CalcToolbar (hwnd);
6696 infoPtr->nWidth = cx;
6697 infoPtr->nHeight = cy;
6700 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6701 TOOLBAR_CalcToolbar (hwnd);
6702 cy = infoPtr->nHeight;
6703 cx = infoPtr->nWidth;
6705 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6706 GetWindowRect(hwnd, &window_rect);
6707 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6708 y = window_rect.top;
6710 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6711 GetWindowRect(hwnd, &window_rect);
6712 y = parent_rect.bottom -
6713 ( window_rect.bottom - window_rect.top);
6717 if (dwStyle & CCS_NOPARENTALIGN) {
6718 uPosFlags |= SWP_NOMOVE;
6719 cy = infoPtr->nHeight;
6720 cx = infoPtr->nWidth;
6723 if (!(dwStyle & CCS_NODIVIDER))
6724 cy += GetSystemMetrics(SM_CYEDGE);
6726 if (dwStyle & WS_BORDER)
6729 cy += GetSystemMetrics(SM_CYEDGE);
6730 cx += GetSystemMetrics(SM_CXEDGE);
6733 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6735 RECT delta_width, delta_height, client, dummy;
6736 DWORD min_x, max_x, min_y, max_y;
6737 TBUTTON_INFO *btnPtr;
6740 GetClientRect(hwnd, &client);
6741 if(client.right > infoPtr->client_rect.right)
6743 min_x = infoPtr->client_rect.right;
6744 max_x = client.right;
6748 max_x = infoPtr->client_rect.right;
6749 min_x = client.right;
6751 if(client.bottom > infoPtr->client_rect.bottom)
6753 min_y = infoPtr->client_rect.bottom;
6754 max_y = client.bottom;
6758 max_y = infoPtr->client_rect.bottom;
6759 min_y = client.bottom;
6762 SetRect(&delta_width, min_x, 0, max_x, min_y);
6763 SetRect(&delta_height, 0, min_y, max_x, max_y);
6765 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6766 btnPtr = infoPtr->buttons;
6767 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6768 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6769 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6770 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6773 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6774 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6776 GetClientRect(hwnd, &infoPtr->client_rect);
6782 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6784 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6786 if (nType == GWL_STYLE)
6788 if (lpStyle->styleNew & TBSTYLE_LIST)
6789 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6791 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6793 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6794 (TBSTYLE_FLAT | TBSTYLE_LIST));
6795 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6797 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6799 infoPtr->dwStyle = lpStyle->styleNew;
6801 /* only resize if one of the CCS_* styles was changed */
6802 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6804 TOOLBAR_AutoSize (hwnd);
6806 InvalidateRect(hwnd, NULL, TRUE);
6815 TOOLBAR_SysColorChange (HWND hwnd)
6817 COMCTL32_RefreshSysColors();
6824 static LRESULT WINAPI
6825 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6829 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6830 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6832 if (!infoPtr && (uMsg != WM_NCCREATE))
6833 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6838 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6840 case TB_ADDBUTTONSA:
6841 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6843 case TB_ADDBUTTONSW:
6844 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6847 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6850 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6853 return TOOLBAR_AutoSize (hwnd);
6855 case TB_BUTTONCOUNT:
6856 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6858 case TB_BUTTONSTRUCTSIZE:
6859 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6861 case TB_CHANGEBITMAP:
6862 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6864 case TB_CHECKBUTTON:
6865 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6867 case TB_COMMANDTOINDEX:
6868 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6871 return TOOLBAR_Customize (hwnd);
6873 case TB_DELETEBUTTON:
6874 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6876 case TB_ENABLEBUTTON:
6877 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6879 case TB_GETANCHORHIGHLIGHT:
6880 return TOOLBAR_GetAnchorHighlight (hwnd);
6883 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6885 case TB_GETBITMAPFLAGS:
6886 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6889 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6891 case TB_GETBUTTONINFOA:
6892 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6894 case TB_GETBUTTONINFOW:
6895 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6897 case TB_GETBUTTONSIZE:
6898 return TOOLBAR_GetButtonSize (hwnd);
6900 case TB_GETBUTTONTEXTA:
6901 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6903 case TB_GETBUTTONTEXTW:
6904 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6906 case TB_GETDISABLEDIMAGELIST:
6907 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6909 case TB_GETEXTENDEDSTYLE:
6910 return TOOLBAR_GetExtendedStyle (hwnd);
6912 case TB_GETHOTIMAGELIST:
6913 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6916 return TOOLBAR_GetHotItem (hwnd);
6918 case TB_GETIMAGELIST:
6919 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6921 case TB_GETINSERTMARK:
6922 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6924 case TB_GETINSERTMARKCOLOR:
6925 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6927 case TB_GETITEMRECT:
6928 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6931 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6933 /* case TB_GETOBJECT: */ /* 4.71 */
6936 return TOOLBAR_GetPadding (hwnd);
6939 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6942 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6945 return TOOLBAR_GetState (hwnd, wParam, lParam);
6948 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6951 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6954 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6956 case TB_GETTEXTROWS:
6957 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6959 case TB_GETTOOLTIPS:
6960 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6962 case TB_GETUNICODEFORMAT:
6963 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6966 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6969 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6971 case TB_INDETERMINATE:
6972 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6974 case TB_INSERTBUTTONA:
6975 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6977 case TB_INSERTBUTTONW:
6978 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6980 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6982 case TB_ISBUTTONCHECKED:
6983 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6985 case TB_ISBUTTONENABLED:
6986 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6988 case TB_ISBUTTONHIDDEN:
6989 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6991 case TB_ISBUTTONHIGHLIGHTED:
6992 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6994 case TB_ISBUTTONINDETERMINATE:
6995 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6997 case TB_ISBUTTONPRESSED:
6998 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
7001 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
7003 case TB_MAPACCELERATORA:
7004 case TB_MAPACCELERATORW:
7005 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
7008 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
7011 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
7013 case TB_PRESSBUTTON:
7014 return TOOLBAR_PressButton (hwnd, wParam, lParam);
7016 case TB_REPLACEBITMAP:
7017 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
7019 case TB_SAVERESTOREA:
7020 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
7022 case TB_SAVERESTOREW:
7023 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
7025 case TB_SETANCHORHIGHLIGHT:
7026 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
7028 case TB_SETBITMAPSIZE:
7029 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
7031 case TB_SETBUTTONINFOA:
7032 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
7034 case TB_SETBUTTONINFOW:
7035 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
7037 case TB_SETBUTTONSIZE:
7038 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
7040 case TB_SETBUTTONWIDTH:
7041 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
7044 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
7046 case TB_SETDISABLEDIMAGELIST:
7047 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
7049 case TB_SETDRAWTEXTFLAGS:
7050 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
7052 case TB_SETEXTENDEDSTYLE:
7053 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
7055 case TB_SETHOTIMAGELIST:
7056 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
7059 return TOOLBAR_SetHotItem (hwnd, wParam);
7061 case TB_SETIMAGELIST:
7062 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
7065 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
7067 case TB_SETINSERTMARK:
7068 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
7070 case TB_SETINSERTMARKCOLOR:
7071 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
7073 case TB_SETMAXTEXTROWS:
7074 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
7077 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
7080 return TOOLBAR_SetParent (hwnd, wParam, lParam);
7083 return TOOLBAR_SetRows (hwnd, wParam, lParam);
7086 return TOOLBAR_SetState (hwnd, wParam, lParam);
7089 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
7091 case TB_SETTOOLTIPS:
7092 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
7094 case TB_SETUNICODEFORMAT:
7095 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
7098 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
7101 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
7104 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
7107 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
7110 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
7113 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
7115 /* Common Control Messages */
7117 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
7118 case CCM_GETCOLORSCHEME:
7119 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7121 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7122 case CCM_SETCOLORSCHEME:
7123 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7125 case CCM_GETVERSION:
7126 return TOOLBAR_GetVersion (hwnd);
7128 case CCM_SETVERSION:
7129 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7135 return TOOLBAR_Create (hwnd, wParam, lParam);
7138 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7141 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7144 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7146 /* case WM_KEYDOWN: */
7147 /* case WM_KILLFOCUS: */
7149 case WM_LBUTTONDBLCLK:
7150 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7152 case WM_LBUTTONDOWN:
7153 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7156 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7159 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7161 case WM_RBUTTONDBLCLK:
7162 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7165 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7168 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7170 case WM_CAPTURECHANGED:
7171 return TOOLBAR_CaptureChanged(hwnd);
7174 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7177 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7180 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7183 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7186 return TOOLBAR_Notify (hwnd, wParam, lParam);
7188 case WM_NOTIFYFORMAT:
7189 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7192 return TOOLBAR_Paint (hwnd, wParam);
7195 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7198 return TOOLBAR_Size (hwnd, wParam, lParam);
7200 case WM_STYLECHANGED:
7201 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7203 case WM_SYSCOLORCHANGE:
7204 return TOOLBAR_SysColorChange (hwnd);
7206 /* case WM_WININICHANGE: */
7211 case WM_MEASUREITEM:
7213 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7215 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7216 case PGM_FORWARDMOUSE:
7217 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7220 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7221 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7222 uMsg, wParam, lParam);
7223 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7229 TOOLBAR_Register (void)
7233 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7234 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7235 wndClass.lpfnWndProc = ToolbarWindowProc;
7236 wndClass.cbClsExtra = 0;
7237 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7238 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7239 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7240 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7242 RegisterClassW (&wndClass);
7247 TOOLBAR_Unregister (void)
7249 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7252 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7257 /* Check if the entry already exists */
7258 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7260 /* If this is a new entry we must create it and insert into the array */
7265 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7268 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7269 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7284 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7288 for (i = 0; i < *cies; i++)
7298 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7306 for (i = 0; i < cies; i++)
7308 if (pies[i]->id == id)
7320 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7322 HIMAGELIST himlDef = 0;
7323 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7326 himlDef = pie->himl;
7332 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7334 if (infoPtr->bUnicode)
7335 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7342 nmtba.iItem = nmtb->iItem;
7343 nmtba.pszText = Buffer;
7344 nmtba.cchText = 256;
7345 ZeroMemory(nmtba.pszText, nmtba.cchText);
7347 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7349 int ccht = strlen(nmtba.pszText);
7351 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7352 nmtb->pszText, nmtb->cchText);
7354 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7363 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7364 int iItem, PCUSTOMBUTTON btnInfo)
7368 /* MSDN states that iItem is the index of the button, rather than the
7369 * command ID as used by every other NMTOOLBAR notification */
7371 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7373 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);