4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Differences between MSDN and actual native control operation:
25 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
26 * to the right of the bitmap. Otherwise, this style is
27 * identical to TBSTYLE_FLAT."
28 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
29 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
30 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
31 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
33 * This code was audited for completeness against the documented features
34 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
36 * Unless otherwise noted, we believe this code to be complete, as per
37 * the specification mentioned above.
38 * If you discover missing features or bugs please note them below.
42 * - TBSTYLE_REGISTERDROP
43 * - TBSTYLE_EX_DOUBLEBUFFER
46 * - TB_GETINSERTMARKCOLOR
49 * - TB_INSERTMARKHITTEST
60 * - Button wrapping (under construction).
62 * - iListGap custom draw support.
63 * - Customization dialog:
64 * - Minor buglet in 'available buttons' list:
65 * Buttons are not listed in MS-like order. MS seems to use a single
66 * internal list to store the button information of both listboxes.
67 * - Drag list support.
70 * - Run tests using Waite Group Windows95 API Bible Volume 2.
71 * The second cdrom contains executables addstr.exe, btncount.exe,
72 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
73 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
74 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
75 * setparnt.exe, setrows.exe, toolwnd.exe.
76 * - Microsofts controlspy examples.
77 * - Charles Petzold's 'Programming Windows': gadgets.exe
87 #include "wine/unicode.h"
91 #include "wine/debug.h"
93 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
95 static HCURSOR hCursorDrag = NULL;
108 INT cx; /* manually set size */
122 } IMLENTRY, *PIMLENTRY;
126 DWORD dwStructSize; /* size of TBBUTTON struct */
127 INT nHeight; /* height of the toolbar */
128 INT nWidth; /* width of the toolbar */
135 INT nRows; /* number of button rows */
136 INT nMaxTextRows; /* maximum number of text rows */
137 INT cxMin; /* minimum button width */
138 INT cxMax; /* maximum button width */
139 INT nNumButtons; /* number of buttons */
140 INT nNumBitmaps; /* number of bitmaps */
141 INT nNumStrings; /* number of strings */
143 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
144 BOOL bCaptured; /* mouse captured? */
145 INT nButtonDown; /* toolbar button being pressed or -1 if none */
146 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
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 dwStyle; /* regular toolbar style */
173 DWORD dwExStyle; /* extended toolbar style */
174 DWORD dwDTFlags; /* DrawText flags */
176 COLORREF clrInsertMark; /* insert mark color */
177 COLORREF clrBtnHighlight; /* color for Flat Separator */
178 COLORREF clrBtnShadow; /* color for Flag Separator */
179 RECT rcBound; /* bounding rectangle */
181 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
182 * for TTN_GETDISPINFOW notification */
183 TBUTTON_INFO *buttons; /* pointer to button array */
184 LPWSTR *strings; /* pointer to string array */
185 TBITMAP_INFO *bitmaps;
186 } TOOLBAR_INFO, *PTOOLBAR_INFO;
189 /* used by customization dialog */
192 PTOOLBAR_INFO tbInfo;
194 } CUSTDLG_INFO, *PCUSTDLG_INFO;
202 } CUSTOMBUTTON, *PCUSTOMBUTTON;
211 #define SEPARATOR_WIDTH 8
213 #define BOTTOM_BORDER 2
214 #define DDARROW_WIDTH 11
215 #define ARROW_HEIGHT 3
217 /* gap between border of button and text/image */
220 /* how wide to treat the bitmap if it isn't present */
221 #define LIST_IMAGE_ABSENT_WIDTH 2
223 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
224 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
225 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
227 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
229 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
232 /* Used to find undocumented extended styles */
233 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
234 TBSTYLE_EX_UNDOC1 | \
235 TBSTYLE_EX_MIXEDBUTTONS | \
236 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
238 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
239 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
240 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
241 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
242 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
244 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
245 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
246 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
247 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
248 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
249 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
250 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
253 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
259 LPWSTR lpText = NULL;
261 /* NOTE: iString == -1 is undocumented */
262 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
263 lpText = (LPWSTR)btnPtr->iString;
264 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
265 lpText = infoPtr->strings[btnPtr->iString];
271 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
273 if (TRACE_ON(toolbar)){
274 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
275 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
276 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
277 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
280 btn_num, bP->idCommand,
281 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
282 bP->rect.left, bP->rect.top,
283 bP->rect.right, bP->rect.bottom);
289 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
291 if (TRACE_ON(toolbar)) {
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, iP->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_REGISTERDROP)
320 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
325 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
327 if(!IsWindow(infoPtr->hwndSelf))
328 return 0; /* we have just been destroyed */
330 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
331 nmhdr->hwndFrom = infoPtr->hwndSelf;
334 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
335 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
337 if (infoPtr->bNtfUnicode)
338 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
339 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
341 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
342 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
345 /***********************************************************************
346 * TOOLBAR_GetBitmapIndex
348 * This function returns the bitmap index associated with a button.
349 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
350 * is issued to retrieve the index.
353 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
355 INT ret = btnPtr->iBitmap;
357 if (ret == I_IMAGECALLBACK) {
358 /* issue TBN_GETDISPINFO */
361 nmgd.idCommand = btnPtr->idCommand;
362 nmgd.lParam = btnPtr->dwData;
363 nmgd.dwMask = TBNF_IMAGE;
364 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
365 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
367 if (nmgd.dwMask & TBNF_DI_SETITEM) {
368 btnPtr->iBitmap = nmgd.iImage;
371 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
372 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
375 if (ret != I_IMAGENONE)
376 ret = GETIBITMAP(infoPtr, ret);
383 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
386 INT id = GETHIMLID(infoPtr, index);
387 INT iBitmap = GETIBITMAP(infoPtr, index);
389 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
390 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
391 (index == I_IMAGECALLBACK))
398 /***********************************************************************
399 * TOOLBAR_GetImageListForDrawing
401 * This function validates the bitmap index (including I_IMAGECALLBACK
402 * functionality) and returns the corresponding image list.
405 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
409 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
410 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
411 ERR("index %d,%d is not valid, max %d\n",
412 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
416 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
417 if ((*index == I_IMAGECALLBACK) ||
418 (*index == I_IMAGENONE)) return NULL;
419 ERR("TBN_GETDISPINFO returned invalid index %d\n",
426 case IMAGE_LIST_DEFAULT:
427 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
430 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
432 case IMAGE_LIST_DISABLED:
433 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
437 FIXME("Shouldn't reach here\n");
441 TRACE("no image list\n");
447 /***********************************************************************
448 * TOOLBAR_TestImageExist
450 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
451 * return the image list. The I_IMAGECALLBACK functionality is implemented.
454 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
458 if (!himl) return FALSE;
460 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
461 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
462 ERR("index %d is not valid, max %d\n",
463 btnPtr->iBitmap, infoPtr->nNumBitmaps);
467 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
468 if ((index == I_IMAGECALLBACK) ||
469 (index == I_IMAGENONE)) return FALSE;
470 ERR("TBN_GETDISPINFO returned invalid index %d\n",
479 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
482 COLORREF oldcolor, newcolor;
484 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
485 myrect.right = myrect.left + 1;
486 myrect.top = lpRect->top + 2;
487 myrect.bottom = lpRect->bottom - 2;
489 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
490 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
491 oldcolor = SetBkColor (hdc, newcolor);
492 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
494 myrect.left = myrect.right;
495 myrect.right = myrect.left + 1;
497 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
498 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
499 SetBkColor (hdc, newcolor);
500 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
502 SetBkColor (hdc, oldcolor);
506 /***********************************************************************
507 * TOOLBAR_DrawDDFlatSeparator
509 * This function draws the separator that was flagged as BTNS_DROPDOWN.
510 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
511 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
512 * are horizontal as opposed to the vertical separators for not dropdown
515 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
518 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
521 COLORREF oldcolor, newcolor;
523 myrect.left = lpRect->left;
524 myrect.right = lpRect->right;
525 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
526 myrect.bottom = myrect.top + 1;
528 InflateRect (&myrect, -2, 0);
530 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
531 myrect.left, myrect.top, myrect.right, myrect.bottom);
533 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
534 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
535 oldcolor = SetBkColor (hdc, newcolor);
536 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
538 myrect.top = myrect.bottom;
539 myrect.bottom = myrect.top + 1;
541 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
542 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
543 SetBkColor (hdc, newcolor);
544 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
546 SetBkColor (hdc, oldcolor);
551 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
556 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
557 hOldPen = SelectObject ( hdc, hPen );
560 MoveToEx (hdc, x, y, NULL);
561 LineTo (hdc, x+5, y++); x++;
562 MoveToEx (hdc, x, y, NULL);
563 LineTo (hdc, x+3, y++); x++;
564 MoveToEx (hdc, x, y, NULL);
565 LineTo (hdc, x+1, y++);
566 SelectObject( hdc, hOldPen );
567 DeleteObject( hPen );
571 * Draw the text string for this button.
572 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
573 * is non-zero, so we can simply check himlDef to see if we have
577 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
578 NMTBCUSTOMDRAW *tbcd)
580 HDC hdc = tbcd->nmcd.hdc;
583 COLORREF clrOldBk = 0;
585 UINT state = tbcd->nmcd.uItemState;
589 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
590 rcText->left, rcText->top, rcText->right, rcText->bottom);
592 hOldFont = SelectObject (hdc, infoPtr->hFont);
593 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
594 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
596 else if (state & CDIS_DISABLED) {
597 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
598 OffsetRect (rcText, 1, 1);
599 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
600 SetTextColor (hdc, comctl32_color.clr3dShadow);
601 OffsetRect (rcText, -1, -1);
603 else if (state & CDIS_INDETERMINATE) {
604 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
606 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
607 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
608 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
609 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
612 clrOld = SetTextColor (hdc, tbcd->clrText);
615 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
616 SetTextColor (hdc, clrOld);
617 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
619 SetBkColor (hdc, clrOldBk);
620 SetBkMode (hdc, oldBkMode);
622 SelectObject (hdc, hOldFont);
628 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
630 HDC hdc = tbcd->nmcd.hdc;
631 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
634 INT cx = lpRect->right - lpRect->left;
635 INT cy = lpRect->bottom - lpRect->top;
636 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
637 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
638 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
639 SetBkColor(hdc, clrBkOld);
640 SetTextColor(hdc, clrTextOld);
641 SelectObject (hdc, hbr);
645 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
646 HDC hdc, INT x, INT y)
650 TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
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, index, 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 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
683 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
684 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
685 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
688 DeleteObject(hbmImage);
690 DeleteObject (hbmMask);
697 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
701 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
702 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
703 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
704 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
705 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
706 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
707 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
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) && (infoPtr->dwStyle & 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);
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);
810 DrawEdge (hdc, rcArrow, EDGE_RAISED,
811 BF_SOFT | BF_RECT | BF_MIDDLE);
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 = infoPtr->dwStyle;
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 = infoPtr->dwStyle;
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;
1504 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1505 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1512 hOldFont = SelectObject (hdc, infoPtr->hFont);
1514 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1516 SelectObject (hdc, hOldFont);
1517 ReleaseDC (hwnd, hdc);
1519 /* add space on for button frame, etc */
1520 cx = sz.cx + infoPtr->szPadding.cx;
1522 /* add list padding */
1523 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1524 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1526 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1528 if (dwStyle & TBSTYLE_LIST)
1529 cx += infoPtr->nBitmapWidth;
1530 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1531 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1533 else if (dwStyle & TBSTYLE_LIST)
1534 cx += LIST_IMAGE_ABSENT_WIDTH;
1537 cx = infoPtr->nButtonWidth;
1539 /* if size has been set manually then don't add on extra space
1540 * for the drop down arrow */
1541 if (!btnPtr->cx && hasDropDownArrows &&
1542 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1543 cx += DDARROW_WIDTH;
1545 if (btnPtr->fsState & TBSTATE_WRAP )
1548 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1550 if (infoPtr->rcBound.left > x)
1551 infoPtr->rcBound.left = x;
1552 if (infoPtr->rcBound.right < x + cx)
1553 infoPtr->rcBound.right = x + cx;
1554 if (infoPtr->rcBound.bottom < y + cy)
1555 infoPtr->rcBound.bottom = y + cy;
1557 /* Set the toolTip only for non-hidden, non-separator button */
1558 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1562 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1563 ti.cbSize = sizeof(TTTOOLINFOA);
1565 ti.uId = btnPtr->idCommand;
1566 ti.rect = btnPtr->rect;
1567 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1571 /* btnPtr->nRow is zero based. The space between the rows is */
1572 /* also considered as a row. */
1573 btnPtr->nRow = nRows + nSepRows;
1575 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1576 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1581 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1585 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1586 /* it is the actual width of the separator. This is used for */
1587 /* custom controls in toolbars. */
1588 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1589 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1590 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1594 /* nSepRows is used to calculate the extra height follwoing */
1598 x = infoPtr->nIndent;
1600 /* Increment row number unless this is the last button */
1601 /* and it has Wrap set. */
1602 if (i != infoPtr->nNumButtons-1)
1609 /* infoPtr->nRows is the number of rows on the toolbar */
1610 infoPtr->nRows = nRows + nSepRows + 1;
1613 /********************************************************************
1614 * The following while interesting, does not match the values *
1615 * created above for the button rectangles, nor the rcBound rect. *
1616 * We will comment it out and remove it later. *
1618 * The problem showed up as heights in the pager control that was *
1620 ********************************************************************/
1622 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1624 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1625 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1626 nSepRows * (infoPtr->nBitmapHeight + 1) +
1630 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1632 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1637 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1640 TBUTTON_INFO *btnPtr;
1643 btnPtr = infoPtr->buttons;
1644 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1645 if (btnPtr->fsState & TBSTATE_HIDDEN)
1648 if (btnPtr->fsStyle & BTNS_SEP) {
1649 if (PtInRect (&btnPtr->rect, *lpPt)) {
1650 TRACE(" ON SEPARATOR %d!\n", i);
1655 if (PtInRect (&btnPtr->rect, *lpPt)) {
1656 TRACE(" ON BUTTON %d!\n", i);
1662 TRACE(" NOWHERE!\n");
1668 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1670 TBUTTON_INFO *btnPtr;
1673 if (CommandIsIndex) {
1674 TRACE("command is really index command=%d\n", idCommand);
1675 if (idCommand >= infoPtr->nNumButtons) return -1;
1678 btnPtr = infoPtr->buttons;
1679 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1680 if (btnPtr->idCommand == idCommand) {
1681 TRACE("command=%d index=%d\n", idCommand, i);
1685 TRACE("no index found for command=%d\n", idCommand);
1691 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1693 TBUTTON_INFO *btnPtr;
1696 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1699 /* check index button */
1700 btnPtr = &infoPtr->buttons[nIndex];
1701 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1702 if (btnPtr->fsState & TBSTATE_CHECKED)
1706 /* check previous buttons */
1707 nRunIndex = nIndex - 1;
1708 while (nRunIndex >= 0) {
1709 btnPtr = &infoPtr->buttons[nRunIndex];
1710 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1711 if (btnPtr->fsState & TBSTATE_CHECKED)
1719 /* check next buttons */
1720 nRunIndex = nIndex + 1;
1721 while (nRunIndex < infoPtr->nNumButtons) {
1722 btnPtr = &infoPtr->buttons[nRunIndex];
1723 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1724 if (btnPtr->fsState & TBSTATE_CHECKED)
1737 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1738 WPARAM wParam, LPARAM lParam)
1744 msg.wParam = wParam;
1745 msg.lParam = lParam;
1746 msg.time = GetMessageTime ();
1747 msg.pt.x = LOWORD(GetMessagePos ());
1748 msg.pt.y = HIWORD(GetMessagePos ());
1750 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1754 /***********************************************************************
1755 * TOOLBAR_CustomizeDialogProc
1756 * This function implements the toolbar customization dialog.
1758 static INT_PTR CALLBACK
1759 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1761 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1762 PCUSTOMBUTTON btnInfo;
1764 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1769 custInfo = (PCUSTDLG_INFO)lParam;
1770 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1778 infoPtr = custInfo->tbInfo;
1780 /* send TBN_QUERYINSERT notification */
1781 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1783 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1786 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1787 nmtb.iItem = (int)hwnd;
1788 /* Send TBN_INITCUSTOMIZE notification */
1789 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1792 TRACE("TBNRF_HIDEHELP requested\n");
1793 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1796 /* add items to 'toolbar buttons' list and check if removable */
1797 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1799 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1800 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1801 btnInfo->btn.fsStyle = BTNS_SEP;
1802 btnInfo->bVirtual = FALSE;
1803 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1805 /* send TBN_QUERYDELETE notification */
1806 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1808 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1809 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1812 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1814 /* insert separator button into 'available buttons' list */
1815 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1816 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1817 btnInfo->btn.fsStyle = BTNS_SEP;
1818 btnInfo->bVirtual = FALSE;
1819 btnInfo->bRemovable = TRUE;
1820 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1821 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1822 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1824 /* insert all buttons into dsa */
1827 /* send TBN_GETBUTTONINFO notification */
1830 nmtb.pszText = Buffer;
1833 /* Clear previous button's text */
1834 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1836 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1839 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1840 nmtb.tbButton.fsStyle, i,
1841 nmtb.tbButton.idCommand,
1842 nmtb.tbButton.iString,
1843 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1846 /* insert button into the apropriate list */
1847 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1850 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1851 btnInfo->bVirtual = FALSE;
1852 btnInfo->bRemovable = TRUE;
1854 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1855 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1856 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1860 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1861 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1864 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1865 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1867 if (lstrlenW(nmtb.pszText))
1868 lstrcpyW(btnInfo->text, nmtb.pszText);
1869 else if (nmtb.tbButton.iString >= 0 &&
1870 nmtb.tbButton.iString < infoPtr->nNumStrings)
1872 lstrcpyW(btnInfo->text,
1873 infoPtr->strings[nmtb.tbButton.iString]);
1878 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1880 /* select first item in the 'available' list */
1881 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1883 /* append 'virtual' separator button to the 'toolbar buttons' list */
1884 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1885 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1886 btnInfo->btn.fsStyle = BTNS_SEP;
1887 btnInfo->bVirtual = TRUE;
1888 btnInfo->bRemovable = FALSE;
1889 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1890 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1891 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1893 /* select last item in the 'toolbar' list */
1894 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1895 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1897 /* set focus and disable buttons */
1898 PostMessageA (hwnd, WM_USER, 0, 0);
1903 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1904 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1905 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1906 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1910 EndDialog(hwnd, FALSE);
1914 switch (LOWORD(wParam))
1916 case IDC_TOOLBARBTN_LBOX:
1917 if (HIWORD(wParam) == LBN_SELCHANGE)
1919 PCUSTOMBUTTON btnInfo;
1924 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1925 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1927 /* send TBN_QUERYINSERT notification */
1929 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1932 /* get list box item */
1933 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1935 if (index == (count - 1))
1937 /* last item (virtual separator) */
1938 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1939 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1941 else if (index == (count - 2))
1943 /* second last item (last non-virtual item) */
1944 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1945 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1947 else if (index == 0)
1950 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1951 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1955 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1959 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1963 case IDC_MOVEUP_BTN:
1965 PCUSTOMBUTTON btnInfo;
1969 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1970 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1971 TRACE("Move up: index %d\n", index);
1973 /* send TBN_QUERYINSERT notification */
1976 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1981 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1983 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1984 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1985 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1986 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1989 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1990 else if (index >= (count - 3))
1991 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1993 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1994 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1996 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2001 case IDC_MOVEDN_BTN: /* move down */
2003 PCUSTOMBUTTON btnInfo;
2007 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2008 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2009 TRACE("Move up: index %d\n", index);
2011 /* send TBN_QUERYINSERT notification */
2013 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2018 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2020 /* move button down */
2021 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2022 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2023 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2024 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2027 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2028 else if (index >= (count - 3))
2029 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2031 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2032 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2034 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2039 case IDC_REMOVE_BTN: /* remove button */
2041 PCUSTOMBUTTON btnInfo;
2044 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2046 if (LB_ERR == index)
2049 TRACE("Remove: index %d\n", index);
2051 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2052 LB_GETITEMDATA, index, 0);
2054 /* send TBN_QUERYDELETE notification */
2055 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2059 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2060 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2061 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2063 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2065 /* insert into 'available button' list */
2066 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2068 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2069 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2074 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2079 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2082 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2085 case IDOK: /* Add button */
2090 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2091 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2092 TRACE("Add: index %d\n", index);
2094 /* send TBN_QUERYINSERT notification */
2096 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2101 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2105 /* remove from 'available buttons' list */
2106 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2107 if (index == count-1)
2108 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2110 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2114 PCUSTOMBUTTON btnNew;
2116 /* duplicate 'separator' button */
2117 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2118 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2122 /* insert into 'toolbar button' list */
2123 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2124 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2125 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2127 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2129 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2135 EndDialog(hwnd, FALSE);
2145 /* delete items from 'toolbar buttons' listbox*/
2146 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2147 for (i = 0; i < count; i++)
2149 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2151 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2153 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2156 /* delete items from 'available buttons' listbox*/
2157 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2158 for (i = 0; i < count; i++)
2160 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2162 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2164 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2169 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2171 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2176 COLORREF oldText = 0;
2180 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2181 if (btnInfo == NULL)
2183 FIXME("btnInfo invalid!\n");
2187 /* set colors and select objects */
2188 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2189 if (btnInfo->bVirtual)
2190 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2192 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2193 hPen = CreatePen( PS_SOLID, 1,
2194 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2195 hOldPen = SelectObject (lpdis->hDC, hPen );
2196 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2198 /* fill background rectangle */
2199 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2200 lpdis->rcItem.right, lpdis->rcItem.bottom);
2202 /* calculate button and text rectangles */
2203 CopyRect (&rcButton, &lpdis->rcItem);
2204 InflateRect (&rcButton, -1, -1);
2205 CopyRect (&rcText, &rcButton);
2206 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2207 rcText.left = rcButton.right + 2;
2209 /* draw focus rectangle */
2210 if (lpdis->itemState & ODS_FOCUS)
2211 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2214 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2215 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2217 /* draw image and text */
2218 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2219 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2220 btnInfo->btn.iBitmap));
2221 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2222 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2224 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2225 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2227 /* delete objects and reset colors */
2228 SelectObject (lpdis->hDC, hOldBrush);
2229 SelectObject (lpdis->hDC, hOldPen);
2230 SetBkColor (lpdis->hDC, oldBk);
2231 SetTextColor (lpdis->hDC, oldText);
2232 DeleteObject( hPen );
2237 case WM_MEASUREITEM:
2238 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2240 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2242 lpmis->itemHeight = 15 + 8; /* default height */
2254 /***********************************************************************
2255 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2259 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2261 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2262 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2263 INT nIndex = 0, nButtons, nCount;
2267 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2271 if (lpAddBmp->hInst == HINST_COMMCTRL)
2273 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2275 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2277 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2282 TRACE ("adding %d internal bitmaps!\n", nButtons);
2284 /* Windows resize all the buttons to the size of a newly added standard image */
2285 if (lpAddBmp->nID & 1)
2288 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2289 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2291 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2292 MAKELPARAM((WORD)24, (WORD)24));
2293 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2294 MAKELPARAM((WORD)31, (WORD)30));
2299 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2300 MAKELPARAM((WORD)16, (WORD)16));
2301 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2302 MAKELPARAM((WORD)22, (WORD)22));
2305 TOOLBAR_CalcToolbar (hwnd);
2309 nButtons = (INT)wParam;
2313 TRACE ("adding %d bitmaps!\n", nButtons);
2316 if (!infoPtr->cimlDef) {
2317 /* create new default image list */
2318 TRACE ("creating default image list!\n");
2320 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2321 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2322 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2323 infoPtr->himlInt = himlDef;
2326 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2330 WARN("No default image list available\n");
2334 nCount = ImageList_GetImageCount(himlDef);
2336 /* Add bitmaps to the default image list */
2337 if (lpAddBmp->hInst == NULL)
2340 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2341 HDC hdcImage, hdcBitmap;
2343 /* copy the bitmap before adding it so that the user's bitmap
2344 * doesn't get modified.
2346 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2348 hdcImage = CreateCompatibleDC(0);
2349 hdcBitmap = CreateCompatibleDC(0);
2351 /* create new bitmap */
2352 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2353 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2354 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2356 /* Copy the user's image */
2357 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2358 hdcBitmap, 0, 0, SRCCOPY);
2360 SelectObject (hdcImage, hOldBitmapLoad);
2361 SelectObject (hdcBitmap, hOldBitmapBitmap);
2362 DeleteDC (hdcImage);
2363 DeleteDC (hdcBitmap);
2365 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2366 DeleteObject (hbmLoad);
2368 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2370 /* Add system bitmaps */
2371 switch (lpAddBmp->nID)
2373 case IDB_STD_SMALL_COLOR:
2374 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2375 MAKEINTRESOURCEA(IDB_STD_SMALL));
2376 nIndex = ImageList_AddMasked (himlDef,
2377 hbmLoad, comctl32_color.clrBtnFace);
2378 DeleteObject (hbmLoad);
2381 case IDB_STD_LARGE_COLOR:
2382 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2383 MAKEINTRESOURCEA(IDB_STD_LARGE));
2384 nIndex = ImageList_AddMasked (himlDef,
2385 hbmLoad, comctl32_color.clrBtnFace);
2386 DeleteObject (hbmLoad);
2389 case IDB_VIEW_SMALL_COLOR:
2390 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2391 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2392 nIndex = ImageList_AddMasked (himlDef,
2393 hbmLoad, comctl32_color.clrBtnFace);
2394 DeleteObject (hbmLoad);
2397 case IDB_VIEW_LARGE_COLOR:
2398 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2399 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2400 nIndex = ImageList_AddMasked (himlDef,
2401 hbmLoad, comctl32_color.clrBtnFace);
2402 DeleteObject (hbmLoad);
2405 case IDB_HIST_SMALL_COLOR:
2406 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2407 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2408 nIndex = ImageList_AddMasked (himlDef,
2409 hbmLoad, comctl32_color.clrBtnFace);
2410 DeleteObject (hbmLoad);
2413 case IDB_HIST_LARGE_COLOR:
2414 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2415 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2416 nIndex = ImageList_AddMasked (himlDef,
2417 hbmLoad, comctl32_color.clrBtnFace);
2418 DeleteObject (hbmLoad);
2422 nIndex = ImageList_GetImageCount (himlDef);
2423 ERR ("invalid imagelist!\n");
2429 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2430 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2431 DeleteObject (hbmLoad);
2434 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2436 if (infoPtr->nNumBitmapInfos == 0)
2438 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2442 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2443 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2444 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2447 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2448 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2449 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2451 infoPtr->nNumBitmapInfos++;
2452 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2456 INT imagecount = ImageList_GetImageCount(himlDef);
2458 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2460 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",
2461 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2462 infoPtr->nNumBitmaps+nButtons,imagecount);
2464 infoPtr->nNumBitmaps = imagecount;
2467 infoPtr->nNumBitmaps += nButtons;
2470 InvalidateRect(hwnd, NULL, TRUE);
2477 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2480 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2481 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2483 TRACE("adding %d buttons!\n", wParam);
2485 nAddButtons = (UINT)wParam;
2486 nOldButtons = infoPtr->nNumButtons;
2487 nNewButtons = nOldButtons + nAddButtons;
2489 if (infoPtr->nNumButtons == 0) {
2491 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2494 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2496 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2497 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2498 nOldButtons * sizeof(TBUTTON_INFO));
2502 infoPtr->nNumButtons = nNewButtons;
2504 /* insert new button data */
2505 for (nCount = 0; nCount < nAddButtons; nCount++) {
2506 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2507 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2508 btnPtr->idCommand = lpTbb[nCount].idCommand;
2509 btnPtr->fsState = lpTbb[nCount].fsState;
2510 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2511 btnPtr->dwData = lpTbb[nCount].dwData;
2512 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2513 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2515 btnPtr->iString = lpTbb[nCount].iString;
2516 btnPtr->bHot = FALSE;
2518 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2521 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2522 ti.cbSize = sizeof (TTTOOLINFOA);
2524 ti.uId = btnPtr->idCommand;
2526 ti.lpszText = LPSTR_TEXTCALLBACKA;
2528 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2533 TOOLBAR_CalcToolbar (hwnd);
2535 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2537 InvalidateRect(hwnd, NULL, TRUE);
2544 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2547 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2548 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2550 TRACE("adding %d buttons!\n", wParam);
2552 nAddButtons = (UINT)wParam;
2553 nOldButtons = infoPtr->nNumButtons;
2554 nNewButtons = nOldButtons + nAddButtons;
2556 if (infoPtr->nNumButtons == 0) {
2558 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2561 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2563 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2564 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2565 nOldButtons * sizeof(TBUTTON_INFO));
2569 infoPtr->nNumButtons = nNewButtons;
2571 /* insert new button data */
2572 for (nCount = 0; nCount < nAddButtons; nCount++) {
2573 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2574 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2575 btnPtr->idCommand = lpTbb[nCount].idCommand;
2576 btnPtr->fsState = lpTbb[nCount].fsState;
2577 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2578 btnPtr->dwData = lpTbb[nCount].dwData;
2579 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2580 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2582 btnPtr->iString = lpTbb[nCount].iString;
2583 btnPtr->bHot = FALSE;
2585 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2588 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2589 ti.cbSize = sizeof (TTTOOLINFOW);
2591 ti.uId = btnPtr->idCommand;
2593 ti.lpszText = LPSTR_TEXTCALLBACKW;
2596 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2601 TOOLBAR_CalcToolbar (hwnd);
2603 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2605 InvalidateRect(hwnd, NULL, TRUE);
2612 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2614 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2617 if ((wParam) && (HIWORD(lParam) == 0)) {
2620 TRACE("adding string from resource!\n");
2622 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2625 TRACE("len=%d \"%s\"\n", len, szString);
2626 nIndex = infoPtr->nNumStrings;
2627 if (infoPtr->nNumStrings == 0) {
2629 Alloc (sizeof(LPWSTR));
2632 LPWSTR *oldStrings = infoPtr->strings;
2634 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2635 memcpy (&infoPtr->strings[0], &oldStrings[0],
2636 sizeof(LPWSTR) * infoPtr->nNumStrings);
2640 /*Alloc zeros out the allocated memory*/
2641 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2642 infoPtr->nNumStrings++;
2645 LPSTR p = (LPSTR)lParam;
2650 TRACE("adding string(s) from array!\n");
2652 nIndex = infoPtr->nNumStrings;
2655 TRACE("len=%d \"%s\"\n", len, p);
2657 if (infoPtr->nNumStrings == 0) {
2659 Alloc (sizeof(LPWSTR));
2662 LPWSTR *oldStrings = infoPtr->strings;
2664 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2665 memcpy (&infoPtr->strings[0], &oldStrings[0],
2666 sizeof(LPWSTR) * infoPtr->nNumStrings);
2670 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2671 infoPtr->nNumStrings++;
2682 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2684 #define MAX_RESOURCE_STRING_LENGTH 512
2685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2688 if ((wParam) && (HIWORD(lParam) == 0)) {
2689 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2691 TRACE("adding string from resource!\n");
2693 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2694 szString, MAX_RESOURCE_STRING_LENGTH);
2696 TRACE("len=%d %s\n", len, debugstr_w(szString));
2697 TRACE("First char: 0x%x\n", *szString);
2698 if (szString[0] == L'|')
2700 PWSTR p = szString + 1;
2702 nIndex = infoPtr->nNumStrings;
2703 while (*p != L'|' && *p != L'\0') {
2706 if (infoPtr->nNumStrings == 0) {
2707 infoPtr->strings = Alloc (sizeof(LPWSTR));
2711 LPWSTR *oldStrings = infoPtr->strings;
2712 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2713 memcpy(&infoPtr->strings[0], &oldStrings[0],
2714 sizeof(LPWSTR) * infoPtr->nNumStrings);
2718 np=strchrW (p, '|');
2726 TRACE("len=%d %s\n", len, debugstr_w(p));
2727 infoPtr->strings[infoPtr->nNumStrings] =
2728 Alloc (sizeof(WCHAR)*(len+1));
2729 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2730 infoPtr->nNumStrings++;
2737 nIndex = infoPtr->nNumStrings;
2738 if (infoPtr->nNumStrings == 0) {
2740 Alloc (sizeof(LPWSTR));
2743 LPWSTR *oldStrings = infoPtr->strings;
2745 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2746 memcpy (&infoPtr->strings[0], &oldStrings[0],
2747 sizeof(LPWSTR) * infoPtr->nNumStrings);
2751 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2752 infoPtr->nNumStrings++;
2756 LPWSTR p = (LPWSTR)lParam;
2761 TRACE("adding string(s) from array!\n");
2762 nIndex = infoPtr->nNumStrings;
2766 TRACE("len=%d %s\n", len, debugstr_w(p));
2767 if (infoPtr->nNumStrings == 0) {
2769 Alloc (sizeof(LPWSTR));
2772 LPWSTR *oldStrings = infoPtr->strings;
2774 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2775 memcpy (&infoPtr->strings[0], &oldStrings[0],
2776 sizeof(LPWSTR) * infoPtr->nNumStrings);
2780 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2781 infoPtr->nNumStrings++;
2792 TOOLBAR_AutoSize (HWND hwnd)
2794 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 UINT uPosFlags = SWP_NOZORDER;
2802 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2804 parent = GetParent (hwnd);
2805 GetClientRect(parent, &parent_rect);
2807 x = parent_rect.left;
2808 y = parent_rect.top;
2810 /* FIXME: we should be able to early out if nothing */
2811 /* has changed with nWidth != parent_rect width */
2813 if (infoPtr->dwStyle & CCS_NORESIZE) {
2814 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2817 TOOLBAR_CalcToolbar (hwnd);
2820 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2821 TOOLBAR_CalcToolbar (hwnd);
2822 InvalidateRect( hwnd, NULL, TRUE );
2823 cy = infoPtr->nHeight;
2824 cx = infoPtr->nWidth;
2826 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2827 GetWindowRect(hwnd, &window_rect);
2828 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2829 y = window_rect.top;
2831 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2832 GetWindowRect(hwnd, &window_rect);
2833 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2837 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2838 uPosFlags |= SWP_NOMOVE;
2840 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2841 cy += GetSystemMetrics(SM_CYEDGE);
2843 if (infoPtr->dwStyle & WS_BORDER)
2846 cy += GetSystemMetrics(SM_CYEDGE);
2847 cx += GetSystemMetrics(SM_CYEDGE);
2850 infoPtr->bAutoSize = TRUE;
2851 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2852 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2853 * after the setwindowpos calls */
2854 infoPtr->bAutoSize = FALSE;
2861 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2865 return infoPtr->nNumButtons;
2870 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2872 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2874 if (infoPtr == NULL) {
2875 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2876 ERR("infoPtr == NULL!\n");
2880 infoPtr->dwStructSize = (DWORD)wParam;
2887 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2890 TBUTTON_INFO *btnPtr;
2893 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2895 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2899 btnPtr = &infoPtr->buttons[nIndex];
2900 btnPtr->iBitmap = LOWORD(lParam);
2902 /* we HAVE to erase the background, the new bitmap could be */
2904 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2911 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2913 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2914 TBUTTON_INFO *btnPtr;
2917 BOOL bChecked = FALSE;
2919 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2921 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2926 btnPtr = &infoPtr->buttons[nIndex];
2928 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2930 if (LOWORD(lParam) == FALSE)
2931 btnPtr->fsState &= ~TBSTATE_CHECKED;
2933 if (btnPtr->fsStyle & BTNS_GROUP) {
2935 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2936 if (nOldIndex == nIndex)
2938 if (nOldIndex != -1)
2939 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2941 btnPtr->fsState |= TBSTATE_CHECKED;
2944 if( bChecked != LOWORD(lParam) )
2946 if (nOldIndex != -1)
2947 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2948 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2951 /* FIXME: Send a WM_NOTIFY?? */
2958 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2962 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2967 TOOLBAR_Customize (HWND hwnd)
2969 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2970 CUSTDLG_INFO custInfo;
2976 custInfo.tbInfo = infoPtr;
2977 custInfo.tbHwnd = hwnd;
2979 /* send TBN_BEGINADJUST notification */
2980 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2983 if (!(hRes = FindResourceA (COMCTL32_hModule,
2984 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2988 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2991 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
2992 (LPDLGTEMPLATEA)template,
2994 TOOLBAR_CustomizeDialogProc,
2997 /* send TBN_ENDADJUST notification */
2998 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3006 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3008 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3009 INT nIndex = (INT)wParam;
3012 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3015 memset(&nmtb, 0, sizeof(nmtb));
3016 nmtb.iItem = nIndex;
3017 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3019 if ((infoPtr->hwndToolTip) &&
3020 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3023 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3024 ti.cbSize = sizeof (TTTOOLINFOA);
3026 ti.uId = infoPtr->buttons[nIndex].idCommand;
3028 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3031 if (infoPtr->nNumButtons == 1) {
3032 TRACE(" simple delete!\n");
3033 Free (infoPtr->buttons);
3034 infoPtr->buttons = NULL;
3035 infoPtr->nNumButtons = 0;
3038 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3039 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3041 infoPtr->nNumButtons--;
3042 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3044 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3045 nIndex * sizeof(TBUTTON_INFO));
3048 if (nIndex < infoPtr->nNumButtons) {
3049 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3050 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3056 TOOLBAR_CalcToolbar (hwnd);
3058 InvalidateRect (hwnd, NULL, TRUE);
3065 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3068 TBUTTON_INFO *btnPtr;
3072 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3074 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3079 btnPtr = &infoPtr->buttons[nIndex];
3081 bState = btnPtr->fsState & TBSTATE_ENABLED;
3083 /* update the toolbar button state */
3084 if(LOWORD(lParam) == FALSE) {
3085 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3087 btnPtr->fsState |= TBSTATE_ENABLED;
3090 /* redraw the button only if the state of the button changed */
3091 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3092 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3098 static inline LRESULT
3099 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3103 return infoPtr->bAnchor;
3108 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3113 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3117 return infoPtr->buttons[nIndex].iBitmap;
3121 static inline LRESULT
3122 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3129 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3131 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3132 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3133 INT nIndex = (INT)wParam;
3134 TBUTTON_INFO *btnPtr;
3136 if (infoPtr == NULL)
3142 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3145 btnPtr = &infoPtr->buttons[nIndex];
3146 lpTbb->iBitmap = btnPtr->iBitmap;
3147 lpTbb->idCommand = btnPtr->idCommand;
3148 lpTbb->fsState = btnPtr->fsState;
3149 lpTbb->fsStyle = btnPtr->fsStyle;
3150 lpTbb->bReserved[0] = 0;
3151 lpTbb->bReserved[1] = 0;
3152 lpTbb->dwData = btnPtr->dwData;
3153 lpTbb->iString = btnPtr->iString;
3160 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3163 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3164 TBUTTON_INFO *btnPtr;
3167 if (infoPtr == NULL)
3169 if (lpTbInfo == NULL)
3171 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3174 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3175 lpTbInfo->dwMask & 0x80000000);
3179 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3181 if (lpTbInfo->dwMask & TBIF_COMMAND)
3182 lpTbInfo->idCommand = btnPtr->idCommand;
3183 if (lpTbInfo->dwMask & TBIF_IMAGE)
3184 lpTbInfo->iImage = btnPtr->iBitmap;
3185 if (lpTbInfo->dwMask & TBIF_LPARAM)
3186 lpTbInfo->lParam = btnPtr->dwData;
3187 if (lpTbInfo->dwMask & TBIF_SIZE)
3188 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3189 if (lpTbInfo->dwMask & TBIF_STATE)
3190 lpTbInfo->fsState = btnPtr->fsState;
3191 if (lpTbInfo->dwMask & TBIF_STYLE)
3192 lpTbInfo->fsStyle = btnPtr->fsStyle;
3193 if (lpTbInfo->dwMask & TBIF_TEXT) {
3194 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3195 can't use TOOLBAR_GetText here */
3197 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3198 lpText = (LPWSTR)btnPtr->iString;
3199 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3201 lpTbInfo->pszText[0] = '\0';
3208 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3210 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3211 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3212 TBUTTON_INFO *btnPtr;
3215 if (infoPtr == NULL)
3217 if (lpTbInfo == NULL)
3219 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3222 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3223 lpTbInfo->dwMask & 0x80000000);
3227 btnPtr = &infoPtr->buttons[nIndex];
3232 if (lpTbInfo->dwMask & TBIF_COMMAND)
3233 lpTbInfo->idCommand = btnPtr->idCommand;
3234 if (lpTbInfo->dwMask & TBIF_IMAGE)
3235 lpTbInfo->iImage = btnPtr->iBitmap;
3236 if (lpTbInfo->dwMask & TBIF_LPARAM)
3237 lpTbInfo->lParam = btnPtr->dwData;
3238 if (lpTbInfo->dwMask & TBIF_SIZE)
3239 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3240 if (lpTbInfo->dwMask & TBIF_STATE)
3241 lpTbInfo->fsState = btnPtr->fsState;
3242 if (lpTbInfo->dwMask & TBIF_STYLE)
3243 lpTbInfo->fsStyle = btnPtr->fsStyle;
3244 if (lpTbInfo->dwMask & TBIF_TEXT) {
3245 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3246 can't use TOOLBAR_GetText here */
3248 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3249 lpText = (LPWSTR)btnPtr->iString;
3250 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3252 lpTbInfo->pszText[0] = '\0';
3260 TOOLBAR_GetButtonSize (HWND hwnd)
3262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3264 if (infoPtr->nNumButtons > 0)
3265 return MAKELONG((WORD)infoPtr->nButtonWidth,
3266 (WORD)infoPtr->nButtonHeight);
3268 return MAKELONG(8,7);
3273 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3282 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3286 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3288 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3289 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3294 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3296 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3307 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3309 strcpyW ((LPWSTR)lParam, lpText);
3311 return strlenW (lpText);
3316 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3318 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3319 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3320 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3324 inline static LRESULT
3325 TOOLBAR_GetExtendedStyle (HWND hwnd)
3327 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3331 return infoPtr->dwExStyle;
3336 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3338 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3339 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3340 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3345 TOOLBAR_GetHotItem (HWND hwnd)
3347 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3349 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3352 if (infoPtr->nHotItem < 0)
3355 return (LRESULT)infoPtr->nHotItem;
3360 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3362 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3363 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3364 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3368 /* << TOOLBAR_GetInsertMark >> */
3369 /* << TOOLBAR_GetInsertMarkColor >> */
3373 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3376 TBUTTON_INFO *btnPtr;
3380 if (infoPtr == NULL)
3382 nIndex = (INT)wParam;
3383 btnPtr = &infoPtr->buttons[nIndex];
3384 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3386 lpRect = (LPRECT)lParam;
3389 if (btnPtr->fsState & TBSTATE_HIDDEN)
3392 lpRect->left = btnPtr->rect.left;
3393 lpRect->right = btnPtr->rect.right;
3394 lpRect->bottom = btnPtr->rect.bottom;
3395 lpRect->top = btnPtr->rect.top;
3402 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3405 LPSIZE lpSize = (LPSIZE)lParam;
3410 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3411 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3413 TRACE("maximum size %ld x %ld\n",
3414 infoPtr->rcBound.right - infoPtr->rcBound.left,
3415 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3421 /* << TOOLBAR_GetObject >> */
3425 TOOLBAR_GetPadding (HWND hwnd)
3427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3430 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3431 return (LRESULT) oldPad;
3436 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3438 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3439 TBUTTON_INFO *btnPtr;
3443 if (infoPtr == NULL)
3445 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3446 btnPtr = &infoPtr->buttons[nIndex];
3447 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3449 lpRect = (LPRECT)lParam;
3453 lpRect->left = btnPtr->rect.left;
3454 lpRect->right = btnPtr->rect.right;
3455 lpRect->bottom = btnPtr->rect.bottom;
3456 lpRect->top = btnPtr->rect.top;
3463 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3467 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3468 return infoPtr->nRows;
3475 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3477 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3480 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3484 return infoPtr->buttons[nIndex].fsState;
3489 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3491 return GetWindowLongW(hwnd, GWL_STYLE);
3496 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3498 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3500 if (infoPtr == NULL)
3503 return infoPtr->nMaxTextRows;
3508 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3512 if (infoPtr == NULL)
3514 return (LRESULT)infoPtr->hwndToolTip;
3519 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3521 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3523 TRACE("%s hwnd=%p stub!\n",
3524 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3526 return infoPtr->bUnicode;
3530 inline static LRESULT
3531 TOOLBAR_GetVersion (HWND hwnd)
3533 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3534 return infoPtr->iVersion;
3539 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3542 TBUTTON_INFO *btnPtr;
3547 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3551 btnPtr = &infoPtr->buttons[nIndex];
3552 if (LOWORD(lParam) == FALSE)
3553 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3555 btnPtr->fsState |= TBSTATE_HIDDEN;
3557 TOOLBAR_CalcToolbar (hwnd);
3559 InvalidateRect (hwnd, NULL, TRUE);
3565 inline static LRESULT
3566 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3568 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3573 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3575 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3576 TBUTTON_INFO *btnPtr;
3580 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3584 btnPtr = &infoPtr->buttons[nIndex];
3585 oldState = btnPtr->fsState;
3586 if (LOWORD(lParam) == FALSE)
3587 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3589 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3591 if(oldState != btnPtr->fsState)
3592 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3599 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3602 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3603 INT nIndex = (INT)wParam;
3604 TBUTTON_INFO *oldButtons;
3609 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3612 /* EPP: this seems to be an undocumented call (from my IE4)
3613 * I assume in that case that:
3614 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3615 * - index of insertion is at the end of existing buttons
3616 * I only see this happen with nIndex == -1, but it could have a special
3617 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3619 nIndex = infoPtr->nNumButtons;
3621 } else if (nIndex < 0)
3624 /* If the string passed is not an index, assume address of string
3625 and do our own AddString */
3626 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3630 TRACE("string %s passed instead of index, adding string\n",
3631 debugstr_a((LPSTR)lpTbb->iString));
3632 len = strlen((LPSTR)lpTbb->iString) + 2;
3634 strcpy(ptr, (LPSTR)lpTbb->iString);
3635 ptr[len - 1] = 0; /* ended by two '\0' */
3636 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3640 TRACE("inserting button index=%d\n", nIndex);
3641 if (nIndex > infoPtr->nNumButtons) {
3642 nIndex = infoPtr->nNumButtons;
3643 TRACE("adjust index=%d\n", nIndex);
3646 oldButtons = infoPtr->buttons;
3647 infoPtr->nNumButtons++;
3648 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3649 /* pre insert copy */
3651 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3652 nIndex * sizeof(TBUTTON_INFO));
3655 /* insert new button */
3656 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3657 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3658 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3659 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3660 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3661 /* if passed string and not index, then add string */
3662 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3663 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3666 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3668 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3671 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3672 ti.cbSize = sizeof (TTTOOLINFOA);
3674 ti.uId = lpTbb->idCommand;
3676 ti.lpszText = LPSTR_TEXTCALLBACKA;
3678 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3682 /* post insert copy */
3683 if (nIndex < infoPtr->nNumButtons - 1) {
3684 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3685 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3690 TOOLBAR_CalcToolbar (hwnd);
3692 InvalidateRect (hwnd, NULL, TRUE);
3699 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3701 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3702 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3703 INT nIndex = (INT)wParam;
3704 TBUTTON_INFO *oldButtons;
3709 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3712 /* EPP: this seems to be an undocumented call (from my IE4)
3713 * I assume in that case that:
3714 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3715 * - index of insertion is at the end of existing buttons
3716 * I only see this happen with nIndex == -1, but it could have a special
3717 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3719 nIndex = infoPtr->nNumButtons;
3721 } else if (nIndex < 0)
3724 /* If the string passed is not an index, assume address of string
3725 and do our own AddString */
3726 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3730 TRACE("string %s passed instead of index, adding string\n",
3731 debugstr_w((LPWSTR)lpTbb->iString));
3732 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3733 ptr = Alloc(len*sizeof(WCHAR));
3734 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3735 ptr[len - 1] = 0; /* ended by two '\0' */
3736 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3740 TRACE("inserting button index=%d\n", nIndex);
3741 if (nIndex > infoPtr->nNumButtons) {
3742 nIndex = infoPtr->nNumButtons;
3743 TRACE("adjust index=%d\n", nIndex);
3746 oldButtons = infoPtr->buttons;
3747 infoPtr->nNumButtons++;
3748 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3749 /* pre insert copy */
3751 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3752 nIndex * sizeof(TBUTTON_INFO));
3755 /* insert new button */
3756 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3757 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3758 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3759 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3760 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3761 /* if passed string and not index, then add string */
3762 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3763 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3766 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3768 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3771 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3772 ti.cbSize = sizeof (TTTOOLINFOW);
3774 ti.uId = lpTbb->idCommand;
3776 ti.lpszText = LPSTR_TEXTCALLBACKW;
3778 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3782 /* post insert copy */
3783 if (nIndex < infoPtr->nNumButtons - 1) {
3784 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3785 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3790 TOOLBAR_CalcToolbar (hwnd);
3792 InvalidateRect (hwnd, NULL, TRUE);
3798 /* << TOOLBAR_InsertMarkHitTest >> */
3802 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3807 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3811 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3816 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3821 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3825 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3830 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3835 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3839 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3844 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3849 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3853 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3858 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3863 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3867 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3872 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3874 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3881 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3886 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3889 tbab.hInst = (HINSTANCE)lParam;
3890 tbab.nID = (UINT_PTR)wParam;
3892 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3894 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3899 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3901 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3902 WCHAR wAccel = (WCHAR)wParam;
3903 UINT* pIDButton = (UINT*)lParam;
3904 WCHAR wszAccel[] = {'&',wAccel,0};
3907 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3908 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3910 for (i = 0; i < infoPtr->nNumButtons; i++)
3912 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3913 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3914 !(btnPtr->fsState & TBSTATE_HIDDEN))
3916 int iLen = strlenW(wszAccel);
3917 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3924 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3929 if (!strncmpiW(lpszStr, wszAccel, iLen))
3931 *pIDButton = btnPtr->idCommand;
3943 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3948 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3950 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3955 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3957 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3963 /* fixes up an index of a button affected by a move */
3964 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3968 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3970 else if (*pIndex == nIndex)
3971 *pIndex = nMoveIndex;
3975 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3977 else if (*pIndex == nIndex)
3978 *pIndex = nMoveIndex;
3984 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3986 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3989 INT nMoveIndex = (INT)lParam;
3990 TBUTTON_INFO button;
3992 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
3994 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
3995 if ((nIndex == -1) || (nMoveIndex < 0))
3998 if (nMoveIndex > infoPtr->nNumButtons - 1)
3999 nMoveIndex = infoPtr->nNumButtons - 1;
4001 button = infoPtr->buttons[nIndex];
4003 /* move button right */
4004 if (nIndex < nMoveIndex)
4006 nCount = nMoveIndex - nIndex;
4007 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4008 infoPtr->buttons[nMoveIndex] = button;
4010 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4011 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4012 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4013 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4015 else if (nIndex > nMoveIndex) /* move button left */
4017 nCount = nIndex - nMoveIndex;
4018 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4019 infoPtr->buttons[nMoveIndex] = button;
4021 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4022 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4023 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4024 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4027 TOOLBAR_CalcToolbar(hwnd);
4028 InvalidateRect(hwnd, NULL, TRUE);
4035 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4037 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4038 TBUTTON_INFO *btnPtr;
4042 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4046 btnPtr = &infoPtr->buttons[nIndex];
4047 oldState = btnPtr->fsState;
4048 if (LOWORD(lParam) == FALSE)
4049 btnPtr->fsState &= ~TBSTATE_PRESSED;
4051 btnPtr->fsState |= TBSTATE_PRESSED;
4053 if(oldState != btnPtr->fsState)
4054 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4059 /* FIXME: there might still be some confusion her between number of buttons
4060 * and number of bitmaps */
4062 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4064 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4065 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4067 int i = 0, nOldButtons = 0, pos = 0;
4068 int nOldBitmaps, nNewBitmaps;
4069 HIMAGELIST himlDef = 0;
4071 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4072 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4073 lpReplace->nButtons);
4075 if (lpReplace->hInstOld == HINST_COMMCTRL)
4077 FIXME("changing standard bitmaps not implemented\n");
4080 else if (lpReplace->hInstOld != 0)
4082 FIXME("resources not in the current module not implemented\n");
4087 hBitmap = (HBITMAP) lpReplace->nIDNew;
4090 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4091 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4092 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4093 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4094 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4096 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4097 nOldButtons = tbi->nButtons;
4098 tbi->nButtons = lpReplace->nButtons;
4099 tbi->hInst = lpReplace->hInstNew;
4100 tbi->nID = lpReplace->nIDNew;
4101 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4104 pos += tbi->nButtons;
4107 if (nOldButtons == 0)
4109 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4113 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4114 nOldBitmaps = ImageList_GetImageCount(himlDef);
4116 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4118 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4119 ImageList_Remove(himlDef, i);
4123 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4124 HDC hdcImage, hdcBitmap;
4126 /* copy the bitmap before adding it so that the user's bitmap
4127 * doesn't get modified.
4129 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4131 hdcImage = CreateCompatibleDC(0);
4132 hdcBitmap = CreateCompatibleDC(0);
4134 /* create new bitmap */
4135 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4136 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4137 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4139 /* Copy the user's image */
4140 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4141 hdcBitmap, 0, 0, SRCCOPY);
4143 SelectObject (hdcImage, hOldBitmapLoad);
4144 SelectObject (hdcBitmap, hOldBitmapBitmap);
4145 DeleteDC (hdcImage);
4146 DeleteDC (hdcBitmap);
4148 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4149 nNewBitmaps = ImageList_GetImageCount(himlDef);
4150 DeleteObject (hbmLoad);
4153 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4155 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4156 pos, nOldBitmaps, nNewBitmaps);
4158 InvalidateRect(hwnd, NULL, TRUE);
4164 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4168 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4170 if (lpSave == NULL) return 0;
4173 /* save toolbar information */
4174 FIXME("save to \"%s\" \"%s\"\n",
4175 lpSave->pszSubKey, lpSave->pszValueName);
4180 /* restore toolbar information */
4182 FIXME("restore from \"%s\" \"%s\"\n",
4183 lpSave->pszSubKey, lpSave->pszValueName);
4194 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4198 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4204 /* save toolbar information */
4205 FIXME("save to \"%s\" \"%s\"\n",
4206 lpSave->pszSubKey, lpSave->pszValueName);
4211 /* restore toolbar information */
4213 FIXME("restore from \"%s\" \"%s\"\n",
4214 lpSave->pszSubKey, lpSave->pszValueName);
4225 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4227 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4228 BOOL bOldAnchor = infoPtr->bAnchor;
4230 infoPtr->bAnchor = (BOOL)wParam;
4232 return (LRESULT)bOldAnchor;
4237 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4240 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4242 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4245 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4247 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4250 if (infoPtr->nNumButtons > 0)
4251 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4252 infoPtr->nNumButtons,
4253 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4254 LOWORD(lParam), HIWORD(lParam));
4256 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4257 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4260 if ((himlDef == infoPtr->himlInt) &&
4261 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4263 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4264 infoPtr->nBitmapHeight);
4272 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4275 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4276 TBUTTON_INFO *btnPtr;
4282 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4285 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4286 lptbbi->dwMask & 0x80000000);
4290 btnPtr = &infoPtr->buttons[nIndex];
4291 if (lptbbi->dwMask & TBIF_COMMAND)
4292 btnPtr->idCommand = lptbbi->idCommand;
4293 if (lptbbi->dwMask & TBIF_IMAGE)
4294 btnPtr->iBitmap = lptbbi->iImage;
4295 if (lptbbi->dwMask & TBIF_LPARAM)
4296 btnPtr->dwData = lptbbi->lParam;
4297 if (lptbbi->dwMask & TBIF_SIZE)
4298 btnPtr->cx = lptbbi->cx;
4299 if (lptbbi->dwMask & TBIF_STATE)
4300 btnPtr->fsState = lptbbi->fsState;
4301 if (lptbbi->dwMask & TBIF_STYLE)
4302 btnPtr->fsStyle = lptbbi->fsStyle;
4304 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4305 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4306 /* iString is index, zero it to make Str_SetPtr succeed */
4309 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4312 /* save the button rect to see if we need to redraw the whole toolbar */
4313 oldBtnRect = btnPtr->rect;
4314 TOOLBAR_CalcToolbar(hwnd);
4316 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4317 InvalidateRect(hwnd, NULL, TRUE);
4319 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4326 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4329 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4330 TBUTTON_INFO *btnPtr;
4336 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4339 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4340 lptbbi->dwMask & 0x80000000);
4344 btnPtr = &infoPtr->buttons[nIndex];
4345 if (lptbbi->dwMask & TBIF_COMMAND)
4346 btnPtr->idCommand = lptbbi->idCommand;
4347 if (lptbbi->dwMask & TBIF_IMAGE)
4348 btnPtr->iBitmap = lptbbi->iImage;
4349 if (lptbbi->dwMask & TBIF_LPARAM)
4350 btnPtr->dwData = lptbbi->lParam;
4351 if (lptbbi->dwMask & TBIF_SIZE)
4352 btnPtr->cx = lptbbi->cx;
4353 if (lptbbi->dwMask & TBIF_STATE)
4354 btnPtr->fsState = lptbbi->fsState;
4355 if (lptbbi->dwMask & TBIF_STYLE)
4356 btnPtr->fsStyle = lptbbi->fsStyle;
4358 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4359 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4360 /* iString is index, zero it to make Str_SetPtr succeed */
4362 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4365 /* save the button rect to see if we need to redraw the whole toolbar */
4366 oldBtnRect = btnPtr->rect;
4367 TOOLBAR_CalcToolbar(hwnd);
4369 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4370 InvalidateRect(hwnd, NULL, TRUE);
4372 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4379 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4382 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4384 if ((cx < 0) || (cy < 0))
4386 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4390 /* The documentation claims you can only change the button size before
4391 * any button has been added. But this is wrong.
4392 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4393 * it to the toolbar, and it checks that the return value is nonzero - mjm
4394 * Further testing shows that we must actually perform the change too.
4397 * The documentation also does not mention that if 0 is supplied for
4398 * either size, the system changes it to the default of 24 wide and
4399 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4401 infoPtr->nButtonWidth = (cx) ? cx : 24;
4402 infoPtr->nButtonHeight = (cy) ? cy : 22;
4408 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4412 if (infoPtr == NULL) {
4413 TRACE("Toolbar not initialized yet?????\n");
4417 /* if setting to current values, ignore */
4418 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4419 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4420 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4421 infoPtr->cxMin, infoPtr->cxMax);
4425 /* save new values */
4426 infoPtr->cxMin = (INT)LOWORD(lParam);
4427 infoPtr->cxMax = (INT)HIWORD(lParam);
4429 /* if both values are 0 then we are done */
4431 TRACE("setting both min and max to 0, norecalc\n");
4435 /* otherwise we need to recalc the toolbar and in some cases
4436 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4437 which doesn't actually draw - GA). */
4438 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4439 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4441 TOOLBAR_CalcToolbar (hwnd);
4443 InvalidateRect (hwnd, NULL, TRUE);
4450 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4453 INT nIndex = (INT)wParam;
4455 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4458 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4460 if (infoPtr->hwndToolTip) {
4462 FIXME("change tool tip!\n");
4471 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4474 HIMAGELIST himl = (HIMAGELIST)lParam;
4475 HIMAGELIST himlTemp;
4478 if (infoPtr->iVersion >= 5)
4481 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4482 &infoPtr->cimlDis, himl, id);
4484 /* FIXME: redraw ? */
4486 return (LRESULT)himlTemp;
4491 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4496 dwTemp = infoPtr->dwDTFlags;
4497 infoPtr->dwDTFlags =
4498 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4500 return (LRESULT)dwTemp;
4503 /* This function differs a bit from what MSDN says it does:
4504 * 1. lParam contains extended style flags to OR with current style
4505 * (MSDN isn't clear on the OR bit)
4506 * 2. wParam appears to contain extended style flags to be reset
4507 * (MSDN says that this parameter is reserved)
4510 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4512 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4515 dwTemp = infoPtr->dwExStyle;
4516 infoPtr->dwExStyle &= ~wParam;
4517 infoPtr->dwExStyle |= (DWORD)lParam;
4519 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4521 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4522 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4523 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4525 TOOLBAR_CalcToolbar (hwnd);
4527 TOOLBAR_AutoSize(hwnd);
4529 InvalidateRect(hwnd, NULL, TRUE);
4531 return (LRESULT)dwTemp;
4536 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4538 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4539 HIMAGELIST himlTemp;
4540 HIMAGELIST himl = (HIMAGELIST)lParam;
4543 if (infoPtr->iVersion >= 5)
4546 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4548 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4549 &infoPtr->cimlHot, himl, id);
4551 /* FIXME: redraw ? */
4553 return (LRESULT)himlTemp;
4557 /* Makes previous hot button no longer hot, makes the specified
4558 * button hot and sends appropriate notifications. dwReason is one or
4559 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4560 * NOTE 1: this function does not validate nHit
4561 * NOTE 2: the name of this function is completely made up and
4562 * not based on any documentation from Microsoft. */
4564 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4566 if (infoPtr->nHotItem != nHit)
4568 NMTBHOTITEM nmhotitem;
4569 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4570 LRESULT no_highlight;
4572 /* Remove the effect of an old hot button if the button was
4573 drawn with the hot button effect */
4574 if(infoPtr->nHotItem >= 0)
4576 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4577 oldBtnPtr->bHot = FALSE;
4580 infoPtr->nHotItem = nHit;
4582 /* It's not a separator or in nowhere. It's a hot button. */
4584 btnPtr = &infoPtr->buttons[nHit];
4586 nmhotitem.dwFlags = dwReason;
4588 nmhotitem.idOld = oldBtnPtr->idCommand;
4590 nmhotitem.dwFlags |= HICF_ENTERING;
4592 nmhotitem.idNew = btnPtr->idCommand;
4594 nmhotitem.dwFlags |= HICF_LEAVING;
4596 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4598 /* now invalidate the old and new buttons so they will be painted */
4600 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4601 if (btnPtr && !no_highlight)
4603 btnPtr->bHot = TRUE;
4604 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4610 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4613 INT nOldHotItem = infoPtr->nHotItem;
4615 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4618 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4619 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4621 if (nOldHotItem < 0)
4624 return (LRESULT)nOldHotItem;
4629 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4632 HIMAGELIST himlTemp;
4633 HIMAGELIST himl = (HIMAGELIST)lParam;
4636 if (infoPtr->iVersion >= 5)
4639 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4640 &infoPtr->cimlDef, himl, id);
4642 infoPtr->nNumBitmaps = 0;
4643 for (i = 0; i < infoPtr->cimlDef; i++)
4644 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4646 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4647 &infoPtr->nBitmapHeight);
4648 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4649 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4650 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4652 InvalidateRect(hwnd, NULL, TRUE);
4654 return (LRESULT)himlTemp;
4659 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4663 infoPtr->nIndent = (INT)wParam;
4667 /* process only on indent changing */
4668 if(infoPtr->nIndent != (INT)wParam)
4670 infoPtr->nIndent = (INT)wParam;
4671 TOOLBAR_CalcToolbar (hwnd);
4672 InvalidateRect(hwnd, NULL, FALSE);
4679 /* << TOOLBAR_SetInsertMark >> */
4683 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4687 infoPtr->clrInsertMark = (COLORREF)lParam;
4689 /* FIXME : redraw ??*/
4696 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4698 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4700 if (infoPtr == NULL)
4703 infoPtr->nMaxTextRows = (INT)wParam;
4705 TOOLBAR_CalcToolbar(hwnd);
4710 /* MSDN gives slightly wrong info on padding.
4711 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4712 * 2. It is not used to create a blank area between the edge of the button
4713 * and the text or image if TBSTYLE_LIST is set. It is used to control
4714 * the gap between the image and text.
4715 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4716 * to control the bottom and right borders [with the border being
4717 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4718 * is shared evenly on both sides of the button.
4721 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4726 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4727 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4728 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4729 TRACE("cx=%ld, cy=%ld\n",
4730 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4731 return (LRESULT) oldPad;
4736 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4743 if (infoPtr == NULL)
4745 hwndOldNotify = infoPtr->hwndNotify;
4746 infoPtr->hwndNotify = (HWND)wParam;
4748 return (LRESULT)hwndOldNotify;
4753 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4755 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4756 LPRECT lprc = (LPRECT)lParam;
4760 if (LOWORD(wParam) > 1) {
4761 FIXME("multiple rows not supported!\n");
4764 if(infoPtr->nRows != LOWORD(wParam))
4766 infoPtr->nRows = LOWORD(wParam);
4768 /* recalculate toolbar */
4769 TOOLBAR_CalcToolbar (hwnd);
4771 /* repaint toolbar */
4772 InvalidateRect(hwnd, NULL, TRUE);
4775 /* return bounding rectangle */
4777 lprc->left = infoPtr->rcBound.left;
4778 lprc->right = infoPtr->rcBound.right;
4779 lprc->top = infoPtr->rcBound.top;
4780 lprc->bottom = infoPtr->rcBound.bottom;
4788 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4790 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4791 TBUTTON_INFO *btnPtr;
4794 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4798 btnPtr = &infoPtr->buttons[nIndex];
4800 /* if hidden state has changed the invalidate entire window and recalc */
4801 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4802 btnPtr->fsState = LOWORD(lParam);
4803 TOOLBAR_CalcToolbar (hwnd);
4804 InvalidateRect(hwnd, 0, TRUE);
4808 /* process state changing if current state doesn't match new state */
4809 if(btnPtr->fsState != LOWORD(lParam))
4811 btnPtr->fsState = LOWORD(lParam);
4812 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4820 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4822 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4828 inline static LRESULT
4829 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4833 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4835 if (infoPtr == NULL)
4837 infoPtr->hwndToolTip = (HWND)wParam;
4843 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4845 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4848 TRACE("%s hwnd=%p stub!\n",
4849 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4851 bTemp = infoPtr->bUnicode;
4852 infoPtr->bUnicode = (BOOL)wParam;
4859 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4863 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4864 comctl32_color.clrBtnHighlight :
4865 infoPtr->clrBtnHighlight;
4866 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4867 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4873 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4877 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4878 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4879 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4881 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4882 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4883 InvalidateRect(hwnd, NULL, TRUE);
4889 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4892 INT iOldVersion = infoPtr->iVersion;
4894 infoPtr->iVersion = iVersion;
4896 if (infoPtr->iVersion >= 5)
4897 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4904 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4906 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4907 WORD iString = HIWORD(wParam);
4908 WORD buffersize = LOWORD(wParam);
4909 LPSTR str = (LPSTR)lParam;
4912 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4914 if (iString < infoPtr->nNumStrings)
4916 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4918 TRACE("returning %s\n", debugstr_a(str));
4921 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4928 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4930 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4931 WORD iString = HIWORD(wParam);
4932 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4933 LPWSTR str = (LPWSTR)lParam;
4936 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4938 if (iString < infoPtr->nNumStrings)
4940 len = min(len, strlenW(infoPtr->strings[iString]));
4941 ret = (len+1)*sizeof(WCHAR);
4942 memcpy(str, infoPtr->strings[iString], ret);
4945 TRACE("returning %s\n", debugstr_w(str));
4948 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4953 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4954 * is the maximum size of the toolbar? */
4955 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4957 SIZE * pSize = (SIZE*)lParam;
4958 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4963 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4964 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4965 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4968 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4971 INT nOldHotItem = infoPtr->nHotItem;
4973 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4974 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4976 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4979 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4983 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4986 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4987 * which controls the amount of spacing between the image and the text
4988 * of buttons for TBSTYLE_LIST toolbars. */
4989 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4991 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4993 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
4996 FIXME("lParam = 0x%08lx. Please report\n", lParam);
4998 infoPtr->iListGap = (INT)wParam;
5000 TOOLBAR_CalcToolbar(hwnd);
5001 InvalidateRect(hwnd, NULL, TRUE);
5006 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5007 * of image lists associated with the various states. */
5008 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5012 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5014 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5018 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5021 LPSIZE lpsize = (LPSIZE)lParam;
5027 * Testing shows the following:
5028 * wParam = 0 adjust cx value
5029 * = 1 set cy value to max size.
5030 * lParam pointer to SIZE structure
5033 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5034 wParam, lParam, lpsize->cx, lpsize->cy);
5038 if (lpsize->cx == -1) {
5039 /* **** this is wrong, native measures each button and sets it */
5040 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5042 else if(HIWORD(lpsize->cx)) {
5044 HWND hwndParent = GetParent(hwnd);
5046 GetWindowRect(hwnd, &rc);
5047 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5048 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5049 rc.left, rc.top, rc.right, rc.bottom);
5050 lpsize->cx = max(rc.right-rc.left,
5051 infoPtr->rcBound.right - infoPtr->rcBound.left);
5054 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5058 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5059 /* lpsize->cy = infoPtr->nHeight; */
5062 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5066 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5067 lpsize->cx, lpsize->cy);
5071 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5073 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5075 InvalidateRect(hwnd, NULL, TRUE);
5081 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5084 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5087 TRACE("hwnd = %p\n", hwnd);
5089 /* initialize info structure */
5090 infoPtr->nButtonHeight = 22;
5091 infoPtr->nButtonWidth = 24;
5092 infoPtr->nBitmapHeight = 15;
5093 infoPtr->nBitmapWidth = 16;
5095 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5096 infoPtr->nMaxTextRows = 1;
5097 infoPtr->cxMin = -1;
5098 infoPtr->cxMax = -1;
5099 infoPtr->nNumBitmaps = 0;
5100 infoPtr->nNumStrings = 0;
5102 infoPtr->bCaptured = FALSE;
5103 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5104 infoPtr->nButtonDown = -1;
5105 infoPtr->nButtonDrag = -1;
5106 infoPtr->nOldHit = -1;
5107 infoPtr->nHotItem = -1;
5108 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5109 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
5110 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5111 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
5112 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5113 infoPtr->iVersion = 0;
5114 infoPtr->hwndSelf = hwnd;
5115 infoPtr->bDoRedraw = TRUE;
5116 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5117 infoPtr->clrBtnShadow = CLR_DEFAULT;
5118 /* not sure where the +1 comes from, but this comes to the same value
5119 * as native so this is probably correct */
5120 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5121 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5122 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5123 infoPtr->dwStyle = dwStyle;
5124 GetClientRect(hwnd, &infoPtr->client_rect);
5125 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5127 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5128 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5130 if (dwStyle & TBSTYLE_TOOLTIPS) {
5131 /* Create tooltip control */
5132 infoPtr->hwndToolTip =
5133 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5134 CW_USEDEFAULT, CW_USEDEFAULT,
5135 CW_USEDEFAULT, CW_USEDEFAULT,
5138 /* Send NM_TOOLTIPSCREATED notification */
5139 if (infoPtr->hwndToolTip) {
5140 NMTOOLTIPSCREATED nmttc;
5142 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5144 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5145 NM_TOOLTIPSCREATED);
5149 TOOLBAR_CheckStyle (hwnd, dwStyle);
5151 TOOLBAR_CalcToolbar(hwnd);
5158 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5162 /* delete tooltip control */
5163 if (infoPtr->hwndToolTip)
5164 DestroyWindow (infoPtr->hwndToolTip);
5166 /* delete temporary buffer for tooltip text */
5167 if (infoPtr->pszTooltipText)
5168 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5170 /* delete button data */
5171 if (infoPtr->buttons)
5172 Free (infoPtr->buttons);
5174 /* delete strings */
5175 if (infoPtr->strings) {
5177 for (i = 0; i < infoPtr->nNumStrings; i++)
5178 if (infoPtr->strings[i])
5179 Free (infoPtr->strings[i]);
5181 Free (infoPtr->strings);
5184 /* destroy internal image list */
5185 if (infoPtr->himlInt)
5186 ImageList_Destroy (infoPtr->himlInt);
5188 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5189 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5190 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5192 /* delete default font */
5194 DeleteObject (infoPtr->hDefaultFont);
5196 /* free toolbar info data */
5198 SetWindowLongPtrW (hwnd, 0, 0);
5205 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5208 NMTBCUSTOMDRAW tbcd;
5212 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5213 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5214 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5215 tbcd.nmcd.hdc = (HDC)wParam;
5216 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5217 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5219 /* FIXME: in general the return flags *can* be or'ed together */
5220 switch (infoPtr->dwBaseCustDraw)
5222 case CDRF_DODEFAULT:
5224 case CDRF_SKIPDEFAULT:
5227 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5232 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5233 * to my parent for processing.
5235 if (infoPtr->bTransparent) {
5237 HDC hdc = (HDC)wParam;
5242 parent = GetParent(hwnd);
5243 MapWindowPoints(hwnd, parent, &pt, 1);
5244 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5245 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5246 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5249 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5251 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5252 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5253 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5254 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5255 tbcd.nmcd.hdc = (HDC)wParam;
5256 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5257 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5258 switch (infoPtr->dwBaseCustDraw)
5260 case CDRF_DODEFAULT:
5262 case CDRF_SKIPDEFAULT:
5265 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5274 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5278 return (LRESULT)infoPtr->hFont;
5283 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5288 pt.x = (INT)LOWORD(lParam);
5289 pt.y = (INT)HIWORD(lParam);
5290 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5293 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5294 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5295 TOOLBAR_Customize (hwnd);
5302 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5305 TBUTTON_INFO *btnPtr;
5309 BOOL bDragKeyPressed;
5311 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5312 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5314 bDragKeyPressed = (wParam & MK_SHIFT);
5316 if (infoPtr->hwndToolTip)
5317 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5318 WM_LBUTTONDOWN, wParam, lParam);
5320 pt.x = (INT)LOWORD(lParam);
5321 pt.y = (INT)HIWORD(lParam);
5322 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5324 btnPtr = &infoPtr->buttons[nHit];
5326 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5328 infoPtr->nButtonDrag = nHit;
5331 /* If drag cursor has not been loaded, load it.
5332 * Note: it doesn't need to be freed */
5334 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5335 SetCursor(hCursorDrag);
5340 infoPtr->nOldHit = nHit;
5342 CopyRect(&arrowRect, &btnPtr->rect);
5343 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5345 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5346 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5347 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5348 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5349 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5350 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5354 /* draw in pressed state */
5355 btnPtr->fsState |= TBSTATE_PRESSED;
5356 RedrawWindow(hwnd,&btnPtr->rect,0,
5357 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5359 nmtb.iItem = btnPtr->idCommand;
5360 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5363 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5364 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5366 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5368 if (res != TBDDRET_TREATPRESSED)
5372 /* redraw button in unpressed state */
5373 btnPtr->fsState &= ~TBSTATE_PRESSED;
5374 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5376 /* find and set hot item
5377 * NOTE: native doesn't do this, but that is a bug */
5379 ScreenToClient(hwnd, &pt);
5380 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5381 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5383 /* remove any left mouse button down messages so that we can
5384 * get a toggle effect on the button */
5385 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE))
5390 /* otherwise drop through and process as pushed */
5392 infoPtr->bCaptured = TRUE;
5393 infoPtr->nButtonDown = nHit;
5395 btnPtr->fsState |= TBSTATE_PRESSED;
5397 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5399 if (btnPtr->fsState & TBSTATE_ENABLED)
5400 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5407 nmtb.iItem = btnPtr->idCommand;
5408 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5409 nmtb.tbButton.idCommand = btnPtr->idCommand;
5410 nmtb.tbButton.fsState = btnPtr->fsState;
5411 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5412 nmtb.tbButton.dwData = btnPtr->dwData;
5413 nmtb.tbButton.iString = btnPtr->iString;
5414 nmtb.cchText = 0; /* !!! not correct */
5415 nmtb.pszText = 0; /* !!! not correct */
5416 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5423 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5425 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5426 TBUTTON_INFO *btnPtr;
5430 BOOL bSendMessage = TRUE;
5435 if (infoPtr->hwndToolTip)
5436 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5437 WM_LBUTTONUP, wParam, lParam);
5439 pt.x = (INT)LOWORD(lParam);
5440 pt.y = (INT)HIWORD(lParam);
5441 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5443 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5445 if (infoPtr->nButtonDrag >= 0) {
5449 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5452 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5454 GetClientRect(hwnd, &rcClient);
5455 if (PtInRect(&rcClient, pt))
5462 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5465 if (nButton == infoPtr->nButtonDrag)
5467 /* if the button is moved sightly left and we have a
5468 * separator there then remove it */
5469 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5471 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5472 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5474 else /* else insert a separator before the dragged button */
5477 memset(&tbb, 0, sizeof(tbb));
5478 tbb.fsStyle = BTNS_SEP;
5480 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5487 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5488 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5490 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5493 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5498 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5499 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5502 /* button under cursor changed so need to re-set hot item */
5503 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5504 infoPtr->nButtonDrag = -1;
5506 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5508 else if (infoPtr->nButtonDown >= 0) {
5509 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5510 btnPtr->fsState &= ~TBSTATE_PRESSED;
5512 if (btnPtr->fsStyle & BTNS_CHECK) {
5513 if (btnPtr->fsStyle & BTNS_GROUP) {
5514 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5516 if (nOldIndex == nHit)
5517 bSendMessage = FALSE;
5518 if ((nOldIndex != nHit) &&
5520 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5521 btnPtr->fsState |= TBSTATE_CHECKED;
5524 if (btnPtr->fsState & TBSTATE_CHECKED)
5525 btnPtr->fsState &= ~TBSTATE_CHECKED;
5527 btnPtr->fsState |= TBSTATE_CHECKED;
5531 if (nOldIndex != -1)
5532 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5535 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5536 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5537 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5539 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5541 infoPtr->nButtonDown = -1;
5543 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5544 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5545 NM_RELEASEDCAPTURE);
5547 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5550 nmtb.iItem = btnPtr->idCommand;
5551 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5552 nmtb.tbButton.idCommand = btnPtr->idCommand;
5553 nmtb.tbButton.fsState = btnPtr->fsState;
5554 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5555 nmtb.tbButton.dwData = btnPtr->dwData;
5556 nmtb.tbButton.iString = btnPtr->iString;
5557 nmtb.cchText = 0; /* !!! not correct */
5558 nmtb.pszText = 0; /* !!! not correct */
5559 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5562 if (btnPtr->fsState & TBSTATE_ENABLED)
5564 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5565 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5567 /* !!! Undocumented - toolbar at 4.71 level and above sends
5568 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5569 * Only NM_RCLICK is documented.
5571 nmmouse.dwItemSpec = btnPtr->idCommand;
5572 nmmouse.dwItemData = btnPtr->dwData;
5573 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5580 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5587 pt.x = LOWORD(lParam);
5588 pt.y = HIWORD(lParam);
5590 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5592 if (nmmouse.dwHitInfo < 0) {
5593 nmmouse.dwItemSpec = -1;
5595 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5596 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5599 ClientToScreen(hwnd, &pt);
5600 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5602 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5608 TOOLBAR_CaptureChanged(HWND hwnd)
5610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5611 TBUTTON_INFO *btnPtr;
5613 infoPtr->bCaptured = FALSE;
5615 if (infoPtr->nButtonDown >= 0)
5617 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5618 btnPtr->fsState &= ~TBSTATE_PRESSED;
5620 infoPtr->nOldHit = -1;
5622 if (btnPtr->fsState & TBSTATE_ENABLED)
5623 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5629 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5632 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5635 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5637 if (infoPtr->nOldHit < 0)
5640 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5642 /* If the last button we were over is depressed then make it not */
5643 /* depressed and redraw it */
5644 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5646 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5648 btnPtr->fsState &= ~TBSTATE_PRESSED;
5650 rc1 = hotBtnPtr->rect;
5651 InflateRect (&rc1, 1, 1);
5652 InvalidateRect (hwnd, &rc1, TRUE);
5655 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5661 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5663 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5665 TRACKMOUSEEVENT trackinfo;
5667 TBUTTON_INFO *btnPtr;
5669 /* fill in the TRACKMOUSEEVENT struct */
5670 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5671 trackinfo.dwFlags = TME_QUERY;
5672 trackinfo.hwndTrack = hwnd;
5673 trackinfo.dwHoverTime = HOVER_DEFAULT;
5675 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5676 _TrackMouseEvent(&trackinfo);
5678 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5679 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5680 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5682 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5683 /* and can properly deactivate the hot toolbar button */
5684 _TrackMouseEvent(&trackinfo);
5687 if (infoPtr->hwndToolTip)
5688 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5689 WM_MOUSEMOVE, wParam, lParam);
5691 pt.x = (INT)LOWORD(lParam);
5692 pt.y = (INT)HIWORD(lParam);
5694 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5696 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5698 if (infoPtr->nOldHit != nHit)
5700 if (infoPtr->bCaptured)
5702 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5703 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5704 btnPtr->fsState &= ~TBSTATE_PRESSED;
5705 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5707 else if (nHit == infoPtr->nButtonDown) {
5708 btnPtr->fsState |= TBSTATE_PRESSED;
5709 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5711 infoPtr->nOldHit = nHit;
5719 inline static LRESULT
5720 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5722 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5723 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5725 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5729 inline static LRESULT
5730 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5732 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5733 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5735 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5740 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5742 TOOLBAR_INFO *infoPtr;
5743 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5746 /* allocate memory for info structure */
5747 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5748 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5751 infoPtr->dwStructSize = sizeof(TBBUTTON);
5754 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5755 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5756 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5757 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5760 /* native control does:
5761 * Get a lot of colors and brushes
5763 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5764 * CreateFontIndirectA(adr1)
5765 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5766 * hdc = GetDC(toolbar)
5767 * GetSystemMetrics(0x48)
5768 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5769 * 0, 0, 0, 0, "MARLETT")
5770 * oldfnt = SelectObject(hdc, fnt2)
5771 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5772 * GetTextMetricsA(hdc, adr3)
5773 * SelectObject(hdc, oldfnt)
5774 * DeleteObject(fnt2)
5776 * InvalidateRect(toolbar, 0, 1)
5777 * SetWindowLongA(toolbar, 0, addr)
5778 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5781 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5782 * ie 2 0x4600094c 0x4600094c 0x4600894d
5783 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5784 * rebar 0x50008844 0x40008844 0x50008845
5785 * pager 0x50000844 0x40000844 0x50008845
5786 * IC35mgr 0x5400084e **nochange**
5787 * on entry to _NCCREATE 0x5400084e
5788 * rowlist 0x5400004e **nochange**
5789 * on entry to _NCCREATE 0x5400004e
5793 /* I think the code below is a bug, but it is the way that the native
5794 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5795 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5796 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5797 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5798 * Some how, the only cases of this seem to be MFC programs.
5800 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5801 * does not occur in the WM_STYLECHANGING routine.
5802 * (Guy Albertelli 9/2001)
5805 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5806 styleadd |= TBSTYLE_TRANSPARENT;
5807 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5808 styleadd |= CCS_TOP; /* default to top */
5809 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5812 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5817 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5819 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5823 if (dwStyle & WS_MINIMIZE)
5824 return 0; /* Nothing to do */
5826 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5828 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5831 if (!(dwStyle & CCS_NODIVIDER))
5833 GetWindowRect (hwnd, &rcWindow);
5834 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5835 if( dwStyle & WS_BORDER )
5836 OffsetRect (&rcWindow, 1, 1);
5837 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5840 ReleaseDC( hwnd, hdc );
5846 /* handles requests from the tooltip control on what text to display */
5847 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5849 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5851 TRACE("button index = %d\n", index);
5853 if (infoPtr->pszTooltipText)
5855 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5856 infoPtr->pszTooltipText = NULL;
5862 if (infoPtr->bNtfUnicode)
5864 WCHAR wszBuffer[INFOTIPSIZE+1];
5865 NMTBGETINFOTIPW tbgit;
5866 int len; /* in chars */
5868 wszBuffer[0] = '\0';
5869 wszBuffer[INFOTIPSIZE] = '\0';
5871 tbgit.pszText = wszBuffer;
5872 tbgit.cchTextMax = INFOTIPSIZE;
5873 tbgit.iItem = lpnmtdi->hdr.idFrom;
5874 tbgit.lParam = infoPtr->buttons[index].dwData;
5876 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5878 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5880 len = strlenW(tbgit.pszText);
5881 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5883 /* need to allocate temporary buffer in infoPtr as there
5884 * isn't enough space in buffer passed to us by the
5885 * tooltip control */
5886 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5887 if (infoPtr->pszTooltipText)
5889 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5890 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5896 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5902 CHAR szBuffer[INFOTIPSIZE+1];
5903 NMTBGETINFOTIPA tbgit;
5904 int len; /* in chars */
5907 szBuffer[INFOTIPSIZE] = '\0';
5909 tbgit.pszText = szBuffer;
5910 tbgit.cchTextMax = INFOTIPSIZE;
5911 tbgit.iItem = lpnmtdi->hdr.idFrom;
5912 tbgit.lParam = infoPtr->buttons[index].dwData;
5914 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5916 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5918 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5919 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5921 /* need to allocate temporary buffer in infoPtr as there
5922 * isn't enough space in buffer passed to us by the
5923 * tooltip control */
5924 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5925 if (infoPtr->pszTooltipText)
5927 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5928 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5934 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
5939 /* if button has text, but it is not shown then automatically
5940 * use that text as tooltip */
5941 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
5942 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
5944 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
5945 int len = pszText ? strlenW(pszText) : 0;
5947 TRACE("using button hidden text %s\n", debugstr_w(pszText));
5949 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5951 /* need to allocate temporary buffer in infoPtr as there
5952 * isn't enough space in buffer passed to us by the
5953 * tooltip control */
5954 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5955 if (infoPtr->pszTooltipText)
5957 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
5958 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5964 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
5969 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
5971 /* last resort: send notification on to app */
5972 /* FIXME: find out what is really used here */
5973 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
5977 inline static LRESULT
5978 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5980 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5981 LPNMHDR lpnmh = (LPNMHDR)lParam;
5983 switch (lpnmh->code)
5987 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5989 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5990 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5991 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5995 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5996 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6004 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6006 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6007 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6008 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6009 lppgs->iScroll, lppgs->iDir);
6013 case TTN_GETDISPINFOW:
6014 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6016 case TTN_GETDISPINFOA:
6017 FIXME("TTN_GETDISPINFOA - stub\n");
6027 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6029 /* remove this routine when Toolbar is improved to pass infoPtr
6030 * around instead of hwnd.
6032 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6033 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6038 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6042 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6044 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6047 if (lParam == NF_REQUERY) {
6048 i = SendMessageA(infoPtr->hwndNotify,
6049 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6050 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6051 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6055 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6058 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6063 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6069 /* fill ps.rcPaint with a default rect */
6070 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6072 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6074 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6075 ps.rcPaint.left, ps.rcPaint.top,
6076 ps.rcPaint.right, ps.rcPaint.bottom);
6078 TOOLBAR_Refresh (hwnd, hdc, &ps);
6079 if (!wParam) EndPaint (hwnd, &ps);
6086 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6087 /*****************************************************
6090 * Handles the WM_SETREDRAW message.
6093 * According to testing V4.71 of COMCTL32 returns the
6094 * *previous* status of the redraw flag (either 0 or 1)
6095 * instead of the MSDN documented value of 0 if handled.
6096 * (For laughs see the "consistency" with same function
6099 *****************************************************/
6101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6102 BOOL oldredraw = infoPtr->bDoRedraw;
6104 TRACE("set to %s\n",
6105 (wParam) ? "TRUE" : "FALSE");
6106 infoPtr->bDoRedraw = (BOOL) wParam;
6108 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6110 return (oldredraw) ? 1 : 0;
6115 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6117 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6118 DWORD dwStyle = infoPtr->dwStyle;
6127 /* Resize deadlock check */
6128 if (infoPtr->bAutoSize) {
6129 infoPtr->bAutoSize = FALSE;
6133 /* FIXME: optimize to only update size if the new size doesn't */
6134 /* match the current size */
6136 flags = (INT) wParam;
6138 /* FIXME for flags =
6139 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6142 TRACE("sizing toolbar!\n");
6144 if (flags == SIZE_RESTORED) {
6145 /* width and height don't apply */
6146 parent = GetParent (hwnd);
6147 GetClientRect(parent, &parent_rect);
6148 x = parent_rect.left;
6149 y = parent_rect.top;
6151 if (dwStyle & CCS_NORESIZE) {
6152 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6155 * this sets the working width of the toolbar, and
6156 * Calc Toolbar will not adjust it, only the height
6158 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6159 cy = infoPtr->nHeight;
6160 cx = infoPtr->nWidth;
6161 TOOLBAR_CalcToolbar (hwnd);
6162 infoPtr->nWidth = cx;
6163 infoPtr->nHeight = cy;
6166 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6167 TOOLBAR_CalcToolbar (hwnd);
6168 cy = infoPtr->nHeight;
6169 cx = infoPtr->nWidth;
6171 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6172 GetWindowRect(hwnd, &window_rect);
6173 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6174 y = window_rect.top;
6176 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6177 GetWindowRect(hwnd, &window_rect);
6178 y = parent_rect.bottom -
6179 ( window_rect.bottom - window_rect.top);
6183 if (dwStyle & CCS_NOPARENTALIGN) {
6184 uPosFlags |= SWP_NOMOVE;
6185 cy = infoPtr->nHeight;
6186 cx = infoPtr->nWidth;
6189 if (!(dwStyle & CCS_NODIVIDER))
6190 cy += GetSystemMetrics(SM_CYEDGE);
6192 if (dwStyle & WS_BORDER)
6195 cy += GetSystemMetrics(SM_CYEDGE);
6196 cx += GetSystemMetrics(SM_CYEDGE);
6199 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6201 RECT delta_width, delta_height, client, dummy;
6202 DWORD min_x, max_x, min_y, max_y;
6203 TBUTTON_INFO *btnPtr;
6206 GetClientRect(hwnd, &client);
6207 if(client.right > infoPtr->client_rect.right)
6209 min_x = infoPtr->client_rect.right;
6210 max_x = client.right;
6214 max_x = infoPtr->client_rect.right;
6215 min_x = client.right;
6217 if(client.bottom > infoPtr->client_rect.bottom)
6219 min_y = infoPtr->client_rect.bottom;
6220 max_y = client.bottom;
6224 max_y = infoPtr->client_rect.bottom;
6225 min_y = client.bottom;
6228 SetRect(&delta_width, min_x, 0, max_x, min_y);
6229 SetRect(&delta_height, 0, min_y, max_x, max_y);
6231 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6232 btnPtr = infoPtr->buttons;
6233 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6234 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6235 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6236 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6239 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6240 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6242 GetClientRect(hwnd, &infoPtr->client_rect);
6248 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6252 if (nType == GWL_STYLE) {
6253 if (lpStyle->styleNew & TBSTYLE_LIST) {
6254 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
6257 infoPtr->dwDTFlags = DT_CENTER;
6259 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
6260 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6261 (TBSTYLE_FLAT | TBSTYLE_LIST));
6262 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6264 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6266 infoPtr->dwStyle = lpStyle->styleNew;
6269 TOOLBAR_CalcToolbar(hwnd);
6271 TOOLBAR_AutoSize (hwnd);
6273 InvalidateRect(hwnd, NULL, TRUE);
6280 TOOLBAR_SysColorChange (HWND hwnd)
6282 COMCTL32_RefreshSysColors();
6289 static LRESULT WINAPI
6290 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6294 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6295 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6297 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6298 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6303 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6305 case TB_ADDBUTTONSA:
6306 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6308 case TB_ADDBUTTONSW:
6309 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6312 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6315 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6318 return TOOLBAR_AutoSize (hwnd);
6320 case TB_BUTTONCOUNT:
6321 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6323 case TB_BUTTONSTRUCTSIZE:
6324 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6326 case TB_CHANGEBITMAP:
6327 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6329 case TB_CHECKBUTTON:
6330 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6332 case TB_COMMANDTOINDEX:
6333 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6336 return TOOLBAR_Customize (hwnd);
6338 case TB_DELETEBUTTON:
6339 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6341 case TB_ENABLEBUTTON:
6342 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6344 case TB_GETANCHORHIGHLIGHT:
6345 return TOOLBAR_GetAnchorHighlight (hwnd);
6348 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6350 case TB_GETBITMAPFLAGS:
6351 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6354 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6356 case TB_GETBUTTONINFOA:
6357 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6359 case TB_GETBUTTONINFOW:
6360 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6362 case TB_GETBUTTONSIZE:
6363 return TOOLBAR_GetButtonSize (hwnd);
6365 case TB_GETBUTTONTEXTA:
6366 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6368 case TB_GETBUTTONTEXTW:
6369 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6371 case TB_GETDISABLEDIMAGELIST:
6372 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6374 case TB_GETEXTENDEDSTYLE:
6375 return TOOLBAR_GetExtendedStyle (hwnd);
6377 case TB_GETHOTIMAGELIST:
6378 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6381 return TOOLBAR_GetHotItem (hwnd);
6383 case TB_GETIMAGELIST:
6384 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6386 /* case TB_GETINSERTMARK: */ /* 4.71 */
6387 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6389 case TB_GETITEMRECT:
6390 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6393 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6395 /* case TB_GETOBJECT: */ /* 4.71 */
6398 return TOOLBAR_GetPadding (hwnd);
6401 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6404 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6407 return TOOLBAR_GetState (hwnd, wParam, lParam);
6410 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6413 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6416 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6418 case TB_GETTEXTROWS:
6419 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6421 case TB_GETTOOLTIPS:
6422 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6424 case TB_GETUNICODEFORMAT:
6425 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6428 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6431 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6433 case TB_INDETERMINATE:
6434 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6436 case TB_INSERTBUTTONA:
6437 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6439 case TB_INSERTBUTTONW:
6440 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6442 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6444 case TB_ISBUTTONCHECKED:
6445 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6447 case TB_ISBUTTONENABLED:
6448 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6450 case TB_ISBUTTONHIDDEN:
6451 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6453 case TB_ISBUTTONHIGHLIGHTED:
6454 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6456 case TB_ISBUTTONINDETERMINATE:
6457 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6459 case TB_ISBUTTONPRESSED:
6460 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6463 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6465 case TB_MAPACCELERATORA:
6466 case TB_MAPACCELERATORW:
6467 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6470 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6473 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6475 case TB_PRESSBUTTON:
6476 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6478 case TB_REPLACEBITMAP:
6479 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6481 case TB_SAVERESTOREA:
6482 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6484 case TB_SAVERESTOREW:
6485 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6487 case TB_SETANCHORHIGHLIGHT:
6488 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6490 case TB_SETBITMAPSIZE:
6491 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6493 case TB_SETBUTTONINFOA:
6494 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6496 case TB_SETBUTTONINFOW:
6497 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6499 case TB_SETBUTTONSIZE:
6500 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6502 case TB_SETBUTTONWIDTH:
6503 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6506 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6508 case TB_SETDISABLEDIMAGELIST:
6509 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6511 case TB_SETDRAWTEXTFLAGS:
6512 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6514 case TB_SETEXTENDEDSTYLE:
6515 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6517 case TB_SETHOTIMAGELIST:
6518 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6521 return TOOLBAR_SetHotItem (hwnd, wParam);
6523 case TB_SETIMAGELIST:
6524 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6527 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6529 /* case TB_SETINSERTMARK: */ /* 4.71 */
6531 case TB_SETINSERTMARKCOLOR:
6532 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6534 case TB_SETMAXTEXTROWS:
6535 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6538 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6541 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6544 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6547 return TOOLBAR_SetState (hwnd, wParam, lParam);
6550 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6552 case TB_SETTOOLTIPS:
6553 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6555 case TB_SETUNICODEFORMAT:
6556 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6559 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6562 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6565 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6568 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6571 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6574 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6576 /* Common Control Messages */
6578 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6579 case CCM_GETCOLORSCHEME:
6580 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6582 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6583 case CCM_SETCOLORSCHEME:
6584 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6586 case CCM_GETVERSION:
6587 return TOOLBAR_GetVersion (hwnd);
6589 case CCM_SETVERSION:
6590 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6596 return TOOLBAR_Create (hwnd, wParam, lParam);
6599 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6602 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6605 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6607 /* case WM_KEYDOWN: */
6608 /* case WM_KILLFOCUS: */
6610 case WM_LBUTTONDBLCLK:
6611 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6613 case WM_LBUTTONDOWN:
6614 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6617 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6620 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6623 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6626 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6628 case WM_CAPTURECHANGED:
6629 return TOOLBAR_CaptureChanged(hwnd);
6632 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6635 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6638 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6641 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6644 return TOOLBAR_Notify (hwnd, wParam, lParam);
6646 case WM_NOTIFYFORMAT:
6647 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6650 return TOOLBAR_Paint (hwnd, wParam);
6653 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6656 return TOOLBAR_Size (hwnd, wParam, lParam);
6658 case WM_STYLECHANGED:
6659 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6661 case WM_SYSCOLORCHANGE:
6662 return TOOLBAR_SysColorChange (hwnd);
6664 /* case WM_WININICHANGE: */
6669 case WM_MEASUREITEM:
6671 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6673 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6674 case PGM_FORWARDMOUSE:
6675 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6678 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6679 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6680 uMsg, wParam, lParam);
6681 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6688 TOOLBAR_Register (void)
6692 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6693 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6694 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6695 wndClass.cbClsExtra = 0;
6696 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6697 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6698 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6699 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6701 RegisterClassA (&wndClass);
6706 TOOLBAR_Unregister (void)
6708 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6711 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6716 /* Check if the entry already exists */
6717 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6719 /* If this is a new entry we must create it and insert into the array */
6724 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6727 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6728 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6743 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6747 for (i = 0; i < *cies; i++)
6757 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6765 for (i = 0; i < cies; i++)
6767 if (pies[i]->id == id)
6779 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6781 HIMAGELIST himlDef = 0;
6782 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6785 himlDef = pie->himl;
6791 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6793 if (infoPtr->bUnicode)
6794 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6801 nmtba.iItem = nmtb->iItem;
6802 nmtba.pszText = Buffer;
6803 nmtba.cchText = 256;
6804 ZeroMemory(nmtba.pszText, nmtba.cchText);
6806 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6808 int ccht = strlen(nmtba.pszText);
6810 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6811 nmtb->pszText, nmtb->cchText);
6813 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6822 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6823 int iItem, PCUSTOMBUTTON btnInfo)
6828 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6830 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);