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_NORMAL;
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) + OFFSET_X;
873 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
876 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
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 /* send TBN_QUERYINSERT notification */
1805 nmtb.iItem = nIndexFrom; /* FIXME: this doesn't look right */
1806 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1808 PCUSTOMBUTTON btnInfo;
1810 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1811 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1813 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
1815 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
1816 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1817 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1818 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
1821 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
1823 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
1825 /* last item is always separator, so -2 instead of -1 */
1826 if (nIndexTo >= (count - 2))
1827 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
1829 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
1831 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
1832 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1834 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1838 static void TOOLBAR_Cust_AddButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
1842 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
1844 /* send TBN_QUERYINSERT notification */
1845 nmtb.iItem = nIndexAvail; /* FIXME: this doesn't look right */
1846 if (TOOLBAR_SendNotify((NMHDR *)&nmtb, custInfo->tbInfo, TBN_QUERYINSERT))
1848 PCUSTOMBUTTON btnInfo;
1850 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1851 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1852 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
1854 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
1856 if (nIndexAvail != 0) /* index == 0 indicates separator */
1858 /* remove from 'available buttons' list */
1859 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
1860 if (nIndexAvail == count-1)
1861 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
1863 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
1867 PCUSTOMBUTTON btnNew;
1869 /* duplicate 'separator' button */
1870 btnNew = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1871 memcpy(btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1875 /* insert into 'toolbar button' list */
1876 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
1877 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
1879 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
1881 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1885 static void TOOLBAR_Cust_RemoveButton(PCUSTDLG_INFO custInfo, HWND hwnd, INT index)
1887 PCUSTOMBUTTON btnInfo;
1888 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1890 TRACE("Remove: index %d\n", index);
1892 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
1894 /* send TBN_QUERYDELETE notification */
1895 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
1899 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
1900 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
1902 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1904 /* insert into 'available button' list */
1905 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
1906 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
1910 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
1914 /* drag list notification function for toolbar buttons list box */
1915 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1917 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1918 switch (pDLI->uNotification)
1922 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1923 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1924 /* no dragging for last item (separator) */
1925 if (nCurrentItem >= (nCount - 1)) return FALSE;
1930 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1931 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1932 /* no dragging past last item (separator) */
1933 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
1935 DrawInsert(hwnd, hwndList, nCurrentItem);
1936 /* FIXME: native uses "move button" cursor */
1937 return DL_COPYCURSOR;
1940 /* not over toolbar buttons list */
1941 if (nCurrentItem < 0)
1943 POINT ptWindow = pDLI->ptCursor;
1944 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1945 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1946 /* over available buttons list? */
1947 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1948 /* FIXME: native uses "move button" cursor */
1949 return DL_COPYCURSOR;
1951 /* clear drag arrow */
1952 DrawInsert(hwnd, hwndList, -1);
1953 return DL_STOPCURSOR;
1957 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1958 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
1959 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
1960 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
1962 /* clear drag arrow */
1963 DrawInsert(hwnd, hwndList, -1);
1965 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
1967 /* not over toolbar buttons list */
1970 POINT ptWindow = pDLI->ptCursor;
1971 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
1972 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
1973 /* over available buttons list? */
1974 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
1975 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
1980 /* Clear drag arrow */
1981 DrawInsert(hwnd, hwndList, -1);
1988 /* drag list notification function for available buttons list box */
1989 static LRESULT TOOLBAR_Cust_AvailDragListNotification(PCUSTDLG_INFO custInfo, HWND hwnd, DRAGLISTINFO *pDLI)
1991 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
1992 switch (pDLI->uNotification)
1998 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
1999 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2000 /* no dragging past last item (separator) */
2001 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2003 DrawInsert(hwnd, hwndList, nCurrentItem);
2004 /* FIXME: native uses "move button" cursor */
2005 return DL_COPYCURSOR;
2008 /* not over toolbar buttons list */
2009 if (nCurrentItem < 0)
2011 POINT ptWindow = pDLI->ptCursor;
2012 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2013 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2014 /* over available buttons list? */
2015 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2016 /* FIXME: native uses "move button" cursor */
2017 return DL_COPYCURSOR;
2019 /* clear drag arrow */
2020 DrawInsert(hwnd, hwndList, -1);
2021 return DL_STOPCURSOR;
2025 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2026 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2027 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2028 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2030 /* clear drag arrow */
2031 DrawInsert(hwnd, hwndList, -1);
2033 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2037 /* Clear drag arrow */
2038 DrawInsert(hwnd, hwndList, -1);
2044 extern UINT uDragListMessage;
2046 /***********************************************************************
2047 * TOOLBAR_CustomizeDialogProc
2048 * This function implements the toolbar customization dialog.
2050 static INT_PTR CALLBACK
2051 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2053 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2054 PCUSTOMBUTTON btnInfo;
2056 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2061 custInfo = (PCUSTDLG_INFO)lParam;
2062 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2070 infoPtr = custInfo->tbInfo;
2072 /* send TBN_QUERYINSERT notification */
2073 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2075 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
2078 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
2079 nmtb.iItem = (int)hwnd;
2080 /* Send TBN_INITCUSTOMIZE notification */
2081 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
2084 TRACE("TBNRF_HIDEHELP requested\n");
2085 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2088 /* add items to 'toolbar buttons' list and check if removable */
2089 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2091 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2092 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2093 btnInfo->btn.fsStyle = BTNS_SEP;
2094 btnInfo->bVirtual = FALSE;
2095 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2097 /* send TBN_QUERYDELETE notification */
2098 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2100 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2101 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2104 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2106 /* insert separator button into 'available buttons' list */
2107 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2108 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2109 btnInfo->btn.fsStyle = BTNS_SEP;
2110 btnInfo->bVirtual = FALSE;
2111 btnInfo->bRemovable = TRUE;
2112 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2113 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2114 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2116 /* insert all buttons into dsa */
2119 /* send TBN_GETBUTTONINFO notification */
2122 nmtb.pszText = Buffer;
2125 /* Clear previous button's text */
2126 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2128 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2131 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
2132 nmtb.tbButton.fsStyle, i,
2133 nmtb.tbButton.idCommand,
2134 nmtb.tbButton.iString,
2135 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2138 /* insert button into the apropriate list */
2139 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2142 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2143 btnInfo->bVirtual = FALSE;
2144 btnInfo->bRemovable = TRUE;
2148 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2149 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2152 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
2153 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2155 if (lstrlenW(nmtb.pszText))
2156 lstrcpyW(btnInfo->text, nmtb.pszText);
2157 else if (nmtb.tbButton.iString >= 0 &&
2158 nmtb.tbButton.iString < infoPtr->nNumStrings)
2160 lstrcpyW(btnInfo->text,
2161 infoPtr->strings[nmtb.tbButton.iString]);
2166 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2169 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2171 /* select first item in the 'available' list */
2172 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2174 /* append 'virtual' separator button to the 'toolbar buttons' list */
2175 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
2176 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2177 btnInfo->btn.fsStyle = BTNS_SEP;
2178 btnInfo->bVirtual = TRUE;
2179 btnInfo->bRemovable = FALSE;
2180 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2181 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2182 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2184 /* select last item in the 'toolbar' list */
2185 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2186 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2188 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2189 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2191 /* set focus and disable buttons */
2192 PostMessageW (hwnd, WM_USER, 0, 0);
2197 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2198 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2199 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2200 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2204 EndDialog(hwnd, FALSE);
2208 switch (LOWORD(wParam))
2210 case IDC_TOOLBARBTN_LBOX:
2211 if (HIWORD(wParam) == LBN_SELCHANGE)
2213 PCUSTOMBUTTON btnInfo;
2218 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2219 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2221 /* send TBN_QUERYINSERT notification */
2223 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2226 /* get list box item */
2227 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2229 if (index == (count - 1))
2231 /* last item (virtual separator) */
2232 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2233 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2235 else if (index == (count - 2))
2237 /* second last item (last non-virtual item) */
2238 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2239 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2241 else if (index == 0)
2244 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2245 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2249 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2250 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2253 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2257 case IDC_MOVEUP_BTN:
2259 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2260 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2264 case IDC_MOVEDN_BTN: /* move down */
2266 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2267 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2271 case IDC_REMOVE_BTN: /* remove button */
2273 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2275 if (LB_ERR == index)
2278 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2282 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2285 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2288 case IDOK: /* Add button */
2293 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2294 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2296 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2301 EndDialog(hwnd, FALSE);
2311 /* delete items from 'toolbar buttons' listbox*/
2312 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2313 for (i = 0; i < count; i++)
2315 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2317 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2319 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2322 /* delete items from 'available buttons' listbox*/
2323 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2324 for (i = 0; i < count; i++)
2326 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2328 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2330 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2335 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2337 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2342 COLORREF oldText = 0;
2346 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2347 if (btnInfo == NULL)
2349 FIXME("btnInfo invalid!\n");
2353 /* set colors and select objects */
2354 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2355 if (btnInfo->bVirtual)
2356 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2358 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2359 hPen = CreatePen( PS_SOLID, 1,
2360 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2361 hOldPen = SelectObject (lpdis->hDC, hPen );
2362 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2364 /* fill background rectangle */
2365 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2366 lpdis->rcItem.right, lpdis->rcItem.bottom);
2368 /* calculate button and text rectangles */
2369 CopyRect (&rcButton, &lpdis->rcItem);
2370 InflateRect (&rcButton, -1, -1);
2371 CopyRect (&rcText, &rcButton);
2372 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2373 rcText.left = rcButton.right + 2;
2375 /* draw focus rectangle */
2376 if (lpdis->itemState & ODS_FOCUS)
2377 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2380 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2381 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2383 /* draw image and text */
2384 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2385 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2386 btnInfo->btn.iBitmap));
2387 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2388 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2390 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2391 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2393 /* delete objects and reset colors */
2394 SelectObject (lpdis->hDC, hOldBrush);
2395 SelectObject (lpdis->hDC, hOldPen);
2396 SetBkColor (lpdis->hDC, oldBk);
2397 SetTextColor (lpdis->hDC, oldText);
2398 DeleteObject( hPen );
2403 case WM_MEASUREITEM:
2404 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2406 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2408 lpmis->itemHeight = 15 + 8; /* default height */
2415 if (uDragListMessage && (uMsg == uDragListMessage))
2417 if (wParam == IDC_TOOLBARBTN_LBOX)
2419 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2420 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2421 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2424 else if (wParam == IDC_AVAILBTN_LBOX)
2426 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2427 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2428 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2437 /***********************************************************************
2438 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2442 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2445 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2446 INT nIndex = 0, nButtons, nCount;
2450 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2454 if (lpAddBmp->hInst == HINST_COMMCTRL)
2456 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2458 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2460 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2465 TRACE ("adding %d internal bitmaps!\n", nButtons);
2467 /* Windows resize all the buttons to the size of a newly added standard image */
2468 if (lpAddBmp->nID & 1)
2471 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2472 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2474 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2475 MAKELPARAM((WORD)24, (WORD)24));
2476 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2477 MAKELPARAM((WORD)31, (WORD)30));
2482 SendMessageW (hwnd, TB_SETBITMAPSIZE, 0,
2483 MAKELPARAM((WORD)16, (WORD)16));
2484 SendMessageW (hwnd, TB_SETBUTTONSIZE, 0,
2485 MAKELPARAM((WORD)22, (WORD)22));
2488 TOOLBAR_CalcToolbar (hwnd);
2492 nButtons = (INT)wParam;
2496 TRACE ("adding %d bitmaps!\n", nButtons);
2499 if (!infoPtr->cimlDef) {
2500 /* create new default image list */
2501 TRACE ("creating default image list!\n");
2503 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2504 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2505 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2506 infoPtr->himlInt = himlDef;
2509 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2513 WARN("No default image list available\n");
2517 nCount = ImageList_GetImageCount(himlDef);
2519 /* Add bitmaps to the default image list */
2520 if (lpAddBmp->hInst == NULL)
2523 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2524 HDC hdcImage, hdcBitmap;
2526 /* copy the bitmap before adding it so that the user's bitmap
2527 * doesn't get modified.
2529 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2531 hdcImage = CreateCompatibleDC(0);
2532 hdcBitmap = CreateCompatibleDC(0);
2534 /* create new bitmap */
2535 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2536 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2537 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2539 /* Copy the user's image */
2540 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2541 hdcBitmap, 0, 0, SRCCOPY);
2543 SelectObject (hdcImage, hOldBitmapLoad);
2544 SelectObject (hdcBitmap, hOldBitmapBitmap);
2545 DeleteDC (hdcImage);
2546 DeleteDC (hdcBitmap);
2548 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2549 DeleteObject (hbmLoad);
2551 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2553 /* Add system bitmaps */
2554 switch (lpAddBmp->nID)
2556 case IDB_STD_SMALL_COLOR:
2557 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2558 MAKEINTRESOURCEA(IDB_STD_SMALL));
2559 nIndex = ImageList_AddMasked (himlDef,
2560 hbmLoad, comctl32_color.clrBtnFace);
2561 DeleteObject (hbmLoad);
2564 case IDB_STD_LARGE_COLOR:
2565 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2566 MAKEINTRESOURCEA(IDB_STD_LARGE));
2567 nIndex = ImageList_AddMasked (himlDef,
2568 hbmLoad, comctl32_color.clrBtnFace);
2569 DeleteObject (hbmLoad);
2572 case IDB_VIEW_SMALL_COLOR:
2573 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2574 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2575 nIndex = ImageList_AddMasked (himlDef,
2576 hbmLoad, comctl32_color.clrBtnFace);
2577 DeleteObject (hbmLoad);
2580 case IDB_VIEW_LARGE_COLOR:
2581 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2582 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2583 nIndex = ImageList_AddMasked (himlDef,
2584 hbmLoad, comctl32_color.clrBtnFace);
2585 DeleteObject (hbmLoad);
2588 case IDB_HIST_SMALL_COLOR:
2589 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2590 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2591 nIndex = ImageList_AddMasked (himlDef,
2592 hbmLoad, comctl32_color.clrBtnFace);
2593 DeleteObject (hbmLoad);
2596 case IDB_HIST_LARGE_COLOR:
2597 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2598 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2599 nIndex = ImageList_AddMasked (himlDef,
2600 hbmLoad, comctl32_color.clrBtnFace);
2601 DeleteObject (hbmLoad);
2605 nIndex = ImageList_GetImageCount (himlDef);
2606 ERR ("invalid imagelist!\n");
2612 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2613 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2614 DeleteObject (hbmLoad);
2617 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2619 if (infoPtr->nNumBitmapInfos == 0)
2621 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2625 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2626 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2627 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2630 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2631 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2632 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2634 infoPtr->nNumBitmapInfos++;
2635 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2639 INT imagecount = ImageList_GetImageCount(himlDef);
2641 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2643 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",
2644 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2645 infoPtr->nNumBitmaps+nButtons,imagecount);
2647 infoPtr->nNumBitmaps = imagecount;
2650 infoPtr->nNumBitmaps += nButtons;
2653 InvalidateRect(hwnd, NULL, TRUE);
2660 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2662 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2663 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2664 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2666 TRACE("adding %d buttons!\n", wParam);
2668 nAddButtons = (UINT)wParam;
2669 nOldButtons = infoPtr->nNumButtons;
2670 nNewButtons = nOldButtons + nAddButtons;
2672 if (infoPtr->nNumButtons == 0) {
2674 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2677 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2679 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2680 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2681 nOldButtons * sizeof(TBUTTON_INFO));
2685 infoPtr->nNumButtons = nNewButtons;
2687 /* insert new button data */
2688 for (nCount = 0; nCount < nAddButtons; nCount++) {
2689 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2690 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2691 btnPtr->idCommand = lpTbb[nCount].idCommand;
2692 btnPtr->fsState = lpTbb[nCount].fsState;
2693 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2694 btnPtr->dwData = lpTbb[nCount].dwData;
2695 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2696 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2698 btnPtr->iString = lpTbb[nCount].iString;
2699 btnPtr->bHot = FALSE;
2701 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2704 ZeroMemory (&ti, sizeof(ti));
2705 ti.cbSize = sizeof(ti);
2707 ti.uId = btnPtr->idCommand;
2709 ti.lpszText = LPSTR_TEXTCALLBACKW;
2711 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2716 TOOLBAR_CalcToolbar (hwnd);
2718 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2720 InvalidateRect(hwnd, NULL, TRUE);
2727 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2730 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2731 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2733 TRACE("adding %d buttons!\n", wParam);
2735 nAddButtons = (UINT)wParam;
2736 nOldButtons = infoPtr->nNumButtons;
2737 nNewButtons = nOldButtons + nAddButtons;
2739 if (infoPtr->nNumButtons == 0) {
2741 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2744 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2746 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2747 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2748 nOldButtons * sizeof(TBUTTON_INFO));
2752 infoPtr->nNumButtons = nNewButtons;
2754 /* insert new button data */
2755 for (nCount = 0; nCount < nAddButtons; nCount++) {
2756 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2757 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2758 btnPtr->idCommand = lpTbb[nCount].idCommand;
2759 btnPtr->fsState = lpTbb[nCount].fsState;
2760 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2761 btnPtr->dwData = lpTbb[nCount].dwData;
2762 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2763 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2765 btnPtr->iString = lpTbb[nCount].iString;
2766 btnPtr->bHot = FALSE;
2768 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2771 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2772 ti.cbSize = sizeof (TTTOOLINFOW);
2774 ti.uId = btnPtr->idCommand;
2776 ti.lpszText = LPSTR_TEXTCALLBACKW;
2779 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2784 TOOLBAR_CalcToolbar (hwnd);
2786 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2788 InvalidateRect(hwnd, NULL, TRUE);
2795 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 if ((wParam) && (HIWORD(lParam) == 0)) {
2803 TRACE("adding string from resource!\n");
2805 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2808 TRACE("len=%d \"%s\"\n", len, szString);
2809 nIndex = infoPtr->nNumStrings;
2810 if (infoPtr->nNumStrings == 0) {
2812 Alloc (sizeof(LPWSTR));
2815 LPWSTR *oldStrings = infoPtr->strings;
2817 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2818 memcpy (&infoPtr->strings[0], &oldStrings[0],
2819 sizeof(LPWSTR) * infoPtr->nNumStrings);
2823 /*Alloc zeros out the allocated memory*/
2824 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2825 infoPtr->nNumStrings++;
2828 LPSTR p = (LPSTR)lParam;
2833 TRACE("adding string(s) from array!\n");
2835 nIndex = infoPtr->nNumStrings;
2838 TRACE("len=%d \"%s\"\n", len, p);
2840 if (infoPtr->nNumStrings == 0) {
2842 Alloc (sizeof(LPWSTR));
2845 LPWSTR *oldStrings = infoPtr->strings;
2847 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2848 memcpy (&infoPtr->strings[0], &oldStrings[0],
2849 sizeof(LPWSTR) * infoPtr->nNumStrings);
2853 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2854 infoPtr->nNumStrings++;
2865 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2867 #define MAX_RESOURCE_STRING_LENGTH 512
2868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2871 if ((wParam) && (HIWORD(lParam) == 0)) {
2872 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2874 TRACE("adding string from resource!\n");
2876 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2877 szString, MAX_RESOURCE_STRING_LENGTH);
2879 TRACE("len=%d %s\n", len, debugstr_w(szString));
2880 TRACE("First char: 0x%x\n", *szString);
2881 if (szString[0] == L'|')
2883 PWSTR p = szString + 1;
2885 nIndex = infoPtr->nNumStrings;
2886 while (*p != L'|' && *p != L'\0') {
2889 if (infoPtr->nNumStrings == 0) {
2890 infoPtr->strings = Alloc (sizeof(LPWSTR));
2894 LPWSTR *oldStrings = infoPtr->strings;
2895 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2896 memcpy(&infoPtr->strings[0], &oldStrings[0],
2897 sizeof(LPWSTR) * infoPtr->nNumStrings);
2901 np=strchrW (p, '|');
2909 TRACE("len=%d %s\n", len, debugstr_w(p));
2910 infoPtr->strings[infoPtr->nNumStrings] =
2911 Alloc (sizeof(WCHAR)*(len+1));
2912 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2913 infoPtr->nNumStrings++;
2920 nIndex = infoPtr->nNumStrings;
2921 if (infoPtr->nNumStrings == 0) {
2923 Alloc (sizeof(LPWSTR));
2926 LPWSTR *oldStrings = infoPtr->strings;
2928 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2929 memcpy (&infoPtr->strings[0], &oldStrings[0],
2930 sizeof(LPWSTR) * infoPtr->nNumStrings);
2934 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2935 infoPtr->nNumStrings++;
2939 LPWSTR p = (LPWSTR)lParam;
2944 TRACE("adding string(s) from array!\n");
2945 nIndex = infoPtr->nNumStrings;
2949 TRACE("len=%d %s\n", len, debugstr_w(p));
2950 if (infoPtr->nNumStrings == 0) {
2952 Alloc (sizeof(LPWSTR));
2955 LPWSTR *oldStrings = infoPtr->strings;
2957 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2958 memcpy (&infoPtr->strings[0], &oldStrings[0],
2959 sizeof(LPWSTR) * infoPtr->nNumStrings);
2963 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2964 infoPtr->nNumStrings++;
2975 TOOLBAR_AutoSize (HWND hwnd)
2977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2983 UINT uPosFlags = SWP_NOZORDER;
2985 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2987 parent = GetParent (hwnd);
2988 GetClientRect(parent, &parent_rect);
2990 x = parent_rect.left;
2991 y = parent_rect.top;
2993 /* FIXME: we should be able to early out if nothing */
2994 /* has changed with nWidth != parent_rect width */
2996 if (infoPtr->dwStyle & CCS_NORESIZE) {
2997 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3000 TOOLBAR_CalcToolbar (hwnd);
3003 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3004 TOOLBAR_CalcToolbar (hwnd);
3005 InvalidateRect( hwnd, NULL, TRUE );
3006 cy = infoPtr->nHeight;
3007 cx = infoPtr->nWidth;
3009 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
3010 GetWindowRect(hwnd, &window_rect);
3011 ScreenToClient(parent, (LPPOINT)&window_rect.left);
3012 y = window_rect.top;
3014 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
3015 GetWindowRect(hwnd, &window_rect);
3016 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3020 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3021 uPosFlags |= SWP_NOMOVE;
3023 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3024 cy += GetSystemMetrics(SM_CYEDGE);
3026 if (infoPtr->dwStyle & WS_BORDER)
3029 cy += GetSystemMetrics(SM_CYEDGE);
3030 cx += GetSystemMetrics(SM_CYEDGE);
3033 infoPtr->bAutoSize = TRUE;
3034 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
3035 /* The following line makes sure that the infoPtr->bAutoSize is turned off
3036 * after the setwindowpos calls */
3037 infoPtr->bAutoSize = FALSE;
3044 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
3046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3048 return infoPtr->nNumButtons;
3053 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3055 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3057 if (infoPtr == NULL) {
3058 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
3059 ERR("infoPtr == NULL!\n");
3063 infoPtr->dwStructSize = (DWORD)wParam;
3070 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3073 TBUTTON_INFO *btnPtr;
3076 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
3078 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3082 btnPtr = &infoPtr->buttons[nIndex];
3083 btnPtr->iBitmap = LOWORD(lParam);
3085 /* we HAVE to erase the background, the new bitmap could be */
3087 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3094 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3097 TBUTTON_INFO *btnPtr;
3100 BOOL bChecked = FALSE;
3102 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3104 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
3109 btnPtr = &infoPtr->buttons[nIndex];
3111 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
3113 if (LOWORD(lParam) == FALSE)
3114 btnPtr->fsState &= ~TBSTATE_CHECKED;
3116 if (btnPtr->fsStyle & BTNS_GROUP) {
3118 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3119 if (nOldIndex == nIndex)
3121 if (nOldIndex != -1)
3122 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3124 btnPtr->fsState |= TBSTATE_CHECKED;
3127 if( bChecked != LOWORD(lParam) )
3129 if (nOldIndex != -1)
3130 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
3131 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3134 /* FIXME: Send a WM_NOTIFY?? */
3141 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3145 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3150 TOOLBAR_Customize (HWND hwnd)
3152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3153 CUSTDLG_INFO custInfo;
3159 custInfo.tbInfo = infoPtr;
3160 custInfo.tbHwnd = hwnd;
3162 /* send TBN_BEGINADJUST notification */
3163 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3166 if (!(hRes = FindResourceW (COMCTL32_hModule,
3167 MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3168 (LPWSTR)RT_DIALOG)))
3171 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3174 ret = DialogBoxIndirectParamW ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3175 (LPDLGTEMPLATEW)template,
3177 TOOLBAR_CustomizeDialogProc,
3180 /* send TBN_ENDADJUST notification */
3181 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3189 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3191 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3192 INT nIndex = (INT)wParam;
3195 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3198 memset(&nmtb, 0, sizeof(nmtb));
3199 nmtb.iItem = nIndex;
3200 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3202 if ((infoPtr->hwndToolTip) &&
3203 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3206 ZeroMemory (&ti, sizeof(ti));
3207 ti.cbSize = sizeof(ti);
3209 ti.uId = infoPtr->buttons[nIndex].idCommand;
3211 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
3214 if (infoPtr->nNumButtons == 1) {
3215 TRACE(" simple delete!\n");
3216 Free (infoPtr->buttons);
3217 infoPtr->buttons = NULL;
3218 infoPtr->nNumButtons = 0;
3221 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3222 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3224 infoPtr->nNumButtons--;
3225 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3227 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3228 nIndex * sizeof(TBUTTON_INFO));
3231 if (nIndex < infoPtr->nNumButtons) {
3232 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3233 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3239 TOOLBAR_CalcToolbar (hwnd);
3241 InvalidateRect (hwnd, NULL, TRUE);
3248 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3251 TBUTTON_INFO *btnPtr;
3255 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3257 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3262 btnPtr = &infoPtr->buttons[nIndex];
3264 bState = btnPtr->fsState & TBSTATE_ENABLED;
3266 /* update the toolbar button state */
3267 if(LOWORD(lParam) == FALSE) {
3268 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3270 btnPtr->fsState |= TBSTATE_ENABLED;
3273 /* redraw the button only if the state of the button changed */
3274 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3275 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3281 static inline LRESULT
3282 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3286 return infoPtr->bAnchor;
3291 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3296 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3300 return infoPtr->buttons[nIndex].iBitmap;
3304 static inline LRESULT
3305 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3307 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3312 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3315 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3316 INT nIndex = (INT)wParam;
3317 TBUTTON_INFO *btnPtr;
3319 if (infoPtr == NULL)
3325 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3328 btnPtr = &infoPtr->buttons[nIndex];
3329 lpTbb->iBitmap = btnPtr->iBitmap;
3330 lpTbb->idCommand = btnPtr->idCommand;
3331 lpTbb->fsState = btnPtr->fsState;
3332 lpTbb->fsStyle = btnPtr->fsStyle;
3333 lpTbb->bReserved[0] = 0;
3334 lpTbb->bReserved[1] = 0;
3335 lpTbb->dwData = btnPtr->dwData;
3336 lpTbb->iString = btnPtr->iString;
3343 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3345 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3346 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3347 TBUTTON_INFO *btnPtr;
3350 if (infoPtr == NULL)
3352 if (lpTbInfo == NULL)
3354 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3357 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3358 lpTbInfo->dwMask & 0x80000000);
3362 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3364 if (lpTbInfo->dwMask & TBIF_COMMAND)
3365 lpTbInfo->idCommand = btnPtr->idCommand;
3366 if (lpTbInfo->dwMask & TBIF_IMAGE)
3367 lpTbInfo->iImage = btnPtr->iBitmap;
3368 if (lpTbInfo->dwMask & TBIF_LPARAM)
3369 lpTbInfo->lParam = btnPtr->dwData;
3370 if (lpTbInfo->dwMask & TBIF_SIZE)
3371 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3372 if (lpTbInfo->dwMask & TBIF_STATE)
3373 lpTbInfo->fsState = btnPtr->fsState;
3374 if (lpTbInfo->dwMask & TBIF_STYLE)
3375 lpTbInfo->fsStyle = btnPtr->fsStyle;
3376 if (lpTbInfo->dwMask & TBIF_TEXT) {
3377 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3378 can't use TOOLBAR_GetText here */
3380 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3381 lpText = (LPWSTR)btnPtr->iString;
3382 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3384 lpTbInfo->pszText[0] = '\0';
3391 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3393 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3394 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3395 TBUTTON_INFO *btnPtr;
3398 if (infoPtr == NULL)
3400 if (lpTbInfo == NULL)
3402 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3405 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3406 lpTbInfo->dwMask & 0x80000000);
3410 btnPtr = &infoPtr->buttons[nIndex];
3415 if (lpTbInfo->dwMask & TBIF_COMMAND)
3416 lpTbInfo->idCommand = btnPtr->idCommand;
3417 if (lpTbInfo->dwMask & TBIF_IMAGE)
3418 lpTbInfo->iImage = btnPtr->iBitmap;
3419 if (lpTbInfo->dwMask & TBIF_LPARAM)
3420 lpTbInfo->lParam = btnPtr->dwData;
3421 if (lpTbInfo->dwMask & TBIF_SIZE)
3422 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3423 if (lpTbInfo->dwMask & TBIF_STATE)
3424 lpTbInfo->fsState = btnPtr->fsState;
3425 if (lpTbInfo->dwMask & TBIF_STYLE)
3426 lpTbInfo->fsStyle = btnPtr->fsStyle;
3427 if (lpTbInfo->dwMask & TBIF_TEXT) {
3428 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3429 can't use TOOLBAR_GetText here */
3431 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3432 lpText = (LPWSTR)btnPtr->iString;
3433 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3435 lpTbInfo->pszText[0] = '\0';
3443 TOOLBAR_GetButtonSize (HWND hwnd)
3445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3447 if (infoPtr->nNumButtons > 0)
3448 return MAKELONG((WORD)infoPtr->nButtonWidth,
3449 (WORD)infoPtr->nButtonHeight);
3451 return MAKELONG(8,7);
3456 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3465 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3469 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3471 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3472 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3477 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3484 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3488 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3492 ret = strlenW (lpText);
3495 strcpyW ((LPWSTR)lParam, lpText);
3503 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3505 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3506 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3507 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3511 inline static LRESULT
3512 TOOLBAR_GetExtendedStyle (HWND hwnd)
3514 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3518 return infoPtr->dwExStyle;
3523 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3525 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3526 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3527 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3532 TOOLBAR_GetHotItem (HWND hwnd)
3534 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3536 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3539 if (infoPtr->nHotItem < 0)
3542 return (LRESULT)infoPtr->nHotItem;
3547 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3549 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3550 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3551 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3556 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3558 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3559 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3561 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3563 *lptbim = infoPtr->tbim;
3570 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3574 TRACE("hwnd = %p\n", hwnd);
3576 return (LRESULT)infoPtr->clrInsertMark;
3581 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3583 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3584 TBUTTON_INFO *btnPtr;
3588 if (infoPtr == NULL)
3590 nIndex = (INT)wParam;
3591 btnPtr = &infoPtr->buttons[nIndex];
3592 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3594 lpRect = (LPRECT)lParam;
3597 if (btnPtr->fsState & TBSTATE_HIDDEN)
3600 lpRect->left = btnPtr->rect.left;
3601 lpRect->right = btnPtr->rect.right;
3602 lpRect->bottom = btnPtr->rect.bottom;
3603 lpRect->top = btnPtr->rect.top;
3610 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3613 LPSIZE lpSize = (LPSIZE)lParam;
3618 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3619 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3621 TRACE("maximum size %ld x %ld\n",
3622 infoPtr->rcBound.right - infoPtr->rcBound.left,
3623 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3629 /* << TOOLBAR_GetObject >> */
3633 TOOLBAR_GetPadding (HWND hwnd)
3635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3638 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3639 return (LRESULT) oldPad;
3644 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3647 TBUTTON_INFO *btnPtr;
3651 if (infoPtr == NULL)
3653 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3654 btnPtr = &infoPtr->buttons[nIndex];
3655 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3657 lpRect = (LPRECT)lParam;
3661 lpRect->left = btnPtr->rect.left;
3662 lpRect->right = btnPtr->rect.right;
3663 lpRect->bottom = btnPtr->rect.bottom;
3664 lpRect->top = btnPtr->rect.top;
3671 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3675 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3676 return infoPtr->nRows;
3683 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3688 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3692 return infoPtr->buttons[nIndex].fsState;
3697 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3699 return GetWindowLongW(hwnd, GWL_STYLE);
3704 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3708 if (infoPtr == NULL)
3711 return infoPtr->nMaxTextRows;
3716 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3718 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3720 if (infoPtr == NULL)
3722 return (LRESULT)infoPtr->hwndToolTip;
3727 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3731 TRACE("%s hwnd=%p\n",
3732 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3734 return infoPtr->bUnicode;
3738 inline static LRESULT
3739 TOOLBAR_GetVersion (HWND hwnd)
3741 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3742 return infoPtr->iVersion;
3747 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3749 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3750 TBUTTON_INFO *btnPtr;
3755 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3759 btnPtr = &infoPtr->buttons[nIndex];
3760 if (LOWORD(lParam) == FALSE)
3761 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3763 btnPtr->fsState |= TBSTATE_HIDDEN;
3765 TOOLBAR_CalcToolbar (hwnd);
3767 InvalidateRect (hwnd, NULL, TRUE);
3773 inline static LRESULT
3774 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3776 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3781 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3784 TBUTTON_INFO *btnPtr;
3788 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3792 btnPtr = &infoPtr->buttons[nIndex];
3793 oldState = btnPtr->fsState;
3794 if (LOWORD(lParam) == FALSE)
3795 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3797 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3799 if(oldState != btnPtr->fsState)
3800 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3807 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3810 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3811 INT nIndex = (INT)wParam;
3812 TBUTTON_INFO *oldButtons;
3817 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3820 /* EPP: this seems to be an undocumented call (from my IE4)
3821 * I assume in that case that:
3822 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3823 * - index of insertion is at the end of existing buttons
3824 * I only see this happen with nIndex == -1, but it could have a special
3825 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3827 nIndex = infoPtr->nNumButtons;
3829 } else if (nIndex < 0)
3832 /* If the string passed is not an index, assume address of string
3833 and do our own AddString */
3834 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3838 TRACE("string %s passed instead of index, adding string\n",
3839 debugstr_a((LPSTR)lpTbb->iString));
3840 len = strlen((LPSTR)lpTbb->iString) + 2;
3842 strcpy(ptr, (LPSTR)lpTbb->iString);
3843 ptr[len - 1] = 0; /* ended by two '\0' */
3844 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3848 TRACE("inserting button index=%d\n", nIndex);
3849 if (nIndex > infoPtr->nNumButtons) {
3850 nIndex = infoPtr->nNumButtons;
3851 TRACE("adjust index=%d\n", nIndex);
3854 oldButtons = infoPtr->buttons;
3855 infoPtr->nNumButtons++;
3856 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3857 /* pre insert copy */
3859 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3860 nIndex * sizeof(TBUTTON_INFO));
3863 /* insert new button */
3864 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3865 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3866 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3867 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3868 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3869 /* if passed string and not index, then add string */
3870 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3871 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3874 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3876 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3879 ZeroMemory (&ti, sizeof(ti));
3880 ti.cbSize = sizeof (ti);
3882 ti.uId = lpTbb->idCommand;
3884 ti.lpszText = LPSTR_TEXTCALLBACKW;
3886 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3890 /* post insert copy */
3891 if (nIndex < infoPtr->nNumButtons - 1) {
3892 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3893 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3898 TOOLBAR_CalcToolbar (hwnd);
3900 InvalidateRect (hwnd, NULL, TRUE);
3907 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3910 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3911 INT nIndex = (INT)wParam;
3912 TBUTTON_INFO *oldButtons;
3917 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3920 /* EPP: this seems to be an undocumented call (from my IE4)
3921 * I assume in that case that:
3922 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3923 * - index of insertion is at the end of existing buttons
3924 * I only see this happen with nIndex == -1, but it could have a special
3925 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3927 nIndex = infoPtr->nNumButtons;
3929 } else if (nIndex < 0)
3932 /* If the string passed is not an index, assume address of string
3933 and do our own AddString */
3934 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3938 TRACE("string %s passed instead of index, adding string\n",
3939 debugstr_w((LPWSTR)lpTbb->iString));
3940 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3941 ptr = Alloc(len*sizeof(WCHAR));
3942 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3943 ptr[len - 1] = 0; /* ended by two '\0' */
3944 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3948 TRACE("inserting button index=%d\n", nIndex);
3949 if (nIndex > infoPtr->nNumButtons) {
3950 nIndex = infoPtr->nNumButtons;
3951 TRACE("adjust index=%d\n", nIndex);
3954 oldButtons = infoPtr->buttons;
3955 infoPtr->nNumButtons++;
3956 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3957 /* pre insert copy */
3959 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3960 nIndex * sizeof(TBUTTON_INFO));
3963 /* insert new button */
3964 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3965 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3966 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3967 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3968 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3969 /* if passed string and not index, then add string */
3970 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3971 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3974 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3976 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3979 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3980 ti.cbSize = sizeof (TTTOOLINFOW);
3982 ti.uId = lpTbb->idCommand;
3984 ti.lpszText = LPSTR_TEXTCALLBACKW;
3986 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3990 /* post insert copy */
3991 if (nIndex < infoPtr->nNumButtons - 1) {
3992 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3993 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3998 TOOLBAR_CalcToolbar (hwnd);
4000 InvalidateRect (hwnd, NULL, TRUE);
4006 /* << TOOLBAR_InsertMarkHitTest >> */
4010 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
4012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4015 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4019 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
4024 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
4026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4029 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4033 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
4038 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
4040 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4043 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4047 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
4052 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
4054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4057 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4061 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
4066 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4071 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4075 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
4080 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
4082 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4085 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4089 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
4094 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
4097 tbab.hInst = (HINSTANCE)lParam;
4098 tbab.nID = (UINT_PTR)wParam;
4100 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
4102 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
4107 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
4109 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4110 WCHAR wAccel = (WCHAR)wParam;
4111 UINT* pIDButton = (UINT*)lParam;
4112 WCHAR wszAccel[] = {'&',wAccel,0};
4115 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
4116 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
4118 for (i = 0; i < infoPtr->nNumButtons; i++)
4120 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
4121 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
4122 !(btnPtr->fsState & TBSTATE_HIDDEN))
4124 int iLen = strlenW(wszAccel);
4125 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
4132 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
4137 if (!strncmpiW(lpszStr, wszAccel, iLen))
4139 *pIDButton = btnPtr->idCommand;
4151 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4153 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4156 TBUTTON_INFO *btnPtr;
4158 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
4160 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4164 btnPtr = &infoPtr->buttons[nIndex];
4165 oldState = btnPtr->fsState;
4168 btnPtr->fsState |= TBSTATE_MARKED;
4170 btnPtr->fsState &= ~TBSTATE_MARKED;
4172 if(oldState != btnPtr->fsState)
4173 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4179 /* fixes up an index of a button affected by a move */
4180 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4184 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4186 else if (*pIndex == nIndex)
4187 *pIndex = nMoveIndex;
4191 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4193 else if (*pIndex == nIndex)
4194 *pIndex = nMoveIndex;
4200 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4205 INT nMoveIndex = (INT)lParam;
4206 TBUTTON_INFO button;
4208 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4210 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4211 if ((nIndex == -1) || (nMoveIndex < 0))
4214 if (nMoveIndex > infoPtr->nNumButtons - 1)
4215 nMoveIndex = infoPtr->nNumButtons - 1;
4217 button = infoPtr->buttons[nIndex];
4219 /* move button right */
4220 if (nIndex < nMoveIndex)
4222 nCount = nMoveIndex - nIndex;
4223 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4224 infoPtr->buttons[nMoveIndex] = button;
4226 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4227 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4228 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4229 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4231 else if (nIndex > nMoveIndex) /* move button left */
4233 nCount = nIndex - nMoveIndex;
4234 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4235 infoPtr->buttons[nMoveIndex] = button;
4237 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4238 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4239 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4240 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4243 TOOLBAR_CalcToolbar(hwnd);
4244 InvalidateRect(hwnd, NULL, TRUE);
4251 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4253 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4254 TBUTTON_INFO *btnPtr;
4258 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4262 btnPtr = &infoPtr->buttons[nIndex];
4263 oldState = btnPtr->fsState;
4264 if (LOWORD(lParam) == FALSE)
4265 btnPtr->fsState &= ~TBSTATE_PRESSED;
4267 btnPtr->fsState |= TBSTATE_PRESSED;
4269 if(oldState != btnPtr->fsState)
4270 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4275 /* FIXME: there might still be some confusion her between number of buttons
4276 * and number of bitmaps */
4278 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4281 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4283 int i = 0, nOldButtons = 0, pos = 0;
4284 int nOldBitmaps, nNewBitmaps;
4285 HIMAGELIST himlDef = 0;
4287 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4288 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4289 lpReplace->nButtons);
4291 if (lpReplace->hInstOld == HINST_COMMCTRL)
4293 FIXME("changing standard bitmaps not implemented\n");
4296 else if (lpReplace->hInstOld != 0)
4298 FIXME("resources not in the current module not implemented\n");
4303 hBitmap = (HBITMAP) lpReplace->nIDNew;
4306 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4307 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4308 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4309 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4310 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4312 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4313 nOldButtons = tbi->nButtons;
4314 tbi->nButtons = lpReplace->nButtons;
4315 tbi->hInst = lpReplace->hInstNew;
4316 tbi->nID = lpReplace->nIDNew;
4317 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4320 pos += tbi->nButtons;
4323 if (nOldButtons == 0)
4325 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4329 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4330 nOldBitmaps = ImageList_GetImageCount(himlDef);
4332 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4334 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4335 ImageList_Remove(himlDef, i);
4339 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4340 HDC hdcImage, hdcBitmap;
4342 /* copy the bitmap before adding it so that the user's bitmap
4343 * doesn't get modified.
4345 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4347 hdcImage = CreateCompatibleDC(0);
4348 hdcBitmap = CreateCompatibleDC(0);
4350 /* create new bitmap */
4351 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4352 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4353 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4355 /* Copy the user's image */
4356 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4357 hdcBitmap, 0, 0, SRCCOPY);
4359 SelectObject (hdcImage, hOldBitmapLoad);
4360 SelectObject (hdcBitmap, hOldBitmapBitmap);
4361 DeleteDC (hdcImage);
4362 DeleteDC (hdcBitmap);
4364 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4365 nNewBitmaps = ImageList_GetImageCount(himlDef);
4366 DeleteObject (hbmLoad);
4369 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4371 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4372 pos, nOldBitmaps, nNewBitmaps);
4374 InvalidateRect(hwnd, NULL, TRUE);
4380 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4383 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4384 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4386 if (lpSave == NULL) return 0;
4389 /* save toolbar information */
4390 FIXME("save to \"%s\" \"%s\"\n",
4391 lpSave->pszSubKey, lpSave->pszValueName);
4396 /* restore toolbar information */
4398 FIXME("restore from \"%s\" \"%s\"\n",
4399 lpSave->pszSubKey, lpSave->pszValueName);
4410 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4414 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4420 /* save toolbar information */
4421 FIXME("save to \"%s\" \"%s\"\n",
4422 lpSave->pszSubKey, lpSave->pszValueName);
4427 /* restore toolbar information */
4429 FIXME("restore from \"%s\" \"%s\"\n",
4430 lpSave->pszSubKey, lpSave->pszValueName);
4441 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4444 BOOL bOldAnchor = infoPtr->bAnchor;
4446 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4448 infoPtr->bAnchor = (BOOL)wParam;
4450 /* Native does not remove the hot effect from an already hot button */
4452 return (LRESULT)bOldAnchor;
4457 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4460 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4462 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4465 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4467 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4470 if (infoPtr->nNumButtons > 0)
4471 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4472 infoPtr->nNumButtons,
4473 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4474 LOWORD(lParam), HIWORD(lParam));
4476 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4477 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4480 if ((himlDef == infoPtr->himlInt) &&
4481 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4483 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4484 infoPtr->nBitmapHeight);
4492 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4494 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4495 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4496 TBUTTON_INFO *btnPtr;
4502 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4505 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4506 lptbbi->dwMask & 0x80000000);
4510 btnPtr = &infoPtr->buttons[nIndex];
4511 if (lptbbi->dwMask & TBIF_COMMAND)
4512 btnPtr->idCommand = lptbbi->idCommand;
4513 if (lptbbi->dwMask & TBIF_IMAGE)
4514 btnPtr->iBitmap = lptbbi->iImage;
4515 if (lptbbi->dwMask & TBIF_LPARAM)
4516 btnPtr->dwData = lptbbi->lParam;
4517 if (lptbbi->dwMask & TBIF_SIZE)
4518 btnPtr->cx = lptbbi->cx;
4519 if (lptbbi->dwMask & TBIF_STATE)
4520 btnPtr->fsState = lptbbi->fsState;
4521 if (lptbbi->dwMask & TBIF_STYLE)
4522 btnPtr->fsStyle = lptbbi->fsStyle;
4524 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4525 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4526 /* iString is index, zero it to make Str_SetPtr succeed */
4529 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4532 /* save the button rect to see if we need to redraw the whole toolbar */
4533 oldBtnRect = btnPtr->rect;
4534 TOOLBAR_CalcToolbar(hwnd);
4536 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4537 InvalidateRect(hwnd, NULL, TRUE);
4539 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4546 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4549 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4550 TBUTTON_INFO *btnPtr;
4556 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4559 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4560 lptbbi->dwMask & 0x80000000);
4564 btnPtr = &infoPtr->buttons[nIndex];
4565 if (lptbbi->dwMask & TBIF_COMMAND)
4566 btnPtr->idCommand = lptbbi->idCommand;
4567 if (lptbbi->dwMask & TBIF_IMAGE)
4568 btnPtr->iBitmap = lptbbi->iImage;
4569 if (lptbbi->dwMask & TBIF_LPARAM)
4570 btnPtr->dwData = lptbbi->lParam;
4571 if (lptbbi->dwMask & TBIF_SIZE)
4572 btnPtr->cx = lptbbi->cx;
4573 if (lptbbi->dwMask & TBIF_STATE)
4574 btnPtr->fsState = lptbbi->fsState;
4575 if (lptbbi->dwMask & TBIF_STYLE)
4576 btnPtr->fsStyle = lptbbi->fsStyle;
4578 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4579 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4580 /* iString is index, zero it to make Str_SetPtr succeed */
4582 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4585 /* save the button rect to see if we need to redraw the whole toolbar */
4586 oldBtnRect = btnPtr->rect;
4587 TOOLBAR_CalcToolbar(hwnd);
4589 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4590 InvalidateRect(hwnd, NULL, TRUE);
4592 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4599 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4602 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4604 if ((cx < 0) || (cy < 0))
4606 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4610 /* The documentation claims you can only change the button size before
4611 * any button has been added. But this is wrong.
4612 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4613 * it to the toolbar, and it checks that the return value is nonzero - mjm
4614 * Further testing shows that we must actually perform the change too.
4617 * The documentation also does not mention that if 0 is supplied for
4618 * either size, the system changes it to the default of 24 wide and
4619 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4621 infoPtr->nButtonWidth = (cx) ? cx : 24;
4622 infoPtr->nButtonHeight = (cy) ? cy : 22;
4628 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4632 if (infoPtr == NULL) {
4633 TRACE("Toolbar not initialized yet?????\n");
4637 /* if setting to current values, ignore */
4638 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4639 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4640 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4641 infoPtr->cxMin, infoPtr->cxMax);
4645 /* save new values */
4646 infoPtr->cxMin = (INT)LOWORD(lParam);
4647 infoPtr->cxMax = (INT)HIWORD(lParam);
4649 /* if both values are 0 then we are done */
4651 TRACE("setting both min and max to 0, norecalc\n");
4655 /* otherwise we need to recalc the toolbar and in some cases
4656 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4657 which doesn't actually draw - GA). */
4658 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4659 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4661 TOOLBAR_CalcToolbar (hwnd);
4663 InvalidateRect (hwnd, NULL, TRUE);
4670 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4673 INT nIndex = (INT)wParam;
4675 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4678 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4680 if (infoPtr->hwndToolTip) {
4682 FIXME("change tool tip!\n");
4691 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4694 HIMAGELIST himl = (HIMAGELIST)lParam;
4695 HIMAGELIST himlTemp;
4698 if (infoPtr->iVersion >= 5)
4701 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4702 &infoPtr->cimlDis, himl, id);
4704 /* FIXME: redraw ? */
4706 return (LRESULT)himlTemp;
4711 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4716 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4718 dwTemp = infoPtr->dwDTFlags;
4719 infoPtr->dwDTFlags =
4720 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4722 return (LRESULT)dwTemp;
4725 /* This function differs a bit from what MSDN says it does:
4726 * 1. lParam contains extended style flags to OR with current style
4727 * (MSDN isn't clear on the OR bit)
4728 * 2. wParam appears to contain extended style flags to be reset
4729 * (MSDN says that this parameter is reserved)
4732 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4737 dwTemp = infoPtr->dwExStyle;
4738 infoPtr->dwExStyle &= ~wParam;
4739 infoPtr->dwExStyle |= (DWORD)lParam;
4741 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4743 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4744 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4745 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4747 TOOLBAR_CalcToolbar (hwnd);
4749 TOOLBAR_AutoSize(hwnd);
4751 InvalidateRect(hwnd, NULL, TRUE);
4753 return (LRESULT)dwTemp;
4758 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4761 HIMAGELIST himlTemp;
4762 HIMAGELIST himl = (HIMAGELIST)lParam;
4765 if (infoPtr->iVersion >= 5)
4768 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4770 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4771 &infoPtr->cimlHot, himl, id);
4773 /* FIXME: redraw ? */
4775 return (LRESULT)himlTemp;
4779 /* Makes previous hot button no longer hot, makes the specified
4780 * button hot and sends appropriate notifications. dwReason is one or
4781 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4782 * NOTE 1: this function does not validate nHit
4783 * NOTE 2: the name of this function is completely made up and
4784 * not based on any documentation from Microsoft. */
4786 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4788 if (infoPtr->nHotItem != nHit)
4790 NMTBHOTITEM nmhotitem;
4791 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4792 LRESULT no_highlight;
4794 /* Remove the effect of an old hot button if the button was
4795 drawn with the hot button effect */
4796 if(infoPtr->nHotItem >= 0)
4798 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4799 oldBtnPtr->bHot = FALSE;
4802 infoPtr->nHotItem = nHit;
4804 /* It's not a separator or in nowhere. It's a hot button. */
4806 btnPtr = &infoPtr->buttons[nHit];
4808 nmhotitem.dwFlags = dwReason;
4810 nmhotitem.idOld = oldBtnPtr->idCommand;
4812 nmhotitem.dwFlags |= HICF_ENTERING;
4814 nmhotitem.idNew = btnPtr->idCommand;
4816 nmhotitem.dwFlags |= HICF_LEAVING;
4818 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4820 /* now invalidate the old and new buttons so they will be painted */
4822 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4823 if (btnPtr && !no_highlight)
4825 btnPtr->bHot = TRUE;
4826 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4832 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4834 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4835 INT nOldHotItem = infoPtr->nHotItem;
4837 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4839 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4842 /* NOTE: an application can still remove the hot item even if anchor
4843 * highlighting is enabled */
4845 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4846 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4848 if (nOldHotItem < 0)
4851 return (LRESULT)nOldHotItem;
4856 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4859 HIMAGELIST himlTemp;
4860 HIMAGELIST himl = (HIMAGELIST)lParam;
4863 if (infoPtr->iVersion >= 5)
4866 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4867 &infoPtr->cimlDef, himl, id);
4869 infoPtr->nNumBitmaps = 0;
4870 for (i = 0; i < infoPtr->cimlDef; i++)
4871 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4873 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4874 &infoPtr->nBitmapHeight);
4875 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4876 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4877 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4879 InvalidateRect(hwnd, NULL, TRUE);
4881 return (LRESULT)himlTemp;
4886 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4890 infoPtr->nIndent = (INT)wParam;
4894 /* process only on indent changing */
4895 if(infoPtr->nIndent != (INT)wParam)
4897 infoPtr->nIndent = (INT)wParam;
4898 TOOLBAR_CalcToolbar (hwnd);
4899 InvalidateRect(hwnd, NULL, FALSE);
4907 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4910 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4912 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4914 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4916 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4920 if ((lptbim->iButton == -1) ||
4921 ((lptbim->iButton < infoPtr->nNumButtons) &&
4922 (lptbim->iButton >= 0)))
4924 infoPtr->tbim = *lptbim;
4925 /* FIXME: don't need to update entire toolbar */
4926 InvalidateRect(hwnd, NULL, TRUE);
4929 ERR("Invalid button index %d\n", lptbim->iButton);
4936 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4938 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4940 infoPtr->clrInsertMark = (COLORREF)lParam;
4942 /* FIXME: don't need to update entire toolbar */
4943 InvalidateRect(hwnd, NULL, TRUE);
4950 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4952 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4954 if (infoPtr == NULL)
4957 infoPtr->nMaxTextRows = (INT)wParam;
4959 TOOLBAR_CalcToolbar(hwnd);
4964 /* MSDN gives slightly wrong info on padding.
4965 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4966 * 2. It is not used to create a blank area between the edge of the button
4967 * and the text or image if TBSTYLE_LIST is set. It is used to control
4968 * the gap between the image and text.
4969 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4970 * to control the bottom and right borders [with the border being
4971 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4972 * is shared evenly on both sides of the button.
4975 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4980 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4981 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4982 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4983 TRACE("cx=%ld, cy=%ld\n",
4984 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4985 return (LRESULT) oldPad;
4990 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4992 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4997 if (infoPtr == NULL)
4999 hwndOldNotify = infoPtr->hwndNotify;
5000 infoPtr->hwndNotify = (HWND)wParam;
5002 return (LRESULT)hwndOldNotify;
5007 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
5009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5010 LPRECT lprc = (LPRECT)lParam;
5014 if (LOWORD(wParam) > 1) {
5015 FIXME("multiple rows not supported!\n");
5018 if(infoPtr->nRows != LOWORD(wParam))
5020 infoPtr->nRows = LOWORD(wParam);
5022 /* recalculate toolbar */
5023 TOOLBAR_CalcToolbar (hwnd);
5025 /* repaint toolbar */
5026 InvalidateRect(hwnd, NULL, TRUE);
5029 /* return bounding rectangle */
5031 lprc->left = infoPtr->rcBound.left;
5032 lprc->right = infoPtr->rcBound.right;
5033 lprc->top = infoPtr->rcBound.top;
5034 lprc->bottom = infoPtr->rcBound.bottom;
5042 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
5044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5045 TBUTTON_INFO *btnPtr;
5048 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
5052 btnPtr = &infoPtr->buttons[nIndex];
5054 /* if hidden state has changed the invalidate entire window and recalc */
5055 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
5056 btnPtr->fsState = LOWORD(lParam);
5057 TOOLBAR_CalcToolbar (hwnd);
5058 InvalidateRect(hwnd, 0, TRUE);
5062 /* process state changing if current state doesn't match new state */
5063 if(btnPtr->fsState != LOWORD(lParam))
5065 btnPtr->fsState = LOWORD(lParam);
5066 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5074 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
5076 SetWindowLongW(hwnd, GWL_STYLE, lParam);
5082 inline static LRESULT
5083 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
5085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5087 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
5089 if (infoPtr == NULL)
5091 infoPtr->hwndToolTip = (HWND)wParam;
5097 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
5099 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5102 TRACE("%s hwnd=%p\n",
5103 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
5105 bTemp = infoPtr->bUnicode;
5106 infoPtr->bUnicode = (BOOL)wParam;
5113 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5117 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
5118 comctl32_color.clrBtnHighlight :
5119 infoPtr->clrBtnHighlight;
5120 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
5121 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
5127 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
5129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5131 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
5132 lParam->clrBtnHighlight, lParam->clrBtnShadow,
5133 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
5135 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
5136 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
5137 InvalidateRect(hwnd, NULL, TRUE);
5143 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
5145 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5146 INT iOldVersion = infoPtr->iVersion;
5148 infoPtr->iVersion = iVersion;
5150 if (infoPtr->iVersion >= 5)
5151 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
5158 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
5160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5161 WORD iString = HIWORD(wParam);
5162 WORD buffersize = LOWORD(wParam);
5163 LPSTR str = (LPSTR)lParam;
5166 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5168 if (iString < infoPtr->nNumStrings)
5170 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5172 TRACE("returning %s\n", debugstr_a(str));
5175 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5182 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5185 WORD iString = HIWORD(wParam);
5186 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5187 LPWSTR str = (LPWSTR)lParam;
5190 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5192 if (iString < infoPtr->nNumStrings)
5194 len = min(len, strlenW(infoPtr->strings[iString]));
5195 ret = (len+1)*sizeof(WCHAR);
5196 memcpy(str, infoPtr->strings[iString], ret);
5199 TRACE("returning %s\n", debugstr_w(str));
5202 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5207 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5208 * is the maximum size of the toolbar? */
5209 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5211 SIZE * pSize = (SIZE*)lParam;
5212 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5217 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5218 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5219 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5222 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5225 INT nOldHotItem = infoPtr->nHotItem;
5227 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5228 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5230 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5233 /* NOTE: an application can still remove the hot item even if anchor
5234 * highlighting is enabled */
5236 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5240 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5243 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5244 * which controls the amount of spacing between the image and the text
5245 * of buttons for TBSTYLE_LIST toolbars. */
5246 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5248 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5250 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5253 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5255 infoPtr->iListGap = (INT)wParam;
5257 InvalidateRect(hwnd, NULL, TRUE);
5262 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5263 * of image lists associated with the various states. */
5264 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5268 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5270 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5274 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5277 LPSIZE lpsize = (LPSIZE)lParam;
5283 * Testing shows the following:
5284 * wParam = 0 adjust cx value
5285 * = 1 set cy value to max size.
5286 * lParam pointer to SIZE structure
5289 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5290 wParam, lParam, lpsize->cx, lpsize->cy);
5294 if (lpsize->cx == -1) {
5295 /* **** this is wrong, native measures each button and sets it */
5296 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5298 else if(HIWORD(lpsize->cx)) {
5300 HWND hwndParent = GetParent(hwnd);
5302 GetWindowRect(hwnd, &rc);
5303 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5304 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5305 rc.left, rc.top, rc.right, rc.bottom);
5306 lpsize->cx = max(rc.right-rc.left,
5307 infoPtr->rcBound.right - infoPtr->rcBound.left);
5310 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5314 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5315 /* lpsize->cy = infoPtr->nHeight; */
5318 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5322 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5323 lpsize->cx, lpsize->cy);
5327 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5329 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5331 InvalidateRect(hwnd, NULL, TRUE);
5337 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5339 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5340 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5343 TRACE("hwnd = %p\n", hwnd);
5345 /* initialize info structure */
5346 infoPtr->nButtonHeight = 22;
5347 infoPtr->nButtonWidth = 24;
5348 infoPtr->nBitmapHeight = 15;
5349 infoPtr->nBitmapWidth = 16;
5351 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5352 infoPtr->nMaxTextRows = 1;
5353 infoPtr->cxMin = -1;
5354 infoPtr->cxMax = -1;
5355 infoPtr->nNumBitmaps = 0;
5356 infoPtr->nNumStrings = 0;
5358 infoPtr->bCaptured = FALSE;
5359 infoPtr->nButtonDown = -1;
5360 infoPtr->nButtonDrag = -1;
5361 infoPtr->nOldHit = -1;
5362 infoPtr->nHotItem = -1;
5363 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5364 infoPtr->bUnicode = IsWindowUnicode (infoPtr->hwndNotify);
5365 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5366 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5367 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5368 infoPtr->bDragOutSent = FALSE;
5369 infoPtr->iVersion = 0;
5370 infoPtr->hwndSelf = hwnd;
5371 infoPtr->bDoRedraw = TRUE;
5372 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5373 infoPtr->clrBtnShadow = CLR_DEFAULT;
5374 /* not sure where the +1 comes from, but this comes to the same value
5375 * as native so this is probably correct */
5376 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5377 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5378 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5379 infoPtr->dwStyle = dwStyle;
5380 infoPtr->tbim.iButton = -1;
5381 GetClientRect(hwnd, &infoPtr->client_rect);
5382 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5384 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5385 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5387 if (dwStyle & TBSTYLE_TOOLTIPS) {
5388 /* Create tooltip control */
5389 infoPtr->hwndToolTip =
5390 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5391 CW_USEDEFAULT, CW_USEDEFAULT,
5392 CW_USEDEFAULT, CW_USEDEFAULT,
5395 /* Send NM_TOOLTIPSCREATED notification */
5396 if (infoPtr->hwndToolTip) {
5397 NMTOOLTIPSCREATED nmttc;
5399 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5401 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5402 NM_TOOLTIPSCREATED);
5406 TOOLBAR_CheckStyle (hwnd, dwStyle);
5408 TOOLBAR_CalcToolbar(hwnd);
5415 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5419 /* delete tooltip control */
5420 if (infoPtr->hwndToolTip)
5421 DestroyWindow (infoPtr->hwndToolTip);
5423 /* delete temporary buffer for tooltip text */
5424 if (infoPtr->pszTooltipText)
5425 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5427 /* delete button data */
5428 if (infoPtr->buttons)
5429 Free (infoPtr->buttons);
5431 /* delete strings */
5432 if (infoPtr->strings) {
5434 for (i = 0; i < infoPtr->nNumStrings; i++)
5435 if (infoPtr->strings[i])
5436 Free (infoPtr->strings[i]);
5438 Free (infoPtr->strings);
5441 /* destroy internal image list */
5442 if (infoPtr->himlInt)
5443 ImageList_Destroy (infoPtr->himlInt);
5445 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5446 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5447 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5449 /* delete default font */
5451 DeleteObject (infoPtr->hDefaultFont);
5453 /* free toolbar info data */
5455 SetWindowLongPtrW (hwnd, 0, 0);
5462 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5465 NMTBCUSTOMDRAW tbcd;
5469 /* the app has told us not to redraw the toolbar */
5470 if (!infoPtr->bDoRedraw)
5473 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5474 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5475 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5476 tbcd.nmcd.hdc = (HDC)wParam;
5477 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5478 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5480 /* FIXME: in general the return flags *can* be or'ed together */
5481 switch (infoPtr->dwBaseCustDraw)
5483 case CDRF_DODEFAULT:
5485 case CDRF_SKIPDEFAULT:
5488 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5493 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5494 * to my parent for processing.
5496 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5498 HDC hdc = (HDC)wParam;
5503 parent = GetParent(hwnd);
5504 MapWindowPoints(hwnd, parent, &pt, 1);
5505 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5506 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5507 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5510 ret = DefWindowProcW (hwnd, WM_ERASEBKGND, wParam, lParam);
5512 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5513 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5514 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5515 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5516 tbcd.nmcd.hdc = (HDC)wParam;
5517 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5518 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5519 switch (infoPtr->dwBaseCustDraw)
5521 case CDRF_DODEFAULT:
5523 case CDRF_SKIPDEFAULT:
5526 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5535 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5539 return (LRESULT)infoPtr->hFont;
5544 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5549 pt.x = (INT)LOWORD(lParam);
5550 pt.y = (INT)HIWORD(lParam);
5551 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5554 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5555 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5556 TOOLBAR_Customize (hwnd);
5563 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5566 TBUTTON_INFO *btnPtr;
5571 BOOL bDragKeyPressed;
5575 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5576 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5578 bDragKeyPressed = (wParam & MK_SHIFT);
5580 if (infoPtr->hwndToolTip)
5581 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5582 WM_LBUTTONDOWN, wParam, lParam);
5584 pt.x = (INT)LOWORD(lParam);
5585 pt.y = (INT)HIWORD(lParam);
5586 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5588 btnPtr = &infoPtr->buttons[nHit];
5590 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5592 infoPtr->nButtonDrag = nHit;
5595 /* If drag cursor has not been loaded, load it.
5596 * Note: it doesn't need to be freed */
5598 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5599 SetCursor(hCursorDrag);
5604 infoPtr->nOldHit = nHit;
5606 CopyRect(&arrowRect, &btnPtr->rect);
5607 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5609 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5610 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5611 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5612 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5613 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5614 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5618 /* draw in pressed state */
5619 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5620 btnPtr->fsState |= TBSTATE_PRESSED;
5622 btnPtr->bDropDownPressed = TRUE;
5623 RedrawWindow(hwnd,&btnPtr->rect,0,
5624 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5626 nmtb.iItem = btnPtr->idCommand;
5627 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5630 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5631 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5633 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5635 if (res != TBDDRET_TREATPRESSED)
5639 /* redraw button in unpressed state */
5640 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5641 btnPtr->fsState &= ~TBSTATE_PRESSED;
5643 btnPtr->bDropDownPressed = FALSE;
5644 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5646 /* find and set hot item
5647 * NOTE: native doesn't do this, but that is a bug */
5649 ScreenToClient(hwnd, &pt);
5650 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5651 if (!infoPtr->bAnchor || (nHit >= 0))
5652 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5654 /* remove any left mouse button down or double-click messages
5655 * so that we can get a toggle effect on the button */
5656 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5657 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5662 /* otherwise drop through and process as pushed */
5664 infoPtr->bCaptured = TRUE;
5665 infoPtr->nButtonDown = nHit;
5666 infoPtr->bDragOutSent = FALSE;
5668 btnPtr->fsState |= TBSTATE_PRESSED;
5670 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5672 if (btnPtr->fsState & TBSTATE_ENABLED)
5673 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5680 nmtb.iItem = btnPtr->idCommand;
5681 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5682 nmtb.tbButton.idCommand = btnPtr->idCommand;
5683 nmtb.tbButton.fsState = btnPtr->fsState;
5684 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5685 nmtb.tbButton.dwData = btnPtr->dwData;
5686 nmtb.tbButton.iString = btnPtr->iString;
5687 nmtb.cchText = 0; /* !!! not correct */
5688 nmtb.pszText = 0; /* !!! not correct */
5689 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5692 nmmouse.dwHitInfo = nHit;
5694 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5695 if (nmmouse.dwHitInfo < 0)
5696 nmmouse.dwItemSpec = -1;
5699 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5700 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5703 ClientToScreen(hwnd, &pt);
5706 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_LDOWN))
5707 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5713 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5715 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5716 TBUTTON_INFO *btnPtr;
5720 BOOL bSendMessage = TRUE;
5725 if (infoPtr->hwndToolTip)
5726 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5727 WM_LBUTTONUP, wParam, lParam);
5729 pt.x = (INT)LOWORD(lParam);
5730 pt.y = (INT)HIWORD(lParam);
5731 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5733 if (!infoPtr->bAnchor || (nHit >= 0))
5734 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5736 if (infoPtr->nButtonDrag >= 0) {
5740 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5743 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5745 GetClientRect(hwnd, &rcClient);
5746 if (PtInRect(&rcClient, pt))
5753 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5756 if (nButton == infoPtr->nButtonDrag)
5758 /* if the button is moved sightly left and we have a
5759 * separator there then remove it */
5760 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5762 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5763 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5765 else /* else insert a separator before the dragged button */
5768 memset(&tbb, 0, sizeof(tbb));
5769 tbb.fsStyle = BTNS_SEP;
5771 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5778 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5779 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5781 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5784 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5789 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5790 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5793 /* button under cursor changed so need to re-set hot item */
5794 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5795 infoPtr->nButtonDrag = -1;
5797 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5799 else if (infoPtr->nButtonDown >= 0) {
5800 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5801 btnPtr->fsState &= ~TBSTATE_PRESSED;
5803 if (btnPtr->fsStyle & BTNS_CHECK) {
5804 if (btnPtr->fsStyle & BTNS_GROUP) {
5805 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5807 if (nOldIndex == nHit)
5808 bSendMessage = FALSE;
5809 if ((nOldIndex != nHit) &&
5811 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5812 btnPtr->fsState |= TBSTATE_CHECKED;
5815 if (btnPtr->fsState & TBSTATE_CHECKED)
5816 btnPtr->fsState &= ~TBSTATE_CHECKED;
5818 btnPtr->fsState |= TBSTATE_CHECKED;
5822 if (nOldIndex != -1)
5823 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5826 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5827 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5828 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5830 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5832 infoPtr->nButtonDown = -1;
5834 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5835 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5836 NM_RELEASEDCAPTURE);
5838 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5841 nmtb.iItem = btnPtr->idCommand;
5842 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5843 nmtb.tbButton.idCommand = btnPtr->idCommand;
5844 nmtb.tbButton.fsState = btnPtr->fsState;
5845 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5846 nmtb.tbButton.dwData = btnPtr->dwData;
5847 nmtb.tbButton.iString = btnPtr->iString;
5848 nmtb.cchText = 0; /* !!! not correct */
5849 nmtb.pszText = 0; /* !!! not correct */
5850 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5853 if (btnPtr->fsState & TBSTATE_ENABLED)
5855 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5856 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5860 /* !!! Undocumented - toolbar at 4.71 level and above sends
5861 * NM_CLICK with the NMMOUSE structure. */
5862 nmmouse.dwHitInfo = nHit;
5864 if (nmmouse.dwHitInfo < 0)
5865 nmmouse.dwItemSpec = -1;
5868 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5869 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5872 ClientToScreen(hwnd, &pt);
5875 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5876 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5882 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5884 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5889 pt.x = LOWORD(lParam);
5890 pt.y = HIWORD(lParam);
5892 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5894 if (nmmouse.dwHitInfo < 0) {
5895 nmmouse.dwItemSpec = -1;
5897 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5898 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5901 ClientToScreen(hwnd, &pt);
5904 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5905 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5911 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5913 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5916 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5917 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5923 TOOLBAR_CaptureChanged(HWND hwnd)
5925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5926 TBUTTON_INFO *btnPtr;
5928 infoPtr->bCaptured = FALSE;
5930 if (infoPtr->nButtonDown >= 0)
5932 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5933 btnPtr->fsState &= ~TBSTATE_PRESSED;
5935 infoPtr->nOldHit = -1;
5937 if (btnPtr->fsState & TBSTATE_ENABLED)
5938 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5944 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5947 TBUTTON_INFO *hotBtnPtr;
5949 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5951 /* don't remove hot effects when in anchor highlighting mode or when a
5952 * drop-down button is pressed */
5953 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
5954 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5956 if (infoPtr->nOldHit < 0)
5959 /* If the last button we were over is depressed then make it not */
5960 /* depressed and redraw it */
5961 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5963 TBUTTON_INFO *btnPtr;
5966 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5968 btnPtr->fsState &= ~TBSTATE_PRESSED;
5970 rc1 = hotBtnPtr->rect;
5971 InflateRect (&rc1, 1, 1);
5972 InvalidateRect (hwnd, &rc1, TRUE);
5975 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5978 ZeroMemory(&nmt, sizeof(nmt));
5979 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5980 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5981 infoPtr->bDragOutSent = TRUE;
5984 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5990 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5992 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5994 TRACKMOUSEEVENT trackinfo;
5996 TBUTTON_INFO *btnPtr;
5998 /* fill in the TRACKMOUSEEVENT struct */
5999 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
6000 trackinfo.dwFlags = TME_QUERY;
6001 trackinfo.hwndTrack = hwnd;
6002 trackinfo.dwHoverTime = HOVER_DEFAULT;
6004 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
6005 _TrackMouseEvent(&trackinfo);
6007 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
6008 if(!(trackinfo.dwFlags & TME_LEAVE)) {
6009 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
6011 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
6012 /* and can properly deactivate the hot toolbar button */
6013 _TrackMouseEvent(&trackinfo);
6016 if (infoPtr->hwndToolTip)
6017 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
6018 WM_MOUSEMOVE, wParam, lParam);
6020 pt.x = (INT)LOWORD(lParam);
6021 pt.y = (INT)HIWORD(lParam);
6023 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
6025 if (!infoPtr->bAnchor || (nHit >= 0))
6026 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
6028 if (infoPtr->nOldHit != nHit)
6030 if (infoPtr->bCaptured)
6032 if (!infoPtr->bDragOutSent)
6035 ZeroMemory(&nmt, sizeof(nmt));
6036 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
6037 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
6038 infoPtr->bDragOutSent = TRUE;
6041 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
6042 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
6043 btnPtr->fsState &= ~TBSTATE_PRESSED;
6044 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6046 else if (nHit == infoPtr->nButtonDown) {
6047 btnPtr->fsState |= TBSTATE_PRESSED;
6048 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6050 infoPtr->nOldHit = nHit;
6058 inline static LRESULT
6059 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6061 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
6062 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
6064 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
6068 inline static LRESULT
6069 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
6071 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
6072 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
6074 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
6079 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
6081 TOOLBAR_INFO *infoPtr;
6082 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
6085 /* allocate memory for info structure */
6086 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
6087 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
6090 infoPtr->dwStructSize = sizeof(TBBUTTON);
6093 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
6094 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
6095 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
6096 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
6099 /* native control does:
6100 * Get a lot of colors and brushes
6102 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
6103 * CreateFontIndirectA(adr1)
6104 * CreateBitmap(0x27, 0x24, 1, 1, 0)
6105 * hdc = GetDC(toolbar)
6106 * GetSystemMetrics(0x48)
6107 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
6108 * 0, 0, 0, 0, "MARLETT")
6109 * oldfnt = SelectObject(hdc, fnt2)
6110 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
6111 * GetTextMetricsA(hdc, adr3)
6112 * SelectObject(hdc, oldfnt)
6113 * DeleteObject(fnt2)
6115 * InvalidateRect(toolbar, 0, 1)
6116 * SetWindowLongA(toolbar, 0, addr)
6117 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
6120 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
6121 * ie 2 0x4600094c 0x4600094c 0x4600894d
6122 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
6123 * rebar 0x50008844 0x40008844 0x50008845
6124 * pager 0x50000844 0x40000844 0x50008845
6125 * IC35mgr 0x5400084e **nochange**
6126 * on entry to _NCCREATE 0x5400084e
6127 * rowlist 0x5400004e **nochange**
6128 * on entry to _NCCREATE 0x5400004e
6132 /* I think the code below is a bug, but it is the way that the native
6133 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
6134 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
6135 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
6136 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
6137 * Some how, the only cases of this seem to be MFC programs.
6139 * Note also that the addition of _TRANSPARENT occurs *only* here. It
6140 * does not occur in the WM_STYLECHANGING routine.
6141 * (Guy Albertelli 9/2001)
6144 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
6145 styleadd |= TBSTYLE_TRANSPARENT;
6146 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
6147 styleadd |= CCS_TOP; /* default to top */
6148 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
6151 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, lParam);
6156 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
6158 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
6162 if (dwStyle & WS_MINIMIZE)
6163 return 0; /* Nothing to do */
6165 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
6167 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6170 if (!(dwStyle & CCS_NODIVIDER))
6172 GetWindowRect (hwnd, &rcWindow);
6173 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6174 if( dwStyle & WS_BORDER )
6175 OffsetRect (&rcWindow, 1, 1);
6176 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6179 ReleaseDC( hwnd, hdc );
6185 /* handles requests from the tooltip control on what text to display */
6186 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6188 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6190 TRACE("button index = %d\n", index);
6192 if (infoPtr->pszTooltipText)
6194 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6195 infoPtr->pszTooltipText = NULL;
6201 if (infoPtr->bNtfUnicode)
6203 WCHAR wszBuffer[INFOTIPSIZE+1];
6204 NMTBGETINFOTIPW tbgit;
6205 unsigned int len; /* in chars */
6207 wszBuffer[0] = '\0';
6208 wszBuffer[INFOTIPSIZE] = '\0';
6210 tbgit.pszText = wszBuffer;
6211 tbgit.cchTextMax = INFOTIPSIZE;
6212 tbgit.iItem = lpnmtdi->hdr.idFrom;
6213 tbgit.lParam = infoPtr->buttons[index].dwData;
6215 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6217 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6219 len = strlenW(tbgit.pszText);
6220 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6222 /* need to allocate temporary buffer in infoPtr as there
6223 * isn't enough space in buffer passed to us by the
6224 * tooltip control */
6225 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6226 if (infoPtr->pszTooltipText)
6228 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6229 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6235 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6241 CHAR szBuffer[INFOTIPSIZE+1];
6242 NMTBGETINFOTIPA tbgit;
6243 unsigned int len; /* in chars */
6246 szBuffer[INFOTIPSIZE] = '\0';
6248 tbgit.pszText = szBuffer;
6249 tbgit.cchTextMax = INFOTIPSIZE;
6250 tbgit.iItem = lpnmtdi->hdr.idFrom;
6251 tbgit.lParam = infoPtr->buttons[index].dwData;
6253 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6255 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6257 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6258 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6260 /* need to allocate temporary buffer in infoPtr as there
6261 * isn't enough space in buffer passed to us by the
6262 * tooltip control */
6263 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6264 if (infoPtr->pszTooltipText)
6266 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6267 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6273 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6278 /* if button has text, but it is not shown then automatically
6279 * use that text as tooltip */
6280 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6281 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6283 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6284 unsigned int len = pszText ? strlenW(pszText) : 0;
6286 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6288 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6290 /* need to allocate temporary buffer in infoPtr as there
6291 * isn't enough space in buffer passed to us by the
6292 * tooltip control */
6293 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6294 if (infoPtr->pszTooltipText)
6296 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6297 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6303 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6308 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6310 /* last resort: send notification on to app */
6311 /* FIXME: find out what is really used here */
6312 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6316 inline static LRESULT
6317 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6319 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6320 LPNMHDR lpnmh = (LPNMHDR)lParam;
6322 switch (lpnmh->code)
6326 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6328 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6329 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6330 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6334 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6335 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6343 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6345 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6346 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6347 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6348 lppgs->iScroll, lppgs->iDir);
6352 case TTN_GETDISPINFOW:
6353 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6355 case TTN_GETDISPINFOA:
6356 FIXME("TTN_GETDISPINFOA - stub\n");
6366 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6368 /* remove this routine when Toolbar is improved to pass infoPtr
6369 * around instead of hwnd.
6371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6372 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6377 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6381 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6383 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6386 if (lParam == NF_REQUERY) {
6387 i = SendMessageW(infoPtr->hwndNotify,
6388 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6389 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6390 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6394 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6397 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6402 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6408 /* fill ps.rcPaint with a default rect */
6409 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6411 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6413 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6414 ps.rcPaint.left, ps.rcPaint.top,
6415 ps.rcPaint.right, ps.rcPaint.bottom);
6417 TOOLBAR_Refresh (hwnd, hdc, &ps);
6418 if (!wParam) EndPaint (hwnd, &ps);
6425 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6426 /*****************************************************
6429 * Handles the WM_SETREDRAW message.
6432 * According to testing V4.71 of COMCTL32 returns the
6433 * *previous* status of the redraw flag (either 0 or 1)
6434 * instead of the MSDN documented value of 0 if handled.
6435 * (For laughs see the "consistency" with same function
6438 *****************************************************/
6440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6441 BOOL oldredraw = infoPtr->bDoRedraw;
6443 TRACE("set to %s\n",
6444 (wParam) ? "TRUE" : "FALSE");
6445 infoPtr->bDoRedraw = (BOOL) wParam;
6447 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6449 return (oldredraw) ? 1 : 0;
6454 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6456 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6457 DWORD dwStyle = infoPtr->dwStyle;
6466 /* Resize deadlock check */
6467 if (infoPtr->bAutoSize) {
6468 infoPtr->bAutoSize = FALSE;
6472 /* FIXME: optimize to only update size if the new size doesn't */
6473 /* match the current size */
6475 flags = (INT) wParam;
6477 /* FIXME for flags =
6478 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6481 TRACE("sizing toolbar!\n");
6483 if (flags == SIZE_RESTORED) {
6484 /* width and height don't apply */
6485 parent = GetParent (hwnd);
6486 GetClientRect(parent, &parent_rect);
6487 x = parent_rect.left;
6488 y = parent_rect.top;
6490 if (dwStyle & CCS_NORESIZE) {
6491 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6494 * this sets the working width of the toolbar, and
6495 * Calc Toolbar will not adjust it, only the height
6497 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6498 cy = infoPtr->nHeight;
6499 cx = infoPtr->nWidth;
6500 TOOLBAR_CalcToolbar (hwnd);
6501 infoPtr->nWidth = cx;
6502 infoPtr->nHeight = cy;
6505 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6506 TOOLBAR_CalcToolbar (hwnd);
6507 cy = infoPtr->nHeight;
6508 cx = infoPtr->nWidth;
6510 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6511 GetWindowRect(hwnd, &window_rect);
6512 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6513 y = window_rect.top;
6515 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6516 GetWindowRect(hwnd, &window_rect);
6517 y = parent_rect.bottom -
6518 ( window_rect.bottom - window_rect.top);
6522 if (dwStyle & CCS_NOPARENTALIGN) {
6523 uPosFlags |= SWP_NOMOVE;
6524 cy = infoPtr->nHeight;
6525 cx = infoPtr->nWidth;
6528 if (!(dwStyle & CCS_NODIVIDER))
6529 cy += GetSystemMetrics(SM_CYEDGE);
6531 if (dwStyle & WS_BORDER)
6534 cy += GetSystemMetrics(SM_CYEDGE);
6535 cx += GetSystemMetrics(SM_CYEDGE);
6538 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6540 RECT delta_width, delta_height, client, dummy;
6541 DWORD min_x, max_x, min_y, max_y;
6542 TBUTTON_INFO *btnPtr;
6545 GetClientRect(hwnd, &client);
6546 if(client.right > infoPtr->client_rect.right)
6548 min_x = infoPtr->client_rect.right;
6549 max_x = client.right;
6553 max_x = infoPtr->client_rect.right;
6554 min_x = client.right;
6556 if(client.bottom > infoPtr->client_rect.bottom)
6558 min_y = infoPtr->client_rect.bottom;
6559 max_y = client.bottom;
6563 max_y = infoPtr->client_rect.bottom;
6564 min_y = client.bottom;
6567 SetRect(&delta_width, min_x, 0, max_x, min_y);
6568 SetRect(&delta_height, 0, min_y, max_x, max_y);
6570 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6571 btnPtr = infoPtr->buttons;
6572 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6573 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6574 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6575 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6578 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6579 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6581 GetClientRect(hwnd, &infoPtr->client_rect);
6587 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6589 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6591 if (nType == GWL_STYLE) {
6592 if (lpStyle->styleNew & TBSTYLE_LIST) {
6593 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6596 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6598 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6599 (TBSTYLE_FLAT | TBSTYLE_LIST));
6600 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6602 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6604 infoPtr->dwStyle = lpStyle->styleNew;
6607 TOOLBAR_CalcToolbar(hwnd);
6609 TOOLBAR_AutoSize (hwnd);
6611 InvalidateRect(hwnd, NULL, TRUE);
6618 TOOLBAR_SysColorChange (HWND hwnd)
6620 COMCTL32_RefreshSysColors();
6627 static LRESULT WINAPI
6628 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6632 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6633 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6635 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6636 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6641 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6643 case TB_ADDBUTTONSA:
6644 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6646 case TB_ADDBUTTONSW:
6647 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6650 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6653 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6656 return TOOLBAR_AutoSize (hwnd);
6658 case TB_BUTTONCOUNT:
6659 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6661 case TB_BUTTONSTRUCTSIZE:
6662 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6664 case TB_CHANGEBITMAP:
6665 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6667 case TB_CHECKBUTTON:
6668 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6670 case TB_COMMANDTOINDEX:
6671 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6674 return TOOLBAR_Customize (hwnd);
6676 case TB_DELETEBUTTON:
6677 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6679 case TB_ENABLEBUTTON:
6680 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6682 case TB_GETANCHORHIGHLIGHT:
6683 return TOOLBAR_GetAnchorHighlight (hwnd);
6686 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6688 case TB_GETBITMAPFLAGS:
6689 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6692 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6694 case TB_GETBUTTONINFOA:
6695 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6697 case TB_GETBUTTONINFOW:
6698 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6700 case TB_GETBUTTONSIZE:
6701 return TOOLBAR_GetButtonSize (hwnd);
6703 case TB_GETBUTTONTEXTA:
6704 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6706 case TB_GETBUTTONTEXTW:
6707 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6709 case TB_GETDISABLEDIMAGELIST:
6710 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6712 case TB_GETEXTENDEDSTYLE:
6713 return TOOLBAR_GetExtendedStyle (hwnd);
6715 case TB_GETHOTIMAGELIST:
6716 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6719 return TOOLBAR_GetHotItem (hwnd);
6721 case TB_GETIMAGELIST:
6722 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6724 case TB_GETINSERTMARK:
6725 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6727 case TB_GETINSERTMARKCOLOR:
6728 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6730 case TB_GETITEMRECT:
6731 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6734 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6736 /* case TB_GETOBJECT: */ /* 4.71 */
6739 return TOOLBAR_GetPadding (hwnd);
6742 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6745 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6748 return TOOLBAR_GetState (hwnd, wParam, lParam);
6751 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6754 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6757 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6759 case TB_GETTEXTROWS:
6760 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6762 case TB_GETTOOLTIPS:
6763 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6765 case TB_GETUNICODEFORMAT:
6766 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6769 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6772 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6774 case TB_INDETERMINATE:
6775 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6777 case TB_INSERTBUTTONA:
6778 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6780 case TB_INSERTBUTTONW:
6781 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6783 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6785 case TB_ISBUTTONCHECKED:
6786 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6788 case TB_ISBUTTONENABLED:
6789 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6791 case TB_ISBUTTONHIDDEN:
6792 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6794 case TB_ISBUTTONHIGHLIGHTED:
6795 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6797 case TB_ISBUTTONINDETERMINATE:
6798 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6800 case TB_ISBUTTONPRESSED:
6801 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6804 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6806 case TB_MAPACCELERATORA:
6807 case TB_MAPACCELERATORW:
6808 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6811 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6814 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6816 case TB_PRESSBUTTON:
6817 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6819 case TB_REPLACEBITMAP:
6820 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6822 case TB_SAVERESTOREA:
6823 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6825 case TB_SAVERESTOREW:
6826 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6828 case TB_SETANCHORHIGHLIGHT:
6829 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6831 case TB_SETBITMAPSIZE:
6832 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6834 case TB_SETBUTTONINFOA:
6835 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6837 case TB_SETBUTTONINFOW:
6838 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6840 case TB_SETBUTTONSIZE:
6841 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6843 case TB_SETBUTTONWIDTH:
6844 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6847 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6849 case TB_SETDISABLEDIMAGELIST:
6850 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6852 case TB_SETDRAWTEXTFLAGS:
6853 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6855 case TB_SETEXTENDEDSTYLE:
6856 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6858 case TB_SETHOTIMAGELIST:
6859 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6862 return TOOLBAR_SetHotItem (hwnd, wParam);
6864 case TB_SETIMAGELIST:
6865 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6868 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6870 case TB_SETINSERTMARK:
6871 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6873 case TB_SETINSERTMARKCOLOR:
6874 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6876 case TB_SETMAXTEXTROWS:
6877 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6880 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6883 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6886 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6889 return TOOLBAR_SetState (hwnd, wParam, lParam);
6892 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6894 case TB_SETTOOLTIPS:
6895 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6897 case TB_SETUNICODEFORMAT:
6898 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6901 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6904 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6907 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6910 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6913 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6916 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6918 /* Common Control Messages */
6920 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6921 case CCM_GETCOLORSCHEME:
6922 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6924 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6925 case CCM_SETCOLORSCHEME:
6926 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6928 case CCM_GETVERSION:
6929 return TOOLBAR_GetVersion (hwnd);
6931 case CCM_SETVERSION:
6932 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6938 return TOOLBAR_Create (hwnd, wParam, lParam);
6941 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6944 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6947 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6949 /* case WM_KEYDOWN: */
6950 /* case WM_KILLFOCUS: */
6952 case WM_LBUTTONDBLCLK:
6953 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6955 case WM_LBUTTONDOWN:
6956 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6959 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6962 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6964 case WM_RBUTTONDBLCLK:
6965 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6968 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6971 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6973 case WM_CAPTURECHANGED:
6974 return TOOLBAR_CaptureChanged(hwnd);
6977 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6980 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6983 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6986 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6989 return TOOLBAR_Notify (hwnd, wParam, lParam);
6991 case WM_NOTIFYFORMAT:
6992 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6995 return TOOLBAR_Paint (hwnd, wParam);
6998 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
7001 return TOOLBAR_Size (hwnd, wParam, lParam);
7003 case WM_STYLECHANGED:
7004 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
7006 case WM_SYSCOLORCHANGE:
7007 return TOOLBAR_SysColorChange (hwnd);
7009 /* case WM_WININICHANGE: */
7014 case WM_MEASUREITEM:
7016 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
7018 /* We see this in Outlook Express 5.x and just does DefWindowProc */
7019 case PGM_FORWARDMOUSE:
7020 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7023 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
7024 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
7025 uMsg, wParam, lParam);
7026 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
7033 TOOLBAR_Register (void)
7037 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
7038 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7039 wndClass.lpfnWndProc = ToolbarWindowProc;
7040 wndClass.cbClsExtra = 0;
7041 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
7042 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
7043 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
7044 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
7046 RegisterClassW (&wndClass);
7051 TOOLBAR_Unregister (void)
7053 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
7056 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
7061 /* Check if the entry already exists */
7062 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
7064 /* If this is a new entry we must create it and insert into the array */
7069 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
7072 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
7073 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
7088 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
7092 for (i = 0; i < *cies; i++)
7102 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
7110 for (i = 0; i < cies; i++)
7112 if (pies[i]->id == id)
7124 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
7126 HIMAGELIST himlDef = 0;
7127 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
7130 himlDef = pie->himl;
7136 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
7138 if (infoPtr->bUnicode)
7139 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
7146 nmtba.iItem = nmtb->iItem;
7147 nmtba.pszText = Buffer;
7148 nmtba.cchText = 256;
7149 ZeroMemory(nmtba.pszText, nmtba.cchText);
7151 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
7153 int ccht = strlen(nmtba.pszText);
7155 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
7156 nmtb->pszText, nmtb->cchText);
7158 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7167 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7168 int iItem, PCUSTOMBUTTON btnInfo)
7173 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7175 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);