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 (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
896 if (dwStyle & TBSTYLE_LIST)
897 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
899 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
902 if (dwStyle & TBSTYLE_LIST)
903 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
905 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
906 OffsetRect (&rcText, 1, 1);
909 /* Initialize fields in all cases, because we use these later
910 * NOTE: applications can and do alter these to customize their
912 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
913 tbcd.clrText = comctl32_color.clrBtnText;
914 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
915 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
916 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
917 tbcd.clrMark = comctl32_color.clrHighlight;
918 tbcd.clrHighlightHotTrack = 0;
919 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
920 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
921 /* MSDN says that this is the text rectangle.
922 * But (why always a but) tracing of v5.7 of native shows
923 * that this is really a *relative* rectangle based on the
924 * the nmcd.rc. Also the left and top are always 0 ignoring
925 * any bitmap that might be present. */
926 tbcd.rcText.left = 0;
928 tbcd.rcText.right = rcText.right - rc.left;
929 tbcd.rcText.bottom = rcText.bottom - rc.top;
930 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
933 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
935 /* FIXME: what are these used for? */
939 /* Issue Item Prepaint notify */
940 infoPtr->dwItemCustDraw = 0;
941 infoPtr->dwItemCDFlag = 0;
942 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
944 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
945 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
946 tbcd.nmcd.lItemlParam = btnPtr->dwData;
947 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
948 /* reset these fields so the user can't alter the behaviour like native */
952 infoPtr->dwItemCustDraw = ntfret & 0xffff;
953 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
954 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
956 /* save the only part of the rect that the user can change */
957 rcText.right = tbcd.rcText.right + rc.left;
958 rcText.bottom = tbcd.rcText.bottom + rc.top;
962 if (btnPtr->fsStyle & BTNS_SEP) {
963 /* with the FLAT style, iBitmap is the width and has already */
964 /* been taken into consideration in calculating the width */
965 /* so now we need to draw the vertical separator */
966 /* empirical tests show that iBitmap can/will be non-zero */
967 /* when drawing the vertical bar... */
968 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
969 if (btnPtr->fsStyle & BTNS_DROPDOWN)
970 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
972 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
974 else if (btnPtr->fsStyle != BTNS_SEP) {
975 FIXME("Draw some kind of separator: fsStyle=%x\n",
981 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
982 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
983 TOOLBAR_DrawPattern (&rc, &tbcd);
985 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
987 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
991 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
992 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
993 if (hasDropDownArrow)
994 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
995 SetBkColor(hdc, oldclr);
999 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1001 if (drawSepDropDownArrow)
1002 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1004 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1005 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1007 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1009 if (hasDropDownArrow && !drawSepDropDownArrow)
1011 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1013 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1014 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1016 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1018 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1019 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1022 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1026 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1028 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1029 tbcd.nmcd.hdc = hdc;
1031 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1032 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1033 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1034 tbcd.rcText = rcText;
1035 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1036 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1037 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1044 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1047 TBUTTON_INFO *btnPtr;
1048 INT i, oldBKmode = 0;
1049 RECT rcTemp, rcClient;
1050 NMTBCUSTOMDRAW tbcd;
1053 /* the app has told us not to redraw the toolbar */
1054 if (!infoPtr->bDoRedraw)
1057 /* if imagelist belongs to the app, it can be changed
1058 by the app after setting it */
1059 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1061 infoPtr->nNumBitmaps = 0;
1062 for (i = 0; i < infoPtr->cimlDef; i++)
1063 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1066 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1068 /* Send initial notify */
1069 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1070 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1071 tbcd.nmcd.hdc = hdc;
1072 tbcd.nmcd.rc = ps->rcPaint;
1073 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1074 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1076 if (infoPtr->bBtnTranspnt)
1077 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1079 GetClientRect(hwnd, &rcClient);
1081 /* redraw necessary buttons */
1082 btnPtr = infoPtr->buttons;
1083 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1086 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1088 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1089 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1093 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1094 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1096 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1099 /* draw insert mark if required */
1100 if (infoPtr->tbim.iButton != -1)
1102 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1104 rcInsertMark.top = rcButton.top;
1105 rcInsertMark.bottom = rcButton.bottom;
1106 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1107 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1109 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1110 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1113 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1114 SetBkMode (hdc, oldBKmode);
1116 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1118 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1119 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1120 tbcd.nmcd.hdc = hdc;
1121 tbcd.nmcd.rc = ps->rcPaint;
1122 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1126 /***********************************************************************
1127 * TOOLBAR_MeasureString
1129 * This function gets the width and height of a string in pixels. This
1130 * is done first by using GetTextExtentPoint to get the basic width
1131 * and height. The DrawText is called with DT_CALCRECT to get the exact
1132 * width. The reason is because the text may have more than one "&" (or
1133 * prefix characters as M$ likes to call them). The prefix character
1134 * indicates where the underline goes, except for the string "&&" which
1135 * is reduced to a single "&". GetTextExtentPoint does not process these
1136 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1139 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1140 HDC hdc, LPSIZE lpSize)
1147 if (infoPtr->nMaxTextRows > 0 &&
1148 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1149 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1150 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1152 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1154 if(lpText != NULL) {
1155 /* first get size of all the text */
1156 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1158 /* feed above size into the rectangle for DrawText */
1159 myrect.left = myrect.top = 0;
1160 myrect.right = lpSize->cx;
1161 myrect.bottom = lpSize->cy;
1163 /* Use DrawText to get true size as drawn (less pesky "&") */
1164 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1165 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1168 /* feed back to caller */
1169 lpSize->cx = myrect.right;
1170 lpSize->cy = myrect.bottom;
1174 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1177 /***********************************************************************
1178 * TOOLBAR_CalcStrings
1180 * This function walks through each string and measures it and returns
1181 * the largest height and width to caller.
1184 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1186 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1187 TBUTTON_INFO *btnPtr;
1196 if(infoPtr->nMaxTextRows == 0)
1200 hOldFont = SelectObject (hdc, infoPtr->hFont);
1202 btnPtr = infoPtr->buttons;
1203 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1204 if(TOOLBAR_HasText(infoPtr, btnPtr))
1206 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1207 if (sz.cx > lpSize->cx)
1209 if (sz.cy > lpSize->cy)
1214 SelectObject (hdc, hOldFont);
1215 ReleaseDC (hwnd, hdc);
1217 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1220 /***********************************************************************
1221 * TOOLBAR_WrapToolbar
1223 * This function walks through the buttons and separators in the
1224 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1225 * wrapping should occur based on the width of the toolbar window.
1226 * It does *not* calculate button placement itself. That task
1227 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1228 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1229 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1231 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1232 * vertical toolbar lists.
1236 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1238 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1239 TBUTTON_INFO *btnPtr;
1242 BOOL bWrap, bButtonWrap;
1244 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1245 /* no layout is necessary. Applications may use this style */
1246 /* to perform their own layout on the toolbar. */
1247 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1248 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1250 btnPtr = infoPtr->buttons;
1251 x = infoPtr->nIndent;
1253 /* this can get the parents width, to know how far we can extend
1254 * this toolbar. We cannot use its height, as there may be multiple
1255 * toolbars in a rebar control
1257 GetClientRect( GetParent(hwnd), &rc );
1258 infoPtr->nWidth = rc.right - rc.left;
1259 bButtonWrap = FALSE;
1261 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1262 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1265 for (i = 0; i < infoPtr->nNumButtons; i++ )
1268 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1270 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1273 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1274 /* it is the actual width of the separator. This is used for */
1275 /* custom controls in toolbars. */
1277 /* BTNS_DROPDOWN separators are treated as buttons for */
1278 /* width. - GA 8/01 */
1279 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1280 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1281 cx = (btnPtr[i].iBitmap > 0) ?
1282 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1284 cx = infoPtr->nButtonWidth;
1286 /* Two or more adjacent separators form a separator group. */
1287 /* The first separator in a group should be wrapped to the */
1288 /* next row if the previous wrapping is on a button. */
1290 (btnPtr[i].fsStyle & BTNS_SEP) &&
1291 (i + 1 < infoPtr->nNumButtons ) &&
1292 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1294 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1295 btnPtr[i].fsState |= TBSTATE_WRAP;
1296 x = infoPtr->nIndent;
1298 bButtonWrap = FALSE;
1302 /* The layout makes sure the bitmap is visible, but not the button. */
1303 /* Test added to also wrap after a button that starts a row but */
1304 /* is bigger than the area. - GA 8/01 */
1305 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1306 > infoPtr->nWidth ) ||
1307 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1309 BOOL bFound = FALSE;
1311 /* If the current button is a separator and not hidden, */
1312 /* go to the next until it reaches a non separator. */
1313 /* Wrap the last separator if it is before a button. */
1314 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1315 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1316 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1317 i < infoPtr->nNumButtons )
1323 if( bFound && i < infoPtr->nNumButtons )
1326 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1327 i, btnPtr[i].fsStyle, x, cx);
1328 btnPtr[i].fsState |= TBSTATE_WRAP;
1329 x = infoPtr->nIndent;
1330 bButtonWrap = FALSE;
1333 else if ( i >= infoPtr->nNumButtons)
1336 /* If the current button is not a separator, find the last */
1337 /* separator and wrap it. */
1338 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1340 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1341 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1345 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1346 i, btnPtr[i].fsStyle, x, cx);
1347 x = infoPtr->nIndent;
1348 btnPtr[j].fsState |= TBSTATE_WRAP;
1349 bButtonWrap = FALSE;
1354 /* If no separator available for wrapping, wrap one of */
1355 /* non-hidden previous button. */
1359 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1361 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1366 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1367 i, btnPtr[i].fsStyle, x, cx);
1368 x = infoPtr->nIndent;
1369 btnPtr[j].fsState |= TBSTATE_WRAP;
1375 /* If all above failed, wrap the current button. */
1378 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1379 i, btnPtr[i].fsStyle, x, cx);
1380 btnPtr[i].fsState |= TBSTATE_WRAP;
1382 x = infoPtr->nIndent;
1383 if (btnPtr[i].fsStyle & BTNS_SEP )
1384 bButtonWrap = FALSE;
1390 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1391 i, btnPtr[i].fsStyle, x, cx);
1398 /***********************************************************************
1399 * TOOLBAR_CalcToolbar
1401 * This function calculates button and separator placement. It first
1402 * calculates the button sizes, gets the toolbar window width and then
1403 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1404 * on. It assigns a new location to each item and sends this location to
1405 * the tooltip window if appropriate. Finally, it updates the rcBound
1406 * rect and calculates the new required toolbar window height.
1410 TOOLBAR_CalcToolbar (HWND hwnd)
1412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1413 DWORD dwStyle = infoPtr->dwStyle;
1414 TBUTTON_INFO *btnPtr;
1415 INT i, nRows, nSepRows;
1419 BOOL usesBitmaps = FALSE;
1420 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1422 TOOLBAR_CalcStrings (hwnd, &sizeString);
1424 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1426 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1428 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1431 if (dwStyle & TBSTYLE_LIST)
1433 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1434 0, sizeString.cy) + infoPtr->szPadding.cy;
1435 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1436 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1437 if (sizeString.cx > 0)
1438 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1439 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1440 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1441 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1444 if (sizeString.cy > 0)
1447 infoPtr->nButtonHeight = sizeString.cy +
1448 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1449 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1451 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1454 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1456 if (sizeString.cx > infoPtr->nBitmapWidth)
1457 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1459 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1462 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1463 infoPtr->nButtonWidth = infoPtr->cxMin;
1464 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1465 infoPtr->nButtonWidth = infoPtr->cxMax;
1467 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1469 x = infoPtr->nIndent;
1472 /* from above, minimum is a button, and possible text */
1473 cx = infoPtr->nButtonWidth;
1475 /* cannot use just ButtonHeight, we may have no buttons! */
1476 if (infoPtr->nNumButtons > 0)
1477 infoPtr->nHeight = infoPtr->nButtonHeight;
1479 cy = infoPtr->nHeight;
1481 nRows = nSepRows = 0;
1483 infoPtr->rcBound.top = y;
1484 infoPtr->rcBound.left = x;
1485 infoPtr->rcBound.bottom = y + cy;
1486 infoPtr->rcBound.right = x;
1488 btnPtr = infoPtr->buttons;
1490 TRACE("cy=%d\n", cy);
1492 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1495 if (btnPtr->fsState & TBSTATE_HIDDEN)
1497 SetRectEmpty (&btnPtr->rect);
1501 cy = infoPtr->nHeight;
1503 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1504 /* it is the actual width of the separator. This is used for */
1505 /* custom controls in toolbars. */
1506 if (btnPtr->fsStyle & BTNS_SEP) {
1507 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1508 cy = (btnPtr->iBitmap > 0) ?
1509 btnPtr->iBitmap : SEPARATOR_WIDTH;
1510 cx = infoPtr->nButtonWidth;
1513 cx = (btnPtr->iBitmap > 0) ?
1514 btnPtr->iBitmap : SEPARATOR_WIDTH;
1520 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1521 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1528 hOldFont = SelectObject (hdc, infoPtr->hFont);
1530 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1532 SelectObject (hdc, hOldFont);
1533 ReleaseDC (hwnd, hdc);
1535 /* add space on for button frame, etc */
1536 cx = sz.cx + infoPtr->szPadding.cx;
1538 /* add list padding */
1539 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1540 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1542 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1544 if (dwStyle & TBSTYLE_LIST)
1545 cx += infoPtr->nBitmapWidth;
1546 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1547 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1549 else if (dwStyle & TBSTYLE_LIST)
1550 cx += LIST_IMAGE_ABSENT_WIDTH;
1553 cx = infoPtr->nButtonWidth;
1555 /* if size has been set manually then don't add on extra space
1556 * for the drop down arrow */
1557 if (!btnPtr->cx && hasDropDownArrows &&
1558 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1559 cx += DDARROW_WIDTH;
1561 if (btnPtr->fsState & TBSTATE_WRAP )
1564 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1566 if (infoPtr->rcBound.left > x)
1567 infoPtr->rcBound.left = x;
1568 if (infoPtr->rcBound.right < x + cx)
1569 infoPtr->rcBound.right = x + cx;
1570 if (infoPtr->rcBound.bottom < y + cy)
1571 infoPtr->rcBound.bottom = y + cy;
1573 /* Set the toolTip only for non-hidden, non-separator button */
1574 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1578 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1579 ti.cbSize = sizeof(TTTOOLINFOA);
1581 ti.uId = btnPtr->idCommand;
1582 ti.rect = btnPtr->rect;
1583 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1587 /* btnPtr->nRow is zero based. The space between the rows is */
1588 /* also considered as a row. */
1589 btnPtr->nRow = nRows + nSepRows;
1591 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1592 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1597 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1601 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1602 /* it is the actual width of the separator. This is used for */
1603 /* custom controls in toolbars. */
1604 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1605 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1606 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1610 /* nSepRows is used to calculate the extra height follwoing */
1614 x = infoPtr->nIndent;
1616 /* Increment row number unless this is the last button */
1617 /* and it has Wrap set. */
1618 if (i != infoPtr->nNumButtons-1)
1625 /* infoPtr->nRows is the number of rows on the toolbar */
1626 infoPtr->nRows = nRows + nSepRows + 1;
1629 /********************************************************************
1630 * The following while interesting, does not match the values *
1631 * created above for the button rectangles, nor the rcBound rect. *
1632 * We will comment it out and remove it later. *
1634 * The problem showed up as heights in the pager control that was *
1636 ********************************************************************/
1638 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1640 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1641 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1642 nSepRows * (infoPtr->nBitmapHeight + 1) +
1646 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1648 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1653 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1656 TBUTTON_INFO *btnPtr;
1659 btnPtr = infoPtr->buttons;
1660 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1661 if (btnPtr->fsState & TBSTATE_HIDDEN)
1664 if (btnPtr->fsStyle & BTNS_SEP) {
1665 if (PtInRect (&btnPtr->rect, *lpPt)) {
1666 TRACE(" ON SEPARATOR %d!\n", i);
1671 if (PtInRect (&btnPtr->rect, *lpPt)) {
1672 TRACE(" ON BUTTON %d!\n", i);
1678 TRACE(" NOWHERE!\n");
1679 return TOOLBAR_NOWHERE;
1684 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1686 TBUTTON_INFO *btnPtr;
1689 if (CommandIsIndex) {
1690 TRACE("command is really index command=%d\n", idCommand);
1691 if (idCommand >= infoPtr->nNumButtons) return -1;
1694 btnPtr = infoPtr->buttons;
1695 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1696 if (btnPtr->idCommand == idCommand) {
1697 TRACE("command=%d index=%d\n", idCommand, i);
1701 TRACE("no index found for command=%d\n", idCommand);
1707 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1709 TBUTTON_INFO *btnPtr;
1712 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1715 /* check index button */
1716 btnPtr = &infoPtr->buttons[nIndex];
1717 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1718 if (btnPtr->fsState & TBSTATE_CHECKED)
1722 /* check previous buttons */
1723 nRunIndex = nIndex - 1;
1724 while (nRunIndex >= 0) {
1725 btnPtr = &infoPtr->buttons[nRunIndex];
1726 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1727 if (btnPtr->fsState & TBSTATE_CHECKED)
1735 /* check next buttons */
1736 nRunIndex = nIndex + 1;
1737 while (nRunIndex < infoPtr->nNumButtons) {
1738 btnPtr = &infoPtr->buttons[nRunIndex];
1739 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1740 if (btnPtr->fsState & TBSTATE_CHECKED)
1753 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1754 WPARAM wParam, LPARAM lParam)
1760 msg.wParam = wParam;
1761 msg.lParam = lParam;
1762 msg.time = GetMessageTime ();
1763 msg.pt.x = LOWORD(GetMessagePos ());
1764 msg.pt.y = HIWORD(GetMessagePos ());
1766 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1770 /***********************************************************************
1771 * TOOLBAR_CustomizeDialogProc
1772 * This function implements the toolbar customization dialog.
1774 static INT_PTR CALLBACK
1775 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1777 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1778 PCUSTOMBUTTON btnInfo;
1780 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1785 custInfo = (PCUSTDLG_INFO)lParam;
1786 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1794 infoPtr = custInfo->tbInfo;
1796 /* send TBN_QUERYINSERT notification */
1797 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1799 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1802 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1803 nmtb.iItem = (int)hwnd;
1804 /* Send TBN_INITCUSTOMIZE notification */
1805 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1808 TRACE("TBNRF_HIDEHELP requested\n");
1809 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1812 /* add items to 'toolbar buttons' list and check if removable */
1813 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1815 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1816 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1817 btnInfo->btn.fsStyle = BTNS_SEP;
1818 btnInfo->bVirtual = FALSE;
1819 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1821 /* send TBN_QUERYDELETE notification */
1822 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1824 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1825 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1828 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1830 /* insert separator button into 'available buttons' list */
1831 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1832 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1833 btnInfo->btn.fsStyle = BTNS_SEP;
1834 btnInfo->bVirtual = FALSE;
1835 btnInfo->bRemovable = TRUE;
1836 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1837 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1838 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1840 /* insert all buttons into dsa */
1843 /* send TBN_GETBUTTONINFO notification */
1846 nmtb.pszText = Buffer;
1849 /* Clear previous button's text */
1850 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1852 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1855 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1856 nmtb.tbButton.fsStyle, i,
1857 nmtb.tbButton.idCommand,
1858 nmtb.tbButton.iString,
1859 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1862 /* insert button into the apropriate list */
1863 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1866 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1867 btnInfo->bVirtual = FALSE;
1868 btnInfo->bRemovable = TRUE;
1870 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1871 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1872 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1876 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1877 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1880 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1881 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1883 if (lstrlenW(nmtb.pszText))
1884 lstrcpyW(btnInfo->text, nmtb.pszText);
1885 else if (nmtb.tbButton.iString >= 0 &&
1886 nmtb.tbButton.iString < infoPtr->nNumStrings)
1888 lstrcpyW(btnInfo->text,
1889 infoPtr->strings[nmtb.tbButton.iString]);
1894 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1896 /* select first item in the 'available' list */
1897 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1899 /* append 'virtual' separator button to the 'toolbar buttons' list */
1900 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1901 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1902 btnInfo->btn.fsStyle = BTNS_SEP;
1903 btnInfo->bVirtual = TRUE;
1904 btnInfo->bRemovable = FALSE;
1905 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1906 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1907 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1909 /* select last item in the 'toolbar' list */
1910 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1911 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1913 /* set focus and disable buttons */
1914 PostMessageA (hwnd, WM_USER, 0, 0);
1919 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1920 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1921 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1922 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1926 EndDialog(hwnd, FALSE);
1930 switch (LOWORD(wParam))
1932 case IDC_TOOLBARBTN_LBOX:
1933 if (HIWORD(wParam) == LBN_SELCHANGE)
1935 PCUSTOMBUTTON btnInfo;
1940 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1941 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1943 /* send TBN_QUERYINSERT notification */
1945 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1948 /* get list box item */
1949 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1951 if (index == (count - 1))
1953 /* last item (virtual separator) */
1954 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1955 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1957 else if (index == (count - 2))
1959 /* second last item (last non-virtual item) */
1960 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1961 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1963 else if (index == 0)
1966 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1967 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1971 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1972 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1975 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1979 case IDC_MOVEUP_BTN:
1981 PCUSTOMBUTTON btnInfo;
1985 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1986 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1987 TRACE("Move up: index %d\n", index);
1989 /* send TBN_QUERYINSERT notification */
1992 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1997 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1999 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2000 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
2001 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
2002 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2005 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2006 else if (index >= (count - 3))
2007 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2009 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2010 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
2012 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2017 case IDC_MOVEDN_BTN: /* move down */
2019 PCUSTOMBUTTON btnInfo;
2023 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2024 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2025 TRACE("Move up: index %d\n", index);
2027 /* send TBN_QUERYINSERT notification */
2029 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2034 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2036 /* move button down */
2037 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2038 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2039 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2040 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2043 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2044 else if (index >= (count - 3))
2045 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2047 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2048 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2050 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2055 case IDC_REMOVE_BTN: /* remove button */
2057 PCUSTOMBUTTON btnInfo;
2060 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2062 if (LB_ERR == index)
2065 TRACE("Remove: index %d\n", index);
2067 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2068 LB_GETITEMDATA, index, 0);
2070 /* send TBN_QUERYDELETE notification */
2071 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2075 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2076 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2077 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2079 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2081 /* insert into 'available button' list */
2082 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2084 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2085 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2090 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2095 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2098 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2101 case IDOK: /* Add button */
2106 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2107 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2108 TRACE("Add: index %d\n", index);
2110 /* send TBN_QUERYINSERT notification */
2112 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2117 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2121 /* remove from 'available buttons' list */
2122 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2123 if (index == count-1)
2124 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2126 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2130 PCUSTOMBUTTON btnNew;
2132 /* duplicate 'separator' button */
2133 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2134 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2138 /* insert into 'toolbar button' list */
2139 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2140 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2141 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2143 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2145 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2151 EndDialog(hwnd, FALSE);
2161 /* delete items from 'toolbar buttons' listbox*/
2162 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2163 for (i = 0; i < count; i++)
2165 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2167 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2169 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2172 /* delete items from 'available buttons' listbox*/
2173 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2174 for (i = 0; i < count; i++)
2176 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2178 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2180 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2185 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2187 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2192 COLORREF oldText = 0;
2196 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2197 if (btnInfo == NULL)
2199 FIXME("btnInfo invalid!\n");
2203 /* set colors and select objects */
2204 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2205 if (btnInfo->bVirtual)
2206 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2208 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2209 hPen = CreatePen( PS_SOLID, 1,
2210 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2211 hOldPen = SelectObject (lpdis->hDC, hPen );
2212 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2214 /* fill background rectangle */
2215 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2216 lpdis->rcItem.right, lpdis->rcItem.bottom);
2218 /* calculate button and text rectangles */
2219 CopyRect (&rcButton, &lpdis->rcItem);
2220 InflateRect (&rcButton, -1, -1);
2221 CopyRect (&rcText, &rcButton);
2222 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2223 rcText.left = rcButton.right + 2;
2225 /* draw focus rectangle */
2226 if (lpdis->itemState & ODS_FOCUS)
2227 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2230 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2231 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2233 /* draw image and text */
2234 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2235 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2236 btnInfo->btn.iBitmap));
2237 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2238 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2240 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2241 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2243 /* delete objects and reset colors */
2244 SelectObject (lpdis->hDC, hOldBrush);
2245 SelectObject (lpdis->hDC, hOldPen);
2246 SetBkColor (lpdis->hDC, oldBk);
2247 SetTextColor (lpdis->hDC, oldText);
2248 DeleteObject( hPen );
2253 case WM_MEASUREITEM:
2254 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2256 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2258 lpmis->itemHeight = 15 + 8; /* default height */
2270 /***********************************************************************
2271 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2275 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2277 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2278 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2279 INT nIndex = 0, nButtons, nCount;
2283 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2287 if (lpAddBmp->hInst == HINST_COMMCTRL)
2289 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2291 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2293 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2298 TRACE ("adding %d internal bitmaps!\n", nButtons);
2300 /* Windows resize all the buttons to the size of a newly added standard image */
2301 if (lpAddBmp->nID & 1)
2304 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2305 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2307 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2308 MAKELPARAM((WORD)24, (WORD)24));
2309 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2310 MAKELPARAM((WORD)31, (WORD)30));
2315 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2316 MAKELPARAM((WORD)16, (WORD)16));
2317 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2318 MAKELPARAM((WORD)22, (WORD)22));
2321 TOOLBAR_CalcToolbar (hwnd);
2325 nButtons = (INT)wParam;
2329 TRACE ("adding %d bitmaps!\n", nButtons);
2332 if (!infoPtr->cimlDef) {
2333 /* create new default image list */
2334 TRACE ("creating default image list!\n");
2336 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2337 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2338 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2339 infoPtr->himlInt = himlDef;
2342 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2346 WARN("No default image list available\n");
2350 nCount = ImageList_GetImageCount(himlDef);
2352 /* Add bitmaps to the default image list */
2353 if (lpAddBmp->hInst == NULL)
2356 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2357 HDC hdcImage, hdcBitmap;
2359 /* copy the bitmap before adding it so that the user's bitmap
2360 * doesn't get modified.
2362 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2364 hdcImage = CreateCompatibleDC(0);
2365 hdcBitmap = CreateCompatibleDC(0);
2367 /* create new bitmap */
2368 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2369 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2370 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2372 /* Copy the user's image */
2373 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2374 hdcBitmap, 0, 0, SRCCOPY);
2376 SelectObject (hdcImage, hOldBitmapLoad);
2377 SelectObject (hdcBitmap, hOldBitmapBitmap);
2378 DeleteDC (hdcImage);
2379 DeleteDC (hdcBitmap);
2381 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2382 DeleteObject (hbmLoad);
2384 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2386 /* Add system bitmaps */
2387 switch (lpAddBmp->nID)
2389 case IDB_STD_SMALL_COLOR:
2390 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2391 MAKEINTRESOURCEA(IDB_STD_SMALL));
2392 nIndex = ImageList_AddMasked (himlDef,
2393 hbmLoad, comctl32_color.clrBtnFace);
2394 DeleteObject (hbmLoad);
2397 case IDB_STD_LARGE_COLOR:
2398 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2399 MAKEINTRESOURCEA(IDB_STD_LARGE));
2400 nIndex = ImageList_AddMasked (himlDef,
2401 hbmLoad, comctl32_color.clrBtnFace);
2402 DeleteObject (hbmLoad);
2405 case IDB_VIEW_SMALL_COLOR:
2406 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2407 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2408 nIndex = ImageList_AddMasked (himlDef,
2409 hbmLoad, comctl32_color.clrBtnFace);
2410 DeleteObject (hbmLoad);
2413 case IDB_VIEW_LARGE_COLOR:
2414 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2415 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2416 nIndex = ImageList_AddMasked (himlDef,
2417 hbmLoad, comctl32_color.clrBtnFace);
2418 DeleteObject (hbmLoad);
2421 case IDB_HIST_SMALL_COLOR:
2422 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2423 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2424 nIndex = ImageList_AddMasked (himlDef,
2425 hbmLoad, comctl32_color.clrBtnFace);
2426 DeleteObject (hbmLoad);
2429 case IDB_HIST_LARGE_COLOR:
2430 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2431 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2432 nIndex = ImageList_AddMasked (himlDef,
2433 hbmLoad, comctl32_color.clrBtnFace);
2434 DeleteObject (hbmLoad);
2438 nIndex = ImageList_GetImageCount (himlDef);
2439 ERR ("invalid imagelist!\n");
2445 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2446 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2447 DeleteObject (hbmLoad);
2450 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2452 if (infoPtr->nNumBitmapInfos == 0)
2454 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2458 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2459 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2460 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2463 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2464 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2465 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2467 infoPtr->nNumBitmapInfos++;
2468 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2472 INT imagecount = ImageList_GetImageCount(himlDef);
2474 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2476 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",
2477 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2478 infoPtr->nNumBitmaps+nButtons,imagecount);
2480 infoPtr->nNumBitmaps = imagecount;
2483 infoPtr->nNumBitmaps += nButtons;
2486 InvalidateRect(hwnd, NULL, TRUE);
2493 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2496 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2497 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2499 TRACE("adding %d buttons!\n", wParam);
2501 nAddButtons = (UINT)wParam;
2502 nOldButtons = infoPtr->nNumButtons;
2503 nNewButtons = nOldButtons + nAddButtons;
2505 if (infoPtr->nNumButtons == 0) {
2507 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2510 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2512 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2513 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2514 nOldButtons * sizeof(TBUTTON_INFO));
2518 infoPtr->nNumButtons = nNewButtons;
2520 /* insert new button data */
2521 for (nCount = 0; nCount < nAddButtons; nCount++) {
2522 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2523 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2524 btnPtr->idCommand = lpTbb[nCount].idCommand;
2525 btnPtr->fsState = lpTbb[nCount].fsState;
2526 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2527 btnPtr->dwData = lpTbb[nCount].dwData;
2528 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2529 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2531 btnPtr->iString = lpTbb[nCount].iString;
2532 btnPtr->bHot = FALSE;
2534 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2537 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2538 ti.cbSize = sizeof (TTTOOLINFOA);
2540 ti.uId = btnPtr->idCommand;
2542 ti.lpszText = LPSTR_TEXTCALLBACKA;
2544 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2549 TOOLBAR_CalcToolbar (hwnd);
2551 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2553 InvalidateRect(hwnd, NULL, TRUE);
2560 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2562 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2563 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2564 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2566 TRACE("adding %d buttons!\n", wParam);
2568 nAddButtons = (UINT)wParam;
2569 nOldButtons = infoPtr->nNumButtons;
2570 nNewButtons = nOldButtons + nAddButtons;
2572 if (infoPtr->nNumButtons == 0) {
2574 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2577 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2579 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2580 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2581 nOldButtons * sizeof(TBUTTON_INFO));
2585 infoPtr->nNumButtons = nNewButtons;
2587 /* insert new button data */
2588 for (nCount = 0; nCount < nAddButtons; nCount++) {
2589 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2590 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2591 btnPtr->idCommand = lpTbb[nCount].idCommand;
2592 btnPtr->fsState = lpTbb[nCount].fsState;
2593 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2594 btnPtr->dwData = lpTbb[nCount].dwData;
2595 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2596 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2598 btnPtr->iString = lpTbb[nCount].iString;
2599 btnPtr->bHot = FALSE;
2601 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2604 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2605 ti.cbSize = sizeof (TTTOOLINFOW);
2607 ti.uId = btnPtr->idCommand;
2609 ti.lpszText = LPSTR_TEXTCALLBACKW;
2612 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2617 TOOLBAR_CalcToolbar (hwnd);
2619 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2621 InvalidateRect(hwnd, NULL, TRUE);
2628 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2633 if ((wParam) && (HIWORD(lParam) == 0)) {
2636 TRACE("adding string from resource!\n");
2638 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2641 TRACE("len=%d \"%s\"\n", len, szString);
2642 nIndex = infoPtr->nNumStrings;
2643 if (infoPtr->nNumStrings == 0) {
2645 Alloc (sizeof(LPWSTR));
2648 LPWSTR *oldStrings = infoPtr->strings;
2650 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2651 memcpy (&infoPtr->strings[0], &oldStrings[0],
2652 sizeof(LPWSTR) * infoPtr->nNumStrings);
2656 /*Alloc zeros out the allocated memory*/
2657 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2658 infoPtr->nNumStrings++;
2661 LPSTR p = (LPSTR)lParam;
2666 TRACE("adding string(s) from array!\n");
2668 nIndex = infoPtr->nNumStrings;
2671 TRACE("len=%d \"%s\"\n", len, p);
2673 if (infoPtr->nNumStrings == 0) {
2675 Alloc (sizeof(LPWSTR));
2678 LPWSTR *oldStrings = infoPtr->strings;
2680 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2681 memcpy (&infoPtr->strings[0], &oldStrings[0],
2682 sizeof(LPWSTR) * infoPtr->nNumStrings);
2686 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2687 infoPtr->nNumStrings++;
2698 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2700 #define MAX_RESOURCE_STRING_LENGTH 512
2701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2704 if ((wParam) && (HIWORD(lParam) == 0)) {
2705 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2707 TRACE("adding string from resource!\n");
2709 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2710 szString, MAX_RESOURCE_STRING_LENGTH);
2712 TRACE("len=%d %s\n", len, debugstr_w(szString));
2713 TRACE("First char: 0x%x\n", *szString);
2714 if (szString[0] == L'|')
2716 PWSTR p = szString + 1;
2718 nIndex = infoPtr->nNumStrings;
2719 while (*p != L'|' && *p != L'\0') {
2722 if (infoPtr->nNumStrings == 0) {
2723 infoPtr->strings = Alloc (sizeof(LPWSTR));
2727 LPWSTR *oldStrings = infoPtr->strings;
2728 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2729 memcpy(&infoPtr->strings[0], &oldStrings[0],
2730 sizeof(LPWSTR) * infoPtr->nNumStrings);
2734 np=strchrW (p, '|');
2742 TRACE("len=%d %s\n", len, debugstr_w(p));
2743 infoPtr->strings[infoPtr->nNumStrings] =
2744 Alloc (sizeof(WCHAR)*(len+1));
2745 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2746 infoPtr->nNumStrings++;
2753 nIndex = infoPtr->nNumStrings;
2754 if (infoPtr->nNumStrings == 0) {
2756 Alloc (sizeof(LPWSTR));
2759 LPWSTR *oldStrings = infoPtr->strings;
2761 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2762 memcpy (&infoPtr->strings[0], &oldStrings[0],
2763 sizeof(LPWSTR) * infoPtr->nNumStrings);
2767 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2768 infoPtr->nNumStrings++;
2772 LPWSTR p = (LPWSTR)lParam;
2777 TRACE("adding string(s) from array!\n");
2778 nIndex = infoPtr->nNumStrings;
2782 TRACE("len=%d %s\n", len, debugstr_w(p));
2783 if (infoPtr->nNumStrings == 0) {
2785 Alloc (sizeof(LPWSTR));
2788 LPWSTR *oldStrings = infoPtr->strings;
2790 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2791 memcpy (&infoPtr->strings[0], &oldStrings[0],
2792 sizeof(LPWSTR) * infoPtr->nNumStrings);
2796 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2797 infoPtr->nNumStrings++;
2808 TOOLBAR_AutoSize (HWND hwnd)
2810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2816 UINT uPosFlags = SWP_NOZORDER;
2818 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2820 parent = GetParent (hwnd);
2821 GetClientRect(parent, &parent_rect);
2823 x = parent_rect.left;
2824 y = parent_rect.top;
2826 /* FIXME: we should be able to early out if nothing */
2827 /* has changed with nWidth != parent_rect width */
2829 if (infoPtr->dwStyle & CCS_NORESIZE) {
2830 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2833 TOOLBAR_CalcToolbar (hwnd);
2836 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2837 TOOLBAR_CalcToolbar (hwnd);
2838 InvalidateRect( hwnd, NULL, TRUE );
2839 cy = infoPtr->nHeight;
2840 cx = infoPtr->nWidth;
2842 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2843 GetWindowRect(hwnd, &window_rect);
2844 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2845 y = window_rect.top;
2847 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2848 GetWindowRect(hwnd, &window_rect);
2849 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2853 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2854 uPosFlags |= SWP_NOMOVE;
2856 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2857 cy += GetSystemMetrics(SM_CYEDGE);
2859 if (infoPtr->dwStyle & WS_BORDER)
2862 cy += GetSystemMetrics(SM_CYEDGE);
2863 cx += GetSystemMetrics(SM_CYEDGE);
2866 infoPtr->bAutoSize = TRUE;
2867 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2868 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2869 * after the setwindowpos calls */
2870 infoPtr->bAutoSize = FALSE;
2877 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2881 return infoPtr->nNumButtons;
2886 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2888 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2890 if (infoPtr == NULL) {
2891 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2892 ERR("infoPtr == NULL!\n");
2896 infoPtr->dwStructSize = (DWORD)wParam;
2903 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2906 TBUTTON_INFO *btnPtr;
2909 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2911 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2915 btnPtr = &infoPtr->buttons[nIndex];
2916 btnPtr->iBitmap = LOWORD(lParam);
2918 /* we HAVE to erase the background, the new bitmap could be */
2920 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2927 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2929 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2930 TBUTTON_INFO *btnPtr;
2933 BOOL bChecked = FALSE;
2935 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2937 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2942 btnPtr = &infoPtr->buttons[nIndex];
2944 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2946 if (LOWORD(lParam) == FALSE)
2947 btnPtr->fsState &= ~TBSTATE_CHECKED;
2949 if (btnPtr->fsStyle & BTNS_GROUP) {
2951 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2952 if (nOldIndex == nIndex)
2954 if (nOldIndex != -1)
2955 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2957 btnPtr->fsState |= TBSTATE_CHECKED;
2960 if( bChecked != LOWORD(lParam) )
2962 if (nOldIndex != -1)
2963 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2964 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2967 /* FIXME: Send a WM_NOTIFY?? */
2974 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2978 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2983 TOOLBAR_Customize (HWND hwnd)
2985 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2986 CUSTDLG_INFO custInfo;
2992 custInfo.tbInfo = infoPtr;
2993 custInfo.tbHwnd = hwnd;
2995 /* send TBN_BEGINADJUST notification */
2996 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2999 if (!(hRes = FindResourceA (COMCTL32_hModule,
3000 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
3004 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
3007 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
3008 (LPDLGTEMPLATEA)template,
3010 TOOLBAR_CustomizeDialogProc,
3013 /* send TBN_ENDADJUST notification */
3014 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3022 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3024 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3025 INT nIndex = (INT)wParam;
3028 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3031 memset(&nmtb, 0, sizeof(nmtb));
3032 nmtb.iItem = nIndex;
3033 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3035 if ((infoPtr->hwndToolTip) &&
3036 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3039 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3040 ti.cbSize = sizeof (TTTOOLINFOA);
3042 ti.uId = infoPtr->buttons[nIndex].idCommand;
3044 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3047 if (infoPtr->nNumButtons == 1) {
3048 TRACE(" simple delete!\n");
3049 Free (infoPtr->buttons);
3050 infoPtr->buttons = NULL;
3051 infoPtr->nNumButtons = 0;
3054 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3055 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3057 infoPtr->nNumButtons--;
3058 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3060 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3061 nIndex * sizeof(TBUTTON_INFO));
3064 if (nIndex < infoPtr->nNumButtons) {
3065 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3066 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3072 TOOLBAR_CalcToolbar (hwnd);
3074 InvalidateRect (hwnd, NULL, TRUE);
3081 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3084 TBUTTON_INFO *btnPtr;
3088 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3090 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3095 btnPtr = &infoPtr->buttons[nIndex];
3097 bState = btnPtr->fsState & TBSTATE_ENABLED;
3099 /* update the toolbar button state */
3100 if(LOWORD(lParam) == FALSE) {
3101 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3103 btnPtr->fsState |= TBSTATE_ENABLED;
3106 /* redraw the button only if the state of the button changed */
3107 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3108 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3114 static inline LRESULT
3115 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3119 return infoPtr->bAnchor;
3124 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3126 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3129 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3133 return infoPtr->buttons[nIndex].iBitmap;
3137 static inline LRESULT
3138 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3140 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3145 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3148 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3149 INT nIndex = (INT)wParam;
3150 TBUTTON_INFO *btnPtr;
3152 if (infoPtr == NULL)
3158 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3161 btnPtr = &infoPtr->buttons[nIndex];
3162 lpTbb->iBitmap = btnPtr->iBitmap;
3163 lpTbb->idCommand = btnPtr->idCommand;
3164 lpTbb->fsState = btnPtr->fsState;
3165 lpTbb->fsStyle = btnPtr->fsStyle;
3166 lpTbb->bReserved[0] = 0;
3167 lpTbb->bReserved[1] = 0;
3168 lpTbb->dwData = btnPtr->dwData;
3169 lpTbb->iString = btnPtr->iString;
3176 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3179 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3180 TBUTTON_INFO *btnPtr;
3183 if (infoPtr == NULL)
3185 if (lpTbInfo == NULL)
3187 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3190 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3191 lpTbInfo->dwMask & 0x80000000);
3195 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3197 if (lpTbInfo->dwMask & TBIF_COMMAND)
3198 lpTbInfo->idCommand = btnPtr->idCommand;
3199 if (lpTbInfo->dwMask & TBIF_IMAGE)
3200 lpTbInfo->iImage = btnPtr->iBitmap;
3201 if (lpTbInfo->dwMask & TBIF_LPARAM)
3202 lpTbInfo->lParam = btnPtr->dwData;
3203 if (lpTbInfo->dwMask & TBIF_SIZE)
3204 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3205 if (lpTbInfo->dwMask & TBIF_STATE)
3206 lpTbInfo->fsState = btnPtr->fsState;
3207 if (lpTbInfo->dwMask & TBIF_STYLE)
3208 lpTbInfo->fsStyle = btnPtr->fsStyle;
3209 if (lpTbInfo->dwMask & TBIF_TEXT) {
3210 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3211 can't use TOOLBAR_GetText here */
3213 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3214 lpText = (LPWSTR)btnPtr->iString;
3215 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3217 lpTbInfo->pszText[0] = '\0';
3224 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3226 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3227 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3228 TBUTTON_INFO *btnPtr;
3231 if (infoPtr == NULL)
3233 if (lpTbInfo == NULL)
3235 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3238 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3239 lpTbInfo->dwMask & 0x80000000);
3243 btnPtr = &infoPtr->buttons[nIndex];
3248 if (lpTbInfo->dwMask & TBIF_COMMAND)
3249 lpTbInfo->idCommand = btnPtr->idCommand;
3250 if (lpTbInfo->dwMask & TBIF_IMAGE)
3251 lpTbInfo->iImage = btnPtr->iBitmap;
3252 if (lpTbInfo->dwMask & TBIF_LPARAM)
3253 lpTbInfo->lParam = btnPtr->dwData;
3254 if (lpTbInfo->dwMask & TBIF_SIZE)
3255 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3256 if (lpTbInfo->dwMask & TBIF_STATE)
3257 lpTbInfo->fsState = btnPtr->fsState;
3258 if (lpTbInfo->dwMask & TBIF_STYLE)
3259 lpTbInfo->fsStyle = btnPtr->fsStyle;
3260 if (lpTbInfo->dwMask & TBIF_TEXT) {
3261 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3262 can't use TOOLBAR_GetText here */
3264 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3265 lpText = (LPWSTR)btnPtr->iString;
3266 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3268 lpTbInfo->pszText[0] = '\0';
3276 TOOLBAR_GetButtonSize (HWND hwnd)
3278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3280 if (infoPtr->nNumButtons > 0)
3281 return MAKELONG((WORD)infoPtr->nButtonWidth,
3282 (WORD)infoPtr->nButtonHeight);
3284 return MAKELONG(8,7);
3289 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3298 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3302 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3304 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3305 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3310 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3312 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3321 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3325 ret = strlenW (lpText);
3328 strcpyW ((LPWSTR)lParam, lpText);
3336 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3338 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3339 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3340 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3344 inline static LRESULT
3345 TOOLBAR_GetExtendedStyle (HWND hwnd)
3347 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 return infoPtr->dwExStyle;
3356 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3358 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3359 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3360 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3365 TOOLBAR_GetHotItem (HWND hwnd)
3367 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3369 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3372 if (infoPtr->nHotItem < 0)
3375 return (LRESULT)infoPtr->nHotItem;
3380 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3382 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3383 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3384 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3389 TOOLBAR_GetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
3391 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3392 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
3394 TRACE("hwnd = %p, lptbim = %p\n", hwnd, lptbim);
3396 *lptbim = infoPtr->tbim;
3403 TOOLBAR_GetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3405 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3407 TRACE("hwnd = %p\n", hwnd);
3409 return (LRESULT)infoPtr->clrInsertMark;
3414 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3417 TBUTTON_INFO *btnPtr;
3421 if (infoPtr == NULL)
3423 nIndex = (INT)wParam;
3424 btnPtr = &infoPtr->buttons[nIndex];
3425 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3427 lpRect = (LPRECT)lParam;
3430 if (btnPtr->fsState & TBSTATE_HIDDEN)
3433 lpRect->left = btnPtr->rect.left;
3434 lpRect->right = btnPtr->rect.right;
3435 lpRect->bottom = btnPtr->rect.bottom;
3436 lpRect->top = btnPtr->rect.top;
3443 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3446 LPSIZE lpSize = (LPSIZE)lParam;
3451 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3452 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3454 TRACE("maximum size %ld x %ld\n",
3455 infoPtr->rcBound.right - infoPtr->rcBound.left,
3456 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3462 /* << TOOLBAR_GetObject >> */
3466 TOOLBAR_GetPadding (HWND hwnd)
3468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3471 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3472 return (LRESULT) oldPad;
3477 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3480 TBUTTON_INFO *btnPtr;
3484 if (infoPtr == NULL)
3486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3487 btnPtr = &infoPtr->buttons[nIndex];
3488 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3490 lpRect = (LPRECT)lParam;
3494 lpRect->left = btnPtr->rect.left;
3495 lpRect->right = btnPtr->rect.right;
3496 lpRect->bottom = btnPtr->rect.bottom;
3497 lpRect->top = btnPtr->rect.top;
3504 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3506 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3508 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3509 return infoPtr->nRows;
3516 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3518 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3521 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3525 return infoPtr->buttons[nIndex].fsState;
3530 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3532 return GetWindowLongW(hwnd, GWL_STYLE);
3537 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3541 if (infoPtr == NULL)
3544 return infoPtr->nMaxTextRows;
3549 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3553 if (infoPtr == NULL)
3555 return (LRESULT)infoPtr->hwndToolTip;
3560 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3564 TRACE("%s hwnd=%p stub!\n",
3565 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3567 return infoPtr->bUnicode;
3571 inline static LRESULT
3572 TOOLBAR_GetVersion (HWND hwnd)
3574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3575 return infoPtr->iVersion;
3580 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3583 TBUTTON_INFO *btnPtr;
3588 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3592 btnPtr = &infoPtr->buttons[nIndex];
3593 if (LOWORD(lParam) == FALSE)
3594 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3596 btnPtr->fsState |= TBSTATE_HIDDEN;
3598 TOOLBAR_CalcToolbar (hwnd);
3600 InvalidateRect (hwnd, NULL, TRUE);
3606 inline static LRESULT
3607 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3609 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3614 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3616 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3617 TBUTTON_INFO *btnPtr;
3621 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3625 btnPtr = &infoPtr->buttons[nIndex];
3626 oldState = btnPtr->fsState;
3627 if (LOWORD(lParam) == FALSE)
3628 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3630 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3632 if(oldState != btnPtr->fsState)
3633 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3640 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3642 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3643 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3644 INT nIndex = (INT)wParam;
3645 TBUTTON_INFO *oldButtons;
3650 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3653 /* EPP: this seems to be an undocumented call (from my IE4)
3654 * I assume in that case that:
3655 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3656 * - index of insertion is at the end of existing buttons
3657 * I only see this happen with nIndex == -1, but it could have a special
3658 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3660 nIndex = infoPtr->nNumButtons;
3662 } else if (nIndex < 0)
3665 /* If the string passed is not an index, assume address of string
3666 and do our own AddString */
3667 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3671 TRACE("string %s passed instead of index, adding string\n",
3672 debugstr_a((LPSTR)lpTbb->iString));
3673 len = strlen((LPSTR)lpTbb->iString) + 2;
3675 strcpy(ptr, (LPSTR)lpTbb->iString);
3676 ptr[len - 1] = 0; /* ended by two '\0' */
3677 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3681 TRACE("inserting button index=%d\n", nIndex);
3682 if (nIndex > infoPtr->nNumButtons) {
3683 nIndex = infoPtr->nNumButtons;
3684 TRACE("adjust index=%d\n", nIndex);
3687 oldButtons = infoPtr->buttons;
3688 infoPtr->nNumButtons++;
3689 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3690 /* pre insert copy */
3692 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3693 nIndex * sizeof(TBUTTON_INFO));
3696 /* insert new button */
3697 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3698 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3699 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3700 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3701 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3702 /* if passed string and not index, then add string */
3703 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3704 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3707 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3709 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3712 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3713 ti.cbSize = sizeof (TTTOOLINFOA);
3715 ti.uId = lpTbb->idCommand;
3717 ti.lpszText = LPSTR_TEXTCALLBACKA;
3719 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3723 /* post insert copy */
3724 if (nIndex < infoPtr->nNumButtons - 1) {
3725 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3726 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3731 TOOLBAR_CalcToolbar (hwnd);
3733 InvalidateRect (hwnd, NULL, TRUE);
3740 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3742 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3743 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3744 INT nIndex = (INT)wParam;
3745 TBUTTON_INFO *oldButtons;
3750 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3753 /* EPP: this seems to be an undocumented call (from my IE4)
3754 * I assume in that case that:
3755 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3756 * - index of insertion is at the end of existing buttons
3757 * I only see this happen with nIndex == -1, but it could have a special
3758 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3760 nIndex = infoPtr->nNumButtons;
3762 } else if (nIndex < 0)
3765 /* If the string passed is not an index, assume address of string
3766 and do our own AddString */
3767 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3771 TRACE("string %s passed instead of index, adding string\n",
3772 debugstr_w((LPWSTR)lpTbb->iString));
3773 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3774 ptr = Alloc(len*sizeof(WCHAR));
3775 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3776 ptr[len - 1] = 0; /* ended by two '\0' */
3777 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3781 TRACE("inserting button index=%d\n", nIndex);
3782 if (nIndex > infoPtr->nNumButtons) {
3783 nIndex = infoPtr->nNumButtons;
3784 TRACE("adjust index=%d\n", nIndex);
3787 oldButtons = infoPtr->buttons;
3788 infoPtr->nNumButtons++;
3789 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3790 /* pre insert copy */
3792 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3793 nIndex * sizeof(TBUTTON_INFO));
3796 /* insert new button */
3797 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3798 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3799 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3800 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3801 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3802 /* if passed string and not index, then add string */
3803 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3804 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3807 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3809 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3812 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3813 ti.cbSize = sizeof (TTTOOLINFOW);
3815 ti.uId = lpTbb->idCommand;
3817 ti.lpszText = LPSTR_TEXTCALLBACKW;
3819 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3823 /* post insert copy */
3824 if (nIndex < infoPtr->nNumButtons - 1) {
3825 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3826 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3831 TOOLBAR_CalcToolbar (hwnd);
3833 InvalidateRect (hwnd, NULL, TRUE);
3839 /* << TOOLBAR_InsertMarkHitTest >> */
3843 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3845 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3848 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3852 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3857 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3862 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3866 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3871 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3873 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3876 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3880 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3885 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3887 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3890 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3894 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3899 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3901 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3904 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3908 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3913 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3918 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3922 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3927 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3930 tbab.hInst = (HINSTANCE)lParam;
3931 tbab.nID = (UINT_PTR)wParam;
3933 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3935 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3940 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3942 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3943 WCHAR wAccel = (WCHAR)wParam;
3944 UINT* pIDButton = (UINT*)lParam;
3945 WCHAR wszAccel[] = {'&',wAccel,0};
3948 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3949 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3951 for (i = 0; i < infoPtr->nNumButtons; i++)
3953 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3954 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3955 !(btnPtr->fsState & TBSTATE_HIDDEN))
3957 int iLen = strlenW(wszAccel);
3958 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3965 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3970 if (!strncmpiW(lpszStr, wszAccel, iLen))
3972 *pIDButton = btnPtr->idCommand;
3984 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3989 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3991 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3996 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3998 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
4004 /* fixes up an index of a button affected by a move */
4005 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
4009 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
4011 else if (*pIndex == nIndex)
4012 *pIndex = nMoveIndex;
4016 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
4018 else if (*pIndex == nIndex)
4019 *pIndex = nMoveIndex;
4025 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4027 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4030 INT nMoveIndex = (INT)lParam;
4031 TBUTTON_INFO button;
4033 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4035 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4036 if ((nIndex == -1) || (nMoveIndex < 0))
4039 if (nMoveIndex > infoPtr->nNumButtons - 1)
4040 nMoveIndex = infoPtr->nNumButtons - 1;
4042 button = infoPtr->buttons[nIndex];
4044 /* move button right */
4045 if (nIndex < nMoveIndex)
4047 nCount = nMoveIndex - nIndex;
4048 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4049 infoPtr->buttons[nMoveIndex] = button;
4051 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4052 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4053 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4054 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4056 else if (nIndex > nMoveIndex) /* move button left */
4058 nCount = nIndex - nMoveIndex;
4059 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4060 infoPtr->buttons[nMoveIndex] = button;
4062 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4063 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4064 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4065 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4068 TOOLBAR_CalcToolbar(hwnd);
4069 InvalidateRect(hwnd, NULL, TRUE);
4076 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4079 TBUTTON_INFO *btnPtr;
4083 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4087 btnPtr = &infoPtr->buttons[nIndex];
4088 oldState = btnPtr->fsState;
4089 if (LOWORD(lParam) == FALSE)
4090 btnPtr->fsState &= ~TBSTATE_PRESSED;
4092 btnPtr->fsState |= TBSTATE_PRESSED;
4094 if(oldState != btnPtr->fsState)
4095 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4100 /* FIXME: there might still be some confusion her between number of buttons
4101 * and number of bitmaps */
4103 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4105 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4106 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4108 int i = 0, nOldButtons = 0, pos = 0;
4109 int nOldBitmaps, nNewBitmaps;
4110 HIMAGELIST himlDef = 0;
4112 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4113 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4114 lpReplace->nButtons);
4116 if (lpReplace->hInstOld == HINST_COMMCTRL)
4118 FIXME("changing standard bitmaps not implemented\n");
4121 else if (lpReplace->hInstOld != 0)
4123 FIXME("resources not in the current module not implemented\n");
4128 hBitmap = (HBITMAP) lpReplace->nIDNew;
4131 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4132 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4133 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4134 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4135 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4137 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4138 nOldButtons = tbi->nButtons;
4139 tbi->nButtons = lpReplace->nButtons;
4140 tbi->hInst = lpReplace->hInstNew;
4141 tbi->nID = lpReplace->nIDNew;
4142 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4145 pos += tbi->nButtons;
4148 if (nOldButtons == 0)
4150 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4154 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4155 nOldBitmaps = ImageList_GetImageCount(himlDef);
4157 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4159 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4160 ImageList_Remove(himlDef, i);
4164 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4165 HDC hdcImage, hdcBitmap;
4167 /* copy the bitmap before adding it so that the user's bitmap
4168 * doesn't get modified.
4170 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4172 hdcImage = CreateCompatibleDC(0);
4173 hdcBitmap = CreateCompatibleDC(0);
4175 /* create new bitmap */
4176 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4177 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4178 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4180 /* Copy the user's image */
4181 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4182 hdcBitmap, 0, 0, SRCCOPY);
4184 SelectObject (hdcImage, hOldBitmapLoad);
4185 SelectObject (hdcBitmap, hOldBitmapBitmap);
4186 DeleteDC (hdcImage);
4187 DeleteDC (hdcBitmap);
4189 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4190 nNewBitmaps = ImageList_GetImageCount(himlDef);
4191 DeleteObject (hbmLoad);
4194 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4196 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4197 pos, nOldBitmaps, nNewBitmaps);
4199 InvalidateRect(hwnd, NULL, TRUE);
4205 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4209 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4211 if (lpSave == NULL) return 0;
4214 /* save toolbar information */
4215 FIXME("save to \"%s\" \"%s\"\n",
4216 lpSave->pszSubKey, lpSave->pszValueName);
4221 /* restore toolbar information */
4223 FIXME("restore from \"%s\" \"%s\"\n",
4224 lpSave->pszSubKey, lpSave->pszValueName);
4235 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4238 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4239 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4245 /* save toolbar information */
4246 FIXME("save to \"%s\" \"%s\"\n",
4247 lpSave->pszSubKey, lpSave->pszValueName);
4252 /* restore toolbar information */
4254 FIXME("restore from \"%s\" \"%s\"\n",
4255 lpSave->pszSubKey, lpSave->pszValueName);
4266 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4268 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4269 BOOL bOldAnchor = infoPtr->bAnchor;
4271 TRACE("hwnd=%p, bAnchor = %s\n", hwnd, wParam ? "TRUE" : "FALSE");
4273 infoPtr->bAnchor = (BOOL)wParam;
4275 if (!infoPtr->bAnchor)
4276 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_OTHER);
4278 return (LRESULT)bOldAnchor;
4283 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4286 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4288 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4291 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4293 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4296 if (infoPtr->nNumButtons > 0)
4297 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4298 infoPtr->nNumButtons,
4299 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4300 LOWORD(lParam), HIWORD(lParam));
4302 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4303 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4306 if ((himlDef == infoPtr->himlInt) &&
4307 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4309 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4310 infoPtr->nBitmapHeight);
4318 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4320 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4321 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4322 TBUTTON_INFO *btnPtr;
4328 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4332 lptbbi->dwMask & 0x80000000);
4336 btnPtr = &infoPtr->buttons[nIndex];
4337 if (lptbbi->dwMask & TBIF_COMMAND)
4338 btnPtr->idCommand = lptbbi->idCommand;
4339 if (lptbbi->dwMask & TBIF_IMAGE)
4340 btnPtr->iBitmap = lptbbi->iImage;
4341 if (lptbbi->dwMask & TBIF_LPARAM)
4342 btnPtr->dwData = lptbbi->lParam;
4343 if (lptbbi->dwMask & TBIF_SIZE)
4344 btnPtr->cx = lptbbi->cx;
4345 if (lptbbi->dwMask & TBIF_STATE)
4346 btnPtr->fsState = lptbbi->fsState;
4347 if (lptbbi->dwMask & TBIF_STYLE)
4348 btnPtr->fsStyle = lptbbi->fsStyle;
4350 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4351 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4352 /* iString is index, zero it to make Str_SetPtr succeed */
4355 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4358 /* save the button rect to see if we need to redraw the whole toolbar */
4359 oldBtnRect = btnPtr->rect;
4360 TOOLBAR_CalcToolbar(hwnd);
4362 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4363 InvalidateRect(hwnd, NULL, TRUE);
4365 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4372 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4374 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4375 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4376 TBUTTON_INFO *btnPtr;
4382 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4385 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4386 lptbbi->dwMask & 0x80000000);
4390 btnPtr = &infoPtr->buttons[nIndex];
4391 if (lptbbi->dwMask & TBIF_COMMAND)
4392 btnPtr->idCommand = lptbbi->idCommand;
4393 if (lptbbi->dwMask & TBIF_IMAGE)
4394 btnPtr->iBitmap = lptbbi->iImage;
4395 if (lptbbi->dwMask & TBIF_LPARAM)
4396 btnPtr->dwData = lptbbi->lParam;
4397 if (lptbbi->dwMask & TBIF_SIZE)
4398 btnPtr->cx = lptbbi->cx;
4399 if (lptbbi->dwMask & TBIF_STATE)
4400 btnPtr->fsState = lptbbi->fsState;
4401 if (lptbbi->dwMask & TBIF_STYLE)
4402 btnPtr->fsStyle = lptbbi->fsStyle;
4404 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4405 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4406 /* iString is index, zero it to make Str_SetPtr succeed */
4408 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4411 /* save the button rect to see if we need to redraw the whole toolbar */
4412 oldBtnRect = btnPtr->rect;
4413 TOOLBAR_CalcToolbar(hwnd);
4415 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4416 InvalidateRect(hwnd, NULL, TRUE);
4418 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4425 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4428 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4430 if ((cx < 0) || (cy < 0))
4432 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4436 /* The documentation claims you can only change the button size before
4437 * any button has been added. But this is wrong.
4438 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4439 * it to the toolbar, and it checks that the return value is nonzero - mjm
4440 * Further testing shows that we must actually perform the change too.
4443 * The documentation also does not mention that if 0 is supplied for
4444 * either size, the system changes it to the default of 24 wide and
4445 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4447 infoPtr->nButtonWidth = (cx) ? cx : 24;
4448 infoPtr->nButtonHeight = (cy) ? cy : 22;
4454 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4456 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4458 if (infoPtr == NULL) {
4459 TRACE("Toolbar not initialized yet?????\n");
4463 /* if setting to current values, ignore */
4464 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4465 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4466 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4467 infoPtr->cxMin, infoPtr->cxMax);
4471 /* save new values */
4472 infoPtr->cxMin = (INT)LOWORD(lParam);
4473 infoPtr->cxMax = (INT)HIWORD(lParam);
4475 /* if both values are 0 then we are done */
4477 TRACE("setting both min and max to 0, norecalc\n");
4481 /* otherwise we need to recalc the toolbar and in some cases
4482 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4483 which doesn't actually draw - GA). */
4484 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4485 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4487 TOOLBAR_CalcToolbar (hwnd);
4489 InvalidateRect (hwnd, NULL, TRUE);
4496 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4498 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4499 INT nIndex = (INT)wParam;
4501 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4504 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4506 if (infoPtr->hwndToolTip) {
4508 FIXME("change tool tip!\n");
4517 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4520 HIMAGELIST himl = (HIMAGELIST)lParam;
4521 HIMAGELIST himlTemp;
4524 if (infoPtr->iVersion >= 5)
4527 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4528 &infoPtr->cimlDis, himl, id);
4530 /* FIXME: redraw ? */
4532 return (LRESULT)himlTemp;
4537 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4542 dwTemp = infoPtr->dwDTFlags;
4543 infoPtr->dwDTFlags =
4544 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4546 return (LRESULT)dwTemp;
4549 /* This function differs a bit from what MSDN says it does:
4550 * 1. lParam contains extended style flags to OR with current style
4551 * (MSDN isn't clear on the OR bit)
4552 * 2. wParam appears to contain extended style flags to be reset
4553 * (MSDN says that this parameter is reserved)
4556 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4558 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4561 dwTemp = infoPtr->dwExStyle;
4562 infoPtr->dwExStyle &= ~wParam;
4563 infoPtr->dwExStyle |= (DWORD)lParam;
4565 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4567 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4568 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4569 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4571 TOOLBAR_CalcToolbar (hwnd);
4573 TOOLBAR_AutoSize(hwnd);
4575 InvalidateRect(hwnd, NULL, TRUE);
4577 return (LRESULT)dwTemp;
4582 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4585 HIMAGELIST himlTemp;
4586 HIMAGELIST himl = (HIMAGELIST)lParam;
4589 if (infoPtr->iVersion >= 5)
4592 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4594 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4595 &infoPtr->cimlHot, himl, id);
4597 /* FIXME: redraw ? */
4599 return (LRESULT)himlTemp;
4603 /* Makes previous hot button no longer hot, makes the specified
4604 * button hot and sends appropriate notifications. dwReason is one or
4605 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4606 * NOTE 1: this function does not validate nHit
4607 * NOTE 2: the name of this function is completely made up and
4608 * not based on any documentation from Microsoft. */
4610 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4612 if (infoPtr->nHotItem != nHit)
4614 NMTBHOTITEM nmhotitem;
4615 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4616 LRESULT no_highlight;
4618 if (nHit == TOOLBAR_NOWHERE && infoPtr->bAnchor)
4621 /* Remove the effect of an old hot button if the button was
4622 drawn with the hot button effect */
4623 if(infoPtr->nHotItem >= 0)
4625 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4626 oldBtnPtr->bHot = FALSE;
4629 infoPtr->nHotItem = nHit;
4631 /* It's not a separator or in nowhere. It's a hot button. */
4633 btnPtr = &infoPtr->buttons[nHit];
4635 nmhotitem.dwFlags = dwReason;
4637 nmhotitem.idOld = oldBtnPtr->idCommand;
4639 nmhotitem.dwFlags |= HICF_ENTERING;
4641 nmhotitem.idNew = btnPtr->idCommand;
4643 nmhotitem.dwFlags |= HICF_LEAVING;
4645 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4647 /* now invalidate the old and new buttons so they will be painted */
4649 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4650 if (btnPtr && !no_highlight)
4652 btnPtr->bHot = TRUE;
4653 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4659 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4662 INT nOldHotItem = infoPtr->nHotItem;
4664 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4667 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4668 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4670 if (nOldHotItem < 0)
4673 return (LRESULT)nOldHotItem;
4678 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4681 HIMAGELIST himlTemp;
4682 HIMAGELIST himl = (HIMAGELIST)lParam;
4685 if (infoPtr->iVersion >= 5)
4688 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4689 &infoPtr->cimlDef, himl, id);
4691 infoPtr->nNumBitmaps = 0;
4692 for (i = 0; i < infoPtr->cimlDef; i++)
4693 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4695 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4696 &infoPtr->nBitmapHeight);
4697 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4698 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4699 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4701 InvalidateRect(hwnd, NULL, TRUE);
4703 return (LRESULT)himlTemp;
4708 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4712 infoPtr->nIndent = (INT)wParam;
4716 /* process only on indent changing */
4717 if(infoPtr->nIndent != (INT)wParam)
4719 infoPtr->nIndent = (INT)wParam;
4720 TOOLBAR_CalcToolbar (hwnd);
4721 InvalidateRect(hwnd, NULL, FALSE);
4729 TOOLBAR_SetInsertMark (HWND hwnd, WPARAM wParam, LPARAM lParam)
4731 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4732 TBINSERTMARK *lptbim = (TBINSERTMARK*)lParam;
4734 TRACE("hwnd = %p, lptbim = { %d, 0x%08lx}\n", hwnd, lptbim->iButton, lptbim->dwFlags);
4736 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4738 FIXME("Unrecognized flag(s): 0x%08lx\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4742 if ((lptbim->iButton == -1) ||
4743 ((lptbim->iButton < infoPtr->nNumButtons) &&
4744 (lptbim->iButton >= 0)))
4746 infoPtr->tbim = *lptbim;
4747 /* FIXME: don't need to update entire toolbar */
4748 InvalidateRect(hwnd, NULL, TRUE);
4751 ERR("Invalid button index %d\n", lptbim->iButton);
4758 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4762 infoPtr->clrInsertMark = (COLORREF)lParam;
4764 /* FIXME: don't need to update entire toolbar */
4765 InvalidateRect(hwnd, NULL, TRUE);
4772 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4774 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4776 if (infoPtr == NULL)
4779 infoPtr->nMaxTextRows = (INT)wParam;
4781 TOOLBAR_CalcToolbar(hwnd);
4786 /* MSDN gives slightly wrong info on padding.
4787 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4788 * 2. It is not used to create a blank area between the edge of the button
4789 * and the text or image if TBSTYLE_LIST is set. It is used to control
4790 * the gap between the image and text.
4791 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4792 * to control the bottom and right borders [with the border being
4793 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4794 * is shared evenly on both sides of the button.
4797 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4802 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4803 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4804 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4805 TRACE("cx=%ld, cy=%ld\n",
4806 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4807 return (LRESULT) oldPad;
4812 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4814 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4819 if (infoPtr == NULL)
4821 hwndOldNotify = infoPtr->hwndNotify;
4822 infoPtr->hwndNotify = (HWND)wParam;
4824 return (LRESULT)hwndOldNotify;
4829 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4832 LPRECT lprc = (LPRECT)lParam;
4836 if (LOWORD(wParam) > 1) {
4837 FIXME("multiple rows not supported!\n");
4840 if(infoPtr->nRows != LOWORD(wParam))
4842 infoPtr->nRows = LOWORD(wParam);
4844 /* recalculate toolbar */
4845 TOOLBAR_CalcToolbar (hwnd);
4847 /* repaint toolbar */
4848 InvalidateRect(hwnd, NULL, TRUE);
4851 /* return bounding rectangle */
4853 lprc->left = infoPtr->rcBound.left;
4854 lprc->right = infoPtr->rcBound.right;
4855 lprc->top = infoPtr->rcBound.top;
4856 lprc->bottom = infoPtr->rcBound.bottom;
4864 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4867 TBUTTON_INFO *btnPtr;
4870 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4874 btnPtr = &infoPtr->buttons[nIndex];
4876 /* if hidden state has changed the invalidate entire window and recalc */
4877 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4878 btnPtr->fsState = LOWORD(lParam);
4879 TOOLBAR_CalcToolbar (hwnd);
4880 InvalidateRect(hwnd, 0, TRUE);
4884 /* process state changing if current state doesn't match new state */
4885 if(btnPtr->fsState != LOWORD(lParam))
4887 btnPtr->fsState = LOWORD(lParam);
4888 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4896 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4898 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4904 inline static LRESULT
4905 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4909 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4911 if (infoPtr == NULL)
4913 infoPtr->hwndToolTip = (HWND)wParam;
4919 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4924 TRACE("%s hwnd=%p stub!\n",
4925 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4927 bTemp = infoPtr->bUnicode;
4928 infoPtr->bUnicode = (BOOL)wParam;
4935 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4939 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4940 comctl32_color.clrBtnHighlight :
4941 infoPtr->clrBtnHighlight;
4942 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4943 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4949 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4951 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4953 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4954 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4955 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4957 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4958 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4959 InvalidateRect(hwnd, NULL, TRUE);
4965 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4967 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4968 INT iOldVersion = infoPtr->iVersion;
4970 infoPtr->iVersion = iVersion;
4972 if (infoPtr->iVersion >= 5)
4973 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4980 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4982 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4983 WORD iString = HIWORD(wParam);
4984 WORD buffersize = LOWORD(wParam);
4985 LPSTR str = (LPSTR)lParam;
4988 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4990 if (iString < infoPtr->nNumStrings)
4992 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4994 TRACE("returning %s\n", debugstr_a(str));
4997 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5004 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
5006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5007 WORD iString = HIWORD(wParam);
5008 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5009 LPWSTR str = (LPWSTR)lParam;
5012 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
5014 if (iString < infoPtr->nNumStrings)
5016 len = min(len, strlenW(infoPtr->strings[iString]));
5017 ret = (len+1)*sizeof(WCHAR);
5018 memcpy(str, infoPtr->strings[iString], ret);
5021 TRACE("returning %s\n", debugstr_w(str));
5024 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5029 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5030 * is the maximum size of the toolbar? */
5031 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5033 SIZE * pSize = (SIZE*)lParam;
5034 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5039 /* UNDOCUMENTED MESSAGE: This is an extended version of the
5040 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
5041 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
5044 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
5046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5047 INT nOldHotItem = infoPtr->nHotItem;
5049 TRACE("old item=%d, new item=%d, flags=%08lx\n",
5050 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
5052 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
5055 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
5059 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5062 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
5063 * which controls the amount of spacing between the image and the text
5064 * of buttons for TBSTYLE_LIST toolbars. */
5065 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
5067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5069 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5072 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5074 infoPtr->iListGap = (INT)wParam;
5076 TOOLBAR_CalcToolbar(hwnd);
5077 InvalidateRect(hwnd, NULL, TRUE);
5082 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5083 * of image lists associated with the various states. */
5084 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5088 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5090 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5094 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5096 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5097 LPSIZE lpsize = (LPSIZE)lParam;
5103 * Testing shows the following:
5104 * wParam = 0 adjust cx value
5105 * = 1 set cy value to max size.
5106 * lParam pointer to SIZE structure
5109 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5110 wParam, lParam, lpsize->cx, lpsize->cy);
5114 if (lpsize->cx == -1) {
5115 /* **** this is wrong, native measures each button and sets it */
5116 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5118 else if(HIWORD(lpsize->cx)) {
5120 HWND hwndParent = GetParent(hwnd);
5122 GetWindowRect(hwnd, &rc);
5123 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5124 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5125 rc.left, rc.top, rc.right, rc.bottom);
5126 lpsize->cx = max(rc.right-rc.left,
5127 infoPtr->rcBound.right - infoPtr->rcBound.left);
5130 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5134 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5135 /* lpsize->cy = infoPtr->nHeight; */
5138 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5142 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5143 lpsize->cx, lpsize->cy);
5147 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5149 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5151 InvalidateRect(hwnd, NULL, TRUE);
5157 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5160 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5163 TRACE("hwnd = %p\n", hwnd);
5165 /* initialize info structure */
5166 infoPtr->nButtonHeight = 22;
5167 infoPtr->nButtonWidth = 24;
5168 infoPtr->nBitmapHeight = 15;
5169 infoPtr->nBitmapWidth = 16;
5171 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5172 infoPtr->nMaxTextRows = 1;
5173 infoPtr->cxMin = -1;
5174 infoPtr->cxMax = -1;
5175 infoPtr->nNumBitmaps = 0;
5176 infoPtr->nNumStrings = 0;
5178 infoPtr->bCaptured = FALSE;
5179 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5180 infoPtr->nButtonDown = -1;
5181 infoPtr->nButtonDrag = -1;
5182 infoPtr->nOldHit = -1;
5183 infoPtr->nHotItem = -1;
5184 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5185 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5186 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5187 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5188 infoPtr->bDragOutSent = FALSE;
5189 infoPtr->iVersion = 0;
5190 infoPtr->hwndSelf = hwnd;
5191 infoPtr->bDoRedraw = TRUE;
5192 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5193 infoPtr->clrBtnShadow = CLR_DEFAULT;
5194 /* not sure where the +1 comes from, but this comes to the same value
5195 * as native so this is probably correct */
5196 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5197 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5198 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5199 infoPtr->dwStyle = dwStyle;
5200 infoPtr->tbim.iButton = -1;
5201 GetClientRect(hwnd, &infoPtr->client_rect);
5202 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5204 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5205 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5207 if (dwStyle & TBSTYLE_TOOLTIPS) {
5208 /* Create tooltip control */
5209 infoPtr->hwndToolTip =
5210 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5211 CW_USEDEFAULT, CW_USEDEFAULT,
5212 CW_USEDEFAULT, CW_USEDEFAULT,
5215 /* Send NM_TOOLTIPSCREATED notification */
5216 if (infoPtr->hwndToolTip) {
5217 NMTOOLTIPSCREATED nmttc;
5219 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5221 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5222 NM_TOOLTIPSCREATED);
5226 TOOLBAR_CheckStyle (hwnd, dwStyle);
5228 TOOLBAR_CalcToolbar(hwnd);
5235 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5239 /* delete tooltip control */
5240 if (infoPtr->hwndToolTip)
5241 DestroyWindow (infoPtr->hwndToolTip);
5243 /* delete temporary buffer for tooltip text */
5244 if (infoPtr->pszTooltipText)
5245 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5247 /* delete button data */
5248 if (infoPtr->buttons)
5249 Free (infoPtr->buttons);
5251 /* delete strings */
5252 if (infoPtr->strings) {
5254 for (i = 0; i < infoPtr->nNumStrings; i++)
5255 if (infoPtr->strings[i])
5256 Free (infoPtr->strings[i]);
5258 Free (infoPtr->strings);
5261 /* destroy internal image list */
5262 if (infoPtr->himlInt)
5263 ImageList_Destroy (infoPtr->himlInt);
5265 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5266 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5267 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5269 /* delete default font */
5271 DeleteObject (infoPtr->hDefaultFont);
5273 /* free toolbar info data */
5275 SetWindowLongPtrW (hwnd, 0, 0);
5282 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5285 NMTBCUSTOMDRAW tbcd;
5289 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5290 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5291 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5292 tbcd.nmcd.hdc = (HDC)wParam;
5293 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5294 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5296 /* FIXME: in general the return flags *can* be or'ed together */
5297 switch (infoPtr->dwBaseCustDraw)
5299 case CDRF_DODEFAULT:
5301 case CDRF_SKIPDEFAULT:
5304 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5309 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5310 * to my parent for processing.
5312 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5314 HDC hdc = (HDC)wParam;
5319 parent = GetParent(hwnd);
5320 MapWindowPoints(hwnd, parent, &pt, 1);
5321 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5322 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5323 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5326 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5328 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5329 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5330 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5331 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5332 tbcd.nmcd.hdc = (HDC)wParam;
5333 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5334 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5335 switch (infoPtr->dwBaseCustDraw)
5337 case CDRF_DODEFAULT:
5339 case CDRF_SKIPDEFAULT:
5342 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5351 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5355 return (LRESULT)infoPtr->hFont;
5360 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5365 pt.x = (INT)LOWORD(lParam);
5366 pt.y = (INT)HIWORD(lParam);
5367 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5370 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5371 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5372 TOOLBAR_Customize (hwnd);
5379 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5382 TBUTTON_INFO *btnPtr;
5386 BOOL bDragKeyPressed;
5390 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5391 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5393 bDragKeyPressed = (wParam & MK_SHIFT);
5395 if (infoPtr->hwndToolTip)
5396 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5397 WM_LBUTTONDOWN, wParam, lParam);
5399 pt.x = (INT)LOWORD(lParam);
5400 pt.y = (INT)HIWORD(lParam);
5401 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5403 btnPtr = &infoPtr->buttons[nHit];
5405 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5407 infoPtr->nButtonDrag = nHit;
5410 /* If drag cursor has not been loaded, load it.
5411 * Note: it doesn't need to be freed */
5413 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5414 SetCursor(hCursorDrag);
5419 infoPtr->nOldHit = nHit;
5421 CopyRect(&arrowRect, &btnPtr->rect);
5422 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5424 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5425 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5426 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5427 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5428 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5429 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5433 /* draw in pressed state */
5434 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5435 btnPtr->fsState |= TBSTATE_PRESSED;
5437 btnPtr->bDropDownPressed = TRUE;
5438 RedrawWindow(hwnd,&btnPtr->rect,0,
5439 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5441 nmtb.iItem = btnPtr->idCommand;
5442 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5445 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5446 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5448 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5450 if (res != TBDDRET_TREATPRESSED)
5454 /* redraw button in unpressed state */
5455 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5456 btnPtr->fsState &= ~TBSTATE_PRESSED;
5458 btnPtr->bDropDownPressed = FALSE;
5459 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5461 /* find and set hot item
5462 * NOTE: native doesn't do this, but that is a bug */
5464 ScreenToClient(hwnd, &pt);
5465 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5466 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5468 /* remove any left mouse button down or double-click messages
5469 * so that we can get a toggle effect on the button */
5470 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5471 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5476 /* otherwise drop through and process as pushed */
5478 infoPtr->bCaptured = TRUE;
5479 infoPtr->nButtonDown = nHit;
5480 infoPtr->bDragOutSent = FALSE;
5482 btnPtr->fsState |= TBSTATE_PRESSED;
5484 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5486 if (btnPtr->fsState & TBSTATE_ENABLED)
5487 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5494 nmtb.iItem = btnPtr->idCommand;
5495 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5496 nmtb.tbButton.idCommand = btnPtr->idCommand;
5497 nmtb.tbButton.fsState = btnPtr->fsState;
5498 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5499 nmtb.tbButton.dwData = btnPtr->dwData;
5500 nmtb.tbButton.iString = btnPtr->iString;
5501 nmtb.cchText = 0; /* !!! not correct */
5502 nmtb.pszText = 0; /* !!! not correct */
5503 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5510 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5512 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5513 TBUTTON_INFO *btnPtr;
5517 BOOL bSendMessage = TRUE;
5522 if (infoPtr->hwndToolTip)
5523 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5524 WM_LBUTTONUP, wParam, lParam);
5526 pt.x = (INT)LOWORD(lParam);
5527 pt.y = (INT)HIWORD(lParam);
5528 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5530 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5532 if (infoPtr->nButtonDrag >= 0) {
5536 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5539 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5541 GetClientRect(hwnd, &rcClient);
5542 if (PtInRect(&rcClient, pt))
5549 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5552 if (nButton == infoPtr->nButtonDrag)
5554 /* if the button is moved sightly left and we have a
5555 * separator there then remove it */
5556 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5558 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5559 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5561 else /* else insert a separator before the dragged button */
5564 memset(&tbb, 0, sizeof(tbb));
5565 tbb.fsStyle = BTNS_SEP;
5567 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5574 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5575 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5577 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5580 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5585 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5586 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5589 /* button under cursor changed so need to re-set hot item */
5590 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5591 infoPtr->nButtonDrag = -1;
5593 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5595 else if (infoPtr->nButtonDown >= 0) {
5596 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5597 btnPtr->fsState &= ~TBSTATE_PRESSED;
5599 if (btnPtr->fsStyle & BTNS_CHECK) {
5600 if (btnPtr->fsStyle & BTNS_GROUP) {
5601 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5603 if (nOldIndex == nHit)
5604 bSendMessage = FALSE;
5605 if ((nOldIndex != nHit) &&
5607 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5608 btnPtr->fsState |= TBSTATE_CHECKED;
5611 if (btnPtr->fsState & TBSTATE_CHECKED)
5612 btnPtr->fsState &= ~TBSTATE_CHECKED;
5614 btnPtr->fsState |= TBSTATE_CHECKED;
5618 if (nOldIndex != -1)
5619 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5622 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5623 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5624 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5626 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5628 infoPtr->nButtonDown = -1;
5630 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5631 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5632 NM_RELEASEDCAPTURE);
5634 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5637 nmtb.iItem = btnPtr->idCommand;
5638 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5639 nmtb.tbButton.idCommand = btnPtr->idCommand;
5640 nmtb.tbButton.fsState = btnPtr->fsState;
5641 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5642 nmtb.tbButton.dwData = btnPtr->dwData;
5643 nmtb.tbButton.iString = btnPtr->iString;
5644 nmtb.cchText = 0; /* !!! not correct */
5645 nmtb.pszText = 0; /* !!! not correct */
5646 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5649 if (btnPtr->fsState & TBSTATE_ENABLED)
5651 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5652 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5654 /* !!! Undocumented - toolbar at 4.71 level and above sends
5655 * either NM_RCLICK or NM_CLICK with the NMMOUSE structure.
5656 * Only NM_RCLICK is documented.
5658 nmmouse.dwItemSpec = btnPtr->idCommand;
5659 nmmouse.dwItemData = btnPtr->dwData;
5660 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5667 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5669 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5674 pt.x = LOWORD(lParam);
5675 pt.y = HIWORD(lParam);
5677 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5679 if (nmmouse.dwHitInfo < 0) {
5680 nmmouse.dwItemSpec = -1;
5682 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5683 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5686 ClientToScreen(hwnd, &pt);
5687 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5689 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5695 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5697 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5702 pt.x = LOWORD(lParam);
5703 pt.y = HIWORD(lParam);
5705 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5707 if (nmmouse.dwHitInfo < 0)
5708 nmmouse.dwItemSpec = -1;
5710 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5711 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5714 ClientToScreen(hwnd, &pt);
5715 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5717 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RDBLCLK);
5723 TOOLBAR_CaptureChanged(HWND hwnd)
5725 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5726 TBUTTON_INFO *btnPtr;
5728 infoPtr->bCaptured = FALSE;
5730 if (infoPtr->nButtonDown >= 0)
5732 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5733 btnPtr->fsState &= ~TBSTATE_PRESSED;
5735 infoPtr->nOldHit = -1;
5737 if (btnPtr->fsState & TBSTATE_ENABLED)
5738 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5744 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5747 TBUTTON_INFO *hotBtnPtr;
5749 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5751 /* don't remove hot effects when in drop-down */
5752 if (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed)
5753 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5755 if (infoPtr->nOldHit < 0)
5758 /* If the last button we were over is depressed then make it not */
5759 /* depressed and redraw it */
5760 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5762 TBUTTON_INFO *btnPtr;
5765 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5767 btnPtr->fsState &= ~TBSTATE_PRESSED;
5769 rc1 = hotBtnPtr->rect;
5770 InflateRect (&rc1, 1, 1);
5771 InvalidateRect (hwnd, &rc1, TRUE);
5774 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5777 ZeroMemory(&nmt, sizeof(nmt));
5778 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5779 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5780 infoPtr->bDragOutSent = TRUE;
5783 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5789 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5793 TRACKMOUSEEVENT trackinfo;
5795 TBUTTON_INFO *btnPtr;
5797 /* fill in the TRACKMOUSEEVENT struct */
5798 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5799 trackinfo.dwFlags = TME_QUERY;
5800 trackinfo.hwndTrack = hwnd;
5801 trackinfo.dwHoverTime = HOVER_DEFAULT;
5803 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5804 _TrackMouseEvent(&trackinfo);
5806 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5807 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5808 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5810 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5811 /* and can properly deactivate the hot toolbar button */
5812 _TrackMouseEvent(&trackinfo);
5815 if (infoPtr->hwndToolTip)
5816 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5817 WM_MOUSEMOVE, wParam, lParam);
5819 pt.x = (INT)LOWORD(lParam);
5820 pt.y = (INT)HIWORD(lParam);
5822 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5824 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5826 if (infoPtr->nOldHit != nHit)
5828 if (infoPtr->bCaptured)
5830 if (!infoPtr->bDragOutSent)
5833 ZeroMemory(&nmt, sizeof(nmt));
5834 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5835 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5836 infoPtr->bDragOutSent = TRUE;
5839 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5840 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5841 btnPtr->fsState &= ~TBSTATE_PRESSED;
5842 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5844 else if (nHit == infoPtr->nButtonDown) {
5845 btnPtr->fsState |= TBSTATE_PRESSED;
5846 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5848 infoPtr->nOldHit = nHit;
5856 inline static LRESULT
5857 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5859 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5860 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5862 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5866 inline static LRESULT
5867 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5869 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5870 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5872 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5877 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5879 TOOLBAR_INFO *infoPtr;
5880 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5883 /* allocate memory for info structure */
5884 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5885 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5888 infoPtr->dwStructSize = sizeof(TBBUTTON);
5891 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5892 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5893 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5894 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5897 /* native control does:
5898 * Get a lot of colors and brushes
5900 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5901 * CreateFontIndirectA(adr1)
5902 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5903 * hdc = GetDC(toolbar)
5904 * GetSystemMetrics(0x48)
5905 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5906 * 0, 0, 0, 0, "MARLETT")
5907 * oldfnt = SelectObject(hdc, fnt2)
5908 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5909 * GetTextMetricsA(hdc, adr3)
5910 * SelectObject(hdc, oldfnt)
5911 * DeleteObject(fnt2)
5913 * InvalidateRect(toolbar, 0, 1)
5914 * SetWindowLongA(toolbar, 0, addr)
5915 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5918 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5919 * ie 2 0x4600094c 0x4600094c 0x4600894d
5920 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5921 * rebar 0x50008844 0x40008844 0x50008845
5922 * pager 0x50000844 0x40000844 0x50008845
5923 * IC35mgr 0x5400084e **nochange**
5924 * on entry to _NCCREATE 0x5400084e
5925 * rowlist 0x5400004e **nochange**
5926 * on entry to _NCCREATE 0x5400004e
5930 /* I think the code below is a bug, but it is the way that the native
5931 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5932 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5933 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5934 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5935 * Some how, the only cases of this seem to be MFC programs.
5937 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5938 * does not occur in the WM_STYLECHANGING routine.
5939 * (Guy Albertelli 9/2001)
5942 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5943 styleadd |= TBSTYLE_TRANSPARENT;
5944 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5945 styleadd |= CCS_TOP; /* default to top */
5946 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5949 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5954 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5956 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5960 if (dwStyle & WS_MINIMIZE)
5961 return 0; /* Nothing to do */
5963 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5965 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5968 if (!(dwStyle & CCS_NODIVIDER))
5970 GetWindowRect (hwnd, &rcWindow);
5971 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5972 if( dwStyle & WS_BORDER )
5973 OffsetRect (&rcWindow, 1, 1);
5974 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5977 ReleaseDC( hwnd, hdc );
5983 /* handles requests from the tooltip control on what text to display */
5984 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5986 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5988 TRACE("button index = %d\n", index);
5990 if (infoPtr->pszTooltipText)
5992 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5993 infoPtr->pszTooltipText = NULL;
5999 if (infoPtr->bNtfUnicode)
6001 WCHAR wszBuffer[INFOTIPSIZE+1];
6002 NMTBGETINFOTIPW tbgit;
6003 int len; /* in chars */
6005 wszBuffer[0] = '\0';
6006 wszBuffer[INFOTIPSIZE] = '\0';
6008 tbgit.pszText = wszBuffer;
6009 tbgit.cchTextMax = INFOTIPSIZE;
6010 tbgit.iItem = lpnmtdi->hdr.idFrom;
6011 tbgit.lParam = infoPtr->buttons[index].dwData;
6013 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6015 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6017 len = strlenW(tbgit.pszText);
6018 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6020 /* need to allocate temporary buffer in infoPtr as there
6021 * isn't enough space in buffer passed to us by the
6022 * tooltip control */
6023 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6024 if (infoPtr->pszTooltipText)
6026 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6027 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6033 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6039 CHAR szBuffer[INFOTIPSIZE+1];
6040 NMTBGETINFOTIPA tbgit;
6041 int len; /* in chars */
6044 szBuffer[INFOTIPSIZE] = '\0';
6046 tbgit.pszText = szBuffer;
6047 tbgit.cchTextMax = INFOTIPSIZE;
6048 tbgit.iItem = lpnmtdi->hdr.idFrom;
6049 tbgit.lParam = infoPtr->buttons[index].dwData;
6051 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6053 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6055 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6056 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6058 /* need to allocate temporary buffer in infoPtr as there
6059 * isn't enough space in buffer passed to us by the
6060 * tooltip control */
6061 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6062 if (infoPtr->pszTooltipText)
6064 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
6065 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6071 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6076 /* if button has text, but it is not shown then automatically
6077 * use that text as tooltip */
6078 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6079 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6081 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6082 int len = pszText ? strlenW(pszText) : 0;
6084 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6086 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6088 /* need to allocate temporary buffer in infoPtr as there
6089 * isn't enough space in buffer passed to us by the
6090 * tooltip control */
6091 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6092 if (infoPtr->pszTooltipText)
6094 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6095 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6101 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6106 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6108 /* last resort: send notification on to app */
6109 /* FIXME: find out what is really used here */
6110 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6114 inline static LRESULT
6115 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6118 LPNMHDR lpnmh = (LPNMHDR)lParam;
6120 switch (lpnmh->code)
6124 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6126 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6127 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6128 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6132 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6133 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6141 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6143 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6144 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6145 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6146 lppgs->iScroll, lppgs->iDir);
6150 case TTN_GETDISPINFOW:
6151 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6153 case TTN_GETDISPINFOA:
6154 FIXME("TTN_GETDISPINFOA - stub\n");
6164 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6166 /* remove this routine when Toolbar is improved to pass infoPtr
6167 * around instead of hwnd.
6169 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6170 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6175 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6179 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6181 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6184 if (lParam == NF_REQUERY) {
6185 i = SendMessageA(infoPtr->hwndNotify,
6186 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6187 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6188 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6192 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6195 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6200 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6206 /* fill ps.rcPaint with a default rect */
6207 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6209 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6211 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6212 ps.rcPaint.left, ps.rcPaint.top,
6213 ps.rcPaint.right, ps.rcPaint.bottom);
6215 TOOLBAR_Refresh (hwnd, hdc, &ps);
6216 if (!wParam) EndPaint (hwnd, &ps);
6223 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6224 /*****************************************************
6227 * Handles the WM_SETREDRAW message.
6230 * According to testing V4.71 of COMCTL32 returns the
6231 * *previous* status of the redraw flag (either 0 or 1)
6232 * instead of the MSDN documented value of 0 if handled.
6233 * (For laughs see the "consistency" with same function
6236 *****************************************************/
6238 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6239 BOOL oldredraw = infoPtr->bDoRedraw;
6241 TRACE("set to %s\n",
6242 (wParam) ? "TRUE" : "FALSE");
6243 infoPtr->bDoRedraw = (BOOL) wParam;
6245 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6247 return (oldredraw) ? 1 : 0;
6252 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6254 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6255 DWORD dwStyle = infoPtr->dwStyle;
6264 /* Resize deadlock check */
6265 if (infoPtr->bAutoSize) {
6266 infoPtr->bAutoSize = FALSE;
6270 /* FIXME: optimize to only update size if the new size doesn't */
6271 /* match the current size */
6273 flags = (INT) wParam;
6275 /* FIXME for flags =
6276 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6279 TRACE("sizing toolbar!\n");
6281 if (flags == SIZE_RESTORED) {
6282 /* width and height don't apply */
6283 parent = GetParent (hwnd);
6284 GetClientRect(parent, &parent_rect);
6285 x = parent_rect.left;
6286 y = parent_rect.top;
6288 if (dwStyle & CCS_NORESIZE) {
6289 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6292 * this sets the working width of the toolbar, and
6293 * Calc Toolbar will not adjust it, only the height
6295 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6296 cy = infoPtr->nHeight;
6297 cx = infoPtr->nWidth;
6298 TOOLBAR_CalcToolbar (hwnd);
6299 infoPtr->nWidth = cx;
6300 infoPtr->nHeight = cy;
6303 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6304 TOOLBAR_CalcToolbar (hwnd);
6305 cy = infoPtr->nHeight;
6306 cx = infoPtr->nWidth;
6308 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6309 GetWindowRect(hwnd, &window_rect);
6310 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6311 y = window_rect.top;
6313 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6314 GetWindowRect(hwnd, &window_rect);
6315 y = parent_rect.bottom -
6316 ( window_rect.bottom - window_rect.top);
6320 if (dwStyle & CCS_NOPARENTALIGN) {
6321 uPosFlags |= SWP_NOMOVE;
6322 cy = infoPtr->nHeight;
6323 cx = infoPtr->nWidth;
6326 if (!(dwStyle & CCS_NODIVIDER))
6327 cy += GetSystemMetrics(SM_CYEDGE);
6329 if (dwStyle & WS_BORDER)
6332 cy += GetSystemMetrics(SM_CYEDGE);
6333 cx += GetSystemMetrics(SM_CYEDGE);
6336 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6338 RECT delta_width, delta_height, client, dummy;
6339 DWORD min_x, max_x, min_y, max_y;
6340 TBUTTON_INFO *btnPtr;
6343 GetClientRect(hwnd, &client);
6344 if(client.right > infoPtr->client_rect.right)
6346 min_x = infoPtr->client_rect.right;
6347 max_x = client.right;
6351 max_x = infoPtr->client_rect.right;
6352 min_x = client.right;
6354 if(client.bottom > infoPtr->client_rect.bottom)
6356 min_y = infoPtr->client_rect.bottom;
6357 max_y = client.bottom;
6361 max_y = infoPtr->client_rect.bottom;
6362 min_y = client.bottom;
6365 SetRect(&delta_width, min_x, 0, max_x, min_y);
6366 SetRect(&delta_height, 0, min_y, max_x, max_y);
6368 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6369 btnPtr = infoPtr->buttons;
6370 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6371 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6372 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6373 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6376 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6377 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6379 GetClientRect(hwnd, &infoPtr->client_rect);
6385 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6389 if (nType == GWL_STYLE) {
6390 if (lpStyle->styleNew & TBSTYLE_LIST) {
6391 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6394 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6396 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6397 (TBSTYLE_FLAT | TBSTYLE_LIST));
6398 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6400 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6402 infoPtr->dwStyle = lpStyle->styleNew;
6405 TOOLBAR_CalcToolbar(hwnd);
6407 TOOLBAR_AutoSize (hwnd);
6409 InvalidateRect(hwnd, NULL, TRUE);
6416 TOOLBAR_SysColorChange (HWND hwnd)
6418 COMCTL32_RefreshSysColors();
6425 static LRESULT WINAPI
6426 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6430 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6431 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6433 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6434 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6439 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6441 case TB_ADDBUTTONSA:
6442 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6444 case TB_ADDBUTTONSW:
6445 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6448 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6451 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6454 return TOOLBAR_AutoSize (hwnd);
6456 case TB_BUTTONCOUNT:
6457 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6459 case TB_BUTTONSTRUCTSIZE:
6460 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6462 case TB_CHANGEBITMAP:
6463 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6465 case TB_CHECKBUTTON:
6466 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6468 case TB_COMMANDTOINDEX:
6469 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6472 return TOOLBAR_Customize (hwnd);
6474 case TB_DELETEBUTTON:
6475 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6477 case TB_ENABLEBUTTON:
6478 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6480 case TB_GETANCHORHIGHLIGHT:
6481 return TOOLBAR_GetAnchorHighlight (hwnd);
6484 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6486 case TB_GETBITMAPFLAGS:
6487 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6490 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6492 case TB_GETBUTTONINFOA:
6493 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6495 case TB_GETBUTTONINFOW:
6496 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6498 case TB_GETBUTTONSIZE:
6499 return TOOLBAR_GetButtonSize (hwnd);
6501 case TB_GETBUTTONTEXTA:
6502 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6504 case TB_GETBUTTONTEXTW:
6505 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6507 case TB_GETDISABLEDIMAGELIST:
6508 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6510 case TB_GETEXTENDEDSTYLE:
6511 return TOOLBAR_GetExtendedStyle (hwnd);
6513 case TB_GETHOTIMAGELIST:
6514 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6517 return TOOLBAR_GetHotItem (hwnd);
6519 case TB_GETIMAGELIST:
6520 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6522 case TB_GETINSERTMARK:
6523 return TOOLBAR_GetInsertMark (hwnd, wParam, lParam);
6525 case TB_GETINSERTMARKCOLOR:
6526 return TOOLBAR_GetInsertMarkColor (hwnd, wParam, lParam);
6528 case TB_GETITEMRECT:
6529 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6532 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6534 /* case TB_GETOBJECT: */ /* 4.71 */
6537 return TOOLBAR_GetPadding (hwnd);
6540 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6543 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6546 return TOOLBAR_GetState (hwnd, wParam, lParam);
6549 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6552 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6555 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6557 case TB_GETTEXTROWS:
6558 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6560 case TB_GETTOOLTIPS:
6561 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6563 case TB_GETUNICODEFORMAT:
6564 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6567 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6570 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6572 case TB_INDETERMINATE:
6573 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6575 case TB_INSERTBUTTONA:
6576 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6578 case TB_INSERTBUTTONW:
6579 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6581 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6583 case TB_ISBUTTONCHECKED:
6584 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6586 case TB_ISBUTTONENABLED:
6587 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6589 case TB_ISBUTTONHIDDEN:
6590 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6592 case TB_ISBUTTONHIGHLIGHTED:
6593 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6595 case TB_ISBUTTONINDETERMINATE:
6596 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6598 case TB_ISBUTTONPRESSED:
6599 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6602 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6604 case TB_MAPACCELERATORA:
6605 case TB_MAPACCELERATORW:
6606 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6609 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6612 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6614 case TB_PRESSBUTTON:
6615 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6617 case TB_REPLACEBITMAP:
6618 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6620 case TB_SAVERESTOREA:
6621 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6623 case TB_SAVERESTOREW:
6624 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6626 case TB_SETANCHORHIGHLIGHT:
6627 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6629 case TB_SETBITMAPSIZE:
6630 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6632 case TB_SETBUTTONINFOA:
6633 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6635 case TB_SETBUTTONINFOW:
6636 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6638 case TB_SETBUTTONSIZE:
6639 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6641 case TB_SETBUTTONWIDTH:
6642 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6645 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6647 case TB_SETDISABLEDIMAGELIST:
6648 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6650 case TB_SETDRAWTEXTFLAGS:
6651 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6653 case TB_SETEXTENDEDSTYLE:
6654 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6656 case TB_SETHOTIMAGELIST:
6657 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6660 return TOOLBAR_SetHotItem (hwnd, wParam);
6662 case TB_SETIMAGELIST:
6663 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6666 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6668 case TB_SETINSERTMARK:
6669 return TOOLBAR_SetInsertMark (hwnd, wParam, lParam);
6671 case TB_SETINSERTMARKCOLOR:
6672 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6674 case TB_SETMAXTEXTROWS:
6675 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6678 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6681 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6684 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6687 return TOOLBAR_SetState (hwnd, wParam, lParam);
6690 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6692 case TB_SETTOOLTIPS:
6693 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6695 case TB_SETUNICODEFORMAT:
6696 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6699 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6702 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6705 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6708 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6711 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6714 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6716 /* Common Control Messages */
6718 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6719 case CCM_GETCOLORSCHEME:
6720 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6722 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6723 case CCM_SETCOLORSCHEME:
6724 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6726 case CCM_GETVERSION:
6727 return TOOLBAR_GetVersion (hwnd);
6729 case CCM_SETVERSION:
6730 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6736 return TOOLBAR_Create (hwnd, wParam, lParam);
6739 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6742 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6745 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6747 /* case WM_KEYDOWN: */
6748 /* case WM_KILLFOCUS: */
6750 case WM_LBUTTONDBLCLK:
6751 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6753 case WM_LBUTTONDOWN:
6754 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6757 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6760 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6762 case WM_RBUTTONDBLCLK:
6763 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6766 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6769 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6771 case WM_CAPTURECHANGED:
6772 return TOOLBAR_CaptureChanged(hwnd);
6775 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6778 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6781 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6784 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6787 return TOOLBAR_Notify (hwnd, wParam, lParam);
6789 case WM_NOTIFYFORMAT:
6790 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6793 return TOOLBAR_Paint (hwnd, wParam);
6796 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6799 return TOOLBAR_Size (hwnd, wParam, lParam);
6801 case WM_STYLECHANGED:
6802 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6804 case WM_SYSCOLORCHANGE:
6805 return TOOLBAR_SysColorChange (hwnd);
6807 /* case WM_WININICHANGE: */
6812 case WM_MEASUREITEM:
6814 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6816 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6817 case PGM_FORWARDMOUSE:
6818 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6821 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6822 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6823 uMsg, wParam, lParam);
6824 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6831 TOOLBAR_Register (void)
6835 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6836 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6837 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6838 wndClass.cbClsExtra = 0;
6839 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6840 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6841 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6842 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6844 RegisterClassA (&wndClass);
6849 TOOLBAR_Unregister (void)
6851 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6854 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6859 /* Check if the entry already exists */
6860 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6862 /* If this is a new entry we must create it and insert into the array */
6867 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6870 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6871 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6886 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6890 for (i = 0; i < *cies; i++)
6900 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6908 for (i = 0; i < cies; i++)
6910 if (pies[i]->id == id)
6922 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6924 HIMAGELIST himlDef = 0;
6925 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6928 himlDef = pie->himl;
6934 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6936 if (infoPtr->bUnicode)
6937 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6944 nmtba.iItem = nmtb->iItem;
6945 nmtba.pszText = Buffer;
6946 nmtba.cchText = 256;
6947 ZeroMemory(nmtba.pszText, nmtba.cchText);
6949 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6951 int ccht = strlen(nmtba.pszText);
6953 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6954 nmtb->pszText, nmtb->cchText);
6956 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6965 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6966 int iItem, PCUSTOMBUTTON btnInfo)
6971 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6973 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);