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
215 /* gap between border of button and text/image */
218 /* how wide to treat the bitmap if it isn't present */
219 #define LIST_IMAGE_ABSENT_WIDTH 2
221 #define TOOLBAR_NOWHERE (-1)
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
224 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
225 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
227 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
229 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
232 /* Used to find undocumented extended styles */
233 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
234 TBSTYLE_EX_UNDOC1 | \
235 TBSTYLE_EX_MIXEDBUTTONS | \
236 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
238 /* all of the CCS_ styles */
239 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
240 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
242 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
243 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
244 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
245 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
246 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
248 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
249 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
250 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
251 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
252 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
253 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
254 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
255 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
258 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
262 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
264 LPWSTR lpText = NULL;
266 /* NOTE: iString == -1 is undocumented */
267 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
268 lpText = (LPWSTR)btnPtr->iString;
269 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
270 lpText = infoPtr->strings[btnPtr->iString];
276 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
278 if (TRACE_ON(toolbar)){
279 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
280 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
281 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
282 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
284 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
285 btn_num, bP->idCommand,
286 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
287 bP->rect.left, bP->rect.top,
288 bP->rect.right, bP->rect.bottom);
294 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
296 if (TRACE_ON(toolbar)) {
299 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
301 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
302 iP->nNumStrings, iP->dwStyle);
303 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
305 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
306 (iP->bDoRedraw) ? "TRUE" : "FALSE");
307 for(i=0; i<iP->nNumButtons; i++) {
308 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
314 /***********************************************************************
317 * This function validates that the styles set are implemented and
318 * issues FIXME's warning of possible problems. In a perfect world this
319 * function should be null.
322 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
324 if (dwStyle & TBSTYLE_REGISTERDROP)
325 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
330 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
332 if(!IsWindow(infoPtr->hwndSelf))
333 return 0; /* we have just been destroyed */
335 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
336 nmhdr->hwndFrom = infoPtr->hwndSelf;
339 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
340 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
342 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
343 (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
346 /***********************************************************************
347 * TOOLBAR_GetBitmapIndex
349 * This function returns the bitmap index associated with a button.
350 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
351 * is issued to retrieve the index.
354 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
356 INT ret = btnPtr->iBitmap;
358 if (ret == I_IMAGECALLBACK)
360 /* issue TBN_GETDISPINFO */
363 memset(&nmgd, 0, sizeof(nmgd));
364 nmgd.idCommand = btnPtr->idCommand;
365 nmgd.lParam = btnPtr->dwData;
366 nmgd.dwMask = TBNF_IMAGE;
367 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr,
368 infoPtr->bUnicode ? TBN_GETDISPINFOW : TBN_GETDISPINFOA);
369 if (nmgd.dwMask & TBNF_DI_SETITEM)
370 btnPtr->iBitmap = nmgd.iImage;
372 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
373 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
376 if (ret != I_IMAGENONE)
377 ret = GETIBITMAP(infoPtr, ret);
384 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
387 INT id = GETHIMLID(infoPtr, index);
388 INT iBitmap = GETIBITMAP(infoPtr, index);
390 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
391 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
392 (index == I_IMAGECALLBACK))
399 /***********************************************************************
400 * TOOLBAR_GetImageListForDrawing
402 * This function validates the bitmap index (including I_IMAGECALLBACK
403 * functionality) and returns the corresponding image list.
406 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
410 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
411 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
412 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
413 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
417 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
418 if ((*index == I_IMAGECALLBACK) ||
419 (*index == I_IMAGENONE)) return NULL;
420 ERR("TBN_GETDISPINFO returned invalid index %d\n",
427 case IMAGE_LIST_DEFAULT:
428 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
431 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 case IMAGE_LIST_DISABLED:
434 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 FIXME("Shouldn't reach here\n");
442 TRACE("no image list\n");
448 /***********************************************************************
449 * TOOLBAR_TestImageExist
451 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
452 * return the image list. The I_IMAGECALLBACK functionality is implemented.
455 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
459 if (!himl) return FALSE;
461 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
462 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
463 ERR("index %d is not valid, max %d\n",
464 btnPtr->iBitmap, infoPtr->nNumBitmaps);
468 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
469 if ((index == I_IMAGECALLBACK) ||
470 (index == I_IMAGENONE)) return FALSE;
471 ERR("TBN_GETDISPINFO returned invalid index %d\n",
480 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
483 COLORREF oldcolor, newcolor;
485 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
486 myrect.right = myrect.left + 1;
487 myrect.top = lpRect->top + 2;
488 myrect.bottom = lpRect->bottom - 2;
490 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
491 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
492 oldcolor = SetBkColor (hdc, newcolor);
493 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
495 myrect.left = myrect.right;
496 myrect.right = myrect.left + 1;
498 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
499 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
500 SetBkColor (hdc, newcolor);
501 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
503 SetBkColor (hdc, oldcolor);
507 /***********************************************************************
508 * TOOLBAR_DrawDDFlatSeparator
510 * This function draws the separator that was flagged as BTNS_DROPDOWN.
511 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
512 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
513 * are horizontal as opposed to the vertical separators for not dropdown
516 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
519 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
522 COLORREF oldcolor, newcolor;
524 myrect.left = lpRect->left;
525 myrect.right = lpRect->right;
526 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
527 myrect.bottom = myrect.top + 1;
529 InflateRect (&myrect, -2, 0);
531 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
532 myrect.left, myrect.top, myrect.right, myrect.bottom);
534 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
535 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
536 oldcolor = SetBkColor (hdc, newcolor);
537 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
539 myrect.top = myrect.bottom;
540 myrect.bottom = myrect.top + 1;
542 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
543 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
544 SetBkColor (hdc, newcolor);
545 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
547 SetBkColor (hdc, oldcolor);
552 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
557 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
558 hOldPen = SelectObject ( hdc, hPen );
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+5, y++); x++;
563 MoveToEx (hdc, x, y, NULL);
564 LineTo (hdc, x+3, y++); x++;
565 MoveToEx (hdc, x, y, NULL);
566 LineTo (hdc, x+1, y++);
567 SelectObject( hdc, hOldPen );
568 DeleteObject( hPen );
572 * Draw the text string for this button.
573 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
574 * is non-zero, so we can simply check himlDef to see if we have
578 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
579 NMTBCUSTOMDRAW *tbcd)
581 HDC hdc = tbcd->nmcd.hdc;
584 COLORREF clrOldBk = 0;
586 UINT state = tbcd->nmcd.uItemState;
590 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
591 rcText->left, rcText->top, rcText->right, rcText->bottom);
593 hOldFont = SelectObject (hdc, infoPtr->hFont);
594 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
595 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
597 else if (state & CDIS_DISABLED) {
598 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
599 OffsetRect (rcText, 1, 1);
600 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
601 SetTextColor (hdc, comctl32_color.clr3dShadow);
602 OffsetRect (rcText, -1, -1);
604 else if (state & CDIS_INDETERMINATE) {
605 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
607 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
608 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
609 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
610 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
613 clrOld = SetTextColor (hdc, tbcd->clrText);
616 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
617 SetTextColor (hdc, clrOld);
618 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
620 SetBkColor (hdc, clrOldBk);
621 SetBkMode (hdc, oldBkMode);
623 SelectObject (hdc, hOldFont);
629 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
631 HDC hdc = tbcd->nmcd.hdc;
632 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
635 INT cx = lpRect->right - lpRect->left;
636 INT cy = lpRect->bottom - lpRect->top;
637 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
638 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
639 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
640 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
641 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
642 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
643 SetBkColor(hdc, clrBkOld);
644 SetTextColor(hdc, clrTextOld);
645 SelectObject (hdc, hbr);
649 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
652 HBITMAP hbmMask, hbmImage;
653 HDC hdcMask, hdcImage;
655 ImageList_GetIconSize(himl, &cx, &cy);
657 /* Create src image */
658 hdcImage = CreateCompatibleDC(hdc);
659 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
660 SelectObject(hdcImage, hbmImage);
661 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
662 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
665 hdcMask = CreateCompatibleDC(0);
666 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
667 SelectObject(hdcMask, hbmMask);
669 /* Remove the background and all white pixels */
670 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
671 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
672 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
673 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
675 /* draw the new mask 'etched' to hdc */
676 SetBkColor(hdc, RGB(255, 255, 255));
677 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
678 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
679 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
680 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
681 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
684 DeleteObject(hbmImage);
686 DeleteObject (hbmMask);
692 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
696 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
698 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
699 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
700 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
701 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
702 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
706 /* draws the image on a toolbar button */
708 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
710 HIMAGELIST himl = NULL;
711 BOOL draw_masked = FALSE;
714 UINT draw_flags = ILD_TRANSPARENT;
716 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
718 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
721 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
725 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
727 /* if hot, attempt to draw with hot image list, if fails,
728 use default image list */
729 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
731 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
734 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
739 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
740 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
743 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
744 (tbcd->nmcd.uItemState & CDIS_MARKED))
745 draw_flags |= ILD_BLEND50;
747 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
748 index, himl, left, top, offset);
751 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
753 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
756 /* draws a blank frame for a toolbar button */
758 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
760 HDC hdc = tbcd->nmcd.hdc;
761 RECT rc = tbcd->nmcd.rc;
762 /* if the state is disabled or indeterminate then the button
763 * cannot have an interactive look like pressed or hot */
764 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
765 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
766 BOOL pressed_look = !non_interactive_state &&
767 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
768 (tbcd->nmcd.uItemState & CDIS_CHECKED));
770 /* app don't want us to draw any edges */
771 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
777 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
778 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
779 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
784 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
786 DrawEdge (hdc, &rc, EDGE_RAISED,
787 BF_SOFT | BF_RECT | BF_MIDDLE);
792 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
794 HDC hdc = tbcd->nmcd.hdc;
796 BOOL pressed = bDropDownPressed ||
797 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
799 if (infoPtr->dwStyle & TBSTYLE_FLAT)
802 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
803 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
804 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
805 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
806 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
811 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
813 DrawEdge (hdc, rcArrow, EDGE_RAISED,
814 BF_SOFT | BF_RECT | BF_MIDDLE);
818 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
820 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
822 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
823 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
826 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
829 /* draws a complete toolbar button */
831 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
834 DWORD dwStyle = infoPtr->dwStyle;
835 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
836 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
837 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 BOOL drawSepDropDownArrow = hasDropDownArrow &&
839 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
840 RECT rc, rcArrow, rcBitmap, rcText;
841 LPWSTR lpText = NULL;
847 CopyRect (&rcArrow, &rc);
848 CopyRect(&rcBitmap, &rc);
850 /* get a pointer to the text */
851 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
853 if (hasDropDownArrow)
857 if (dwStyle & TBSTYLE_FLAT)
858 right = max(rc.left, rc.right - DDARROW_WIDTH);
860 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
862 if (drawSepDropDownArrow)
865 rcArrow.left = right;
868 /* copy text rect after adjusting for drop-down arrow
869 * so that text is centred in the rectangle not containing
871 CopyRect(&rcText, &rc);
873 /* Center the bitmap horizontally and vertically */
874 if (dwStyle & TBSTYLE_LIST)
875 rcBitmap.left += GetSystemMetrics(SM_CXEDGE);
877 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
880 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE);
882 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
884 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
885 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
886 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
887 TRACE ("iString: %x\n", btnPtr->iString);
888 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
892 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
893 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
894 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
895 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
897 if (dwStyle & TBSTYLE_LIST)
898 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
900 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
903 if (dwStyle & TBSTYLE_LIST)
904 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
906 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
907 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
908 OffsetRect(&rcText, 1, 1);
911 /* Initialize fields in all cases, because we use these later
912 * NOTE: applications can and do alter these to customize their
914 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
915 tbcd.clrText = comctl32_color.clrBtnText;
916 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
917 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
918 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
919 tbcd.clrMark = comctl32_color.clrHighlight;
920 tbcd.clrHighlightHotTrack = 0;
921 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
922 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
923 /* MSDN says that this is the text rectangle.
924 * But (why always a but) tracing of v5.7 of native shows
925 * that this is really a *relative* rectangle based on the
926 * the nmcd.rc. Also the left and top are always 0 ignoring
927 * any bitmap that might be present. */
928 tbcd.rcText.left = 0;
930 tbcd.rcText.right = rcText.right - rc.left;
931 tbcd.rcText.bottom = rcText.bottom - rc.top;
932 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
935 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
937 /* FIXME: what are these used for? */
941 /* Issue Item Prepaint notify */
942 infoPtr->dwItemCustDraw = 0;
943 infoPtr->dwItemCDFlag = 0;
944 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
946 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
947 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
948 tbcd.nmcd.lItemlParam = btnPtr->dwData;
949 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
950 /* reset these fields so the user can't alter the behaviour like native */
954 infoPtr->dwItemCustDraw = ntfret & 0xffff;
955 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
956 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
958 /* save the only part of the rect that the user can change */
959 rcText.right = tbcd.rcText.right + rc.left;
960 rcText.bottom = tbcd.rcText.bottom + rc.top;
964 if (btnPtr->fsStyle & BTNS_SEP) {
965 /* with the FLAT style, iBitmap is the width and has already */
966 /* been taken into consideration in calculating the width */
967 /* so now we need to draw the vertical separator */
968 /* empirical tests show that iBitmap can/will be non-zero */
969 /* when drawing the vertical bar... */
970 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
971 if (btnPtr->fsStyle & BTNS_DROPDOWN)
972 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
974 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
976 else if (btnPtr->fsStyle != BTNS_SEP) {
977 FIXME("Draw some kind of separator: fsStyle=%x\n",
983 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
984 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
985 TOOLBAR_DrawPattern (&rc, &tbcd);
987 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
989 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
993 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
994 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
995 if (hasDropDownArrow)
996 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
997 SetBkColor(hdc, oldclr);
1001 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1003 if (drawSepDropDownArrow)
1004 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1006 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1007 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1009 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1011 if (hasDropDownArrow && !drawSepDropDownArrow)
1013 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1015 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1016 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1018 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1020 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1021 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1028 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1030 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1031 tbcd.nmcd.hdc = hdc;
1033 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1034 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1035 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1036 tbcd.rcText = rcText;
1037 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1038 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1039 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1046 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1049 TBUTTON_INFO *btnPtr;
1050 INT i, oldBKmode = 0;
1051 RECT rcTemp, rcClient;
1052 NMTBCUSTOMDRAW tbcd;
1055 /* the app has told us not to redraw the toolbar */
1056 if (!infoPtr->bDoRedraw)
1059 /* if imagelist belongs to the app, it can be changed
1060 by the app after setting it */
1061 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1063 infoPtr->nNumBitmaps = 0;
1064 for (i = 0; i < infoPtr->cimlDef; i++)
1065 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1068 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1070 /* Send initial notify */
1071 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1072 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1073 tbcd.nmcd.hdc = hdc;
1074 tbcd.nmcd.rc = ps->rcPaint;
1075 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1076 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1078 if (infoPtr->bBtnTranspnt)
1079 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1081 GetClientRect(hwnd, &rcClient);
1083 /* redraw necessary buttons */
1084 btnPtr = infoPtr->buttons;
1085 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1088 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1090 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1091 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1095 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1096 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1098 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1101 /* draw insert mark if required */
1102 if (infoPtr->tbim.iButton != -1)
1104 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1106 rcInsertMark.top = rcButton.top;
1107 rcInsertMark.bottom = rcButton.bottom;
1108 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1109 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1111 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1112 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1115 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1116 SetBkMode (hdc, oldBKmode);
1118 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1120 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1121 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1122 tbcd.nmcd.hdc = hdc;
1123 tbcd.nmcd.rc = ps->rcPaint;
1124 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1128 /***********************************************************************
1129 * TOOLBAR_MeasureString
1131 * This function gets the width and height of a string in pixels. This
1132 * is done first by using GetTextExtentPoint to get the basic width
1133 * and height. The DrawText is called with DT_CALCRECT to get the exact
1134 * width. The reason is because the text may have more than one "&" (or
1135 * prefix characters as M$ likes to call them). The prefix character
1136 * indicates where the underline goes, except for the string "&&" which
1137 * is reduced to a single "&". GetTextExtentPoint does not process these
1138 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1141 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1142 HDC hdc, LPSIZE lpSize)
1149 if (infoPtr->nMaxTextRows > 0 &&
1150 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1151 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1152 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1154 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1156 if(lpText != NULL) {
1157 /* first get size of all the text */
1158 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1160 /* feed above size into the rectangle for DrawText */
1161 myrect.left = myrect.top = 0;
1162 myrect.right = lpSize->cx;
1163 myrect.bottom = lpSize->cy;
1165 /* Use DrawText to get true size as drawn (less pesky "&") */
1166 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1167 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1170 /* feed back to caller */
1171 lpSize->cx = myrect.right;
1172 lpSize->cy = myrect.bottom;
1176 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1179 /***********************************************************************
1180 * TOOLBAR_CalcStrings
1182 * This function walks through each string and measures it and returns
1183 * the largest height and width to caller.
1186 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1189 TBUTTON_INFO *btnPtr;
1198 if(infoPtr->nMaxTextRows == 0)
1202 hOldFont = SelectObject (hdc, infoPtr->hFont);
1204 btnPtr = infoPtr->buttons;
1205 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1206 if(TOOLBAR_HasText(infoPtr, btnPtr))
1208 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1209 if (sz.cx > lpSize->cx)
1211 if (sz.cy > lpSize->cy)
1216 SelectObject (hdc, hOldFont);
1217 ReleaseDC (hwnd, hdc);
1219 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1222 /***********************************************************************
1223 * TOOLBAR_WrapToolbar
1225 * This function walks through the buttons and separators in the
1226 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1227 * wrapping should occur based on the width of the toolbar window.
1228 * It does *not* calculate button placement itself. That task
1229 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1230 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1231 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1233 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1234 * vertical toolbar lists.
1238 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1241 TBUTTON_INFO *btnPtr;
1244 BOOL bWrap, bButtonWrap;
1246 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1247 /* no layout is necessary. Applications may use this style */
1248 /* to perform their own layout on the toolbar. */
1249 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1250 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1252 btnPtr = infoPtr->buttons;
1253 x = infoPtr->nIndent;
1255 /* this can get the parents width, to know how far we can extend
1256 * this toolbar. We cannot use its height, as there may be multiple
1257 * toolbars in a rebar control
1259 GetClientRect( GetParent(hwnd), &rc );
1260 infoPtr->nWidth = rc.right - rc.left;
1261 bButtonWrap = FALSE;
1263 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1264 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1267 for (i = 0; i < infoPtr->nNumButtons; i++ )
1270 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1272 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1275 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1276 /* it is the actual width of the separator. This is used for */
1277 /* custom controls in toolbars. */
1279 /* BTNS_DROPDOWN separators are treated as buttons for */
1280 /* width. - GA 8/01 */
1281 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1282 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1283 cx = (btnPtr[i].iBitmap > 0) ?
1284 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1286 cx = infoPtr->nButtonWidth;
1288 /* Two or more adjacent separators form a separator group. */
1289 /* The first separator in a group should be wrapped to the */
1290 /* next row if the previous wrapping is on a button. */
1292 (btnPtr[i].fsStyle & BTNS_SEP) &&
1293 (i + 1 < infoPtr->nNumButtons ) &&
1294 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1296 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1297 btnPtr[i].fsState |= TBSTATE_WRAP;
1298 x = infoPtr->nIndent;
1300 bButtonWrap = FALSE;
1304 /* The layout makes sure the bitmap is visible, but not the button. */
1305 /* Test added to also wrap after a button that starts a row but */
1306 /* is bigger than the area. - GA 8/01 */
1307 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1308 > infoPtr->nWidth ) ||
1309 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1311 BOOL bFound = FALSE;
1313 /* If the current button is a separator and not hidden, */
1314 /* go to the next until it reaches a non separator. */
1315 /* Wrap the last separator if it is before a button. */
1316 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1317 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1318 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1319 i < infoPtr->nNumButtons )
1325 if( bFound && i < infoPtr->nNumButtons )
1328 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1329 i, btnPtr[i].fsStyle, x, cx);
1330 btnPtr[i].fsState |= TBSTATE_WRAP;
1331 x = infoPtr->nIndent;
1332 bButtonWrap = FALSE;
1335 else if ( i >= infoPtr->nNumButtons)
1338 /* If the current button is not a separator, find the last */
1339 /* separator and wrap it. */
1340 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1342 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1343 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1347 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1348 i, btnPtr[i].fsStyle, x, cx);
1349 x = infoPtr->nIndent;
1350 btnPtr[j].fsState |= TBSTATE_WRAP;
1351 bButtonWrap = FALSE;
1356 /* If no separator available for wrapping, wrap one of */
1357 /* non-hidden previous button. */
1361 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1363 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1368 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1369 i, btnPtr[i].fsStyle, x, cx);
1370 x = infoPtr->nIndent;
1371 btnPtr[j].fsState |= TBSTATE_WRAP;
1377 /* If all above failed, wrap the current button. */
1380 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1381 i, btnPtr[i].fsStyle, x, cx);
1382 btnPtr[i].fsState |= TBSTATE_WRAP;
1384 x = infoPtr->nIndent;
1385 if (btnPtr[i].fsStyle & BTNS_SEP )
1386 bButtonWrap = FALSE;
1392 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1393 i, btnPtr[i].fsStyle, x, cx);
1400 /***********************************************************************
1401 * TOOLBAR_CalcToolbar
1403 * This function calculates button and separator placement. It first
1404 * calculates the button sizes, gets the toolbar window width and then
1405 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1406 * on. It assigns a new location to each item and sends this location to
1407 * the tooltip window if appropriate. Finally, it updates the rcBound
1408 * rect and calculates the new required toolbar window height.
1412 TOOLBAR_CalcToolbar (HWND hwnd)
1414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1415 DWORD dwStyle = infoPtr->dwStyle;
1416 TBUTTON_INFO *btnPtr;
1417 INT i, nRows, nSepRows;
1421 BOOL usesBitmaps = FALSE;
1422 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1424 TOOLBAR_CalcStrings (hwnd, &sizeString);
1426 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1428 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1430 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1433 if (dwStyle & TBSTYLE_LIST)
1435 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1436 0, sizeString.cy) + infoPtr->szPadding.cy;
1437 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1438 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1439 if (sizeString.cx > 0)
1440 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1441 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1442 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1443 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1446 if (sizeString.cy > 0)
1449 infoPtr->nButtonHeight = sizeString.cy +
1450 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1451 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1453 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1456 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1458 if (sizeString.cx > infoPtr->nBitmapWidth)
1459 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1461 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1464 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1465 infoPtr->nButtonWidth = infoPtr->cxMin;
1466 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1467 infoPtr->nButtonWidth = infoPtr->cxMax;
1469 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1471 x = infoPtr->nIndent;
1474 /* from above, minimum is a button, and possible text */
1475 cx = infoPtr->nButtonWidth;
1477 /* cannot use just ButtonHeight, we may have no buttons! */
1478 if (infoPtr->nNumButtons > 0)
1479 infoPtr->nHeight = infoPtr->nButtonHeight;
1481 cy = infoPtr->nHeight;
1483 nRows = nSepRows = 0;
1485 infoPtr->rcBound.top = y;
1486 infoPtr->rcBound.left = x;
1487 infoPtr->rcBound.bottom = y + cy;
1488 infoPtr->rcBound.right = x;
1490 btnPtr = infoPtr->buttons;
1492 TRACE("cy=%d\n", cy);
1494 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1497 if (btnPtr->fsState & TBSTATE_HIDDEN)
1499 SetRectEmpty (&btnPtr->rect);
1503 cy = infoPtr->nHeight;
1505 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1506 /* it is the actual width of the separator. This is used for */
1507 /* custom controls in toolbars. */
1508 if (btnPtr->fsStyle & BTNS_SEP) {
1509 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1510 cy = (btnPtr->iBitmap > 0) ?
1511 btnPtr->iBitmap : SEPARATOR_WIDTH;
1512 cx = infoPtr->nButtonWidth;
1515 cx = (btnPtr->iBitmap > 0) ?
1516 btnPtr->iBitmap : SEPARATOR_WIDTH;
1522 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1523 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1530 hOldFont = SelectObject (hdc, infoPtr->hFont);
1532 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1534 SelectObject (hdc, hOldFont);
1535 ReleaseDC (hwnd, hdc);
1537 /* add space on for button frame, etc */
1538 cx = sz.cx + infoPtr->szPadding.cx;
1540 /* add list padding */
1541 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1542 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1544 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1546 if (dwStyle & TBSTYLE_LIST)
1547 cx += infoPtr->nBitmapWidth;
1548 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1549 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1551 else if (dwStyle & TBSTYLE_LIST)
1552 cx += LIST_IMAGE_ABSENT_WIDTH;
1555 cx = infoPtr->nButtonWidth;
1557 /* if size has been set manually then don't add on extra space
1558 * for the drop down arrow */
1559 if (!btnPtr->cx && hasDropDownArrows &&
1560 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1561 cx += DDARROW_WIDTH;
1563 if (btnPtr->fsState & TBSTATE_WRAP )
1566 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1568 if (infoPtr->rcBound.left > x)
1569 infoPtr->rcBound.left = x;
1570 if (infoPtr->rcBound.right < x + cx)
1571 infoPtr->rcBound.right = x + cx;
1572 if (infoPtr->rcBound.bottom < y + cy)
1573 infoPtr->rcBound.bottom = y + cy;
1575 /* Set the toolTip only for non-hidden, non-separator button */
1576 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1580 ZeroMemory (&ti, sizeof(ti));
1581 ti.cbSize = sizeof(ti);
1583 ti.uId = btnPtr->idCommand;
1584 ti.rect = btnPtr->rect;
1585 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1589 /* btnPtr->nRow is zero based. The space between the rows is */
1590 /* also considered as a row. */
1591 btnPtr->nRow = nRows + nSepRows;
1593 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1594 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1599 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1603 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1604 /* it is the actual width of the separator. This is used for */
1605 /* custom controls in toolbars. */
1606 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1607 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1608 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1612 /* nSepRows is used to calculate the extra height follwoing */
1616 x = infoPtr->nIndent;
1618 /* Increment row number unless this is the last button */
1619 /* and it has Wrap set. */
1620 if (i != infoPtr->nNumButtons-1)
1627 /* infoPtr->nRows is the number of rows on the toolbar */
1628 infoPtr->nRows = nRows + nSepRows + 1;
1631 /********************************************************************
1632 * The following while interesting, does not match the values *
1633 * created above for the button rectangles, nor the rcBound rect. *
1634 * We will comment it out and remove it later. *
1636 * The problem showed up as heights in the pager control that was *
1638 ********************************************************************/
1640 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1642 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1643 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1644 nSepRows * (infoPtr->nBitmapHeight + 1) +
1648 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1650 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1655 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1658 TBUTTON_INFO *btnPtr;
1661 btnPtr = infoPtr->buttons;
1662 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1663 if (btnPtr->fsState & TBSTATE_HIDDEN)
1666 if (btnPtr->fsStyle & BTNS_SEP) {
1667 if (PtInRect (&btnPtr->rect, *lpPt)) {
1668 TRACE(" ON SEPARATOR %d!\n", i);
1673 if (PtInRect (&btnPtr->rect, *lpPt)) {
1674 TRACE(" ON BUTTON %d!\n", i);
1680 TRACE(" NOWHERE!\n");
1681 return TOOLBAR_NOWHERE;
1686 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1688 TBUTTON_INFO *btnPtr;
1691 if (CommandIsIndex) {
1692 TRACE("command is really index command=%d\n", idCommand);
1693 if (idCommand >= infoPtr->nNumButtons) return -1;
1696 btnPtr = infoPtr->buttons;
1697 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1698 if (btnPtr->idCommand == idCommand) {
1699 TRACE("command=%d index=%d\n", idCommand, i);
1703 TRACE("no index found for command=%d\n", idCommand);
1709 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1711 TBUTTON_INFO *btnPtr;
1714 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1717 /* check index button */
1718 btnPtr = &infoPtr->buttons[nIndex];
1719 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1720 if (btnPtr->fsState & TBSTATE_CHECKED)
1724 /* check previous buttons */
1725 nRunIndex = nIndex - 1;
1726 while (nRunIndex >= 0) {
1727 btnPtr = &infoPtr->buttons[nRunIndex];
1728 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1729 if (btnPtr->fsState & TBSTATE_CHECKED)
1737 /* check next buttons */
1738 nRunIndex = nIndex + 1;
1739 while (nRunIndex < infoPtr->nNumButtons) {
1740 btnPtr = &infoPtr->buttons[nRunIndex];
1741 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1742 if (btnPtr->fsState & TBSTATE_CHECKED)
1755 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1756 WPARAM wParam, LPARAM lParam)
1762 msg.wParam = wParam;
1763 msg.lParam = lParam;
1764 msg.time = GetMessageTime ();
1765 msg.pt.x = LOWORD(GetMessagePos ());
1766 msg.pt.y = HIWORD(GetMessagePos ());
1768 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1771 /* keeps available button list box sorted by button id */
1772 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1776 PCUSTOMBUTTON btnInfo;
1777 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1779 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1781 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1783 /* position 0 is always separator */
1784 for (i = 1; i < count; i++)
1786 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1787 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1789 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1790 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1794 /* id higher than all others add to end */
1795 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1796 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1799 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1803 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1805 if (nIndexFrom == nIndexTo)
1808 /* MSDN states that iItem is the index of the button, rather than the
1809 * command ID as used by every other NMTOOLBAR notification */
1810 nmtb.iItem = nIndexFrom;
1811 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1813 PCUSTOMBUTTON btnInfo;
1815 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1816 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1818 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1820 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1821 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1822 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1823 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1826 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1828 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1830 /* last item is always separator, so -2 instead of -1 */
1831 if (nIndexTo >= (count - 2))
1832 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1834 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1836 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1837 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1839 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1843 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1847 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1849 /* MSDN states that iItem is the index of the button, rather than the
1850 * command ID as used by every other NMTOOLBAR notification */
1851 nmtb.iItem = nIndexAvail;
1852 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
1854 PCUSTOMBUTTON btnInfo;
1856 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1857 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1858 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1860 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1862 if (nIndexAvail != 0) /* index == 0 indicates separator */
1864 /* remove from 'available buttons' list */
1865 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1866 if (nIndexAvail == count-1)
1867 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1869 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1873 PCUSTOMBUTTON btnNew;
1875 /* duplicate 'separator' button */
1876 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1877 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1881 /* insert into 'toolbar button' list */
1882 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1883 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1885 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1887 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1891 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1893 PCUSTOMBUTTON btnInfo;
1894 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1896 TRACE("Remove: index %d\n", index);
1898 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
1900 /* send TBN_QUERYDELETE notification */
1901 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
1905 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
1906 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
1908 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1910 /* insert into 'available button' list */
1911 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
1912 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
1916 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1920 /* drag list notification function for toolbar buttons list box */
1921 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1923 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1924 switch (pDLI->uNotification)
1928 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1929 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1930 /* no dragging for last item (separator) */
1931 if (nCurrentItem >= (nCount - 1)) return FALSE;
1936 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1937 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1938 /* no dragging past last item (separator) */
1939 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
1941 DrawInsert(hwnd, hwndList, nCurrentItem);
1942 /* FIXME: native uses "move button" cursor */
1943 return DL_COPYCURSOR;
1946 /* not over toolbar buttons list */
1947 if (nCurrentItem < 0)
1949 POINT ptWindow = pDLI->ptCursor;
1950 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1951 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1952 /* over available buttons list? */
1953 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1954 /* FIXME: native uses "move button" cursor */
1955 return DL_COPYCURSOR;
1957 /* clear drag arrow */
1958 DrawInsert(hwnd, hwndList, -1);
1959 return DL_STOPCURSOR;
1963 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1964 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
1965 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1966 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
1968 /* clear drag arrow */
1969 DrawInsert(hwnd, hwndList, -1);
1971 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
1973 /* not over toolbar buttons list */
1976 POINT ptWindow = pDLI->ptCursor;
1977 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1978 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1979 /* over available buttons list? */
1980 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1981 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
1986 /* Clear drag arrow */
1987 DrawInsert(hwnd, hwndList, -1);
1994 /* drag list notification function for available buttons list box */
1995 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1997 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1998 switch (pDLI->uNotification)
2004 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2005 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2006 /* no dragging past last item (separator) */
2007 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2009 DrawInsert(hwnd, hwndList, nCurrentItem);
2010 /* FIXME: native uses "move button" cursor */
2011 return DL_COPYCURSOR;
2014 /* not over toolbar buttons list */
2015 if (nCurrentItem < 0)
2017 POINT ptWindow = pDLI->ptCursor;
2018 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2019 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2020 /* over available buttons list? */
2021 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2022 /* FIXME: native uses "move button" cursor */
2023 return DL_COPYCURSOR;
2025 /* clear drag arrow */
2026 DrawInsert(hwnd, hwndList, -1);
2027 return DL_STOPCURSOR;
2031 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2032 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2033 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2034 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2036 /* clear drag arrow */
2037 DrawInsert(hwnd, hwndList, -1);
2039 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2043 /* Clear drag arrow */
2044 DrawInsert(hwnd, hwndList, -1);
2050 extern UINT uDragListMessage;
2052 /***********************************************************************
2053 * TOOLBAR_CustomizeDialogProc
2054 * This function implements the toolbar customization dialog.
2056 static INT_PTR CALLBACK
2057 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2059 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2060 PCUSTOMBUTTON btnInfo;
2062 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2067 custInfo = (PCUSTDLG_INFO)lParam;
2068 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2076 infoPtr = custInfo->tbInfo;
2078 /* send TBN_QUERYINSERT notification */
2079 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2081 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2084 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2085 /* FIXME: this hack won't work on 64-bit - we need to declare a structure for this */
2086 nmtb.iItem = (int)hwnd;
2087 /* Send TBN_INITCUSTOMIZE notification */
2088 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2091 TRACE("TBNRF_HIDEHELP requested\n");
2092 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2095 /* add items to 'toolbar buttons' list and check if removable */
2096 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2098 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2099 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2100 btnInfo->btn.fsStyle = BTNS_SEP;
2101 btnInfo->bVirtual = FALSE;
2102 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2104 /* send TBN_QUERYDELETE notification */
2105 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2107 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2108 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2111 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2113 /* insert separator button into 'available buttons' list */
2114 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2115 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2116 btnInfo->btn.fsStyle = BTNS_SEP;
2117 btnInfo->bVirtual = FALSE;
2118 btnInfo->bRemovable = TRUE;
2119 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2120 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2121 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2123 /* insert all buttons into dsa */
2126 /* send TBN_GETBUTTONINFO notification */
2129 nmtb.pszText = Buffer;
2132 /* Clear previous button's text */
2133 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2135 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2138 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2139 nmtb.tbButton.fsStyle, i,
2140 nmtb.tbButton.idCommand,
2141 nmtb.tbButton.iString,
2142 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2145 /* insert button into the apropriate list */
2146 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2149 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2150 btnInfo->bVirtual = FALSE;
2151 btnInfo->bRemovable = TRUE;
2155 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2156 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2159 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2160 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2162 if (lstrlenW(nmtb.pszText))
2163 lstrcpyW(btnInfo->text, nmtb.pszText);
2164 else if (nmtb.tbButton.iString >= 0 &&
2165 nmtb.tbButton.iString < infoPtr->nNumStrings)
2167 lstrcpyW(btnInfo->text,
2168 infoPtr->strings[nmtb.tbButton.iString]);
2173 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2176 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2178 /* select first item in the 'available' list */
2179 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2181 /* append 'virtual' separator button to the 'toolbar buttons' list */
2182 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2183 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2184 btnInfo->btn.fsStyle = BTNS_SEP;
2185 btnInfo->bVirtual = TRUE;
2186 btnInfo->bRemovable = FALSE;
2187 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2188 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2189 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2191 /* select last item in the 'toolbar' list */
2192 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2193 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2195 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2196 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2198 /* set focus and disable buttons */
2199 PostMessageW (hwnd, WM_USER, 0, 0);
2204 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2205 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2206 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2207 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2211 EndDialog(hwnd, FALSE);
2215 switch (LOWORD(wParam))
2217 case IDC_TOOLBARBTN_LBOX:
2218 if (HIWORD(wParam) == LBN_SELCHANGE)
2220 PCUSTOMBUTTON btnInfo;
2225 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2226 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2228 /* send TBN_QUERYINSERT notification */
2230 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2232 /* get list box item */
2233 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2235 if (index == (count - 1))
2237 /* last item (virtual separator) */
2238 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2239 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2241 else if (index == (count - 2))
2243 /* second last item (last non-virtual item) */
2244 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2245 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2247 else if (index == 0)
2250 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2251 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2255 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2256 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2259 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2263 case IDC_MOVEUP_BTN:
2265 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2266 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2270 case IDC_MOVEDN_BTN: /* move down */
2272 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2273 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2277 case IDC_REMOVE_BTN: /* remove button */
2279 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2281 if (LB_ERR == index)
2284 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2288 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2291 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2294 case IDOK: /* Add button */
2299 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2300 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2302 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2307 EndDialog(hwnd, FALSE);
2317 /* delete items from 'toolbar buttons' listbox*/
2318 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2319 for (i = 0; i < count; i++)
2321 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2323 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2325 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2328 /* delete items from 'available buttons' listbox*/
2329 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2330 for (i = 0; i < count; i++)
2332 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2334 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2336 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2341 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2343 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2348 COLORREF oldText = 0;
2352 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2353 if (btnInfo == NULL)
2355 FIXME("btnInfo invalid!\n");
2359 /* set colors and select objects */
2360 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2361 if (btnInfo->bVirtual)
2362 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2364 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2365 hPen = CreatePen( PS_SOLID, 1,
2366 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2367 hOldPen = SelectObject (lpdis->hDC, hPen );
2368 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2370 /* fill background rectangle */
2371 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2372 lpdis->rcItem.right, lpdis->rcItem.bottom);
2374 /* calculate button and text rectangles */
2375 CopyRect (&rcButton, &lpdis->rcItem);
2376 InflateRect (&rcButton, -1, -1);
2377 CopyRect (&rcText, &rcButton);
2378 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2379 rcText.left = rcButton.right + 2;
2381 /* draw focus rectangle */
2382 if (lpdis->itemState & ODS_FOCUS)
2383 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2386 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2387 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2389 /* draw image and text */
2390 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2391 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2392 btnInfo->btn.iBitmap));
2393 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2394 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2396 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2397 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2399 /* delete objects and reset colors */
2400 SelectObject (lpdis->hDC, hOldBrush);
2401 SelectObject (lpdis->hDC, hOldPen);
2402 SetBkColor (lpdis->hDC, oldBk);
2403 SetTextColor (lpdis->hDC, oldText);
2404 DeleteObject( hPen );
2409 case WM_MEASUREITEM:
2410 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2412 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2414 lpmis->itemHeight = 15 + 8; /* default height */
2421 if (uDragListMessage && (uMsg == uDragListMessage))
2423 if (wParam == IDC_TOOLBARBTN_LBOX)
2425 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2426 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2427 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2430 else if (wParam == IDC_AVAILBTN_LBOX)
2432 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2433 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2434 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2443 /***********************************************************************
2444 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2448 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2451 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2452 INT nIndex = 0, nButtons, nCount;
2456 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2460 if (lpAddBmp->hInst == HINST_COMMCTRL)
2462 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2464 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2466 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2471 TRACE ("adding %d internal bitmaps!\n", nButtons);
2473 /* Windows resize all the buttons to the size of a newly added standard image */
2474 if (lpAddBmp->nID & 1)
2477 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2478 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2480 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2481 MAKELPARAM((WORD)24, (WORD)24));
2482 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2483 MAKELPARAM((WORD)31, (WORD)30));
2488 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2489 MAKELPARAM((WORD)16, (WORD)16));
2490 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2491 MAKELPARAM((WORD)22, (WORD)22));
2494 TOOLBAR_CalcToolbar (hwnd);
2498 nButtons = (INT)wParam;
2502 TRACE ("adding %d bitmaps!\n", nButtons);
2505 if (!infoPtr->cimlDef) {
2506 /* create new default image list */
2507 TRACE ("creating default image list!\n");
2509 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2510 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2511 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2512 infoPtr->himlInt = himlDef;
2515 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2519 WARN("No default image list available\n");
2523 nCount = ImageList_GetImageCount(himlDef);
2525 /* Add bitmaps to the default image list */
2526 if (lpAddBmp->hInst == NULL)
2529 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2530 HDC hdcImage, hdcBitmap;
2532 /* copy the bitmap before adding it so that the user's bitmap
2533 * doesn't get modified.
2535 GetObjectW ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2537 hdcImage = CreateCompatibleDC(0);
2538 hdcBitmap = CreateCompatibleDC(0);
2540 /* create new bitmap */
2541 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2542 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2543 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2545 /* Copy the user's image */
2546 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2547 hdcBitmap, 0, 0, SRCCOPY);
2549 SelectObject (hdcImage, hOldBitmapLoad);
2550 SelectObject (hdcBitmap, hOldBitmapBitmap);
2551 DeleteDC (hdcImage);
2552 DeleteDC (hdcBitmap);
2554 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2555 DeleteObject (hbmLoad);
2557 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2559 /* Add system bitmaps */
2560 switch (lpAddBmp->nID)
2562 case IDB_STD_SMALL_COLOR:
2563 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2564 MAKEINTRESOURCEW(IDB_STD_SMALL));
2565 nIndex = ImageList_AddMasked (himlDef,
2566 hbmLoad, comctl32_color.clrBtnFace);
2567 DeleteObject (hbmLoad);
2570 case IDB_STD_LARGE_COLOR:
2571 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2572 MAKEINTRESOURCEW(IDB_STD_LARGE));
2573 nIndex = ImageList_AddMasked (himlDef,
2574 hbmLoad, comctl32_color.clrBtnFace);
2575 DeleteObject (hbmLoad);
2578 case IDB_VIEW_SMALL_COLOR:
2579 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2580 MAKEINTRESOURCEW(IDB_VIEW_SMALL));
2581 nIndex = ImageList_AddMasked (himlDef,
2582 hbmLoad, comctl32_color.clrBtnFace);
2583 DeleteObject (hbmLoad);
2586 case IDB_VIEW_LARGE_COLOR:
2587 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2588 MAKEINTRESOURCEW(IDB_VIEW_LARGE));
2589 nIndex = ImageList_AddMasked (himlDef,
2590 hbmLoad, comctl32_color.clrBtnFace);
2591 DeleteObject (hbmLoad);
2594 case IDB_HIST_SMALL_COLOR:
2595 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2596 MAKEINTRESOURCEW(IDB_HIST_SMALL));
2597 nIndex = ImageList_AddMasked (himlDef,
2598 hbmLoad, comctl32_color.clrBtnFace);
2599 DeleteObject (hbmLoad);
2602 case IDB_HIST_LARGE_COLOR:
2603 hbmLoad = LoadBitmapW (COMCTL32_hModule,
2604 MAKEINTRESOURCEW(IDB_HIST_LARGE));
2605 nIndex = ImageList_AddMasked (himlDef,
2606 hbmLoad, comctl32_color.clrBtnFace);
2607 DeleteObject (hbmLoad);
2611 nIndex = ImageList_GetImageCount (himlDef);
2612 ERR ("invalid imagelist!\n");
2618 hbmLoad = LoadBitmapW (lpAddBmp->hInst, (LPWSTR)lpAddBmp->nID);
2619 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2620 DeleteObject (hbmLoad);
2623 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2625 if (infoPtr->nNumBitmapInfos == 0)
2627 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2631 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2632 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2633 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2636 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2637 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2638 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2640 infoPtr->nNumBitmapInfos++;
2641 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2645 INT imagecount = ImageList_GetImageCount(himlDef);
2647 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2649 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",
2650 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2651 infoPtr->nNumBitmaps+nButtons,imagecount);
2653 infoPtr->nNumBitmaps = imagecount;
2656 infoPtr->nNumBitmaps += nButtons;
2659 InvalidateRect(hwnd, NULL, TRUE);
2666 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2669 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2670 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2672 TRACE("adding %d buttons!\n", wParam);
2674 nAddButtons = (UINT)wParam;
2675 nOldButtons = infoPtr->nNumButtons;
2676 nNewButtons = nOldButtons + nAddButtons;
2678 if (infoPtr->nNumButtons == 0) {
2680 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2683 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2685 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2686 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2687 nOldButtons * sizeof(TBUTTON_INFO));
2691 infoPtr->nNumButtons = nNewButtons;
2693 /* insert new button data */
2694 for (nCount = 0; nCount < nAddButtons; nCount++) {
2695 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2696 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2697 btnPtr->idCommand = lpTbb[nCount].idCommand;
2698 btnPtr->fsState = lpTbb[nCount].fsState;
2699 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2700 btnPtr->dwData = lpTbb[nCount].dwData;
2701 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2702 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2704 btnPtr->iString = lpTbb[nCount].iString;
2705 btnPtr->bHot = FALSE;
2707 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2710 ZeroMemory (&ti, sizeof(ti));
2711 ti.cbSize = sizeof(ti);
2713 ti.uId = btnPtr->idCommand;
2715 ti.lpszText = LPSTR_TEXTCALLBACKW;
2717 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2722 TOOLBAR_CalcToolbar (hwnd);
2724 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2726 InvalidateRect(hwnd, NULL, TRUE);
2733 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2735 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2736 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2737 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2739 TRACE("adding %d buttons!\n", wParam);
2741 nAddButtons = (UINT)wParam;
2742 nOldButtons = infoPtr->nNumButtons;
2743 nNewButtons = nOldButtons + nAddButtons;
2745 if (infoPtr->nNumButtons == 0) {
2747 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2750 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2752 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2753 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2754 nOldButtons * sizeof(TBUTTON_INFO));
2758 infoPtr->nNumButtons = nNewButtons;
2760 /* insert new button data */
2761 for (nCount = 0; nCount < nAddButtons; nCount++) {
2762 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2763 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2764 btnPtr->idCommand = lpTbb[nCount].idCommand;
2765 btnPtr->fsState = lpTbb[nCount].fsState;
2766 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2767 btnPtr->dwData = lpTbb[nCount].dwData;
2768 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2769 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2771 btnPtr->iString = lpTbb[nCount].iString;
2772 btnPtr->bHot = FALSE;
2774 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2777 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2778 ti.cbSize = sizeof (TTTOOLINFOW);
2780 ti.uId = btnPtr->idCommand;
2782 ti.lpszText = LPSTR_TEXTCALLBACKW;
2785 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2790 TOOLBAR_CalcToolbar (hwnd);
2792 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2794 InvalidateRect(hwnd, NULL, TRUE);
2801 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2803 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2806 if ((wParam) && (HIWORD(lParam) == 0)) {
2809 TRACE("adding string from resource!\n");
2811 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam, szString, sizeof(szString));
2813 TRACE("len=%d \"%s\"\n", len, szString);
2814 nIndex = infoPtr->nNumStrings;
2815 if (infoPtr->nNumStrings == 0) {
2817 Alloc (sizeof(LPWSTR));
2820 LPWSTR *oldStrings = infoPtr->strings;
2822 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2823 memcpy (&infoPtr->strings[0], &oldStrings[0],
2824 sizeof(LPWSTR) * infoPtr->nNumStrings);
2828 /*Alloc zeros out the allocated memory*/
2829 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2830 infoPtr->nNumStrings++;
2833 LPSTR p = (LPSTR)lParam;
2838 TRACE("adding string(s) from array!\n");
2840 nIndex = infoPtr->nNumStrings;
2843 TRACE("len=%d \"%s\"\n", len, p);
2845 if (infoPtr->nNumStrings == 0) {
2847 Alloc (sizeof(LPWSTR));
2850 LPWSTR *oldStrings = infoPtr->strings;
2852 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2853 memcpy (&infoPtr->strings[0], &oldStrings[0],
2854 sizeof(LPWSTR) * infoPtr->nNumStrings);
2858 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2859 infoPtr->nNumStrings++;
2870 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2872 #define MAX_RESOURCE_STRING_LENGTH 512
2873 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2876 if ((wParam) && (HIWORD(lParam) == 0)) {
2877 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2879 TRACE("adding string from resource!\n");
2881 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2882 szString, MAX_RESOURCE_STRING_LENGTH);
2884 TRACE("len=%d %s\n", len, debugstr_w(szString));
2885 TRACE("First char: 0x%x\n", *szString);
2886 if (szString[0] == L'|')
2888 PWSTR p = szString + 1;
2890 nIndex = infoPtr->nNumStrings;
2891 while (*p != L'|' && *p != L'\0') {
2894 if (infoPtr->nNumStrings == 0) {
2895 infoPtr->strings = Alloc (sizeof(LPWSTR));
2899 LPWSTR *oldStrings = infoPtr->strings;
2900 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2901 memcpy(&infoPtr->strings[0], &oldStrings[0],
2902 sizeof(LPWSTR) * infoPtr->nNumStrings);
2906 np=strchrW (p, '|');
2914 TRACE("len=%d %s\n", len, debugstr_w(p));
2915 infoPtr->strings[infoPtr->nNumStrings] =
2916 Alloc (sizeof(WCHAR)*(len+1));
2917 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2918 infoPtr->nNumStrings++;
2925 nIndex = infoPtr->nNumStrings;
2926 if (infoPtr->nNumStrings == 0) {
2928 Alloc (sizeof(LPWSTR));
2931 LPWSTR *oldStrings = infoPtr->strings;
2933 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2934 memcpy (&infoPtr->strings[0], &oldStrings[0],
2935 sizeof(LPWSTR) * infoPtr->nNumStrings);
2939 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2940 infoPtr->nNumStrings++;
2944 LPWSTR p = (LPWSTR)lParam;
2949 TRACE("adding string(s) from array!\n");
2950 nIndex = infoPtr->nNumStrings;
2954 TRACE("len=%d %s\n", len, debugstr_w(p));
2955 if (infoPtr->nNumStrings == 0) {
2957 Alloc (sizeof(LPWSTR));
2960 LPWSTR *oldStrings = infoPtr->strings;
2962 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2963 memcpy (&infoPtr->strings[0], &oldStrings[0],
2964 sizeof(LPWSTR) * infoPtr->nNumStrings);
2968 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2969 infoPtr->nNumStrings++;
2980 TOOLBAR_AutoSize (HWND hwnd)
2982 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2988 UINT uPosFlags = SWP_NOZORDER;
2990 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2992 parent = GetParent (hwnd);
2993 GetClientRect(parent, &parent_rect);
2995 x = parent_rect.left;
2996 y = parent_rect.top;
2998 /* FIXME: we should be able to early out if nothing */
2999 /* has changed with nWidth != parent_rect width */
3001 if (infoPtr->dwStyle & CCS_NORESIZE) {
3002 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3005 TOOLBAR_CalcToolbar (hwnd);
3008 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3009 TOOLBAR_CalcToolbar (hwnd);
3010 InvalidateRect( hwnd, NULL, TRUE );
3011 cy = infoPtr->nHeight;
3012 cx = infoPtr->nWidth;
3014 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3015 GetWindowRect(hwnd, &window_rect);
3016 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3017 y = window_rect.top;
3019 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3020 GetWindowRect(hwnd, &window_rect);
3021 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3025 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3026 uPosFlags |= SWP_NOMOVE;
3028 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3029 cy += GetSystemMetrics(SM_CYEDGE);
3031 if (infoPtr->dwStyle & WS_BORDER)
3034 cy += GetSystemMetrics(SM_CYEDGE);
3035 cx += GetSystemMetrics(SM_CXEDGE);
3038 infoPtr->bAutoSize = TRUE;
3039 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3040 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3041 * after the setwindowpos calls */
3042 infoPtr->bAutoSize = FALSE;
3049 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3053 return infoPtr->nNumButtons;
3058 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3060 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3062 infoPtr->dwStructSize = (DWORD)wParam;
3069 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3072 TBUTTON_INFO *btnPtr;
3075 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3077 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3081 btnPtr = &infoPtr->buttons[nIndex];
3082 btnPtr->iBitmap = LOWORD(lParam);
3084 /* we HAVE to erase the background, the new bitmap could be */
3086 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3093 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3096 TBUTTON_INFO *btnPtr;
3099 BOOL bChecked = FALSE;
3101 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3103 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3108 btnPtr = &infoPtr->buttons[nIndex];
3110 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3112 if (LOWORD(lParam) == FALSE)
3113 btnPtr->fsState &= ~TBSTATE_CHECKED;
3115 if (btnPtr->fsStyle & BTNS_GROUP) {
3117 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3118 if (nOldIndex == nIndex)
3120 if (nOldIndex != -1)
3121 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3123 btnPtr->fsState |= TBSTATE_CHECKED;
3126 if( bChecked != LOWORD(lParam) )
3128 if (nOldIndex != -1)
3129 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3130 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3133 /* FIXME: Send a WM_NOTIFY?? */
3140 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3144 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3149 TOOLBAR_Customize (HWND hwnd)
3151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3152 CUSTDLG_INFO custInfo;
3158 custInfo.tbInfo = infoPtr;
3159 custInfo.tbHwnd = hwnd;
3161 /* send TBN_BEGINADJUST notification */
3162 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3164 if (!(hRes = FindResourceW (COMCTL32_hModule,
3165 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3166 (LPWSTR)RT_DIALOG)))
3169 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3172 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3173 (LPDLGTEMPLATEW)template,
3175 TOOLBAR_CustomizeDialogProc,
3178 /* send TBN_ENDADJUST notification */
3179 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3186 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3189 INT nIndex = (INT)wParam;
3191 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3193 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3196 memset(&nmtb, 0, sizeof(nmtb));
3197 nmtb.iItem = btnPtr->idCommand;
3198 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3199 nmtb.tbButton.idCommand = btnPtr->idCommand;
3200 nmtb.tbButton.fsState = btnPtr->fsState;
3201 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3202 nmtb.tbButton.dwData = btnPtr->dwData;
3203 nmtb.tbButton.iString = btnPtr->iString;
3204 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3206 if ((infoPtr->hwndToolTip) &&
3207 !(btnPtr->fsStyle & BTNS_SEP)) {
3210 ZeroMemory (&ti, sizeof(ti));
3211 ti.cbSize = sizeof(ti);
3213 ti.uId = infoPtr->buttons[nIndex].idCommand;
3215 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3218 if (infoPtr->nNumButtons == 1) {
3219 TRACE(" simple delete!\n");
3220 Free (infoPtr->buttons);
3221 infoPtr->buttons = NULL;
3222 infoPtr->nNumButtons = 0;
3225 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3226 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3228 infoPtr->nNumButtons--;
3229 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3231 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3232 nIndex * sizeof(TBUTTON_INFO));
3235 if (nIndex < infoPtr->nNumButtons) {
3236 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3237 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3243 TOOLBAR_CalcToolbar (hwnd);
3245 InvalidateRect (hwnd, NULL, TRUE);
3252 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3254 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3255 TBUTTON_INFO *btnPtr;
3259 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3261 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3266 btnPtr = &infoPtr->buttons[nIndex];
3268 bState = btnPtr->fsState & TBSTATE_ENABLED;
3270 /* update the toolbar button state */
3271 if(LOWORD(lParam) == FALSE) {
3272 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3274 btnPtr->fsState |= TBSTATE_ENABLED;
3277 /* redraw the button only if the state of the button changed */
3278 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3279 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3285 static inline LRESULT
3286 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3288 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3290 return infoPtr->bAnchor;
3295 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3300 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3304 return infoPtr->buttons[nIndex].iBitmap;
3308 static inline LRESULT
3309 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3311 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3316 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3318 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3319 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3320 INT nIndex = (INT)wParam;
3321 TBUTTON_INFO *btnPtr;
3326 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3329 btnPtr = &infoPtr->buttons[nIndex];
3330 lpTbb->iBitmap = btnPtr->iBitmap;
3331 lpTbb->idCommand = btnPtr->idCommand;
3332 lpTbb->fsState = btnPtr->fsState;
3333 lpTbb->fsStyle = btnPtr->fsStyle;
3334 lpTbb->bReserved[0] = 0;
3335 lpTbb->bReserved[1] = 0;
3336 lpTbb->dwData = btnPtr->dwData;
3337 lpTbb->iString = btnPtr->iString;
3344 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3346 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3347 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3348 TBUTTON_INFO *btnPtr;
3351 if (lpTbInfo == NULL)
3353 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3356 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3357 lpTbInfo->dwMask & 0x80000000);
3361 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3363 if (lpTbInfo->dwMask & TBIF_COMMAND)
3364 lpTbInfo->idCommand = btnPtr->idCommand;
3365 if (lpTbInfo->dwMask & TBIF_IMAGE)
3366 lpTbInfo->iImage = btnPtr->iBitmap;
3367 if (lpTbInfo->dwMask & TBIF_LPARAM)
3368 lpTbInfo->lParam = btnPtr->dwData;
3369 if (lpTbInfo->dwMask & TBIF_SIZE)
3370 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3371 if (lpTbInfo->dwMask & TBIF_STATE)
3372 lpTbInfo->fsState = btnPtr->fsState;
3373 if (lpTbInfo->dwMask & TBIF_STYLE)
3374 lpTbInfo->fsStyle = btnPtr->fsStyle;
3375 if (lpTbInfo->dwMask & TBIF_TEXT) {
3376 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3377 can't use TOOLBAR_GetText here */
3379 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3380 lpText = (LPWSTR)btnPtr->iString;
3381 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3383 lpTbInfo->pszText[0] = '\0';
3390 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3393 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3394 TBUTTON_INFO *btnPtr;
3397 if (lpTbInfo == NULL)
3399 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3402 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3403 lpTbInfo->dwMask & 0x80000000);
3407 btnPtr = &infoPtr->buttons[nIndex];
3412 if (lpTbInfo->dwMask & TBIF_COMMAND)
3413 lpTbInfo->idCommand = btnPtr->idCommand;
3414 if (lpTbInfo->dwMask & TBIF_IMAGE)
3415 lpTbInfo->iImage = btnPtr->iBitmap;
3416 if (lpTbInfo->dwMask & TBIF_LPARAM)
3417 lpTbInfo->lParam = btnPtr->dwData;
3418 if (lpTbInfo->dwMask & TBIF_SIZE)
3419 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3420 if (lpTbInfo->dwMask & TBIF_STATE)
3421 lpTbInfo->fsState = btnPtr->fsState;
3422 if (lpTbInfo->dwMask & TBIF_STYLE)
3423 lpTbInfo->fsStyle = btnPtr->fsStyle;
3424 if (lpTbInfo->dwMask & TBIF_TEXT) {
3425 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3426 can't use TOOLBAR_GetText here */
3428 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3429 lpText = (LPWSTR)btnPtr->iString;
3430 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3432 lpTbInfo->pszText[0] = '\0';
3440 TOOLBAR_GetButtonSize (HWND hwnd)
3442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3444 if (infoPtr->nNumButtons > 0)
3445 return MAKELONG((WORD)infoPtr->nButtonWidth,
3446 (WORD)infoPtr->nButtonHeight);
3448 return MAKELONG(8,7);
3453 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3455 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3462 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3466 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3468 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3469 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3474 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3481 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3485 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3489 ret = strlenW (lpText);
3492 strcpyW ((LPWSTR)lParam, lpText);
3500 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3502 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3503 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3504 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3508 inline static LRESULT
3509 TOOLBAR_GetExtendedStyle (HWND hwnd)
3511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3515 return infoPtr->dwExStyle;
3520 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3522 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3523 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3524 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3529 TOOLBAR_GetHotItem (HWND hwnd)
3531 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3533 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3536 if (infoPtr->nHotItem < 0)
3539 return (LRESULT)infoPtr->nHotItem;
3544 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3546 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3547 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3548 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3553 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3555 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3556 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3558 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3560 *lptbim = infoPtr->tbim;
3567 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3571 TRACE("hwnd = %p\n", hwnd);
3573 return (LRESULT)infoPtr->clrInsertMark;
3578 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3580 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3581 TBUTTON_INFO *btnPtr;
3585 nIndex = (INT)wParam;
3586 btnPtr = &infoPtr->buttons[nIndex];
3587 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3589 lpRect = (LPRECT)lParam;
3592 if (btnPtr->fsState & TBSTATE_HIDDEN)
3595 lpRect->left = btnPtr->rect.left;
3596 lpRect->right = btnPtr->rect.right;
3597 lpRect->bottom = btnPtr->rect.bottom;
3598 lpRect->top = btnPtr->rect.top;
3605 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3608 LPSIZE lpSize = (LPSIZE)lParam;
3613 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3614 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3616 TRACE("maximum size %ld x %ld\n",
3617 infoPtr->rcBound.right - infoPtr->rcBound.left,
3618 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3624 /* << TOOLBAR_GetObject >> */
3628 TOOLBAR_GetPadding (HWND hwnd)
3630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3633 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3634 return (LRESULT) oldPad;
3639 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3642 TBUTTON_INFO *btnPtr;
3646 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3647 btnPtr = &infoPtr->buttons[nIndex];
3648 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3650 lpRect = (LPRECT)lParam;
3654 lpRect->left = btnPtr->rect.left;
3655 lpRect->right = btnPtr->rect.right;
3656 lpRect->bottom = btnPtr->rect.bottom;
3657 lpRect->top = btnPtr->rect.top;
3664 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3668 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3669 return infoPtr->nRows;
3676 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3681 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3685 return infoPtr->buttons[nIndex].fsState;
3690 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3692 return GetWindowLongW(hwnd, GWL_STYLE);
3697 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3699 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3701 return infoPtr->nMaxTextRows;
3706 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3710 return (LRESULT)infoPtr->hwndToolTip;
3715 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3717 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3719 TRACE("%s hwnd=%p\n",
3720 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3722 return infoPtr->bUnicode;
3726 inline static LRESULT
3727 TOOLBAR_GetVersion (HWND hwnd)
3729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3730 return infoPtr->iVersion;
3735 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3738 TBUTTON_INFO *btnPtr;
3743 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3747 btnPtr = &infoPtr->buttons[nIndex];
3748 if (LOWORD(lParam) == FALSE)
3749 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3751 btnPtr->fsState |= TBSTATE_HIDDEN;
3753 TOOLBAR_CalcToolbar (hwnd);
3755 InvalidateRect (hwnd, NULL, TRUE);
3761 inline static LRESULT
3762 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3764 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3769 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3772 TBUTTON_INFO *btnPtr;
3776 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3780 btnPtr = &infoPtr->buttons[nIndex];
3781 oldState = btnPtr->fsState;
3782 if (LOWORD(lParam) == FALSE)
3783 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3785 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3787 if(oldState != btnPtr->fsState)
3788 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3795 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3798 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3799 INT nIndex = (INT)wParam;
3800 TBUTTON_INFO *oldButtons;
3805 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3808 /* EPP: this seems to be an undocumented call (from my IE4)
3809 * I assume in that case that:
3810 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3811 * - index of insertion is at the end of existing buttons
3812 * I only see this happen with nIndex == -1, but it could have a special
3813 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3815 nIndex = infoPtr->nNumButtons;
3817 } else if (nIndex < 0)
3820 /* If the string passed is not an index, assume address of string
3821 and do our own AddString */
3822 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3826 TRACE("string %s passed instead of index, adding string\n",
3827 debugstr_a((LPSTR)lpTbb->iString));
3828 len = strlen((LPSTR)lpTbb->iString) + 2;
3830 strcpy(ptr, (LPSTR)lpTbb->iString);
3831 ptr[len - 1] = 0; /* ended by two '\0' */
3832 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3836 TRACE("inserting button index=%d\n", nIndex);
3837 if (nIndex > infoPtr->nNumButtons) {
3838 nIndex = infoPtr->nNumButtons;
3839 TRACE("adjust index=%d\n", nIndex);
3842 oldButtons = infoPtr->buttons;
3843 infoPtr->nNumButtons++;
3844 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3845 /* pre insert copy */
3847 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3848 nIndex * sizeof(TBUTTON_INFO));
3851 /* insert new button */
3852 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3853 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3854 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3855 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3856 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3857 /* if passed string and not index, then add string */
3858 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3859 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3862 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3864 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3867 ZeroMemory (&ti, sizeof(ti));
3868 ti.cbSize = sizeof (ti);
3870 ti.uId = lpTbb->idCommand;
3872 ti.lpszText = LPSTR_TEXTCALLBACKW;
3874 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3878 /* post insert copy */
3879 if (nIndex < infoPtr->nNumButtons - 1) {
3880 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3881 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3886 TOOLBAR_CalcToolbar (hwnd);
3888 InvalidateRect (hwnd, NULL, TRUE);
3895 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3898 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3899 INT nIndex = (INT)wParam;
3900 TBUTTON_INFO *oldButtons;
3905 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3908 /* EPP: this seems to be an undocumented call (from my IE4)
3909 * I assume in that case that:
3910 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3911 * - index of insertion is at the end of existing buttons
3912 * I only see this happen with nIndex == -1, but it could have a special
3913 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3915 nIndex = infoPtr->nNumButtons;
3917 } else if (nIndex < 0)
3920 /* If the string passed is not an index, assume address of string
3921 and do our own AddString */
3922 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3926 TRACE("string %s passed instead of index, adding string\n",
3927 debugstr_w((LPWSTR)lpTbb->iString));
3928 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3929 ptr = Alloc(len*sizeof(WCHAR));
3930 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3931 ptr[len - 1] = 0; /* ended by two '\0' */
3932 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3936 TRACE("inserting button index=%d\n", nIndex);
3937 if (nIndex > infoPtr->nNumButtons) {
3938 nIndex = infoPtr->nNumButtons;
3939 TRACE("adjust index=%d\n", nIndex);
3942 oldButtons = infoPtr->buttons;
3943 infoPtr->nNumButtons++;
3944 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3945 /* pre insert copy */
3947 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3948 nIndex * sizeof(TBUTTON_INFO));
3951 /* insert new button */
3952 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3953 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3954 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3955 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3956 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3957 /* if passed string and not index, then add string */
3958 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3959 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3962 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3964 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3967 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3968 ti.cbSize = sizeof (TTTOOLINFOW);
3970 ti.uId = lpTbb->idCommand;
3972 ti.lpszText = LPSTR_TEXTCALLBACKW;
3974 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3978 /* post insert copy */
3979 if (nIndex < infoPtr->nNumButtons - 1) {
3980 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3981 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3986 TOOLBAR_CalcToolbar (hwnd);
3988 InvalidateRect (hwnd, NULL, TRUE);
3994 /* << TOOLBAR_InsertMarkHitTest >> */
3998 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4003 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4007 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4012 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4014 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4017 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4021 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4026 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4031 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4035 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4040 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4042 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4045 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4049 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4054 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4059 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4063 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4068 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4077 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4082 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4085 tbab.hInst = (HINSTANCE)lParam;
4086 tbab.nID = (UINT_PTR)wParam;
4088 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4090 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4095 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4098 WCHAR wAccel = (WCHAR)wParam;
4099 UINT* pIDButton = (UINT*)lParam;
4100 WCHAR wszAccel[] = {'&',wAccel,0};
4103 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4104 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4106 for (i = 0; i < infoPtr->nNumButtons; i++)
4108 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4109 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4110 !(btnPtr->fsState & TBSTATE_HIDDEN))
4112 int iLen = strlenW(wszAccel);
4113 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4120 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4125 if (!strncmpiW(lpszStr, wszAccel, iLen))
4127 *pIDButton = btnPtr->idCommand;
4139 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4141 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4144 TBUTTON_INFO *btnPtr;
4146 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4148 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4152 btnPtr = &infoPtr->buttons[nIndex];
4153 oldState = btnPtr->fsState;
4156 btnPtr->fsState |= TBSTATE_MARKED;
4158 btnPtr->fsState &= ~TBSTATE_MARKED;
4160 if(oldState != btnPtr->fsState)
4161 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4167 /* fixes up an index of a button affected by a move */
4168 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4172 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4174 else if (*pIndex == nIndex)
4175 *pIndex = nMoveIndex;
4179 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4181 else if (*pIndex == nIndex)
4182 *pIndex = nMoveIndex;
4188 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4193 INT nMoveIndex = (INT)lParam;
4194 TBUTTON_INFO button;
4196 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4198 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4199 if ((nIndex == -1) || (nMoveIndex < 0))
4202 if (nMoveIndex > infoPtr->nNumButtons - 1)
4203 nMoveIndex = infoPtr->nNumButtons - 1;
4205 button = infoPtr->buttons[nIndex];
4207 /* move button right */
4208 if (nIndex < nMoveIndex)
4210 nCount = nMoveIndex - nIndex;
4211 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4212 infoPtr->buttons[nMoveIndex] = button;
4214 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4215 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4216 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4217 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4219 else if (nIndex > nMoveIndex) /* move button left */
4221 nCount = nIndex - nMoveIndex;
4222 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4223 infoPtr->buttons[nMoveIndex] = button;
4225 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4226 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4227 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4228 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4231 TOOLBAR_CalcToolbar(hwnd);
4232 InvalidateRect(hwnd, NULL, TRUE);
4239 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4241 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4242 TBUTTON_INFO *btnPtr;
4246 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4250 btnPtr = &infoPtr->buttons[nIndex];
4251 oldState = btnPtr->fsState;
4252 if (LOWORD(lParam) == FALSE)
4253 btnPtr->fsState &= ~TBSTATE_PRESSED;
4255 btnPtr->fsState |= TBSTATE_PRESSED;
4257 if(oldState != btnPtr->fsState)
4258 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4263 /* FIXME: there might still be some confusion her between number of buttons
4264 * and number of bitmaps */
4266 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4268 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4269 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4271 int i = 0, nOldButtons = 0, pos = 0;
4272 int nOldBitmaps, nNewBitmaps = 0;
4273 HIMAGELIST himlDef = 0;
4275 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4276 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4277 lpReplace->nButtons);
4279 if (lpReplace->hInstOld == HINST_COMMCTRL)
4281 FIXME("changing standard bitmaps not implemented\n");
4284 else if (lpReplace->hInstOld != 0)
4286 FIXME("resources not in the current module not implemented\n");
4291 hBitmap = (HBITMAP) lpReplace->nIDNew;
4294 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4295 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4296 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4297 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4298 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4300 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4301 nOldButtons = tbi->nButtons;
4302 tbi->nButtons = lpReplace->nButtons;
4303 tbi->hInst = lpReplace->hInstNew;
4304 tbi->nID = lpReplace->nIDNew;
4305 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4308 pos += tbi->nButtons;
4311 if (nOldButtons == 0)
4313 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4317 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4318 nOldBitmaps = ImageList_GetImageCount(himlDef);
4320 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4322 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4323 ImageList_Remove(himlDef, i);
4328 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4329 HDC hdcImage, hdcBitmap;
4331 /* copy the bitmap before adding it so that the user's bitmap
4332 * doesn't get modified.
4334 GetObjectW (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4336 hdcImage = CreateCompatibleDC(0);
4337 hdcBitmap = CreateCompatibleDC(0);
4339 /* create new bitmap */
4340 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4341 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4342 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4344 /* Copy the user's image */
4345 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4346 hdcBitmap, 0, 0, SRCCOPY);
4348 SelectObject (hdcImage, hOldBitmapLoad);
4349 SelectObject (hdcBitmap, hOldBitmapBitmap);
4350 DeleteDC (hdcImage);
4351 DeleteDC (hdcBitmap);
4353 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4354 nNewBitmaps = ImageList_GetImageCount(himlDef);
4355 DeleteObject (hbmLoad);
4358 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4360 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4361 pos, nOldBitmaps, nNewBitmaps);
4363 InvalidateRect(hwnd, NULL, TRUE);
4369 /* helper for TOOLBAR_SaveRestoreW */
4371 TOOLBAR_Save(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4373 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4374 debugstr_w(lpSave->pszValueName));
4380 /* helper for TOOLBAR_Restore */
4382 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4387 ZeroMemory(&ti, sizeof(ti));
4388 ti.cbSize = sizeof(ti);
4389 ti.hwnd = infoPtr->hwndSelf;
4391 for (i = 0; i < infoPtr->nNumButtons; i++)
4393 if ((infoPtr->hwndToolTip) &&
4394 !(infoPtr->buttons[i].fsStyle & BTNS_SEP))
4396 ti.uId = infoPtr->buttons[i].idCommand;
4397 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
4401 Free(infoPtr->buttons);
4402 infoPtr->buttons = NULL;
4403 infoPtr->nNumButtons = 0;
4407 /* helper for TOOLBAR_SaveRestoreW */
4409 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, LPTBSAVEPARAMSW lpSave)
4418 /* restore toolbar information */
4419 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4420 debugstr_w(lpSave->pszValueName));
4422 memset(&nmtbr, 0, sizeof(nmtbr));
4424 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4425 KEY_QUERY_VALUE, &hkey);
4427 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4429 if (!res && dwType != REG_BINARY)
4430 res = ERROR_FILE_NOT_FOUND;
4433 nmtbr.pData = HeapAlloc(GetProcessHeap(), 0, dwSize);
4434 nmtbr.cbData = (UINT)dwSize;
4435 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4438 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4439 (LPBYTE)nmtbr.pData, &dwSize);
4442 nmtbr.pCurrent = nmtbr.pData;
4444 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4445 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4447 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4451 /* remove all existing buttons as this function is designed to
4452 * restore the toolbar to a previously saved state */
4453 TOOLBAR_DeleteAllButtons(infoPtr);
4455 for (i = 0; i < nmtbr.cButtons; i++)
4458 nmtbr.tbButton.iBitmap = -1;
4459 nmtbr.tbButton.fsState = 0;
4460 nmtbr.tbButton.fsStyle = 0;
4461 nmtbr.tbButton.idCommand = 0;
4462 if (*nmtbr.pCurrent == (DWORD)-1)
4465 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4466 nmtbr.tbButton.iBitmap = SEPARATOR_WIDTH;
4468 else if (*nmtbr.pCurrent == (DWORD)-2)
4470 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4472 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4476 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4478 /* can't contain real string as we don't know whether
4479 * the client put an ANSI or Unicode string in there */
4480 if (HIWORD(nmtbr.tbButton.iString))
4481 nmtbr.tbButton.iString = 0;
4483 TOOLBAR_InsertButtonW(infoPtr->hwndSelf, -1,
4484 (LPARAM)&nmtbr.tbButton);
4487 /* do legacy notifications */
4488 if (infoPtr->iVersion < 5)
4490 /* FIXME: send TBN_BEGINADJUST */
4491 FIXME("send TBN_GETBUTTONINFO for each button\n");
4492 /* FIXME: send TBN_ENDADJUST */
4495 /* remove all uninitialised buttons
4496 * note: loop backwards to avoid having to fixup i on a
4498 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4499 if (infoPtr->buttons[i].iBitmap == -1)
4500 TOOLBAR_DeleteButton(infoPtr->hwndSelf, i, 0);
4502 /* only indicate success if at least one button survived */
4503 if (infoPtr->nNumButtons > 0) ret = TRUE;
4506 HeapFree(GetProcessHeap(), 0, nmtbr.pData);
4514 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSW lpSave)
4516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4518 if (lpSave == NULL) return 0;
4521 return TOOLBAR_Save(infoPtr, lpSave);
4523 return TOOLBAR_Restore(infoPtr, lpSave);
4528 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPTBSAVEPARAMSA lpSave)
4530 TBSAVEPARAMSW SaveW;
4533 if (lpSave == NULL) return 0;
4535 SaveW.hkr = lpSave->hkr;
4537 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4538 SaveW.pszSubKey = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
4539 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, (LPWSTR)SaveW.pszSubKey, len);
4541 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4542 SaveW.pszValueName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
4543 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, (LPWSTR)SaveW.pszValueName, len);
4545 /* FIXME: shoudn't we free the HeapAlloc()ed memory? */
4546 return TOOLBAR_SaveRestoreW(hwnd, wParam, &SaveW);
4551 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4554 BOOL bOldAnchor = infoPtr->bAnchor;
4556 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4558 infoPtr->bAnchor = (BOOL)wParam;
4560 /* Native does not remove the hot effect from an already hot button */
4562 return (LRESULT)bOldAnchor;
4567 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4570 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4572 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4575 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4577 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4580 if (infoPtr->nNumButtons > 0)
4581 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4582 infoPtr->nNumButtons,
4583 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4584 LOWORD(lParam), HIWORD(lParam));
4586 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4587 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4590 if ((himlDef == infoPtr->himlInt) &&
4591 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4593 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4594 infoPtr->nBitmapHeight);
4602 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4604 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4605 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4606 TBUTTON_INFO *btnPtr;
4612 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4615 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4616 lptbbi->dwMask & 0x80000000);
4620 btnPtr = &infoPtr->buttons[nIndex];
4621 if (lptbbi->dwMask & TBIF_COMMAND)
4622 btnPtr->idCommand = lptbbi->idCommand;
4623 if (lptbbi->dwMask & TBIF_IMAGE)
4624 btnPtr->iBitmap = lptbbi->iImage;
4625 if (lptbbi->dwMask & TBIF_LPARAM)
4626 btnPtr->dwData = lptbbi->lParam;
4627 if (lptbbi->dwMask & TBIF_SIZE)
4628 btnPtr->cx = lptbbi->cx;
4629 if (lptbbi->dwMask & TBIF_STATE)
4630 btnPtr->fsState = lptbbi->fsState;
4631 if (lptbbi->dwMask & TBIF_STYLE)
4632 btnPtr->fsStyle = lptbbi->fsStyle;
4634 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4635 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4636 /* iString is index, zero it to make Str_SetPtr succeed */
4639 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4642 /* save the button rect to see if we need to redraw the whole toolbar */
4643 oldBtnRect = btnPtr->rect;
4644 TOOLBAR_CalcToolbar(hwnd);
4646 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4647 InvalidateRect(hwnd, NULL, TRUE);
4649 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4656 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4659 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4660 TBUTTON_INFO *btnPtr;
4666 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4669 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4670 lptbbi->dwMask & 0x80000000);
4674 btnPtr = &infoPtr->buttons[nIndex];
4675 if (lptbbi->dwMask & TBIF_COMMAND)
4676 btnPtr->idCommand = lptbbi->idCommand;
4677 if (lptbbi->dwMask & TBIF_IMAGE)
4678 btnPtr->iBitmap = lptbbi->iImage;
4679 if (lptbbi->dwMask & TBIF_LPARAM)
4680 btnPtr->dwData = lptbbi->lParam;
4681 if (lptbbi->dwMask & TBIF_SIZE)
4682 btnPtr->cx = lptbbi->cx;
4683 if (lptbbi->dwMask & TBIF_STATE)
4684 btnPtr->fsState = lptbbi->fsState;
4685 if (lptbbi->dwMask & TBIF_STYLE)
4686 btnPtr->fsStyle = lptbbi->fsStyle;
4688 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4689 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4690 /* iString is index, zero it to make Str_SetPtr succeed */
4692 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4695 /* save the button rect to see if we need to redraw the whole toolbar */
4696 oldBtnRect = btnPtr->rect;
4697 TOOLBAR_CalcToolbar(hwnd);
4699 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4700 InvalidateRect(hwnd, NULL, TRUE);
4702 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4709 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4711 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4712 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4714 if ((cx < 0) || (cy < 0))
4716 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4720 TRACE("%p, cx = %d, cy = %d\n", hwnd, cx, cy);
4722 /* The documentation claims you can only change the button size before
4723 * any button has been added. But this is wrong.
4724 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4725 * it to the toolbar, and it checks that the return value is nonzero - mjm
4726 * Further testing shows that we must actually perform the change too.
4729 * The documentation also does not mention that if 0 is supplied for
4730 * either size, the system changes it to the default of 24 wide and
4731 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4733 infoPtr->nButtonWidth = (cx) ? cx : 24;
4734 infoPtr->nButtonHeight = (cy) ? cy : 22;
4740 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4744 /* if setting to current values, ignore */
4745 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4746 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4747 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4748 infoPtr->cxMin, infoPtr->cxMax);
4752 /* save new values */
4753 infoPtr->cxMin = (INT)LOWORD(lParam);
4754 infoPtr->cxMax = (INT)HIWORD(lParam);
4756 /* if both values are 0 then we are done */
4758 TRACE("setting both min and max to 0, norecalc\n");
4762 /* otherwise we need to recalc the toolbar and in some cases
4763 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4764 which doesn't actually draw - GA). */
4765 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4766 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4768 TOOLBAR_CalcToolbar (hwnd);
4770 InvalidateRect (hwnd, NULL, TRUE);
4777 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4780 INT nIndex = (INT)wParam;
4782 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4785 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4787 if (infoPtr->hwndToolTip) {
4789 FIXME("change tool tip!\n");
4798 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4801 HIMAGELIST himl = (HIMAGELIST)lParam;
4802 HIMAGELIST himlTemp;
4805 if (infoPtr->iVersion >= 5)
4808 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4809 &infoPtr->cimlDis, himl, id);
4811 /* FIXME: redraw ? */
4813 return (LRESULT)himlTemp;
4818 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4820 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4823 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4825 dwTemp = infoPtr->dwDTFlags;
4826 infoPtr->dwDTFlags =
4827 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4829 return (LRESULT)dwTemp;
4832 /* This function differs a bit from what MSDN says it does:
4833 * 1. lParam contains extended style flags to OR with current style
4834 * (MSDN isn't clear on the OR bit)
4835 * 2. wParam appears to contain extended style flags to be reset
4836 * (MSDN says that this parameter is reserved)
4839 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4841 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4844 dwTemp = infoPtr->dwExStyle;
4845 infoPtr->dwExStyle &= ~wParam;
4846 infoPtr->dwExStyle |= (DWORD)lParam;
4848 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4850 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4851 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4852 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4854 TOOLBAR_CalcToolbar (hwnd);
4856 TOOLBAR_AutoSize(hwnd);
4858 InvalidateRect(hwnd, NULL, TRUE);
4860 return (LRESULT)dwTemp;
4865 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4868 HIMAGELIST himlTemp;
4869 HIMAGELIST himl = (HIMAGELIST)lParam;
4872 if (infoPtr->iVersion >= 5)
4875 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4877 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4878 &infoPtr->cimlHot, himl, id);
4880 /* FIXME: redraw ? */
4882 return (LRESULT)himlTemp;
4886 /* Makes previous hot button no longer hot, makes the specified
4887 * button hot and sends appropriate notifications. dwReason is one or
4888 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4889 * NOTE 1: this function does not validate nHit
4890 * NOTE 2: the name of this function is completely made up and
4891 * not based on any documentation from Microsoft. */
4893 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4895 if (infoPtr->nHotItem != nHit)
4897 NMTBHOTITEM nmhotitem;
4898 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4899 LRESULT no_highlight;
4901 /* Remove the effect of an old hot button if the button was
4902 drawn with the hot button effect */
4903 if(infoPtr->nHotItem >= 0)
4905 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4906 oldBtnPtr->bHot = FALSE;
4909 infoPtr->nHotItem = nHit;
4911 /* It's not a separator or in nowhere. It's a hot button. */
4913 btnPtr = &infoPtr->buttons[nHit];
4915 nmhotitem.dwFlags = dwReason;
4917 nmhotitem.idOld = oldBtnPtr->idCommand;
4919 nmhotitem.dwFlags |= HICF_ENTERING;
4921 nmhotitem.idNew = btnPtr->idCommand;
4923 nmhotitem.dwFlags |= HICF_LEAVING;
4925 no_highlight = TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE);
4927 /* now invalidate the old and new buttons so they will be painted */
4929 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4930 if (btnPtr && !no_highlight)
4932 btnPtr->bHot = TRUE;
4933 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4939 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4942 INT nOldHotItem = infoPtr->nHotItem;
4944 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4946 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4949 /* NOTE: an application can still remove the hot item even if anchor
4950 * highlighting is enabled */
4952 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4953 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4955 if (nOldHotItem < 0)
4958 return (LRESULT)nOldHotItem;
4963 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4966 HIMAGELIST himlTemp;
4967 HIMAGELIST himl = (HIMAGELIST)lParam;
4970 if (infoPtr->iVersion >= 5)
4973 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4974 &infoPtr->cimlDef, himl, id);
4976 infoPtr->nNumBitmaps = 0;
4977 for (i = 0; i < infoPtr->cimlDef; i++)
4978 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4980 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4981 &infoPtr->nBitmapHeight))
4983 infoPtr->nBitmapWidth = 0;
4984 infoPtr->nBitmapHeight = 0;
4987 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4988 hwnd, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4989 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4991 InvalidateRect(hwnd, NULL, TRUE);
4993 return (LRESULT)himlTemp;
4998 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5002 infoPtr->nIndent = (INT)wParam;
5006 /* process only on indent changing */
5007 if(infoPtr->nIndent != (INT)wParam)
5009 infoPtr->nIndent = (INT)wParam;
5010 TOOLBAR_CalcToolbar (hwnd);
5011 InvalidateRect(hwnd, NULL, FALSE);
5019 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
5021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5022 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
5024 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
5026 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
5028 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
5032 if ((lptbim->iButton == -1) ||
5033 ((lptbim->iButton < infoPtr->nNumButtons) &&
5034 (lptbim->iButton >= 0)))
5036 infoPtr->tbim = *lptbim;
5037 /* FIXME: don't need to update entire toolbar */
5038 InvalidateRect(hwnd, NULL, TRUE);
5041 ERR("Invalid button index %d\n", lptbim->iButton);
5048 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
5050 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5052 infoPtr->clrInsertMark = (COLORREF)lParam;
5054 /* FIXME: don't need to update entire toolbar */
5055 InvalidateRect(hwnd, NULL, TRUE);
5062 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5066 infoPtr->nMaxTextRows = (INT)wParam;
5068 TOOLBAR_CalcToolbar(hwnd);
5073 /* MSDN gives slightly wrong info on padding.
5074 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
5075 * 2. It is not used to create a blank area between the edge of the button
5076 * and the text or image if TBSTYLE_LIST is set. It is used to control
5077 * the gap between the image and text.
5078 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
5079 * to control the bottom and right borders [with the border being
5080 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
5081 * is shared evenly on both sides of the button.
5084 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
5086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5089 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5090 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
5091 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
5092 TRACE("cx=%ld, cy=%ld\n",
5093 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
5094 return (LRESULT) oldPad;
5099 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5106 hwndOldNotify = infoPtr->hwndNotify;
5107 infoPtr->hwndNotify = (HWND)wParam;
5109 return (LRESULT)hwndOldNotify;
5114 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5116 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5117 LPRECT lprc = (LPRECT)lParam;
5121 if (LOWORD(wParam) > 1) {
5122 FIXME("multiple rows not supported!\n");
5125 if(infoPtr->nRows != LOWORD(wParam))
5127 infoPtr->nRows = LOWORD(wParam);
5129 /* recalculate toolbar */
5130 TOOLBAR_CalcToolbar (hwnd);
5132 /* repaint toolbar */
5133 InvalidateRect(hwnd, NULL, TRUE);
5136 /* return bounding rectangle */
5138 lprc->left = infoPtr->rcBound.left;
5139 lprc->right = infoPtr->rcBound.right;
5140 lprc->top = infoPtr->rcBound.top;
5141 lprc->bottom = infoPtr->rcBound.bottom;
5149 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5152 TBUTTON_INFO *btnPtr;
5155 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5159 btnPtr = &infoPtr->buttons[nIndex];
5161 /* if hidden state has changed the invalidate entire window and recalc */
5162 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5163 btnPtr->fsState = LOWORD(lParam);
5164 TOOLBAR_CalcToolbar (hwnd);
5165 InvalidateRect(hwnd, 0, TRUE);
5169 /* process state changing if current state doesn't match new state */
5170 if(btnPtr->fsState != LOWORD(lParam))
5172 btnPtr->fsState = LOWORD(lParam);
5173 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5181 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5183 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5189 inline static LRESULT
5190 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5192 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5194 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5196 infoPtr->hwndToolTip = (HWND)wParam;
5202 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5204 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5207 TRACE("%s hwnd=%p\n",
5208 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5210 bTemp = infoPtr->bUnicode;
5211 infoPtr->bUnicode = (BOOL)wParam;
5218 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5222 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5223 comctl32_color.clrBtnHighlight :
5224 infoPtr->clrBtnHighlight;
5225 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5226 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5232 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5234 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5236 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5237 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5238 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5240 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5241 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5242 InvalidateRect(hwnd, NULL, TRUE);
5248 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5251 INT iOldVersion = infoPtr->iVersion;
5253 infoPtr->iVersion = iVersion;
5255 if (infoPtr->iVersion >= 5)
5256 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5263 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5266 WORD iString = HIWORD(wParam);
5267 WORD buffersize = LOWORD(wParam);
5268 LPSTR str = (LPSTR)lParam;
5271 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5273 if (iString < infoPtr->nNumStrings)
5275 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5277 TRACE("returning %s\n", debugstr_a(str));
5280 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5287 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5290 WORD iString = HIWORD(wParam);
5291 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5292 LPWSTR str = (LPWSTR)lParam;
5295 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5297 if (iString < infoPtr->nNumStrings)
5299 len = min(len, strlenW(infoPtr->strings[iString]));
5300 ret = (len+1)*sizeof(WCHAR);
5301 memcpy(str, infoPtr->strings[iString], ret);
5304 TRACE("returning %s\n", debugstr_w(str));
5307 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5312 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5313 * is the maximum size of the toolbar? */
5314 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5316 SIZE * pSize = (SIZE*)lParam;
5317 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5322 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5323 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5324 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5327 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5330 INT nOldHotItem = infoPtr->nHotItem;
5332 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5333 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5335 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5338 /* NOTE: an application can still remove the hot item even if anchor
5339 * highlighting is enabled */
5341 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5345 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5348 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5349 * which controls the amount of spacing between the image and the text
5350 * of buttons for TBSTYLE_LIST toolbars. */
5351 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5355 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5358 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5360 infoPtr->iListGap = (INT)wParam;
5362 InvalidateRect(hwnd, NULL, TRUE);
5367 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5368 * of image lists associated with the various states. */
5369 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5373 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5375 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5379 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5382 LPSIZE lpsize = (LPSIZE)lParam;
5388 * Testing shows the following:
5389 * wParam = 0 adjust cx value
5390 * = 1 set cy value to max size.
5391 * lParam pointer to SIZE structure
5394 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5395 wParam, lParam, lpsize->cx, lpsize->cy);
5399 if (lpsize->cx == -1) {
5400 /* **** this is wrong, native measures each button and sets it */
5401 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5403 else if(HIWORD(lpsize->cx)) {
5405 HWND hwndParent = GetParent(hwnd);
5407 GetWindowRect(hwnd, &rc);
5408 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5409 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5410 rc.left, rc.top, rc.right, rc.bottom);
5411 lpsize->cx = max(rc.right-rc.left,
5412 infoPtr->rcBound.right - infoPtr->rcBound.left);
5415 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5419 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5420 /* lpsize->cy = infoPtr->nHeight; */
5423 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5427 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5428 lpsize->cx, lpsize->cy);
5432 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5434 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5436 InvalidateRect(hwnd, NULL, TRUE);
5442 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5445 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5448 TRACE("hwnd = %p\n", hwnd);
5450 /* initialize info structure */
5451 infoPtr->nButtonHeight = 22;
5452 infoPtr->nButtonWidth = 24;
5453 infoPtr->nBitmapHeight = 15;
5454 infoPtr->nBitmapWidth = 16;
5456 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5457 infoPtr->nMaxTextRows = 1;
5458 infoPtr->cxMin = -1;
5459 infoPtr->cxMax = -1;
5460 infoPtr->nNumBitmaps = 0;
5461 infoPtr->nNumStrings = 0;
5463 infoPtr->bCaptured = FALSE;
5464 infoPtr->nButtonDown = -1;
5465 infoPtr->nButtonDrag = -1;
5466 infoPtr->nOldHit = -1;
5467 infoPtr->nHotItem = -1;
5468 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5469 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5470 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5471 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5472 infoPtr->bDragOutSent = FALSE;
5473 infoPtr->iVersion = 0;
5474 infoPtr->hwndSelf = hwnd;
5475 infoPtr->bDoRedraw = TRUE;
5476 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5477 infoPtr->clrBtnShadow = CLR_DEFAULT;
5478 infoPtr->szPadding.cx = DEFPAD_CX;
5479 infoPtr->szPadding.cy = DEFPAD_CY;
5480 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5481 infoPtr->dwStyle = dwStyle;
5482 infoPtr->tbim.iButton = -1;
5483 GetClientRect(hwnd, &infoPtr->client_rect);
5484 infoPtr->bUnicode = infoPtr->hwndNotify &&
5485 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5487 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5488 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5490 if (dwStyle & TBSTYLE_TOOLTIPS) {
5491 /* Create tooltip control */
5492 infoPtr->hwndToolTip =
5493 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
5494 CW_USEDEFAULT, CW_USEDEFAULT,
5495 CW_USEDEFAULT, CW_USEDEFAULT,
5498 /* Send NM_TOOLTIPSCREATED notification */
5499 if (infoPtr->hwndToolTip)
5501 NMTOOLTIPSCREATED nmttc;
5503 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5505 TOOLBAR_SendNotify (&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
5509 TOOLBAR_CheckStyle (hwnd, dwStyle);
5511 TOOLBAR_CalcToolbar(hwnd);
5518 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5522 /* delete tooltip control */
5523 if (infoPtr->hwndToolTip)
5524 DestroyWindow (infoPtr->hwndToolTip);
5526 /* delete temporary buffer for tooltip text */
5527 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5529 /* delete button data */
5530 if (infoPtr->buttons)
5531 Free (infoPtr->buttons);
5533 /* delete strings */
5534 if (infoPtr->strings) {
5536 for (i = 0; i < infoPtr->nNumStrings; i++)
5537 if (infoPtr->strings[i])
5538 Free (infoPtr->strings[i]);
5540 Free (infoPtr->strings);
5543 /* destroy internal image list */
5544 if (infoPtr->himlInt)
5545 ImageList_Destroy (infoPtr->himlInt);
5547 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5548 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5549 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5551 /* delete default font */
5553 DeleteObject (infoPtr->hDefaultFont);
5555 /* free toolbar info data */
5557 SetWindowLongPtrW (hwnd, 0, 0);
5564 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5566 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5567 NMTBCUSTOMDRAW tbcd;
5571 /* the app has told us not to redraw the toolbar */
5572 if (!infoPtr->bDoRedraw)
5575 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5576 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5577 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5578 tbcd.nmcd.hdc = (HDC)wParam;
5579 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5580 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5582 /* FIXME: in general the return flags *can* be or'ed together */
5583 switch (infoPtr->dwBaseCustDraw)
5585 case CDRF_DODEFAULT:
5587 case CDRF_SKIPDEFAULT:
5590 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5595 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5596 * to my parent for processing.
5598 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5600 HDC hdc = (HDC)wParam;
5605 parent = GetParent(hwnd);
5606 MapWindowPoints(hwnd, parent, &pt, 1);
5607 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5608 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5609 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5612 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5614 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5615 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5616 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5617 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5618 tbcd.nmcd.hdc = (HDC)wParam;
5619 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5620 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5621 switch (infoPtr->dwBaseCustDraw)
5623 case CDRF_DODEFAULT:
5625 case CDRF_SKIPDEFAULT:
5628 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5637 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5641 return (LRESULT)infoPtr->hFont;
5646 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5651 pt.x = (INT)LOWORD(lParam);
5652 pt.y = (INT)HIWORD(lParam);
5653 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5656 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5657 else if (GetWindowLongW (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5658 TOOLBAR_Customize (hwnd);
5665 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5668 TBUTTON_INFO *btnPtr;
5673 BOOL bDragKeyPressed;
5677 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5678 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5680 bDragKeyPressed = (wParam & MK_SHIFT);
5682 if (infoPtr->hwndToolTip)
5683 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5684 WM_LBUTTONDOWN, wParam, lParam);
5686 pt.x = (INT)LOWORD(lParam);
5687 pt.y = (INT)HIWORD(lParam);
5688 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5690 btnPtr = &infoPtr->buttons[nHit];
5692 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5694 infoPtr->nButtonDrag = nHit;
5697 /* If drag cursor has not been loaded, load it.
5698 * Note: it doesn't need to be freed */
5700 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5701 SetCursor(hCursorDrag);
5706 infoPtr->nOldHit = nHit;
5708 CopyRect(&arrowRect, &btnPtr->rect);
5709 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5711 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5712 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5713 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5714 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5715 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5716 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5720 /* draw in pressed state */
5721 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5722 btnPtr->fsState |= TBSTATE_PRESSED;
5724 btnPtr->bDropDownPressed = TRUE;
5725 RedrawWindow(hwnd,&btnPtr->rect,0,
5726 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5728 memset(&nmtb, 0, sizeof(nmtb));
5729 nmtb.iItem = btnPtr->idCommand;
5730 nmtb.rcButton = btnPtr->rect;
5731 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5733 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5735 if (res != TBDDRET_TREATPRESSED)
5739 /* redraw button in unpressed state */
5740 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5741 btnPtr->fsState &= ~TBSTATE_PRESSED;
5743 btnPtr->bDropDownPressed = FALSE;
5744 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5746 /* find and set hot item
5747 * NOTE: native doesn't do this, but that is a bug */
5749 ScreenToClient(hwnd, &pt);
5750 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5751 if (!infoPtr->bAnchor || (nHit >= 0))
5752 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5754 /* remove any left mouse button down or double-click messages
5755 * so that we can get a toggle effect on the button */
5756 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5757 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5762 /* otherwise drop through and process as pushed */
5764 infoPtr->bCaptured = TRUE;
5765 infoPtr->nButtonDown = nHit;
5766 infoPtr->bDragOutSent = FALSE;
5768 btnPtr->fsState |= TBSTATE_PRESSED;
5770 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5772 if (btnPtr->fsState & TBSTATE_ENABLED)
5773 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5780 memset(&nmtb, 0, sizeof(nmtb));
5781 nmtb.iItem = btnPtr->idCommand;
5782 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5785 nmmouse.dwHitInfo = nHit;
5787 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5789 nmmouse.dwItemSpec = -1;
5792 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5793 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5796 ClientToScreen(hwnd, &pt);
5799 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5800 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5806 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5808 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5809 TBUTTON_INFO *btnPtr;
5813 BOOL bSendMessage = TRUE;
5818 if (infoPtr->hwndToolTip)
5819 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5820 WM_LBUTTONUP, wParam, lParam);
5822 pt.x = (INT)LOWORD(lParam);
5823 pt.y = (INT)HIWORD(lParam);
5824 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5826 if (!infoPtr->bAnchor || (nHit >= 0))
5827 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5829 if (infoPtr->nButtonDrag >= 0) {
5833 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5836 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5838 GetClientRect(hwnd, &rcClient);
5839 if (PtInRect(&rcClient, pt))
5846 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5849 if (nButton == infoPtr->nButtonDrag)
5851 /* if the button is moved sightly left and we have a
5852 * separator there then remove it */
5853 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5855 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5856 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5858 else /* else insert a separator before the dragged button */
5861 memset(&tbb, 0, sizeof(tbb));
5862 tbb.fsStyle = BTNS_SEP;
5864 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5871 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5872 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5874 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5877 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5882 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5883 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5886 /* button under cursor changed so need to re-set hot item */
5887 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5888 infoPtr->nButtonDrag = -1;
5890 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5892 else if (infoPtr->nButtonDown >= 0) {
5893 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5894 btnPtr->fsState &= ~TBSTATE_PRESSED;
5896 if (btnPtr->fsStyle & BTNS_CHECK) {
5897 if (btnPtr->fsStyle & BTNS_GROUP) {
5898 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5900 if (nOldIndex == nHit)
5901 bSendMessage = FALSE;
5902 if ((nOldIndex != nHit) &&
5904 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5905 btnPtr->fsState |= TBSTATE_CHECKED;
5908 if (btnPtr->fsState & TBSTATE_CHECKED)
5909 btnPtr->fsState &= ~TBSTATE_CHECKED;
5911 btnPtr->fsState |= TBSTATE_CHECKED;
5915 if (nOldIndex != -1)
5916 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5919 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5920 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5921 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5923 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5925 infoPtr->nButtonDown = -1;
5927 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5928 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5929 NM_RELEASEDCAPTURE);
5931 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5934 memset(&nmtb, 0, sizeof(nmtb));
5935 nmtb.iItem = btnPtr->idCommand;
5936 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5939 if (btnPtr->fsState & TBSTATE_ENABLED)
5941 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5942 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5946 /* !!! Undocumented - toolbar at 4.71 level and above sends
5947 * NM_CLICK with the NMMOUSE structure. */
5948 nmmouse.dwHitInfo = nHit;
5950 if (nmmouse.dwHitInfo < 0)
5951 nmmouse.dwItemSpec = -1;
5954 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5955 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5958 ClientToScreen(hwnd, &pt);
5961 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5962 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5968 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5975 pt.x = LOWORD(lParam);
5976 pt.y = HIWORD(lParam);
5978 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5979 nmmouse.dwHitInfo = nHit;
5982 nmmouse.dwItemSpec = -1;
5984 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5985 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5988 ClientToScreen(hwnd, &pt);
5991 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5992 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5998 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
6000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6003 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
6004 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
6010 TOOLBAR_CaptureChanged(HWND hwnd)
6012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6013 TBUTTON_INFO *btnPtr;
6015 infoPtr->bCaptured = FALSE;
6017 if (infoPtr->nButtonDown >= 0)
6019 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6020 btnPtr->fsState &= ~TBSTATE_PRESSED;
6022 infoPtr->nOldHit = -1;
6024 if (btnPtr->fsState & TBSTATE_ENABLED)
6025 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6031 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
6033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6034 TBUTTON_INFO *hotBtnPtr;
6036 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
6038 /* don't remove hot effects when in anchor highlighting mode or when a
6039 * drop-down button is pressed */
6040 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
6041 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
6043 if (infoPtr->nOldHit < 0)
6046 /* If the last button we were over is depressed then make it not */
6047 /* depressed and redraw it */
6048 if(infoPtr->nOldHit == infoPtr->nButtonDown)
6050 TBUTTON_INFO *btnPtr;
6053 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6055 btnPtr->fsState &= ~TBSTATE_PRESSED;
6057 rc1 = hotBtnPtr->rect;
6058 InflateRect (&rc1, 1, 1);
6059 InvalidateRect (hwnd, &rc1, TRUE);
6062 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
6065 ZeroMemory(&nmt, sizeof(nmt));
6066 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6067 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6068 infoPtr->bDragOutSent = TRUE;
6071 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
6077 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6079 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6081 TRACKMOUSEEVENT trackinfo;
6083 TBUTTON_INFO *btnPtr;
6085 if (infoPtr->dwStyle & TBSTYLE_FLAT) {
6086 /* fill in the TRACKMOUSEEVENT struct */
6087 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6088 trackinfo.dwFlags = TME_QUERY;
6089 trackinfo.hwndTrack = hwnd;
6090 trackinfo.dwHoverTime = HOVER_DEFAULT;
6092 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6093 _TrackMouseEvent(&trackinfo);
6095 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6096 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6097 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6099 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6100 /* and can properly deactivate the hot toolbar button */
6101 _TrackMouseEvent(&trackinfo);
6105 if (infoPtr->hwndToolTip)
6106 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6107 WM_MOUSEMOVE, wParam, lParam);
6109 pt.x = (INT)LOWORD(lParam);
6110 pt.y = (INT)HIWORD(lParam);
6112 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6114 if ((infoPtr->dwStyle & TBSTYLE_FLAT) && (!infoPtr->bAnchor || (nHit >= 0)))
6115 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6117 if (infoPtr->nOldHit != nHit)
6119 if (infoPtr->bCaptured)
6121 if (!infoPtr->bDragOutSent)
6124 ZeroMemory(&nmt, sizeof(nmt));
6125 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6126 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6127 infoPtr->bDragOutSent = TRUE;
6130 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6131 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6132 btnPtr->fsState &= ~TBSTATE_PRESSED;
6133 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6135 else if (nHit == infoPtr->nButtonDown) {
6136 btnPtr->fsState |= TBSTATE_PRESSED;
6137 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6139 infoPtr->nOldHit = nHit;
6147 inline static LRESULT
6148 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6150 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6151 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6153 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6157 inline static LRESULT
6158 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6160 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6161 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6163 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6168 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6170 TOOLBAR_INFO *infoPtr;
6171 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6174 /* allocate memory for info structure */
6175 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6176 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6179 infoPtr->dwStructSize = sizeof(TBBUTTON);
6182 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6183 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6184 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6185 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6188 /* native control does:
6189 * Get a lot of colors and brushes
6191 * SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
6192 * CreateFontIndirectW(adr1)
6193 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6194 * hdc = GetDC(toolbar)
6195 * GetSystemMetrics(0x48)
6196 * fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6197 * 0, 0, 0, 0, "MARLETT")
6198 * oldfnt = SelectObject(hdc, fnt2)
6199 * GetCharWidthW(hdc, 0x36, 0x36, adr2)
6200 * GetTextMetricsW(hdc, adr3)
6201 * SelectObject(hdc, oldfnt)
6202 * DeleteObject(fnt2)
6204 * InvalidateRect(toolbar, 0, 1)
6205 * SetWindowLongW(toolbar, 0, addr)
6206 * SetWindowLongW(toolbar, -16, xxx) **sometimes**
6209 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6210 * ie 2 0x4600094c 0x4600094c 0x4600894d
6211 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6212 * rebar 0x50008844 0x40008844 0x50008845
6213 * pager 0x50000844 0x40000844 0x50008845
6214 * IC35mgr 0x5400084e **nochange**
6215 * on entry to _NCCREATE 0x5400084e
6216 * rowlist 0x5400004e **nochange**
6217 * on entry to _NCCREATE 0x5400004e
6221 /* I think the code below is a bug, but it is the way that the native
6222 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6223 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6224 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6225 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6226 * Some how, the only cases of this seem to be MFC programs.
6228 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6229 * does not occur in the WM_STYLECHANGING routine.
6230 * (Guy Albertelli 9/2001)
6233 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6234 styleadd |= TBSTYLE_TRANSPARENT;
6235 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6236 styleadd |= CCS_TOP; /* default to top */
6237 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6240 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6245 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6247 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6251 if (dwStyle & WS_MINIMIZE)
6252 return 0; /* Nothing to do */
6254 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6256 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6259 if (!(dwStyle & CCS_NODIVIDER))
6261 GetWindowRect (hwnd, &rcWindow);
6262 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6263 if( dwStyle & WS_BORDER )
6264 OffsetRect (&rcWindow, 1, 1);
6265 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6268 ReleaseDC( hwnd, hdc );
6274 /* handles requests from the tooltip control on what text to display */
6275 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6277 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6279 TRACE("button index = %d\n", index);
6281 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6282 infoPtr->pszTooltipText = NULL;
6287 if (infoPtr->bUnicode)
6289 WCHAR wszBuffer[INFOTIPSIZE+1];
6290 NMTBGETINFOTIPW tbgit;
6291 unsigned int len; /* in chars */
6293 wszBuffer[0] = '\0';
6294 wszBuffer[INFOTIPSIZE] = '\0';
6296 tbgit.pszText = wszBuffer;
6297 tbgit.cchTextMax = INFOTIPSIZE;
6298 tbgit.iItem = lpnmtdi->hdr.idFrom;
6299 tbgit.lParam = infoPtr->buttons[index].dwData;
6301 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6303 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6305 len = strlenW(tbgit.pszText);
6306 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6308 /* need to allocate temporary buffer in infoPtr as there
6309 * isn't enough space in buffer passed to us by the
6310 * tooltip control */
6311 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6312 if (infoPtr->pszTooltipText)
6314 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6315 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6321 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6327 CHAR szBuffer[INFOTIPSIZE+1];
6328 NMTBGETINFOTIPA tbgit;
6329 unsigned int len; /* in chars */
6332 szBuffer[INFOTIPSIZE] = '\0';
6334 tbgit.pszText = szBuffer;
6335 tbgit.cchTextMax = INFOTIPSIZE;
6336 tbgit.iItem = lpnmtdi->hdr.idFrom;
6337 tbgit.lParam = infoPtr->buttons[index].dwData;
6339 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6341 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6343 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6344 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6346 /* need to allocate temporary buffer in infoPtr as there
6347 * isn't enough space in buffer passed to us by the
6348 * tooltip control */
6349 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6350 if (infoPtr->pszTooltipText)
6352 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6353 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6359 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6364 /* if button has text, but it is not shown then automatically
6365 * use that text as tooltip */
6366 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6367 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6369 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6370 unsigned int len = pszText ? strlenW(pszText) : 0;
6372 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6374 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6376 /* need to allocate temporary buffer in infoPtr as there
6377 * isn't enough space in buffer passed to us by the
6378 * tooltip control */
6379 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6380 if (infoPtr->pszTooltipText)
6382 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6383 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6389 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6394 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6396 /* last resort: send notification on to app */
6397 /* FIXME: find out what is really used here */
6398 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6402 inline static LRESULT
6403 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6405 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6406 LPNMHDR lpnmh = (LPNMHDR)lParam;
6408 switch (lpnmh->code)
6412 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6414 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6415 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6416 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6420 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6421 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6429 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6431 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6432 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6433 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6434 lppgs->iScroll, lppgs->iDir);
6438 case TTN_GETDISPINFOW:
6439 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6441 case TTN_GETDISPINFOA:
6442 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6452 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6456 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6458 if (lParam == NF_QUERY)
6461 if (lParam == NF_REQUERY) {
6462 format = SendMessageW(infoPtr->hwndNotify,
6463 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6464 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6465 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6476 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6482 /* fill ps.rcPaint with a default rect */
6483 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6485 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6487 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6488 ps.rcPaint.left, ps.rcPaint.top,
6489 ps.rcPaint.right, ps.rcPaint.bottom);
6491 TOOLBAR_Refresh (hwnd, hdc, &ps);
6492 if (!wParam) EndPaint (hwnd, &ps);
6499 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6500 /*****************************************************
6503 * Handles the WM_SETREDRAW message.
6506 * According to testing V4.71 of COMCTL32 returns the
6507 * *previous* status of the redraw flag (either 0 or 1)
6508 * instead of the MSDN documented value of 0 if handled.
6509 * (For laughs see the "consistency" with same function
6512 *****************************************************/
6514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6515 BOOL oldredraw = infoPtr->bDoRedraw;
6517 TRACE("set to %s\n",
6518 (wParam) ? "TRUE" : "FALSE");
6519 infoPtr->bDoRedraw = (BOOL) wParam;
6521 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6523 return (oldredraw) ? 1 : 0;
6528 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6531 DWORD dwStyle = infoPtr->dwStyle;
6540 /* Resize deadlock check */
6541 if (infoPtr->bAutoSize) {
6542 infoPtr->bAutoSize = FALSE;
6546 /* FIXME: optimize to only update size if the new size doesn't */
6547 /* match the current size */
6549 flags = (INT) wParam;
6551 /* FIXME for flags =
6552 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6555 TRACE("sizing toolbar!\n");
6557 if (flags == SIZE_RESTORED) {
6558 /* width and height don't apply */
6559 parent = GetParent (hwnd);
6560 GetClientRect(parent, &parent_rect);
6561 x = parent_rect.left;
6562 y = parent_rect.top;
6564 if (dwStyle & CCS_NORESIZE) {
6565 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6568 * this sets the working width of the toolbar, and
6569 * Calc Toolbar will not adjust it, only the height
6571 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6572 cy = infoPtr->nHeight;
6573 cx = infoPtr->nWidth;
6574 TOOLBAR_CalcToolbar (hwnd);
6575 infoPtr->nWidth = cx;
6576 infoPtr->nHeight = cy;
6579 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6580 TOOLBAR_CalcToolbar (hwnd);
6581 cy = infoPtr->nHeight;
6582 cx = infoPtr->nWidth;
6584 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6585 GetWindowRect(hwnd, &window_rect);
6586 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6587 y = window_rect.top;
6589 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6590 GetWindowRect(hwnd, &window_rect);
6591 y = parent_rect.bottom -
6592 ( window_rect.bottom - window_rect.top);
6596 if (dwStyle & CCS_NOPARENTALIGN) {
6597 uPosFlags |= SWP_NOMOVE;
6598 cy = infoPtr->nHeight;
6599 cx = infoPtr->nWidth;
6602 if (!(dwStyle & CCS_NODIVIDER))
6603 cy += GetSystemMetrics(SM_CYEDGE);
6605 if (dwStyle & WS_BORDER)
6608 cy += GetSystemMetrics(SM_CYEDGE);
6609 cx += GetSystemMetrics(SM_CXEDGE);
6612 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6614 RECT delta_width, delta_height, client, dummy;
6615 DWORD min_x, max_x, min_y, max_y;
6616 TBUTTON_INFO *btnPtr;
6619 GetClientRect(hwnd, &client);
6620 if(client.right > infoPtr->client_rect.right)
6622 min_x = infoPtr->client_rect.right;
6623 max_x = client.right;
6627 max_x = infoPtr->client_rect.right;
6628 min_x = client.right;
6630 if(client.bottom > infoPtr->client_rect.bottom)
6632 min_y = infoPtr->client_rect.bottom;
6633 max_y = client.bottom;
6637 max_y = infoPtr->client_rect.bottom;
6638 min_y = client.bottom;
6641 SetRect(&delta_width, min_x, 0, max_x, min_y);
6642 SetRect(&delta_height, 0, min_y, max_x, max_y);
6644 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6645 btnPtr = infoPtr->buttons;
6646 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6647 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6648 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6649 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6652 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6653 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6655 GetClientRect(hwnd, &infoPtr->client_rect);
6661 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6663 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6665 if (nType == GWL_STYLE)
6667 if (lpStyle->styleNew & TBSTYLE_LIST)
6668 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6670 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6672 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6673 (TBSTYLE_FLAT | TBSTYLE_LIST));
6674 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6676 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6678 infoPtr->dwStyle = lpStyle->styleNew;
6680 /* only resize if one of the CCS_* styles was changed */
6681 if ((infoPtr->dwStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6683 TOOLBAR_AutoSize (hwnd);
6685 InvalidateRect(hwnd, NULL, TRUE);
6694 TOOLBAR_SysColorChange (HWND hwnd)
6696 COMCTL32_RefreshSysColors();
6703 static LRESULT WINAPI
6704 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6708 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6709 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6711 if (!infoPtr && (uMsg != WM_NCCREATE))
6712 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6717 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6719 case TB_ADDBUTTONSA:
6720 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6722 case TB_ADDBUTTONSW:
6723 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6726 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6729 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6732 return TOOLBAR_AutoSize (hwnd);
6734 case TB_BUTTONCOUNT:
6735 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6737 case TB_BUTTONSTRUCTSIZE:
6738 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6740 case TB_CHANGEBITMAP:
6741 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6743 case TB_CHECKBUTTON:
6744 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6746 case TB_COMMANDTOINDEX:
6747 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6750 return TOOLBAR_Customize (hwnd);
6752 case TB_DELETEBUTTON:
6753 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6755 case TB_ENABLEBUTTON:
6756 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6758 case TB_GETANCHORHIGHLIGHT:
6759 return TOOLBAR_GetAnchorHighlight (hwnd);
6762 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6764 case TB_GETBITMAPFLAGS:
6765 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6768 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6770 case TB_GETBUTTONINFOA:
6771 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6773 case TB_GETBUTTONINFOW:
6774 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6776 case TB_GETBUTTONSIZE:
6777 return TOOLBAR_GetButtonSize (hwnd);
6779 case TB_GETBUTTONTEXTA:
6780 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6782 case TB_GETBUTTONTEXTW:
6783 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6785 case TB_GETDISABLEDIMAGELIST:
6786 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6788 case TB_GETEXTENDEDSTYLE:
6789 return TOOLBAR_GetExtendedStyle (hwnd);
6791 case TB_GETHOTIMAGELIST:
6792 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6795 return TOOLBAR_GetHotItem (hwnd);
6797 case TB_GETIMAGELIST:
6798 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6800 case TB_GETINSERTMARK:
6801 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6803 case TB_GETINSERTMARKCOLOR:
6804 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6806 case TB_GETITEMRECT:
6807 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6810 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6812 /* case TB_GETOBJECT: */ /* 4.71 */
6815 return TOOLBAR_GetPadding (hwnd);
6818 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6821 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6824 return TOOLBAR_GetState (hwnd, wParam, lParam);
6827 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6830 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6833 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6835 case TB_GETTEXTROWS:
6836 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6838 case TB_GETTOOLTIPS:
6839 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6841 case TB_GETUNICODEFORMAT:
6842 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6845 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6848 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6850 case TB_INDETERMINATE:
6851 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6853 case TB_INSERTBUTTONA:
6854 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6856 case TB_INSERTBUTTONW:
6857 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6859 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6861 case TB_ISBUTTONCHECKED:
6862 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6864 case TB_ISBUTTONENABLED:
6865 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6867 case TB_ISBUTTONHIDDEN:
6868 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6870 case TB_ISBUTTONHIGHLIGHTED:
6871 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6873 case TB_ISBUTTONINDETERMINATE:
6874 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6876 case TB_ISBUTTONPRESSED:
6877 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6880 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6882 case TB_MAPACCELERATORA:
6883 case TB_MAPACCELERATORW:
6884 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6887 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6890 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6892 case TB_PRESSBUTTON:
6893 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6895 case TB_REPLACEBITMAP:
6896 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6898 case TB_SAVERESTOREA:
6899 return TOOLBAR_SaveRestoreA (hwnd, wParam, (LPTBSAVEPARAMSA)lParam);
6901 case TB_SAVERESTOREW:
6902 return TOOLBAR_SaveRestoreW (hwnd, wParam, (LPTBSAVEPARAMSW)lParam);
6904 case TB_SETANCHORHIGHLIGHT:
6905 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6907 case TB_SETBITMAPSIZE:
6908 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6910 case TB_SETBUTTONINFOA:
6911 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6913 case TB_SETBUTTONINFOW:
6914 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6916 case TB_SETBUTTONSIZE:
6917 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6919 case TB_SETBUTTONWIDTH:
6920 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6923 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6925 case TB_SETDISABLEDIMAGELIST:
6926 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6928 case TB_SETDRAWTEXTFLAGS:
6929 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6931 case TB_SETEXTENDEDSTYLE:
6932 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6934 case TB_SETHOTIMAGELIST:
6935 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6938 return TOOLBAR_SetHotItem (hwnd, wParam);
6940 case TB_SETIMAGELIST:
6941 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6944 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6946 case TB_SETINSERTMARK:
6947 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6949 case TB_SETINSERTMARKCOLOR:
6950 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6952 case TB_SETMAXTEXTROWS:
6953 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6956 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6959 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6962 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6965 return TOOLBAR_SetState (hwnd, wParam, lParam);
6968 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6970 case TB_SETTOOLTIPS:
6971 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6973 case TB_SETUNICODEFORMAT:
6974 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6977 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6980 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6983 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6986 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6989 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6992 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6994 /* Common Control Messages */
6996 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6997 case CCM_GETCOLORSCHEME:
6998 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7000 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
7001 case CCM_SETCOLORSCHEME:
7002 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
7004 case CCM_GETVERSION:
7005 return TOOLBAR_GetVersion (hwnd);
7007 case CCM_SETVERSION:
7008 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
7014 return TOOLBAR_Create (hwnd, wParam, lParam);
7017 return TOOLBAR_Destroy (hwnd, wParam, lParam);
7020 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
7023 return TOOLBAR_GetFont (hwnd, wParam, lParam);
7025 /* case WM_KEYDOWN: */
7026 /* case WM_KILLFOCUS: */
7028 case WM_LBUTTONDBLCLK:
7029 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
7031 case WM_LBUTTONDOWN:
7032 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
7035 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
7038 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
7040 case WM_RBUTTONDBLCLK:
7041 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
7044 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
7047 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
7049 case WM_CAPTURECHANGED:
7050 return TOOLBAR_CaptureChanged(hwnd);
7053 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
7056 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
7059 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
7062 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
7065 return TOOLBAR_Notify (hwnd, wParam, lParam);
7067 case WM_NOTIFYFORMAT:
7068 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
7071 return TOOLBAR_Paint (hwnd, wParam);
7074 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7077 return TOOLBAR_Size (hwnd, wParam, lParam);
7079 case WM_STYLECHANGED:
7080 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7082 case WM_SYSCOLORCHANGE:
7083 return TOOLBAR_SysColorChange (hwnd);
7085 /* case WM_WININICHANGE: */
7090 case WM_MEASUREITEM:
7092 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7094 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7095 case PGM_FORWARDMOUSE:
7096 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7099 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7100 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7101 uMsg, wParam, lParam);
7102 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7108 TOOLBAR_Register (void)
7112 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7113 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7114 wndClass.lpfnWndProc = ToolbarWindowProc;
7115 wndClass.cbClsExtra = 0;
7116 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7117 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7118 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7119 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7121 RegisterClassW (&wndClass);
7126 TOOLBAR_Unregister (void)
7128 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7131 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7136 /* Check if the entry already exists */
7137 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7139 /* If this is a new entry we must create it and insert into the array */
7144 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7147 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7148 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7163 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7167 for (i = 0; i < *cies; i++)
7177 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7185 for (i = 0; i < cies; i++)
7187 if (pies[i]->id == id)
7199 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7201 HIMAGELIST himlDef = 0;
7202 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7205 himlDef = pie->himl;
7211 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7213 if (infoPtr->bUnicode)
7214 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
7221 nmtba.iItem = nmtb->iItem;
7222 nmtba.pszText = Buffer;
7223 nmtba.cchText = 256;
7224 ZeroMemory(nmtba.pszText, nmtba.cchText);
7226 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
7228 int ccht = strlen(nmtba.pszText);
7230 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7231 nmtb->pszText, nmtb->cchText);
7233 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7242 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7243 int iItem, PCUSTOMBUTTON btnInfo)
7247 /* MSDN states that iItem is the index of the button, rather than the
7248 * command ID as used by every other NMTOOLBAR notification */
7250 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7252 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);