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
55 * - Button wrapping (under construction).
57 * - iListGap custom draw support.
58 * - Customization dialog:
59 * - Minor buglet in 'available buttons' list:
60 * Buttons are not listed in MS-like order. MS seems to use a single
61 * internal list to store the button information of both listboxes.
62 * - Drag list support.
65 * - Run tests using Waite Group Windows95 API Bible Volume 2.
66 * The second cdrom contains executables addstr.exe, btncount.exe,
67 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
68 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
69 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
70 * setparnt.exe, setrows.exe, toolwnd.exe.
71 * - Microsofts controlspy examples.
72 * - Charles Petzold's 'Programming Windows': gadgets.exe
82 #include "wine/unicode.h"
86 #include "wine/debug.h"
88 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
90 static HCURSOR hCursorDrag = NULL;
99 BYTE bDropDownPressed;
104 INT cx; /* manually set size */
118 } IMLENTRY, *PIMLENTRY;
122 DWORD dwStructSize; /* size of TBBUTTON struct */
123 INT nHeight; /* height of the toolbar */
124 INT nWidth; /* width of the toolbar */
126 RECT rcBound; /* bounding rectangle */
132 INT nRows; /* number of button rows */
133 INT nMaxTextRows; /* maximum number of text rows */
134 INT cxMin; /* minimum button width */
135 INT cxMax; /* maximum button width */
136 INT nNumButtons; /* number of buttons */
137 INT nNumBitmaps; /* number of bitmaps */
138 INT nNumStrings; /* number of strings */
140 INT nButtonDown; /* toolbar button being pressed or -1 if none */
141 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
143 INT nHotItem; /* index of the "hot" item */
144 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
145 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
146 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
147 SIZE szPadding; /* padding values around button */
148 INT iListGap; /* default gap between text and image for toolbar with list style */
150 HFONT hFont; /* text font */
151 HIMAGELIST himlInt; /* image list created internally */
152 PIMLENTRY *himlDef; /* default image list array */
153 INT cimlDef; /* default image list array count */
154 PIMLENTRY *himlHot; /* hot image list array */
155 INT cimlHot; /* hot image list array count */
156 PIMLENTRY *himlDis; /* disabled image list array */
157 INT cimlDis; /* disabled image list array count */
158 HWND hwndToolTip; /* handle to tool tip control */
159 HWND hwndNotify; /* handle to the window that gets notifications */
160 HWND hwndSelf; /* my own handle */
161 BOOL bBtnTranspnt; /* button transparency flag */
162 BOOL bAutoSize; /* auto size deadlock indicator */
163 BOOL bAnchor; /* anchor highlight enabled */
164 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
165 BOOL bDoRedraw; /* Redraw status */
166 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
167 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
168 BOOL bCaptured; /* mouse captured? */
169 DWORD dwStyle; /* regular toolbar style */
170 DWORD dwExStyle; /* extended toolbar style */
171 DWORD dwDTFlags; /* DrawText flags */
173 COLORREF clrInsertMark; /* insert mark color */
174 COLORREF clrBtnHighlight; /* color for Flat Separator */
175 COLORREF clrBtnShadow; /* color for Flag Separator */
177 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
178 * for TTN_GETDISPINFOW notification */
179 TBINSERTMARK tbim; /* info on insertion mark */
180 TBUTTON_INFO *buttons; /* pointer to button array */
181 LPWSTR *strings; /* pointer to string array */
182 TBITMAP_INFO *bitmaps;
183 } TOOLBAR_INFO, *PTOOLBAR_INFO;
186 /* used by customization dialog */
189 PTOOLBAR_INFO tbInfo;
191 } CUSTDLG_INFO, *PCUSTDLG_INFO;
199 } CUSTOMBUTTON, *PCUSTOMBUTTON;
208 #define SEPARATOR_WIDTH 8
210 #define BOTTOM_BORDER 2
211 #define DDARROW_WIDTH 11
212 #define ARROW_HEIGHT 3
213 #define INSERTMARK_WIDTH 2
215 /* gap between border of button and text/image */
218 /* how wide to treat the bitmap if it isn't present */
219 #define LIST_IMAGE_ABSENT_WIDTH 2
221 #define TOOLBAR_NOWHERE (-1)
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
224 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
225 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
227 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
229 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
232 /* Used to find undocumented extended styles */
233 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
234 TBSTYLE_EX_UNDOC1 | \
235 TBSTYLE_EX_MIXEDBUTTONS | \
236 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
238 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
239 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
240 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
241 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
242 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
251 static void TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason);
254 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
258 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
260 LPWSTR lpText = NULL;
262 /* NOTE: iString == -1 is undocumented */
263 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
264 lpText = (LPWSTR)btnPtr->iString;
265 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
266 lpText = infoPtr->strings[btnPtr->iString];
272 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
280 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
281 btn_num, bP->idCommand,
282 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
283 bP->rect.left, bP->rect.top,
284 bP->rect.right, bP->rect.bottom);
290 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
292 if (TRACE_ON(toolbar)) {
295 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
297 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
298 iP->nNumStrings, iP->dwStyle);
299 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
301 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
302 (iP->bDoRedraw) ? "TRUE" : "FALSE");
303 for(i=0; i<iP->nNumButtons; i++) {
304 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
310 /***********************************************************************
313 * This function validates that the styles set are implemented and
314 * issues FIXME's warning of possible problems. In a perfect world this
315 * function should be null.
318 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
320 if (dwStyle & TBSTYLE_REGISTERDROP)
321 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
326 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
328 if(!IsWindow(infoPtr->hwndSelf))
329 return 0; /* we have just been destroyed */
331 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
332 nmhdr->hwndFrom = infoPtr->hwndSelf;
335 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
336 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
338 if (infoPtr->bNtfUnicode)
339 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
340 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
342 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
343 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
346 /***********************************************************************
347 * TOOLBAR_GetBitmapIndex
349 * This function returns the bitmap index associated with a button.
350 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
351 * is issued to retrieve the index.
354 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
356 INT ret = btnPtr->iBitmap;
358 if (ret == I_IMAGECALLBACK) {
359 /* issue TBN_GETDISPINFO */
362 nmgd.idCommand = btnPtr->idCommand;
363 nmgd.lParam = btnPtr->dwData;
364 nmgd.dwMask = TBNF_IMAGE;
365 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
366 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
368 if (nmgd.dwMask & TBNF_DI_SETITEM) {
369 btnPtr->iBitmap = nmgd.iImage;
372 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
373 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
376 if (ret != I_IMAGENONE)
377 ret = GETIBITMAP(infoPtr, ret);
384 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
387 INT id = GETHIMLID(infoPtr, index);
388 INT iBitmap = GETIBITMAP(infoPtr, index);
390 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
391 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
392 (index == I_IMAGECALLBACK))
399 /***********************************************************************
400 * TOOLBAR_GetImageListForDrawing
402 * This function validates the bitmap index (including I_IMAGECALLBACK
403 * functionality) and returns the corresponding image list.
406 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
410 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
411 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
412 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
413 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
417 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
418 if ((*index == I_IMAGECALLBACK) ||
419 (*index == I_IMAGENONE)) return NULL;
420 ERR("TBN_GETDISPINFO returned invalid index %d\n",
427 case IMAGE_LIST_DEFAULT:
428 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
431 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
433 case IMAGE_LIST_DISABLED:
434 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
438 FIXME("Shouldn't reach here\n");
442 TRACE("no image list\n");
448 /***********************************************************************
449 * TOOLBAR_TestImageExist
451 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
452 * return the image list. The I_IMAGECALLBACK functionality is implemented.
455 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
459 if (!himl) return FALSE;
461 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
462 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
463 ERR("index %d is not valid, max %d\n",
464 btnPtr->iBitmap, infoPtr->nNumBitmaps);
468 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
469 if ((index == I_IMAGECALLBACK) ||
470 (index == I_IMAGENONE)) return FALSE;
471 ERR("TBN_GETDISPINFO returned invalid index %d\n",
480 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
483 COLORREF oldcolor, newcolor;
485 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
486 myrect.right = myrect.left + 1;
487 myrect.top = lpRect->top + 2;
488 myrect.bottom = lpRect->bottom - 2;
490 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
491 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
492 oldcolor = SetBkColor (hdc, newcolor);
493 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
495 myrect.left = myrect.right;
496 myrect.right = myrect.left + 1;
498 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
499 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
500 SetBkColor (hdc, newcolor);
501 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
503 SetBkColor (hdc, oldcolor);
507 /***********************************************************************
508 * TOOLBAR_DrawDDFlatSeparator
510 * This function draws the separator that was flagged as BTNS_DROPDOWN.
511 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
512 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
513 * are horizontal as opposed to the vertical separators for not dropdown
516 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
519 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
522 COLORREF oldcolor, newcolor;
524 myrect.left = lpRect->left;
525 myrect.right = lpRect->right;
526 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
527 myrect.bottom = myrect.top + 1;
529 InflateRect (&myrect, -2, 0);
531 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
532 myrect.left, myrect.top, myrect.right, myrect.bottom);
534 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
535 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
536 oldcolor = SetBkColor (hdc, newcolor);
537 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
539 myrect.top = myrect.bottom;
540 myrect.bottom = myrect.top + 1;
542 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
543 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
544 SetBkColor (hdc, newcolor);
545 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
547 SetBkColor (hdc, oldcolor);
552 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
557 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
558 hOldPen = SelectObject ( hdc, hPen );
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+5, y++); x++;
563 MoveToEx (hdc, x, y, NULL);
564 LineTo (hdc, x+3, y++); x++;
565 MoveToEx (hdc, x, y, NULL);
566 LineTo (hdc, x+1, y++);
567 SelectObject( hdc, hOldPen );
568 DeleteObject( hPen );
572 * Draw the text string for this button.
573 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
574 * is non-zero, so we can simply check himlDef to see if we have
578 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
579 NMTBCUSTOMDRAW *tbcd)
581 HDC hdc = tbcd->nmcd.hdc;
584 COLORREF clrOldBk = 0;
586 UINT state = tbcd->nmcd.uItemState;
590 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
591 rcText->left, rcText->top, rcText->right, rcText->bottom);
593 hOldFont = SelectObject (hdc, infoPtr->hFont);
594 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
595 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
597 else if (state & CDIS_DISABLED) {
598 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
599 OffsetRect (rcText, 1, 1);
600 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
601 SetTextColor (hdc, comctl32_color.clr3dShadow);
602 OffsetRect (rcText, -1, -1);
604 else if (state & CDIS_INDETERMINATE) {
605 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
607 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
608 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
609 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
610 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
613 clrOld = SetTextColor (hdc, tbcd->clrText);
616 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
617 SetTextColor (hdc, clrOld);
618 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
620 SetBkColor (hdc, clrOldBk);
621 SetBkMode (hdc, oldBkMode);
623 SelectObject (hdc, hOldFont);
629 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
631 HDC hdc = tbcd->nmcd.hdc;
632 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
635 INT cx = lpRect->right - lpRect->left;
636 INT cy = lpRect->bottom - lpRect->top;
637 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
638 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
639 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
640 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
641 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
642 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
643 SetBkColor(hdc, clrBkOld);
644 SetTextColor(hdc, clrTextOld);
645 SelectObject (hdc, hbr);
649 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
652 HBITMAP hbmMask, hbmImage;
653 HDC hdcMask, hdcImage;
655 ImageList_GetIconSize(himl, &cx, &cy);
657 /* Create src image */
658 hdcImage = CreateCompatibleDC(hdc);
659 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
660 SelectObject(hdcImage, hbmImage);
661 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
662 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
665 hdcMask = CreateCompatibleDC(0);
666 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
667 SelectObject(hdcMask, hbmMask);
669 /* Remove the background and all white pixels */
670 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
671 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
672 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
673 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
675 /* draw the new mask 'etched' to hdc */
676 SetBkColor(hdc, RGB(255, 255, 255));
677 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
678 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
679 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
680 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
681 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
684 DeleteObject(hbmImage);
686 DeleteObject (hbmMask);
692 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
696 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
698 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
699 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
700 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
701 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
702 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
706 /* draws the image on a toolbar button */
708 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
710 HIMAGELIST himl = NULL;
711 BOOL draw_masked = FALSE;
714 UINT draw_flags = ILD_NORMAL;
716 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
718 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
721 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
725 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
727 /* if hot, attempt to draw with hot image list, if fails,
728 use default image list */
729 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
731 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
734 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
739 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
740 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
743 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
744 (tbcd->nmcd.uItemState & CDIS_MARKED))
745 draw_flags |= ILD_BLEND50;
747 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
748 index, himl, left, top, offset);
751 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
753 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
756 /* draws a blank frame for a toolbar button */
758 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
760 HDC hdc = tbcd->nmcd.hdc;
761 RECT rc = tbcd->nmcd.rc;
762 /* if the state is disabled or indeterminate then the button
763 * cannot have an interactive look like pressed or hot */
764 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
765 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
766 BOOL pressed_look = !non_interactive_state &&
767 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
768 (tbcd->nmcd.uItemState & CDIS_CHECKED));
770 /* app don't want us to draw any edges */
771 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
777 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
778 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
779 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
784 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
786 DrawEdge (hdc, &rc, EDGE_RAISED,
787 BF_SOFT | BF_RECT | BF_MIDDLE);
792 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
794 HDC hdc = tbcd->nmcd.hdc;
796 BOOL pressed = bDropDownPressed ||
797 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
799 if (infoPtr->dwStyle & TBSTYLE_FLAT)
802 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
803 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
804 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
805 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
806 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
811 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
813 DrawEdge (hdc, rcArrow, EDGE_RAISED,
814 BF_SOFT | BF_RECT | BF_MIDDLE);
818 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
820 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
822 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
823 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
826 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
829 /* draws a complete toolbar button */
831 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
834 DWORD dwStyle = infoPtr->dwStyle;
835 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
836 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
837 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 BOOL drawSepDropDownArrow = hasDropDownArrow &&
839 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
840 RECT rc, rcArrow, rcBitmap, rcText;
841 LPWSTR lpText = NULL;
847 CopyRect (&rcArrow, &rc);
848 CopyRect(&rcBitmap, &rc);
850 /* get a pointer to the text */
851 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
853 if (hasDropDownArrow)
857 if (dwStyle & TBSTYLE_FLAT)
858 right = max(rc.left, rc.right - DDARROW_WIDTH);
860 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
862 if (drawSepDropDownArrow)
865 rcArrow.left = right;
868 /* copy text rect after adjusting for drop-down arrow
869 * so that text is centred in the rectangle not containing
871 CopyRect(&rcText, &rc);
873 /* Center the bitmap horizontally and vertically */
874 if (dwStyle & TBSTYLE_LIST)
875 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
877 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
880 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
882 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
884 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
885 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
886 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
887 TRACE ("iString: %x\n", btnPtr->iString);
888 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
892 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
893 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
894 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
895 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
897 if (dwStyle & TBSTYLE_LIST)
898 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
900 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
903 if (dwStyle & TBSTYLE_LIST)
904 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
906 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
907 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
908 OffsetRect(&rcText, 1, 1);
911 /* Initialize fields in all cases, because we use these later
912 * NOTE: applications can and do alter these to customize their
914 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
915 tbcd.clrText = comctl32_color.clrBtnText;
916 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
917 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
918 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
919 tbcd.clrMark = comctl32_color.clrHighlight;
920 tbcd.clrHighlightHotTrack = 0;
921 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
922 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
923 /* MSDN says that this is the text rectangle.
924 * But (why always a but) tracing of v5.7 of native shows
925 * that this is really a *relative* rectangle based on the
926 * the nmcd.rc. Also the left and top are always 0 ignoring
927 * any bitmap that might be present. */
928 tbcd.rcText.left = 0;
930 tbcd.rcText.right = rcText.right - rc.left;
931 tbcd.rcText.bottom = rcText.bottom - rc.top;
932 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
935 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
937 /* FIXME: what are these used for? */
941 /* Issue Item Prepaint notify */
942 infoPtr->dwItemCustDraw = 0;
943 infoPtr->dwItemCDFlag = 0;
944 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
946 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
947 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
948 tbcd.nmcd.lItemlParam = btnPtr->dwData;
949 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
950 /* reset these fields so the user can't alter the behaviour like native */
954 infoPtr->dwItemCustDraw = ntfret & 0xffff;
955 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
956 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
958 /* save the only part of the rect that the user can change */
959 rcText.right = tbcd.rcText.right + rc.left;
960 rcText.bottom = tbcd.rcText.bottom + rc.top;
964 if (btnPtr->fsStyle & BTNS_SEP) {
965 /* with the FLAT style, iBitmap is the width and has already */
966 /* been taken into consideration in calculating the width */
967 /* so now we need to draw the vertical separator */
968 /* empirical tests show that iBitmap can/will be non-zero */
969 /* when drawing the vertical bar... */
970 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
971 if (btnPtr->fsStyle & BTNS_DROPDOWN)
972 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
974 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
976 else if (btnPtr->fsStyle != BTNS_SEP) {
977 FIXME("Draw some kind of separator: fsStyle=%x\n",
983 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
984 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
985 TOOLBAR_DrawPattern (&rc, &tbcd);
987 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
989 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
993 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
994 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
995 if (hasDropDownArrow)
996 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
997 SetBkColor(hdc, oldclr);
1001 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1003 if (drawSepDropDownArrow)
1004 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1006 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1007 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1009 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1011 if (hasDropDownArrow && !drawSepDropDownArrow)
1013 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1015 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1016 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1018 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1020 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1021 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1028 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1030 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1031 tbcd.nmcd.hdc = hdc;
1033 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1034 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1035 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1036 tbcd.rcText = rcText;
1037 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1038 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1039 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1046 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1049 TBUTTON_INFO *btnPtr;
1050 INT i, oldBKmode = 0;
1051 RECT rcTemp, rcClient;
1052 NMTBCUSTOMDRAW tbcd;
1055 /* the app has told us not to redraw the toolbar */
1056 if (!infoPtr->bDoRedraw)
1059 /* if imagelist belongs to the app, it can be changed
1060 by the app after setting it */
1061 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1063 infoPtr->nNumBitmaps = 0;
1064 for (i = 0; i < infoPtr->cimlDef; i++)
1065 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1068 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1070 /* Send initial notify */
1071 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1072 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1073 tbcd.nmcd.hdc = hdc;
1074 tbcd.nmcd.rc = ps->rcPaint;
1075 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1076 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1078 if (infoPtr->bBtnTranspnt)
1079 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1081 GetClientRect(hwnd, &rcClient);
1083 /* redraw necessary buttons */
1084 btnPtr = infoPtr->buttons;
1085 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1088 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1090 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1091 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1095 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1096 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1098 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1101 /* draw insert mark if required */
1102 if (infoPtr->tbim.iButton != -1)
1104 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1106 rcInsertMark.top = rcButton.top;
1107 rcInsertMark.bottom = rcButton.bottom;
1108 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1109 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1111 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1112 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1115 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1116 SetBkMode (hdc, oldBKmode);
1118 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1120 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1121 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1122 tbcd.nmcd.hdc = hdc;
1123 tbcd.nmcd.rc = ps->rcPaint;
1124 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1128 /***********************************************************************
1129 * TOOLBAR_MeasureString
1131 * This function gets the width and height of a string in pixels. This
1132 * is done first by using GetTextExtentPoint to get the basic width
1133 * and height. The DrawText is called with DT_CALCRECT to get the exact
1134 * width. The reason is because the text may have more than one "&" (or
1135 * prefix characters as M$ likes to call them). The prefix character
1136 * indicates where the underline goes, except for the string "&&" which
1137 * is reduced to a single "&". GetTextExtentPoint does not process these
1138 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1141 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1142 HDC hdc, LPSIZE lpSize)
1149 if (infoPtr->nMaxTextRows > 0 &&
1150 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1151 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1152 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1154 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1156 if(lpText != NULL) {
1157 /* first get size of all the text */
1158 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1160 /* feed above size into the rectangle for DrawText */
1161 myrect.left = myrect.top = 0;
1162 myrect.right = lpSize->cx;
1163 myrect.bottom = lpSize->cy;
1165 /* Use DrawText to get true size as drawn (less pesky "&") */
1166 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1167 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1170 /* feed back to caller */
1171 lpSize->cx = myrect.right;
1172 lpSize->cy = myrect.bottom;
1176 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1179 /***********************************************************************
1180 * TOOLBAR_CalcStrings
1182 * This function walks through each string and measures it and returns
1183 * the largest height and width to caller.
1186 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1189 TBUTTON_INFO *btnPtr;
1198 if(infoPtr->nMaxTextRows == 0)
1202 hOldFont = SelectObject (hdc, infoPtr->hFont);
1204 btnPtr = infoPtr->buttons;
1205 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1206 if(TOOLBAR_HasText(infoPtr, btnPtr))
1208 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1209 if (sz.cx > lpSize->cx)
1211 if (sz.cy > lpSize->cy)
1216 SelectObject (hdc, hOldFont);
1217 ReleaseDC (hwnd, hdc);
1219 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1222 /***********************************************************************
1223 * TOOLBAR_WrapToolbar
1225 * This function walks through the buttons and separators in the
1226 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1227 * wrapping should occur based on the width of the toolbar window.
1228 * It does *not* calculate button placement itself. That task
1229 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1230 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1231 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1233 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1234 * vertical toolbar lists.
1238 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1241 TBUTTON_INFO *btnPtr;
1244 BOOL bWrap, bButtonWrap;
1246 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1247 /* no layout is necessary. Applications may use this style */
1248 /* to perform their own layout on the toolbar. */
1249 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1250 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1252 btnPtr = infoPtr->buttons;
1253 x = infoPtr->nIndent;
1255 /* this can get the parents width, to know how far we can extend
1256 * this toolbar. We cannot use its height, as there may be multiple
1257 * toolbars in a rebar control
1259 GetClientRect( GetParent(hwnd), &rc );
1260 infoPtr->nWidth = rc.right - rc.left;
1261 bButtonWrap = FALSE;
1263 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1264 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1267 for (i = 0; i < infoPtr->nNumButtons; i++ )
1270 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1272 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1275 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1276 /* it is the actual width of the separator. This is used for */
1277 /* custom controls in toolbars. */
1279 /* BTNS_DROPDOWN separators are treated as buttons for */
1280 /* width. - GA 8/01 */
1281 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1282 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1283 cx = (btnPtr[i].iBitmap > 0) ?
1284 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1286 cx = infoPtr->nButtonWidth;
1288 /* Two or more adjacent separators form a separator group. */
1289 /* The first separator in a group should be wrapped to the */
1290 /* next row if the previous wrapping is on a button. */
1292 (btnPtr[i].fsStyle & BTNS_SEP) &&
1293 (i + 1 < infoPtr->nNumButtons ) &&
1294 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1296 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1297 btnPtr[i].fsState |= TBSTATE_WRAP;
1298 x = infoPtr->nIndent;
1300 bButtonWrap = FALSE;
1304 /* The layout makes sure the bitmap is visible, but not the button. */
1305 /* Test added to also wrap after a button that starts a row but */
1306 /* is bigger than the area. - GA 8/01 */
1307 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1308 > infoPtr->nWidth ) ||
1309 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1311 BOOL bFound = FALSE;
1313 /* If the current button is a separator and not hidden, */
1314 /* go to the next until it reaches a non separator. */
1315 /* Wrap the last separator if it is before a button. */
1316 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1317 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1318 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1319 i < infoPtr->nNumButtons )
1325 if( bFound && i < infoPtr->nNumButtons )
1328 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1329 i, btnPtr[i].fsStyle, x, cx);
1330 btnPtr[i].fsState |= TBSTATE_WRAP;
1331 x = infoPtr->nIndent;
1332 bButtonWrap = FALSE;
1335 else if ( i >= infoPtr->nNumButtons)
1338 /* If the current button is not a separator, find the last */
1339 /* separator and wrap it. */
1340 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1342 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1343 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1347 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1348 i, btnPtr[i].fsStyle, x, cx);
1349 x = infoPtr->nIndent;
1350 btnPtr[j].fsState |= TBSTATE_WRAP;
1351 bButtonWrap = FALSE;
1356 /* If no separator available for wrapping, wrap one of */
1357 /* non-hidden previous button. */
1361 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1363 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1368 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1369 i, btnPtr[i].fsStyle, x, cx);
1370 x = infoPtr->nIndent;
1371 btnPtr[j].fsState |= TBSTATE_WRAP;
1377 /* If all above failed, wrap the current button. */
1380 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1381 i, btnPtr[i].fsStyle, x, cx);
1382 btnPtr[i].fsState |= TBSTATE_WRAP;
1384 x = infoPtr->nIndent;
1385 if (btnPtr[i].fsStyle & BTNS_SEP )
1386 bButtonWrap = FALSE;
1392 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1393 i, btnPtr[i].fsStyle, x, cx);
1400 /***********************************************************************
1401 * TOOLBAR_CalcToolbar
1403 * This function calculates button and separator placement. It first
1404 * calculates the button sizes, gets the toolbar window width and then
1405 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1406 * on. It assigns a new location to each item and sends this location to
1407 * the tooltip window if appropriate. Finally, it updates the rcBound
1408 * rect and calculates the new required toolbar window height.
1412 TOOLBAR_CalcToolbar (HWND hwnd)
1414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1415 DWORD dwStyle = infoPtr->dwStyle;
1416 TBUTTON_INFO *btnPtr;
1417 INT i, nRows, nSepRows;
1421 BOOL usesBitmaps = FALSE;
1422 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1424 TOOLBAR_CalcStrings (hwnd, &sizeString);
1426 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1428 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1430 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1433 if (dwStyle & TBSTYLE_LIST)
1435 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1436 0, sizeString.cy) + infoPtr->szPadding.cy;
1437 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1438 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1439 if (sizeString.cx > 0)
1440 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1441 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1442 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1443 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1446 if (sizeString.cy > 0)
1449 infoPtr->nButtonHeight = sizeString.cy +
1450 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1451 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1453 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1456 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1458 if (sizeString.cx > infoPtr->nBitmapWidth)
1459 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1461 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1464 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1465 infoPtr->nButtonWidth = infoPtr->cxMin;
1466 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1467 infoPtr->nButtonWidth = infoPtr->cxMax;
1469 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1471 x = infoPtr->nIndent;
1474 /* from above, minimum is a button, and possible text */
1475 cx = infoPtr->nButtonWidth;
1477 /* cannot use just ButtonHeight, we may have no buttons! */
1478 if (infoPtr->nNumButtons > 0)
1479 infoPtr->nHeight = infoPtr->nButtonHeight;
1481 cy = infoPtr->nHeight;
1483 nRows = nSepRows = 0;
1485 infoPtr->rcBound.top = y;
1486 infoPtr->rcBound.left = x;
1487 infoPtr->rcBound.bottom = y + cy;
1488 infoPtr->rcBound.right = x;
1490 btnPtr = infoPtr->buttons;
1492 TRACE("cy=%d\n", cy);
1494 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1497 if (btnPtr->fsState & TBSTATE_HIDDEN)
1499 SetRectEmpty (&btnPtr->rect);
1503 cy = infoPtr->nHeight;
1505 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1506 /* it is the actual width of the separator. This is used for */
1507 /* custom controls in toolbars. */
1508 if (btnPtr->fsStyle & BTNS_SEP) {
1509 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1510 cy = (btnPtr->iBitmap > 0) ?
1511 btnPtr->iBitmap : SEPARATOR_WIDTH;
1512 cx = infoPtr->nButtonWidth;
1515 cx = (btnPtr->iBitmap > 0) ?
1516 btnPtr->iBitmap : SEPARATOR_WIDTH;
1522 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1523 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1530 hOldFont = SelectObject (hdc, infoPtr->hFont);
1532 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1534 SelectObject (hdc, hOldFont);
1535 ReleaseDC (hwnd, hdc);
1537 /* add space on for button frame, etc */
1538 cx = sz.cx + infoPtr->szPadding.cx;
1540 /* add list padding */
1541 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1542 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1544 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1546 if (dwStyle & TBSTYLE_LIST)
1547 cx += infoPtr->nBitmapWidth;
1548 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1549 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1551 else if (dwStyle & TBSTYLE_LIST)
1552 cx += LIST_IMAGE_ABSENT_WIDTH;
1555 cx = infoPtr->nButtonWidth;
1557 /* if size has been set manually then don't add on extra space
1558 * for the drop down arrow */
1559 if (!btnPtr->cx && hasDropDownArrows &&
1560 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1561 cx += DDARROW_WIDTH;
1563 if (btnPtr->fsState & TBSTATE_WRAP )
1566 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1568 if (infoPtr->rcBound.left > x)
1569 infoPtr->rcBound.left = x;
1570 if (infoPtr->rcBound.right < x + cx)
1571 infoPtr->rcBound.right = x + cx;
1572 if (infoPtr->rcBound.bottom < y + cy)
1573 infoPtr->rcBound.bottom = y + cy;
1575 /* Set the toolTip only for non-hidden, non-separator button */
1576 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1580 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1581 ti.cbSize = sizeof(TTTOOLINFOA);
1583 ti.uId = btnPtr->idCommand;
1584 ti.rect = btnPtr->rect;
1585 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1589 /* btnPtr->nRow is zero based. The space between the rows is */
1590 /* also considered as a row. */
1591 btnPtr->nRow = nRows + nSepRows;
1593 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1594 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1599 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1603 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1604 /* it is the actual width of the separator. This is used for */
1605 /* custom controls in toolbars. */
1606 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1607 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1608 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1612 /* nSepRows is used to calculate the extra height follwoing */
1616 x = infoPtr->nIndent;
1618 /* Increment row number unless this is the last button */
1619 /* and it has Wrap set. */
1620 if (i != infoPtr->nNumButtons-1)
1627 /* infoPtr->nRows is the number of rows on the toolbar */
1628 infoPtr->nRows = nRows + nSepRows + 1;
1631 /********************************************************************
1632 * The following while interesting, does not match the values *
1633 * created above for the button rectangles, nor the rcBound rect. *
1634 * We will comment it out and remove it later. *
1636 * The problem showed up as heights in the pager control that was *
1638 ********************************************************************/
1640 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1642 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1643 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1644 nSepRows * (infoPtr->nBitmapHeight + 1) +
1648 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1650 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1655 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1658 TBUTTON_INFO *btnPtr;
1661 btnPtr = infoPtr->buttons;
1662 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1663 if (btnPtr->fsState & TBSTATE_HIDDEN)
1666 if (btnPtr->fsStyle & BTNS_SEP) {
1667 if (PtInRect (&btnPtr->rect, *lpPt)) {
1668 TRACE(" ON SEPARATOR %d!\n", i);
1673 if (PtInRect (&btnPtr->rect, *lpPt)) {
1674 TRACE(" ON BUTTON %d!\n", i);
1680 TRACE(" NOWHERE!\n");
1681 return TOOLBAR_NOWHERE;
1686 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1688 TBUTTON_INFO *btnPtr;
1691 if (CommandIsIndex) {
1692 TRACE("command is really index command=%d\n", idCommand);
1693 if (idCommand >= infoPtr->nNumButtons) return -1;
1696 btnPtr = infoPtr->buttons;
1697 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1698 if (btnPtr->idCommand == idCommand) {
1699 TRACE("command=%d index=%d\n", idCommand, i);
1703 TRACE("no index found for command=%d\n", idCommand);
1709 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1711 TBUTTON_INFO *btnPtr;
1714 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1717 /* check index button */
1718 btnPtr = &infoPtr->buttons[nIndex];
1719 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1720 if (btnPtr->fsState & TBSTATE_CHECKED)
1724 /* check previous buttons */
1725 nRunIndex = nIndex - 1;
1726 while (nRunIndex >= 0) {
1727 btnPtr = &infoPtr->buttons[nRunIndex];
1728 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1729 if (btnPtr->fsState & TBSTATE_CHECKED)
1737 /* check next buttons */
1738 nRunIndex = nIndex + 1;
1739 while (nRunIndex < infoPtr->nNumButtons) {
1740 btnPtr = &infoPtr->buttons[nRunIndex];
1741 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1742 if (btnPtr->fsState & TBSTATE_CHECKED)
1755 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1756 WPARAM wParam, LPARAM lParam)
1762 msg.wParam = wParam;
1763 msg.lParam = lParam;
1764 msg.time = GetMessageTime ();
1765 msg.pt.x = LOWORD(GetMessagePos ());
1766 msg.pt.y = HIWORD(GetMessagePos ());
1768 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1772 /***********************************************************************
1773 * TOOLBAR_CustomizeDialogProc
1774 * This function implements the toolbar customization dialog.
1776 static INT_PTR CALLBACK
1777 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1779 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1780 PCUSTOMBUTTON btnInfo;
1782 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1787 custInfo = (PCUSTDLG_INFO)lParam;
1788 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1796 infoPtr = custInfo->tbInfo;
1798 /* send TBN_QUERYINSERT notification */
1799 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1801 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1804 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1805 nmtb.iItem = (int)hwnd;
1806 /* Send TBN_INITCUSTOMIZE notification */
1807 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1810 TRACE("TBNRF_HIDEHELP requested\n");
1811 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1814 /* add items to 'toolbar buttons' list and check if removable */
1815 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1817 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1818 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1819 btnInfo->btn.fsStyle = BTNS_SEP;
1820 btnInfo->bVirtual = FALSE;
1821 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1823 /* send TBN_QUERYDELETE notification */
1824 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1826 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1827 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1830 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1832 /* insert separator button into 'available buttons' list */
1833 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1834 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1835 btnInfo->btn.fsStyle = BTNS_SEP;
1836 btnInfo->bVirtual = FALSE;
1837 btnInfo->bRemovable = TRUE;
1838 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1839 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1840 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1842 /* insert all buttons into dsa */
1845 /* send TBN_GETBUTTONINFO notification */
1848 nmtb.pszText = Buffer;
1851 /* Clear previous button's text */
1852 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1854 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1857 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1858 nmtb.tbButton.fsStyle, i,
1859 nmtb.tbButton.idCommand,
1860 nmtb.tbButton.iString,
1861 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1864 /* insert button into the apropriate list */
1865 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1868 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1869 btnInfo->bVirtual = FALSE;
1870 btnInfo->bRemovable = TRUE;
1872 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1873 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1874 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1878 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1879 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1882 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1883 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1885 if (lstrlenW(nmtb.pszText))
1886 lstrcpyW(btnInfo->text, nmtb.pszText);
1887 else if (nmtb.tbButton.iString >= 0 &&
1888 nmtb.tbButton.iString < infoPtr->nNumStrings)
1890 lstrcpyW(btnInfo->text,
1891 infoPtr->strings[nmtb.tbButton.iString]);
1896 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1898 /* select first item in the 'available' list */
1899 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1901 /* append 'virtual' separator button to the 'toolbar buttons' list */
1902 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1903 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1904 btnInfo->btn.fsStyle = BTNS_SEP;
1905 btnInfo->bVirtual = TRUE;
1906 btnInfo->bRemovable = FALSE;
1907 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1908 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1909 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1911 /* select last item in the 'toolbar' list */
1912 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1913 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1915 /* set focus and disable buttons */
1916 PostMessageA (hwnd, WM_USER, 0, 0);
1921 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1922 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1923 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1924 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1928 EndDialog(hwnd, FALSE);
1932 switch (LOWORD(wParam))
1934 case IDC_TOOLBARBTN_LBOX:
1935 if (HIWORD(wParam) == LBN_SELCHANGE)
1937 PCUSTOMBUTTON btnInfo;
1942 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1943 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1945 /* send TBN_QUERYINSERT notification */
1947 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1950 /* get list box item */
1951 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1953 if (index == (count - 1))
1955 /* last item (virtual separator) */
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1959 else if (index == (count - 2))
1961 /* second last item (last non-virtual item) */
1962 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1963 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1965 else if (index == 0)
1968 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1969 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1973 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1974 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1977 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1981 case IDC_MOVEUP_BTN:
1983 PCUSTOMBUTTON btnInfo;
1987 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1988 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1989 TRACE("Move up: index %d\n", index);
1991 /* send TBN_QUERYINSERT notification */
1994 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1999 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2001 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2002 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
2003 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
2004 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2007 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2008 else if (index >= (count - 3))
2009 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2011 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2012 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
2014 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2019 case IDC_MOVEDN_BTN: /* move down */
2021 PCUSTOMBUTTON btnInfo;
2025 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2026 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2027 TRACE("Move up: index %d\n", index);
2029 /* send TBN_QUERYINSERT notification */
2031 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2036 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2038 /* move button down */
2039 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2040 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2041 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2042 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2045 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2046 else if (index >= (count - 3))
2047 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2049 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2050 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2052 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2057 case IDC_REMOVE_BTN: /* remove button */
2059 PCUSTOMBUTTON btnInfo;
2062 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2064 if (LB_ERR == index)
2067 TRACE("Remove: index %d\n", index);
2069 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2070 LB_GETITEMDATA, index, 0);
2072 /* send TBN_QUERYDELETE notification */
2073 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2077 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2078 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2079 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2081 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2083 /* insert into 'available button' list */
2084 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2086 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2087 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2092 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2097 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2100 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2103 case IDOK: /* Add button */
2108 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2109 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2110 TRACE("Add: index %d\n", index);
2112 /* send TBN_QUERYINSERT notification */
2114 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2119 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2123 /* remove from 'available buttons' list */
2124 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2125 if (index == count-1)
2126 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2128 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2132 PCUSTOMBUTTON btnNew;
2134 /* duplicate 'separator' button */
2135 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2136 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2140 /* insert into 'toolbar button' list */
2141 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2142 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2143 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2145 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2147 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2153 EndDialog(hwnd, FALSE);
2163 /* delete items from 'toolbar buttons' listbox*/
2164 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2165 for (i = 0; i < count; i++)
2167 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2169 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2171 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2174 /* delete items from 'available buttons' listbox*/
2175 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2176 for (i = 0; i < count; i++)
2178 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2180 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2182 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2187 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2189 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2194 COLORREF oldText = 0;
2198 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2199 if (btnInfo == NULL)
2201 FIXME("btnInfo invalid!\n");
2205 /* set colors and select objects */
2206 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2207 if (btnInfo->bVirtual)
2208 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2210 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2211 hPen = CreatePen( PS_SOLID, 1,
2212 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2213 hOldPen = SelectObject (lpdis->hDC, hPen );
2214 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2216 /* fill background rectangle */
2217 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2218 lpdis->rcItem.right, lpdis->rcItem.bottom);
2220 /* calculate button and text rectangles */
2221 CopyRect (&rcButton, &lpdis->rcItem);
2222 InflateRect (&rcButton, -1, -1);
2223 CopyRect (&rcText, &rcButton);
2224 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2225 rcText.left = rcButton.right + 2;
2227 /* draw focus rectangle */
2228 if (lpdis->itemState & ODS_FOCUS)
2229 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2232 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2233 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2235 /* draw image and text */
2236 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2237 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2238 btnInfo->btn.iBitmap));
2239 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2240 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2242 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2243 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2245 /* delete objects and reset colors */
2246 SelectObject (lpdis->hDC, hOldBrush);
2247 SelectObject (lpdis->hDC, hOldPen);
2248 SetBkColor (lpdis->hDC, oldBk);
2249 SetTextColor (lpdis->hDC, oldText);
2250 DeleteObject( hPen );
2255 case WM_MEASUREITEM:
2256 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2258 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2260 lpmis->itemHeight = 15 + 8; /* default height */
2272 /***********************************************************************
2273 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2277 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2280 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2281 INT nIndex = 0, nButtons, nCount;
2285 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2289 if (lpAddBmp->hInst == HINST_COMMCTRL)
2291 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2293 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2295 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2300 TRACE ("adding %d internal bitmaps!\n", nButtons);
2302 /* Windows resize all the buttons to the size of a newly added standard image */
2303 if (lpAddBmp->nID & 1)
2306 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2307 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2309 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2310 MAKELPARAM((WORD)24, (WORD)24));
2311 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2312 MAKELPARAM((WORD)31, (WORD)30));
2317 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2318 MAKELPARAM((WORD)16, (WORD)16));
2319 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2320 MAKELPARAM((WORD)22, (WORD)22));
2323 TOOLBAR_CalcToolbar (hwnd);
2327 nButtons = (INT)wParam;
2331 TRACE ("adding %d bitmaps!\n", nButtons);
2334 if (!infoPtr->cimlDef) {
2335 /* create new default image list */
2336 TRACE ("creating default image list!\n");
2338 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2339 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2340 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2341 infoPtr->himlInt = himlDef;
2344 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2348 WARN("No default image list available\n");
2352 nCount = ImageList_GetImageCount(himlDef);
2354 /* Add bitmaps to the default image list */
2355 if (lpAddBmp->hInst == NULL)
2358 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2359 HDC hdcImage, hdcBitmap;
2361 /* copy the bitmap before adding it so that the user's bitmap
2362 * doesn't get modified.
2364 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2366 hdcImage = CreateCompatibleDC(0);
2367 hdcBitmap = CreateCompatibleDC(0);
2369 /* create new bitmap */
2370 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2371 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2372 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2374 /* Copy the user's image */
2375 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2376 hdcBitmap, 0, 0, SRCCOPY);
2378 SelectObject (hdcImage, hOldBitmapLoad);
2379 SelectObject (hdcBitmap, hOldBitmapBitmap);
2380 DeleteDC (hdcImage);
2381 DeleteDC (hdcBitmap);
2383 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2384 DeleteObject (hbmLoad);
2386 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2388 /* Add system bitmaps */
2389 switch (lpAddBmp->nID)
2391 case IDB_STD_SMALL_COLOR:
2392 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2393 MAKEINTRESOURCEA(IDB_STD_SMALL));
2394 nIndex = ImageList_AddMasked (himlDef,
2395 hbmLoad, comctl32_color.clrBtnFace);
2396 DeleteObject (hbmLoad);
2399 case IDB_STD_LARGE_COLOR:
2400 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2401 MAKEINTRESOURCEA(IDB_STD_LARGE));
2402 nIndex = ImageList_AddMasked (himlDef,
2403 hbmLoad, comctl32_color.clrBtnFace);
2404 DeleteObject (hbmLoad);
2407 case IDB_VIEW_SMALL_COLOR:
2408 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2409 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2410 nIndex = ImageList_AddMasked (himlDef,
2411 hbmLoad, comctl32_color.clrBtnFace);
2412 DeleteObject (hbmLoad);
2415 case IDB_VIEW_LARGE_COLOR:
2416 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2417 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2418 nIndex = ImageList_AddMasked (himlDef,
2419 hbmLoad, comctl32_color.clrBtnFace);
2420 DeleteObject (hbmLoad);
2423 case IDB_HIST_SMALL_COLOR:
2424 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2425 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2426 nIndex = ImageList_AddMasked (himlDef,
2427 hbmLoad, comctl32_color.clrBtnFace);
2428 DeleteObject (hbmLoad);
2431 case IDB_HIST_LARGE_COLOR:
2432 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2433 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2434 nIndex = ImageList_AddMasked (himlDef,
2435 hbmLoad, comctl32_color.clrBtnFace);
2436 DeleteObject (hbmLoad);
2440 nIndex = ImageList_GetImageCount (himlDef);
2441 ERR ("invalid imagelist!\n");
2447 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2448 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2449 DeleteObject (hbmLoad);
2452 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2454 if (infoPtr->nNumBitmapInfos == 0)
2456 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2460 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2461 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2462 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2465 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2466 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2467 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2469 infoPtr->nNumBitmapInfos++;
2470 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2474 INT imagecount = ImageList_GetImageCount(himlDef);
2476 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2478 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",
2479 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2480 infoPtr->nNumBitmaps+nButtons,imagecount);
2482 infoPtr->nNumBitmaps = imagecount;
2485 infoPtr->nNumBitmaps += nButtons;
2488 InvalidateRect(hwnd, NULL, TRUE);
2495 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2497 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2498 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2499 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2501 TRACE("adding %d buttons!\n", wParam);
2503 nAddButtons = (UINT)wParam;
2504 nOldButtons = infoPtr->nNumButtons;
2505 nNewButtons = nOldButtons + nAddButtons;
2507 if (infoPtr->nNumButtons == 0) {
2509 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2512 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2514 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2515 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2516 nOldButtons * sizeof(TBUTTON_INFO));
2520 infoPtr->nNumButtons = nNewButtons;
2522 /* insert new button data */
2523 for (nCount = 0; nCount < nAddButtons; nCount++) {
2524 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2525 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2526 btnPtr->idCommand = lpTbb[nCount].idCommand;
2527 btnPtr->fsState = lpTbb[nCount].fsState;
2528 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2529 btnPtr->dwData = lpTbb[nCount].dwData;
2530 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2531 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2533 btnPtr->iString = lpTbb[nCount].iString;
2534 btnPtr->bHot = FALSE;
2536 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2539 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2540 ti.cbSize = sizeof (TTTOOLINFOA);
2542 ti.uId = btnPtr->idCommand;
2544 ti.lpszText = LPSTR_TEXTCALLBACKA;
2546 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2551 TOOLBAR_CalcToolbar (hwnd);
2553 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2555 InvalidateRect(hwnd, NULL, TRUE);
2562 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2565 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2566 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2568 TRACE("adding %d buttons!\n", wParam);
2570 nAddButtons = (UINT)wParam;
2571 nOldButtons = infoPtr->nNumButtons;
2572 nNewButtons = nOldButtons + nAddButtons;
2574 if (infoPtr->nNumButtons == 0) {
2576 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2579 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2581 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2582 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2583 nOldButtons * sizeof(TBUTTON_INFO));
2587 infoPtr->nNumButtons = nNewButtons;
2589 /* insert new button data */
2590 for (nCount = 0; nCount < nAddButtons; nCount++) {
2591 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2592 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2593 btnPtr->idCommand = lpTbb[nCount].idCommand;
2594 btnPtr->fsState = lpTbb[nCount].fsState;
2595 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2596 btnPtr->dwData = lpTbb[nCount].dwData;
2597 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2598 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2600 btnPtr->iString = lpTbb[nCount].iString;
2601 btnPtr->bHot = FALSE;
2603 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2606 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2607 ti.cbSize = sizeof (TTTOOLINFOW);
2609 ti.uId = btnPtr->idCommand;
2611 ti.lpszText = LPSTR_TEXTCALLBACKW;
2614 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2619 TOOLBAR_CalcToolbar (hwnd);
2621 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2623 InvalidateRect(hwnd, NULL, TRUE);
2630 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2635 if ((wParam) && (HIWORD(lParam) == 0)) {
2638 TRACE("adding string from resource!\n");
2640 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2643 TRACE("len=%d \"%s\"\n", len, szString);
2644 nIndex = infoPtr->nNumStrings;
2645 if (infoPtr->nNumStrings == 0) {
2647 Alloc (sizeof(LPWSTR));
2650 LPWSTR *oldStrings = infoPtr->strings;
2652 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2653 memcpy (&infoPtr->strings[0], &oldStrings[0],
2654 sizeof(LPWSTR) * infoPtr->nNumStrings);
2658 /*Alloc zeros out the allocated memory*/
2659 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2660 infoPtr->nNumStrings++;
2663 LPSTR p = (LPSTR)lParam;
2668 TRACE("adding string(s) from array!\n");
2670 nIndex = infoPtr->nNumStrings;
2673 TRACE("len=%d \"%s\"\n", len, p);
2675 if (infoPtr->nNumStrings == 0) {
2677 Alloc (sizeof(LPWSTR));
2680 LPWSTR *oldStrings = infoPtr->strings;
2682 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2683 memcpy (&infoPtr->strings[0], &oldStrings[0],
2684 sizeof(LPWSTR) * infoPtr->nNumStrings);
2688 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2689 infoPtr->nNumStrings++;
2700 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2702 #define MAX_RESOURCE_STRING_LENGTH 512
2703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2706 if ((wParam) && (HIWORD(lParam) == 0)) {
2707 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2709 TRACE("adding string from resource!\n");
2711 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2712 szString, MAX_RESOURCE_STRING_LENGTH);
2714 TRACE("len=%d %s\n", len, debugstr_w(szString));
2715 TRACE("First char: 0x%x\n", *szString);
2716 if (szString[0] == L'|')
2718 PWSTR p = szString + 1;
2720 nIndex = infoPtr->nNumStrings;
2721 while (*p != L'|' && *p != L'\0') {
2724 if (infoPtr->nNumStrings == 0) {
2725 infoPtr->strings = Alloc (sizeof(LPWSTR));
2729 LPWSTR *oldStrings = infoPtr->strings;
2730 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2731 memcpy(&infoPtr->strings[0], &oldStrings[0],
2732 sizeof(LPWSTR) * infoPtr->nNumStrings);
2736 np=strchrW (p, '|');
2744 TRACE("len=%d %s\n", len, debugstr_w(p));
2745 infoPtr->strings[infoPtr->nNumStrings] =
2746 Alloc (sizeof(WCHAR)*(len+1));
2747 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2748 infoPtr->nNumStrings++;
2755 nIndex = infoPtr->nNumStrings;
2756 if (infoPtr->nNumStrings == 0) {
2758 Alloc (sizeof(LPWSTR));
2761 LPWSTR *oldStrings = infoPtr->strings;
2763 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2764 memcpy (&infoPtr->strings[0], &oldStrings[0],
2765 sizeof(LPWSTR) * infoPtr->nNumStrings);
2769 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2770 infoPtr->nNumStrings++;
2774 LPWSTR p = (LPWSTR)lParam;
2779 TRACE("adding string(s) from array!\n");
2780 nIndex = infoPtr->nNumStrings;
2784 TRACE("len=%d %s\n", len, debugstr_w(p));
2785 if (infoPtr->nNumStrings == 0) {
2787 Alloc (sizeof(LPWSTR));
2790 LPWSTR *oldStrings = infoPtr->strings;
2792 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2793 memcpy (&infoPtr->strings[0], &oldStrings[0],
2794 sizeof(LPWSTR) * infoPtr->nNumStrings);
2798 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2799 infoPtr->nNumStrings++;
2810 TOOLBAR_AutoSize (HWND hwnd)
2812 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2818 UINT uPosFlags = SWP_NOZORDER;
2820 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2822 parent = GetParent (hwnd);
2823 GetClientRect(parent, &parent_rect);
2825 x = parent_rect.left;
2826 y = parent_rect.top;
2828 /* FIXME: we should be able to early out if nothing */
2829 /* has changed with nWidth != parent_rect width */
2831 if (infoPtr->dwStyle & CCS_NORESIZE) {
2832 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2835 TOOLBAR_CalcToolbar (hwnd);
2838 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2839 TOOLBAR_CalcToolbar (hwnd);
2840 InvalidateRect( hwnd, NULL, TRUE );
2841 cy = infoPtr->nHeight;
2842 cx = infoPtr->nWidth;
2844 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2845 GetWindowRect(hwnd, &window_rect);
2846 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2847 y = window_rect.top;
2849 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2850 GetWindowRect(hwnd, &window_rect);
2851 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2855 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2856 uPosFlags |= SWP_NOMOVE;
2858 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2859 cy += GetSystemMetrics(SM_CYEDGE);
2861 if (infoPtr->dwStyle & WS_BORDER)
2864 cy += GetSystemMetrics(SM_CYEDGE);
2865 cx += GetSystemMetrics(SM_CYEDGE);
2868 infoPtr->bAutoSize = TRUE;
2869 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2870 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2871 * after the setwindowpos calls */
2872 infoPtr->bAutoSize = FALSE;
2879 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2883 return infoPtr->nNumButtons;
2888 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2892 if (infoPtr == NULL) {
2893 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2894 ERR("infoPtr == NULL!\n");
2898 infoPtr->dwStructSize = (DWORD)wParam;
2905 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2908 TBUTTON_INFO *btnPtr;
2911 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2913 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2917 btnPtr = &infoPtr->buttons[nIndex];
2918 btnPtr->iBitmap = LOWORD(lParam);
2920 /* we HAVE to erase the background, the new bitmap could be */
2922 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2929 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2932 TBUTTON_INFO *btnPtr;
2935 BOOL bChecked = FALSE;
2937 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2939 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2944 btnPtr = &infoPtr->buttons[nIndex];
2946 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2948 if (LOWORD(lParam) == FALSE)
2949 btnPtr->fsState &= ~TBSTATE_CHECKED;
2951 if (btnPtr->fsStyle & BTNS_GROUP) {
2953 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2954 if (nOldIndex == nIndex)
2956 if (nOldIndex != -1)
2957 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2959 btnPtr->fsState |= TBSTATE_CHECKED;
2962 if( bChecked != LOWORD(lParam) )
2964 if (nOldIndex != -1)
2965 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2966 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2969 /* FIXME: Send a WM_NOTIFY?? */
2976 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2980 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2985 TOOLBAR_Customize (HWND hwnd)
2987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2988 CUSTDLG_INFO custInfo;
2994 custInfo.tbInfo = infoPtr;
2995 custInfo.tbHwnd = hwnd;
2997 /* send TBN_BEGINADJUST notification */
2998 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3001 if (!(hRes = FindResourceA (COMCTL32_hModule,
3002 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
3006 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3009 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3010 (LPDLGTEMPLATEA)template,
3012 TOOLBAR_CustomizeDialogProc,
3015 /* send TBN_ENDADJUST notification */
3016 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3024 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3027 INT nIndex = (INT)wParam;
3030 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3033 memset(&nmtb, 0, sizeof(nmtb));
3034 nmtb.iItem = nIndex;
3035 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3037 if ((infoPtr->hwndToolTip) &&
3038 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3041 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3042 ti.cbSize = sizeof (TTTOOLINFOA);
3044 ti.uId = infoPtr->buttons[nIndex].idCommand;
3046 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3049 if (infoPtr->nNumButtons == 1) {
3050 TRACE(" simple delete!\n");
3051 Free (infoPtr->buttons);
3052 infoPtr->buttons = NULL;
3053 infoPtr->nNumButtons = 0;
3056 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3057 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3059 infoPtr->nNumButtons--;
3060 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3062 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3063 nIndex * sizeof(TBUTTON_INFO));
3066 if (nIndex < infoPtr->nNumButtons) {
3067 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3068 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3074 TOOLBAR_CalcToolbar (hwnd);
3076 InvalidateRect (hwnd, NULL, TRUE);
3083 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3086 TBUTTON_INFO *btnPtr;
3090 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3092 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3097 btnPtr = &infoPtr->buttons[nIndex];
3099 bState = btnPtr->fsState & TBSTATE_ENABLED;
3101 /* update the toolbar button state */
3102 if(LOWORD(lParam) == FALSE) {
3103 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3105 btnPtr->fsState |= TBSTATE_ENABLED;
3108 /* redraw the button only if the state of the button changed */
3109 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3110 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3116 static inline LRESULT
3117 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3121 return infoPtr->bAnchor;
3126 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3128 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3131 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3135 return infoPtr->buttons[nIndex].iBitmap;
3139 static inline LRESULT
3140 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3147 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3150 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3151 INT nIndex = (INT)wParam;
3152 TBUTTON_INFO *btnPtr;
3154 if (infoPtr == NULL)
3160 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3163 btnPtr = &infoPtr->buttons[nIndex];
3164 lpTbb->iBitmap = btnPtr->iBitmap;
3165 lpTbb->idCommand = btnPtr->idCommand;
3166 lpTbb->fsState = btnPtr->fsState;
3167 lpTbb->fsStyle = btnPtr->fsStyle;
3168 lpTbb->bReserved[0] = 0;
3169 lpTbb->bReserved[1] = 0;
3170 lpTbb->dwData = btnPtr->dwData;
3171 lpTbb->iString = btnPtr->iString;
3178 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3181 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3182 TBUTTON_INFO *btnPtr;
3185 if (infoPtr == NULL)
3187 if (lpTbInfo == NULL)
3189 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3192 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3193 lpTbInfo->dwMask & 0x80000000);
3197 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3199 if (lpTbInfo->dwMask & TBIF_COMMAND)
3200 lpTbInfo->idCommand = btnPtr->idCommand;
3201 if (lpTbInfo->dwMask & TBIF_IMAGE)
3202 lpTbInfo->iImage = btnPtr->iBitmap;
3203 if (lpTbInfo->dwMask & TBIF_LPARAM)
3204 lpTbInfo->lParam = btnPtr->dwData;
3205 if (lpTbInfo->dwMask & TBIF_SIZE)
3206 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3207 if (lpTbInfo->dwMask & TBIF_STATE)
3208 lpTbInfo->fsState = btnPtr->fsState;
3209 if (lpTbInfo->dwMask & TBIF_STYLE)
3210 lpTbInfo->fsStyle = btnPtr->fsStyle;
3211 if (lpTbInfo->dwMask & TBIF_TEXT) {
3212 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3213 can't use TOOLBAR_GetText here */
3215 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3216 lpText = (LPWSTR)btnPtr->iString;
3217 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3219 lpTbInfo->pszText[0] = '\0';
3226 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3229 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3230 TBUTTON_INFO *btnPtr;
3233 if (infoPtr == NULL)
3235 if (lpTbInfo == NULL)
3237 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3240 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3241 lpTbInfo->dwMask & 0x80000000);
3245 btnPtr = &infoPtr->buttons[nIndex];
3250 if (lpTbInfo->dwMask & TBIF_COMMAND)
3251 lpTbInfo->idCommand = btnPtr->idCommand;
3252 if (lpTbInfo->dwMask & TBIF_IMAGE)
3253 lpTbInfo->iImage = btnPtr->iBitmap;
3254 if (lpTbInfo->dwMask & TBIF_LPARAM)
3255 lpTbInfo->lParam = btnPtr->dwData;
3256 if (lpTbInfo->dwMask & TBIF_SIZE)
3257 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3258 if (lpTbInfo->dwMask & TBIF_STATE)
3259 lpTbInfo->fsState = btnPtr->fsState;
3260 if (lpTbInfo->dwMask & TBIF_STYLE)
3261 lpTbInfo->fsStyle = btnPtr->fsStyle;
3262 if (lpTbInfo->dwMask & TBIF_TEXT) {
3263 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3264 can't use TOOLBAR_GetText here */
3266 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3267 lpText = (LPWSTR)btnPtr->iString;
3268 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3270 lpTbInfo->pszText[0] = '\0';
3278 TOOLBAR_GetButtonSize (HWND hwnd)
3280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3282 if (infoPtr->nNumButtons > 0)
3283 return MAKELONG((WORD)infoPtr->nButtonWidth,
3284 (WORD)infoPtr->nButtonHeight);
3286 return MAKELONG(8,7);
3291 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3293 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3300 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3304 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3306 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3307 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3312 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3319 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3323 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3327 ret = strlenW (lpText);
3330 strcpyW ((LPWSTR)lParam, lpText);
3338 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3340 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3341 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3342 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3346 inline static LRESULT
3347 TOOLBAR_GetExtendedStyle (HWND hwnd)
3349 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3353 return infoPtr->dwExStyle;
3358 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3360 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3361 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3362 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3367 TOOLBAR_GetHotItem (HWND hwnd)
3369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3371 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3374 if (infoPtr->nHotItem < 0)
3377 return (LRESULT)infoPtr->nHotItem;
3382 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3384 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3385 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3386 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3391 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3393 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3394 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3396 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3398 *lptbim = infoPtr->tbim;
3405 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3409 TRACE("hwnd = %p\n", hwnd);
3411 return (LRESULT)infoPtr->clrInsertMark;
3416 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3419 TBUTTON_INFO *btnPtr;
3423 if (infoPtr == NULL)
3425 nIndex = (INT)wParam;
3426 btnPtr = &infoPtr->buttons[nIndex];
3427 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3429 lpRect = (LPRECT)lParam;
3432 if (btnPtr->fsState & TBSTATE_HIDDEN)
3435 lpRect->left = btnPtr->rect.left;
3436 lpRect->right = btnPtr->rect.right;
3437 lpRect->bottom = btnPtr->rect.bottom;
3438 lpRect->top = btnPtr->rect.top;
3445 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3448 LPSIZE lpSize = (LPSIZE)lParam;
3453 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3454 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3456 TRACE("maximum size %ld x %ld\n",
3457 infoPtr->rcBound.right - infoPtr->rcBound.left,
3458 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3464 /* << TOOLBAR_GetObject >> */
3468 TOOLBAR_GetPadding (HWND hwnd)
3470 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3473 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3474 return (LRESULT) oldPad;
3479 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3482 TBUTTON_INFO *btnPtr;
3486 if (infoPtr == NULL)
3488 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3489 btnPtr = &infoPtr->buttons[nIndex];
3490 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3492 lpRect = (LPRECT)lParam;
3496 lpRect->left = btnPtr->rect.left;
3497 lpRect->right = btnPtr->rect.right;
3498 lpRect->bottom = btnPtr->rect.bottom;
3499 lpRect->top = btnPtr->rect.top;
3506 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3510 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3511 return infoPtr->nRows;
3518 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3523 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3527 return infoPtr->buttons[nIndex].fsState;
3532 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3534 return GetWindowLongW(hwnd, GWL_STYLE);
3539 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3543 if (infoPtr == NULL)
3546 return infoPtr->nMaxTextRows;
3551 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3555 if (infoPtr == NULL)
3557 return (LRESULT)infoPtr->hwndToolTip;
3562 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3566 TRACE("%s hwnd=%p stub!\n",
3567 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3569 return infoPtr->bUnicode;
3573 inline static LRESULT
3574 TOOLBAR_GetVersion (HWND hwnd)
3576 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3577 return infoPtr->iVersion;
3582 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 TBUTTON_INFO *btnPtr;
3590 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3594 btnPtr = &infoPtr->buttons[nIndex];
3595 if (LOWORD(lParam) == FALSE)
3596 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3598 btnPtr->fsState |= TBSTATE_HIDDEN;
3600 TOOLBAR_CalcToolbar (hwnd);
3602 InvalidateRect (hwnd, NULL, TRUE);
3608 inline static LRESULT
3609 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3611 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3616 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3619 TBUTTON_INFO *btnPtr;
3623 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3627 btnPtr = &infoPtr->buttons[nIndex];
3628 oldState = btnPtr->fsState;
3629 if (LOWORD(lParam) == FALSE)
3630 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3632 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3634 if(oldState != btnPtr->fsState)
3635 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3642 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3646 INT nIndex = (INT)wParam;
3647 TBUTTON_INFO *oldButtons;
3652 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3655 /* EPP: this seems to be an undocumented call (from my IE4)
3656 * I assume in that case that:
3657 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3658 * - index of insertion is at the end of existing buttons
3659 * I only see this happen with nIndex == -1, but it could have a special
3660 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3662 nIndex = infoPtr->nNumButtons;
3664 } else if (nIndex < 0)
3667 /* If the string passed is not an index, assume address of string
3668 and do our own AddString */
3669 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3673 TRACE("string %s passed instead of index, adding string\n",
3674 debugstr_a((LPSTR)lpTbb->iString));
3675 len = strlen((LPSTR)lpTbb->iString) + 2;
3677 strcpy(ptr, (LPSTR)lpTbb->iString);
3678 ptr[len - 1] = 0; /* ended by two '\0' */
3679 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3683 TRACE("inserting button index=%d\n", nIndex);
3684 if (nIndex > infoPtr->nNumButtons) {
3685 nIndex = infoPtr->nNumButtons;
3686 TRACE("adjust index=%d\n", nIndex);
3689 oldButtons = infoPtr->buttons;
3690 infoPtr->nNumButtons++;
3691 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3692 /* pre insert copy */
3694 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3695 nIndex * sizeof(TBUTTON_INFO));
3698 /* insert new button */
3699 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3700 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3701 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3702 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3703 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3704 /* if passed string and not index, then add string */
3705 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3706 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3709 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3711 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3714 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3715 ti.cbSize = sizeof (TTTOOLINFOA);
3717 ti.uId = lpTbb->idCommand;
3719 ti.lpszText = LPSTR_TEXTCALLBACKA;
3721 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3725 /* post insert copy */
3726 if (nIndex < infoPtr->nNumButtons - 1) {
3727 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3728 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3733 TOOLBAR_CalcToolbar (hwnd);
3735 InvalidateRect (hwnd, NULL, TRUE);
3742 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3745 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3746 INT nIndex = (INT)wParam;
3747 TBUTTON_INFO *oldButtons;
3752 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3755 /* EPP: this seems to be an undocumented call (from my IE4)
3756 * I assume in that case that:
3757 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3758 * - index of insertion is at the end of existing buttons
3759 * I only see this happen with nIndex == -1, but it could have a special
3760 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3762 nIndex = infoPtr->nNumButtons;
3764 } else if (nIndex < 0)
3767 /* If the string passed is not an index, assume address of string
3768 and do our own AddString */
3769 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3773 TRACE("string %s passed instead of index, adding string\n",
3774 debugstr_w((LPWSTR)lpTbb->iString));
3775 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3776 ptr = Alloc(len*sizeof(WCHAR));
3777 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3778 ptr[len - 1] = 0; /* ended by two '\0' */
3779 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3783 TRACE("inserting button index=%d\n", nIndex);
3784 if (nIndex > infoPtr->nNumButtons) {
3785 nIndex = infoPtr->nNumButtons;
3786 TRACE("adjust index=%d\n", nIndex);
3789 oldButtons = infoPtr->buttons;
3790 infoPtr->nNumButtons++;
3791 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3792 /* pre insert copy */
3794 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3795 nIndex * sizeof(TBUTTON_INFO));
3798 /* insert new button */
3799 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3800 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3801 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3802 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3803 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3804 /* if passed string and not index, then add string */
3805 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3806 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3809 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3811 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3814 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3815 ti.cbSize = sizeof (TTTOOLINFOW);
3817 ti.uId = lpTbb->idCommand;
3819 ti.lpszText = LPSTR_TEXTCALLBACKW;
3821 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3825 /* post insert copy */
3826 if (nIndex < infoPtr->nNumButtons - 1) {
3827 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3828 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3833 TOOLBAR_CalcToolbar (hwnd);
3835 InvalidateRect (hwnd, NULL, TRUE);
3841 /* << TOOLBAR_InsertMarkHitTest >> */
3845 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3850 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3854 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3859 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3868 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3873 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3878 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3882 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3887 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3892 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3896 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3901 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3906 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3910 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3915 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3917 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3920 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3924 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3929 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3932 tbab.hInst = (HINSTANCE)lParam;
3933 tbab.nID = (UINT_PTR)wParam;
3935 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3937 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3942 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3944 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3945 WCHAR wAccel = (WCHAR)wParam;
3946 UINT* pIDButton = (UINT*)lParam;
3947 WCHAR wszAccel[] = {'&',wAccel,0};
3950 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3951 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3953 for (i = 0; i < infoPtr->nNumButtons; i++)
3955 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3956 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3957 !(btnPtr->fsState & TBSTATE_HIDDEN))
3959 int iLen = strlenW(wszAccel);
3960 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3967 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3972 if (!strncmpiW(lpszStr, wszAccel, iLen))
3974 *pIDButton = btnPtr->idCommand;
3986 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3991 TBUTTON_INFO *btnPtr;
3993 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3995 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3999 btnPtr = &infoPtr->buttons[nIndex];
4000 oldState = btnPtr->fsState;
4003 btnPtr->fsState |= TBSTATE_MARKED;
4005 btnPtr->fsState &= ~TBSTATE_MARKED;
4007 if(oldState != btnPtr->fsState)
4008 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4014 /* fixes up an index of a button affected by a move */
4015 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4019 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4021 else if (*pIndex == nIndex)
4022 *pIndex = nMoveIndex;
4026 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4028 else if (*pIndex == nIndex)
4029 *pIndex = nMoveIndex;
4035 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4037 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4040 INT nMoveIndex = (INT)lParam;
4041 TBUTTON_INFO button;
4043 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4045 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4046 if ((nIndex == -1) || (nMoveIndex < 0))
4049 if (nMoveIndex > infoPtr->nNumButtons - 1)
4050 nMoveIndex = infoPtr->nNumButtons - 1;
4052 button = infoPtr->buttons[nIndex];
4054 /* move button right */
4055 if (nIndex < nMoveIndex)
4057 nCount = nMoveIndex - nIndex;
4058 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4059 infoPtr->buttons[nMoveIndex] = button;
4061 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4062 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4063 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4064 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4066 else if (nIndex > nMoveIndex) /* move button left */
4068 nCount = nIndex - nMoveIndex;
4069 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4070 infoPtr->buttons[nMoveIndex] = button;
4072 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4073 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4074 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4075 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4078 TOOLBAR_CalcToolbar(hwnd);
4079 InvalidateRect(hwnd, NULL, TRUE);
4086 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4089 TBUTTON_INFO *btnPtr;
4093 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4097 btnPtr = &infoPtr->buttons[nIndex];
4098 oldState = btnPtr->fsState;
4099 if (LOWORD(lParam) == FALSE)
4100 btnPtr->fsState &= ~TBSTATE_PRESSED;
4102 btnPtr->fsState |= TBSTATE_PRESSED;
4104 if(oldState != btnPtr->fsState)
4105 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4110 /* FIXME: there might still be some confusion her between number of buttons
4111 * and number of bitmaps */
4113 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4116 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4118 int i = 0, nOldButtons = 0, pos = 0;
4119 int nOldBitmaps, nNewBitmaps;
4120 HIMAGELIST himlDef = 0;
4122 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4123 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4124 lpReplace->nButtons);
4126 if (lpReplace->hInstOld == HINST_COMMCTRL)
4128 FIXME("changing standard bitmaps not implemented\n");
4131 else if (lpReplace->hInstOld != 0)
4133 FIXME("resources not in the current module not implemented\n");
4138 hBitmap = (HBITMAP) lpReplace->nIDNew;
4141 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4142 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4143 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4144 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4145 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4147 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4148 nOldButtons = tbi->nButtons;
4149 tbi->nButtons = lpReplace->nButtons;
4150 tbi->hInst = lpReplace->hInstNew;
4151 tbi->nID = lpReplace->nIDNew;
4152 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4155 pos += tbi->nButtons;
4158 if (nOldButtons == 0)
4160 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4164 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4165 nOldBitmaps = ImageList_GetImageCount(himlDef);
4167 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4169 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4170 ImageList_Remove(himlDef, i);
4174 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4175 HDC hdcImage, hdcBitmap;
4177 /* copy the bitmap before adding it so that the user's bitmap
4178 * doesn't get modified.
4180 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4182 hdcImage = CreateCompatibleDC(0);
4183 hdcBitmap = CreateCompatibleDC(0);
4185 /* create new bitmap */
4186 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4187 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4188 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4190 /* Copy the user's image */
4191 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4192 hdcBitmap, 0, 0, SRCCOPY);
4194 SelectObject (hdcImage, hOldBitmapLoad);
4195 SelectObject (hdcBitmap, hOldBitmapBitmap);
4196 DeleteDC (hdcImage);
4197 DeleteDC (hdcBitmap);
4199 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4200 nNewBitmaps = ImageList_GetImageCount(himlDef);
4201 DeleteObject (hbmLoad);
4204 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4206 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4207 pos, nOldBitmaps, nNewBitmaps);
4209 InvalidateRect(hwnd, NULL, TRUE);
4215 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4218 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4219 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4221 if (lpSave == NULL) return 0;
4224 /* save toolbar information */
4225 FIXME("save to \"%s\" \"%s\"\n",
4226 lpSave->pszSubKey, lpSave->pszValueName);
4231 /* restore toolbar information */
4233 FIXME("restore from \"%s\" \"%s\"\n",
4234 lpSave->pszSubKey, lpSave->pszValueName);
4245 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4248 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4249 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4255 /* save toolbar information */
4256 FIXME("save to \"%s\" \"%s\"\n",
4257 lpSave->pszSubKey, lpSave->pszValueName);
4262 /* restore toolbar information */
4264 FIXME("restore from \"%s\" \"%s\"\n",
4265 lpSave->pszSubKey, lpSave->pszValueName);
4276 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4279 BOOL bOldAnchor = infoPtr->bAnchor;
4281 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4283 infoPtr->bAnchor = (BOOL)wParam;
4285 /* Native does not remove the hot effect from an already hot button */
4287 return (LRESULT)bOldAnchor;
4292 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4295 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4297 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4300 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4302 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4305 if (infoPtr->nNumButtons > 0)
4306 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4307 infoPtr->nNumButtons,
4308 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4309 LOWORD(lParam), HIWORD(lParam));
4311 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4312 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4315 if ((himlDef == infoPtr->himlInt) &&
4316 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4318 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4319 infoPtr->nBitmapHeight);
4327 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4330 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4331 TBUTTON_INFO *btnPtr;
4337 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4340 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4341 lptbbi->dwMask & 0x80000000);
4345 btnPtr = &infoPtr->buttons[nIndex];
4346 if (lptbbi->dwMask & TBIF_COMMAND)
4347 btnPtr->idCommand = lptbbi->idCommand;
4348 if (lptbbi->dwMask & TBIF_IMAGE)
4349 btnPtr->iBitmap = lptbbi->iImage;
4350 if (lptbbi->dwMask & TBIF_LPARAM)
4351 btnPtr->dwData = lptbbi->lParam;
4352 if (lptbbi->dwMask & TBIF_SIZE)
4353 btnPtr->cx = lptbbi->cx;
4354 if (lptbbi->dwMask & TBIF_STATE)
4355 btnPtr->fsState = lptbbi->fsState;
4356 if (lptbbi->dwMask & TBIF_STYLE)
4357 btnPtr->fsStyle = lptbbi->fsStyle;
4359 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4360 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4361 /* iString is index, zero it to make Str_SetPtr succeed */
4364 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4367 /* save the button rect to see if we need to redraw the whole toolbar */
4368 oldBtnRect = btnPtr->rect;
4369 TOOLBAR_CalcToolbar(hwnd);
4371 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4372 InvalidateRect(hwnd, NULL, TRUE);
4374 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4381 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4383 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4384 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4385 TBUTTON_INFO *btnPtr;
4391 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4394 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4395 lptbbi->dwMask & 0x80000000);
4399 btnPtr = &infoPtr->buttons[nIndex];
4400 if (lptbbi->dwMask & TBIF_COMMAND)
4401 btnPtr->idCommand = lptbbi->idCommand;
4402 if (lptbbi->dwMask & TBIF_IMAGE)
4403 btnPtr->iBitmap = lptbbi->iImage;
4404 if (lptbbi->dwMask & TBIF_LPARAM)
4405 btnPtr->dwData = lptbbi->lParam;
4406 if (lptbbi->dwMask & TBIF_SIZE)
4407 btnPtr->cx = lptbbi->cx;
4408 if (lptbbi->dwMask & TBIF_STATE)
4409 btnPtr->fsState = lptbbi->fsState;
4410 if (lptbbi->dwMask & TBIF_STYLE)
4411 btnPtr->fsStyle = lptbbi->fsStyle;
4413 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4414 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4415 /* iString is index, zero it to make Str_SetPtr succeed */
4417 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4420 /* save the button rect to see if we need to redraw the whole toolbar */
4421 oldBtnRect = btnPtr->rect;
4422 TOOLBAR_CalcToolbar(hwnd);
4424 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4425 InvalidateRect(hwnd, NULL, TRUE);
4427 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4434 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4436 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4437 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4439 if ((cx < 0) || (cy < 0))
4441 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4445 /* The documentation claims you can only change the button size before
4446 * any button has been added. But this is wrong.
4447 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4448 * it to the toolbar, and it checks that the return value is nonzero - mjm
4449 * Further testing shows that we must actually perform the change too.
4452 * The documentation also does not mention that if 0 is supplied for
4453 * either size, the system changes it to the default of 24 wide and
4454 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4456 infoPtr->nButtonWidth = (cx) ? cx : 24;
4457 infoPtr->nButtonHeight = (cy) ? cy : 22;
4463 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4467 if (infoPtr == NULL) {
4468 TRACE("Toolbar not initialized yet?????\n");
4472 /* if setting to current values, ignore */
4473 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4474 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4475 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4476 infoPtr->cxMin, infoPtr->cxMax);
4480 /* save new values */
4481 infoPtr->cxMin = (INT)LOWORD(lParam);
4482 infoPtr->cxMax = (INT)HIWORD(lParam);
4484 /* if both values are 0 then we are done */
4486 TRACE("setting both min and max to 0, norecalc\n");
4490 /* otherwise we need to recalc the toolbar and in some cases
4491 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4492 which doesn't actually draw - GA). */
4493 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4494 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4496 TOOLBAR_CalcToolbar (hwnd);
4498 InvalidateRect (hwnd, NULL, TRUE);
4505 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4508 INT nIndex = (INT)wParam;
4510 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4513 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4515 if (infoPtr->hwndToolTip) {
4517 FIXME("change tool tip!\n");
4526 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4529 HIMAGELIST himl = (HIMAGELIST)lParam;
4530 HIMAGELIST himlTemp;
4533 if (infoPtr->iVersion >= 5)
4536 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4537 &infoPtr->cimlDis, himl, id);
4539 /* FIXME: redraw ? */
4541 return (LRESULT)himlTemp;
4546 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4551 TRACE("hwnd = %p, dwMask = 0x%08lx, dwDTFlags = 0x%08lx\n", hwnd, (DWORD)wParam, (DWORD)lParam);
4553 dwTemp = infoPtr->dwDTFlags;
4554 infoPtr->dwDTFlags =
4555 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4557 return (LRESULT)dwTemp;
4560 /* This function differs a bit from what MSDN says it does:
4561 * 1. lParam contains extended style flags to OR with current style
4562 * (MSDN isn't clear on the OR bit)
4563 * 2. wParam appears to contain extended style flags to be reset
4564 * (MSDN says that this parameter is reserved)
4567 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4569 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4572 dwTemp = infoPtr->dwExStyle;
4573 infoPtr->dwExStyle &= ~wParam;
4574 infoPtr->dwExStyle |= (DWORD)lParam;
4576 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4578 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4579 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4580 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4582 TOOLBAR_CalcToolbar (hwnd);
4584 TOOLBAR_AutoSize(hwnd);
4586 InvalidateRect(hwnd, NULL, TRUE);
4588 return (LRESULT)dwTemp;
4593 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4596 HIMAGELIST himlTemp;
4597 HIMAGELIST himl = (HIMAGELIST)lParam;
4600 if (infoPtr->iVersion >= 5)
4603 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4605 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4606 &infoPtr->cimlHot, himl, id);
4608 /* FIXME: redraw ? */
4610 return (LRESULT)himlTemp;
4614 /* Makes previous hot button no longer hot, makes the specified
4615 * button hot and sends appropriate notifications. dwReason is one or
4616 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4617 * NOTE 1: this function does not validate nHit
4618 * NOTE 2: the name of this function is completely made up and
4619 * not based on any documentation from Microsoft. */
4621 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4623 if (infoPtr->nHotItem != nHit)
4625 NMTBHOTITEM nmhotitem;
4626 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4627 LRESULT no_highlight;
4629 /* Remove the effect of an old hot button if the button was
4630 drawn with the hot button effect */
4631 if(infoPtr->nHotItem >= 0)
4633 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4634 oldBtnPtr->bHot = FALSE;
4637 infoPtr->nHotItem = nHit;
4639 /* It's not a separator or in nowhere. It's a hot button. */
4641 btnPtr = &infoPtr->buttons[nHit];
4643 nmhotitem.dwFlags = dwReason;
4645 nmhotitem.idOld = oldBtnPtr->idCommand;
4647 nmhotitem.dwFlags |= HICF_ENTERING;
4649 nmhotitem.idNew = btnPtr->idCommand;
4651 nmhotitem.dwFlags |= HICF_LEAVING;
4653 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4655 /* now invalidate the old and new buttons so they will be painted */
4657 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4658 if (btnPtr && !no_highlight)
4660 btnPtr->bHot = TRUE;
4661 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4667 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4669 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4670 INT nOldHotItem = infoPtr->nHotItem;
4672 TRACE("hwnd = %p, nHit = %d\n", hwnd, (INT)wParam);
4674 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4677 /* NOTE: an application can still remove the hot item even if anchor
4678 * highlighting is enabled */
4680 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4681 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4683 if (nOldHotItem < 0)
4686 return (LRESULT)nOldHotItem;
4691 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4694 HIMAGELIST himlTemp;
4695 HIMAGELIST himl = (HIMAGELIST)lParam;
4698 if (infoPtr->iVersion >= 5)
4701 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4702 &infoPtr->cimlDef, himl, id);
4704 infoPtr->nNumBitmaps = 0;
4705 for (i = 0; i < infoPtr->cimlDef; i++)
4706 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4708 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4709 &infoPtr->nBitmapHeight);
4710 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4711 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4712 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4714 InvalidateRect(hwnd, NULL, TRUE);
4716 return (LRESULT)himlTemp;
4721 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4725 infoPtr->nIndent = (INT)wParam;
4729 /* process only on indent changing */
4730 if(infoPtr->nIndent != (INT)wParam)
4732 infoPtr->nIndent = (INT)wParam;
4733 TOOLBAR_CalcToolbar (hwnd);
4734 InvalidateRect(hwnd, NULL, FALSE);
4742 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4745 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4747 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4749 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4751 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4755 if ((lptbim->iButton == -1) ||
4756 ((lptbim->iButton < infoPtr->nNumButtons) &&
4757 (lptbim->iButton >= 0)))
4759 infoPtr->tbim = *lptbim;
4760 /* FIXME: don't need to update entire toolbar */
4761 InvalidateRect(hwnd, NULL, TRUE);
4764 ERR("Invalid button index %d\n", lptbim->iButton);
4771 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4775 infoPtr->clrInsertMark = (COLORREF)lParam;
4777 /* FIXME: don't need to update entire toolbar */
4778 InvalidateRect(hwnd, NULL, TRUE);
4785 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4789 if (infoPtr == NULL)
4792 infoPtr->nMaxTextRows = (INT)wParam;
4794 TOOLBAR_CalcToolbar(hwnd);
4799 /* MSDN gives slightly wrong info on padding.
4800 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4801 * 2. It is not used to create a blank area between the edge of the button
4802 * and the text or image if TBSTYLE_LIST is set. It is used to control
4803 * the gap between the image and text.
4804 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4805 * to control the bottom and right borders [with the border being
4806 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4807 * is shared evenly on both sides of the button.
4810 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4812 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4815 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4816 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4817 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4818 TRACE("cx=%ld, cy=%ld\n",
4819 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4820 return (LRESULT) oldPad;
4825 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4832 if (infoPtr == NULL)
4834 hwndOldNotify = infoPtr->hwndNotify;
4835 infoPtr->hwndNotify = (HWND)wParam;
4837 return (LRESULT)hwndOldNotify;
4842 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4844 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4845 LPRECT lprc = (LPRECT)lParam;
4849 if (LOWORD(wParam) > 1) {
4850 FIXME("multiple rows not supported!\n");
4853 if(infoPtr->nRows != LOWORD(wParam))
4855 infoPtr->nRows = LOWORD(wParam);
4857 /* recalculate toolbar */
4858 TOOLBAR_CalcToolbar (hwnd);
4860 /* repaint toolbar */
4861 InvalidateRect(hwnd, NULL, TRUE);
4864 /* return bounding rectangle */
4866 lprc->left = infoPtr->rcBound.left;
4867 lprc->right = infoPtr->rcBound.right;
4868 lprc->top = infoPtr->rcBound.top;
4869 lprc->bottom = infoPtr->rcBound.bottom;
4877 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4880 TBUTTON_INFO *btnPtr;
4883 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4887 btnPtr = &infoPtr->buttons[nIndex];
4889 /* if hidden state has changed the invalidate entire window and recalc */
4890 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4891 btnPtr->fsState = LOWORD(lParam);
4892 TOOLBAR_CalcToolbar (hwnd);
4893 InvalidateRect(hwnd, 0, TRUE);
4897 /* process state changing if current state doesn't match new state */
4898 if(btnPtr->fsState != LOWORD(lParam))
4900 btnPtr->fsState = LOWORD(lParam);
4901 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4909 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4911 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4917 inline static LRESULT
4918 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4920 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4922 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4924 if (infoPtr == NULL)
4926 infoPtr->hwndToolTip = (HWND)wParam;
4932 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4937 TRACE("%s hwnd=%p stub!\n",
4938 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4940 bTemp = infoPtr->bUnicode;
4941 infoPtr->bUnicode = (BOOL)wParam;
4948 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4952 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4953 comctl32_color.clrBtnHighlight :
4954 infoPtr->clrBtnHighlight;
4955 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4956 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4962 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4964 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4966 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4967 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4968 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4970 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4971 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4972 InvalidateRect(hwnd, NULL, TRUE);
4978 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4980 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4981 INT iOldVersion = infoPtr->iVersion;
4983 infoPtr->iVersion = iVersion;
4985 if (infoPtr->iVersion >= 5)
4986 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4993 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4995 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4996 WORD iString = HIWORD(wParam);
4997 WORD buffersize = LOWORD(wParam);
4998 LPSTR str = (LPSTR)lParam;
5001 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
5003 if (iString < infoPtr->nNumStrings)
5005 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
5007 TRACE("returning %s\n", debugstr_a(str));
5010 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5017 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5019 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5020 WORD iString = HIWORD(wParam);
5021 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5022 LPWSTR str = (LPWSTR)lParam;
5025 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5027 if (iString < infoPtr->nNumStrings)
5029 len = min(len, strlenW(infoPtr->strings[iString]));
5030 ret = (len+1)*sizeof(WCHAR);
5031 memcpy(str, infoPtr->strings[iString], ret);
5034 TRACE("returning %s\n", debugstr_w(str));
5037 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5042 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5043 * is the maximum size of the toolbar? */
5044 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5046 SIZE * pSize = (SIZE*)lParam;
5047 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5052 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5053 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5054 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5057 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5059 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5060 INT nOldHotItem = infoPtr->nHotItem;
5062 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5063 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5065 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5068 /* NOTE: an application can still remove the hot item even if anchor
5069 * highlighting is enabled */
5071 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5075 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5078 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5079 * which controls the amount of spacing between the image and the text
5080 * of buttons for TBSTYLE_LIST toolbars. */
5081 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5085 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5088 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5090 infoPtr->iListGap = (INT)wParam;
5092 InvalidateRect(hwnd, NULL, TRUE);
5097 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5098 * of image lists associated with the various states. */
5099 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5103 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5105 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5109 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5112 LPSIZE lpsize = (LPSIZE)lParam;
5118 * Testing shows the following:
5119 * wParam = 0 adjust cx value
5120 * = 1 set cy value to max size.
5121 * lParam pointer to SIZE structure
5124 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5125 wParam, lParam, lpsize->cx, lpsize->cy);
5129 if (lpsize->cx == -1) {
5130 /* **** this is wrong, native measures each button and sets it */
5131 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5133 else if(HIWORD(lpsize->cx)) {
5135 HWND hwndParent = GetParent(hwnd);
5137 GetWindowRect(hwnd, &rc);
5138 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5139 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5140 rc.left, rc.top, rc.right, rc.bottom);
5141 lpsize->cx = max(rc.right-rc.left,
5142 infoPtr->rcBound.right - infoPtr->rcBound.left);
5145 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5149 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5150 /* lpsize->cy = infoPtr->nHeight; */
5153 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5157 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5158 lpsize->cx, lpsize->cy);
5162 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5164 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5166 InvalidateRect(hwnd, NULL, TRUE);
5172 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5175 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5178 TRACE("hwnd = %p\n", hwnd);
5180 /* initialize info structure */
5181 infoPtr->nButtonHeight = 22;
5182 infoPtr->nButtonWidth = 24;
5183 infoPtr->nBitmapHeight = 15;
5184 infoPtr->nBitmapWidth = 16;
5186 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5187 infoPtr->nMaxTextRows = 1;
5188 infoPtr->cxMin = -1;
5189 infoPtr->cxMax = -1;
5190 infoPtr->nNumBitmaps = 0;
5191 infoPtr->nNumStrings = 0;
5193 infoPtr->bCaptured = FALSE;
5194 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5195 infoPtr->nButtonDown = -1;
5196 infoPtr->nButtonDrag = -1;
5197 infoPtr->nOldHit = -1;
5198 infoPtr->nHotItem = -1;
5199 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5200 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5201 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5202 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5203 infoPtr->bDragOutSent = FALSE;
5204 infoPtr->iVersion = 0;
5205 infoPtr->hwndSelf = hwnd;
5206 infoPtr->bDoRedraw = TRUE;
5207 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5208 infoPtr->clrBtnShadow = CLR_DEFAULT;
5209 /* not sure where the +1 comes from, but this comes to the same value
5210 * as native so this is probably correct */
5211 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5212 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5213 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5214 infoPtr->dwStyle = dwStyle;
5215 infoPtr->tbim.iButton = -1;
5216 GetClientRect(hwnd, &infoPtr->client_rect);
5217 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5219 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5220 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5222 if (dwStyle & TBSTYLE_TOOLTIPS) {
5223 /* Create tooltip control */
5224 infoPtr->hwndToolTip =
5225 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5226 CW_USEDEFAULT, CW_USEDEFAULT,
5227 CW_USEDEFAULT, CW_USEDEFAULT,
5230 /* Send NM_TOOLTIPSCREATED notification */
5231 if (infoPtr->hwndToolTip) {
5232 NMTOOLTIPSCREATED nmttc;
5234 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5236 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5237 NM_TOOLTIPSCREATED);
5241 TOOLBAR_CheckStyle (hwnd, dwStyle);
5243 TOOLBAR_CalcToolbar(hwnd);
5250 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5254 /* delete tooltip control */
5255 if (infoPtr->hwndToolTip)
5256 DestroyWindow (infoPtr->hwndToolTip);
5258 /* delete temporary buffer for tooltip text */
5259 if (infoPtr->pszTooltipText)
5260 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5262 /* delete button data */
5263 if (infoPtr->buttons)
5264 Free (infoPtr->buttons);
5266 /* delete strings */
5267 if (infoPtr->strings) {
5269 for (i = 0; i < infoPtr->nNumStrings; i++)
5270 if (infoPtr->strings[i])
5271 Free (infoPtr->strings[i]);
5273 Free (infoPtr->strings);
5276 /* destroy internal image list */
5277 if (infoPtr->himlInt)
5278 ImageList_Destroy (infoPtr->himlInt);
5280 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5281 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5282 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5284 /* delete default font */
5286 DeleteObject (infoPtr->hDefaultFont);
5288 /* free toolbar info data */
5290 SetWindowLongPtrW (hwnd, 0, 0);
5297 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5300 NMTBCUSTOMDRAW tbcd;
5304 /* the app has told us not to redraw the toolbar */
5305 if (!infoPtr->bDoRedraw)
5308 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5309 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5310 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5311 tbcd.nmcd.hdc = (HDC)wParam;
5312 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5313 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5315 /* FIXME: in general the return flags *can* be or'ed together */
5316 switch (infoPtr->dwBaseCustDraw)
5318 case CDRF_DODEFAULT:
5320 case CDRF_SKIPDEFAULT:
5323 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5328 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5329 * to my parent for processing.
5331 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5333 HDC hdc = (HDC)wParam;
5338 parent = GetParent(hwnd);
5339 MapWindowPoints(hwnd, parent, &pt, 1);
5340 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5341 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5342 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5345 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5347 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5348 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5349 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5350 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5351 tbcd.nmcd.hdc = (HDC)wParam;
5352 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5353 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5354 switch (infoPtr->dwBaseCustDraw)
5356 case CDRF_DODEFAULT:
5358 case CDRF_SKIPDEFAULT:
5361 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5370 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5374 return (LRESULT)infoPtr->hFont;
5379 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5384 pt.x = (INT)LOWORD(lParam);
5385 pt.y = (INT)HIWORD(lParam);
5386 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5389 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5390 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5391 TOOLBAR_Customize (hwnd);
5398 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5401 TBUTTON_INFO *btnPtr;
5406 BOOL bDragKeyPressed;
5410 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5411 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5413 bDragKeyPressed = (wParam & MK_SHIFT);
5415 if (infoPtr->hwndToolTip)
5416 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5417 WM_LBUTTONDOWN, wParam, lParam);
5419 pt.x = (INT)LOWORD(lParam);
5420 pt.y = (INT)HIWORD(lParam);
5421 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5423 btnPtr = &infoPtr->buttons[nHit];
5425 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5427 infoPtr->nButtonDrag = nHit;
5430 /* If drag cursor has not been loaded, load it.
5431 * Note: it doesn't need to be freed */
5433 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5434 SetCursor(hCursorDrag);
5439 infoPtr->nOldHit = nHit;
5441 CopyRect(&arrowRect, &btnPtr->rect);
5442 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5444 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5445 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5446 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5447 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5448 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5449 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5453 /* draw in pressed state */
5454 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5455 btnPtr->fsState |= TBSTATE_PRESSED;
5457 btnPtr->bDropDownPressed = TRUE;
5458 RedrawWindow(hwnd,&btnPtr->rect,0,
5459 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5461 nmtb.iItem = btnPtr->idCommand;
5462 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5465 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5466 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5468 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5470 if (res != TBDDRET_TREATPRESSED)
5474 /* redraw button in unpressed state */
5475 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5476 btnPtr->fsState &= ~TBSTATE_PRESSED;
5478 btnPtr->bDropDownPressed = FALSE;
5479 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5481 /* find and set hot item
5482 * NOTE: native doesn't do this, but that is a bug */
5484 ScreenToClient(hwnd, &pt);
5485 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5486 if (!infoPtr->bAnchor || (nHit >= 0))
5487 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5489 /* remove any left mouse button down or double-click messages
5490 * so that we can get a toggle effect on the button */
5491 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5492 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5497 /* otherwise drop through and process as pushed */
5499 infoPtr->bCaptured = TRUE;
5500 infoPtr->nButtonDown = nHit;
5501 infoPtr->bDragOutSent = FALSE;
5503 btnPtr->fsState |= TBSTATE_PRESSED;
5505 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5507 if (btnPtr->fsState & TBSTATE_ENABLED)
5508 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5515 nmtb.iItem = btnPtr->idCommand;
5516 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5517 nmtb.tbButton.idCommand = btnPtr->idCommand;
5518 nmtb.tbButton.fsState = btnPtr->fsState;
5519 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5520 nmtb.tbButton.dwData = btnPtr->dwData;
5521 nmtb.tbButton.iString = btnPtr->iString;
5522 nmtb.cchText = 0; /* !!! not correct */
5523 nmtb.pszText = 0; /* !!! not correct */
5524 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5527 nmmouse.dwHitInfo = nHit;
5529 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5530 if (nmmouse.dwHitInfo < 0)
5531 nmmouse.dwItemSpec = -1;
5534 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5535 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5538 ClientToScreen(hwnd, &pt);
5541 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_LDOWN))
5542 return DefWindowProcW(hwnd, WM_LBUTTONDOWN, wParam, lParam);
5548 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5551 TBUTTON_INFO *btnPtr;
5555 BOOL bSendMessage = TRUE;
5560 if (infoPtr->hwndToolTip)
5561 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5562 WM_LBUTTONUP, wParam, lParam);
5564 pt.x = (INT)LOWORD(lParam);
5565 pt.y = (INT)HIWORD(lParam);
5566 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5568 if (!infoPtr->bAnchor || (nHit >= 0))
5569 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5571 if (infoPtr->nButtonDrag >= 0) {
5575 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5578 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5580 GetClientRect(hwnd, &rcClient);
5581 if (PtInRect(&rcClient, pt))
5588 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5591 if (nButton == infoPtr->nButtonDrag)
5593 /* if the button is moved sightly left and we have a
5594 * separator there then remove it */
5595 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5597 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5598 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5600 else /* else insert a separator before the dragged button */
5603 memset(&tbb, 0, sizeof(tbb));
5604 tbb.fsStyle = BTNS_SEP;
5606 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5613 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5614 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5616 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5619 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5624 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5625 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5628 /* button under cursor changed so need to re-set hot item */
5629 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5630 infoPtr->nButtonDrag = -1;
5632 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5634 else if (infoPtr->nButtonDown >= 0) {
5635 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5636 btnPtr->fsState &= ~TBSTATE_PRESSED;
5638 if (btnPtr->fsStyle & BTNS_CHECK) {
5639 if (btnPtr->fsStyle & BTNS_GROUP) {
5640 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5642 if (nOldIndex == nHit)
5643 bSendMessage = FALSE;
5644 if ((nOldIndex != nHit) &&
5646 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5647 btnPtr->fsState |= TBSTATE_CHECKED;
5650 if (btnPtr->fsState & TBSTATE_CHECKED)
5651 btnPtr->fsState &= ~TBSTATE_CHECKED;
5653 btnPtr->fsState |= TBSTATE_CHECKED;
5657 if (nOldIndex != -1)
5658 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5661 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5662 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5663 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5665 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5667 infoPtr->nButtonDown = -1;
5669 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5670 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5671 NM_RELEASEDCAPTURE);
5673 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5676 nmtb.iItem = btnPtr->idCommand;
5677 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5678 nmtb.tbButton.idCommand = btnPtr->idCommand;
5679 nmtb.tbButton.fsState = btnPtr->fsState;
5680 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5681 nmtb.tbButton.dwData = btnPtr->dwData;
5682 nmtb.tbButton.iString = btnPtr->iString;
5683 nmtb.cchText = 0; /* !!! not correct */
5684 nmtb.pszText = 0; /* !!! not correct */
5685 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5688 if (btnPtr->fsState & TBSTATE_ENABLED)
5690 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5691 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5695 /* !!! Undocumented - toolbar at 4.71 level and above sends
5696 * NM_CLICK with the NMMOUSE structure. */
5697 nmmouse.dwHitInfo = nHit;
5699 if (nmmouse.dwHitInfo < 0)
5700 nmmouse.dwItemSpec = -1;
5703 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5704 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5707 ClientToScreen(hwnd, &pt);
5710 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5711 return DefWindowProcW(hwnd, WM_LBUTTONUP, wParam, lParam);
5717 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5719 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5724 pt.x = LOWORD(lParam);
5725 pt.y = HIWORD(lParam);
5727 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5729 if (nmmouse.dwHitInfo < 0) {
5730 nmmouse.dwItemSpec = -1;
5732 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5733 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5736 ClientToScreen(hwnd, &pt);
5739 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5740 return DefWindowProcW(hwnd, WM_RBUTTONUP, wParam, lParam);
5746 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5748 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5751 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5752 return DefWindowProcW(hwnd, WM_RBUTTONDBLCLK, wParam, lParam);
5758 TOOLBAR_CaptureChanged(HWND hwnd)
5760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5761 TBUTTON_INFO *btnPtr;
5763 infoPtr->bCaptured = FALSE;
5765 if (infoPtr->nButtonDown >= 0)
5767 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5768 btnPtr->fsState &= ~TBSTATE_PRESSED;
5770 infoPtr->nOldHit = -1;
5772 if (btnPtr->fsState & TBSTATE_ENABLED)
5773 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5779 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5781 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5782 TBUTTON_INFO *hotBtnPtr;
5784 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5786 /* don't remove hot effects when in anchor highlighting mode or when a
5787 * drop-down button is pressed */
5788 if (!infoPtr->bAnchor && (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed))
5789 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5791 if (infoPtr->nOldHit < 0)
5794 /* If the last button we were over is depressed then make it not */
5795 /* depressed and redraw it */
5796 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5798 TBUTTON_INFO *btnPtr;
5801 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5803 btnPtr->fsState &= ~TBSTATE_PRESSED;
5805 rc1 = hotBtnPtr->rect;
5806 InflateRect (&rc1, 1, 1);
5807 InvalidateRect (hwnd, &rc1, TRUE);
5810 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5813 ZeroMemory(&nmt, sizeof(nmt));
5814 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5815 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5816 infoPtr->bDragOutSent = TRUE;
5819 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5825 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5829 TRACKMOUSEEVENT trackinfo;
5831 TBUTTON_INFO *btnPtr;
5833 /* fill in the TRACKMOUSEEVENT struct */
5834 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5835 trackinfo.dwFlags = TME_QUERY;
5836 trackinfo.hwndTrack = hwnd;
5837 trackinfo.dwHoverTime = HOVER_DEFAULT;
5839 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5840 _TrackMouseEvent(&trackinfo);
5842 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5843 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5844 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5846 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5847 /* and can properly deactivate the hot toolbar button */
5848 _TrackMouseEvent(&trackinfo);
5851 if (infoPtr->hwndToolTip)
5852 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5853 WM_MOUSEMOVE, wParam, lParam);
5855 pt.x = (INT)LOWORD(lParam);
5856 pt.y = (INT)HIWORD(lParam);
5858 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5860 if (!infoPtr->bAnchor || (nHit >= 0))
5861 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5863 if (infoPtr->nOldHit != nHit)
5865 if (infoPtr->bCaptured)
5867 if (!infoPtr->bDragOutSent)
5870 ZeroMemory(&nmt, sizeof(nmt));
5871 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5872 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5873 infoPtr->bDragOutSent = TRUE;
5876 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5877 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5878 btnPtr->fsState &= ~TBSTATE_PRESSED;
5879 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5881 else if (nHit == infoPtr->nButtonDown) {
5882 btnPtr->fsState |= TBSTATE_PRESSED;
5883 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5885 infoPtr->nOldHit = nHit;
5893 inline static LRESULT
5894 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5896 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5897 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5899 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5903 inline static LRESULT
5904 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5906 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5907 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5909 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5914 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5916 TOOLBAR_INFO *infoPtr;
5917 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5920 /* allocate memory for info structure */
5921 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5922 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5925 infoPtr->dwStructSize = sizeof(TBBUTTON);
5928 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5929 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5930 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5931 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5934 /* native control does:
5935 * Get a lot of colors and brushes
5937 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5938 * CreateFontIndirectA(adr1)
5939 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5940 * hdc = GetDC(toolbar)
5941 * GetSystemMetrics(0x48)
5942 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5943 * 0, 0, 0, 0, "MARLETT")
5944 * oldfnt = SelectObject(hdc, fnt2)
5945 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5946 * GetTextMetricsA(hdc, adr3)
5947 * SelectObject(hdc, oldfnt)
5948 * DeleteObject(fnt2)
5950 * InvalidateRect(toolbar, 0, 1)
5951 * SetWindowLongA(toolbar, 0, addr)
5952 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5955 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5956 * ie 2 0x4600094c 0x4600094c 0x4600894d
5957 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5958 * rebar 0x50008844 0x40008844 0x50008845
5959 * pager 0x50000844 0x40000844 0x50008845
5960 * IC35mgr 0x5400084e **nochange**
5961 * on entry to _NCCREATE 0x5400084e
5962 * rowlist 0x5400004e **nochange**
5963 * on entry to _NCCREATE 0x5400004e
5967 /* I think the code below is a bug, but it is the way that the native
5968 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5969 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5970 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5971 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5972 * Some how, the only cases of this seem to be MFC programs.
5974 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5975 * does not occur in the WM_STYLECHANGING routine.
5976 * (Guy Albertelli 9/2001)
5979 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5980 styleadd |= TBSTYLE_TRANSPARENT;
5981 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5982 styleadd |= CCS_TOP; /* default to top */
5983 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5986 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5991 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5993 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5997 if (dwStyle & WS_MINIMIZE)
5998 return 0; /* Nothing to do */
6000 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
6002 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
6005 if (!(dwStyle & CCS_NODIVIDER))
6007 GetWindowRect (hwnd, &rcWindow);
6008 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
6009 if( dwStyle & WS_BORDER )
6010 OffsetRect (&rcWindow, 1, 1);
6011 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
6014 ReleaseDC( hwnd, hdc );
6020 /* handles requests from the tooltip control on what text to display */
6021 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
6023 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
6025 TRACE("button index = %d\n", index);
6027 if (infoPtr->pszTooltipText)
6029 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
6030 infoPtr->pszTooltipText = NULL;
6036 if (infoPtr->bNtfUnicode)
6038 WCHAR wszBuffer[INFOTIPSIZE+1];
6039 NMTBGETINFOTIPW tbgit;
6040 unsigned int len; /* in chars */
6042 wszBuffer[0] = '\0';
6043 wszBuffer[INFOTIPSIZE] = '\0';
6045 tbgit.pszText = wszBuffer;
6046 tbgit.cchTextMax = INFOTIPSIZE;
6047 tbgit.iItem = lpnmtdi->hdr.idFrom;
6048 tbgit.lParam = infoPtr->buttons[index].dwData;
6050 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6052 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6054 len = strlenW(tbgit.pszText);
6055 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6057 /* need to allocate temporary buffer in infoPtr as there
6058 * isn't enough space in buffer passed to us by the
6059 * tooltip control */
6060 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6061 if (infoPtr->pszTooltipText)
6063 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6064 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6070 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6076 CHAR szBuffer[INFOTIPSIZE+1];
6077 NMTBGETINFOTIPA tbgit;
6078 unsigned int len; /* in chars */
6081 szBuffer[INFOTIPSIZE] = '\0';
6083 tbgit.pszText = szBuffer;
6084 tbgit.cchTextMax = INFOTIPSIZE;
6085 tbgit.iItem = lpnmtdi->hdr.idFrom;
6086 tbgit.lParam = infoPtr->buttons[index].dwData;
6088 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6090 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6092 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6093 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6095 /* need to allocate temporary buffer in infoPtr as there
6096 * isn't enough space in buffer passed to us by the
6097 * tooltip control */
6098 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6099 if (infoPtr->pszTooltipText)
6101 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6102 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6108 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6113 /* if button has text, but it is not shown then automatically
6114 * use that text as tooltip */
6115 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6116 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6118 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6119 unsigned int len = pszText ? strlenW(pszText) : 0;
6121 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6123 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6125 /* need to allocate temporary buffer in infoPtr as there
6126 * isn't enough space in buffer passed to us by the
6127 * tooltip control */
6128 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6129 if (infoPtr->pszTooltipText)
6131 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6132 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6138 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6143 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6145 /* last resort: send notification on to app */
6146 /* FIXME: find out what is really used here */
6147 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6151 inline static LRESULT
6152 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6154 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6155 LPNMHDR lpnmh = (LPNMHDR)lParam;
6157 switch (lpnmh->code)
6161 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6163 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6164 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6165 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6169 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6170 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6178 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6180 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6181 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6182 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6183 lppgs->iScroll, lppgs->iDir);
6187 case TTN_GETDISPINFOW:
6188 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6190 case TTN_GETDISPINFOA:
6191 FIXME("TTN_GETDISPINFOA - stub\n");
6201 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6203 /* remove this routine when Toolbar is improved to pass infoPtr
6204 * around instead of hwnd.
6206 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6207 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6212 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6216 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6218 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6221 if (lParam == NF_REQUERY) {
6222 i = SendMessageA(infoPtr->hwndNotify,
6223 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6224 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6225 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6229 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6232 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6237 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6243 /* fill ps.rcPaint with a default rect */
6244 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6246 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6248 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6249 ps.rcPaint.left, ps.rcPaint.top,
6250 ps.rcPaint.right, ps.rcPaint.bottom);
6252 TOOLBAR_Refresh (hwnd, hdc, &ps);
6253 if (!wParam) EndPaint (hwnd, &ps);
6260 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6261 /*****************************************************
6264 * Handles the WM_SETREDRAW message.
6267 * According to testing V4.71 of COMCTL32 returns the
6268 * *previous* status of the redraw flag (either 0 or 1)
6269 * instead of the MSDN documented value of 0 if handled.
6270 * (For laughs see the "consistency" with same function
6273 *****************************************************/
6275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6276 BOOL oldredraw = infoPtr->bDoRedraw;
6278 TRACE("set to %s\n",
6279 (wParam) ? "TRUE" : "FALSE");
6280 infoPtr->bDoRedraw = (BOOL) wParam;
6282 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6284 return (oldredraw) ? 1 : 0;
6289 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6292 DWORD dwStyle = infoPtr->dwStyle;
6301 /* Resize deadlock check */
6302 if (infoPtr->bAutoSize) {
6303 infoPtr->bAutoSize = FALSE;
6307 /* FIXME: optimize to only update size if the new size doesn't */
6308 /* match the current size */
6310 flags = (INT) wParam;
6312 /* FIXME for flags =
6313 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6316 TRACE("sizing toolbar!\n");
6318 if (flags == SIZE_RESTORED) {
6319 /* width and height don't apply */
6320 parent = GetParent (hwnd);
6321 GetClientRect(parent, &parent_rect);
6322 x = parent_rect.left;
6323 y = parent_rect.top;
6325 if (dwStyle & CCS_NORESIZE) {
6326 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6329 * this sets the working width of the toolbar, and
6330 * Calc Toolbar will not adjust it, only the height
6332 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6333 cy = infoPtr->nHeight;
6334 cx = infoPtr->nWidth;
6335 TOOLBAR_CalcToolbar (hwnd);
6336 infoPtr->nWidth = cx;
6337 infoPtr->nHeight = cy;
6340 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6341 TOOLBAR_CalcToolbar (hwnd);
6342 cy = infoPtr->nHeight;
6343 cx = infoPtr->nWidth;
6345 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6346 GetWindowRect(hwnd, &window_rect);
6347 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6348 y = window_rect.top;
6350 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6351 GetWindowRect(hwnd, &window_rect);
6352 y = parent_rect.bottom -
6353 ( window_rect.bottom - window_rect.top);
6357 if (dwStyle & CCS_NOPARENTALIGN) {
6358 uPosFlags |= SWP_NOMOVE;
6359 cy = infoPtr->nHeight;
6360 cx = infoPtr->nWidth;
6363 if (!(dwStyle & CCS_NODIVIDER))
6364 cy += GetSystemMetrics(SM_CYEDGE);
6366 if (dwStyle & WS_BORDER)
6369 cy += GetSystemMetrics(SM_CYEDGE);
6370 cx += GetSystemMetrics(SM_CYEDGE);
6373 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6375 RECT delta_width, delta_height, client, dummy;
6376 DWORD min_x, max_x, min_y, max_y;
6377 TBUTTON_INFO *btnPtr;
6380 GetClientRect(hwnd, &client);
6381 if(client.right > infoPtr->client_rect.right)
6383 min_x = infoPtr->client_rect.right;
6384 max_x = client.right;
6388 max_x = infoPtr->client_rect.right;
6389 min_x = client.right;
6391 if(client.bottom > infoPtr->client_rect.bottom)
6393 min_y = infoPtr->client_rect.bottom;
6394 max_y = client.bottom;
6398 max_y = infoPtr->client_rect.bottom;
6399 min_y = client.bottom;
6402 SetRect(&delta_width, min_x, 0, max_x, min_y);
6403 SetRect(&delta_height, 0, min_y, max_x, max_y);
6405 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6406 btnPtr = infoPtr->buttons;
6407 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6408 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6409 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6410 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6413 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6414 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6416 GetClientRect(hwnd, &infoPtr->client_rect);
6422 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6424 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6426 if (nType == GWL_STYLE) {
6427 if (lpStyle->styleNew & TBSTYLE_LIST) {
6428 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6431 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6433 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6434 (TBSTYLE_FLAT | TBSTYLE_LIST));
6435 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6437 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6439 infoPtr->dwStyle = lpStyle->styleNew;
6442 TOOLBAR_CalcToolbar(hwnd);
6444 TOOLBAR_AutoSize (hwnd);
6446 InvalidateRect(hwnd, NULL, TRUE);
6453 TOOLBAR_SysColorChange (HWND hwnd)
6455 COMCTL32_RefreshSysColors();
6462 static LRESULT WINAPI
6463 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6467 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6468 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6470 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6471 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6476 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6478 case TB_ADDBUTTONSA:
6479 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6481 case TB_ADDBUTTONSW:
6482 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6485 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6488 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6491 return TOOLBAR_AutoSize (hwnd);
6493 case TB_BUTTONCOUNT:
6494 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6496 case TB_BUTTONSTRUCTSIZE:
6497 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6499 case TB_CHANGEBITMAP:
6500 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6502 case TB_CHECKBUTTON:
6503 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6505 case TB_COMMANDTOINDEX:
6506 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6509 return TOOLBAR_Customize (hwnd);
6511 case TB_DELETEBUTTON:
6512 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6514 case TB_ENABLEBUTTON:
6515 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6517 case TB_GETANCHORHIGHLIGHT:
6518 return TOOLBAR_GetAnchorHighlight (hwnd);
6521 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6523 case TB_GETBITMAPFLAGS:
6524 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6527 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6529 case TB_GETBUTTONINFOA:
6530 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6532 case TB_GETBUTTONINFOW:
6533 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6535 case TB_GETBUTTONSIZE:
6536 return TOOLBAR_GetButtonSize (hwnd);
6538 case TB_GETBUTTONTEXTA:
6539 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6541 case TB_GETBUTTONTEXTW:
6542 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6544 case TB_GETDISABLEDIMAGELIST:
6545 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6547 case TB_GETEXTENDEDSTYLE:
6548 return TOOLBAR_GetExtendedStyle (hwnd);
6550 case TB_GETHOTIMAGELIST:
6551 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6554 return TOOLBAR_GetHotItem (hwnd);
6556 case TB_GETIMAGELIST:
6557 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6559 case TB_GETINSERTMARK:
6560 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6562 case TB_GETINSERTMARKCOLOR:
6563 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6565 case TB_GETITEMRECT:
6566 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6569 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6571 /* case TB_GETOBJECT: */ /* 4.71 */
6574 return TOOLBAR_GetPadding (hwnd);
6577 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6580 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6583 return TOOLBAR_GetState (hwnd, wParam, lParam);
6586 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6589 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6592 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6594 case TB_GETTEXTROWS:
6595 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6597 case TB_GETTOOLTIPS:
6598 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6600 case TB_GETUNICODEFORMAT:
6601 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6604 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6607 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6609 case TB_INDETERMINATE:
6610 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6612 case TB_INSERTBUTTONA:
6613 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6615 case TB_INSERTBUTTONW:
6616 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6618 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6620 case TB_ISBUTTONCHECKED:
6621 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6623 case TB_ISBUTTONENABLED:
6624 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6626 case TB_ISBUTTONHIDDEN:
6627 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6629 case TB_ISBUTTONHIGHLIGHTED:
6630 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6632 case TB_ISBUTTONINDETERMINATE:
6633 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6635 case TB_ISBUTTONPRESSED:
6636 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6639 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6641 case TB_MAPACCELERATORA:
6642 case TB_MAPACCELERATORW:
6643 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6646 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6649 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6651 case TB_PRESSBUTTON:
6652 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6654 case TB_REPLACEBITMAP:
6655 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6657 case TB_SAVERESTOREA:
6658 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6660 case TB_SAVERESTOREW:
6661 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6663 case TB_SETANCHORHIGHLIGHT:
6664 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6666 case TB_SETBITMAPSIZE:
6667 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6669 case TB_SETBUTTONINFOA:
6670 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6672 case TB_SETBUTTONINFOW:
6673 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6675 case TB_SETBUTTONSIZE:
6676 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6678 case TB_SETBUTTONWIDTH:
6679 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6682 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6684 case TB_SETDISABLEDIMAGELIST:
6685 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6687 case TB_SETDRAWTEXTFLAGS:
6688 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6690 case TB_SETEXTENDEDSTYLE:
6691 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6693 case TB_SETHOTIMAGELIST:
6694 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6697 return TOOLBAR_SetHotItem (hwnd, wParam);
6699 case TB_SETIMAGELIST:
6700 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6703 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6705 case TB_SETINSERTMARK:
6706 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6708 case TB_SETINSERTMARKCOLOR:
6709 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6711 case TB_SETMAXTEXTROWS:
6712 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6715 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6718 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6721 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6724 return TOOLBAR_SetState (hwnd, wParam, lParam);
6727 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6729 case TB_SETTOOLTIPS:
6730 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6732 case TB_SETUNICODEFORMAT:
6733 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6736 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6739 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6742 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6745 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6748 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6751 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6753 /* Common Control Messages */
6755 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6756 case CCM_GETCOLORSCHEME:
6757 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6759 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6760 case CCM_SETCOLORSCHEME:
6761 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6763 case CCM_GETVERSION:
6764 return TOOLBAR_GetVersion (hwnd);
6766 case CCM_SETVERSION:
6767 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6773 return TOOLBAR_Create (hwnd, wParam, lParam);
6776 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6779 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6782 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6784 /* case WM_KEYDOWN: */
6785 /* case WM_KILLFOCUS: */
6787 case WM_LBUTTONDBLCLK:
6788 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6790 case WM_LBUTTONDOWN:
6791 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6794 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6797 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6799 case WM_RBUTTONDBLCLK:
6800 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6803 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6806 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6808 case WM_CAPTURECHANGED:
6809 return TOOLBAR_CaptureChanged(hwnd);
6812 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6815 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6818 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6821 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6824 return TOOLBAR_Notify (hwnd, wParam, lParam);
6826 case WM_NOTIFYFORMAT:
6827 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6830 return TOOLBAR_Paint (hwnd, wParam);
6833 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6836 return TOOLBAR_Size (hwnd, wParam, lParam);
6838 case WM_STYLECHANGED:
6839 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6841 case WM_SYSCOLORCHANGE:
6842 return TOOLBAR_SysColorChange (hwnd);
6844 /* case WM_WININICHANGE: */
6849 case WM_MEASUREITEM:
6851 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6853 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6854 case PGM_FORWARDMOUSE:
6855 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6858 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6859 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6860 uMsg, wParam, lParam);
6861 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6868 TOOLBAR_Register (void)
6872 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6873 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6874 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6875 wndClass.cbClsExtra = 0;
6876 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6877 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6878 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6879 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6881 RegisterClassA (&wndClass);
6886 TOOLBAR_Unregister (void)
6888 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6891 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6896 /* Check if the entry already exists */
6897 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6899 /* If this is a new entry we must create it and insert into the array */
6904 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6907 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6908 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6923 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6927 for (i = 0; i < *cies; i++)
6937 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6945 for (i = 0; i < cies; i++)
6947 if (pies[i]->id == id)
6959 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6961 HIMAGELIST himlDef = 0;
6962 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6965 himlDef = pie->himl;
6971 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6973 if (infoPtr->bUnicode)
6974 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6981 nmtba.iItem = nmtb->iItem;
6982 nmtba.pszText = Buffer;
6983 nmtba.cchText = 256;
6984 ZeroMemory(nmtba.pszText, nmtba.cchText);
6986 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6988 int ccht = strlen(nmtba.pszText);
6990 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6991 nmtb->pszText, nmtb->cchText);
6993 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
7002 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
7003 int iItem, PCUSTOMBUTTON btnInfo)
7008 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
7010 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);