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 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
42 * - TBSTYLE_REGISTERDROP
43 * - TBSTYLE_EX_DOUBLEBUFFER
47 * - TB_INSERTMARKHITTEST
56 * - Button wrapping (under construction).
58 * - iListGap custom draw support.
61 * - Run tests using Waite Group Windows95 API Bible Volume 2.
62 * The second cdrom contains executables addstr.exe, btncount.exe,
63 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
64 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
65 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
66 * setparnt.exe, setrows.exe, toolwnd.exe.
67 * - Microsofts controlspy examples.
68 * - Charles Petzold's 'Programming Windows': gadgets.exe
78 #include "wine/unicode.h"
82 #include "wine/debug.h"
84 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
86 static HCURSOR hCursorDrag = NULL;
95 BYTE bDropDownPressed;
100 INT cx; /* manually set size */
114 } IMLENTRY, *PIMLENTRY;
118 DWORD dwStructSize; /* size of TBBUTTON struct */
119 INT nHeight; /* height of the toolbar */
120 INT nWidth; /* width of the toolbar */
122 RECT rcBound; /* bounding rectangle */
128 INT nRows; /* number of button rows */
129 INT nMaxTextRows; /* maximum number of text rows */
130 INT cxMin; /* minimum button width */
131 INT cxMax; /* maximum button width */
132 INT nNumButtons; /* number of buttons */
133 INT nNumBitmaps; /* number of bitmaps */
134 INT nNumStrings; /* number of strings */
136 INT nButtonDown; /* toolbar button being pressed or -1 if none */
137 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
139 INT nHotItem; /* index of the "hot" item */
140 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
141 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
142 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
143 SIZE szPadding; /* padding values around button */
144 INT iListGap; /* default gap between text and image for toolbar with list style */
146 HFONT hFont; /* text font */
147 HIMAGELIST himlInt; /* image list created internally */
148 PIMLENTRY *himlDef; /* default image list array */
149 INT cimlDef; /* default image list array count */
150 PIMLENTRY *himlHot; /* hot image list array */
151 INT cimlHot; /* hot image list array count */
152 PIMLENTRY *himlDis; /* disabled image list array */
153 INT cimlDis; /* disabled image list array count */
154 HWND hwndToolTip; /* handle to tool tip control */
155 HWND hwndNotify; /* handle to the window that gets notifications */
156 HWND hwndSelf; /* my own handle */
157 BOOL bBtnTranspnt; /* button transparency flag */
158 BOOL bAutoSize; /* auto size deadlock indicator */
159 BOOL bAnchor; /* anchor highlight enabled */
160 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
161 BOOL bDoRedraw; /* Redraw status */
162 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
163 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
164 BOOL bCaptured; /* mouse captured? */
165 DWORD dwStyle; /* regular toolbar style */
166 DWORD dwExStyle; /* extended toolbar style */
167 DWORD dwDTFlags; /* DrawText flags */
169 COLORREF clrInsertMark; /* insert mark color */
170 COLORREF clrBtnHighlight; /* color for Flat Separator */
171 COLORREF clrBtnShadow; /* color for Flag Separator */
173 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
174 * for TTN_GETDISPINFOW notification */
175 TBINSERTMARK tbim; /* info on insertion mark */
176 TBUTTON_INFO *buttons; /* pointer to button array */
177 LPWSTR *strings; /* pointer to string array */
178 TBITMAP_INFO *bitmaps;
179 } TOOLBAR_INFO, *PTOOLBAR_INFO;
182 /* used by customization dialog */
185 PTOOLBAR_INFO tbInfo;
187 } CUSTDLG_INFO, *PCUSTDLG_INFO;
195 } CUSTOMBUTTON, *PCUSTOMBUTTON;
204 #define SEPARATOR_WIDTH 8
206 #define BOTTOM_BORDER 2
207 #define DDARROW_WIDTH 11
208 #define ARROW_HEIGHT 3
209 #define INSERTMARK_WIDTH 2
211 /* gap between border of button and text/image */
214 /* how wide to treat the bitmap if it isn't present */
215 #define LIST_IMAGE_ABSENT_WIDTH 2
217 #define TOOLBAR_NOWHERE (-1)
219 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
220 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
221 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
223 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
225 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
228 /* Used to find undocumented extended styles */
229 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
230 TBSTYLE_EX_UNDOC1 | \
231 TBSTYLE_EX_MIXEDBUTTONS | \
232 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
234 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
235 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
236 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
237 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
238 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
240 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
241 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
242 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
243 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
244 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
245 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
246 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
247 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
250 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
254 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
256 LPWSTR lpText = NULL;
258 /* NOTE: iString == -1 is undocumented */
259 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
260 lpText = (LPWSTR)btnPtr->iString;
261 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
262 lpText = infoPtr->strings[btnPtr->iString];
268 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
270 if (TRACE_ON(toolbar)){
271 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
272 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
273 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
274 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
276 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
277 btn_num, bP->idCommand,
278 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
279 bP->rect.left, bP->rect.top,
280 bP->rect.right, bP->rect.bottom);
286 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
288 if (TRACE_ON(toolbar)) {
291 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
293 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
294 iP->nNumStrings, iP->dwStyle);
295 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
297 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
298 (iP->bDoRedraw) ? "TRUE" : "FALSE");
299 for(i=0; i<iP->nNumButtons; i++) {
300 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
306 /***********************************************************************
309 * This function validates that the styles set are implemented and
310 * issues FIXME's warning of possible problems. In a perfect world this
311 * function should be null.
314 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
316 if (dwStyle & TBSTYLE_REGISTERDROP)
317 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
322 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
324 if(!IsWindow(infoPtr->hwndSelf))
325 return 0; /* we have just been destroyed */
327 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
328 nmhdr->hwndFrom = infoPtr->hwndSelf;
331 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
332 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
334 if (infoPtr->bNtfUnicode)
335 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
336 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
338 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
342 /***********************************************************************
343 * TOOLBAR_GetBitmapIndex
345 * This function returns the bitmap index associated with a button.
346 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
347 * is issued to retrieve the index.
350 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 INT ret = btnPtr->iBitmap;
354 if (ret == I_IMAGECALLBACK) {
355 /* issue TBN_GETDISPINFO */
358 nmgd.idCommand = btnPtr->idCommand;
359 nmgd.lParam = btnPtr->dwData;
360 nmgd.dwMask = TBNF_IMAGE;
361 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
362 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
364 if (nmgd.dwMask & TBNF_DI_SETITEM) {
365 btnPtr->iBitmap = nmgd.iImage;
368 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
369 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 if (ret != I_IMAGENONE)
373 ret = GETIBITMAP(infoPtr, ret);
380 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
383 INT id = GETHIMLID(infoPtr, index);
384 INT iBitmap = GETIBITMAP(infoPtr, index);
386 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
387 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
388 (index == I_IMAGECALLBACK))
395 /***********************************************************************
396 * TOOLBAR_GetImageListForDrawing
398 * This function validates the bitmap index (including I_IMAGECALLBACK
399 * functionality) and returns the corresponding image list.
402 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
406 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
407 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
408 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
409 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
413 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
414 if ((*index == I_IMAGECALLBACK) ||
415 (*index == I_IMAGENONE)) return NULL;
416 ERR("TBN_GETDISPINFO returned invalid index %d\n",
423 case IMAGE_LIST_DEFAULT:
424 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
427 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
429 case IMAGE_LIST_DISABLED:
430 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
434 FIXME("Shouldn't reach here\n");
438 TRACE("no image list\n");
444 /***********************************************************************
445 * TOOLBAR_TestImageExist
447 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
448 * return the image list. The I_IMAGECALLBACK functionality is implemented.
451 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
455 if (!himl) return FALSE;
457 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
458 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
459 ERR("index %d is not valid, max %d\n",
460 btnPtr->iBitmap, infoPtr->nNumBitmaps);
464 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
465 if ((index == I_IMAGECALLBACK) ||
466 (index == I_IMAGENONE)) return FALSE;
467 ERR("TBN_GETDISPINFO returned invalid index %d\n",
476 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
479 COLORREF oldcolor, newcolor;
481 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
482 myrect.right = myrect.left + 1;
483 myrect.top = lpRect->top + 2;
484 myrect.bottom = lpRect->bottom - 2;
486 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
487 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
488 oldcolor = SetBkColor (hdc, newcolor);
489 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
491 myrect.left = myrect.right;
492 myrect.right = myrect.left + 1;
494 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
495 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
496 SetBkColor (hdc, newcolor);
497 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
499 SetBkColor (hdc, oldcolor);
503 /***********************************************************************
504 * TOOLBAR_DrawDDFlatSeparator
506 * This function draws the separator that was flagged as BTNS_DROPDOWN.
507 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
508 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
509 * are horizontal as opposed to the vertical separators for not dropdown
512 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
515 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
518 COLORREF oldcolor, newcolor;
520 myrect.left = lpRect->left;
521 myrect.right = lpRect->right;
522 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
523 myrect.bottom = myrect.top + 1;
525 InflateRect (&myrect, -2, 0);
527 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
528 myrect.left, myrect.top, myrect.right, myrect.bottom);
530 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
531 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
532 oldcolor = SetBkColor (hdc, newcolor);
533 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
535 myrect.top = myrect.bottom;
536 myrect.bottom = myrect.top + 1;
538 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
539 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
540 SetBkColor (hdc, newcolor);
541 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
543 SetBkColor (hdc, oldcolor);
548 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
553 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
554 hOldPen = SelectObject ( hdc, hPen );
557 MoveToEx (hdc, x, y, NULL);
558 LineTo (hdc, x+5, y++); x++;
559 MoveToEx (hdc, x, y, NULL);
560 LineTo (hdc, x+3, y++); x++;
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+1, y++);
563 SelectObject( hdc, hOldPen );
564 DeleteObject( hPen );
568 * Draw the text string for this button.
569 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
570 * is non-zero, so we can simply check himlDef to see if we have
574 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
575 NMTBCUSTOMDRAW *tbcd)
577 HDC hdc = tbcd->nmcd.hdc;
580 COLORREF clrOldBk = 0;
582 UINT state = tbcd->nmcd.uItemState;
586 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
587 rcText->left, rcText->top, rcText->right, rcText->bottom);
589 hOldFont = SelectObject (hdc, infoPtr->hFont);
590 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
591 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
593 else if (state & CDIS_DISABLED) {
594 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
595 OffsetRect (rcText, 1, 1);
596 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
597 SetTextColor (hdc, comctl32_color.clr3dShadow);
598 OffsetRect (rcText, -1, -1);
600 else if (state & CDIS_INDETERMINATE) {
601 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
603 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
604 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
605 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
606 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
609 clrOld = SetTextColor (hdc, tbcd->clrText);
612 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
613 SetTextColor (hdc, clrOld);
614 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
616 SetBkColor (hdc, clrOldBk);
617 SetBkMode (hdc, oldBkMode);
619 SelectObject (hdc, hOldFont);
625 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
627 HDC hdc = tbcd->nmcd.hdc;
628 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
631 INT cx = lpRect->right - lpRect->left;
632 INT cy = lpRect->bottom - lpRect->top;
633 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
634 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
635 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
636 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
637 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
638 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
639 SetBkColor(hdc, clrBkOld);
640 SetTextColor(hdc, clrTextOld);
641 SelectObject (hdc, hbr);
645 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
648 HBITMAP hbmMask, hbmImage;
649 HDC hdcMask, hdcImage;
651 ImageList_GetIconSize(himl, &cx, &cy);
653 /* Create src image */
654 hdcImage = CreateCompatibleDC(hdc);
655 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
656 SelectObject(hdcImage, hbmImage);
657 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
658 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
661 hdcMask = CreateCompatibleDC(0);
662 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
663 SelectObject(hdcMask, hbmMask);
665 /* Remove the background and all white pixels */
666 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
667 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
668 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
669 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
671 /* draw the new mask 'etched' to hdc */
672 SetBkColor(hdc, RGB(255, 255, 255));
673 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
674 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
675 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
676 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
677 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
680 DeleteObject(hbmImage);
682 DeleteObject (hbmMask);
688 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
692 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
693 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
694 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
695 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
696 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
698 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
702 /* draws the image on a toolbar button */
704 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
706 HIMAGELIST himl = NULL;
707 BOOL draw_masked = FALSE;
710 UINT draw_flags = ILD_TRANSPARENT;
712 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
714 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
721 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
723 /* if hot, attempt to draw with hot image list, if fails,
724 use default image list */
725 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
727 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
730 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
735 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
736 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
739 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
740 (tbcd->nmcd.uItemState & CDIS_MARKED))
741 draw_flags |= ILD_BLEND50;
743 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
744 index, himl, left, top, offset);
747 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
749 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
752 /* draws a blank frame for a toolbar button */
754 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
756 HDC hdc = tbcd->nmcd.hdc;
757 RECT rc = tbcd->nmcd.rc;
758 /* if the state is disabled or indeterminate then the button
759 * cannot have an interactive look like pressed or hot */
760 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
761 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
762 BOOL pressed_look = !non_interactive_state &&
763 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
764 (tbcd->nmcd.uItemState & CDIS_CHECKED));
766 /* app don't want us to draw any edges */
767 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
773 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
774 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
775 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
780 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
782 DrawEdge (hdc, &rc, EDGE_RAISED,
783 BF_SOFT | BF_RECT | BF_MIDDLE);
788 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
790 HDC hdc = tbcd->nmcd.hdc;
792 BOOL pressed = bDropDownPressed ||
793 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
795 if (infoPtr->dwStyle & TBSTYLE_FLAT)
798 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
799 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
800 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
801 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
802 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
807 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
809 DrawEdge (hdc, rcArrow, EDGE_RAISED,
810 BF_SOFT | BF_RECT | BF_MIDDLE);
814 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
816 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
818 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
819 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
822 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
825 /* draws a complete toolbar button */
827 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
830 DWORD dwStyle = infoPtr->dwStyle;
831 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
832 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
833 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
834 BOOL drawSepDropDownArrow = hasDropDownArrow &&
835 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
836 RECT rc, rcArrow, rcBitmap, rcText;
837 LPWSTR lpText = NULL;
843 CopyRect (&rcArrow, &rc);
844 CopyRect(&rcBitmap, &rc);
846 /* get a pointer to the text */
847 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
849 if (hasDropDownArrow)
853 if (dwStyle & TBSTYLE_FLAT)
854 right = max(rc.left, rc.right - DDARROW_WIDTH);
856 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
858 if (drawSepDropDownArrow)
861 rcArrow.left = right;
864 /* copy text rect after adjusting for drop-down arrow
865 * so that text is centred in the rectangle not containing
867 CopyRect(&rcText, &rc);
869 /* Center the bitmap horizontally and vertically */
870 if (dwStyle & TBSTYLE_LIST)
871 rcBitmap.left += GetSystemMetrics(SM_CXEDGE);
873 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
876 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE);
878 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
880 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
881 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
882 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
883 TRACE ("iString: %x\n", btnPtr->iString);
884 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
888 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
889 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
890 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
891 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
893 if (dwStyle & TBSTYLE_LIST)
894 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
896 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
899 if (dwStyle & TBSTYLE_LIST)
900 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
902 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
903 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
904 OffsetRect(&rcText, 1, 1);
907 /* Initialize fields in all cases, because we use these later
908 * NOTE: applications can and do alter these to customize their
910 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
911 tbcd.clrText = comctl32_color.clrBtnText;
912 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
913 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
914 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
915 tbcd.clrMark = comctl32_color.clrHighlight;
916 tbcd.clrHighlightHotTrack = 0;
917 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
918 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 /* MSDN says that this is the text rectangle.
920 * But (why always a but) tracing of v5.7 of native shows
921 * that this is really a *relative* rectangle based on the
922 * the nmcd.rc. Also the left and top are always 0 ignoring
923 * any bitmap that might be present. */
924 tbcd.rcText.left = 0;
926 tbcd.rcText.right = rcText.right - rc.left;
927 tbcd.rcText.bottom = rcText.bottom - rc.top;
928 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
931 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
933 /* FIXME: what are these used for? */
937 /* Issue Item Prepaint notify */
938 infoPtr->dwItemCustDraw = 0;
939 infoPtr->dwItemCDFlag = 0;
940 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
942 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
943 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
944 tbcd.nmcd.lItemlParam = btnPtr->dwData;
945 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
946 /* reset these fields so the user can't alter the behaviour like native */
950 infoPtr->dwItemCustDraw = ntfret & 0xffff;
951 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
952 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
954 /* save the only part of the rect that the user can change */
955 rcText.right = tbcd.rcText.right + rc.left;
956 rcText.bottom = tbcd.rcText.bottom + rc.top;
960 if (btnPtr->fsStyle & BTNS_SEP) {
961 /* with the FLAT style, iBitmap is the width and has already */
962 /* been taken into consideration in calculating the width */
963 /* so now we need to draw the vertical separator */
964 /* empirical tests show that iBitmap can/will be non-zero */
965 /* when drawing the vertical bar... */
966 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
967 if (btnPtr->fsStyle & BTNS_DROPDOWN)
968 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
970 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
972 else if (btnPtr->fsStyle != BTNS_SEP) {
973 FIXME("Draw some kind of separator: fsStyle=%x\n",
979 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
980 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
981 TOOLBAR_DrawPattern (&rc, &tbcd);
983 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
985 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
989 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
990 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
991 if (hasDropDownArrow)
992 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
993 SetBkColor(hdc, oldclr);
997 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
999 if (drawSepDropDownArrow)
1000 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1002 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1003 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1005 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1007 if (hasDropDownArrow && !drawSepDropDownArrow)
1009 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1011 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1014 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1016 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1017 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1020 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1026 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1027 tbcd.nmcd.hdc = hdc;
1029 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1030 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1031 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1032 tbcd.rcText = rcText;
1033 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1034 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1042 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1045 TBUTTON_INFO *btnPtr;
1046 INT i, oldBKmode = 0;
1047 RECT rcTemp, rcClient;
1048 NMTBCUSTOMDRAW tbcd;
1051 /* the app has told us not to redraw the toolbar */
1052 if (!infoPtr->bDoRedraw)
1055 /* if imagelist belongs to the app, it can be changed
1056 by the app after setting it */
1057 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1059 infoPtr->nNumBitmaps = 0;
1060 for (i = 0; i < infoPtr->cimlDef; i++)
1061 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1064 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1066 /* Send initial notify */
1067 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1068 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1069 tbcd.nmcd.hdc = hdc;
1070 tbcd.nmcd.rc = ps->rcPaint;
1071 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1072 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1074 if (infoPtr->bBtnTranspnt)
1075 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1077 GetClientRect(hwnd, &rcClient);
1079 /* redraw necessary buttons */
1080 btnPtr = infoPtr->buttons;
1081 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1084 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1086 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1087 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1091 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1092 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1094 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1097 /* draw insert mark if required */
1098 if (infoPtr->tbim.iButton != -1)
1100 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1102 rcInsertMark.top = rcButton.top;
1103 rcInsertMark.bottom = rcButton.bottom;
1104 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1105 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1107 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1108 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1111 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1112 SetBkMode (hdc, oldBKmode);
1114 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1116 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1117 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1118 tbcd.nmcd.hdc = hdc;
1119 tbcd.nmcd.rc = ps->rcPaint;
1120 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1124 /***********************************************************************
1125 * TOOLBAR_MeasureString
1127 * This function gets the width and height of a string in pixels. This
1128 * is done first by using GetTextExtentPoint to get the basic width
1129 * and height. The DrawText is called with DT_CALCRECT to get the exact
1130 * width. The reason is because the text may have more than one "&" (or
1131 * prefix characters as M$ likes to call them). The prefix character
1132 * indicates where the underline goes, except for the string "&&" which
1133 * is reduced to a single "&". GetTextExtentPoint does not process these
1134 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1137 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1138 HDC hdc, LPSIZE lpSize)
1145 if (infoPtr->nMaxTextRows > 0 &&
1146 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1147 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1148 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1150 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1152 if(lpText != NULL) {
1153 /* first get size of all the text */
1154 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1156 /* feed above size into the rectangle for DrawText */
1157 myrect.left = myrect.top = 0;
1158 myrect.right = lpSize->cx;
1159 myrect.bottom = lpSize->cy;
1161 /* Use DrawText to get true size as drawn (less pesky "&") */
1162 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1163 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1166 /* feed back to caller */
1167 lpSize->cx = myrect.right;
1168 lpSize->cy = myrect.bottom;
1172 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1175 /***********************************************************************
1176 * TOOLBAR_CalcStrings
1178 * This function walks through each string and measures it and returns
1179 * the largest height and width to caller.
1182 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1185 TBUTTON_INFO *btnPtr;
1194 if(infoPtr->nMaxTextRows == 0)
1198 hOldFont = SelectObject (hdc, infoPtr->hFont);
1200 btnPtr = infoPtr->buttons;
1201 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1202 if(TOOLBAR_HasText(infoPtr, btnPtr))
1204 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1205 if (sz.cx > lpSize->cx)
1207 if (sz.cy > lpSize->cy)
1212 SelectObject (hdc, hOldFont);
1213 ReleaseDC (hwnd, hdc);
1215 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1218 /***********************************************************************
1219 * TOOLBAR_WrapToolbar
1221 * This function walks through the buttons and separators in the
1222 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1223 * wrapping should occur based on the width of the toolbar window.
1224 * It does *not* calculate button placement itself. That task
1225 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1226 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1227 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1229 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1230 * vertical toolbar lists.
1234 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1237 TBUTTON_INFO *btnPtr;
1240 BOOL bWrap, bButtonWrap;
1242 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1243 /* no layout is necessary. Applications may use this style */
1244 /* to perform their own layout on the toolbar. */
1245 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1246 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1248 btnPtr = infoPtr->buttons;
1249 x = infoPtr->nIndent;
1251 /* this can get the parents width, to know how far we can extend
1252 * this toolbar. We cannot use its height, as there may be multiple
1253 * toolbars in a rebar control
1255 GetClientRect( GetParent(hwnd), &rc );
1256 infoPtr->nWidth = rc.right - rc.left;
1257 bButtonWrap = FALSE;
1259 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1260 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1263 for (i = 0; i < infoPtr->nNumButtons; i++ )
1266 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1268 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1271 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1272 /* it is the actual width of the separator. This is used for */
1273 /* custom controls in toolbars. */
1275 /* BTNS_DROPDOWN separators are treated as buttons for */
1276 /* width. - GA 8/01 */
1277 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1278 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1279 cx = (btnPtr[i].iBitmap > 0) ?
1280 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1282 cx = infoPtr->nButtonWidth;
1284 /* Two or more adjacent separators form a separator group. */
1285 /* The first separator in a group should be wrapped to the */
1286 /* next row if the previous wrapping is on a button. */
1288 (btnPtr[i].fsStyle & BTNS_SEP) &&
1289 (i + 1 < infoPtr->nNumButtons ) &&
1290 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1292 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1293 btnPtr[i].fsState |= TBSTATE_WRAP;
1294 x = infoPtr->nIndent;
1296 bButtonWrap = FALSE;
1300 /* The layout makes sure the bitmap is visible, but not the button. */
1301 /* Test added to also wrap after a button that starts a row but */
1302 /* is bigger than the area. - GA 8/01 */
1303 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1304 > infoPtr->nWidth ) ||
1305 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1307 BOOL bFound = FALSE;
1309 /* If the current button is a separator and not hidden, */
1310 /* go to the next until it reaches a non separator. */
1311 /* Wrap the last separator if it is before a button. */
1312 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1313 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1314 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1315 i < infoPtr->nNumButtons )
1321 if( bFound && i < infoPtr->nNumButtons )
1324 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1325 i, btnPtr[i].fsStyle, x, cx);
1326 btnPtr[i].fsState |= TBSTATE_WRAP;
1327 x = infoPtr->nIndent;
1328 bButtonWrap = FALSE;
1331 else if ( i >= infoPtr->nNumButtons)
1334 /* If the current button is not a separator, find the last */
1335 /* separator and wrap it. */
1336 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1338 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1339 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1343 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1344 i, btnPtr[i].fsStyle, x, cx);
1345 x = infoPtr->nIndent;
1346 btnPtr[j].fsState |= TBSTATE_WRAP;
1347 bButtonWrap = FALSE;
1352 /* If no separator available for wrapping, wrap one of */
1353 /* non-hidden previous button. */
1357 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1359 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1364 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1365 i, btnPtr[i].fsStyle, x, cx);
1366 x = infoPtr->nIndent;
1367 btnPtr[j].fsState |= TBSTATE_WRAP;
1373 /* If all above failed, wrap the current button. */
1376 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1378 btnPtr[i].fsState |= TBSTATE_WRAP;
1380 x = infoPtr->nIndent;
1381 if (btnPtr[i].fsStyle & BTNS_SEP )
1382 bButtonWrap = FALSE;
1388 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1389 i, btnPtr[i].fsStyle, x, cx);
1396 /***********************************************************************
1397 * TOOLBAR_CalcToolbar
1399 * This function calculates button and separator placement. It first
1400 * calculates the button sizes, gets the toolbar window width and then
1401 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1402 * on. It assigns a new location to each item and sends this location to
1403 * the tooltip window if appropriate. Finally, it updates the rcBound
1404 * rect and calculates the new required toolbar window height.
1408 TOOLBAR_CalcToolbar (HWND hwnd)
1410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1411 DWORD dwStyle = infoPtr->dwStyle;
1412 TBUTTON_INFO *btnPtr;
1413 INT i, nRows, nSepRows;
1417 BOOL usesBitmaps = FALSE;
1418 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1420 TOOLBAR_CalcStrings (hwnd, &sizeString);
1422 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1424 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1426 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1429 if (dwStyle & TBSTYLE_LIST)
1431 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1432 0, sizeString.cy) + infoPtr->szPadding.cy;
1433 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1434 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1435 if (sizeString.cx > 0)
1436 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1437 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1438 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1439 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1442 if (sizeString.cy > 0)
1445 infoPtr->nButtonHeight = sizeString.cy +
1446 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1447 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1449 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1452 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1454 if (sizeString.cx > infoPtr->nBitmapWidth)
1455 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1457 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1460 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1461 infoPtr->nButtonWidth = infoPtr->cxMin;
1462 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1463 infoPtr->nButtonWidth = infoPtr->cxMax;
1465 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1467 x = infoPtr->nIndent;
1470 /* from above, minimum is a button, and possible text */
1471 cx = infoPtr->nButtonWidth;
1473 /* cannot use just ButtonHeight, we may have no buttons! */
1474 if (infoPtr->nNumButtons > 0)
1475 infoPtr->nHeight = infoPtr->nButtonHeight;
1477 cy = infoPtr->nHeight;
1479 nRows = nSepRows = 0;
1481 infoPtr->rcBound.top = y;
1482 infoPtr->rcBound.left = x;
1483 infoPtr->rcBound.bottom = y + cy;
1484 infoPtr->rcBound.right = x;
1486 btnPtr = infoPtr->buttons;
1488 TRACE("cy=%d\n", cy);
1490 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1493 if (btnPtr->fsState & TBSTATE_HIDDEN)
1495 SetRectEmpty (&btnPtr->rect);
1499 cy = infoPtr->nHeight;
1501 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1502 /* it is the actual width of the separator. This is used for */
1503 /* custom controls in toolbars. */
1504 if (btnPtr->fsStyle & BTNS_SEP) {
1505 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1506 cy = (btnPtr->iBitmap > 0) ?
1507 btnPtr->iBitmap : SEPARATOR_WIDTH;
1508 cx = infoPtr->nButtonWidth;
1511 cx = (btnPtr->iBitmap > 0) ?
1512 btnPtr->iBitmap : SEPARATOR_WIDTH;
1518 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1519 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1526 hOldFont = SelectObject (hdc, infoPtr->hFont);
1528 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1530 SelectObject (hdc, hOldFont);
1531 ReleaseDC (hwnd, hdc);
1533 /* add space on for button frame, etc */
1534 cx = sz.cx + infoPtr->szPadding.cx;
1536 /* add list padding */
1537 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1538 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1540 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1542 if (dwStyle & TBSTYLE_LIST)
1543 cx += infoPtr->nBitmapWidth;
1544 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1545 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1547 else if (dwStyle & TBSTYLE_LIST)
1548 cx += LIST_IMAGE_ABSENT_WIDTH;
1551 cx = infoPtr->nButtonWidth;
1553 /* if size has been set manually then don't add on extra space
1554 * for the drop down arrow */
1555 if (!btnPtr->cx && hasDropDownArrows &&
1556 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1557 cx += DDARROW_WIDTH;
1559 if (btnPtr->fsState & TBSTATE_WRAP )
1562 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1564 if (infoPtr->rcBound.left > x)
1565 infoPtr->rcBound.left = x;
1566 if (infoPtr->rcBound.right < x + cx)
1567 infoPtr->rcBound.right = x + cx;
1568 if (infoPtr->rcBound.bottom < y + cy)
1569 infoPtr->rcBound.bottom = y + cy;
1571 /* Set the toolTip only for non-hidden, non-separator button */
1572 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1576 ZeroMemory (&ti, sizeof(ti));
1577 ti.cbSize = sizeof(ti);
1579 ti.uId = btnPtr->idCommand;
1580 ti.rect = btnPtr->rect;
1581 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
1585 /* btnPtr->nRow is zero based. The space between the rows is */
1586 /* also considered as a row. */
1587 btnPtr->nRow = nRows + nSepRows;
1589 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1590 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1595 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1599 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1600 /* it is the actual width of the separator. This is used for */
1601 /* custom controls in toolbars. */
1602 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1603 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1604 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1608 /* nSepRows is used to calculate the extra height follwoing */
1612 x = infoPtr->nIndent;
1614 /* Increment row number unless this is the last button */
1615 /* and it has Wrap set. */
1616 if (i != infoPtr->nNumButtons-1)
1623 /* infoPtr->nRows is the number of rows on the toolbar */
1624 infoPtr->nRows = nRows + nSepRows + 1;
1627 /********************************************************************
1628 * The following while interesting, does not match the values *
1629 * created above for the button rectangles, nor the rcBound rect. *
1630 * We will comment it out and remove it later. *
1632 * The problem showed up as heights in the pager control that was *
1634 ********************************************************************/
1636 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1638 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1639 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1640 nSepRows * (infoPtr->nBitmapHeight + 1) +
1644 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1646 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1651 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1654 TBUTTON_INFO *btnPtr;
1657 btnPtr = infoPtr->buttons;
1658 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1659 if (btnPtr->fsState & TBSTATE_HIDDEN)
1662 if (btnPtr->fsStyle & BTNS_SEP) {
1663 if (PtInRect (&btnPtr->rect, *lpPt)) {
1664 TRACE(" ON SEPARATOR %d!\n", i);
1669 if (PtInRect (&btnPtr->rect, *lpPt)) {
1670 TRACE(" ON BUTTON %d!\n", i);
1676 TRACE(" NOWHERE!\n");
1677 return TOOLBAR_NOWHERE;
1682 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1684 TBUTTON_INFO *btnPtr;
1687 if (CommandIsIndex) {
1688 TRACE("command is really index command=%d\n", idCommand);
1689 if (idCommand >= infoPtr->nNumButtons) return -1;
1692 btnPtr = infoPtr->buttons;
1693 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1694 if (btnPtr->idCommand == idCommand) {
1695 TRACE("command=%d index=%d\n", idCommand, i);
1699 TRACE("no index found for command=%d\n", idCommand);
1705 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1707 TBUTTON_INFO *btnPtr;
1710 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1713 /* check index button */
1714 btnPtr = &infoPtr->buttons[nIndex];
1715 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1716 if (btnPtr->fsState & TBSTATE_CHECKED)
1720 /* check previous buttons */
1721 nRunIndex = nIndex - 1;
1722 while (nRunIndex >= 0) {
1723 btnPtr = &infoPtr->buttons[nRunIndex];
1724 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1725 if (btnPtr->fsState & TBSTATE_CHECKED)
1733 /* check next buttons */
1734 nRunIndex = nIndex + 1;
1735 while (nRunIndex < infoPtr->nNumButtons) {
1736 btnPtr = &infoPtr->buttons[nRunIndex];
1737 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1738 if (btnPtr->fsState & TBSTATE_CHECKED)
1751 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1752 WPARAM wParam, LPARAM lParam)
1758 msg.wParam = wParam;
1759 msg.lParam = lParam;
1760 msg.time = GetMessageTime ();
1761 msg.pt.x = LOWORD(GetMessagePos ());
1762 msg.pt.y = HIWORD(GetMessagePos ());
1764 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1767 /* keeps available button list box sorted by button id */
1768 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
1772 PCUSTOMBUTTON btnInfo;
1773 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1775 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
1777 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1779 /* position 0 is always separator */
1780 for (i = 1; i < count; i++)
1782 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
1783 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
1785 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
1786 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1790 /* id higher than all others add to end */
1791 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
1792 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
1795 static void TOOLBAR_Cust_MoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
1799 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
1801 if (nIndexFrom == nIndexTo)
1804 /* MSDN states that iItem is the index of the button, rather than the
1805 * command ID as used by every other NMTOOLBAR notification */
1806 nmtb.iItem = nIndexFrom;
1807 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1809 PCUSTOMBUTTON btnInfo;
1811 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1812 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1814 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1816 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1817 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1818 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1819 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1822 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1824 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1826 /* last item is always separator, so -2 instead of -1 */
1827 if (nIndexTo >= (count - 2))
1828 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1830 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1832 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1833 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1835 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1839 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1843 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1845 /* MSDN states that iItem is the index of the button, rather than the
1846 * command ID as used by every other NMTOOLBAR notification */
1847 nmtb.iItem = nIndexAvail;
1848 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1850 PCUSTOMBUTTON btnInfo;
1852 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1853 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1854 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1856 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1858 if (nIndexAvail != 0) /* index == 0 indicates separator */
1860 /* remove from 'available buttons' list */
1861 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1862 if (nIndexAvail == count-1)
1863 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1865 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1869 PCUSTOMBUTTON btnNew;
1871 /* duplicate 'separator' button */
1872 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1873 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1877 /* insert into 'toolbar button' list */
1878 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1879 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1881 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1883 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1887 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1889 PCUSTOMBUTTON btnInfo;
1890 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1892 TRACE("Remove: index %d\n", index);
1894 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
1896 /* send TBN_QUERYDELETE notification */
1897 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
1901 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
1902 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
1904 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1906 /* insert into 'available button' list */
1907 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
1908 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
1912 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1916 /* drag list notification function for toolbar buttons list box */
1917 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1919 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1920 switch (pDLI->uNotification)
1924 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1925 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1926 /* no dragging for last item (separator) */
1927 if (nCurrentItem >= (nCount - 1)) return FALSE;
1932 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1933 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1934 /* no dragging past last item (separator) */
1935 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
1937 DrawInsert(hwnd, hwndList, nCurrentItem);
1938 /* FIXME: native uses "move button" cursor */
1939 return DL_COPYCURSOR;
1942 /* not over toolbar buttons list */
1943 if (nCurrentItem < 0)
1945 POINT ptWindow = pDLI->ptCursor;
1946 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1947 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1948 /* over available buttons list? */
1949 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1950 /* FIXME: native uses "move button" cursor */
1951 return DL_COPYCURSOR;
1953 /* clear drag arrow */
1954 DrawInsert(hwnd, hwndList, -1);
1955 return DL_STOPCURSOR;
1959 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1960 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
1961 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1962 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
1964 /* clear drag arrow */
1965 DrawInsert(hwnd, hwndList, -1);
1967 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
1969 /* not over toolbar buttons list */
1972 POINT ptWindow = pDLI->ptCursor;
1973 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1974 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1975 /* over available buttons list? */
1976 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1977 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
1982 /* Clear drag arrow */
1983 DrawInsert(hwnd, hwndList, -1);
1990 /* drag list notification function for available buttons list box */
1991 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1993 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1994 switch (pDLI->uNotification)
2000 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2001 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2002 /* no dragging past last item (separator) */
2003 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2005 DrawInsert(hwnd, hwndList, nCurrentItem);
2006 /* FIXME: native uses "move button" cursor */
2007 return DL_COPYCURSOR;
2010 /* not over toolbar buttons list */
2011 if (nCurrentItem < 0)
2013 POINT ptWindow = pDLI->ptCursor;
2014 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2015 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2016 /* over available buttons list? */
2017 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2018 /* FIXME: native uses "move button" cursor */
2019 return DL_COPYCURSOR;
2021 /* clear drag arrow */
2022 DrawInsert(hwnd, hwndList, -1);
2023 return DL_STOPCURSOR;
2027 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2028 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2029 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2030 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2032 /* clear drag arrow */
2033 DrawInsert(hwnd, hwndList, -1);
2035 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2039 /* Clear drag arrow */
2040 DrawInsert(hwnd, hwndList, -1);
2046 extern UINT uDragListMessage;
2048 /***********************************************************************
2049 * TOOLBAR_CustomizeDialogProc
2050 * This function implements the toolbar customization dialog.
2052 static INT_PTR CALLBACK
2053 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2055 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2056 PCUSTOMBUTTON btnInfo;
2058 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2063 custInfo = (PCUSTDLG_INFO)lParam;
2064 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2072 infoPtr = custInfo->tbInfo;
2074 /* send TBN_QUERYINSERT notification */
2075 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2077 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
2080 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2081 nmtb.iItem = (int)hwnd;
2082 /* Send TBN_INITCUSTOMIZE notification */
2083 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2086 TRACE("TBNRF_HIDEHELP requested\n");
2087 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2090 /* add items to 'toolbar buttons' list and check if removable */
2091 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2093 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2094 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2095 btnInfo->btn.fsStyle = BTNS_SEP;
2096 btnInfo->bVirtual = FALSE;
2097 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2099 /* send TBN_QUERYDELETE notification */
2100 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2102 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2103 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2106 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2108 /* insert separator button into 'available buttons' list */
2109 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2110 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2111 btnInfo->btn.fsStyle = BTNS_SEP;
2112 btnInfo->bVirtual = FALSE;
2113 btnInfo->bRemovable = TRUE;
2114 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2115 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2116 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2118 /* insert all buttons into dsa */
2121 /* send TBN_GETBUTTONINFO notification */
2124 nmtb.pszText = Buffer;
2127 /* Clear previous button's text */
2128 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2130 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2133 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2134 nmtb.tbButton.fsStyle, i,
2135 nmtb.tbButton.idCommand,
2136 nmtb.tbButton.iString,
2137 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2140 /* insert button into the apropriate list */
2141 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2144 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2145 btnInfo->bVirtual = FALSE;
2146 btnInfo->bRemovable = TRUE;
2150 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2151 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2154 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2155 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2157 if (lstrlenW(nmtb.pszText))
2158 lstrcpyW(btnInfo->text, nmtb.pszText);
2159 else if (nmtb.tbButton.iString >= 0 &&
2160 nmtb.tbButton.iString < infoPtr->nNumStrings)
2162 lstrcpyW(btnInfo->text,
2163 infoPtr->strings[nmtb.tbButton.iString]);
2168 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2171 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2173 /* select first item in the 'available' list */
2174 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2176 /* append 'virtual' separator button to the 'toolbar buttons' list */
2177 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2178 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2179 btnInfo->btn.fsStyle = BTNS_SEP;
2180 btnInfo->bVirtual = TRUE;
2181 btnInfo->bRemovable = FALSE;
2182 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2183 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2184 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2186 /* select last item in the 'toolbar' list */
2187 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2188 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2190 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2191 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2193 /* set focus and disable buttons */
2194 PostMessageW (hwnd, WM_USER, 0, 0);
2199 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2200 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2201 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2202 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2206 EndDialog(hwnd, FALSE);
2210 switch (LOWORD(wParam))
2212 case IDC_TOOLBARBTN_LBOX:
2213 if (HIWORD(wParam) == LBN_SELCHANGE)
2215 PCUSTOMBUTTON btnInfo;
2220 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2221 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2223 /* send TBN_QUERYINSERT notification */
2225 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2228 /* get list box item */
2229 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2231 if (index == (count - 1))
2233 /* last item (virtual separator) */
2234 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2235 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2237 else if (index == (count - 2))
2239 /* second last item (last non-virtual item) */
2240 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2241 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2243 else if (index == 0)
2246 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2247 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2251 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2252 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2255 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2259 case IDC_MOVEUP_BTN:
2261 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2262 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2266 case IDC_MOVEDN_BTN: /* move down */
2268 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2269 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2273 case IDC_REMOVE_BTN: /* remove button */
2275 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2277 if (LB_ERR == index)
2280 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2284 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2287 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2290 case IDOK: /* Add button */
2295 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2296 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2298 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2303 EndDialog(hwnd, FALSE);
2313 /* delete items from 'toolbar buttons' listbox*/
2314 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2315 for (i = 0; i < count; i++)
2317 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2321 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2324 /* delete items from 'available buttons' listbox*/
2325 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2326 for (i = 0; i < count; i++)
2328 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2330 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2332 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2337 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2339 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2344 COLORREF oldText = 0;
2348 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2349 if (btnInfo == NULL)
2351 FIXME("btnInfo invalid!\n");
2355 /* set colors and select objects */
2356 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2357 if (btnInfo->bVirtual)
2358 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2360 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2361 hPen = CreatePen( PS_SOLID, 1,
2362 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2363 hOldPen = SelectObject (lpdis->hDC, hPen );
2364 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2366 /* fill background rectangle */
2367 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2368 lpdis->rcItem.right, lpdis->rcItem.bottom);
2370 /* calculate button and text rectangles */
2371 CopyRect (&rcButton, &lpdis->rcItem);
2372 InflateRect (&rcButton, -1, -1);
2373 CopyRect (&rcText, &rcButton);
2374 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2375 rcText.left = rcButton.right + 2;
2377 /* draw focus rectangle */
2378 if (lpdis->itemState & ODS_FOCUS)
2379 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2382 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2383 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2385 /* draw image and text */
2386 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2387 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2388 btnInfo->btn.iBitmap));
2389 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2390 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2392 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2393 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2395 /* delete objects and reset colors */
2396 SelectObject (lpdis->hDC, hOldBrush);
2397 SelectObject (lpdis->hDC, hOldPen);
2398 SetBkColor (lpdis->hDC, oldBk);
2399 SetTextColor (lpdis->hDC, oldText);
2400 DeleteObject( hPen );
2405 case WM_MEASUREITEM:
2406 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2408 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2410 lpmis->itemHeight = 15 + 8; /* default height */
2417 if (uDragListMessage && (uMsg == uDragListMessage))
2419 if (wParam == IDC_TOOLBARBTN_LBOX)
2421 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2422 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2423 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2426 else if (wParam == IDC_AVAILBTN_LBOX)
2428 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2429 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2430 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2439 /***********************************************************************
2440 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2444 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2446 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2447 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2448 INT nIndex = 0, nButtons, nCount;
2452 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2456 if (lpAddBmp->hInst == HINST_COMMCTRL)
2458 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2460 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2462 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2467 TRACE ("adding %d internal bitmaps!\n", nButtons);
2469 /* Windows resize all the buttons to the size of a newly added standard image */
2470 if (lpAddBmp->nID & 1)
2473 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2474 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2476 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2477 MAKELPARAM((WORD)24, (WORD)24));
2478 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2479 MAKELPARAM((WORD)31, (WORD)30));
2484 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2485 MAKELPARAM((WORD)16, (WORD)16));
2486 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2487 MAKELPARAM((WORD)22, (WORD)22));
2490 TOOLBAR_CalcToolbar (hwnd);
2494 nButtons = (INT)wParam;
2498 TRACE ("adding %d bitmaps!\n", nButtons);
2501 if (!infoPtr->cimlDef) {
2502 /* create new default image list */
2503 TRACE ("creating default image list!\n");
2505 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2506 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2507 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2508 infoPtr->himlInt = himlDef;
2511 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2515 WARN("No default image list available\n");
2519 nCount = ImageList_GetImageCount(himlDef);
2521 /* Add bitmaps to the default image list */
2522 if (lpAddBmp->hInst == NULL)
2525 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2526 HDC hdcImage, hdcBitmap;
2528 /* copy the bitmap before adding it so that the user's bitmap
2529 * doesn't get modified.
2531 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2533 hdcImage = CreateCompatibleDC(0);
2534 hdcBitmap = CreateCompatibleDC(0);
2536 /* create new bitmap */
2537 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2538 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2539 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2541 /* Copy the user's image */
2542 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2543 hdcBitmap, 0, 0, SRCCOPY);
2545 SelectObject (hdcImage, hOldBitmapLoad);
2546 SelectObject (hdcBitmap, hOldBitmapBitmap);
2547 DeleteDC (hdcImage);
2548 DeleteDC (hdcBitmap);
2550 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2551 DeleteObject (hbmLoad);
2553 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2555 /* Add system bitmaps */
2556 switch (lpAddBmp->nID)
2558 case IDB_STD_SMALL_COLOR:
2559 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2560 MAKEINTRESOURCEA(IDB_STD_SMALL));
2561 nIndex = ImageList_AddMasked (himlDef,
2562 hbmLoad, comctl32_color.clrBtnFace);
2563 DeleteObject (hbmLoad);
2566 case IDB_STD_LARGE_COLOR:
2567 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2568 MAKEINTRESOURCEA(IDB_STD_LARGE));
2569 nIndex = ImageList_AddMasked (himlDef,
2570 hbmLoad, comctl32_color.clrBtnFace);
2571 DeleteObject (hbmLoad);
2574 case IDB_VIEW_SMALL_COLOR:
2575 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2576 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2577 nIndex = ImageList_AddMasked (himlDef,
2578 hbmLoad, comctl32_color.clrBtnFace);
2579 DeleteObject (hbmLoad);
2582 case IDB_VIEW_LARGE_COLOR:
2583 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2584 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2585 nIndex = ImageList_AddMasked (himlDef,
2586 hbmLoad, comctl32_color.clrBtnFace);
2587 DeleteObject (hbmLoad);
2590 case IDB_HIST_SMALL_COLOR:
2591 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2592 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2593 nIndex = ImageList_AddMasked (himlDef,
2594 hbmLoad, comctl32_color.clrBtnFace);
2595 DeleteObject (hbmLoad);
2598 case IDB_HIST_LARGE_COLOR:
2599 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2600 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2601 nIndex = ImageList_AddMasked (himlDef,
2602 hbmLoad, comctl32_color.clrBtnFace);
2603 DeleteObject (hbmLoad);
2607 nIndex = ImageList_GetImageCount (himlDef);
2608 ERR ("invalid imagelist!\n");
2614 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2615 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2616 DeleteObject (hbmLoad);
2619 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2621 if (infoPtr->nNumBitmapInfos == 0)
2623 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2627 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2628 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2629 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2632 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2633 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2634 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2636 infoPtr->nNumBitmapInfos++;
2637 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2641 INT imagecount = ImageList_GetImageCount(himlDef);
2643 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2645 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",
2646 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2647 infoPtr->nNumBitmaps+nButtons,imagecount);
2649 infoPtr->nNumBitmaps = imagecount;
2652 infoPtr->nNumBitmaps += nButtons;
2655 InvalidateRect(hwnd, NULL, TRUE);
2662 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2665 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2666 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2668 TRACE("adding %d buttons!\n", wParam);
2670 nAddButtons = (UINT)wParam;
2671 nOldButtons = infoPtr->nNumButtons;
2672 nNewButtons = nOldButtons + nAddButtons;
2674 if (infoPtr->nNumButtons == 0) {
2676 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2679 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2681 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2682 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2683 nOldButtons * sizeof(TBUTTON_INFO));
2687 infoPtr->nNumButtons = nNewButtons;
2689 /* insert new button data */
2690 for (nCount = 0; nCount < nAddButtons; nCount++) {
2691 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2692 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2693 btnPtr->idCommand = lpTbb[nCount].idCommand;
2694 btnPtr->fsState = lpTbb[nCount].fsState;
2695 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2696 btnPtr->dwData = lpTbb[nCount].dwData;
2697 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2698 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2700 btnPtr->iString = lpTbb[nCount].iString;
2701 btnPtr->bHot = FALSE;
2703 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2706 ZeroMemory (&ti, sizeof(ti));
2707 ti.cbSize = sizeof(ti);
2709 ti.uId = btnPtr->idCommand;
2711 ti.lpszText = LPSTR_TEXTCALLBACKW;
2713 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2718 TOOLBAR_CalcToolbar (hwnd);
2720 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2722 InvalidateRect(hwnd, NULL, TRUE);
2729 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2733 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2735 TRACE("adding %d buttons!\n", wParam);
2737 nAddButtons = (UINT)wParam;
2738 nOldButtons = infoPtr->nNumButtons;
2739 nNewButtons = nOldButtons + nAddButtons;
2741 if (infoPtr->nNumButtons == 0) {
2743 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2746 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2748 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2749 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2750 nOldButtons * sizeof(TBUTTON_INFO));
2754 infoPtr->nNumButtons = nNewButtons;
2756 /* insert new button data */
2757 for (nCount = 0; nCount < nAddButtons; nCount++) {
2758 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2759 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2760 btnPtr->idCommand = lpTbb[nCount].idCommand;
2761 btnPtr->fsState = lpTbb[nCount].fsState;
2762 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2763 btnPtr->dwData = lpTbb[nCount].dwData;
2764 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2765 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2767 btnPtr->iString = lpTbb[nCount].iString;
2768 btnPtr->bHot = FALSE;
2770 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2773 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2774 ti.cbSize = sizeof (TTTOOLINFOW);
2776 ti.uId = btnPtr->idCommand;
2778 ti.lpszText = LPSTR_TEXTCALLBACKW;
2781 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2786 TOOLBAR_CalcToolbar (hwnd);
2788 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2790 InvalidateRect(hwnd, NULL, TRUE);
2797 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2802 if ((wParam) && (HIWORD(lParam) == 0)) {
2805 TRACE("adding string from resource!\n");
2807 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2810 TRACE("len=%d \"%s\"\n", len, szString);
2811 nIndex = infoPtr->nNumStrings;
2812 if (infoPtr->nNumStrings == 0) {
2814 Alloc (sizeof(LPWSTR));
2817 LPWSTR *oldStrings = infoPtr->strings;
2819 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2820 memcpy (&infoPtr->strings[0], &oldStrings[0],
2821 sizeof(LPWSTR) * infoPtr->nNumStrings);
2825 /*Alloc zeros out the allocated memory*/
2826 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2827 infoPtr->nNumStrings++;
2830 LPSTR p = (LPSTR)lParam;
2835 TRACE("adding string(s) from array!\n");
2837 nIndex = infoPtr->nNumStrings;
2840 TRACE("len=%d \"%s\"\n", len, p);
2842 if (infoPtr->nNumStrings == 0) {
2844 Alloc (sizeof(LPWSTR));
2847 LPWSTR *oldStrings = infoPtr->strings;
2849 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2850 memcpy (&infoPtr->strings[0], &oldStrings[0],
2851 sizeof(LPWSTR) * infoPtr->nNumStrings);
2855 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2856 infoPtr->nNumStrings++;
2867 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2869 #define MAX_RESOURCE_STRING_LENGTH 512
2870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2873 if ((wParam) && (HIWORD(lParam) == 0)) {
2874 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2876 TRACE("adding string from resource!\n");
2878 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2879 szString, MAX_RESOURCE_STRING_LENGTH);
2881 TRACE("len=%d %s\n", len, debugstr_w(szString));
2882 TRACE("First char: 0x%x\n", *szString);
2883 if (szString[0] == L'|')
2885 PWSTR p = szString + 1;
2887 nIndex = infoPtr->nNumStrings;
2888 while (*p != L'|' && *p != L'\0') {
2891 if (infoPtr->nNumStrings == 0) {
2892 infoPtr->strings = Alloc (sizeof(LPWSTR));
2896 LPWSTR *oldStrings = infoPtr->strings;
2897 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2898 memcpy(&infoPtr->strings[0], &oldStrings[0],
2899 sizeof(LPWSTR) * infoPtr->nNumStrings);
2903 np=strchrW (p, '|');
2911 TRACE("len=%d %s\n", len, debugstr_w(p));
2912 infoPtr->strings[infoPtr->nNumStrings] =
2913 Alloc (sizeof(WCHAR)*(len+1));
2914 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2915 infoPtr->nNumStrings++;
2922 nIndex = infoPtr->nNumStrings;
2923 if (infoPtr->nNumStrings == 0) {
2925 Alloc (sizeof(LPWSTR));
2928 LPWSTR *oldStrings = infoPtr->strings;
2930 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2931 memcpy (&infoPtr->strings[0], &oldStrings[0],
2932 sizeof(LPWSTR) * infoPtr->nNumStrings);
2936 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2937 infoPtr->nNumStrings++;
2941 LPWSTR p = (LPWSTR)lParam;
2946 TRACE("adding string(s) from array!\n");
2947 nIndex = infoPtr->nNumStrings;
2951 TRACE("len=%d %s\n", len, debugstr_w(p));
2952 if (infoPtr->nNumStrings == 0) {
2954 Alloc (sizeof(LPWSTR));
2957 LPWSTR *oldStrings = infoPtr->strings;
2959 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2960 memcpy (&infoPtr->strings[0], &oldStrings[0],
2961 sizeof(LPWSTR) * infoPtr->nNumStrings);
2965 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2966 infoPtr->nNumStrings++;
2977 TOOLBAR_AutoSize (HWND hwnd)
2979 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2985 UINT uPosFlags = SWP_NOZORDER;
2987 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2989 parent = GetParent (hwnd);
2990 GetClientRect(parent, &parent_rect);
2992 x = parent_rect.left;
2993 y = parent_rect.top;
2995 /* FIXME: we should be able to early out if nothing */
2996 /* has changed with nWidth != parent_rect width */
2998 if (infoPtr->dwStyle & CCS_NORESIZE) {
2999 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3002 TOOLBAR_CalcToolbar (hwnd);
3005 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3006 TOOLBAR_CalcToolbar (hwnd);
3007 InvalidateRect( hwnd, NULL, TRUE );
3008 cy = infoPtr->nHeight;
3009 cx = infoPtr->nWidth;
3011 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3012 GetWindowRect(hwnd, &window_rect);
3013 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3014 y = window_rect.top;
3016 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3017 GetWindowRect(hwnd, &window_rect);
3018 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3022 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3023 uPosFlags |= SWP_NOMOVE;
3025 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3026 cy += GetSystemMetrics(SM_CYEDGE);
3028 if (infoPtr->dwStyle & WS_BORDER)
3031 cy += GetSystemMetrics(SM_CYEDGE);
3032 cx += GetSystemMetrics(SM_CYEDGE);
3035 infoPtr->bAutoSize = TRUE;
3036 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3037 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3038 * after the setwindowpos calls */
3039 infoPtr->bAutoSize = FALSE;
3046 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3050 return infoPtr->nNumButtons;
3055 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3057 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3059 if (infoPtr == NULL) {
3060 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
3061 ERR("infoPtr == NULL!\n");
3065 infoPtr->dwStructSize = (DWORD)wParam;
3072 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3075 TBUTTON_INFO *btnPtr;
3078 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3080 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3084 btnPtr = &infoPtr->buttons[nIndex];
3085 btnPtr->iBitmap = LOWORD(lParam);
3087 /* we HAVE to erase the background, the new bitmap could be */
3089 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3096 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3099 TBUTTON_INFO *btnPtr;
3102 BOOL bChecked = FALSE;
3104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3106 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3111 btnPtr = &infoPtr->buttons[nIndex];
3113 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3115 if (LOWORD(lParam) == FALSE)
3116 btnPtr->fsState &= ~TBSTATE_CHECKED;
3118 if (btnPtr->fsStyle & BTNS_GROUP) {
3120 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3121 if (nOldIndex == nIndex)
3123 if (nOldIndex != -1)
3124 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3126 btnPtr->fsState |= TBSTATE_CHECKED;
3129 if( bChecked != LOWORD(lParam) )
3131 if (nOldIndex != -1)
3132 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3133 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3136 /* FIXME: Send a WM_NOTIFY?? */
3143 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3145 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3147 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3152 TOOLBAR_Customize (HWND hwnd)
3154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3155 CUSTDLG_INFO custInfo;
3161 custInfo.tbInfo = infoPtr;
3162 custInfo.tbHwnd = hwnd;
3164 /* send TBN_BEGINADJUST notification */
3165 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3168 if (!(hRes = FindResourceW (COMCTL32_hModule,
3169 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3170 (LPWSTR)RT_DIALOG)))
3173 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3176 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3177 (LPDLGTEMPLATEW)template,
3179 TOOLBAR_CustomizeDialogProc,
3182 /* send TBN_ENDADJUST notification */
3183 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3191 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3194 INT nIndex = (INT)wParam;
3196 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3198 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3201 memset(&nmtb, 0, sizeof(nmtb));
3202 nmtb.iItem = btnPtr->idCommand;
3203 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3204 nmtb.tbButton.idCommand = btnPtr->idCommand;
3205 nmtb.tbButton.fsState = btnPtr->fsState;
3206 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3207 nmtb.tbButton.dwData = btnPtr->dwData;
3208 nmtb.tbButton.iString = btnPtr->iString;
3209 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3211 if ((infoPtr->hwndToolTip) &&
3212 !(btnPtr->fsStyle & BTNS_SEP)) {
3215 ZeroMemory (&ti, sizeof(ti));
3216 ti.cbSize = sizeof(ti);
3218 ti.uId = infoPtr->buttons[nIndex].idCommand;
3220 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3223 if (infoPtr->nNumButtons == 1) {
3224 TRACE(" simple delete!\n");
3225 Free (infoPtr->buttons);
3226 infoPtr->buttons = NULL;
3227 infoPtr->nNumButtons = 0;
3230 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3231 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3233 infoPtr->nNumButtons--;
3234 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3236 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3237 nIndex * sizeof(TBUTTON_INFO));
3240 if (nIndex < infoPtr->nNumButtons) {
3241 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3242 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3248 TOOLBAR_CalcToolbar (hwnd);
3250 InvalidateRect (hwnd, NULL, TRUE);
3257 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3260 TBUTTON_INFO *btnPtr;
3264 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3266 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3271 btnPtr = &infoPtr->buttons[nIndex];
3273 bState = btnPtr->fsState & TBSTATE_ENABLED;
3275 /* update the toolbar button state */
3276 if(LOWORD(lParam) == FALSE) {
3277 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3279 btnPtr->fsState |= TBSTATE_ENABLED;
3282 /* redraw the button only if the state of the button changed */
3283 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3284 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3290 static inline LRESULT
3291 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3295 return infoPtr->bAnchor;
3300 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3309 return infoPtr->buttons[nIndex].iBitmap;
3313 static inline LRESULT
3314 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3321 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3324 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3325 INT nIndex = (INT)wParam;
3326 TBUTTON_INFO *btnPtr;
3328 if (infoPtr == NULL)
3334 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3337 btnPtr = &infoPtr->buttons[nIndex];
3338 lpTbb->iBitmap = btnPtr->iBitmap;
3339 lpTbb->idCommand = btnPtr->idCommand;
3340 lpTbb->fsState = btnPtr->fsState;
3341 lpTbb->fsStyle = btnPtr->fsStyle;
3342 lpTbb->bReserved[0] = 0;
3343 lpTbb->bReserved[1] = 0;
3344 lpTbb->dwData = btnPtr->dwData;
3345 lpTbb->iString = btnPtr->iString;
3352 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3355 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3356 TBUTTON_INFO *btnPtr;
3359 if (infoPtr == NULL)
3361 if (lpTbInfo == NULL)
3363 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3366 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3367 lpTbInfo->dwMask & 0x80000000);
3371 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3373 if (lpTbInfo->dwMask & TBIF_COMMAND)
3374 lpTbInfo->idCommand = btnPtr->idCommand;
3375 if (lpTbInfo->dwMask & TBIF_IMAGE)
3376 lpTbInfo->iImage = btnPtr->iBitmap;
3377 if (lpTbInfo->dwMask & TBIF_LPARAM)
3378 lpTbInfo->lParam = btnPtr->dwData;
3379 if (lpTbInfo->dwMask & TBIF_SIZE)
3380 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3381 if (lpTbInfo->dwMask & TBIF_STATE)
3382 lpTbInfo->fsState = btnPtr->fsState;
3383 if (lpTbInfo->dwMask & TBIF_STYLE)
3384 lpTbInfo->fsStyle = btnPtr->fsStyle;
3385 if (lpTbInfo->dwMask & TBIF_TEXT) {
3386 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3387 can't use TOOLBAR_GetText here */
3389 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3390 lpText = (LPWSTR)btnPtr->iString;
3391 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3393 lpTbInfo->pszText[0] = '\0';
3400 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3402 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3403 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3404 TBUTTON_INFO *btnPtr;
3407 if (infoPtr == NULL)
3409 if (lpTbInfo == NULL)
3411 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3414 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3415 lpTbInfo->dwMask & 0x80000000);
3419 btnPtr = &infoPtr->buttons[nIndex];
3424 if (lpTbInfo->dwMask & TBIF_COMMAND)
3425 lpTbInfo->idCommand = btnPtr->idCommand;
3426 if (lpTbInfo->dwMask & TBIF_IMAGE)
3427 lpTbInfo->iImage = btnPtr->iBitmap;
3428 if (lpTbInfo->dwMask & TBIF_LPARAM)
3429 lpTbInfo->lParam = btnPtr->dwData;
3430 if (lpTbInfo->dwMask & TBIF_SIZE)
3431 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3432 if (lpTbInfo->dwMask & TBIF_STATE)
3433 lpTbInfo->fsState = btnPtr->fsState;
3434 if (lpTbInfo->dwMask & TBIF_STYLE)
3435 lpTbInfo->fsStyle = btnPtr->fsStyle;
3436 if (lpTbInfo->dwMask & TBIF_TEXT) {
3437 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3438 can't use TOOLBAR_GetText here */
3440 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3441 lpText = (LPWSTR)btnPtr->iString;
3442 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3444 lpTbInfo->pszText[0] = '\0';
3452 TOOLBAR_GetButtonSize (HWND hwnd)
3454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3456 if (infoPtr->nNumButtons > 0)
3457 return MAKELONG((WORD)infoPtr->nButtonWidth,
3458 (WORD)infoPtr->nButtonHeight);
3460 return MAKELONG(8,7);
3465 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3478 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3480 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3481 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3486 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3488 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3493 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3497 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3501 ret = strlenW (lpText);
3504 strcpyW ((LPWSTR)lParam, lpText);
3512 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3514 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3515 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3516 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3520 inline static LRESULT
3521 TOOLBAR_GetExtendedStyle (HWND hwnd)
3523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3527 return infoPtr->dwExStyle;
3532 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3534 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3535 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3536 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3541 TOOLBAR_GetHotItem (HWND hwnd)
3543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3545 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3548 if (infoPtr->nHotItem < 0)
3551 return (LRESULT)infoPtr->nHotItem;
3556 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3558 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3559 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3560 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3565 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3568 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3570 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3572 *lptbim = infoPtr->tbim;
3579 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3583 TRACE("hwnd = %p\n", hwnd);
3585 return (LRESULT)infoPtr->clrInsertMark;
3590 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 TBUTTON_INFO *btnPtr;
3597 if (infoPtr == NULL)
3599 nIndex = (INT)wParam;
3600 btnPtr = &infoPtr->buttons[nIndex];
3601 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3603 lpRect = (LPRECT)lParam;
3606 if (btnPtr->fsState & TBSTATE_HIDDEN)
3609 lpRect->left = btnPtr->rect.left;
3610 lpRect->right = btnPtr->rect.right;
3611 lpRect->bottom = btnPtr->rect.bottom;
3612 lpRect->top = btnPtr->rect.top;
3619 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3621 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3622 LPSIZE lpSize = (LPSIZE)lParam;
3627 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3628 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3630 TRACE("maximum size %ld x %ld\n",
3631 infoPtr->rcBound.right - infoPtr->rcBound.left,
3632 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3638 /* << TOOLBAR_GetObject >> */
3642 TOOLBAR_GetPadding (HWND hwnd)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3647 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3648 return (LRESULT) oldPad;
3653 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3656 TBUTTON_INFO *btnPtr;
3660 if (infoPtr == NULL)
3662 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3663 btnPtr = &infoPtr->buttons[nIndex];
3664 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3666 lpRect = (LPRECT)lParam;
3670 lpRect->left = btnPtr->rect.left;
3671 lpRect->right = btnPtr->rect.right;
3672 lpRect->bottom = btnPtr->rect.bottom;
3673 lpRect->top = btnPtr->rect.top;
3680 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3685 return infoPtr->nRows;
3692 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3697 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3701 return infoPtr->buttons[nIndex].fsState;
3706 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 return GetWindowLongW(hwnd, GWL_STYLE);
3713 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3717 if (infoPtr == NULL)
3720 return infoPtr->nMaxTextRows;
3725 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3729 if (infoPtr == NULL)
3731 return (LRESULT)infoPtr->hwndToolTip;
3736 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3740 TRACE("%s hwnd=%p\n",
3741 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3743 return infoPtr->bUnicode;
3747 inline static LRESULT
3748 TOOLBAR_GetVersion (HWND hwnd)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3751 return infoPtr->iVersion;
3756 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3759 TBUTTON_INFO *btnPtr;
3764 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3768 btnPtr = &infoPtr->buttons[nIndex];
3769 if (LOWORD(lParam) == FALSE)
3770 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3772 btnPtr->fsState |= TBSTATE_HIDDEN;
3774 TOOLBAR_CalcToolbar (hwnd);
3776 InvalidateRect (hwnd, NULL, TRUE);
3782 inline static LRESULT
3783 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3785 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3790 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3792 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3793 TBUTTON_INFO *btnPtr;
3797 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3801 btnPtr = &infoPtr->buttons[nIndex];
3802 oldState = btnPtr->fsState;
3803 if (LOWORD(lParam) == FALSE)
3804 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3806 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3808 if(oldState != btnPtr->fsState)
3809 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3816 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3819 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3820 INT nIndex = (INT)wParam;
3821 TBUTTON_INFO *oldButtons;
3826 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3829 /* EPP: this seems to be an undocumented call (from my IE4)
3830 * I assume in that case that:
3831 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3832 * - index of insertion is at the end of existing buttons
3833 * I only see this happen with nIndex == -1, but it could have a special
3834 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3836 nIndex = infoPtr->nNumButtons;
3838 } else if (nIndex < 0)
3841 /* If the string passed is not an index, assume address of string
3842 and do our own AddString */
3843 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3847 TRACE("string %s passed instead of index, adding string\n",
3848 debugstr_a((LPSTR)lpTbb->iString));
3849 len = strlen((LPSTR)lpTbb->iString) + 2;
3851 strcpy(ptr, (LPSTR)lpTbb->iString);
3852 ptr[len - 1] = 0; /* ended by two '\0' */
3853 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3857 TRACE("inserting button index=%d\n", nIndex);
3858 if (nIndex > infoPtr->nNumButtons) {
3859 nIndex = infoPtr->nNumButtons;
3860 TRACE("adjust index=%d\n", nIndex);
3863 oldButtons = infoPtr->buttons;
3864 infoPtr->nNumButtons++;
3865 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3866 /* pre insert copy */
3868 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3869 nIndex * sizeof(TBUTTON_INFO));
3872 /* insert new button */
3873 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3874 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3875 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3876 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3877 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3878 /* if passed string and not index, then add string */
3879 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3880 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3883 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3885 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3888 ZeroMemory (&ti, sizeof(ti));
3889 ti.cbSize = sizeof (ti);
3891 ti.uId = lpTbb->idCommand;
3893 ti.lpszText = LPSTR_TEXTCALLBACKW;
3895 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3899 /* post insert copy */
3900 if (nIndex < infoPtr->nNumButtons - 1) {
3901 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3902 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3907 TOOLBAR_CalcToolbar (hwnd);
3909 InvalidateRect (hwnd, NULL, TRUE);
3916 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3919 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3920 INT nIndex = (INT)wParam;
3921 TBUTTON_INFO *oldButtons;
3926 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3929 /* EPP: this seems to be an undocumented call (from my IE4)
3930 * I assume in that case that:
3931 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3932 * - index of insertion is at the end of existing buttons
3933 * I only see this happen with nIndex == -1, but it could have a special
3934 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3936 nIndex = infoPtr->nNumButtons;
3938 } else if (nIndex < 0)
3941 /* If the string passed is not an index, assume address of string
3942 and do our own AddString */
3943 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3947 TRACE("string %s passed instead of index, adding string\n",
3948 debugstr_w((LPWSTR)lpTbb->iString));
3949 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3950 ptr = Alloc(len*sizeof(WCHAR));
3951 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3952 ptr[len - 1] = 0; /* ended by two '\0' */
3953 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3957 TRACE("inserting button index=%d\n", nIndex);
3958 if (nIndex > infoPtr->nNumButtons) {
3959 nIndex = infoPtr->nNumButtons;
3960 TRACE("adjust index=%d\n", nIndex);
3963 oldButtons = infoPtr->buttons;
3964 infoPtr->nNumButtons++;
3965 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3966 /* pre insert copy */
3968 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3969 nIndex * sizeof(TBUTTON_INFO));
3972 /* insert new button */
3973 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3974 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3975 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3976 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3977 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3978 /* if passed string and not index, then add string */
3979 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3980 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3983 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3985 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3988 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3989 ti.cbSize = sizeof (TTTOOLINFOW);
3991 ti.uId = lpTbb->idCommand;
3993 ti.lpszText = LPSTR_TEXTCALLBACKW;
3995 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3999 /* post insert copy */
4000 if (nIndex < infoPtr->nNumButtons - 1) {
4001 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
4002 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
4007 TOOLBAR_CalcToolbar (hwnd);
4009 InvalidateRect (hwnd, NULL, TRUE);
4015 /* << TOOLBAR_InsertMarkHitTest >> */
4019 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4024 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4028 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4033 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4038 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4042 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4047 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4052 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4056 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4061 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4063 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4066 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4070 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4075 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4080 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4084 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4089 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4094 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4098 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4103 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4106 tbab.hInst = (HINSTANCE)lParam;
4107 tbab.nID = (UINT_PTR)wParam;
4109 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4111 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4116 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4119 WCHAR wAccel = (WCHAR)wParam;
4120 UINT* pIDButton = (UINT*)lParam;
4121 WCHAR wszAccel[] = {'&',wAccel,0};
4124 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4125 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4127 for (i = 0; i < infoPtr->nNumButtons; i++)
4129 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4130 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4131 !(btnPtr->fsState & TBSTATE_HIDDEN))
4133 int iLen = strlenW(wszAccel);
4134 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4141 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4146 if (!strncmpiW(lpszStr, wszAccel, iLen))
4148 *pIDButton = btnPtr->idCommand;
4160 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4165 TBUTTON_INFO *btnPtr;
4167 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4169 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4173 btnPtr = &infoPtr->buttons[nIndex];
4174 oldState = btnPtr->fsState;
4177 btnPtr->fsState |= TBSTATE_MARKED;
4179 btnPtr->fsState &= ~TBSTATE_MARKED;
4181 if(oldState != btnPtr->fsState)
4182 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4188 /* fixes up an index of a button affected by a move */
4189 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4193 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4195 else if (*pIndex == nIndex)
4196 *pIndex = nMoveIndex;
4200 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4202 else if (*pIndex == nIndex)
4203 *pIndex = nMoveIndex;
4209 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4214 INT nMoveIndex = (INT)lParam;
4215 TBUTTON_INFO button;
4217 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4219 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4220 if ((nIndex == -1) || (nMoveIndex < 0))
4223 if (nMoveIndex > infoPtr->nNumButtons - 1)
4224 nMoveIndex = infoPtr->nNumButtons - 1;
4226 button = infoPtr->buttons[nIndex];
4228 /* move button right */
4229 if (nIndex < nMoveIndex)
4231 nCount = nMoveIndex - nIndex;
4232 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4233 infoPtr->buttons[nMoveIndex] = button;
4235 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4236 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4237 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4238 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4240 else if (nIndex > nMoveIndex) /* move button left */
4242 nCount = nIndex - nMoveIndex;
4243 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4244 infoPtr->buttons[nMoveIndex] = button;
4246 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4247 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4248 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4249 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4252 TOOLBAR_CalcToolbar(hwnd);
4253 InvalidateRect(hwnd, NULL, TRUE);
4260 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4263 TBUTTON_INFO *btnPtr;
4267 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4271 btnPtr = &infoPtr->buttons[nIndex];
4272 oldState = btnPtr->fsState;
4273 if (LOWORD(lParam) == FALSE)
4274 btnPtr->fsState &= ~TBSTATE_PRESSED;
4276 btnPtr->fsState |= TBSTATE_PRESSED;
4278 if(oldState != btnPtr->fsState)
4279 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4284 /* FIXME: there might still be some confusion her between number of buttons
4285 * and number of bitmaps */
4287 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4290 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4292 int i = 0, nOldButtons = 0, pos = 0;
4293 int nOldBitmaps, nNewBitmaps;
4294 HIMAGELIST himlDef = 0;
4296 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4297 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4298 lpReplace->nButtons);
4300 if (lpReplace->hInstOld == HINST_COMMCTRL)
4302 FIXME("changing standard bitmaps not implemented\n");
4305 else if (lpReplace->hInstOld != 0)
4307 FIXME("resources not in the current module not implemented\n");
4312 hBitmap = (HBITMAP) lpReplace->nIDNew;
4315 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4316 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4317 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4318 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4319 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4321 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4322 nOldButtons = tbi->nButtons;
4323 tbi->nButtons = lpReplace->nButtons;
4324 tbi->hInst = lpReplace->hInstNew;
4325 tbi->nID = lpReplace->nIDNew;
4326 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4329 pos += tbi->nButtons;
4332 if (nOldButtons == 0)
4334 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4338 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4339 nOldBitmaps = ImageList_GetImageCount(himlDef);
4341 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4343 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4344 ImageList_Remove(himlDef, i);
4348 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4349 HDC hdcImage, hdcBitmap;
4351 /* copy the bitmap before adding it so that the user's bitmap
4352 * doesn't get modified.
4354 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4356 hdcImage = CreateCompatibleDC(0);
4357 hdcBitmap = CreateCompatibleDC(0);
4359 /* create new bitmap */
4360 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4361 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4362 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4364 /* Copy the user's image */
4365 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4366 hdcBitmap, 0, 0, SRCCOPY);
4368 SelectObject (hdcImage, hOldBitmapLoad);
4369 SelectObject (hdcBitmap, hOldBitmapBitmap);
4370 DeleteDC (hdcImage);
4371 DeleteDC (hdcBitmap);
4373 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4374 nNewBitmaps = ImageList_GetImageCount(himlDef);
4375 DeleteObject (hbmLoad);
4378 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4380 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4381 pos, nOldBitmaps, nNewBitmaps);
4383 InvalidateRect(hwnd, NULL, TRUE);
4389 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4393 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4395 if (lpSave == NULL) return 0;
4398 /* save toolbar information */
4399 FIXME("save to \"%s\" \"%s\"\n",
4400 lpSave->pszSubKey, lpSave->pszValueName);
4405 /* restore toolbar information */
4407 FIXME("restore from \"%s\" \"%s\"\n",
4408 lpSave->pszSubKey, lpSave->pszValueName);
4419 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4423 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4429 /* save toolbar information */
4430 FIXME("save to \"%s\" \"%s\"\n",
4431 lpSave->pszSubKey, lpSave->pszValueName);
4436 /* restore toolbar information */
4438 FIXME("restore from \"%s\" \"%s\"\n",
4439 lpSave->pszSubKey, lpSave->pszValueName);
4450 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4453 BOOL bOldAnchor = infoPtr->bAnchor;
4455 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4457 infoPtr->bAnchor = (BOOL)wParam;
4459 /* Native does not remove the hot effect from an already hot button */
4461 return (LRESULT)bOldAnchor;
4466 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4469 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4471 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4474 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4476 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4479 if (infoPtr->nNumButtons > 0)
4480 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4481 infoPtr->nNumButtons,
4482 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4483 LOWORD(lParam), HIWORD(lParam));
4485 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4486 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4489 if ((himlDef == infoPtr->himlInt) &&
4490 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4492 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4493 infoPtr->nBitmapHeight);
4501 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4504 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4505 TBUTTON_INFO *btnPtr;
4511 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4514 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4515 lptbbi->dwMask & 0x80000000);
4519 btnPtr = &infoPtr->buttons[nIndex];
4520 if (lptbbi->dwMask & TBIF_COMMAND)
4521 btnPtr->idCommand = lptbbi->idCommand;
4522 if (lptbbi->dwMask & TBIF_IMAGE)
4523 btnPtr->iBitmap = lptbbi->iImage;
4524 if (lptbbi->dwMask & TBIF_LPARAM)
4525 btnPtr->dwData = lptbbi->lParam;
4526 if (lptbbi->dwMask & TBIF_SIZE)
4527 btnPtr->cx = lptbbi->cx;
4528 if (lptbbi->dwMask & TBIF_STATE)
4529 btnPtr->fsState = lptbbi->fsState;
4530 if (lptbbi->dwMask & TBIF_STYLE)
4531 btnPtr->fsStyle = lptbbi->fsStyle;
4533 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4534 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4535 /* iString is index, zero it to make Str_SetPtr succeed */
4538 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4541 /* save the button rect to see if we need to redraw the whole toolbar */
4542 oldBtnRect = btnPtr->rect;
4543 TOOLBAR_CalcToolbar(hwnd);
4545 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4546 InvalidateRect(hwnd, NULL, TRUE);
4548 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4555 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4558 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4559 TBUTTON_INFO *btnPtr;
4565 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4568 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4569 lptbbi->dwMask & 0x80000000);
4573 btnPtr = &infoPtr->buttons[nIndex];
4574 if (lptbbi->dwMask & TBIF_COMMAND)
4575 btnPtr->idCommand = lptbbi->idCommand;
4576 if (lptbbi->dwMask & TBIF_IMAGE)
4577 btnPtr->iBitmap = lptbbi->iImage;
4578 if (lptbbi->dwMask & TBIF_LPARAM)
4579 btnPtr->dwData = lptbbi->lParam;
4580 if (lptbbi->dwMask & TBIF_SIZE)
4581 btnPtr->cx = lptbbi->cx;
4582 if (lptbbi->dwMask & TBIF_STATE)
4583 btnPtr->fsState = lptbbi->fsState;
4584 if (lptbbi->dwMask & TBIF_STYLE)
4585 btnPtr->fsStyle = lptbbi->fsStyle;
4587 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4588 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4589 /* iString is index, zero it to make Str_SetPtr succeed */
4591 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4594 /* save the button rect to see if we need to redraw the whole toolbar */
4595 oldBtnRect = btnPtr->rect;
4596 TOOLBAR_CalcToolbar(hwnd);
4598 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4599 InvalidateRect(hwnd, NULL, TRUE);
4601 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4608 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4611 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4613 if ((cx < 0) || (cy < 0))
4615 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4619 /* The documentation claims you can only change the button size before
4620 * any button has been added. But this is wrong.
4621 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4622 * it to the toolbar, and it checks that the return value is nonzero - mjm
4623 * Further testing shows that we must actually perform the change too.
4626 * The documentation also does not mention that if 0 is supplied for
4627 * either size, the system changes it to the default of 24 wide and
4628 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4630 infoPtr->nButtonWidth = (cx) ? cx : 24;
4631 infoPtr->nButtonHeight = (cy) ? cy : 22;
4637 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4641 if (infoPtr == NULL) {
4642 TRACE("Toolbar not initialized yet?????\n");
4646 /* if setting to current values, ignore */
4647 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4648 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4649 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4650 infoPtr->cxMin, infoPtr->cxMax);
4654 /* save new values */
4655 infoPtr->cxMin = (INT)LOWORD(lParam);
4656 infoPtr->cxMax = (INT)HIWORD(lParam);
4658 /* if both values are 0 then we are done */
4660 TRACE("setting both min and max to 0, norecalc\n");
4664 /* otherwise we need to recalc the toolbar and in some cases
4665 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4666 which doesn't actually draw - GA). */
4667 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4668 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4670 TOOLBAR_CalcToolbar (hwnd);
4672 InvalidateRect (hwnd, NULL, TRUE);
4679 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4682 INT nIndex = (INT)wParam;
4684 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4687 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4689 if (infoPtr->hwndToolTip) {
4691 FIXME("change tool tip!\n");
4700 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4703 HIMAGELIST himl = (HIMAGELIST)lParam;
4704 HIMAGELIST himlTemp;
4707 if (infoPtr->iVersion >= 5)
4710 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4711 &infoPtr->cimlDis, himl, id);
4713 /* FIXME: redraw ? */
4715 return (LRESULT)himlTemp;
4720 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4727 dwTemp = infoPtr->dwDTFlags;
4728 infoPtr->dwDTFlags =
4729 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4731 return (LRESULT)dwTemp;
4734 /* This function differs a bit from what MSDN says it does:
4735 * 1. lParam contains extended style flags to OR with current style
4736 * (MSDN isn't clear on the OR bit)
4737 * 2. wParam appears to contain extended style flags to be reset
4738 * (MSDN says that this parameter is reserved)
4741 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4746 dwTemp = infoPtr->dwExStyle;
4747 infoPtr->dwExStyle &= ~wParam;
4748 infoPtr->dwExStyle |= (DWORD)lParam;
4750 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4752 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4753 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4754 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4756 TOOLBAR_CalcToolbar (hwnd);
4758 TOOLBAR_AutoSize(hwnd);
4760 InvalidateRect(hwnd, NULL, TRUE);
4762 return (LRESULT)dwTemp;
4767 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4770 HIMAGELIST himlTemp;
4771 HIMAGELIST himl = (HIMAGELIST)lParam;
4774 if (infoPtr->iVersion >= 5)
4777 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4779 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4780 &infoPtr->cimlHot, himl, id);
4782 /* FIXME: redraw ? */
4784 return (LRESULT)himlTemp;
4788 /* Makes previous hot button no longer hot, makes the specified
4789 * button hot and sends appropriate notifications. dwReason is one or
4790 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4791 * NOTE 1: this function does not validate nHit
4792 * NOTE 2: the name of this function is completely made up and
4793 * not based on any documentation from Microsoft. */
4795 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4797 if (infoPtr->nHotItem != nHit)
4799 NMTBHOTITEM nmhotitem;
4800 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4801 LRESULT no_highlight;
4803 /* Remove the effect of an old hot button if the button was
4804 drawn with the hot button effect */
4805 if(infoPtr->nHotItem >= 0)
4807 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4808 oldBtnPtr->bHot = FALSE;
4811 infoPtr->nHotItem = nHit;
4813 /* It's not a separator or in nowhere. It's a hot button. */
4815 btnPtr = &infoPtr->buttons[nHit];
4817 nmhotitem.dwFlags = dwReason;
4819 nmhotitem.idOld = oldBtnPtr->idCommand;
4821 nmhotitem.dwFlags |= HICF_ENTERING;
4823 nmhotitem.idNew = btnPtr->idCommand;
4825 nmhotitem.dwFlags |= HICF_LEAVING;
4827 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4829 /* now invalidate the old and new buttons so they will be painted */
4831 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4832 if (btnPtr && !no_highlight)
4834 btnPtr->bHot = TRUE;
4835 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4841 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4844 INT nOldHotItem = infoPtr->nHotItem;
4846 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4848 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4851 /* NOTE: an application can still remove the hot item even if anchor
4852 * highlighting is enabled */
4854 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4855 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4857 if (nOldHotItem < 0)
4860 return (LRESULT)nOldHotItem;
4865 TOOLBAR_SetImageList (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 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4876 &infoPtr->cimlDef, himl, id);
4878 infoPtr->nNumBitmaps = 0;
4879 for (i = 0; i < infoPtr->cimlDef; i++)
4880 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4882 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4883 &infoPtr->nBitmapHeight);
4884 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4885 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4886 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4888 InvalidateRect(hwnd, NULL, TRUE);
4890 return (LRESULT)himlTemp;
4895 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4899 infoPtr->nIndent = (INT)wParam;
4903 /* process only on indent changing */
4904 if(infoPtr->nIndent != (INT)wParam)
4906 infoPtr->nIndent = (INT)wParam;
4907 TOOLBAR_CalcToolbar (hwnd);
4908 InvalidateRect(hwnd, NULL, FALSE);
4916 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4919 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4921 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4923 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4925 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4929 if ((lptbim->iButton == -1) ||
4930 ((lptbim->iButton < infoPtr->nNumButtons) &&
4931 (lptbim->iButton >= 0)))
4933 infoPtr->tbim = *lptbim;
4934 /* FIXME: don't need to update entire toolbar */
4935 InvalidateRect(hwnd, NULL, TRUE);
4938 ERR("Invalid button index %d\n", lptbim->iButton);
4945 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4949 infoPtr->clrInsertMark = (COLORREF)lParam;
4951 /* FIXME: don't need to update entire toolbar */
4952 InvalidateRect(hwnd, NULL, TRUE);
4959 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4963 if (infoPtr == NULL)
4966 infoPtr->nMaxTextRows = (INT)wParam;
4968 TOOLBAR_CalcToolbar(hwnd);
4973 /* MSDN gives slightly wrong info on padding.
4974 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4975 * 2. It is not used to create a blank area between the edge of the button
4976 * and the text or image if TBSTYLE_LIST is set. It is used to control
4977 * the gap between the image and text.
4978 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4979 * to control the bottom and right borders [with the border being
4980 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4981 * is shared evenly on both sides of the button.
4984 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4989 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4990 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4991 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4992 TRACE("cx=%ld, cy=%ld\n",
4993 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4994 return (LRESULT) oldPad;
4999 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
5001 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5006 if (infoPtr == NULL)
5008 hwndOldNotify = infoPtr->hwndNotify;
5009 infoPtr->hwndNotify = (HWND)wParam;
5011 return (LRESULT)hwndOldNotify;
5016 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5019 LPRECT lprc = (LPRECT)lParam;
5023 if (LOWORD(wParam) > 1) {
5024 FIXME("multiple rows not supported!\n");
5027 if(infoPtr->nRows != LOWORD(wParam))
5029 infoPtr->nRows = LOWORD(wParam);
5031 /* recalculate toolbar */
5032 TOOLBAR_CalcToolbar (hwnd);
5034 /* repaint toolbar */
5035 InvalidateRect(hwnd, NULL, TRUE);
5038 /* return bounding rectangle */
5040 lprc->left = infoPtr->rcBound.left;
5041 lprc->right = infoPtr->rcBound.right;
5042 lprc->top = infoPtr->rcBound.top;
5043 lprc->bottom = infoPtr->rcBound.bottom;
5051 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5054 TBUTTON_INFO *btnPtr;
5057 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5061 btnPtr = &infoPtr->buttons[nIndex];
5063 /* if hidden state has changed the invalidate entire window and recalc */
5064 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5065 btnPtr->fsState = LOWORD(lParam);
5066 TOOLBAR_CalcToolbar (hwnd);
5067 InvalidateRect(hwnd, 0, TRUE);
5071 /* process state changing if current state doesn't match new state */
5072 if(btnPtr->fsState != LOWORD(lParam))
5074 btnPtr->fsState = LOWORD(lParam);
5075 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5083 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5085 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5091 inline static LRESULT
5092 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5096 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5098 if (infoPtr == NULL)
5100 infoPtr->hwndToolTip = (HWND)wParam;
5106 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5111 TRACE("%s hwnd=%p\n",
5112 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5114 bTemp = infoPtr->bUnicode;
5115 infoPtr->bUnicode = (BOOL)wParam;
5122 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5126 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5127 comctl32_color.clrBtnHighlight :
5128 infoPtr->clrBtnHighlight;
5129 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5130 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5136 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5140 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5141 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5142 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5144 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5145 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5146 InvalidateRect(hwnd, NULL, TRUE);
5152 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5155 INT iOldVersion = infoPtr->iVersion;
5157 infoPtr->iVersion = iVersion;
5159 if (infoPtr->iVersion >= 5)
5160 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5167 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5170 WORD iString = HIWORD(wParam);
5171 WORD buffersize = LOWORD(wParam);
5172 LPSTR str = (LPSTR)lParam;
5175 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5177 if (iString < infoPtr->nNumStrings)
5179 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5181 TRACE("returning %s\n", debugstr_a(str));
5184 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5191 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5194 WORD iString = HIWORD(wParam);
5195 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5196 LPWSTR str = (LPWSTR)lParam;
5199 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5201 if (iString < infoPtr->nNumStrings)
5203 len = min(len, strlenW(infoPtr->strings[iString]));
5204 ret = (len+1)*sizeof(WCHAR);
5205 memcpy(str, infoPtr->strings[iString], ret);
5208 TRACE("returning %s\n", debugstr_w(str));
5211 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5216 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5217 * is the maximum size of the toolbar? */
5218 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5220 SIZE * pSize = (SIZE*)lParam;
5221 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5226 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5227 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5228 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5231 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5234 INT nOldHotItem = infoPtr->nHotItem;
5236 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5237 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5239 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5242 /* NOTE: an application can still remove the hot item even if anchor
5243 * highlighting is enabled */
5245 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5249 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5252 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5253 * which controls the amount of spacing between the image and the text
5254 * of buttons for TBSTYLE_LIST toolbars. */
5255 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5259 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5262 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5264 infoPtr->iListGap = (INT)wParam;
5266 InvalidateRect(hwnd, NULL, TRUE);
5271 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5272 * of image lists associated with the various states. */
5273 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5277 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5279 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5283 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5286 LPSIZE lpsize = (LPSIZE)lParam;
5292 * Testing shows the following:
5293 * wParam = 0 adjust cx value
5294 * = 1 set cy value to max size.
5295 * lParam pointer to SIZE structure
5298 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5299 wParam, lParam, lpsize->cx, lpsize->cy);
5303 if (lpsize->cx == -1) {
5304 /* **** this is wrong, native measures each button and sets it */
5305 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5307 else if(HIWORD(lpsize->cx)) {
5309 HWND hwndParent = GetParent(hwnd);
5311 GetWindowRect(hwnd, &rc);
5312 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5313 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5314 rc.left, rc.top, rc.right, rc.bottom);
5315 lpsize->cx = max(rc.right-rc.left,
5316 infoPtr->rcBound.right - infoPtr->rcBound.left);
5319 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5323 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5324 /* lpsize->cy = infoPtr->nHeight; */
5327 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5331 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5332 lpsize->cx, lpsize->cy);
5336 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5338 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5340 InvalidateRect(hwnd, NULL, TRUE);
5346 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5349 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5352 TRACE("hwnd = %p\n", hwnd);
5354 /* initialize info structure */
5355 infoPtr->nButtonHeight = 22;
5356 infoPtr->nButtonWidth = 24;
5357 infoPtr->nBitmapHeight = 15;
5358 infoPtr->nBitmapWidth = 16;
5360 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5361 infoPtr->nMaxTextRows = 1;
5362 infoPtr->cxMin = -1;
5363 infoPtr->cxMax = -1;
5364 infoPtr->nNumBitmaps = 0;
5365 infoPtr->nNumStrings = 0;
5367 infoPtr->bCaptured = FALSE;
5368 infoPtr->nButtonDown = -1;
5369 infoPtr->nButtonDrag = -1;
5370 infoPtr->nOldHit = -1;
5371 infoPtr->nHotItem = -1;
5372 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5373 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5374 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5375 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5376 infoPtr->bDragOutSent = FALSE;
5377 infoPtr->iVersion = 0;
5378 infoPtr->hwndSelf = hwnd;
5379 infoPtr->bDoRedraw = TRUE;
5380 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5381 infoPtr->clrBtnShadow = CLR_DEFAULT;
5382 /* not sure where the +1 comes from, but this comes to the same value
5383 * as native so this is probably correct */
5384 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5385 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5386 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5387 infoPtr->dwStyle = dwStyle;
5388 infoPtr->tbim.iButton = -1;
5389 GetClientRect(hwnd, &infoPtr->client_rect);
5390 infoPtr->bUnicode = infoPtr->hwndNotify &&
5391 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, (LPARAM)NF_REQUERY));
5393 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5394 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5396 if (dwStyle & TBSTYLE_TOOLTIPS) {
5397 /* Create tooltip control */
5398 infoPtr->hwndToolTip =
5399 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5400 CW_USEDEFAULT, CW_USEDEFAULT,
5401 CW_USEDEFAULT, CW_USEDEFAULT,
5404 /* Send NM_TOOLTIPSCREATED notification */
5405 if (infoPtr->hwndToolTip) {
5406 NMTOOLTIPSCREATED nmttc;
5408 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5410 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5411 NM_TOOLTIPSCREATED);
5415 TOOLBAR_CheckStyle (hwnd, dwStyle);
5417 TOOLBAR_CalcToolbar(hwnd);
5424 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5428 /* delete tooltip control */
5429 if (infoPtr->hwndToolTip)
5430 DestroyWindow (infoPtr->hwndToolTip);
5432 /* delete temporary buffer for tooltip text */
5433 if (infoPtr->pszTooltipText)
5434 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5436 /* delete button data */
5437 if (infoPtr->buttons)
5438 Free (infoPtr->buttons);
5440 /* delete strings */
5441 if (infoPtr->strings) {
5443 for (i = 0; i < infoPtr->nNumStrings; i++)
5444 if (infoPtr->strings[i])
5445 Free (infoPtr->strings[i]);
5447 Free (infoPtr->strings);
5450 /* destroy internal image list */
5451 if (infoPtr->himlInt)
5452 ImageList_Destroy (infoPtr->himlInt);
5454 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5455 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5456 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5458 /* delete default font */
5460 DeleteObject (infoPtr->hDefaultFont);
5462 /* free toolbar info data */
5464 SetWindowLongPtrW (hwnd, 0, 0);
5471 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5474 NMTBCUSTOMDRAW tbcd;
5478 /* the app has told us not to redraw the toolbar */
5479 if (!infoPtr->bDoRedraw)
5482 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5483 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5484 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5485 tbcd.nmcd.hdc = (HDC)wParam;
5486 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5487 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5489 /* FIXME: in general the return flags *can* be or'ed together */
5490 switch (infoPtr->dwBaseCustDraw)
5492 case CDRF_DODEFAULT:
5494 case CDRF_SKIPDEFAULT:
5497 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5502 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5503 * to my parent for processing.
5505 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5507 HDC hdc = (HDC)wParam;
5512 parent = GetParent(hwnd);
5513 MapWindowPoints(hwnd, parent, &pt, 1);
5514 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5515 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5516 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5519 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5521 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5522 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5523 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5524 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5525 tbcd.nmcd.hdc = (HDC)wParam;
5526 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5527 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5528 switch (infoPtr->dwBaseCustDraw)
5530 case CDRF_DODEFAULT:
5532 case CDRF_SKIPDEFAULT:
5535 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5544 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5548 return (LRESULT)infoPtr->hFont;
5553 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5558 pt.x = (INT)LOWORD(lParam);
5559 pt.y = (INT)HIWORD(lParam);
5560 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5563 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5564 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5565 TOOLBAR_Customize (hwnd);
5572 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5575 TBUTTON_INFO *btnPtr;
5580 BOOL bDragKeyPressed;
5584 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5585 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5587 bDragKeyPressed = (wParam & MK_SHIFT);
5589 if (infoPtr->hwndToolTip)
5590 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5591 WM_LBUTTONDOWN, wParam, lParam);
5593 pt.x = (INT)LOWORD(lParam);
5594 pt.y = (INT)HIWORD(lParam);
5595 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5597 btnPtr = &infoPtr->buttons[nHit];
5599 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5601 infoPtr->nButtonDrag = nHit;
5604 /* If drag cursor has not been loaded, load it.
5605 * Note: it doesn't need to be freed */
5607 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5608 SetCursor(hCursorDrag);
5613 infoPtr->nOldHit = nHit;
5615 CopyRect(&arrowRect, &btnPtr->rect);
5616 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5618 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5619 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5620 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5621 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5622 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5623 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5627 /* draw in pressed state */
5628 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5629 btnPtr->fsState |= TBSTATE_PRESSED;
5631 btnPtr->bDropDownPressed = TRUE;
5632 RedrawWindow(hwnd,&btnPtr->rect,0,
5633 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5635 nmtb.iItem = btnPtr->idCommand;
5636 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5639 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5640 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5642 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5644 if (res != TBDDRET_TREATPRESSED)
5648 /* redraw button in unpressed state */
5649 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5650 btnPtr->fsState &= ~TBSTATE_PRESSED;
5652 btnPtr->bDropDownPressed = FALSE;
5653 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5655 /* find and set hot item
5656 * NOTE: native doesn't do this, but that is a bug */
5658 ScreenToClient(hwnd, &pt);
5659 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5660 if (!infoPtr->bAnchor || (nHit >= 0))
5661 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5663 /* remove any left mouse button down or double-click messages
5664 * so that we can get a toggle effect on the button */
5665 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5666 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5671 /* otherwise drop through and process as pushed */
5673 infoPtr->bCaptured = TRUE;
5674 infoPtr->nButtonDown = nHit;
5675 infoPtr->bDragOutSent = FALSE;
5677 btnPtr->fsState |= TBSTATE_PRESSED;
5679 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5681 if (btnPtr->fsState & TBSTATE_ENABLED)
5682 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5689 nmtb.iItem = btnPtr->idCommand;
5690 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5691 nmtb.tbButton.idCommand = btnPtr->idCommand;
5692 nmtb.tbButton.fsState = btnPtr->fsState;
5693 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5694 nmtb.tbButton.dwData = btnPtr->dwData;
5695 nmtb.tbButton.iString = btnPtr->iString;
5696 nmtb.cchText = 0; /* !!! not correct */
5697 nmtb.pszText = 0; /* !!! not correct */
5698 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5701 nmmouse.dwHitInfo = nHit;
5703 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5704 if (nmmouse.dwHitInfo < 0)
5705 nmmouse.dwItemSpec = -1;
5708 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5709 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5712 ClientToScreen(hwnd, &pt);
5715 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_LDOWN))
5716 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5722 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5725 TBUTTON_INFO *btnPtr;
5729 BOOL bSendMessage = TRUE;
5734 if (infoPtr->hwndToolTip)
5735 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5736 WM_LBUTTONUP, wParam, lParam);
5738 pt.x = (INT)LOWORD(lParam);
5739 pt.y = (INT)HIWORD(lParam);
5740 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5742 if (!infoPtr->bAnchor || (nHit >= 0))
5743 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5745 if (infoPtr->nButtonDrag >= 0) {
5749 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5752 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5754 GetClientRect(hwnd, &rcClient);
5755 if (PtInRect(&rcClient, pt))
5762 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5765 if (nButton == infoPtr->nButtonDrag)
5767 /* if the button is moved sightly left and we have a
5768 * separator there then remove it */
5769 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5771 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5772 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5774 else /* else insert a separator before the dragged button */
5777 memset(&tbb, 0, sizeof(tbb));
5778 tbb.fsStyle = BTNS_SEP;
5780 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5787 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5788 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5790 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5793 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5798 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5799 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5802 /* button under cursor changed so need to re-set hot item */
5803 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5804 infoPtr->nButtonDrag = -1;
5806 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5808 else if (infoPtr->nButtonDown >= 0) {
5809 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5810 btnPtr->fsState &= ~TBSTATE_PRESSED;
5812 if (btnPtr->fsStyle & BTNS_CHECK) {
5813 if (btnPtr->fsStyle & BTNS_GROUP) {
5814 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5816 if (nOldIndex == nHit)
5817 bSendMessage = FALSE;
5818 if ((nOldIndex != nHit) &&
5820 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5821 btnPtr->fsState |= TBSTATE_CHECKED;
5824 if (btnPtr->fsState & TBSTATE_CHECKED)
5825 btnPtr->fsState &= ~TBSTATE_CHECKED;
5827 btnPtr->fsState |= TBSTATE_CHECKED;
5831 if (nOldIndex != -1)
5832 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5835 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5836 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5837 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5839 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5841 infoPtr->nButtonDown = -1;
5843 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5844 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5845 NM_RELEASEDCAPTURE);
5847 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5850 nmtb.iItem = btnPtr->idCommand;
5851 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5852 nmtb.tbButton.idCommand = btnPtr->idCommand;
5853 nmtb.tbButton.fsState = btnPtr->fsState;
5854 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5855 nmtb.tbButton.dwData = btnPtr->dwData;
5856 nmtb.tbButton.iString = btnPtr->iString;
5857 nmtb.cchText = 0; /* !!! not correct */
5858 nmtb.pszText = 0; /* !!! not correct */
5859 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5862 if (btnPtr->fsState & TBSTATE_ENABLED)
5864 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5865 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5869 /* !!! Undocumented - toolbar at 4.71 level and above sends
5870 * NM_CLICK with the NMMOUSE structure. */
5871 nmmouse.dwHitInfo = nHit;
5873 if (nmmouse.dwHitInfo < 0)
5874 nmmouse.dwItemSpec = -1;
5877 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5878 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5881 ClientToScreen(hwnd, &pt);
5884 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5885 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5891 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5898 pt.x = LOWORD(lParam);
5899 pt.y = HIWORD(lParam);
5901 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5903 if (nmmouse.dwHitInfo < 0) {
5904 nmmouse.dwItemSpec = -1;
5906 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5907 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5910 ClientToScreen(hwnd, &pt);
5913 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5914 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5920 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5925 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5926 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5932 TOOLBAR_CaptureChanged(HWND hwnd)
5934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5935 TBUTTON_INFO *btnPtr;
5937 infoPtr->bCaptured = FALSE;
5939 if (infoPtr->nButtonDown >= 0)
5941 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5942 btnPtr->fsState &= ~TBSTATE_PRESSED;
5944 infoPtr->nOldHit = -1;
5946 if (btnPtr->fsState & TBSTATE_ENABLED)
5947 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5953 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5955 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5956 TBUTTON_INFO *hotBtnPtr;
5958 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5960 /* don't remove hot effects when in anchor highlighting mode or when a
5961 * drop-down button is pressed */
5962 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
5963 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5965 if (infoPtr->nOldHit < 0)
5968 /* If the last button we were over is depressed then make it not */
5969 /* depressed and redraw it */
5970 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5972 TBUTTON_INFO *btnPtr;
5975 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5977 btnPtr->fsState &= ~TBSTATE_PRESSED;
5979 rc1 = hotBtnPtr->rect;
5980 InflateRect (&rc1, 1, 1);
5981 InvalidateRect (hwnd, &rc1, TRUE);
5984 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5987 ZeroMemory(&nmt, sizeof(nmt));
5988 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5989 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5990 infoPtr->bDragOutSent = TRUE;
5993 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5999 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
6001 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6003 TRACKMOUSEEVENT trackinfo;
6005 TBUTTON_INFO *btnPtr;
6007 /* fill in the TRACKMOUSEEVENT struct */
6008 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6009 trackinfo.dwFlags = TME_QUERY;
6010 trackinfo.hwndTrack = hwnd;
6011 trackinfo.dwHoverTime = HOVER_DEFAULT;
6013 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6014 _TrackMouseEvent(&trackinfo);
6016 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6017 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6018 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6020 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6021 /* and can properly deactivate the hot toolbar button */
6022 _TrackMouseEvent(&trackinfo);
6025 if (infoPtr->hwndToolTip)
6026 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6027 WM_MOUSEMOVE, wParam, lParam);
6029 pt.x = (INT)LOWORD(lParam);
6030 pt.y = (INT)HIWORD(lParam);
6032 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6034 if (!infoPtr->bAnchor || (nHit >= 0))
6035 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6037 if (infoPtr->nOldHit != nHit)
6039 if (infoPtr->bCaptured)
6041 if (!infoPtr->bDragOutSent)
6044 ZeroMemory(&nmt, sizeof(nmt));
6045 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6046 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6047 infoPtr->bDragOutSent = TRUE;
6050 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6051 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6052 btnPtr->fsState &= ~TBSTATE_PRESSED;
6053 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6055 else if (nHit == infoPtr->nButtonDown) {
6056 btnPtr->fsState |= TBSTATE_PRESSED;
6057 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6059 infoPtr->nOldHit = nHit;
6067 inline static LRESULT
6068 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6070 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6071 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6073 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6077 inline static LRESULT
6078 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6080 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6081 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6083 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6088 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6090 TOOLBAR_INFO *infoPtr;
6091 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6094 /* allocate memory for info structure */
6095 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6096 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6099 infoPtr->dwStructSize = sizeof(TBBUTTON);
6102 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6103 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6104 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6105 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6108 /* native control does:
6109 * Get a lot of colors and brushes
6111 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
6112 * CreateFontIndirectA(adr1)
6113 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6114 * hdc = GetDC(toolbar)
6115 * GetSystemMetrics(0x48)
6116 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6117 * 0, 0, 0, 0, "MARLETT")
6118 * oldfnt = SelectObject(hdc, fnt2)
6119 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
6120 * GetTextMetricsA(hdc, adr3)
6121 * SelectObject(hdc, oldfnt)
6122 * DeleteObject(fnt2)
6124 * InvalidateRect(toolbar, 0, 1)
6125 * SetWindowLongA(toolbar, 0, addr)
6126 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
6129 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6130 * ie 2 0x4600094c 0x4600094c 0x4600894d
6131 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6132 * rebar 0x50008844 0x40008844 0x50008845
6133 * pager 0x50000844 0x40000844 0x50008845
6134 * IC35mgr 0x5400084e **nochange**
6135 * on entry to _NCCREATE 0x5400084e
6136 * rowlist 0x5400004e **nochange**
6137 * on entry to _NCCREATE 0x5400004e
6141 /* I think the code below is a bug, but it is the way that the native
6142 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6143 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6144 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6145 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6146 * Some how, the only cases of this seem to be MFC programs.
6148 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6149 * does not occur in the WM_STYLECHANGING routine.
6150 * (Guy Albertelli 9/2001)
6153 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6154 styleadd |= TBSTYLE_TRANSPARENT;
6155 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6156 styleadd |= CCS_TOP; /* default to top */
6157 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6160 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6165 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6167 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6171 if (dwStyle & WS_MINIMIZE)
6172 return 0; /* Nothing to do */
6174 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6176 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6179 if (!(dwStyle & CCS_NODIVIDER))
6181 GetWindowRect (hwnd, &rcWindow);
6182 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6183 if( dwStyle & WS_BORDER )
6184 OffsetRect (&rcWindow, 1, 1);
6185 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6188 ReleaseDC( hwnd, hdc );
6194 /* handles requests from the tooltip control on what text to display */
6195 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6197 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6199 TRACE("button index = %d\n", index);
6201 if (infoPtr->pszTooltipText)
6203 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6204 infoPtr->pszTooltipText = NULL;
6210 if (infoPtr->bNtfUnicode)
6212 WCHAR wszBuffer[INFOTIPSIZE+1];
6213 NMTBGETINFOTIPW tbgit;
6214 unsigned int len; /* in chars */
6216 wszBuffer[0] = '\0';
6217 wszBuffer[INFOTIPSIZE] = '\0';
6219 tbgit.pszText = wszBuffer;
6220 tbgit.cchTextMax = INFOTIPSIZE;
6221 tbgit.iItem = lpnmtdi->hdr.idFrom;
6222 tbgit.lParam = infoPtr->buttons[index].dwData;
6224 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6226 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6228 len = strlenW(tbgit.pszText);
6229 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6231 /* need to allocate temporary buffer in infoPtr as there
6232 * isn't enough space in buffer passed to us by the
6233 * tooltip control */
6234 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6235 if (infoPtr->pszTooltipText)
6237 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6238 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6244 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6250 CHAR szBuffer[INFOTIPSIZE+1];
6251 NMTBGETINFOTIPA tbgit;
6252 unsigned int len; /* in chars */
6255 szBuffer[INFOTIPSIZE] = '\0';
6257 tbgit.pszText = szBuffer;
6258 tbgit.cchTextMax = INFOTIPSIZE;
6259 tbgit.iItem = lpnmtdi->hdr.idFrom;
6260 tbgit.lParam = infoPtr->buttons[index].dwData;
6262 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6264 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6266 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6267 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6269 /* need to allocate temporary buffer in infoPtr as there
6270 * isn't enough space in buffer passed to us by the
6271 * tooltip control */
6272 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6273 if (infoPtr->pszTooltipText)
6275 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6276 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6282 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6287 /* if button has text, but it is not shown then automatically
6288 * use that text as tooltip */
6289 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6290 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6292 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6293 unsigned int len = pszText ? strlenW(pszText) : 0;
6295 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6297 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6299 /* need to allocate temporary buffer in infoPtr as there
6300 * isn't enough space in buffer passed to us by the
6301 * tooltip control */
6302 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6303 if (infoPtr->pszTooltipText)
6305 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6306 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6312 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6317 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6319 /* last resort: send notification on to app */
6320 /* FIXME: find out what is really used here */
6321 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6325 inline static LRESULT
6326 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6329 LPNMHDR lpnmh = (LPNMHDR)lParam;
6331 switch (lpnmh->code)
6335 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6337 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6338 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6339 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6343 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6344 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6352 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6354 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6355 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6356 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6357 lppgs->iScroll, lppgs->iDir);
6361 case TTN_GETDISPINFOW:
6362 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6364 case TTN_GETDISPINFOA:
6365 FIXME("TTN_GETDISPINFOA - stub\n");
6375 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6377 /* remove this routine when Toolbar is improved to pass infoPtr
6378 * around instead of hwnd.
6380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6381 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6386 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6390 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6392 if (lParam == NF_QUERY)
6395 if (lParam == NF_REQUERY) {
6396 format = SendMessageW(infoPtr->hwndNotify,
6397 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6398 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6399 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6410 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6416 /* fill ps.rcPaint with a default rect */
6417 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6419 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6421 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6422 ps.rcPaint.left, ps.rcPaint.top,
6423 ps.rcPaint.right, ps.rcPaint.bottom);
6425 TOOLBAR_Refresh (hwnd, hdc, &ps);
6426 if (!wParam) EndPaint (hwnd, &ps);
6433 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6434 /*****************************************************
6437 * Handles the WM_SETREDRAW message.
6440 * According to testing V4.71 of COMCTL32 returns the
6441 * *previous* status of the redraw flag (either 0 or 1)
6442 * instead of the MSDN documented value of 0 if handled.
6443 * (For laughs see the "consistency" with same function
6446 *****************************************************/
6448 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6449 BOOL oldredraw = infoPtr->bDoRedraw;
6451 TRACE("set to %s\n",
6452 (wParam) ? "TRUE" : "FALSE");
6453 infoPtr->bDoRedraw = (BOOL) wParam;
6455 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6457 return (oldredraw) ? 1 : 0;
6462 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6465 DWORD dwStyle = infoPtr->dwStyle;
6474 /* Resize deadlock check */
6475 if (infoPtr->bAutoSize) {
6476 infoPtr->bAutoSize = FALSE;
6480 /* FIXME: optimize to only update size if the new size doesn't */
6481 /* match the current size */
6483 flags = (INT) wParam;
6485 /* FIXME for flags =
6486 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6489 TRACE("sizing toolbar!\n");
6491 if (flags == SIZE_RESTORED) {
6492 /* width and height don't apply */
6493 parent = GetParent (hwnd);
6494 GetClientRect(parent, &parent_rect);
6495 x = parent_rect.left;
6496 y = parent_rect.top;
6498 if (dwStyle & CCS_NORESIZE) {
6499 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6502 * this sets the working width of the toolbar, and
6503 * Calc Toolbar will not adjust it, only the height
6505 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6506 cy = infoPtr->nHeight;
6507 cx = infoPtr->nWidth;
6508 TOOLBAR_CalcToolbar (hwnd);
6509 infoPtr->nWidth = cx;
6510 infoPtr->nHeight = cy;
6513 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6514 TOOLBAR_CalcToolbar (hwnd);
6515 cy = infoPtr->nHeight;
6516 cx = infoPtr->nWidth;
6518 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6519 GetWindowRect(hwnd, &window_rect);
6520 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6521 y = window_rect.top;
6523 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6524 GetWindowRect(hwnd, &window_rect);
6525 y = parent_rect.bottom -
6526 ( window_rect.bottom - window_rect.top);
6530 if (dwStyle & CCS_NOPARENTALIGN) {
6531 uPosFlags |= SWP_NOMOVE;
6532 cy = infoPtr->nHeight;
6533 cx = infoPtr->nWidth;
6536 if (!(dwStyle & CCS_NODIVIDER))
6537 cy += GetSystemMetrics(SM_CYEDGE);
6539 if (dwStyle & WS_BORDER)
6542 cy += GetSystemMetrics(SM_CYEDGE);
6543 cx += GetSystemMetrics(SM_CYEDGE);
6546 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6548 RECT delta_width, delta_height, client, dummy;
6549 DWORD min_x, max_x, min_y, max_y;
6550 TBUTTON_INFO *btnPtr;
6553 GetClientRect(hwnd, &client);
6554 if(client.right > infoPtr->client_rect.right)
6556 min_x = infoPtr->client_rect.right;
6557 max_x = client.right;
6561 max_x = infoPtr->client_rect.right;
6562 min_x = client.right;
6564 if(client.bottom > infoPtr->client_rect.bottom)
6566 min_y = infoPtr->client_rect.bottom;
6567 max_y = client.bottom;
6571 max_y = infoPtr->client_rect.bottom;
6572 min_y = client.bottom;
6575 SetRect(&delta_width, min_x, 0, max_x, min_y);
6576 SetRect(&delta_height, 0, min_y, max_x, max_y);
6578 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6579 btnPtr = infoPtr->buttons;
6580 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6581 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6582 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6583 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6586 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6587 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6589 GetClientRect(hwnd, &infoPtr->client_rect);
6595 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6599 if (nType == GWL_STYLE) {
6600 if (lpStyle->styleNew & TBSTYLE_LIST) {
6601 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6604 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6606 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6607 (TBSTYLE_FLAT | TBSTYLE_LIST));
6608 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6610 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6612 infoPtr->dwStyle = lpStyle->styleNew;
6615 TOOLBAR_CalcToolbar(hwnd);
6617 TOOLBAR_AutoSize (hwnd);
6619 InvalidateRect(hwnd, NULL, TRUE);
6626 TOOLBAR_SysColorChange (HWND hwnd)
6628 COMCTL32_RefreshSysColors();
6635 static LRESULT WINAPI
6636 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6640 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6641 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6643 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6644 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6649 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6651 case TB_ADDBUTTONSA:
6652 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6654 case TB_ADDBUTTONSW:
6655 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6658 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6661 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6664 return TOOLBAR_AutoSize (hwnd);
6666 case TB_BUTTONCOUNT:
6667 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6669 case TB_BUTTONSTRUCTSIZE:
6670 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6672 case TB_CHANGEBITMAP:
6673 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6675 case TB_CHECKBUTTON:
6676 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6678 case TB_COMMANDTOINDEX:
6679 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6682 return TOOLBAR_Customize (hwnd);
6684 case TB_DELETEBUTTON:
6685 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6687 case TB_ENABLEBUTTON:
6688 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6690 case TB_GETANCHORHIGHLIGHT:
6691 return TOOLBAR_GetAnchorHighlight (hwnd);
6694 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6696 case TB_GETBITMAPFLAGS:
6697 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6700 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6702 case TB_GETBUTTONINFOA:
6703 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6705 case TB_GETBUTTONINFOW:
6706 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6708 case TB_GETBUTTONSIZE:
6709 return TOOLBAR_GetButtonSize (hwnd);
6711 case TB_GETBUTTONTEXTA:
6712 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6714 case TB_GETBUTTONTEXTW:
6715 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6717 case TB_GETDISABLEDIMAGELIST:
6718 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6720 case TB_GETEXTENDEDSTYLE:
6721 return TOOLBAR_GetExtendedStyle (hwnd);
6723 case TB_GETHOTIMAGELIST:
6724 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6727 return TOOLBAR_GetHotItem (hwnd);
6729 case TB_GETIMAGELIST:
6730 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6732 case TB_GETINSERTMARK:
6733 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6735 case TB_GETINSERTMARKCOLOR:
6736 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6738 case TB_GETITEMRECT:
6739 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6742 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6744 /* case TB_GETOBJECT: */ /* 4.71 */
6747 return TOOLBAR_GetPadding (hwnd);
6750 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6753 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6756 return TOOLBAR_GetState (hwnd, wParam, lParam);
6759 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6762 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6765 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6767 case TB_GETTEXTROWS:
6768 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6770 case TB_GETTOOLTIPS:
6771 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6773 case TB_GETUNICODEFORMAT:
6774 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6777 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6780 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6782 case TB_INDETERMINATE:
6783 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6785 case TB_INSERTBUTTONA:
6786 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6788 case TB_INSERTBUTTONW:
6789 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6791 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6793 case TB_ISBUTTONCHECKED:
6794 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6796 case TB_ISBUTTONENABLED:
6797 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6799 case TB_ISBUTTONHIDDEN:
6800 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6802 case TB_ISBUTTONHIGHLIGHTED:
6803 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6805 case TB_ISBUTTONINDETERMINATE:
6806 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6808 case TB_ISBUTTONPRESSED:
6809 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6812 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6814 case TB_MAPACCELERATORA:
6815 case TB_MAPACCELERATORW:
6816 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6819 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6822 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6824 case TB_PRESSBUTTON:
6825 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6827 case TB_REPLACEBITMAP:
6828 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6830 case TB_SAVERESTOREA:
6831 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6833 case TB_SAVERESTOREW:
6834 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6836 case TB_SETANCHORHIGHLIGHT:
6837 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6839 case TB_SETBITMAPSIZE:
6840 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6842 case TB_SETBUTTONINFOA:
6843 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6845 case TB_SETBUTTONINFOW:
6846 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6848 case TB_SETBUTTONSIZE:
6849 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6851 case TB_SETBUTTONWIDTH:
6852 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6855 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6857 case TB_SETDISABLEDIMAGELIST:
6858 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6860 case TB_SETDRAWTEXTFLAGS:
6861 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6863 case TB_SETEXTENDEDSTYLE:
6864 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6866 case TB_SETHOTIMAGELIST:
6867 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6870 return TOOLBAR_SetHotItem (hwnd, wParam);
6872 case TB_SETIMAGELIST:
6873 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6876 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6878 case TB_SETINSERTMARK:
6879 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6881 case TB_SETINSERTMARKCOLOR:
6882 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6884 case TB_SETMAXTEXTROWS:
6885 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6888 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6891 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6894 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6897 return TOOLBAR_SetState (hwnd, wParam, lParam);
6900 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6902 case TB_SETTOOLTIPS:
6903 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6905 case TB_SETUNICODEFORMAT:
6906 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6909 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6912 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6915 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6918 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6921 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6924 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6926 /* Common Control Messages */
6928 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6929 case CCM_GETCOLORSCHEME:
6930 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6932 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6933 case CCM_SETCOLORSCHEME:
6934 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6936 case CCM_GETVERSION:
6937 return TOOLBAR_GetVersion (hwnd);
6939 case CCM_SETVERSION:
6940 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6946 return TOOLBAR_Create (hwnd, wParam, lParam);
6949 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6952 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6955 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6957 /* case WM_KEYDOWN: */
6958 /* case WM_KILLFOCUS: */
6960 case WM_LBUTTONDBLCLK:
6961 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6963 case WM_LBUTTONDOWN:
6964 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6967 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6970 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6972 case WM_RBUTTONDBLCLK:
6973 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6976 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6979 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6981 case WM_CAPTURECHANGED:
6982 return TOOLBAR_CaptureChanged(hwnd);
6985 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6988 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6991 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6994 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6997 return TOOLBAR_Notify (hwnd, wParam, lParam);
6999 case WM_NOTIFYFORMAT:
7000 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
7003 return TOOLBAR_Paint (hwnd, wParam);
7006 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7009 return TOOLBAR_Size (hwnd, wParam, lParam);
7011 case WM_STYLECHANGED:
7012 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7014 case WM_SYSCOLORCHANGE:
7015 return TOOLBAR_SysColorChange (hwnd);
7017 /* case WM_WININICHANGE: */
7022 case WM_MEASUREITEM:
7024 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7026 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7027 case PGM_FORWARDMOUSE:
7028 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7031 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7032 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7033 uMsg, wParam, lParam);
7034 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7041 TOOLBAR_Register (void)
7045 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7046 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7047 wndClass.lpfnWndProc = ToolbarWindowProc;
7048 wndClass.cbClsExtra = 0;
7049 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7050 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7051 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7052 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7054 RegisterClassW (&wndClass);
7059 TOOLBAR_Unregister (void)
7061 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7064 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7069 /* Check if the entry already exists */
7070 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7072 /* If this is a new entry we must create it and insert into the array */
7077 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7080 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7081 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7096 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7100 for (i = 0; i < *cies; i++)
7110 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7118 for (i = 0; i < cies; i++)
7120 if (pies[i]->id == id)
7132 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7134 HIMAGELIST himlDef = 0;
7135 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7138 himlDef = pie->himl;
7144 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7146 if (infoPtr->bUnicode)
7147 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
7154 nmtba.iItem = nmtb->iItem;
7155 nmtba.pszText = Buffer;
7156 nmtba.cchText = 256;
7157 ZeroMemory(nmtba.pszText, nmtba.cchText);
7159 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
7161 int ccht = strlen(nmtba.pszText);
7163 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7164 nmtb->pszText, nmtb->cchText);
7166 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7175 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7176 int iItem, PCUSTOMBUTTON btnInfo)
7180 /* MSDN states that iItem is the index of the button, rather than the
7181 * command ID as used by every other NMTOOLBAR notification */
7183 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7185 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);