4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Differences between MSDN and actual native control operation:
24 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
25 * to the right of the bitmap. Otherwise, this style is
26 * identical to TBSTYLE_FLAT."
27 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
28 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
29 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
30 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
32 * This code was audited for completeness against the documented features
33 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
35 * Unless otherwise noted, we believe this code to be complete, as per
36 * the specification mentioned above.
37 * If you discover missing features or bugs please note them below.
40 * - Button wrapping (under construction).
43 * - TB_GETINSERTMARKCOLOR
46 * - TB_INSERTMARKHITTEST
56 * - TBN_DELETINGBUTTON
63 * - Fix TOOLBAR_SetButtonInfo32A/W.
64 * - iListGap custom draw support.
65 * - Customization dialog:
66 * - Minor buglet in 'available buttons' list:
67 * Buttons are not listed in MS-like order. MS seems to use a single
68 * internal list to store the button information of both listboxes.
69 * - Drag list support.
72 * - Run tests using Waite Group Windows95 API Bible Volume 2.
73 * The second cdrom contains executables addstr.exe, btncount.exe,
74 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
75 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
76 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
77 * setparnt.exe, setrows.exe, toolwnd.exe.
78 * - Microsofts controlspy examples.
79 * - Charles Petzold's 'Programming Windows': gadgets.exe
89 #include "wine/unicode.h"
92 #include "imagelist.h"
94 #include "wine/debug.h"
96 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
123 } IMLENTRY, *PIMLENTRY;
127 DWORD dwStructSize; /* size of TBBUTTON struct */
128 INT nHeight; /* height of the toolbar */
129 INT nWidth; /* width of the toolbar */
136 INT nRows; /* number of button rows */
137 INT nMaxTextRows; /* maximum number of text rows */
138 INT cxMin; /* minimum button width */
139 INT cxMax; /* maximum button width */
140 INT nNumButtons; /* number of buttons */
141 INT nNumBitmaps; /* number of bitmaps */
142 INT nNumStrings; /* number of strings */
144 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
145 BOOL bCaptured; /* mouse captured? */
148 INT nHotItem; /* index of the "hot" item */
149 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
150 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
151 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
152 SIZE szPadding; /* padding values around button */
153 INT iListGap; /* default gap between text and image for toolbar with list style */
155 HFONT hFont; /* text font */
156 HIMAGELIST himlInt; /* image list created internally */
157 PIMLENTRY *himlDef; /* default image list array */
158 INT cimlDef; /* default image list array count */
159 PIMLENTRY *himlHot; /* hot image list array */
160 INT cimlHot; /* hot image list array count */
161 PIMLENTRY *himlDis; /* disabled image list array */
162 INT cimlDis; /* disabled image list array count */
163 HWND hwndToolTip; /* handle to tool tip control */
164 HWND hwndNotify; /* handle to the window that gets notifications */
165 HWND hwndSelf; /* my own handle */
166 BOOL bTransparent; /* background transparency flag */
167 BOOL bBtnTranspnt; /* button transparency flag */
168 BOOL bAutoSize; /* auto size deadlock indicator */
169 BOOL bAnchor; /* anchor highlight enabled */
170 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
171 BOOL bDoRedraw; /* Redraw status */
172 DWORD dwExStyle; /* extended toolbar style */
173 DWORD dwDTFlags; /* DrawText flags */
175 COLORREF clrInsertMark; /* insert mark color */
176 COLORREF clrBtnHighlight; /* color for Flat Separator */
177 COLORREF clrBtnShadow; /* color for Flag Separator */
178 RECT rcBound; /* bounding rectangle */
180 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
181 * for TTN_GETDISPINFOW notification */
182 TBUTTON_INFO *buttons; /* pointer to button array */
183 LPWSTR *strings; /* pointer to string array */
184 TBITMAP_INFO *bitmaps;
185 } TOOLBAR_INFO, *PTOOLBAR_INFO;
188 /* used by customization dialog */
191 PTOOLBAR_INFO tbInfo;
193 } CUSTDLG_INFO, *PCUSTDLG_INFO;
201 } CUSTOMBUTTON, *PCUSTOMBUTTON;
210 #define SEPARATOR_WIDTH 8
212 #define BOTTOM_BORDER 2
213 #define DDARROW_WIDTH 11
214 #define ARROW_HEIGHT 3
216 /* gap between border of button and text/image */
219 /* how wide to treat the bitmap if it isn't present */
220 #define LIST_IMAGE_ABSENT_WIDTH 2
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
228 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
231 /* Used to find undocumented extended styles */
232 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
233 TBSTYLE_EX_UNDOC1 | \
234 TBSTYLE_EX_MIXEDBUTTONS | \
235 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
237 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
238 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
239 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
240 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
241 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
251 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
255 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
257 LPWSTR lpText = NULL;
259 /* FIXME: iString == -1 is undocumented */
260 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
261 lpText = (LPWSTR)btnPtr->iString;
262 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
263 lpText = infoPtr->strings[btnPtr->iString];
269 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
271 if (TRACE_ON(toolbar)){
272 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
273 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
274 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
275 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
277 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
278 btn_num, bP->idCommand,
279 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
280 bP->rect.left, bP->rect.top,
281 bP->rect.right, bP->rect.bottom);
287 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
289 if (TRACE_ON(toolbar)) {
293 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
294 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
296 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
297 iP->nNumStrings, dwStyle);
298 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
300 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
301 (iP->bDoRedraw) ? "TRUE" : "FALSE");
302 for(i=0; i<iP->nNumButtons; i++) {
303 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
309 /***********************************************************************
312 * This function validates that the styles set are implemented and
313 * issues FIXME's warning of possible problems. In a perfect world this
314 * function should be null.
317 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
319 if (dwStyle & TBSTYLE_ALTDRAG)
320 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
321 if (dwStyle & TBSTYLE_REGISTERDROP)
322 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
327 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
329 if(!IsWindow(infoPtr->hwndSelf))
330 return 0; /* we have just been destroyed */
332 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
333 nmhdr->hwndFrom = infoPtr->hwndSelf;
336 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
337 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
339 if (infoPtr->bNtfUnicode)
340 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
343 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
344 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
347 /***********************************************************************
348 * TOOLBAR_GetBitmapIndex
350 * This function returns the bitmap index associated with a button.
351 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
352 * is issued to retrieve the index.
355 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
357 INT ret = btnPtr->iBitmap;
359 if (ret == I_IMAGECALLBACK) {
360 /* issue TBN_GETDISPINFO */
363 nmgd.idCommand = btnPtr->idCommand;
364 nmgd.lParam = btnPtr->dwData;
365 nmgd.dwMask = TBNF_IMAGE;
366 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
367 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
369 if (nmgd.dwMask & TBNF_DI_SETITEM) {
370 btnPtr->iBitmap = nmgd.iImage;
373 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
374 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
377 if (ret != I_IMAGENONE)
378 ret = GETIBITMAP(infoPtr, ret);
385 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
388 INT id = GETHIMLID(infoPtr, index);
389 INT iBitmap = GETIBITMAP(infoPtr, index);
391 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
392 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
393 (index == I_IMAGECALLBACK))
400 /***********************************************************************
401 * TOOLBAR_GetImageListForDrawing
403 * This function validates the bitmap index (including I_IMAGECALLBACK
404 * functionality) and returns the corresponding image list.
407 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
411 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
412 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
413 ERR("index %d,%d is not valid, max %d\n",
414 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
418 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
419 if ((*index == I_IMAGECALLBACK) ||
420 (*index == I_IMAGENONE)) return NULL;
421 ERR("TBN_GETDISPINFO returned invalid index %d\n",
428 case IMAGE_LIST_DEFAULT:
429 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
432 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
434 case IMAGE_LIST_DISABLED:
435 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 FIXME("Shouldn't reach here\n");
443 TRACE("no image list\n");
449 /***********************************************************************
450 * TOOLBAR_TestImageExist
452 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
453 * return the image list. The I_IMAGECALLBACK functionality is implemented.
456 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
460 if (!himl) return FALSE;
462 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
463 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
464 ERR("index %d is not valid, max %d\n",
465 btnPtr->iBitmap, infoPtr->nNumBitmaps);
469 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
470 if ((index == I_IMAGECALLBACK) ||
471 (index == I_IMAGENONE)) return FALSE;
472 ERR("TBN_GETDISPINFO returned invalid index %d\n",
481 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
484 COLORREF oldcolor, newcolor;
486 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
487 myrect.right = myrect.left + 1;
488 myrect.top = lpRect->top + 2;
489 myrect.bottom = lpRect->bottom - 2;
491 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
492 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
493 oldcolor = SetBkColor (hdc, newcolor);
494 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
496 myrect.left = myrect.right;
497 myrect.right = myrect.left + 1;
499 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
500 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
501 SetBkColor (hdc, newcolor);
502 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
504 SetBkColor (hdc, oldcolor);
508 /***********************************************************************
509 * TOOLBAR_DrawDDFlatSeparator
511 * This function draws the separator that was flagged as BTNS_DROPDOWN.
512 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
513 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
514 * are horizontal as opposed to the vertical separators for not dropdown
517 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
520 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
523 COLORREF oldcolor, newcolor;
525 myrect.left = lpRect->left;
526 myrect.right = lpRect->right;
527 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
528 myrect.bottom = myrect.top + 1;
530 InflateRect (&myrect, -2, 0);
532 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
533 myrect.left, myrect.top, myrect.right, myrect.bottom);
535 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
536 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
537 oldcolor = SetBkColor (hdc, newcolor);
538 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
540 myrect.top = myrect.bottom;
541 myrect.bottom = myrect.top + 1;
543 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
544 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
545 SetBkColor (hdc, newcolor);
546 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
548 SetBkColor (hdc, oldcolor);
553 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
558 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
559 hOldPen = SelectObject ( hdc, hPen );
562 MoveToEx (hdc, x, y, NULL);
563 LineTo (hdc, x+5, y++); x++;
564 MoveToEx (hdc, x, y, NULL);
565 LineTo (hdc, x+3, y++); x++;
566 MoveToEx (hdc, x, y, NULL);
567 LineTo (hdc, x+1, y++);
568 SelectObject( hdc, hOldPen );
569 DeleteObject( hPen );
573 * Draw the text string for this button.
574 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
575 * is non-zero, so we can simply check himlDef to see if we have
579 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
580 NMTBCUSTOMDRAW *tbcd)
582 HDC hdc = tbcd->nmcd.hdc;
585 COLORREF clrOldBk = 0;
587 UINT state = tbcd->nmcd.uItemState;
591 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
592 rcText->left, rcText->top, rcText->right, rcText->bottom);
594 hOldFont = SelectObject (hdc, infoPtr->hFont);
595 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
596 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
598 else if (state & CDIS_DISABLED) {
599 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
600 OffsetRect (rcText, 1, 1);
601 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
602 SetTextColor (hdc, comctl32_color.clr3dShadow);
603 OffsetRect (rcText, -1, -1);
605 else if (state & CDIS_INDETERMINATE) {
606 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
608 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
609 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
610 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
611 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
614 clrOld = SetTextColor (hdc, tbcd->clrText);
617 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
618 SetTextColor (hdc, clrOld);
619 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
621 SetBkColor (hdc, clrOldBk);
622 SetBkMode (hdc, oldBkMode);
624 SelectObject (hdc, hOldFont);
630 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
632 HDC hdc = tbcd->nmcd.hdc;
633 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
636 INT cx = lpRect->right - lpRect->left;
637 INT cy = lpRect->bottom - lpRect->top;
638 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
639 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
640 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
641 SetBkColor(hdc, clrBkOld);
642 SetTextColor(hdc, clrTextOld);
643 SelectObject (hdc, hbr);
647 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
648 HDC hdc, INT x, INT y)
650 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0);
655 HBITMAP hbmMask, hbmImage;
656 HDC hdcMask, hdcImage;
658 ImageList_GetIconSize(himl, &cx, &cy);
660 /* Create src image */
661 hdcImage = CreateCompatibleDC(hdc);
662 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
663 GetDeviceCaps(hdc,BITSPIXEL), NULL);
664 SelectObject(hdcImage, hbmImage);
665 ImageList_DrawEx(himl, btnPtr->iBitmap, hdcImage, 0, 0, cx, cy,
666 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
669 hdcMask = CreateCompatibleDC(0);
670 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
671 SelectObject(hdcMask, hbmMask);
673 /* Remove the background and all white pixels */
674 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
675 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
676 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
677 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
679 /* draw the new mask 'etched' to hdc */
680 SetBkColor(hdc, RGB(255, 255, 255));
681 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
682 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
683 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
684 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
687 DeleteObject(hbmImage);
689 DeleteObject (hbmMask);
696 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
700 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
701 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
702 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
703 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
704 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
705 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
706 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
707 /* don't test TBSTATE_HIDDEN */
711 /* draws the image on a toolbar button */
713 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
715 HIMAGELIST himl = NULL;
716 BOOL draw_masked = FALSE;
719 UINT draw_flags = ILD_NORMAL;
721 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
723 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
727 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TBSTYLE_FLAT))
729 /* if hot, attempt to draw with hot image list, if fails,
730 use default image list */
731 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
733 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
736 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
738 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
739 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
742 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
743 (tbcd->nmcd.uItemState & CDIS_MARKED))
744 draw_flags |= ILD_BLEND50;
746 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
747 index, himl, left, top, offset);
750 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
752 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
755 /* draws a blank frame for a toolbar button */
757 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
759 HDC hdc = tbcd->nmcd.hdc;
760 RECT rc = tbcd->nmcd.rc;
761 /* if the state is disabled or indeterminate then the button
762 * cannot have an interactive look like pressed or hot */
763 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
764 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
765 BOOL pressed_look = !non_interactive_state &&
766 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
767 (tbcd->nmcd.uItemState & CDIS_CHECKED));
769 /* app don't want us to draw any edges */
770 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
776 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
777 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
778 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
783 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
785 DrawEdge (hdc, &rc, EDGE_RAISED,
786 BF_SOFT | BF_RECT | BF_MIDDLE);
791 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow)
793 HDC hdc = tbcd->nmcd.hdc;
798 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
799 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
800 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
801 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
802 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
803 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
807 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
808 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
810 DrawEdge (hdc, rcArrow, EDGE_RAISED,
811 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
814 if (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
815 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
817 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
819 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
820 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
823 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
826 /* draws a complete toolbar button */
828 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
830 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
831 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
832 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
833 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
834 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
835 BOOL drawSepDropDownArrow = hasDropDownArrow &&
836 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
837 RECT rc, rcArrow, rcBitmap, rcText;
838 LPWSTR lpText = NULL;
844 CopyRect (&rcArrow, &rc);
845 CopyRect(&rcBitmap, &rc);
847 /* get a pointer to the text */
848 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
850 if (hasDropDownArrow)
854 if (dwStyle & TBSTYLE_FLAT)
855 right = max(rc.left, rc.right - DDARROW_WIDTH);
857 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
859 if (drawSepDropDownArrow)
862 rcArrow.left = right;
865 /* copy text rect after adjusting for drop-down arrow
866 * so that text is centred in the rectangle not containing
868 CopyRect(&rcText, &rc);
870 /* Center the bitmap horizontally and vertically */
871 if (dwStyle & TBSTYLE_LIST)
872 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
874 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
877 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
879 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
881 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
882 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
883 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
884 TRACE ("iString: %x\n", btnPtr->iString);
885 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
889 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
890 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
891 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
892 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
894 if (dwStyle & TBSTYLE_LIST)
895 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
897 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
900 if (dwStyle & TBSTYLE_LIST)
901 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
903 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
904 OffsetRect (&rcText, 1, 1);
907 /* Initialize fields in all cases, because we use these later
908 * NOTE: applications can and do alter these to customize their
910 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
911 tbcd.clrText = comctl32_color.clrBtnText;
912 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
913 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
914 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
915 tbcd.clrMark = comctl32_color.clrHighlight;
916 tbcd.clrHighlightHotTrack = 0;
917 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
918 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 /* MSDN says that this is the text rectangle.
920 * But (why always a but) tracing of v5.7 of native shows
921 * that this is really a *relative* rectangle based on the
922 * the nmcd.rc. Also the left and top are always 0 ignoring
923 * any bitmap that might be present. */
924 tbcd.rcText.left = 0;
926 tbcd.rcText.right = rcText.right - rc.left;
927 tbcd.rcText.bottom = rcText.bottom - rc.top;
928 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
931 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
933 /* FIXME: what are these used for? */
937 /* Issue Item Prepaint notify */
938 infoPtr->dwItemCustDraw = 0;
939 infoPtr->dwItemCDFlag = 0;
940 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
942 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
943 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
944 tbcd.nmcd.lItemlParam = btnPtr->dwData;
945 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
946 /* reset these fields so the user can't alter the behaviour like native */
950 infoPtr->dwItemCustDraw = ntfret & 0xffff;
951 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
952 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
954 /* save the only part of the rect that the user can change */
955 rcText.right = tbcd.rcText.right + rc.left;
956 rcText.bottom = tbcd.rcText.bottom + rc.top;
960 if (btnPtr->fsStyle & BTNS_SEP) {
961 /* with the FLAT style, iBitmap is the width and has already */
962 /* been taken into consideration in calculating the width */
963 /* so now we need to draw the vertical separator */
964 /* empirical tests show that iBitmap can/will be non-zero */
965 /* when drawing the vertical bar... */
966 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
967 if (btnPtr->fsStyle & BTNS_DROPDOWN)
968 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
970 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
972 else if (btnPtr->fsStyle != BTNS_SEP) {
973 FIXME("Draw some kind of separator: fsStyle=%x\n",
979 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
980 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
981 TOOLBAR_DrawPattern (&rc, &tbcd);
983 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
985 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
989 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
990 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
991 if (hasDropDownArrow)
992 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
993 SetBkColor(hdc, oldclr);
997 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
999 if (drawSepDropDownArrow)
1000 TOOLBAR_DrawSepDDArrow(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd, &rcArrow);
1002 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1003 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1005 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1007 if (hasDropDownArrow && !drawSepDropDownArrow)
1009 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1011 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1014 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1016 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1017 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1020 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1024 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1026 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1027 tbcd.nmcd.hdc = hdc;
1029 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1030 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1031 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1032 tbcd.rcText = rcText;
1033 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1034 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1042 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1045 TBUTTON_INFO *btnPtr;
1046 INT i, oldBKmode = 0;
1047 RECT rcTemp, rcClient;
1048 NMTBCUSTOMDRAW tbcd;
1051 /* the app has told us not to redraw the toolbar */
1052 if (!infoPtr->bDoRedraw)
1055 /* if imagelist belongs to the app, it can be changed
1056 by the app after setting it */
1057 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1059 infoPtr->nNumBitmaps = 0;
1060 for (i = 0; i < infoPtr->cimlDef; i++)
1061 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1064 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1066 /* Send initial notify */
1067 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1068 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1069 tbcd.nmcd.hdc = hdc;
1070 tbcd.nmcd.rc = ps->rcPaint;
1071 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1072 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1074 if (infoPtr->bBtnTranspnt)
1075 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1077 GetClientRect(hwnd, &rcClient);
1079 /* redraw necessary buttons */
1080 btnPtr = infoPtr->buttons;
1081 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1084 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1086 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1087 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1091 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1092 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1094 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1097 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1098 SetBkMode (hdc, oldBKmode);
1100 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1102 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1103 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1104 tbcd.nmcd.hdc = hdc;
1105 tbcd.nmcd.rc = ps->rcPaint;
1106 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1110 /***********************************************************************
1111 * TOOLBAR_MeasureString
1113 * This function gets the width and height of a string in pixels. This
1114 * is done first by using GetTextExtentPoint to get the basic width
1115 * and height. The DrawText is called with DT_CALCRECT to get the exact
1116 * width. The reason is because the text may have more than one "&" (or
1117 * prefix characters as M$ likes to call them). The prefix character
1118 * indicates where the underline goes, except for the string "&&" which
1119 * is reduced to a single "&". GetTextExtentPoint does not process these
1120 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1123 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1124 HDC hdc, LPSIZE lpSize)
1131 if (infoPtr->nMaxTextRows > 0 &&
1132 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1133 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1134 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1136 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1138 if(lpText != NULL) {
1139 /* first get size of all the text */
1140 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1142 /* feed above size into the rectangle for DrawText */
1143 myrect.left = myrect.top = 0;
1144 myrect.right = lpSize->cx;
1145 myrect.bottom = lpSize->cy;
1147 /* Use DrawText to get true size as drawn (less pesky "&") */
1148 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1149 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1152 /* feed back to caller */
1153 lpSize->cx = myrect.right;
1154 lpSize->cy = myrect.bottom;
1158 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1161 /***********************************************************************
1162 * TOOLBAR_CalcStrings
1164 * This function walks through each string and measures it and returns
1165 * the largest height and width to caller.
1168 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1170 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1171 TBUTTON_INFO *btnPtr;
1180 if(infoPtr->nMaxTextRows == 0)
1184 hOldFont = SelectObject (hdc, infoPtr->hFont);
1186 btnPtr = infoPtr->buttons;
1187 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1188 if(TOOLBAR_HasText(infoPtr, btnPtr))
1190 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1191 if (sz.cx > lpSize->cx)
1193 if (sz.cy > lpSize->cy)
1198 SelectObject (hdc, hOldFont);
1199 ReleaseDC (hwnd, hdc);
1201 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1204 /***********************************************************************
1205 * TOOLBAR_WrapToolbar
1207 * This function walks through the buttons and separators in the
1208 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1209 * wrapping should occur based on the width of the toolbar window.
1210 * It does *not* calculate button placement itself. That task
1211 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1212 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1213 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1215 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1216 * vertical toolbar lists.
1220 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1223 TBUTTON_INFO *btnPtr;
1226 BOOL bWrap, bButtonWrap;
1228 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1229 /* no layout is necessary. Applications may use this style */
1230 /* to perform their own layout on the toolbar. */
1231 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1232 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1234 btnPtr = infoPtr->buttons;
1235 x = infoPtr->nIndent;
1237 /* this can get the parents width, to know how far we can extend
1238 * this toolbar. We cannot use its height, as there may be multiple
1239 * toolbars in a rebar control
1241 GetClientRect( GetParent(hwnd), &rc );
1242 infoPtr->nWidth = rc.right - rc.left;
1243 bButtonWrap = FALSE;
1245 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1246 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1249 for (i = 0; i < infoPtr->nNumButtons; i++ )
1252 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1254 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1257 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1258 /* it is the actual width of the separator. This is used for */
1259 /* custom controls in toolbars. */
1261 /* BTNS_DROPDOWN separators are treated as buttons for */
1262 /* width. - GA 8/01 */
1263 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1264 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1265 cx = (btnPtr[i].iBitmap > 0) ?
1266 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1268 cx = infoPtr->nButtonWidth;
1270 /* Two or more adjacent separators form a separator group. */
1271 /* The first separator in a group should be wrapped to the */
1272 /* next row if the previous wrapping is on a button. */
1274 (btnPtr[i].fsStyle & BTNS_SEP) &&
1275 (i + 1 < infoPtr->nNumButtons ) &&
1276 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1278 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1279 btnPtr[i].fsState |= TBSTATE_WRAP;
1280 x = infoPtr->nIndent;
1282 bButtonWrap = FALSE;
1286 /* The layout makes sure the bitmap is visible, but not the button. */
1287 /* Test added to also wrap after a button that starts a row but */
1288 /* is bigger than the area. - GA 8/01 */
1289 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1290 > infoPtr->nWidth ) ||
1291 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1293 BOOL bFound = FALSE;
1295 /* If the current button is a separator and not hidden, */
1296 /* go to the next until it reaches a non separator. */
1297 /* Wrap the last separator if it is before a button. */
1298 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1299 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1300 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1301 i < infoPtr->nNumButtons )
1307 if( bFound && i < infoPtr->nNumButtons )
1310 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1311 i, btnPtr[i].fsStyle, x, cx);
1312 btnPtr[i].fsState |= TBSTATE_WRAP;
1313 x = infoPtr->nIndent;
1314 bButtonWrap = FALSE;
1317 else if ( i >= infoPtr->nNumButtons)
1320 /* If the current button is not a separator, find the last */
1321 /* separator and wrap it. */
1322 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1324 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1325 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1329 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1330 i, btnPtr[i].fsStyle, x, cx);
1331 x = infoPtr->nIndent;
1332 btnPtr[j].fsState |= TBSTATE_WRAP;
1333 bButtonWrap = FALSE;
1338 /* If no separator available for wrapping, wrap one of */
1339 /* non-hidden previous button. */
1343 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1345 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1350 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1351 i, btnPtr[i].fsStyle, x, cx);
1352 x = infoPtr->nIndent;
1353 btnPtr[j].fsState |= TBSTATE_WRAP;
1359 /* If all above failed, wrap the current button. */
1362 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1363 i, btnPtr[i].fsStyle, x, cx);
1364 btnPtr[i].fsState |= TBSTATE_WRAP;
1366 x = infoPtr->nIndent;
1367 if (btnPtr[i].fsStyle & BTNS_SEP )
1368 bButtonWrap = FALSE;
1374 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1375 i, btnPtr[i].fsStyle, x, cx);
1382 /***********************************************************************
1383 * TOOLBAR_CalcToolbar
1385 * This function calculates button and separator placement. It first
1386 * calculates the button sizes, gets the toolbar window width and then
1387 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1388 * on. It assigns a new location to each item and sends this location to
1389 * the tooltip window if appropriate. Finally, it updates the rcBound
1390 * rect and calculates the new required toolbar window height.
1394 TOOLBAR_CalcToolbar (HWND hwnd)
1396 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1397 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1398 TBUTTON_INFO *btnPtr;
1399 INT i, nRows, nSepRows;
1403 BOOL usesBitmaps = FALSE;
1404 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1406 TOOLBAR_CalcStrings (hwnd, &sizeString);
1408 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1410 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1412 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1415 if (dwStyle & TBSTYLE_LIST)
1417 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1418 0, sizeString.cy) + infoPtr->szPadding.cy;
1419 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1420 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1421 if (sizeString.cx > 0)
1422 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1423 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1424 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1425 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1428 if (sizeString.cy > 0)
1431 infoPtr->nButtonHeight = sizeString.cy +
1432 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1433 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1435 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1438 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1440 if (sizeString.cx > infoPtr->nBitmapWidth)
1441 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1443 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1446 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1447 infoPtr->nButtonWidth = infoPtr->cxMin;
1448 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1449 infoPtr->nButtonWidth = infoPtr->cxMax;
1451 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1453 x = infoPtr->nIndent;
1456 /* from above, minimum is a button, and possible text */
1457 cx = infoPtr->nButtonWidth;
1459 /* cannot use just ButtonHeight, we may have no buttons! */
1460 if (infoPtr->nNumButtons > 0)
1461 infoPtr->nHeight = infoPtr->nButtonHeight;
1463 cy = infoPtr->nHeight;
1465 nRows = nSepRows = 0;
1467 infoPtr->rcBound.top = y;
1468 infoPtr->rcBound.left = x;
1469 infoPtr->rcBound.bottom = y + cy;
1470 infoPtr->rcBound.right = x;
1472 btnPtr = infoPtr->buttons;
1474 TRACE("cy=%d\n", cy);
1476 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1479 if (btnPtr->fsState & TBSTATE_HIDDEN)
1481 SetRectEmpty (&btnPtr->rect);
1485 cy = infoPtr->nHeight;
1487 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1488 /* it is the actual width of the separator. This is used for */
1489 /* custom controls in toolbars. */
1490 if (btnPtr->fsStyle & BTNS_SEP) {
1491 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1492 cy = (btnPtr->iBitmap > 0) ?
1493 btnPtr->iBitmap : SEPARATOR_WIDTH;
1494 cx = infoPtr->nButtonWidth;
1497 cx = (btnPtr->iBitmap > 0) ?
1498 btnPtr->iBitmap : SEPARATOR_WIDTH;
1502 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1503 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1510 hOldFont = SelectObject (hdc, infoPtr->hFont);
1512 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1514 SelectObject (hdc, hOldFont);
1515 ReleaseDC (hwnd, hdc);
1517 /* add space on for button frame, etc */
1518 cx = sz.cx + infoPtr->szPadding.cx;
1520 /* add list padding */
1521 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1522 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1524 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1526 if (dwStyle & TBSTYLE_LIST)
1527 cx += infoPtr->nBitmapWidth;
1528 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1529 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1531 else if (dwStyle & TBSTYLE_LIST)
1532 cx += LIST_IMAGE_ABSENT_WIDTH;
1535 cx = infoPtr->nButtonWidth;
1537 if ((hasDropDownArrows && (btnPtr->fsStyle & BTNS_DROPDOWN)) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN))
1538 cx += DDARROW_WIDTH;
1540 if (btnPtr->fsState & TBSTATE_WRAP )
1543 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1545 if (infoPtr->rcBound.left > x)
1546 infoPtr->rcBound.left = x;
1547 if (infoPtr->rcBound.right < x + cx)
1548 infoPtr->rcBound.right = x + cx;
1549 if (infoPtr->rcBound.bottom < y + cy)
1550 infoPtr->rcBound.bottom = y + cy;
1552 /* Set the toolTip only for non-hidden, non-separator button */
1553 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1557 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1558 ti.cbSize = sizeof(TTTOOLINFOA);
1560 ti.uId = btnPtr->idCommand;
1561 ti.rect = btnPtr->rect;
1562 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1566 /* btnPtr->nRow is zero based. The space between the rows is */
1567 /* also considered as a row. */
1568 btnPtr->nRow = nRows + nSepRows;
1570 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1571 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1576 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1580 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1581 /* it is the actual width of the separator. This is used for */
1582 /* custom controls in toolbars. */
1583 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1584 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1585 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1589 /* nSepRows is used to calculate the extra height follwoing */
1593 x = infoPtr->nIndent;
1595 /* Increment row number unless this is the last button */
1596 /* and it has Wrap set. */
1597 if (i != infoPtr->nNumButtons-1)
1604 /* infoPtr->nRows is the number of rows on the toolbar */
1605 infoPtr->nRows = nRows + nSepRows + 1;
1608 /********************************************************************
1609 * The following while interesting, does not match the values *
1610 * created above for the button rectangles, nor the rcBound rect. *
1611 * We will comment it out and remove it later. *
1613 * The problem showed up as heights in the pager control that was *
1615 ********************************************************************/
1617 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1619 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1620 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1621 nSepRows * (infoPtr->nBitmapHeight + 1) +
1625 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1627 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1632 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1635 TBUTTON_INFO *btnPtr;
1638 btnPtr = infoPtr->buttons;
1639 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1640 if (btnPtr->fsState & TBSTATE_HIDDEN)
1643 if (btnPtr->fsStyle & BTNS_SEP) {
1644 if (PtInRect (&btnPtr->rect, *lpPt)) {
1645 TRACE(" ON SEPARATOR %d!\n", i);
1650 if (PtInRect (&btnPtr->rect, *lpPt)) {
1651 TRACE(" ON BUTTON %d!\n", i);
1657 TRACE(" NOWHERE!\n");
1663 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1665 TBUTTON_INFO *btnPtr;
1668 if (CommandIsIndex) {
1669 TRACE("command is really index command=%d\n", idCommand);
1670 if (idCommand >= infoPtr->nNumButtons) return -1;
1673 btnPtr = infoPtr->buttons;
1674 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1675 if (btnPtr->idCommand == idCommand) {
1676 TRACE("command=%d index=%d\n", idCommand, i);
1680 TRACE("no index found for command=%d\n", idCommand);
1686 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1688 TBUTTON_INFO *btnPtr;
1691 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1694 /* check index button */
1695 btnPtr = &infoPtr->buttons[nIndex];
1696 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1697 if (btnPtr->fsState & TBSTATE_CHECKED)
1701 /* check previous buttons */
1702 nRunIndex = nIndex - 1;
1703 while (nRunIndex >= 0) {
1704 btnPtr = &infoPtr->buttons[nRunIndex];
1705 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1706 if (btnPtr->fsState & TBSTATE_CHECKED)
1714 /* check next buttons */
1715 nRunIndex = nIndex + 1;
1716 while (nRunIndex < infoPtr->nNumButtons) {
1717 btnPtr = &infoPtr->buttons[nRunIndex];
1718 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1719 if (btnPtr->fsState & TBSTATE_CHECKED)
1732 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1733 WPARAM wParam, LPARAM lParam)
1739 msg.wParam = wParam;
1740 msg.lParam = lParam;
1741 msg.time = GetMessageTime ();
1742 msg.pt.x = LOWORD(GetMessagePos ());
1743 msg.pt.y = HIWORD(GetMessagePos ());
1745 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1749 /***********************************************************************
1750 * TOOLBAR_CustomizeDialogProc
1751 * This function implements the toolbar customization dialog.
1753 static INT_PTR CALLBACK
1754 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1756 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1757 PCUSTOMBUTTON btnInfo;
1759 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1764 custInfo = (PCUSTDLG_INFO)lParam;
1765 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1773 infoPtr = custInfo->tbInfo;
1775 /* send TBN_QUERYINSERT notification */
1776 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1778 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1781 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1782 nmtb.iItem = (int)hwnd;
1783 /* Send TBN_INITCUSTOMIZE notification */
1784 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1787 TRACE("TBNRF_HIDEHELP requested\n");
1788 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1791 /* add items to 'toolbar buttons' list and check if removable */
1792 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1794 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1795 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1796 btnInfo->btn.fsStyle = BTNS_SEP;
1797 btnInfo->bVirtual = FALSE;
1798 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1800 /* send TBN_QUERYDELETE notification */
1801 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1803 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1804 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1807 /* insert separator button into 'available buttons' list */
1808 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1809 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1810 btnInfo->btn.fsStyle = BTNS_SEP;
1811 btnInfo->bVirtual = FALSE;
1812 btnInfo->bRemovable = TRUE;
1813 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1814 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1815 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1817 /* insert all buttons into dsa */
1820 /* send TBN_GETBUTTONINFO notification */
1823 nmtb.pszText = Buffer;
1826 /* Clear previous button's text */
1827 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1829 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1832 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1833 nmtb.tbButton.fsStyle, i,
1834 nmtb.tbButton.idCommand,
1835 nmtb.tbButton.iString,
1836 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1839 /* insert button into the apropriate list */
1840 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1843 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1844 btnInfo->bVirtual = FALSE;
1845 btnInfo->bRemovable = TRUE;
1847 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1848 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1849 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1853 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1854 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1857 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1858 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1860 if (lstrlenW(nmtb.pszText))
1861 lstrcpyW(btnInfo->text, nmtb.pszText);
1862 else if (nmtb.tbButton.iString >= 0 &&
1863 nmtb.tbButton.iString < infoPtr->nNumStrings)
1865 lstrcpyW(btnInfo->text,
1866 infoPtr->strings[nmtb.tbButton.iString]);
1871 /* select first item in the 'available' list */
1872 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1874 /* append 'virtual' separator button to the 'toolbar buttons' list */
1875 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1876 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1877 btnInfo->btn.fsStyle = BTNS_SEP;
1878 btnInfo->bVirtual = TRUE;
1879 btnInfo->bRemovable = FALSE;
1880 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1881 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1882 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1884 /* select last item in the 'toolbar' list */
1885 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1886 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1888 /* set focus and disable buttons */
1889 PostMessageA (hwnd, WM_USER, 0, 0);
1894 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1895 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1896 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1897 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1901 EndDialog(hwnd, FALSE);
1905 switch (LOWORD(wParam))
1907 case IDC_TOOLBARBTN_LBOX:
1908 if (HIWORD(wParam) == LBN_SELCHANGE)
1910 PCUSTOMBUTTON btnInfo;
1915 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1916 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1918 /* send TBN_QUERYINSERT notification */
1920 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1923 /* get list box item */
1924 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1926 if (index == (count - 1))
1928 /* last item (virtual separator) */
1929 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1930 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1932 else if (index == (count - 2))
1934 /* second last item (last non-virtual item) */
1935 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1936 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1938 else if (index == 0)
1941 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1942 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1946 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1947 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1950 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1954 case IDC_MOVEUP_BTN:
1956 PCUSTOMBUTTON btnInfo;
1960 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1961 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1962 TRACE("Move up: index %d\n", index);
1964 /* send TBN_QUERYINSERT notification */
1967 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1970 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1972 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1973 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1974 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1975 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1978 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1979 else if (index >= (count - 3))
1980 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1982 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1983 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1988 case IDC_MOVEDN_BTN: /* move down */
1990 PCUSTOMBUTTON btnInfo;
1994 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1995 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1996 TRACE("Move up: index %d\n", index);
1998 /* send TBN_QUERYINSERT notification */
2000 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2003 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2005 /* move button down */
2006 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2007 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2008 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2009 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2012 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2013 else if (index >= (count - 3))
2014 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2016 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2017 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2022 case IDC_REMOVE_BTN: /* remove button */
2024 PCUSTOMBUTTON btnInfo;
2027 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2029 if (LB_ERR == index)
2032 TRACE("Remove: index %d\n", index);
2034 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2035 LB_GETITEMDATA, index, 0);
2037 /* send TBN_QUERYDELETE notification */
2038 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2040 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2041 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2042 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2044 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2046 /* insert into 'available button' list */
2047 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2049 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2050 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2058 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2061 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2064 case IDOK: /* Add button */
2069 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2070 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2071 TRACE("Add: index %d\n", index);
2073 /* send TBN_QUERYINSERT notification */
2075 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2078 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2082 /* remove from 'available buttons' list */
2083 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2084 if (index == count-1)
2085 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2087 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2091 PCUSTOMBUTTON btnNew;
2093 /* duplicate 'separator' button */
2094 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2095 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2099 /* insert into 'toolbar button' list */
2100 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2101 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2102 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2104 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2110 EndDialog(hwnd, FALSE);
2120 /* delete items from 'toolbar buttons' listbox*/
2121 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2122 for (i = 0; i < count; i++)
2124 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2126 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2128 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2131 /* delete items from 'available buttons' listbox*/
2132 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2133 for (i = 0; i < count; i++)
2135 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2137 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2139 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2144 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2146 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2147 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2152 COLORREF oldText = 0;
2156 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2157 if (btnInfo == NULL)
2159 FIXME("btnInfo invalid!\n");
2163 /* set colors and select objects */
2164 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2165 if (btnInfo->bVirtual)
2166 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2168 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2169 hPen = CreatePen( PS_SOLID, 1,
2170 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2171 hOldPen = SelectObject (lpdis->hDC, hPen );
2172 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2174 /* fill background rectangle */
2175 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2176 lpdis->rcItem.right, lpdis->rcItem.bottom);
2178 /* calculate button and text rectangles */
2179 CopyRect (&rcButton, &lpdis->rcItem);
2180 InflateRect (&rcButton, -1, -1);
2181 CopyRect (&rcText, &rcButton);
2182 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2183 rcText.left = rcButton.right + 2;
2185 /* draw focus rectangle */
2186 if (lpdis->itemState & ODS_FOCUS)
2187 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2190 if (!(dwStyle & TBSTYLE_FLAT))
2191 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2193 /* draw image and text */
2194 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2195 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2196 btnInfo->btn.iBitmap));
2197 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2198 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2200 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2201 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2203 /* delete objects and reset colors */
2204 SelectObject (lpdis->hDC, hOldBrush);
2205 SelectObject (lpdis->hDC, hOldPen);
2206 SetBkColor (lpdis->hDC, oldBk);
2207 SetTextColor (lpdis->hDC, oldText);
2208 DeleteObject( hPen );
2213 case WM_MEASUREITEM:
2214 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2216 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2218 if (custInfo && custInfo->tbInfo)
2219 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2221 lpmis->itemHeight = 15 + 8; /* default height */
2233 /***********************************************************************
2234 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2238 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2240 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2241 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2242 INT nIndex = 0, nButtons, nCount;
2246 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2250 if (lpAddBmp->hInst == HINST_COMMCTRL)
2252 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2254 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2256 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2261 TRACE ("adding %d internal bitmaps!\n", nButtons);
2263 /* Windows resize all the buttons to the size of a newly added standard image */
2264 if (lpAddBmp->nID & 1)
2267 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2268 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2270 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2271 MAKELPARAM((WORD)24, (WORD)24));
2272 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2273 MAKELPARAM((WORD)31, (WORD)30));
2278 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2279 MAKELPARAM((WORD)16, (WORD)16));
2280 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2281 MAKELPARAM((WORD)22, (WORD)22));
2284 TOOLBAR_CalcToolbar (hwnd);
2288 nButtons = (INT)wParam;
2292 TRACE ("adding %d bitmaps!\n", nButtons);
2295 if (!infoPtr->cimlDef) {
2296 /* create new default image list */
2297 TRACE ("creating default image list!\n");
2299 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2300 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2301 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2302 infoPtr->himlInt = himlDef;
2305 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2309 WARN("No default image list available\n");
2313 nCount = ImageList_GetImageCount(himlDef);
2315 /* Add bitmaps to the default image list */
2316 if (lpAddBmp->hInst == NULL)
2319 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2320 HDC hdcImage, hdcBitmap;
2322 /* copy the bitmap before adding it so that the user's bitmap
2323 * doesn't get modified.
2325 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2327 hdcImage = CreateCompatibleDC(0);
2328 hdcBitmap = CreateCompatibleDC(0);
2330 /* create new bitmap */
2331 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2332 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2333 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2335 /* Copy the user's image */
2336 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2337 hdcBitmap, 0, 0, SRCCOPY);
2339 SelectObject (hdcImage, hOldBitmapLoad);
2340 SelectObject (hdcBitmap, hOldBitmapBitmap);
2341 DeleteDC (hdcImage);
2342 DeleteDC (hdcBitmap);
2344 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2345 DeleteObject (hbmLoad);
2347 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2349 /* Add system bitmaps */
2350 switch (lpAddBmp->nID)
2352 case IDB_STD_SMALL_COLOR:
2353 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2354 MAKEINTRESOURCEA(IDB_STD_SMALL));
2355 nIndex = ImageList_AddMasked (himlDef,
2356 hbmLoad, comctl32_color.clrBtnFace);
2357 DeleteObject (hbmLoad);
2360 case IDB_STD_LARGE_COLOR:
2361 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2362 MAKEINTRESOURCEA(IDB_STD_LARGE));
2363 nIndex = ImageList_AddMasked (himlDef,
2364 hbmLoad, comctl32_color.clrBtnFace);
2365 DeleteObject (hbmLoad);
2368 case IDB_VIEW_SMALL_COLOR:
2369 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2370 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2371 nIndex = ImageList_AddMasked (himlDef,
2372 hbmLoad, comctl32_color.clrBtnFace);
2373 DeleteObject (hbmLoad);
2376 case IDB_VIEW_LARGE_COLOR:
2377 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2378 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2379 nIndex = ImageList_AddMasked (himlDef,
2380 hbmLoad, comctl32_color.clrBtnFace);
2381 DeleteObject (hbmLoad);
2384 case IDB_HIST_SMALL_COLOR:
2385 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2386 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2387 nIndex = ImageList_AddMasked (himlDef,
2388 hbmLoad, comctl32_color.clrBtnFace);
2389 DeleteObject (hbmLoad);
2392 case IDB_HIST_LARGE_COLOR:
2393 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2394 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2395 nIndex = ImageList_AddMasked (himlDef,
2396 hbmLoad, comctl32_color.clrBtnFace);
2397 DeleteObject (hbmLoad);
2401 nIndex = ImageList_GetImageCount (himlDef);
2402 ERR ("invalid imagelist!\n");
2408 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2409 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2410 DeleteObject (hbmLoad);
2413 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2415 if (infoPtr->nNumBitmapInfos == 0)
2417 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2421 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2422 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2423 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2426 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2427 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2428 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2430 infoPtr->nNumBitmapInfos++;
2431 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2435 INT imagecount = ImageList_GetImageCount(himlDef);
2437 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2439 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",
2440 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2441 infoPtr->nNumBitmaps+nButtons,imagecount);
2443 infoPtr->nNumBitmaps = imagecount;
2446 infoPtr->nNumBitmaps += nButtons;
2449 InvalidateRect(hwnd, NULL, TRUE);
2456 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2459 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2460 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2462 TRACE("adding %d buttons!\n", wParam);
2464 nAddButtons = (UINT)wParam;
2465 nOldButtons = infoPtr->nNumButtons;
2466 nNewButtons = nOldButtons + nAddButtons;
2468 if (infoPtr->nNumButtons == 0) {
2470 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2473 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2475 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2476 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2477 nOldButtons * sizeof(TBUTTON_INFO));
2481 infoPtr->nNumButtons = nNewButtons;
2483 /* insert new button data */
2484 for (nCount = 0; nCount < nAddButtons; nCount++) {
2485 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2486 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2487 btnPtr->idCommand = lpTbb[nCount].idCommand;
2488 btnPtr->fsState = lpTbb[nCount].fsState;
2489 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2490 btnPtr->dwData = lpTbb[nCount].dwData;
2491 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2492 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2494 btnPtr->iString = lpTbb[nCount].iString;
2495 btnPtr->bHot = FALSE;
2497 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2500 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2501 ti.cbSize = sizeof (TTTOOLINFOA);
2503 ti.uId = btnPtr->idCommand;
2505 ti.lpszText = LPSTR_TEXTCALLBACKA;
2507 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2512 TOOLBAR_CalcToolbar (hwnd);
2514 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2516 InvalidateRect(hwnd, NULL, TRUE);
2523 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2526 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2527 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2529 TRACE("adding %d buttons!\n", wParam);
2531 nAddButtons = (UINT)wParam;
2532 nOldButtons = infoPtr->nNumButtons;
2533 nNewButtons = nOldButtons + nAddButtons;
2535 if (infoPtr->nNumButtons == 0) {
2537 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2540 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2542 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2543 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2544 nOldButtons * sizeof(TBUTTON_INFO));
2548 infoPtr->nNumButtons = nNewButtons;
2550 /* insert new button data */
2551 for (nCount = 0; nCount < nAddButtons; nCount++) {
2552 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2553 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2554 btnPtr->idCommand = lpTbb[nCount].idCommand;
2555 btnPtr->fsState = lpTbb[nCount].fsState;
2556 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2557 btnPtr->dwData = lpTbb[nCount].dwData;
2558 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2559 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2561 btnPtr->iString = lpTbb[nCount].iString;
2562 btnPtr->bHot = FALSE;
2564 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2567 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2568 ti.cbSize = sizeof (TTTOOLINFOW);
2570 ti.uId = btnPtr->idCommand;
2572 ti.lpszText = LPSTR_TEXTCALLBACKW;
2575 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2580 TOOLBAR_CalcToolbar (hwnd);
2582 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2584 InvalidateRect(hwnd, NULL, TRUE);
2591 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2593 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2596 if ((wParam) && (HIWORD(lParam) == 0)) {
2599 TRACE("adding string from resource!\n");
2601 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2604 TRACE("len=%d \"%s\"\n", len, szString);
2605 nIndex = infoPtr->nNumStrings;
2606 if (infoPtr->nNumStrings == 0) {
2608 Alloc (sizeof(LPWSTR));
2611 LPWSTR *oldStrings = infoPtr->strings;
2613 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2614 memcpy (&infoPtr->strings[0], &oldStrings[0],
2615 sizeof(LPWSTR) * infoPtr->nNumStrings);
2619 /*Alloc zeros out the allocated memory*/
2620 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2621 infoPtr->nNumStrings++;
2624 LPSTR p = (LPSTR)lParam;
2629 TRACE("adding string(s) from array!\n");
2631 nIndex = infoPtr->nNumStrings;
2634 TRACE("len=%d \"%s\"\n", len, p);
2636 if (infoPtr->nNumStrings == 0) {
2638 Alloc (sizeof(LPWSTR));
2641 LPWSTR *oldStrings = infoPtr->strings;
2643 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2644 memcpy (&infoPtr->strings[0], &oldStrings[0],
2645 sizeof(LPWSTR) * infoPtr->nNumStrings);
2649 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2650 infoPtr->nNumStrings++;
2661 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2663 #define MAX_RESOURCE_STRING_LENGTH 512
2664 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2667 if ((wParam) && (HIWORD(lParam) == 0)) {
2668 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2670 TRACE("adding string from resource!\n");
2672 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2673 szString, MAX_RESOURCE_STRING_LENGTH);
2675 TRACE("len=%d %s\n", len, debugstr_w(szString));
2676 TRACE("First char: 0x%x\n", *szString);
2677 if (szString[0] == L'|')
2679 PWSTR p = szString + 1;
2681 nIndex = infoPtr->nNumStrings;
2682 while (*p != L'|' && *p != L'\0') {
2685 if (infoPtr->nNumStrings == 0) {
2686 infoPtr->strings = Alloc (sizeof(LPWSTR));
2690 LPWSTR *oldStrings = infoPtr->strings;
2691 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2692 memcpy(&infoPtr->strings[0], &oldStrings[0],
2693 sizeof(LPWSTR) * infoPtr->nNumStrings);
2697 np=strchrW (p, '|');
2705 TRACE("len=%d %s\n", len, debugstr_w(p));
2706 infoPtr->strings[infoPtr->nNumStrings] =
2707 Alloc (sizeof(WCHAR)*(len+1));
2708 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2709 infoPtr->nNumStrings++;
2716 nIndex = infoPtr->nNumStrings;
2717 if (infoPtr->nNumStrings == 0) {
2719 Alloc (sizeof(LPWSTR));
2722 LPWSTR *oldStrings = infoPtr->strings;
2724 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2725 memcpy (&infoPtr->strings[0], &oldStrings[0],
2726 sizeof(LPWSTR) * infoPtr->nNumStrings);
2730 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2731 infoPtr->nNumStrings++;
2735 LPWSTR p = (LPWSTR)lParam;
2740 TRACE("adding string(s) from array!\n");
2741 nIndex = infoPtr->nNumStrings;
2745 TRACE("len=%d %s\n", len, debugstr_w(p));
2746 if (infoPtr->nNumStrings == 0) {
2748 Alloc (sizeof(LPWSTR));
2751 LPWSTR *oldStrings = infoPtr->strings;
2753 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2754 memcpy (&infoPtr->strings[0], &oldStrings[0],
2755 sizeof(LPWSTR) * infoPtr->nNumStrings);
2759 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2760 infoPtr->nNumStrings++;
2771 TOOLBAR_AutoSize (HWND hwnd)
2773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2774 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2780 UINT uPosFlags = SWP_NOZORDER;
2782 TRACE("resize forced, style=%lx!\n", dwStyle);
2784 parent = GetParent (hwnd);
2785 GetClientRect(parent, &parent_rect);
2787 x = parent_rect.left;
2788 y = parent_rect.top;
2790 /* FIXME: we should be able to early out if nothing */
2791 /* has changed with nWidth != parent_rect width */
2793 if (dwStyle & CCS_NORESIZE) {
2794 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2797 TOOLBAR_CalcToolbar (hwnd);
2800 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2801 TOOLBAR_CalcToolbar (hwnd);
2802 InvalidateRect( hwnd, NULL, TRUE );
2803 cy = infoPtr->nHeight;
2804 cx = infoPtr->nWidth;
2806 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2807 GetWindowRect(hwnd, &window_rect);
2808 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2809 y = window_rect.top;
2811 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2812 GetWindowRect(hwnd, &window_rect);
2813 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2817 if (dwStyle & CCS_NOPARENTALIGN)
2818 uPosFlags |= SWP_NOMOVE;
2820 if (!(dwStyle & CCS_NODIVIDER))
2821 cy += GetSystemMetrics(SM_CYEDGE);
2823 if (dwStyle & WS_BORDER)
2826 cy += GetSystemMetrics(SM_CYEDGE);
2827 cx += GetSystemMetrics(SM_CYEDGE);
2830 infoPtr->bAutoSize = TRUE;
2831 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2832 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2833 * after the setwindowpos calls */
2834 infoPtr->bAutoSize = FALSE;
2841 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2845 return infoPtr->nNumButtons;
2850 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2854 if (infoPtr == NULL) {
2855 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2856 ERR("infoPtr == NULL!\n");
2860 infoPtr->dwStructSize = (DWORD)wParam;
2867 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2869 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2870 TBUTTON_INFO *btnPtr;
2873 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2875 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2879 btnPtr = &infoPtr->buttons[nIndex];
2880 btnPtr->iBitmap = LOWORD(lParam);
2882 /* we HAVE to erase the background, the new bitmap could be */
2884 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2891 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2894 TBUTTON_INFO *btnPtr;
2897 BOOL bChecked = FALSE;
2899 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2901 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2906 btnPtr = &infoPtr->buttons[nIndex];
2908 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2910 if (LOWORD(lParam) == FALSE)
2911 btnPtr->fsState &= ~TBSTATE_CHECKED;
2913 if (btnPtr->fsStyle & BTNS_GROUP) {
2915 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2916 if (nOldIndex == nIndex)
2918 if (nOldIndex != -1)
2919 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2921 btnPtr->fsState |= TBSTATE_CHECKED;
2924 if( bChecked != LOWORD(lParam) )
2926 if (nOldIndex != -1)
2927 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2928 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2931 /* FIXME: Send a WM_NOTIFY?? */
2938 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2942 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2947 TOOLBAR_Customize (HWND hwnd)
2949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2950 CUSTDLG_INFO custInfo;
2956 custInfo.tbInfo = infoPtr;
2957 custInfo.tbHwnd = hwnd;
2959 /* send TBN_BEGINADJUST notification */
2960 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2963 if (!(hRes = FindResourceA (COMCTL32_hModule,
2964 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2968 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2971 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2972 (LPDLGTEMPLATEA)template,
2974 TOOLBAR_CustomizeDialogProc,
2977 /* send TBN_ENDADJUST notification */
2978 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2986 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2989 INT nIndex = (INT)wParam;
2991 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2994 if ((infoPtr->hwndToolTip) &&
2995 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
2998 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2999 ti.cbSize = sizeof (TTTOOLINFOA);
3001 ti.uId = infoPtr->buttons[nIndex].idCommand;
3003 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3006 if (infoPtr->nNumButtons == 1) {
3007 TRACE(" simple delete!\n");
3008 Free (infoPtr->buttons);
3009 infoPtr->buttons = NULL;
3010 infoPtr->nNumButtons = 0;
3013 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3014 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3016 infoPtr->nNumButtons--;
3017 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3019 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3020 nIndex * sizeof(TBUTTON_INFO));
3023 if (nIndex < infoPtr->nNumButtons) {
3024 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3025 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3031 TOOLBAR_CalcToolbar (hwnd);
3033 InvalidateRect (hwnd, NULL, TRUE);
3040 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3042 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3043 TBUTTON_INFO *btnPtr;
3047 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3049 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3054 btnPtr = &infoPtr->buttons[nIndex];
3056 bState = btnPtr->fsState & TBSTATE_ENABLED;
3058 /* update the toolbar button state */
3059 if(LOWORD(lParam) == FALSE) {
3060 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3062 btnPtr->fsState |= TBSTATE_ENABLED;
3065 /* redraw the button only if the state of the button changed */
3066 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3067 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3073 static inline LRESULT
3074 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3076 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3078 return infoPtr->bAnchor;
3083 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3088 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3092 return infoPtr->buttons[nIndex].iBitmap;
3096 static inline LRESULT
3097 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3099 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3104 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3106 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3107 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3108 INT nIndex = (INT)wParam;
3109 TBUTTON_INFO *btnPtr;
3111 if (infoPtr == NULL)
3117 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3120 btnPtr = &infoPtr->buttons[nIndex];
3121 lpTbb->iBitmap = btnPtr->iBitmap;
3122 lpTbb->idCommand = btnPtr->idCommand;
3123 lpTbb->fsState = btnPtr->fsState;
3124 lpTbb->fsStyle = btnPtr->fsStyle;
3125 lpTbb->bReserved[0] = 0;
3126 lpTbb->bReserved[1] = 0;
3127 lpTbb->dwData = btnPtr->dwData;
3128 lpTbb->iString = btnPtr->iString;
3135 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3138 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3139 TBUTTON_INFO *btnPtr;
3142 if (infoPtr == NULL)
3144 if (lpTbInfo == NULL)
3146 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3149 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3150 lpTbInfo->dwMask & 0x80000000);
3154 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3156 if (lpTbInfo->dwMask & TBIF_COMMAND)
3157 lpTbInfo->idCommand = btnPtr->idCommand;
3158 if (lpTbInfo->dwMask & TBIF_IMAGE)
3159 lpTbInfo->iImage = btnPtr->iBitmap;
3160 if (lpTbInfo->dwMask & TBIF_LPARAM)
3161 lpTbInfo->lParam = btnPtr->dwData;
3162 if (lpTbInfo->dwMask & TBIF_SIZE)
3163 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3164 if (lpTbInfo->dwMask & TBIF_STATE)
3165 lpTbInfo->fsState = btnPtr->fsState;
3166 if (lpTbInfo->dwMask & TBIF_STYLE)
3167 lpTbInfo->fsStyle = btnPtr->fsStyle;
3168 if (lpTbInfo->dwMask & TBIF_TEXT) {
3169 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3170 can't use TOOLBAR_GetText here */
3172 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3173 lpText = (LPWSTR)btnPtr->iString;
3174 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3176 lpTbInfo->pszText[0] = '\0';
3183 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3185 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3186 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3187 TBUTTON_INFO *btnPtr;
3190 if (infoPtr == NULL)
3192 if (lpTbInfo == NULL)
3194 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3197 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3198 lpTbInfo->dwMask & 0x80000000);
3202 btnPtr = &infoPtr->buttons[nIndex];
3207 if (lpTbInfo->dwMask & TBIF_COMMAND)
3208 lpTbInfo->idCommand = btnPtr->idCommand;
3209 if (lpTbInfo->dwMask & TBIF_IMAGE)
3210 lpTbInfo->iImage = btnPtr->iBitmap;
3211 if (lpTbInfo->dwMask & TBIF_LPARAM)
3212 lpTbInfo->lParam = btnPtr->dwData;
3213 if (lpTbInfo->dwMask & TBIF_SIZE)
3214 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3215 if (lpTbInfo->dwMask & TBIF_STATE)
3216 lpTbInfo->fsState = btnPtr->fsState;
3217 if (lpTbInfo->dwMask & TBIF_STYLE)
3218 lpTbInfo->fsStyle = btnPtr->fsStyle;
3219 if (lpTbInfo->dwMask & TBIF_TEXT) {
3220 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3221 can't use TOOLBAR_GetText here */
3223 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3224 lpText = (LPWSTR)btnPtr->iString;
3225 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3227 lpTbInfo->pszText[0] = '\0';
3235 TOOLBAR_GetButtonSize (HWND hwnd)
3237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3239 if (infoPtr->nNumButtons > 0)
3240 return MAKELONG((WORD)infoPtr->nButtonWidth,
3241 (WORD)infoPtr->nButtonHeight);
3243 return MAKELONG(8,7);
3248 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3257 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3261 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3263 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3264 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3269 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3278 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3282 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3284 strcpyW ((LPWSTR)lParam, lpText);
3286 return strlenW (lpText);
3291 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3293 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3294 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3295 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3299 inline static LRESULT
3300 TOOLBAR_GetExtendedStyle (HWND hwnd)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3306 return infoPtr->dwExStyle;
3311 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3313 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3314 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3315 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3320 TOOLBAR_GetHotItem (HWND hwnd)
3322 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3324 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3327 if (infoPtr->nHotItem < 0)
3330 return (LRESULT)infoPtr->nHotItem;
3335 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3338 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3339 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3343 /* << TOOLBAR_GetInsertMark >> */
3344 /* << TOOLBAR_GetInsertMarkColor >> */
3348 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 TBUTTON_INFO *btnPtr;
3355 if (infoPtr == NULL)
3357 nIndex = (INT)wParam;
3358 btnPtr = &infoPtr->buttons[nIndex];
3359 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3361 lpRect = (LPRECT)lParam;
3364 if (btnPtr->fsState & TBSTATE_HIDDEN)
3367 lpRect->left = btnPtr->rect.left;
3368 lpRect->right = btnPtr->rect.right;
3369 lpRect->bottom = btnPtr->rect.bottom;
3370 lpRect->top = btnPtr->rect.top;
3377 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3379 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3380 LPSIZE lpSize = (LPSIZE)lParam;
3385 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3386 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3388 TRACE("maximum size %ld x %ld\n",
3389 infoPtr->rcBound.right - infoPtr->rcBound.left,
3390 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3396 /* << TOOLBAR_GetObject >> */
3400 TOOLBAR_GetPadding (HWND hwnd)
3402 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3405 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3406 return (LRESULT) oldPad;
3411 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3414 TBUTTON_INFO *btnPtr;
3418 if (infoPtr == NULL)
3420 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3421 btnPtr = &infoPtr->buttons[nIndex];
3422 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3424 lpRect = (LPRECT)lParam;
3428 lpRect->left = btnPtr->rect.left;
3429 lpRect->right = btnPtr->rect.right;
3430 lpRect->bottom = btnPtr->rect.bottom;
3431 lpRect->top = btnPtr->rect.top;
3438 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3442 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3443 return infoPtr->nRows;
3450 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3455 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3459 return infoPtr->buttons[nIndex].fsState;
3464 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3469 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3473 return infoPtr->buttons[nIndex].fsStyle;
3478 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3482 if (infoPtr == NULL)
3485 return infoPtr->nMaxTextRows;
3490 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3492 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3494 if (infoPtr == NULL)
3496 return (LRESULT)infoPtr->hwndToolTip;
3501 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3505 TRACE("%s hwnd=%p stub!\n",
3506 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3508 return infoPtr->bUnicode;
3512 inline static LRESULT
3513 TOOLBAR_GetVersion (HWND hwnd)
3515 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3516 return infoPtr->iVersion;
3521 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3524 TBUTTON_INFO *btnPtr;
3529 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3533 btnPtr = &infoPtr->buttons[nIndex];
3534 if (LOWORD(lParam) == FALSE)
3535 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3537 btnPtr->fsState |= TBSTATE_HIDDEN;
3539 TOOLBAR_CalcToolbar (hwnd);
3541 InvalidateRect (hwnd, NULL, TRUE);
3547 inline static LRESULT
3548 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3550 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3555 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3557 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3558 TBUTTON_INFO *btnPtr;
3562 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3566 btnPtr = &infoPtr->buttons[nIndex];
3567 oldState = btnPtr->fsState;
3568 if (LOWORD(lParam) == FALSE)
3569 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3571 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3573 if(oldState != btnPtr->fsState)
3574 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3581 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3583 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3584 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3585 INT nIndex = (INT)wParam;
3586 TBUTTON_INFO *oldButtons;
3591 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3594 /* EPP: this seems to be an undocumented call (from my IE4)
3595 * I assume in that case that:
3596 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3597 * - index of insertion is at the end of existing buttons
3598 * I only see this happen with nIndex == -1, but it could have a special
3599 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3601 nIndex = infoPtr->nNumButtons;
3603 } else if (nIndex < 0)
3606 /* If the string passed is not an index, assume address of string
3607 and do our own AddString */
3608 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3612 TRACE("string %s passed instead of index, adding string\n",
3613 debugstr_a((LPSTR)lpTbb->iString));
3614 len = strlen((LPSTR)lpTbb->iString) + 2;
3616 strcpy(ptr, (LPSTR)lpTbb->iString);
3617 ptr[len - 1] = 0; /* ended by two '\0' */
3618 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3622 TRACE("inserting button index=%d\n", nIndex);
3623 if (nIndex > infoPtr->nNumButtons) {
3624 nIndex = infoPtr->nNumButtons;
3625 TRACE("adjust index=%d\n", nIndex);
3628 oldButtons = infoPtr->buttons;
3629 infoPtr->nNumButtons++;
3630 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3631 /* pre insert copy */
3633 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3634 nIndex * sizeof(TBUTTON_INFO));
3637 /* insert new button */
3638 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3639 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3640 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3641 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3642 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3643 /* if passed string and not index, then add string */
3644 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3645 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3648 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3650 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3653 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3654 ti.cbSize = sizeof (TTTOOLINFOA);
3656 ti.uId = lpTbb->idCommand;
3658 ti.lpszText = LPSTR_TEXTCALLBACKA;
3660 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3664 /* post insert copy */
3665 if (nIndex < infoPtr->nNumButtons - 1) {
3666 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3667 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3672 TOOLBAR_CalcToolbar (hwnd);
3674 InvalidateRect (hwnd, NULL, TRUE);
3681 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3683 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3684 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3685 INT nIndex = (INT)wParam;
3686 TBUTTON_INFO *oldButtons;
3691 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3694 /* EPP: this seems to be an undocumented call (from my IE4)
3695 * I assume in that case that:
3696 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3697 * - index of insertion is at the end of existing buttons
3698 * I only see this happen with nIndex == -1, but it could have a special
3699 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3701 nIndex = infoPtr->nNumButtons;
3703 } else if (nIndex < 0)
3706 /* If the string passed is not an index, assume address of string
3707 and do our own AddString */
3708 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3712 TRACE("string %s passed instead of index, adding string\n",
3713 debugstr_w((LPWSTR)lpTbb->iString));
3714 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3715 ptr = Alloc(len*sizeof(WCHAR));
3716 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3717 ptr[len - 1] = 0; /* ended by two '\0' */
3718 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3722 TRACE("inserting button index=%d\n", nIndex);
3723 if (nIndex > infoPtr->nNumButtons) {
3724 nIndex = infoPtr->nNumButtons;
3725 TRACE("adjust index=%d\n", nIndex);
3728 oldButtons = infoPtr->buttons;
3729 infoPtr->nNumButtons++;
3730 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3731 /* pre insert copy */
3733 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3734 nIndex * sizeof(TBUTTON_INFO));
3737 /* insert new button */
3738 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3739 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3740 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3741 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3742 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3743 /* if passed string and not index, then add string */
3744 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3745 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3748 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3750 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3753 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3754 ti.cbSize = sizeof (TTTOOLINFOW);
3756 ti.uId = lpTbb->idCommand;
3758 ti.lpszText = LPSTR_TEXTCALLBACKW;
3760 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3764 /* post insert copy */
3765 if (nIndex < infoPtr->nNumButtons - 1) {
3766 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3767 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3772 TOOLBAR_CalcToolbar (hwnd);
3774 InvalidateRect (hwnd, NULL, TRUE);
3780 /* << TOOLBAR_InsertMarkHitTest >> */
3784 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3789 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3793 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3798 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3803 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3807 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3812 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3814 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3817 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3821 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3826 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3828 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3831 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3835 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3840 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3842 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3845 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3849 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3854 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3856 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3859 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3863 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3868 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3871 tbab.hInst = (HINSTANCE)lParam;
3872 tbab.nID = (UINT_PTR)wParam;
3874 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3876 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3881 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3883 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3884 WCHAR wAccel = (WCHAR)wParam;
3885 UINT* pIDButton = (UINT*)lParam;
3886 WCHAR wszAccel[] = {'&',wAccel,0};
3889 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3890 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3892 for (i = 0; i < infoPtr->nNumButtons; i++)
3894 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3895 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3896 !(btnPtr->fsState & TBSTATE_HIDDEN))
3898 int iLen = strlenW(wszAccel);
3899 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3906 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3911 if (!strncmpiW(lpszStr, wszAccel, iLen))
3913 *pIDButton = btnPtr->idCommand;
3925 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3930 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3932 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3937 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3939 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3944 /* << TOOLBAR_MoveButton >> */
3948 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3951 TBUTTON_INFO *btnPtr;
3955 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3959 btnPtr = &infoPtr->buttons[nIndex];
3960 oldState = btnPtr->fsState;
3961 if (LOWORD(lParam) == FALSE)
3962 btnPtr->fsState &= ~TBSTATE_PRESSED;
3964 btnPtr->fsState |= TBSTATE_PRESSED;
3966 if(oldState != btnPtr->fsState)
3967 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3972 /* FIXME: there might still be some confusion her between number of buttons
3973 * and number of bitmaps */
3975 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3978 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3980 int i = 0, nOldButtons = 0, pos = 0;
3981 int nOldBitmaps, nNewBitmaps;
3982 HIMAGELIST himlDef = 0;
3984 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3985 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3986 lpReplace->nButtons);
3988 if (lpReplace->hInstOld == HINST_COMMCTRL)
3990 FIXME("changing standard bitmaps not implemented\n");
3993 else if (lpReplace->hInstOld != 0)
3995 FIXME("resources not in the current module not implemented\n");
4000 hBitmap = (HBITMAP) lpReplace->nIDNew;
4003 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4004 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4005 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4006 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4007 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4009 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4010 nOldButtons = tbi->nButtons;
4011 tbi->nButtons = lpReplace->nButtons;
4012 tbi->hInst = lpReplace->hInstNew;
4013 tbi->nID = lpReplace->nIDNew;
4014 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4017 pos += tbi->nButtons;
4020 if (nOldButtons == 0)
4022 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4026 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4027 nOldBitmaps = ImageList_GetImageCount(himlDef);
4029 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4031 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4032 ImageList_Remove(himlDef, i);
4036 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4037 HDC hdcImage, hdcBitmap;
4039 /* copy the bitmap before adding it so that the user's bitmap
4040 * doesn't get modified.
4042 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4044 hdcImage = CreateCompatibleDC(0);
4045 hdcBitmap = CreateCompatibleDC(0);
4047 /* create new bitmap */
4048 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4049 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4050 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4052 /* Copy the user's image */
4053 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4054 hdcBitmap, 0, 0, SRCCOPY);
4056 SelectObject (hdcImage, hOldBitmapLoad);
4057 SelectObject (hdcBitmap, hOldBitmapBitmap);
4058 DeleteDC (hdcImage);
4059 DeleteDC (hdcBitmap);
4061 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4062 nNewBitmaps = ImageList_GetImageCount(himlDef);
4063 DeleteObject (hbmLoad);
4066 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4068 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4069 pos, nOldBitmaps, nNewBitmaps);
4071 InvalidateRect(hwnd, NULL, TRUE);
4077 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4081 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4083 if (lpSave == NULL) return 0;
4086 /* save toolbar information */
4087 FIXME("save to \"%s\" \"%s\"\n",
4088 lpSave->pszSubKey, lpSave->pszValueName);
4093 /* restore toolbar information */
4095 FIXME("restore from \"%s\" \"%s\"\n",
4096 lpSave->pszSubKey, lpSave->pszValueName);
4107 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4111 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4117 /* save toolbar information */
4118 FIXME("save to \"%s\" \"%s\"\n",
4119 lpSave->pszSubKey, lpSave->pszValueName);
4124 /* restore toolbar information */
4126 FIXME("restore from \"%s\" \"%s\"\n",
4127 lpSave->pszSubKey, lpSave->pszValueName);
4138 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4141 BOOL bOldAnchor = infoPtr->bAnchor;
4143 infoPtr->bAnchor = (BOOL)wParam;
4145 return (LRESULT)bOldAnchor;
4150 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4153 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4155 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4158 if (infoPtr->nNumButtons > 0)
4159 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4160 infoPtr->nNumButtons,
4161 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4162 LOWORD(lParam), HIWORD(lParam));
4164 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4165 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4168 /* uses image list internals directly */
4170 himlDef->cx = infoPtr->nBitmapWidth;
4171 himlDef->cy = infoPtr->nBitmapHeight;
4179 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4181 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4182 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4183 TBUTTON_INFO *btnPtr;
4188 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4191 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4192 lptbbi->dwMask & 0x80000000);
4196 btnPtr = &infoPtr->buttons[nIndex];
4197 if (lptbbi->dwMask & TBIF_COMMAND)
4198 btnPtr->idCommand = lptbbi->idCommand;
4199 if (lptbbi->dwMask & TBIF_IMAGE)
4200 btnPtr->iBitmap = lptbbi->iImage;
4201 if (lptbbi->dwMask & TBIF_LPARAM)
4202 btnPtr->dwData = lptbbi->lParam;
4203 /* if (lptbbi->dwMask & TBIF_SIZE) */
4204 /* btnPtr->cx = lptbbi->cx; */
4205 if (lptbbi->dwMask & TBIF_STATE)
4206 btnPtr->fsState = lptbbi->fsState;
4207 if (lptbbi->dwMask & TBIF_STYLE)
4208 btnPtr->fsStyle = lptbbi->fsStyle;
4210 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4211 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4212 /* iString is index, zero it to make Str_SetPtr succeed */
4215 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4222 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4225 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4226 TBUTTON_INFO *btnPtr;
4231 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4234 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4235 lptbbi->dwMask & 0x80000000);
4239 btnPtr = &infoPtr->buttons[nIndex];
4240 if (lptbbi->dwMask & TBIF_COMMAND)
4241 btnPtr->idCommand = lptbbi->idCommand;
4242 if (lptbbi->dwMask & TBIF_IMAGE)
4243 btnPtr->iBitmap = lptbbi->iImage;
4244 if (lptbbi->dwMask & TBIF_LPARAM)
4245 btnPtr->dwData = lptbbi->lParam;
4246 /* if (lptbbi->dwMask & TBIF_SIZE) */
4247 /* btnPtr->cx = lptbbi->cx; */
4248 if (lptbbi->dwMask & TBIF_STATE)
4249 btnPtr->fsState = lptbbi->fsState;
4250 if (lptbbi->dwMask & TBIF_STYLE)
4251 btnPtr->fsStyle = lptbbi->fsStyle;
4253 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4254 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4255 /* iString is index, zero it to make Str_SetPtr succeed */
4257 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4264 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4267 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4269 if ((cx < 0) || (cy < 0))
4271 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4275 /* The documentation claims you can only change the button size before
4276 * any button has been added. But this is wrong.
4277 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4278 * it to the toolbar, and it checks that the return value is nonzero - mjm
4279 * Further testing shows that we must actually perform the change too.
4282 * The documentation also does not mention that if 0 is supplied for
4283 * either size, the system changes it to the default of 24 wide and
4284 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4286 infoPtr->nButtonWidth = (cx) ? cx : 24;
4287 infoPtr->nButtonHeight = (cy) ? cy : 22;
4293 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4295 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4297 if (infoPtr == NULL) {
4298 TRACE("Toolbar not initialized yet?????\n");
4302 /* if setting to current values, ignore */
4303 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4304 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4305 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4306 infoPtr->cxMin, infoPtr->cxMax);
4310 /* save new values */
4311 infoPtr->cxMin = (INT)LOWORD(lParam);
4312 infoPtr->cxMax = (INT)HIWORD(lParam);
4314 /* if both values are 0 then we are done */
4316 TRACE("setting both min and max to 0, norecalc\n");
4320 /* otherwise we need to recalc the toolbar and in some cases
4321 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4322 which doesn't actually draw - GA). */
4323 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4324 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4326 TOOLBAR_CalcToolbar (hwnd);
4328 InvalidateRect (hwnd, NULL, TRUE);
4335 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4338 INT nIndex = (INT)wParam;
4340 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4343 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4345 if (infoPtr->hwndToolTip) {
4347 FIXME("change tool tip!\n");
4356 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4358 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4359 HIMAGELIST himl = (HIMAGELIST)lParam;
4360 HIMAGELIST himlTemp;
4363 if (infoPtr->iVersion >= 5)
4366 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4367 &infoPtr->cimlDis, himl, id);
4369 /* FIXME: redraw ? */
4371 return (LRESULT)himlTemp;
4376 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4381 dwTemp = infoPtr->dwDTFlags;
4382 infoPtr->dwDTFlags =
4383 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4385 return (LRESULT)dwTemp;
4388 /* This function differs a bit from what MSDN says it does:
4389 * 1. lParam contains extended style flags to OR with current style
4390 * (MSDN isn't clear on the OR bit)
4391 * 2. wParam appears to contain extended style flags to be reset
4392 * (MSDN says that this parameter is reserved)
4395 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4400 dwTemp = infoPtr->dwExStyle;
4401 infoPtr->dwExStyle &= ~wParam;
4402 infoPtr->dwExStyle |= (DWORD)lParam;
4404 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4406 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4407 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4408 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4410 TOOLBAR_CalcToolbar (hwnd);
4412 TOOLBAR_AutoSize(hwnd);
4414 InvalidateRect(hwnd, NULL, TRUE);
4416 return (LRESULT)dwTemp;
4421 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4424 HIMAGELIST himlTemp;
4425 HIMAGELIST himl = (HIMAGELIST)lParam;
4428 if (infoPtr->iVersion >= 5)
4431 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4433 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4434 &infoPtr->cimlHot, himl, id);
4436 /* FIXME: redraw ? */
4438 return (LRESULT)himlTemp;
4443 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4446 INT nOldHotItem = infoPtr->nHotItem;
4447 TBUTTON_INFO *btnPtr;
4449 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4452 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4455 infoPtr->nHotItem = (INT)wParam;
4456 if ((INT)wParam >=0)
4458 btnPtr = &infoPtr->buttons[(INT)wParam];
4459 btnPtr->bHot = TRUE;
4460 InvalidateRect (hwnd, &btnPtr->rect, TRUE);
4464 btnPtr = &infoPtr->buttons[nOldHotItem];
4465 btnPtr->bHot = FALSE;
4466 InvalidateRect (hwnd, &btnPtr->rect, TRUE);
4470 if (nOldHotItem < 0)
4473 return (LRESULT)nOldHotItem;
4478 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4481 HIMAGELIST himlTemp;
4482 HIMAGELIST himl = (HIMAGELIST)lParam;
4485 if (infoPtr->iVersion >= 5)
4488 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4489 &infoPtr->cimlDef, himl, id);
4491 infoPtr->nNumBitmaps = 0;
4492 for (i = 0; i < infoPtr->cimlDef; i++)
4493 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4495 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4496 &infoPtr->nBitmapHeight);
4497 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4498 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4499 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4501 InvalidateRect(hwnd, NULL, TRUE);
4503 return (LRESULT)himlTemp;
4508 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4512 infoPtr->nIndent = (INT)wParam;
4516 /* process only on indent changing */
4517 if(infoPtr->nIndent != (INT)wParam)
4519 infoPtr->nIndent = (INT)wParam;
4520 TOOLBAR_CalcToolbar (hwnd);
4521 InvalidateRect(hwnd, NULL, FALSE);
4528 /* << TOOLBAR_SetInsertMark >> */
4532 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4534 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4536 infoPtr->clrInsertMark = (COLORREF)lParam;
4538 /* FIXME : redraw ??*/
4545 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4549 if (infoPtr == NULL)
4552 infoPtr->nMaxTextRows = (INT)wParam;
4554 TOOLBAR_CalcToolbar(hwnd);
4559 /* MSDN gives slightly wrong info on padding.
4560 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4561 * 2. It is not used to create a blank area between the edge of the button
4562 * and the text or image if TBSTYLE_LIST is set. It is used to control
4563 * the gap between the image and text.
4564 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4565 * to control the bottom and right borders [with the border being
4566 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4567 * is shared evenly on both sides of the button.
4570 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4575 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4576 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4577 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4578 TRACE("cx=%ld, cy=%ld\n",
4579 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4580 return (LRESULT) oldPad;
4585 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4587 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4592 if (infoPtr == NULL)
4594 hwndOldNotify = infoPtr->hwndNotify;
4595 infoPtr->hwndNotify = (HWND)wParam;
4597 return (LRESULT)hwndOldNotify;
4602 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4604 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4605 LPRECT lprc = (LPRECT)lParam;
4609 if (LOWORD(wParam) > 1) {
4610 FIXME("multiple rows not supported!\n");
4613 if(infoPtr->nRows != LOWORD(wParam))
4615 infoPtr->nRows = LOWORD(wParam);
4617 /* recalculate toolbar */
4618 TOOLBAR_CalcToolbar (hwnd);
4620 /* repaint toolbar */
4621 InvalidateRect(hwnd, NULL, TRUE);
4624 /* return bounding rectangle */
4626 lprc->left = infoPtr->rcBound.left;
4627 lprc->right = infoPtr->rcBound.right;
4628 lprc->top = infoPtr->rcBound.top;
4629 lprc->bottom = infoPtr->rcBound.bottom;
4637 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4640 TBUTTON_INFO *btnPtr;
4643 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4647 btnPtr = &infoPtr->buttons[nIndex];
4649 /* if hidden state has changed the invalidate entire window and recalc */
4650 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4651 btnPtr->fsState = LOWORD(lParam);
4652 TOOLBAR_CalcToolbar (hwnd);
4653 InvalidateRect(hwnd, 0, TRUE);
4657 /* process state changing if current state doesn't match new state */
4658 if(btnPtr->fsState != LOWORD(lParam))
4660 btnPtr->fsState = LOWORD(lParam);
4661 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4669 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4671 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4677 inline static LRESULT
4678 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4682 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4684 if (infoPtr == NULL)
4686 infoPtr->hwndToolTip = (HWND)wParam;
4692 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4697 TRACE("%s hwnd=%p stub!\n",
4698 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4700 bTemp = infoPtr->bUnicode;
4701 infoPtr->bUnicode = (BOOL)wParam;
4708 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4712 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4713 comctl32_color.clrBtnHighlight :
4714 infoPtr->clrBtnHighlight;
4715 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4716 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4722 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4726 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4727 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4728 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4730 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4731 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4732 InvalidateRect(hwnd, NULL, TRUE);
4738 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4740 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4741 INT iOldVersion = infoPtr->iVersion;
4743 infoPtr->iVersion = iVersion;
4745 if (infoPtr->iVersion >= 5)
4746 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4753 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4755 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4756 WORD iString = HIWORD(wParam);
4757 WORD buffersize = LOWORD(wParam);
4758 LPSTR str = (LPSTR)lParam;
4761 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4763 if (iString < infoPtr->nNumStrings)
4765 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4767 TRACE("returning %s\n", debugstr_a(str));
4770 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4777 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4780 WORD iString = HIWORD(wParam);
4781 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4782 LPWSTR str = (LPWSTR)lParam;
4785 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4787 if (iString < infoPtr->nNumStrings)
4789 len = min(len, strlenW(infoPtr->strings[iString]));
4790 ret = (len+1)*sizeof(WCHAR);
4791 memcpy(str, infoPtr->strings[iString], ret);
4794 TRACE("returning %s\n", debugstr_w(str));
4797 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4802 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4803 * is the maximum size of the toolbar? */
4804 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4806 SIZE * pSize = (SIZE*)lParam;
4807 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4811 /*********************************************************************/
4813 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4814 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4815 /* based on relay traces of the native control and IE 5.5 */
4817 /*********************************************************************/
4819 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4822 INT nOldHotItem = infoPtr->nHotItem;
4823 TBUTTON_INFO *btnPtr;
4825 NMTBHOTITEM nmhotitem;
4827 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4830 infoPtr->nHotItem = (INT)wParam;
4831 if (nOldHotItem != infoPtr->nHotItem) {
4832 nmhotitem.dwFlags = (DWORD)lParam;
4833 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4834 nmhotitem.idOld = (nOldHotItem >= 0) ?
4835 infoPtr->buttons[nOldHotItem].idCommand : 0;
4836 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4837 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4838 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4839 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4841 if ((INT)wParam >=0) {
4842 btnPtr = &infoPtr->buttons[(INT)wParam];
4843 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4844 InvalidateRect (hwnd, &btnPtr->rect, TRUE);
4846 if (nOldHotItem>=0) {
4847 btnPtr = &infoPtr->buttons[nOldHotItem];
4848 btnPtr->bHot = FALSE;
4849 InvalidateRect (hwnd, &btnPtr->rect, TRUE);
4852 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4853 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4855 if (nOldHotItem < 0)
4858 return (LRESULT)nOldHotItem;
4861 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4862 * which controls the amount of spacing between the image and the text
4863 * of buttons for TBSTYLE_LIST toolbars. */
4864 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4868 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
4871 FIXME("lParam = 0x%08lx. Please report\n", lParam);
4873 infoPtr->iListGap = (INT)wParam;
4875 TOOLBAR_CalcToolbar(hwnd);
4876 InvalidateRect(hwnd, NULL, TRUE);
4881 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4882 * of image lists associated with the various states. */
4883 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
4885 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4887 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4889 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
4893 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4896 LPSIZE lpsize = (LPSIZE)lParam;
4902 * Testing shows the following:
4903 * wParam = 0 adjust cx value
4904 * = 1 set cy value to max size.
4905 * lParam pointer to SIZE structure
4908 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4909 wParam, lParam, lpsize->cx, lpsize->cy);
4913 if (lpsize->cx == -1) {
4914 /* **** this is wrong, native measures each button and sets it */
4915 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4917 else if(HIWORD(lpsize->cx)) {
4919 HWND hwndParent = GetParent(hwnd);
4921 GetWindowRect(hwnd, &rc);
4922 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4923 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4924 rc.left, rc.top, rc.right, rc.bottom);
4925 lpsize->cx = max(rc.right-rc.left,
4926 infoPtr->rcBound.right - infoPtr->rcBound.left);
4929 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4933 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4934 /* lpsize->cy = infoPtr->nHeight; */
4937 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4941 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4942 lpsize->cx, lpsize->cy);
4946 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
4948 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4950 InvalidateRect(hwnd, NULL, TRUE);
4956 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4958 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4959 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4962 TRACE("hwnd = %p\n", hwnd);
4964 /* initialize info structure */
4965 infoPtr->nButtonHeight = 22;
4966 infoPtr->nButtonWidth = 24;
4967 infoPtr->nBitmapHeight = 15;
4968 infoPtr->nBitmapWidth = 16;
4970 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4971 infoPtr->nMaxTextRows = 1;
4972 infoPtr->cxMin = -1;
4973 infoPtr->cxMax = -1;
4974 infoPtr->nNumBitmaps = 0;
4975 infoPtr->nNumStrings = 0;
4977 infoPtr->bCaptured = FALSE;
4978 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4979 infoPtr->nButtonDown = -1;
4980 infoPtr->nOldHit = -1;
4981 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4982 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
4983 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4984 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4985 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4986 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4987 infoPtr->iVersion = 0;
4988 infoPtr->hwndSelf = hwnd;
4989 infoPtr->bDoRedraw = TRUE;
4990 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4991 infoPtr->clrBtnShadow = CLR_DEFAULT;
4992 /* not sure where the +1 comes from, but this comes to the same value
4993 * as native so this is probably correct */
4994 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
4995 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
4996 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
4997 GetClientRect(hwnd, &infoPtr->client_rect);
4998 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5000 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5001 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5003 if (dwStyle & TBSTYLE_TOOLTIPS) {
5004 /* Create tooltip control */
5005 infoPtr->hwndToolTip =
5006 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5007 CW_USEDEFAULT, CW_USEDEFAULT,
5008 CW_USEDEFAULT, CW_USEDEFAULT,
5011 /* Send NM_TOOLTIPSCREATED notification */
5012 if (infoPtr->hwndToolTip) {
5013 NMTOOLTIPSCREATED nmttc;
5015 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5017 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5018 NM_TOOLTIPSCREATED);
5022 TOOLBAR_CheckStyle (hwnd, dwStyle);
5024 TOOLBAR_CalcToolbar(hwnd);
5031 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5035 /* delete tooltip control */
5036 if (infoPtr->hwndToolTip)
5037 DestroyWindow (infoPtr->hwndToolTip);
5039 /* delete temporary buffer for tooltip text */
5040 if (infoPtr->pszTooltipText)
5041 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5043 /* delete button data */
5044 if (infoPtr->buttons)
5045 Free (infoPtr->buttons);
5047 /* delete strings */
5048 if (infoPtr->strings) {
5050 for (i = 0; i < infoPtr->nNumStrings; i++)
5051 if (infoPtr->strings[i])
5052 Free (infoPtr->strings[i]);
5054 Free (infoPtr->strings);
5057 /* destroy internal image list */
5058 if (infoPtr->himlInt)
5059 ImageList_Destroy (infoPtr->himlInt);
5061 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5062 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5063 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5065 /* delete default font */
5067 DeleteObject (infoPtr->hDefaultFont);
5069 /* free toolbar info data */
5071 SetWindowLongA (hwnd, 0, 0);
5078 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5081 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5082 NMTBCUSTOMDRAW tbcd;
5086 if (dwStyle & TBSTYLE_CUSTOMERASE) {
5087 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5088 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5089 tbcd.nmcd.hdc = (HDC)wParam;
5090 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5091 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5093 /* FIXME: in general the return flags *can* be or'ed together */
5094 switch (infoPtr->dwBaseCustDraw)
5096 case CDRF_DODEFAULT:
5098 case CDRF_SKIPDEFAULT:
5101 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5106 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5107 * to my parent for processing.
5109 if (infoPtr->bTransparent) {
5111 HDC hdc = (HDC)wParam;
5116 parent = GetParent(hwnd);
5117 MapWindowPoints(hwnd, parent, &pt, 1);
5118 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5119 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5120 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5123 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5125 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5126 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5127 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5128 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5129 tbcd.nmcd.hdc = (HDC)wParam;
5130 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5131 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5132 switch (infoPtr->dwBaseCustDraw)
5134 case CDRF_DODEFAULT:
5136 case CDRF_SKIPDEFAULT:
5139 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5148 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5152 return (LRESULT)infoPtr->hFont;
5157 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5159 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5160 TBUTTON_INFO *btnPtr;
5164 pt.x = (INT)LOWORD(lParam);
5165 pt.y = (INT)HIWORD(lParam);
5166 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5169 btnPtr = &infoPtr->buttons[nHit];
5170 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5173 infoPtr->bCaptured = TRUE;
5174 infoPtr->nButtonDown = nHit;
5176 btnPtr->fsState |= TBSTATE_PRESSED;
5178 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5180 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5181 TOOLBAR_Customize (hwnd);
5188 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5191 TBUTTON_INFO *btnPtr;
5196 if (infoPtr->hwndToolTip)
5197 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5198 WM_LBUTTONDOWN, wParam, lParam);
5200 pt.x = (INT)LOWORD(lParam);
5201 pt.y = (INT)HIWORD(lParam);
5202 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5206 btnPtr = &infoPtr->buttons[nHit];
5207 infoPtr->nOldHit = nHit;
5209 CopyRect(&arrowRect, &btnPtr->rect);
5210 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5212 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5213 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5214 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5215 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5216 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5217 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5221 * this time we must force a Redraw, so the btn is
5222 * painted down before CaptureChanged repaints it up
5224 RedrawWindow(hwnd,&btnPtr->rect,0,
5225 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5227 nmtb.iItem = btnPtr->idCommand;
5228 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5231 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5232 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5234 if (res != TBDDRET_TREATPRESSED)
5235 /* ??? guess (GA) */
5237 /* otherwise drop through and process as pushed */
5239 /* SetCapture (hwnd); */
5240 infoPtr->bCaptured = TRUE;
5241 infoPtr->nButtonDown = nHit;
5243 btnPtr->fsState |= TBSTATE_PRESSED;
5244 btnPtr->bHot = FALSE;
5246 if (btnPtr->fsState & TBSTATE_ENABLED)
5247 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5251 /* native issues the TBN_BEGINDRAG here */
5252 nmtb.iItem = btnPtr->idCommand;
5253 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5254 nmtb.tbButton.idCommand = btnPtr->idCommand;
5255 nmtb.tbButton.fsState = btnPtr->fsState;
5256 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5257 nmtb.tbButton.dwData = btnPtr->dwData;
5258 nmtb.tbButton.iString = btnPtr->iString;
5259 nmtb.cchText = 0; /* !!! not correct */
5260 nmtb.pszText = 0; /* !!! not correct */
5261 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5269 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5272 TBUTTON_INFO *btnPtr;
5276 BOOL bSendMessage = TRUE;
5281 if (infoPtr->hwndToolTip)
5282 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5283 WM_LBUTTONUP, wParam, lParam);
5285 pt.x = (INT)LOWORD(lParam);
5286 pt.y = (INT)HIWORD(lParam);
5287 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5289 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
5290 /* if the cursor is still inside of the toolbar */
5291 if((infoPtr->nHotItem >= 0) && (nHit != -1))
5292 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
5294 if (0 <= infoPtr->nButtonDown) {
5295 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5296 btnPtr->fsState &= ~TBSTATE_PRESSED;
5298 if (btnPtr->fsStyle & BTNS_CHECK) {
5299 if (btnPtr->fsStyle & BTNS_GROUP) {
5300 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5302 if (nOldIndex == nHit)
5303 bSendMessage = FALSE;
5304 if ((nOldIndex != nHit) &&
5306 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5307 btnPtr->fsState |= TBSTATE_CHECKED;
5310 if (btnPtr->fsState & TBSTATE_CHECKED)
5311 btnPtr->fsState &= ~TBSTATE_CHECKED;
5313 btnPtr->fsState |= TBSTATE_CHECKED;
5317 if (nOldIndex != -1)
5318 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5321 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5322 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5323 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5325 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5327 infoPtr->nButtonDown = -1;
5329 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5330 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5331 NM_RELEASEDCAPTURE);
5333 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5336 nmtb.iItem = btnPtr->idCommand;
5337 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5338 nmtb.tbButton.idCommand = btnPtr->idCommand;
5339 nmtb.tbButton.fsState = btnPtr->fsState;
5340 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5341 nmtb.tbButton.dwData = btnPtr->dwData;
5342 nmtb.tbButton.iString = btnPtr->iString;
5343 nmtb.cchText = 0; /* !!! not correct */
5344 nmtb.pszText = 0; /* !!! not correct */
5345 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5348 if (btnPtr->fsState & TBSTATE_ENABLED)
5350 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5351 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5353 /* !!! Undocumented - toolbar at 4.71 level and above sends
5354 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5355 * Only NM_RCLICK is documented.
5357 nmmouse.dwItemSpec = btnPtr->idCommand;
5358 nmmouse.dwItemData = btnPtr->dwData;
5359 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5366 TOOLBAR_CaptureChanged(HWND hwnd)
5368 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5369 TBUTTON_INFO *btnPtr;
5371 infoPtr->bCaptured = FALSE;
5373 if (infoPtr->nButtonDown >= 0)
5375 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5376 btnPtr->fsState &= ~TBSTATE_PRESSED;
5378 infoPtr->nOldHit = -1;
5380 if (btnPtr->fsState & TBSTATE_ENABLED)
5381 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5387 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5390 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5393 if (infoPtr->nOldHit < 0)
5396 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5398 /* Redraw the button if the last button we were over is the hot button and it
5400 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
5402 hotBtnPtr->bHot = FALSE;
5403 rc1 = hotBtnPtr->rect;
5404 InflateRect (&rc1, 1, 1);
5405 InvalidateRect (hwnd, &rc1, TRUE);
5408 /* If the last button we were over is depressed then make it not */
5409 /* depressed and redraw it */
5410 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5412 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5414 btnPtr->fsState &= ~TBSTATE_PRESSED;
5416 rc1 = hotBtnPtr->rect;
5417 InflateRect (&rc1, 1, 1);
5418 InvalidateRect (hwnd, &rc1, TRUE);
5421 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5422 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
5428 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5430 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5431 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5434 TRACKMOUSEEVENT trackinfo;
5435 NMTBHOTITEM nmhotitem;
5437 /* fill in the TRACKMOUSEEVENT struct */
5438 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5439 trackinfo.dwFlags = TME_QUERY;
5440 trackinfo.hwndTrack = hwnd;
5441 trackinfo.dwHoverTime = HOVER_DEFAULT;
5443 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5444 _TrackMouseEvent(&trackinfo);
5446 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5447 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5448 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5450 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5451 /* and can properly deactivate the hot toolbar button */
5452 _TrackMouseEvent(&trackinfo);
5455 if (infoPtr->hwndToolTip)
5456 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5457 WM_MOUSEMOVE, wParam, lParam);
5459 pt.x = (INT)LOWORD(lParam);
5460 pt.y = (INT)HIWORD(lParam);
5462 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5464 if (infoPtr->nOldHit != nHit)
5466 /* Remove the effect of an old hot button if the button was
5467 drawn with the hot button effect */
5468 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem)
5470 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5471 oldBtnPtr->bHot = FALSE;
5474 /* It's not a separator or in nowhere. It's a hot button. */
5477 btnPtr = &infoPtr->buttons[nHit];
5479 infoPtr->nHotItem = nHit;
5481 btnPtr->bHot = TRUE;
5484 nmhotitem.dwFlags = HICF_MOUSE;
5486 nmhotitem.idOld = oldBtnPtr->idCommand;
5488 nmhotitem.dwFlags |= HICF_ENTERING;
5490 nmhotitem.idNew = btnPtr->idCommand;
5492 nmhotitem.dwFlags |= HICF_LEAVING;
5493 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5495 /* now invalidate the old and new buttons so they will be painted */
5497 InvalidateRect (hwnd, &oldBtnPtr->rect, TRUE);
5499 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5501 if (infoPtr->bCaptured) {
5502 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5503 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5504 btnPtr->fsState &= ~TBSTATE_PRESSED;
5505 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5507 else if (nHit == infoPtr->nButtonDown) {
5508 btnPtr->fsState |= TBSTATE_PRESSED;
5509 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5512 infoPtr->nOldHit = nHit;
5518 inline static LRESULT
5519 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5521 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5522 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5524 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5528 inline static LRESULT
5529 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5531 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5532 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5534 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5539 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5541 TOOLBAR_INFO *infoPtr;
5542 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5545 /* allocate memory for info structure */
5546 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5547 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5550 infoPtr->dwStructSize = sizeof(TBBUTTON);
5553 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5554 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5555 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5556 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5559 /* native control does:
5560 * Get a lot of colors and brushes
5562 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5563 * CreateFontIndirectA(adr1)
5564 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5565 * hdc = GetDC(toolbar)
5566 * GetSystemMetrics(0x48)
5567 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5568 * 0, 0, 0, 0, "MARLETT")
5569 * oldfnt = SelectObject(hdc, fnt2)
5570 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5571 * GetTextMetricsA(hdc, adr3)
5572 * SelectObject(hdc, oldfnt)
5573 * DeleteObject(fnt2)
5575 * InvalidateRect(toolbar, 0, 1)
5576 * SetWindowLongA(toolbar, 0, addr)
5577 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5580 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5581 * ie 2 0x4600094c 0x4600094c 0x4600894d
5582 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5583 * rebar 0x50008844 0x40008844 0x50008845
5584 * pager 0x50000844 0x40000844 0x50008845
5585 * IC35mgr 0x5400084e **nochange**
5586 * on entry to _NCCREATE 0x5400084e
5587 * rowlist 0x5400004e **nochange**
5588 * on entry to _NCCREATE 0x5400004e
5592 /* I think the code below is a bug, but it is the way that the native
5593 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5594 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5595 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5596 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5597 * Some how, the only cases of this seem to be MFC programs.
5599 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5600 * does not occur in the WM_STYLECHANGING routine.
5601 * (Guy Albertelli 9/2001)
5604 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5605 styleadd |= TBSTYLE_TRANSPARENT;
5606 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5607 styleadd |= CCS_TOP; /* default to top */
5608 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5611 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5616 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5618 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5622 if (dwStyle & WS_MINIMIZE)
5623 return 0; /* Nothing to do */
5625 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5627 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5630 if (!(dwStyle & CCS_NODIVIDER))
5632 GetWindowRect (hwnd, &rcWindow);
5633 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5634 if( dwStyle & WS_BORDER )
5635 OffsetRect (&rcWindow, 1, 1);
5636 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5639 ReleaseDC( hwnd, hdc );
5645 /* handles requests from the tooltip control on what text to display */
5646 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5648 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5650 TRACE("button index = %d\n", index);
5652 if (infoPtr->pszTooltipText)
5654 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5655 infoPtr->pszTooltipText = NULL;
5661 if (infoPtr->bNtfUnicode)
5663 WCHAR wszBuffer[INFOTIPSIZE+1];
5664 NMTBGETINFOTIPW tbgit;
5665 int len; /* in chars */
5667 wszBuffer[0] = '\0';
5668 wszBuffer[INFOTIPSIZE] = '\0';
5670 tbgit.pszText = wszBuffer;
5671 tbgit.cchTextMax = INFOTIPSIZE;
5672 tbgit.iItem = lpnmtdi->hdr.idFrom;
5673 tbgit.lParam = infoPtr->buttons[index].dwData;
5675 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5677 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5679 len = strlenW(tbgit.pszText);
5680 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5682 /* need to allocate temporary buffer in infoPtr as there
5683 * isn't enough space in buffer passed to us by the
5684 * tooltip control */
5685 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5686 if (infoPtr->pszTooltipText)
5688 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5689 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5695 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5701 CHAR szBuffer[INFOTIPSIZE+1];
5702 NMTBGETINFOTIPA tbgit;
5703 int len; /* in chars */
5706 szBuffer[INFOTIPSIZE] = '\0';
5708 tbgit.pszText = szBuffer;
5709 tbgit.cchTextMax = INFOTIPSIZE;
5710 tbgit.iItem = lpnmtdi->hdr.idFrom;
5711 tbgit.lParam = infoPtr->buttons[index].dwData;
5713 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5715 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5717 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5718 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5720 /* need to allocate temporary buffer in infoPtr as there
5721 * isn't enough space in buffer passed to us by the
5722 * tooltip control */
5723 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5724 if (infoPtr->pszTooltipText)
5726 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5727 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5733 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5738 /* if button has text, but it is not shown then automatically
5739 * use that text as tooltip */
5740 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
5741 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
5743 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
5744 int len = pszText ? strlenW(pszText) : 0;
5746 TRACE("using button hidden text %s\n", debugstr_w(pszText));
5748 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5750 /* need to allocate temporary buffer in infoPtr as there
5751 * isn't enough space in buffer passed to us by the
5752 * tooltip control */
5753 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5754 if (infoPtr->pszTooltipText)
5756 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
5757 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5763 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
5768 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
5770 /* last resort: send notification on to app */
5771 /* FIXME: find out what is really used here */
5772 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
5776 inline static LRESULT
5777 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5780 LPNMHDR lpnmh = (LPNMHDR)lParam;
5782 switch (lpnmh->code)
5786 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5788 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5789 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5790 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5794 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5795 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5803 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5805 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5806 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5807 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5808 lppgs->iScroll, lppgs->iDir);
5812 case TTN_GETDISPINFOW:
5813 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
5815 case TTN_GETDISPINFOA:
5816 FIXME("TTN_GETDISPINFOA - stub\n");
5826 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5828 /* remove this routine when Toolbar is improved to pass infoPtr
5829 * around instead of hwnd.
5831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5832 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5837 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5841 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
5843 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
5846 if (lParam == NF_REQUERY) {
5847 i = SendMessageA(infoPtr->hwndNotify,
5848 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5849 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5850 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5854 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5857 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5862 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5868 /* fill ps.rcPaint with a default rect */
5869 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5871 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5873 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5874 ps.rcPaint.left, ps.rcPaint.top,
5875 ps.rcPaint.right, ps.rcPaint.bottom);
5877 TOOLBAR_Refresh (hwnd, hdc, &ps);
5878 if (!wParam) EndPaint (hwnd, &ps);
5885 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5886 /*****************************************************
5889 * Handles the WM_SETREDRAW message.
5892 * According to testing V4.71 of COMCTL32 returns the
5893 * *previous* status of the redraw flag (either 0 or 1)
5894 * instead of the MSDN documented value of 0 if handled.
5895 * (For laughs see the "consistency" with same function
5898 *****************************************************/
5900 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5901 BOOL oldredraw = infoPtr->bDoRedraw;
5903 TRACE("set to %s\n",
5904 (wParam) ? "TRUE" : "FALSE");
5905 infoPtr->bDoRedraw = (BOOL) wParam;
5907 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5909 return (oldredraw) ? 1 : 0;
5914 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5916 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5917 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5926 /* Resize deadlock check */
5927 if (infoPtr->bAutoSize) {
5928 infoPtr->bAutoSize = FALSE;
5932 /* FIXME: optimize to only update size if the new size doesn't */
5933 /* match the current size */
5935 flags = (INT) wParam;
5937 /* FIXME for flags =
5938 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5941 TRACE("sizing toolbar!\n");
5943 if (flags == SIZE_RESTORED) {
5944 /* width and height don't apply */
5945 parent = GetParent (hwnd);
5946 GetClientRect(parent, &parent_rect);
5947 x = parent_rect.left;
5948 y = parent_rect.top;
5950 if (dwStyle & CCS_NORESIZE) {
5951 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5954 * this sets the working width of the toolbar, and
5955 * Calc Toolbar will not adjust it, only the height
5957 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5958 cy = infoPtr->nHeight;
5959 cx = infoPtr->nWidth;
5960 TOOLBAR_CalcToolbar (hwnd);
5961 infoPtr->nWidth = cx;
5962 infoPtr->nHeight = cy;
5965 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5966 TOOLBAR_CalcToolbar (hwnd);
5967 cy = infoPtr->nHeight;
5968 cx = infoPtr->nWidth;
5970 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
5971 GetWindowRect(hwnd, &window_rect);
5972 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5973 y = window_rect.top;
5975 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
5976 GetWindowRect(hwnd, &window_rect);
5977 y = parent_rect.bottom -
5978 ( window_rect.bottom - window_rect.top);
5982 if (dwStyle & CCS_NOPARENTALIGN) {
5983 uPosFlags |= SWP_NOMOVE;
5984 cy = infoPtr->nHeight;
5985 cx = infoPtr->nWidth;
5988 if (!(dwStyle & CCS_NODIVIDER))
5989 cy += GetSystemMetrics(SM_CYEDGE);
5991 if (dwStyle & WS_BORDER)
5994 cy += GetSystemMetrics(SM_CYEDGE);
5995 cx += GetSystemMetrics(SM_CYEDGE);
5998 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6000 RECT delta_width, delta_height, client, dummy;
6001 DWORD min_x, max_x, min_y, max_y;
6002 TBUTTON_INFO *btnPtr;
6005 GetClientRect(hwnd, &client);
6006 if(client.right > infoPtr->client_rect.right)
6008 min_x = infoPtr->client_rect.right;
6009 max_x = client.right;
6013 max_x = infoPtr->client_rect.right;
6014 min_x = client.right;
6016 if(client.bottom > infoPtr->client_rect.bottom)
6018 min_y = infoPtr->client_rect.bottom;
6019 max_y = client.bottom;
6023 max_y = infoPtr->client_rect.bottom;
6024 min_y = client.bottom;
6027 SetRect(&delta_width, min_x, 0, max_x, min_y);
6028 SetRect(&delta_height, 0, min_y, max_x, max_y);
6030 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6031 btnPtr = infoPtr->buttons;
6032 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6033 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6034 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6035 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6038 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
6039 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6041 GetClientRect(hwnd, &infoPtr->client_rect);
6047 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6051 if (nType == GWL_STYLE) {
6052 if (lpStyle->styleNew & TBSTYLE_LIST) {
6053 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
6056 infoPtr->dwDTFlags = DT_CENTER;
6058 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
6059 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6060 (TBSTYLE_FLAT | TBSTYLE_LIST));
6061 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6063 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6066 TOOLBAR_CalcToolbar(hwnd);
6068 TOOLBAR_AutoSize (hwnd);
6070 InvalidateRect(hwnd, NULL, TRUE);
6077 TOOLBAR_SysColorChange (HWND hwnd)
6079 COMCTL32_RefreshSysColors();
6086 static LRESULT WINAPI
6087 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6091 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6092 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6094 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6095 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6100 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6102 case TB_ADDBUTTONSA:
6103 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6105 case TB_ADDBUTTONSW:
6106 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6109 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6112 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6115 return TOOLBAR_AutoSize (hwnd);
6117 case TB_BUTTONCOUNT:
6118 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6120 case TB_BUTTONSTRUCTSIZE:
6121 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6123 case TB_CHANGEBITMAP:
6124 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6126 case TB_CHECKBUTTON:
6127 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6129 case TB_COMMANDTOINDEX:
6130 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6133 return TOOLBAR_Customize (hwnd);
6135 case TB_DELETEBUTTON:
6136 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6138 case TB_ENABLEBUTTON:
6139 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6141 case TB_GETANCHORHIGHLIGHT:
6142 return TOOLBAR_GetAnchorHighlight (hwnd);
6145 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6147 case TB_GETBITMAPFLAGS:
6148 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6151 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6153 case TB_GETBUTTONINFOA:
6154 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6156 case TB_GETBUTTONINFOW:
6157 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6159 case TB_GETBUTTONSIZE:
6160 return TOOLBAR_GetButtonSize (hwnd);
6162 case TB_GETBUTTONTEXTA:
6163 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6165 case TB_GETBUTTONTEXTW:
6166 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6168 case TB_GETDISABLEDIMAGELIST:
6169 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6171 case TB_GETEXTENDEDSTYLE:
6172 return TOOLBAR_GetExtendedStyle (hwnd);
6174 case TB_GETHOTIMAGELIST:
6175 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6178 return TOOLBAR_GetHotItem (hwnd);
6180 case TB_GETIMAGELIST:
6181 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6183 /* case TB_GETINSERTMARK: */ /* 4.71 */
6184 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6186 case TB_GETITEMRECT:
6187 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6190 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6192 /* case TB_GETOBJECT: */ /* 4.71 */
6195 return TOOLBAR_GetPadding (hwnd);
6198 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6201 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6204 return TOOLBAR_GetState (hwnd, wParam, lParam);
6207 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6210 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6213 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6215 case TB_GETTEXTROWS:
6216 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6218 case TB_GETTOOLTIPS:
6219 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6221 case TB_GETUNICODEFORMAT:
6222 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6225 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6228 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6230 case TB_INDETERMINATE:
6231 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6233 case TB_INSERTBUTTONA:
6234 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6236 case TB_INSERTBUTTONW:
6237 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6239 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6241 case TB_ISBUTTONCHECKED:
6242 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6244 case TB_ISBUTTONENABLED:
6245 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6247 case TB_ISBUTTONHIDDEN:
6248 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6250 case TB_ISBUTTONHIGHLIGHTED:
6251 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6253 case TB_ISBUTTONINDETERMINATE:
6254 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6256 case TB_ISBUTTONPRESSED:
6257 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6260 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6262 case TB_MAPACCELERATORA:
6263 case TB_MAPACCELERATORW:
6264 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6267 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6269 /* case TB_MOVEBUTTON: */ /* 4.71 */
6271 case TB_PRESSBUTTON:
6272 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6274 case TB_REPLACEBITMAP:
6275 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6277 case TB_SAVERESTOREA:
6278 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6280 case TB_SAVERESTOREW:
6281 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6283 case TB_SETANCHORHIGHLIGHT:
6284 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6286 case TB_SETBITMAPSIZE:
6287 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6289 case TB_SETBUTTONINFOA:
6290 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6292 case TB_SETBUTTONINFOW:
6293 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6295 case TB_SETBUTTONSIZE:
6296 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6298 case TB_SETBUTTONWIDTH:
6299 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6302 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6304 case TB_SETDISABLEDIMAGELIST:
6305 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6307 case TB_SETDRAWTEXTFLAGS:
6308 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6310 case TB_SETEXTENDEDSTYLE:
6311 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6313 case TB_SETHOTIMAGELIST:
6314 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6317 return TOOLBAR_SetHotItem (hwnd, wParam);
6319 case TB_SETIMAGELIST:
6320 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6323 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6325 /* case TB_SETINSERTMARK: */ /* 4.71 */
6327 case TB_SETINSERTMARKCOLOR:
6328 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6330 case TB_SETMAXTEXTROWS:
6331 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6334 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6337 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6340 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6343 return TOOLBAR_SetState (hwnd, wParam, lParam);
6346 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6348 case TB_SETTOOLTIPS:
6349 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6351 case TB_SETUNICODEFORMAT:
6352 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6355 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6358 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6361 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6364 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6367 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6370 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6372 /* Common Control Messages */
6374 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6375 case CCM_GETCOLORSCHEME:
6376 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6378 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6379 case CCM_SETCOLORSCHEME:
6380 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6382 case CCM_GETVERSION:
6383 return TOOLBAR_GetVersion (hwnd);
6385 case CCM_SETVERSION:
6386 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6392 return TOOLBAR_Create (hwnd, wParam, lParam);
6395 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6398 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6401 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6403 /* case WM_KEYDOWN: */
6404 /* case WM_KILLFOCUS: */
6406 case WM_LBUTTONDBLCLK:
6407 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6409 case WM_LBUTTONDOWN:
6410 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6413 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6416 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6419 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6421 case WM_CAPTURECHANGED:
6422 return TOOLBAR_CaptureChanged(hwnd);
6425 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6428 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6431 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6434 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6437 return TOOLBAR_Notify (hwnd, wParam, lParam);
6439 case WM_NOTIFYFORMAT:
6440 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6443 return TOOLBAR_Paint (hwnd, wParam);
6446 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6449 return TOOLBAR_Size (hwnd, wParam, lParam);
6451 case WM_STYLECHANGED:
6452 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6454 case WM_SYSCOLORCHANGE:
6455 return TOOLBAR_SysColorChange (hwnd);
6457 /* case WM_WININICHANGE: */
6462 case WM_MEASUREITEM:
6464 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6466 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6467 case PGM_FORWARDMOUSE:
6468 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6471 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6472 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6473 uMsg, wParam, lParam);
6474 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6481 TOOLBAR_Register (void)
6485 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6486 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6487 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6488 wndClass.cbClsExtra = 0;
6489 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6490 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6491 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6492 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6494 RegisterClassA (&wndClass);
6499 TOOLBAR_Unregister (void)
6501 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6504 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6509 /* Check if the entry already exists */
6510 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6512 /* If this is a new entry we must create it and insert into the array */
6517 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6520 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6521 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6536 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6540 for (i = 0; i < *cies; i++)
6550 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6558 for (i = 0; i < cies; i++)
6560 if (pies[i]->id == id)
6572 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6574 HIMAGELIST himlDef = 0;
6575 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6578 himlDef = pie->himl;
6584 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6586 if (infoPtr->bUnicode)
6587 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6594 nmtba.iItem = nmtb->iItem;
6595 nmtba.pszText = Buffer;
6596 nmtba.cchText = 256;
6597 ZeroMemory(nmtba.pszText, nmtba.cchText);
6599 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6601 int ccht = strlen(nmtba.pszText);
6603 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6604 nmtb->pszText, nmtb->cchText);
6606 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6615 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6616 int iItem, PCUSTOMBUTTON btnInfo)
6621 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6623 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);