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
58 * - Button wrapping (under construction).
60 * - iListGap custom draw support.
61 * - Customization dialog:
62 * - Minor buglet in 'available buttons' list:
63 * Buttons are not listed in MS-like order. MS seems to use a single
64 * internal list to store the button information of both listboxes.
65 * - Drag list support.
68 * - Run tests using Waite Group Windows95 API Bible Volume 2.
69 * The second cdrom contains executables addstr.exe, btncount.exe,
70 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
71 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
72 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
73 * setparnt.exe, setrows.exe, toolwnd.exe.
74 * - Microsofts controlspy examples.
75 * - Charles Petzold's 'Programming Windows': gadgets.exe
85 #include "wine/unicode.h"
89 #include "wine/debug.h"
91 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
93 static HCURSOR hCursorDrag = NULL;
102 BYTE bDropDownPressed;
107 INT cx; /* manually set size */
121 } IMLENTRY, *PIMLENTRY;
125 DWORD dwStructSize; /* size of TBBUTTON struct */
126 INT nHeight; /* height of the toolbar */
127 INT nWidth; /* width of the toolbar */
134 INT nRows; /* number of button rows */
135 INT nMaxTextRows; /* maximum number of text rows */
136 INT cxMin; /* minimum button width */
137 INT cxMax; /* maximum button width */
138 INT nNumButtons; /* number of buttons */
139 INT nNumBitmaps; /* number of bitmaps */
140 INT nNumStrings; /* number of strings */
142 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
143 BOOL bCaptured; /* mouse captured? */
144 INT nButtonDown; /* toolbar button being pressed or -1 if none */
145 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
147 INT nHotItem; /* index of the "hot" item */
148 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
149 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
150 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
151 SIZE szPadding; /* padding values around button */
152 INT iListGap; /* default gap between text and image for toolbar with list style */
154 HFONT hFont; /* text font */
155 HIMAGELIST himlInt; /* image list created internally */
156 PIMLENTRY *himlDef; /* default image list array */
157 INT cimlDef; /* default image list array count */
158 PIMLENTRY *himlHot; /* hot image list array */
159 INT cimlHot; /* hot image list array count */
160 PIMLENTRY *himlDis; /* disabled image list array */
161 INT cimlDis; /* disabled image list array count */
162 HWND hwndToolTip; /* handle to tool tip control */
163 HWND hwndNotify; /* handle to the window that gets notifications */
164 HWND hwndSelf; /* my own handle */
165 BOOL bBtnTranspnt; /* button transparency flag */
166 BOOL bAutoSize; /* auto size deadlock indicator */
167 BOOL bAnchor; /* anchor highlight enabled */
168 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
169 BOOL bDoRedraw; /* Redraw status */
170 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
171 DWORD dwStyle; /* regular toolbar style */
172 DWORD dwExStyle; /* extended toolbar style */
173 DWORD dwDTFlags; /* DrawText flags */
175 COLORREF clrInsertMark; /* insert mark color */
176 COLORREF clrBtnHighlight; /* color for Flat Separator */
177 COLORREF clrBtnShadow; /* color for Flag Separator */
178 RECT rcBound; /* bounding rectangle */
180 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
181 * for TTN_GETDISPINFOW notification */
182 TBUTTON_INFO *buttons; /* pointer to button array */
183 LPWSTR *strings; /* pointer to string array */
184 TBITMAP_INFO *bitmaps;
185 } TOOLBAR_INFO, *PTOOLBAR_INFO;
188 /* used by customization dialog */
191 PTOOLBAR_INFO tbInfo;
193 } CUSTDLG_INFO, *PCUSTDLG_INFO;
201 } CUSTOMBUTTON, *PCUSTOMBUTTON;
210 #define SEPARATOR_WIDTH 8
212 #define BOTTOM_BORDER 2
213 #define DDARROW_WIDTH 11
214 #define ARROW_HEIGHT 3
216 /* gap between border of button and text/image */
219 /* how wide to treat the bitmap if it isn't present */
220 #define LIST_IMAGE_ABSENT_WIDTH 2
222 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongPtrW(hwnd,0))
223 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
224 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
226 static inline int TOOLBAR_GetListTextOffset(TOOLBAR_INFO *infoPtr, INT iListGap)
228 return GetSystemMetrics(SM_CXEDGE) + iListGap - infoPtr->szPadding.cx/2;
231 /* Used to find undocumented extended styles */
232 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
233 TBSTYLE_EX_UNDOC1 | \
234 TBSTYLE_EX_MIXEDBUTTONS | \
235 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
237 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
238 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
239 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
240 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
241 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
243 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
244 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
245 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
246 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
247 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
248 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
249 static LRESULT TOOLBAR_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam);
252 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
256 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
258 LPWSTR lpText = NULL;
260 /* NOTE: iString == -1 is undocumented */
261 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
262 lpText = (LPWSTR)btnPtr->iString;
263 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
264 lpText = infoPtr->strings[btnPtr->iString];
270 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
272 if (TRACE_ON(toolbar)){
273 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
274 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
275 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
276 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
278 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
279 btn_num, bP->idCommand,
280 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
281 bP->rect.left, bP->rect.top,
282 bP->rect.right, bP->rect.bottom);
288 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
290 if (TRACE_ON(toolbar)) {
293 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
295 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
296 iP->nNumStrings, iP->dwStyle);
297 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
299 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
300 (iP->bDoRedraw) ? "TRUE" : "FALSE");
301 for(i=0; i<iP->nNumButtons; i++) {
302 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
308 /***********************************************************************
311 * This function validates that the styles set are implemented and
312 * issues FIXME's warning of possible problems. In a perfect world this
313 * function should be null.
316 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
318 if (dwStyle & TBSTYLE_REGISTERDROP)
319 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
324 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
326 if(!IsWindow(infoPtr->hwndSelf))
327 return 0; /* we have just been destroyed */
329 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
330 nmhdr->hwndFrom = infoPtr->hwndSelf;
333 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
334 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
336 if (infoPtr->bNtfUnicode)
337 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
338 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
340 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
341 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
344 /***********************************************************************
345 * TOOLBAR_GetBitmapIndex
347 * This function returns the bitmap index associated with a button.
348 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
349 * is issued to retrieve the index.
352 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
354 INT ret = btnPtr->iBitmap;
356 if (ret == I_IMAGECALLBACK) {
357 /* issue TBN_GETDISPINFO */
360 nmgd.idCommand = btnPtr->idCommand;
361 nmgd.lParam = btnPtr->dwData;
362 nmgd.dwMask = TBNF_IMAGE;
363 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
364 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
366 if (nmgd.dwMask & TBNF_DI_SETITEM) {
367 btnPtr->iBitmap = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
382 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
397 /***********************************************************************
398 * TOOLBAR_GetImageListForDrawing
400 * This function validates the bitmap index (including I_IMAGECALLBACK
401 * functionality) and returns the corresponding image list.
404 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
408 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
409 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
410 ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
411 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
415 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
416 if ((*index == I_IMAGECALLBACK) ||
417 (*index == I_IMAGENONE)) return NULL;
418 ERR("TBN_GETDISPINFO returned invalid index %d\n",
425 case IMAGE_LIST_DEFAULT:
426 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
429 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
431 case IMAGE_LIST_DISABLED:
432 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 FIXME("Shouldn't reach here\n");
440 TRACE("no image list\n");
446 /***********************************************************************
447 * TOOLBAR_TestImageExist
449 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
450 * return the image list. The I_IMAGECALLBACK functionality is implemented.
453 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
457 if (!himl) return FALSE;
459 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
460 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
461 ERR("index %d is not valid, max %d\n",
462 btnPtr->iBitmap, infoPtr->nNumBitmaps);
466 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
467 if ((index == I_IMAGECALLBACK) ||
468 (index == I_IMAGENONE)) return FALSE;
469 ERR("TBN_GETDISPINFO returned invalid index %d\n",
478 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
481 COLORREF oldcolor, newcolor;
483 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
484 myrect.right = myrect.left + 1;
485 myrect.top = lpRect->top + 2;
486 myrect.bottom = lpRect->bottom - 2;
488 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
489 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
490 oldcolor = SetBkColor (hdc, newcolor);
491 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
493 myrect.left = myrect.right;
494 myrect.right = myrect.left + 1;
496 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
497 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
498 SetBkColor (hdc, newcolor);
499 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
501 SetBkColor (hdc, oldcolor);
505 /***********************************************************************
506 * TOOLBAR_DrawDDFlatSeparator
508 * This function draws the separator that was flagged as BTNS_DROPDOWN.
509 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
510 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
511 * are horizontal as opposed to the vertical separators for not dropdown
514 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
517 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
520 COLORREF oldcolor, newcolor;
522 myrect.left = lpRect->left;
523 myrect.right = lpRect->right;
524 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
525 myrect.bottom = myrect.top + 1;
527 InflateRect (&myrect, -2, 0);
529 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
530 myrect.left, myrect.top, myrect.right, myrect.bottom);
532 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
533 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
534 oldcolor = SetBkColor (hdc, newcolor);
535 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
537 myrect.top = myrect.bottom;
538 myrect.bottom = myrect.top + 1;
540 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
541 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
542 SetBkColor (hdc, newcolor);
543 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
545 SetBkColor (hdc, oldcolor);
550 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
555 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
556 hOldPen = SelectObject ( hdc, hPen );
559 MoveToEx (hdc, x, y, NULL);
560 LineTo (hdc, x+5, y++); x++;
561 MoveToEx (hdc, x, y, NULL);
562 LineTo (hdc, x+3, y++); x++;
563 MoveToEx (hdc, x, y, NULL);
564 LineTo (hdc, x+1, y++);
565 SelectObject( hdc, hOldPen );
566 DeleteObject( hPen );
570 * Draw the text string for this button.
571 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
572 * is non-zero, so we can simply check himlDef to see if we have
576 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
577 NMTBCUSTOMDRAW *tbcd)
579 HDC hdc = tbcd->nmcd.hdc;
582 COLORREF clrOldBk = 0;
584 UINT state = tbcd->nmcd.uItemState;
588 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
589 rcText->left, rcText->top, rcText->right, rcText->bottom);
591 hOldFont = SelectObject (hdc, infoPtr->hFont);
592 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
593 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
595 else if (state & CDIS_DISABLED) {
596 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
597 OffsetRect (rcText, 1, 1);
598 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
599 SetTextColor (hdc, comctl32_color.clr3dShadow);
600 OffsetRect (rcText, -1, -1);
602 else if (state & CDIS_INDETERMINATE) {
603 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
605 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
606 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
607 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
608 oldBkMode = SetBkMode (hdc, OPAQUE); /* FIXME: should this be in the NMTBCUSTOMDRAW structure? */
611 clrOld = SetTextColor (hdc, tbcd->clrText);
614 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
615 SetTextColor (hdc, clrOld);
616 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
618 SetBkColor (hdc, clrOldBk);
619 SetBkMode (hdc, oldBkMode);
621 SelectObject (hdc, hOldFont);
627 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
629 HDC hdc = tbcd->nmcd.hdc;
630 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
633 INT cx = lpRect->right - lpRect->left;
634 INT cy = lpRect->bottom - lpRect->top;
635 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
636 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
637 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
638 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
639 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
640 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
641 SetBkColor(hdc, clrBkOld);
642 SetTextColor(hdc, clrTextOld);
643 SelectObject (hdc, hbr);
647 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
650 HBITMAP hbmMask, hbmImage;
651 HDC hdcMask, hdcImage;
653 ImageList_GetIconSize(himl, &cx, &cy);
655 /* Create src image */
656 hdcImage = CreateCompatibleDC(hdc);
657 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
658 SelectObject(hdcImage, hbmImage);
659 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
660 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
663 hdcMask = CreateCompatibleDC(0);
664 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
665 SelectObject(hdcMask, hbmMask);
667 /* Remove the background and all white pixels */
668 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
669 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
670 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
671 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
673 /* draw the new mask 'etched' to hdc */
674 SetBkColor(hdc, RGB(255, 255, 255));
675 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
676 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
677 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
678 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
679 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
682 DeleteObject(hbmImage);
684 DeleteObject (hbmMask);
690 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
694 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
695 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
696 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
697 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
698 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
699 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
700 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
704 /* draws the image on a toolbar button */
706 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
708 HIMAGELIST himl = NULL;
709 BOOL draw_masked = FALSE;
712 UINT draw_flags = ILD_NORMAL;
714 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
716 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
719 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
723 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
725 /* if hot, attempt to draw with hot image list, if fails,
726 use default image list */
727 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
729 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
732 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
737 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
738 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
741 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
742 (tbcd->nmcd.uItemState & CDIS_MARKED))
743 draw_flags |= ILD_BLEND50;
745 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
746 index, himl, left, top, offset);
749 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
751 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
754 /* draws a blank frame for a toolbar button */
756 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
758 HDC hdc = tbcd->nmcd.hdc;
759 RECT rc = tbcd->nmcd.rc;
760 /* if the state is disabled or indeterminate then the button
761 * cannot have an interactive look like pressed or hot */
762 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
763 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
764 BOOL pressed_look = !non_interactive_state &&
765 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
766 (tbcd->nmcd.uItemState & CDIS_CHECKED));
768 /* app don't want us to draw any edges */
769 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
775 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
776 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
777 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
782 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
784 DrawEdge (hdc, &rc, EDGE_RAISED,
785 BF_SOFT | BF_RECT | BF_MIDDLE);
790 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
792 HDC hdc = tbcd->nmcd.hdc;
794 BOOL pressed = bDropDownPressed ||
795 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
797 if (infoPtr->dwStyle & TBSTYLE_FLAT)
800 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
801 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
802 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
803 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
804 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
809 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
811 DrawEdge (hdc, rcArrow, EDGE_RAISED,
812 BF_SOFT | BF_RECT | BF_MIDDLE);
816 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
818 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
820 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
821 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
824 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
827 /* draws a complete toolbar button */
829 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
832 DWORD dwStyle = infoPtr->dwStyle;
833 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
834 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
835 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
836 BOOL drawSepDropDownArrow = hasDropDownArrow &&
837 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
838 RECT rc, rcArrow, rcBitmap, rcText;
839 LPWSTR lpText = NULL;
845 CopyRect (&rcArrow, &rc);
846 CopyRect(&rcBitmap, &rc);
848 /* get a pointer to the text */
849 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
851 if (hasDropDownArrow)
855 if (dwStyle & TBSTYLE_FLAT)
856 right = max(rc.left, rc.right - DDARROW_WIDTH);
858 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
860 if (drawSepDropDownArrow)
863 rcArrow.left = right;
866 /* copy text rect after adjusting for drop-down arrow
867 * so that text is centred in the rectangle not containing
869 CopyRect(&rcText, &rc);
871 /* Center the bitmap horizontally and vertically */
872 if (dwStyle & TBSTYLE_LIST)
873 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
875 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
878 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
880 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
882 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
883 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
884 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
885 TRACE ("iString: %x\n", btnPtr->iString);
886 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
890 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
891 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
892 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
893 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
895 if (dwStyle & TBSTYLE_LIST)
896 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
898 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
901 if (dwStyle & TBSTYLE_LIST)
902 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
904 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
905 OffsetRect (&rcText, 1, 1);
908 /* Initialize fields in all cases, because we use these later
909 * NOTE: applications can and do alter these to customize their
911 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
912 tbcd.clrText = comctl32_color.clrBtnText;
913 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
914 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
915 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
916 tbcd.clrMark = comctl32_color.clrHighlight;
917 tbcd.clrHighlightHotTrack = 0;
918 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
919 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
920 /* MSDN says that this is the text rectangle.
921 * But (why always a but) tracing of v5.7 of native shows
922 * that this is really a *relative* rectangle based on the
923 * the nmcd.rc. Also the left and top are always 0 ignoring
924 * any bitmap that might be present. */
925 tbcd.rcText.left = 0;
927 tbcd.rcText.right = rcText.right - rc.left;
928 tbcd.rcText.bottom = rcText.bottom - rc.top;
929 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
932 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
934 /* FIXME: what are these used for? */
938 /* Issue Item Prepaint notify */
939 infoPtr->dwItemCustDraw = 0;
940 infoPtr->dwItemCDFlag = 0;
941 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
943 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
944 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
945 tbcd.nmcd.lItemlParam = btnPtr->dwData;
946 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
947 /* reset these fields so the user can't alter the behaviour like native */
951 infoPtr->dwItemCustDraw = ntfret & 0xffff;
952 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
953 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
955 /* save the only part of the rect that the user can change */
956 rcText.right = tbcd.rcText.right + rc.left;
957 rcText.bottom = tbcd.rcText.bottom + rc.top;
961 if (btnPtr->fsStyle & BTNS_SEP) {
962 /* with the FLAT style, iBitmap is the width and has already */
963 /* been taken into consideration in calculating the width */
964 /* so now we need to draw the vertical separator */
965 /* empirical tests show that iBitmap can/will be non-zero */
966 /* when drawing the vertical bar... */
967 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
968 if (btnPtr->fsStyle & BTNS_DROPDOWN)
969 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
971 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
973 else if (btnPtr->fsStyle != BTNS_SEP) {
974 FIXME("Draw some kind of separator: fsStyle=%x\n",
980 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
981 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
982 TOOLBAR_DrawPattern (&rc, &tbcd);
984 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
986 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
990 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
991 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
992 if (hasDropDownArrow)
993 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
994 SetBkColor(hdc, oldclr);
998 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1000 if (drawSepDropDownArrow)
1001 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1003 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1004 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1006 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1008 if (hasDropDownArrow && !drawSepDropDownArrow)
1010 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1012 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1013 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1015 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1017 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1018 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1021 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1025 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1027 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1028 tbcd.nmcd.hdc = hdc;
1030 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1031 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1032 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1033 tbcd.rcText = rcText;
1034 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1035 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1036 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1043 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1045 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1046 TBUTTON_INFO *btnPtr;
1047 INT i, oldBKmode = 0;
1048 RECT rcTemp, rcClient;
1049 NMTBCUSTOMDRAW tbcd;
1052 /* the app has told us not to redraw the toolbar */
1053 if (!infoPtr->bDoRedraw)
1056 /* if imagelist belongs to the app, it can be changed
1057 by the app after setting it */
1058 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1060 infoPtr->nNumBitmaps = 0;
1061 for (i = 0; i < infoPtr->cimlDef; i++)
1062 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1065 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1067 /* Send initial notify */
1068 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1069 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1070 tbcd.nmcd.hdc = hdc;
1071 tbcd.nmcd.rc = ps->rcPaint;
1072 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1073 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1075 if (infoPtr->bBtnTranspnt)
1076 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1078 GetClientRect(hwnd, &rcClient);
1080 /* redraw necessary buttons */
1081 btnPtr = infoPtr->buttons;
1082 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1085 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1087 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1088 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1092 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1093 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1095 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1098 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1099 SetBkMode (hdc, oldBKmode);
1101 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1103 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1104 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1105 tbcd.nmcd.hdc = hdc;
1106 tbcd.nmcd.rc = ps->rcPaint;
1107 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1111 /***********************************************************************
1112 * TOOLBAR_MeasureString
1114 * This function gets the width and height of a string in pixels. This
1115 * is done first by using GetTextExtentPoint to get the basic width
1116 * and height. The DrawText is called with DT_CALCRECT to get the exact
1117 * width. The reason is because the text may have more than one "&" (or
1118 * prefix characters as M$ likes to call them). The prefix character
1119 * indicates where the underline goes, except for the string "&&" which
1120 * is reduced to a single "&". GetTextExtentPoint does not process these
1121 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1124 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1125 HDC hdc, LPSIZE lpSize)
1132 if (infoPtr->nMaxTextRows > 0 &&
1133 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1134 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1135 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1137 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1139 if(lpText != NULL) {
1140 /* first get size of all the text */
1141 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1143 /* feed above size into the rectangle for DrawText */
1144 myrect.left = myrect.top = 0;
1145 myrect.right = lpSize->cx;
1146 myrect.bottom = lpSize->cy;
1148 /* Use DrawText to get true size as drawn (less pesky "&") */
1149 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1150 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1153 /* feed back to caller */
1154 lpSize->cx = myrect.right;
1155 lpSize->cy = myrect.bottom;
1159 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1162 /***********************************************************************
1163 * TOOLBAR_CalcStrings
1165 * This function walks through each string and measures it and returns
1166 * the largest height and width to caller.
1169 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1171 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1172 TBUTTON_INFO *btnPtr;
1181 if(infoPtr->nMaxTextRows == 0)
1185 hOldFont = SelectObject (hdc, infoPtr->hFont);
1187 btnPtr = infoPtr->buttons;
1188 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1189 if(TOOLBAR_HasText(infoPtr, btnPtr))
1191 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1192 if (sz.cx > lpSize->cx)
1194 if (sz.cy > lpSize->cy)
1199 SelectObject (hdc, hOldFont);
1200 ReleaseDC (hwnd, hdc);
1202 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1205 /***********************************************************************
1206 * TOOLBAR_WrapToolbar
1208 * This function walks through the buttons and separators in the
1209 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1210 * wrapping should occur based on the width of the toolbar window.
1211 * It does *not* calculate button placement itself. That task
1212 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1213 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1214 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1216 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1217 * vertical toolbar lists.
1221 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1223 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1224 TBUTTON_INFO *btnPtr;
1227 BOOL bWrap, bButtonWrap;
1229 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1230 /* no layout is necessary. Applications may use this style */
1231 /* to perform their own layout on the toolbar. */
1232 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1233 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1235 btnPtr = infoPtr->buttons;
1236 x = infoPtr->nIndent;
1238 /* this can get the parents width, to know how far we can extend
1239 * this toolbar. We cannot use its height, as there may be multiple
1240 * toolbars in a rebar control
1242 GetClientRect( GetParent(hwnd), &rc );
1243 infoPtr->nWidth = rc.right - rc.left;
1244 bButtonWrap = FALSE;
1246 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1247 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1250 for (i = 0; i < infoPtr->nNumButtons; i++ )
1253 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1255 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1258 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1259 /* it is the actual width of the separator. This is used for */
1260 /* custom controls in toolbars. */
1262 /* BTNS_DROPDOWN separators are treated as buttons for */
1263 /* width. - GA 8/01 */
1264 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1265 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1266 cx = (btnPtr[i].iBitmap > 0) ?
1267 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1269 cx = infoPtr->nButtonWidth;
1271 /* Two or more adjacent separators form a separator group. */
1272 /* The first separator in a group should be wrapped to the */
1273 /* next row if the previous wrapping is on a button. */
1275 (btnPtr[i].fsStyle & BTNS_SEP) &&
1276 (i + 1 < infoPtr->nNumButtons ) &&
1277 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1279 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1280 btnPtr[i].fsState |= TBSTATE_WRAP;
1281 x = infoPtr->nIndent;
1283 bButtonWrap = FALSE;
1287 /* The layout makes sure the bitmap is visible, but not the button. */
1288 /* Test added to also wrap after a button that starts a row but */
1289 /* is bigger than the area. - GA 8/01 */
1290 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1291 > infoPtr->nWidth ) ||
1292 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1294 BOOL bFound = FALSE;
1296 /* If the current button is a separator and not hidden, */
1297 /* go to the next until it reaches a non separator. */
1298 /* Wrap the last separator if it is before a button. */
1299 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1300 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1301 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1302 i < infoPtr->nNumButtons )
1308 if( bFound && i < infoPtr->nNumButtons )
1311 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1312 i, btnPtr[i].fsStyle, x, cx);
1313 btnPtr[i].fsState |= TBSTATE_WRAP;
1314 x = infoPtr->nIndent;
1315 bButtonWrap = FALSE;
1318 else if ( i >= infoPtr->nNumButtons)
1321 /* If the current button is not a separator, find the last */
1322 /* separator and wrap it. */
1323 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1325 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1326 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1330 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1331 i, btnPtr[i].fsStyle, x, cx);
1332 x = infoPtr->nIndent;
1333 btnPtr[j].fsState |= TBSTATE_WRAP;
1334 bButtonWrap = FALSE;
1339 /* If no separator available for wrapping, wrap one of */
1340 /* non-hidden previous button. */
1344 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1346 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1351 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1352 i, btnPtr[i].fsStyle, x, cx);
1353 x = infoPtr->nIndent;
1354 btnPtr[j].fsState |= TBSTATE_WRAP;
1360 /* If all above failed, wrap the current button. */
1363 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1364 i, btnPtr[i].fsStyle, x, cx);
1365 btnPtr[i].fsState |= TBSTATE_WRAP;
1367 x = infoPtr->nIndent;
1368 if (btnPtr[i].fsStyle & BTNS_SEP )
1369 bButtonWrap = FALSE;
1375 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1376 i, btnPtr[i].fsStyle, x, cx);
1383 /***********************************************************************
1384 * TOOLBAR_CalcToolbar
1386 * This function calculates button and separator placement. It first
1387 * calculates the button sizes, gets the toolbar window width and then
1388 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1389 * on. It assigns a new location to each item and sends this location to
1390 * the tooltip window if appropriate. Finally, it updates the rcBound
1391 * rect and calculates the new required toolbar window height.
1395 TOOLBAR_CalcToolbar (HWND hwnd)
1397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1398 DWORD dwStyle = infoPtr->dwStyle;
1399 TBUTTON_INFO *btnPtr;
1400 INT i, nRows, nSepRows;
1404 BOOL usesBitmaps = FALSE;
1405 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1407 TOOLBAR_CalcStrings (hwnd, &sizeString);
1409 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1411 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1413 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1416 if (dwStyle & TBSTYLE_LIST)
1418 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1419 0, sizeString.cy) + infoPtr->szPadding.cy;
1420 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1421 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1422 if (sizeString.cx > 0)
1423 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1424 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1425 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1426 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1429 if (sizeString.cy > 0)
1432 infoPtr->nButtonHeight = sizeString.cy +
1433 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1434 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1436 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1439 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1441 if (sizeString.cx > infoPtr->nBitmapWidth)
1442 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1444 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1447 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1448 infoPtr->nButtonWidth = infoPtr->cxMin;
1449 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1450 infoPtr->nButtonWidth = infoPtr->cxMax;
1452 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1454 x = infoPtr->nIndent;
1457 /* from above, minimum is a button, and possible text */
1458 cx = infoPtr->nButtonWidth;
1460 /* cannot use just ButtonHeight, we may have no buttons! */
1461 if (infoPtr->nNumButtons > 0)
1462 infoPtr->nHeight = infoPtr->nButtonHeight;
1464 cy = infoPtr->nHeight;
1466 nRows = nSepRows = 0;
1468 infoPtr->rcBound.top = y;
1469 infoPtr->rcBound.left = x;
1470 infoPtr->rcBound.bottom = y + cy;
1471 infoPtr->rcBound.right = x;
1473 btnPtr = infoPtr->buttons;
1475 TRACE("cy=%d\n", cy);
1477 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1480 if (btnPtr->fsState & TBSTATE_HIDDEN)
1482 SetRectEmpty (&btnPtr->rect);
1486 cy = infoPtr->nHeight;
1488 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1489 /* it is the actual width of the separator. This is used for */
1490 /* custom controls in toolbars. */
1491 if (btnPtr->fsStyle & BTNS_SEP) {
1492 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1493 cy = (btnPtr->iBitmap > 0) ?
1494 btnPtr->iBitmap : SEPARATOR_WIDTH;
1495 cx = infoPtr->nButtonWidth;
1498 cx = (btnPtr->iBitmap > 0) ?
1499 btnPtr->iBitmap : SEPARATOR_WIDTH;
1505 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1506 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1513 hOldFont = SelectObject (hdc, infoPtr->hFont);
1515 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1517 SelectObject (hdc, hOldFont);
1518 ReleaseDC (hwnd, hdc);
1520 /* add space on for button frame, etc */
1521 cx = sz.cx + infoPtr->szPadding.cx;
1523 /* add list padding */
1524 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1525 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1527 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1529 if (dwStyle & TBSTYLE_LIST)
1530 cx += infoPtr->nBitmapWidth;
1531 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1532 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1534 else if (dwStyle & TBSTYLE_LIST)
1535 cx += LIST_IMAGE_ABSENT_WIDTH;
1538 cx = infoPtr->nButtonWidth;
1540 /* if size has been set manually then don't add on extra space
1541 * for the drop down arrow */
1542 if (!btnPtr->cx && hasDropDownArrows &&
1543 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1544 cx += DDARROW_WIDTH;
1546 if (btnPtr->fsState & TBSTATE_WRAP )
1549 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1551 if (infoPtr->rcBound.left > x)
1552 infoPtr->rcBound.left = x;
1553 if (infoPtr->rcBound.right < x + cx)
1554 infoPtr->rcBound.right = x + cx;
1555 if (infoPtr->rcBound.bottom < y + cy)
1556 infoPtr->rcBound.bottom = y + cy;
1558 /* Set the toolTip only for non-hidden, non-separator button */
1559 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1563 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1564 ti.cbSize = sizeof(TTTOOLINFOA);
1566 ti.uId = btnPtr->idCommand;
1567 ti.rect = btnPtr->rect;
1568 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1572 /* btnPtr->nRow is zero based. The space between the rows is */
1573 /* also considered as a row. */
1574 btnPtr->nRow = nRows + nSepRows;
1576 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1577 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1582 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1586 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1587 /* it is the actual width of the separator. This is used for */
1588 /* custom controls in toolbars. */
1589 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1590 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1591 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1595 /* nSepRows is used to calculate the extra height follwoing */
1599 x = infoPtr->nIndent;
1601 /* Increment row number unless this is the last button */
1602 /* and it has Wrap set. */
1603 if (i != infoPtr->nNumButtons-1)
1610 /* infoPtr->nRows is the number of rows on the toolbar */
1611 infoPtr->nRows = nRows + nSepRows + 1;
1614 /********************************************************************
1615 * The following while interesting, does not match the values *
1616 * created above for the button rectangles, nor the rcBound rect. *
1617 * We will comment it out and remove it later. *
1619 * The problem showed up as heights in the pager control that was *
1621 ********************************************************************/
1623 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1625 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1626 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1627 nSepRows * (infoPtr->nBitmapHeight + 1) +
1631 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1633 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1638 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1641 TBUTTON_INFO *btnPtr;
1644 btnPtr = infoPtr->buttons;
1645 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1646 if (btnPtr->fsState & TBSTATE_HIDDEN)
1649 if (btnPtr->fsStyle & BTNS_SEP) {
1650 if (PtInRect (&btnPtr->rect, *lpPt)) {
1651 TRACE(" ON SEPARATOR %d!\n", i);
1656 if (PtInRect (&btnPtr->rect, *lpPt)) {
1657 TRACE(" ON BUTTON %d!\n", i);
1663 TRACE(" NOWHERE!\n");
1669 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1671 TBUTTON_INFO *btnPtr;
1674 if (CommandIsIndex) {
1675 TRACE("command is really index command=%d\n", idCommand);
1676 if (idCommand >= infoPtr->nNumButtons) return -1;
1679 btnPtr = infoPtr->buttons;
1680 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1681 if (btnPtr->idCommand == idCommand) {
1682 TRACE("command=%d index=%d\n", idCommand, i);
1686 TRACE("no index found for command=%d\n", idCommand);
1692 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1694 TBUTTON_INFO *btnPtr;
1697 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1700 /* check index button */
1701 btnPtr = &infoPtr->buttons[nIndex];
1702 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1703 if (btnPtr->fsState & TBSTATE_CHECKED)
1707 /* check previous buttons */
1708 nRunIndex = nIndex - 1;
1709 while (nRunIndex >= 0) {
1710 btnPtr = &infoPtr->buttons[nRunIndex];
1711 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1712 if (btnPtr->fsState & TBSTATE_CHECKED)
1720 /* check next buttons */
1721 nRunIndex = nIndex + 1;
1722 while (nRunIndex < infoPtr->nNumButtons) {
1723 btnPtr = &infoPtr->buttons[nRunIndex];
1724 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1725 if (btnPtr->fsState & TBSTATE_CHECKED)
1738 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1739 WPARAM wParam, LPARAM lParam)
1745 msg.wParam = wParam;
1746 msg.lParam = lParam;
1747 msg.time = GetMessageTime ();
1748 msg.pt.x = LOWORD(GetMessagePos ());
1749 msg.pt.y = HIWORD(GetMessagePos ());
1751 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1755 /***********************************************************************
1756 * TOOLBAR_CustomizeDialogProc
1757 * This function implements the toolbar customization dialog.
1759 static INT_PTR CALLBACK
1760 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1762 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1763 PCUSTOMBUTTON btnInfo;
1765 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1770 custInfo = (PCUSTDLG_INFO)lParam;
1771 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1779 infoPtr = custInfo->tbInfo;
1781 /* send TBN_QUERYINSERT notification */
1782 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1784 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1787 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1788 nmtb.iItem = (int)hwnd;
1789 /* Send TBN_INITCUSTOMIZE notification */
1790 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1793 TRACE("TBNRF_HIDEHELP requested\n");
1794 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1797 /* add items to 'toolbar buttons' list and check if removable */
1798 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1800 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1801 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1802 btnInfo->btn.fsStyle = BTNS_SEP;
1803 btnInfo->bVirtual = FALSE;
1804 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1806 /* send TBN_QUERYDELETE notification */
1807 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1809 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1810 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1813 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1815 /* insert separator button into 'available buttons' list */
1816 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1817 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1818 btnInfo->btn.fsStyle = BTNS_SEP;
1819 btnInfo->bVirtual = FALSE;
1820 btnInfo->bRemovable = TRUE;
1821 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1822 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1823 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1825 /* insert all buttons into dsa */
1828 /* send TBN_GETBUTTONINFO notification */
1831 nmtb.pszText = Buffer;
1834 /* Clear previous button's text */
1835 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1837 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1840 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1841 nmtb.tbButton.fsStyle, i,
1842 nmtb.tbButton.idCommand,
1843 nmtb.tbButton.iString,
1844 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1847 /* insert button into the apropriate list */
1848 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1851 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1852 btnInfo->bVirtual = FALSE;
1853 btnInfo->bRemovable = TRUE;
1855 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1856 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1857 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1861 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1862 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1865 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1866 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1868 if (lstrlenW(nmtb.pszText))
1869 lstrcpyW(btnInfo->text, nmtb.pszText);
1870 else if (nmtb.tbButton.iString >= 0 &&
1871 nmtb.tbButton.iString < infoPtr->nNumStrings)
1873 lstrcpyW(btnInfo->text,
1874 infoPtr->strings[nmtb.tbButton.iString]);
1879 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1881 /* select first item in the 'available' list */
1882 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1884 /* append 'virtual' separator button to the 'toolbar buttons' list */
1885 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1886 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1887 btnInfo->btn.fsStyle = BTNS_SEP;
1888 btnInfo->bVirtual = TRUE;
1889 btnInfo->bRemovable = FALSE;
1890 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1891 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1894 /* select last item in the 'toolbar' list */
1895 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1896 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1898 /* set focus and disable buttons */
1899 PostMessageA (hwnd, WM_USER, 0, 0);
1904 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1905 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1906 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1907 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1911 EndDialog(hwnd, FALSE);
1915 switch (LOWORD(wParam))
1917 case IDC_TOOLBARBTN_LBOX:
1918 if (HIWORD(wParam) == LBN_SELCHANGE)
1920 PCUSTOMBUTTON btnInfo;
1925 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1926 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1928 /* send TBN_QUERYINSERT notification */
1930 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1933 /* get list box item */
1934 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1936 if (index == (count - 1))
1938 /* last item (virtual separator) */
1939 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1940 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1942 else if (index == (count - 2))
1944 /* second last item (last non-virtual item) */
1945 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1946 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1948 else if (index == 0)
1951 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1952 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1956 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1960 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1964 case IDC_MOVEUP_BTN:
1966 PCUSTOMBUTTON btnInfo;
1970 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1971 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1972 TRACE("Move up: index %d\n", index);
1974 /* send TBN_QUERYINSERT notification */
1977 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1982 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1984 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1985 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1986 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1987 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1990 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1991 else if (index >= (count - 3))
1992 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1994 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1995 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1997 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2002 case IDC_MOVEDN_BTN: /* move down */
2004 PCUSTOMBUTTON btnInfo;
2008 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2009 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2010 TRACE("Move up: index %d\n", index);
2012 /* send TBN_QUERYINSERT notification */
2014 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2019 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2021 /* move button down */
2022 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2023 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2024 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2025 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2028 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2029 else if (index >= (count - 3))
2030 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2032 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2033 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2035 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2040 case IDC_REMOVE_BTN: /* remove button */
2042 PCUSTOMBUTTON btnInfo;
2045 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2047 if (LB_ERR == index)
2050 TRACE("Remove: index %d\n", index);
2052 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2053 LB_GETITEMDATA, index, 0);
2055 /* send TBN_QUERYDELETE notification */
2056 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2060 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2061 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2062 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2064 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2066 /* insert into 'available button' list */
2067 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2069 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2070 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2075 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2080 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2083 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2086 case IDOK: /* Add button */
2091 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2092 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2093 TRACE("Add: index %d\n", index);
2095 /* send TBN_QUERYINSERT notification */
2097 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2102 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2106 /* remove from 'available buttons' list */
2107 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2108 if (index == count-1)
2109 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2111 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2115 PCUSTOMBUTTON btnNew;
2117 /* duplicate 'separator' button */
2118 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2119 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2123 /* insert into 'toolbar button' list */
2124 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2125 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2126 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2128 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2130 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2136 EndDialog(hwnd, FALSE);
2146 /* delete items from 'toolbar buttons' listbox*/
2147 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2148 for (i = 0; i < count; i++)
2150 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2152 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2154 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2157 /* delete items from 'available buttons' listbox*/
2158 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2159 for (i = 0; i < count; i++)
2161 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2163 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2165 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2170 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2172 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2177 COLORREF oldText = 0;
2181 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2182 if (btnInfo == NULL)
2184 FIXME("btnInfo invalid!\n");
2188 /* set colors and select objects */
2189 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2190 if (btnInfo->bVirtual)
2191 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2193 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2194 hPen = CreatePen( PS_SOLID, 1,
2195 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2196 hOldPen = SelectObject (lpdis->hDC, hPen );
2197 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2199 /* fill background rectangle */
2200 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2201 lpdis->rcItem.right, lpdis->rcItem.bottom);
2203 /* calculate button and text rectangles */
2204 CopyRect (&rcButton, &lpdis->rcItem);
2205 InflateRect (&rcButton, -1, -1);
2206 CopyRect (&rcText, &rcButton);
2207 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2208 rcText.left = rcButton.right + 2;
2210 /* draw focus rectangle */
2211 if (lpdis->itemState & ODS_FOCUS)
2212 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2215 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2216 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2218 /* draw image and text */
2219 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2220 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2221 btnInfo->btn.iBitmap));
2222 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2223 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2225 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2226 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2228 /* delete objects and reset colors */
2229 SelectObject (lpdis->hDC, hOldBrush);
2230 SelectObject (lpdis->hDC, hOldPen);
2231 SetBkColor (lpdis->hDC, oldBk);
2232 SetTextColor (lpdis->hDC, oldText);
2233 DeleteObject( hPen );
2238 case WM_MEASUREITEM:
2239 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2241 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2243 lpmis->itemHeight = 15 + 8; /* default height */
2255 /***********************************************************************
2256 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2260 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2263 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2264 INT nIndex = 0, nButtons, nCount;
2268 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2272 if (lpAddBmp->hInst == HINST_COMMCTRL)
2274 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2276 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2278 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2283 TRACE ("adding %d internal bitmaps!\n", nButtons);
2285 /* Windows resize all the buttons to the size of a newly added standard image */
2286 if (lpAddBmp->nID & 1)
2289 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2290 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2292 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2293 MAKELPARAM((WORD)24, (WORD)24));
2294 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2295 MAKELPARAM((WORD)31, (WORD)30));
2300 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2301 MAKELPARAM((WORD)16, (WORD)16));
2302 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2303 MAKELPARAM((WORD)22, (WORD)22));
2306 TOOLBAR_CalcToolbar (hwnd);
2310 nButtons = (INT)wParam;
2314 TRACE ("adding %d bitmaps!\n", nButtons);
2317 if (!infoPtr->cimlDef) {
2318 /* create new default image list */
2319 TRACE ("creating default image list!\n");
2321 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2322 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2323 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2324 infoPtr->himlInt = himlDef;
2327 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2331 WARN("No default image list available\n");
2335 nCount = ImageList_GetImageCount(himlDef);
2337 /* Add bitmaps to the default image list */
2338 if (lpAddBmp->hInst == NULL)
2341 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2342 HDC hdcImage, hdcBitmap;
2344 /* copy the bitmap before adding it so that the user's bitmap
2345 * doesn't get modified.
2347 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2349 hdcImage = CreateCompatibleDC(0);
2350 hdcBitmap = CreateCompatibleDC(0);
2352 /* create new bitmap */
2353 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2354 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2355 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2357 /* Copy the user's image */
2358 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2359 hdcBitmap, 0, 0, SRCCOPY);
2361 SelectObject (hdcImage, hOldBitmapLoad);
2362 SelectObject (hdcBitmap, hOldBitmapBitmap);
2363 DeleteDC (hdcImage);
2364 DeleteDC (hdcBitmap);
2366 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2367 DeleteObject (hbmLoad);
2369 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2371 /* Add system bitmaps */
2372 switch (lpAddBmp->nID)
2374 case IDB_STD_SMALL_COLOR:
2375 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2376 MAKEINTRESOURCEA(IDB_STD_SMALL));
2377 nIndex = ImageList_AddMasked (himlDef,
2378 hbmLoad, comctl32_color.clrBtnFace);
2379 DeleteObject (hbmLoad);
2382 case IDB_STD_LARGE_COLOR:
2383 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2384 MAKEINTRESOURCEA(IDB_STD_LARGE));
2385 nIndex = ImageList_AddMasked (himlDef,
2386 hbmLoad, comctl32_color.clrBtnFace);
2387 DeleteObject (hbmLoad);
2390 case IDB_VIEW_SMALL_COLOR:
2391 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2392 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2393 nIndex = ImageList_AddMasked (himlDef,
2394 hbmLoad, comctl32_color.clrBtnFace);
2395 DeleteObject (hbmLoad);
2398 case IDB_VIEW_LARGE_COLOR:
2399 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2400 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2401 nIndex = ImageList_AddMasked (himlDef,
2402 hbmLoad, comctl32_color.clrBtnFace);
2403 DeleteObject (hbmLoad);
2406 case IDB_HIST_SMALL_COLOR:
2407 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2408 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2409 nIndex = ImageList_AddMasked (himlDef,
2410 hbmLoad, comctl32_color.clrBtnFace);
2411 DeleteObject (hbmLoad);
2414 case IDB_HIST_LARGE_COLOR:
2415 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2416 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2417 nIndex = ImageList_AddMasked (himlDef,
2418 hbmLoad, comctl32_color.clrBtnFace);
2419 DeleteObject (hbmLoad);
2423 nIndex = ImageList_GetImageCount (himlDef);
2424 ERR ("invalid imagelist!\n");
2430 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2431 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2432 DeleteObject (hbmLoad);
2435 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2437 if (infoPtr->nNumBitmapInfos == 0)
2439 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2443 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2444 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2445 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2448 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2449 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2450 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2452 infoPtr->nNumBitmapInfos++;
2453 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2457 INT imagecount = ImageList_GetImageCount(himlDef);
2459 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2461 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",
2462 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2463 infoPtr->nNumBitmaps+nButtons,imagecount);
2465 infoPtr->nNumBitmaps = imagecount;
2468 infoPtr->nNumBitmaps += nButtons;
2471 InvalidateRect(hwnd, NULL, TRUE);
2478 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2480 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2481 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2482 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2484 TRACE("adding %d buttons!\n", wParam);
2486 nAddButtons = (UINT)wParam;
2487 nOldButtons = infoPtr->nNumButtons;
2488 nNewButtons = nOldButtons + nAddButtons;
2490 if (infoPtr->nNumButtons == 0) {
2492 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2495 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2497 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2498 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2499 nOldButtons * sizeof(TBUTTON_INFO));
2503 infoPtr->nNumButtons = nNewButtons;
2505 /* insert new button data */
2506 for (nCount = 0; nCount < nAddButtons; nCount++) {
2507 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2508 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2509 btnPtr->idCommand = lpTbb[nCount].idCommand;
2510 btnPtr->fsState = lpTbb[nCount].fsState;
2511 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2512 btnPtr->dwData = lpTbb[nCount].dwData;
2513 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2514 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2516 btnPtr->iString = lpTbb[nCount].iString;
2517 btnPtr->bHot = FALSE;
2519 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2522 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2523 ti.cbSize = sizeof (TTTOOLINFOA);
2525 ti.uId = btnPtr->idCommand;
2527 ti.lpszText = LPSTR_TEXTCALLBACKA;
2529 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2534 TOOLBAR_CalcToolbar (hwnd);
2536 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2538 InvalidateRect(hwnd, NULL, TRUE);
2545 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2548 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2549 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2551 TRACE("adding %d buttons!\n", wParam);
2553 nAddButtons = (UINT)wParam;
2554 nOldButtons = infoPtr->nNumButtons;
2555 nNewButtons = nOldButtons + nAddButtons;
2557 if (infoPtr->nNumButtons == 0) {
2559 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2562 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2564 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2565 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2566 nOldButtons * sizeof(TBUTTON_INFO));
2570 infoPtr->nNumButtons = nNewButtons;
2572 /* insert new button data */
2573 for (nCount = 0; nCount < nAddButtons; nCount++) {
2574 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2575 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2576 btnPtr->idCommand = lpTbb[nCount].idCommand;
2577 btnPtr->fsState = lpTbb[nCount].fsState;
2578 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2579 btnPtr->dwData = lpTbb[nCount].dwData;
2580 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2581 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2583 btnPtr->iString = lpTbb[nCount].iString;
2584 btnPtr->bHot = FALSE;
2586 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2589 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2590 ti.cbSize = sizeof (TTTOOLINFOW);
2592 ti.uId = btnPtr->idCommand;
2594 ti.lpszText = LPSTR_TEXTCALLBACKW;
2597 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2602 TOOLBAR_CalcToolbar (hwnd);
2604 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2606 InvalidateRect(hwnd, NULL, TRUE);
2613 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2618 if ((wParam) && (HIWORD(lParam) == 0)) {
2621 TRACE("adding string from resource!\n");
2623 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2626 TRACE("len=%d \"%s\"\n", len, szString);
2627 nIndex = infoPtr->nNumStrings;
2628 if (infoPtr->nNumStrings == 0) {
2630 Alloc (sizeof(LPWSTR));
2633 LPWSTR *oldStrings = infoPtr->strings;
2635 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2636 memcpy (&infoPtr->strings[0], &oldStrings[0],
2637 sizeof(LPWSTR) * infoPtr->nNumStrings);
2641 /*Alloc zeros out the allocated memory*/
2642 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2643 infoPtr->nNumStrings++;
2646 LPSTR p = (LPSTR)lParam;
2651 TRACE("adding string(s) from array!\n");
2653 nIndex = infoPtr->nNumStrings;
2656 TRACE("len=%d \"%s\"\n", len, p);
2658 if (infoPtr->nNumStrings == 0) {
2660 Alloc (sizeof(LPWSTR));
2663 LPWSTR *oldStrings = infoPtr->strings;
2665 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2666 memcpy (&infoPtr->strings[0], &oldStrings[0],
2667 sizeof(LPWSTR) * infoPtr->nNumStrings);
2671 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2672 infoPtr->nNumStrings++;
2683 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2685 #define MAX_RESOURCE_STRING_LENGTH 512
2686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2689 if ((wParam) && (HIWORD(lParam) == 0)) {
2690 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2692 TRACE("adding string from resource!\n");
2694 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2695 szString, MAX_RESOURCE_STRING_LENGTH);
2697 TRACE("len=%d %s\n", len, debugstr_w(szString));
2698 TRACE("First char: 0x%x\n", *szString);
2699 if (szString[0] == L'|')
2701 PWSTR p = szString + 1;
2703 nIndex = infoPtr->nNumStrings;
2704 while (*p != L'|' && *p != L'\0') {
2707 if (infoPtr->nNumStrings == 0) {
2708 infoPtr->strings = Alloc (sizeof(LPWSTR));
2712 LPWSTR *oldStrings = infoPtr->strings;
2713 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2714 memcpy(&infoPtr->strings[0], &oldStrings[0],
2715 sizeof(LPWSTR) * infoPtr->nNumStrings);
2719 np=strchrW (p, '|');
2727 TRACE("len=%d %s\n", len, debugstr_w(p));
2728 infoPtr->strings[infoPtr->nNumStrings] =
2729 Alloc (sizeof(WCHAR)*(len+1));
2730 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2731 infoPtr->nNumStrings++;
2738 nIndex = infoPtr->nNumStrings;
2739 if (infoPtr->nNumStrings == 0) {
2741 Alloc (sizeof(LPWSTR));
2744 LPWSTR *oldStrings = infoPtr->strings;
2746 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2747 memcpy (&infoPtr->strings[0], &oldStrings[0],
2748 sizeof(LPWSTR) * infoPtr->nNumStrings);
2752 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2753 infoPtr->nNumStrings++;
2757 LPWSTR p = (LPWSTR)lParam;
2762 TRACE("adding string(s) from array!\n");
2763 nIndex = infoPtr->nNumStrings;
2767 TRACE("len=%d %s\n", len, debugstr_w(p));
2768 if (infoPtr->nNumStrings == 0) {
2770 Alloc (sizeof(LPWSTR));
2773 LPWSTR *oldStrings = infoPtr->strings;
2775 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2776 memcpy (&infoPtr->strings[0], &oldStrings[0],
2777 sizeof(LPWSTR) * infoPtr->nNumStrings);
2781 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2782 infoPtr->nNumStrings++;
2793 TOOLBAR_AutoSize (HWND hwnd)
2795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2801 UINT uPosFlags = SWP_NOZORDER;
2803 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2805 parent = GetParent (hwnd);
2806 GetClientRect(parent, &parent_rect);
2808 x = parent_rect.left;
2809 y = parent_rect.top;
2811 /* FIXME: we should be able to early out if nothing */
2812 /* has changed with nWidth != parent_rect width */
2814 if (infoPtr->dwStyle & CCS_NORESIZE) {
2815 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2818 TOOLBAR_CalcToolbar (hwnd);
2821 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2822 TOOLBAR_CalcToolbar (hwnd);
2823 InvalidateRect( hwnd, NULL, TRUE );
2824 cy = infoPtr->nHeight;
2825 cx = infoPtr->nWidth;
2827 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2828 GetWindowRect(hwnd, &window_rect);
2829 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2830 y = window_rect.top;
2832 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2833 GetWindowRect(hwnd, &window_rect);
2834 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2838 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2839 uPosFlags |= SWP_NOMOVE;
2841 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2842 cy += GetSystemMetrics(SM_CYEDGE);
2844 if (infoPtr->dwStyle & WS_BORDER)
2847 cy += GetSystemMetrics(SM_CYEDGE);
2848 cx += GetSystemMetrics(SM_CYEDGE);
2851 infoPtr->bAutoSize = TRUE;
2852 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2853 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2854 * after the setwindowpos calls */
2855 infoPtr->bAutoSize = FALSE;
2862 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2866 return infoPtr->nNumButtons;
2871 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2873 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2875 if (infoPtr == NULL) {
2876 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2877 ERR("infoPtr == NULL!\n");
2881 infoPtr->dwStructSize = (DWORD)wParam;
2888 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2891 TBUTTON_INFO *btnPtr;
2894 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2896 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2900 btnPtr = &infoPtr->buttons[nIndex];
2901 btnPtr->iBitmap = LOWORD(lParam);
2903 /* we HAVE to erase the background, the new bitmap could be */
2905 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2912 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2914 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2915 TBUTTON_INFO *btnPtr;
2918 BOOL bChecked = FALSE;
2920 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2922 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2927 btnPtr = &infoPtr->buttons[nIndex];
2929 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2931 if (LOWORD(lParam) == FALSE)
2932 btnPtr->fsState &= ~TBSTATE_CHECKED;
2934 if (btnPtr->fsStyle & BTNS_GROUP) {
2936 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2937 if (nOldIndex == nIndex)
2939 if (nOldIndex != -1)
2940 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2942 btnPtr->fsState |= TBSTATE_CHECKED;
2945 if( bChecked != LOWORD(lParam) )
2947 if (nOldIndex != -1)
2948 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2949 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2952 /* FIXME: Send a WM_NOTIFY?? */
2959 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2963 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2968 TOOLBAR_Customize (HWND hwnd)
2970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2971 CUSTDLG_INFO custInfo;
2977 custInfo.tbInfo = infoPtr;
2978 custInfo.tbHwnd = hwnd;
2980 /* send TBN_BEGINADJUST notification */
2981 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2984 if (!(hRes = FindResourceA (COMCTL32_hModule,
2985 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2989 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2992 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
2993 (LPDLGTEMPLATEA)template,
2995 TOOLBAR_CustomizeDialogProc,
2998 /* send TBN_ENDADJUST notification */
2999 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3007 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3010 INT nIndex = (INT)wParam;
3013 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3016 memset(&nmtb, 0, sizeof(nmtb));
3017 nmtb.iItem = nIndex;
3018 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3020 if ((infoPtr->hwndToolTip) &&
3021 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3024 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3025 ti.cbSize = sizeof (TTTOOLINFOA);
3027 ti.uId = infoPtr->buttons[nIndex].idCommand;
3029 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3032 if (infoPtr->nNumButtons == 1) {
3033 TRACE(" simple delete!\n");
3034 Free (infoPtr->buttons);
3035 infoPtr->buttons = NULL;
3036 infoPtr->nNumButtons = 0;
3039 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3040 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3042 infoPtr->nNumButtons--;
3043 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3045 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3046 nIndex * sizeof(TBUTTON_INFO));
3049 if (nIndex < infoPtr->nNumButtons) {
3050 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3051 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3057 TOOLBAR_CalcToolbar (hwnd);
3059 InvalidateRect (hwnd, NULL, TRUE);
3066 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3069 TBUTTON_INFO *btnPtr;
3073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3075 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3080 btnPtr = &infoPtr->buttons[nIndex];
3082 bState = btnPtr->fsState & TBSTATE_ENABLED;
3084 /* update the toolbar button state */
3085 if(LOWORD(lParam) == FALSE) {
3086 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3088 btnPtr->fsState |= TBSTATE_ENABLED;
3091 /* redraw the button only if the state of the button changed */
3092 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3093 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3099 static inline LRESULT
3100 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3104 return infoPtr->bAnchor;
3109 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3114 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3118 return infoPtr->buttons[nIndex].iBitmap;
3122 static inline LRESULT
3123 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3125 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3130 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3133 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3134 INT nIndex = (INT)wParam;
3135 TBUTTON_INFO *btnPtr;
3137 if (infoPtr == NULL)
3143 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3146 btnPtr = &infoPtr->buttons[nIndex];
3147 lpTbb->iBitmap = btnPtr->iBitmap;
3148 lpTbb->idCommand = btnPtr->idCommand;
3149 lpTbb->fsState = btnPtr->fsState;
3150 lpTbb->fsStyle = btnPtr->fsStyle;
3151 lpTbb->bReserved[0] = 0;
3152 lpTbb->bReserved[1] = 0;
3153 lpTbb->dwData = btnPtr->dwData;
3154 lpTbb->iString = btnPtr->iString;
3161 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3163 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3164 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3165 TBUTTON_INFO *btnPtr;
3168 if (infoPtr == NULL)
3170 if (lpTbInfo == NULL)
3172 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3175 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3176 lpTbInfo->dwMask & 0x80000000);
3180 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3182 if (lpTbInfo->dwMask & TBIF_COMMAND)
3183 lpTbInfo->idCommand = btnPtr->idCommand;
3184 if (lpTbInfo->dwMask & TBIF_IMAGE)
3185 lpTbInfo->iImage = btnPtr->iBitmap;
3186 if (lpTbInfo->dwMask & TBIF_LPARAM)
3187 lpTbInfo->lParam = btnPtr->dwData;
3188 if (lpTbInfo->dwMask & TBIF_SIZE)
3189 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3190 if (lpTbInfo->dwMask & TBIF_STATE)
3191 lpTbInfo->fsState = btnPtr->fsState;
3192 if (lpTbInfo->dwMask & TBIF_STYLE)
3193 lpTbInfo->fsStyle = btnPtr->fsStyle;
3194 if (lpTbInfo->dwMask & TBIF_TEXT) {
3195 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3196 can't use TOOLBAR_GetText here */
3198 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3199 lpText = (LPWSTR)btnPtr->iString;
3200 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3202 lpTbInfo->pszText[0] = '\0';
3209 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3212 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3213 TBUTTON_INFO *btnPtr;
3216 if (infoPtr == NULL)
3218 if (lpTbInfo == NULL)
3220 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3223 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3224 lpTbInfo->dwMask & 0x80000000);
3228 btnPtr = &infoPtr->buttons[nIndex];
3233 if (lpTbInfo->dwMask & TBIF_COMMAND)
3234 lpTbInfo->idCommand = btnPtr->idCommand;
3235 if (lpTbInfo->dwMask & TBIF_IMAGE)
3236 lpTbInfo->iImage = btnPtr->iBitmap;
3237 if (lpTbInfo->dwMask & TBIF_LPARAM)
3238 lpTbInfo->lParam = btnPtr->dwData;
3239 if (lpTbInfo->dwMask & TBIF_SIZE)
3240 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3241 if (lpTbInfo->dwMask & TBIF_STATE)
3242 lpTbInfo->fsState = btnPtr->fsState;
3243 if (lpTbInfo->dwMask & TBIF_STYLE)
3244 lpTbInfo->fsStyle = btnPtr->fsStyle;
3245 if (lpTbInfo->dwMask & TBIF_TEXT) {
3246 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3247 can't use TOOLBAR_GetText here */
3249 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3250 lpText = (LPWSTR)btnPtr->iString;
3251 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3253 lpTbInfo->pszText[0] = '\0';
3261 TOOLBAR_GetButtonSize (HWND hwnd)
3263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 if (infoPtr->nNumButtons > 0)
3266 return MAKELONG((WORD)infoPtr->nButtonWidth,
3267 (WORD)infoPtr->nButtonHeight);
3269 return MAKELONG(8,7);
3274 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3283 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3287 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3289 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3290 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3295 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3302 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3306 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3310 ret = strlenW (lpText);
3313 strcpyW ((LPWSTR)lParam, lpText);
3321 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3324 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3325 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3329 inline static LRESULT
3330 TOOLBAR_GetExtendedStyle (HWND hwnd)
3332 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3336 return infoPtr->dwExStyle;
3341 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3343 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3344 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3345 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3350 TOOLBAR_GetHotItem (HWND hwnd)
3352 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3354 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3357 if (infoPtr->nHotItem < 0)
3360 return (LRESULT)infoPtr->nHotItem;
3365 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3367 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3368 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3369 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3373 /* << TOOLBAR_GetInsertMark >> */
3374 /* << TOOLBAR_GetInsertMarkColor >> */
3378 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3381 TBUTTON_INFO *btnPtr;
3385 if (infoPtr == NULL)
3387 nIndex = (INT)wParam;
3388 btnPtr = &infoPtr->buttons[nIndex];
3389 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3391 lpRect = (LPRECT)lParam;
3394 if (btnPtr->fsState & TBSTATE_HIDDEN)
3397 lpRect->left = btnPtr->rect.left;
3398 lpRect->right = btnPtr->rect.right;
3399 lpRect->bottom = btnPtr->rect.bottom;
3400 lpRect->top = btnPtr->rect.top;
3407 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 LPSIZE lpSize = (LPSIZE)lParam;
3415 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3416 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3418 TRACE("maximum size %ld x %ld\n",
3419 infoPtr->rcBound.right - infoPtr->rcBound.left,
3420 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3426 /* << TOOLBAR_GetObject >> */
3430 TOOLBAR_GetPadding (HWND hwnd)
3432 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3435 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3436 return (LRESULT) oldPad;
3441 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3444 TBUTTON_INFO *btnPtr;
3448 if (infoPtr == NULL)
3450 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3451 btnPtr = &infoPtr->buttons[nIndex];
3452 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3454 lpRect = (LPRECT)lParam;
3458 lpRect->left = btnPtr->rect.left;
3459 lpRect->right = btnPtr->rect.right;
3460 lpRect->bottom = btnPtr->rect.bottom;
3461 lpRect->top = btnPtr->rect.top;
3468 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3470 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3472 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3473 return infoPtr->nRows;
3480 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3482 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3485 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3489 return infoPtr->buttons[nIndex].fsState;
3494 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3496 return GetWindowLongW(hwnd, GWL_STYLE);
3501 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3505 if (infoPtr == NULL)
3508 return infoPtr->nMaxTextRows;
3513 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3515 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3517 if (infoPtr == NULL)
3519 return (LRESULT)infoPtr->hwndToolTip;
3524 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3528 TRACE("%s hwnd=%p stub!\n",
3529 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3531 return infoPtr->bUnicode;
3535 inline static LRESULT
3536 TOOLBAR_GetVersion (HWND hwnd)
3538 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3539 return infoPtr->iVersion;
3544 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3546 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3547 TBUTTON_INFO *btnPtr;
3552 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3556 btnPtr = &infoPtr->buttons[nIndex];
3557 if (LOWORD(lParam) == FALSE)
3558 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3560 btnPtr->fsState |= TBSTATE_HIDDEN;
3562 TOOLBAR_CalcToolbar (hwnd);
3564 InvalidateRect (hwnd, NULL, TRUE);
3570 inline static LRESULT
3571 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3573 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3578 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3580 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3581 TBUTTON_INFO *btnPtr;
3585 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3589 btnPtr = &infoPtr->buttons[nIndex];
3590 oldState = btnPtr->fsState;
3591 if (LOWORD(lParam) == FALSE)
3592 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3594 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3596 if(oldState != btnPtr->fsState)
3597 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3604 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3607 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3608 INT nIndex = (INT)wParam;
3609 TBUTTON_INFO *oldButtons;
3614 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3617 /* EPP: this seems to be an undocumented call (from my IE4)
3618 * I assume in that case that:
3619 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3620 * - index of insertion is at the end of existing buttons
3621 * I only see this happen with nIndex == -1, but it could have a special
3622 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3624 nIndex = infoPtr->nNumButtons;
3626 } else if (nIndex < 0)
3629 /* If the string passed is not an index, assume address of string
3630 and do our own AddString */
3631 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3635 TRACE("string %s passed instead of index, adding string\n",
3636 debugstr_a((LPSTR)lpTbb->iString));
3637 len = strlen((LPSTR)lpTbb->iString) + 2;
3639 strcpy(ptr, (LPSTR)lpTbb->iString);
3640 ptr[len - 1] = 0; /* ended by two '\0' */
3641 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3645 TRACE("inserting button index=%d\n", nIndex);
3646 if (nIndex > infoPtr->nNumButtons) {
3647 nIndex = infoPtr->nNumButtons;
3648 TRACE("adjust index=%d\n", nIndex);
3651 oldButtons = infoPtr->buttons;
3652 infoPtr->nNumButtons++;
3653 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3654 /* pre insert copy */
3656 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3657 nIndex * sizeof(TBUTTON_INFO));
3660 /* insert new button */
3661 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3662 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3663 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3664 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3665 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3666 /* if passed string and not index, then add string */
3667 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3668 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3671 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3673 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3676 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3677 ti.cbSize = sizeof (TTTOOLINFOA);
3679 ti.uId = lpTbb->idCommand;
3681 ti.lpszText = LPSTR_TEXTCALLBACKA;
3683 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3687 /* post insert copy */
3688 if (nIndex < infoPtr->nNumButtons - 1) {
3689 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3690 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3695 TOOLBAR_CalcToolbar (hwnd);
3697 InvalidateRect (hwnd, NULL, TRUE);
3704 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3707 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3708 INT nIndex = (INT)wParam;
3709 TBUTTON_INFO *oldButtons;
3714 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3717 /* EPP: this seems to be an undocumented call (from my IE4)
3718 * I assume in that case that:
3719 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3720 * - index of insertion is at the end of existing buttons
3721 * I only see this happen with nIndex == -1, but it could have a special
3722 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3724 nIndex = infoPtr->nNumButtons;
3726 } else if (nIndex < 0)
3729 /* If the string passed is not an index, assume address of string
3730 and do our own AddString */
3731 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3735 TRACE("string %s passed instead of index, adding string\n",
3736 debugstr_w((LPWSTR)lpTbb->iString));
3737 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3738 ptr = Alloc(len*sizeof(WCHAR));
3739 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3740 ptr[len - 1] = 0; /* ended by two '\0' */
3741 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3745 TRACE("inserting button index=%d\n", nIndex);
3746 if (nIndex > infoPtr->nNumButtons) {
3747 nIndex = infoPtr->nNumButtons;
3748 TRACE("adjust index=%d\n", nIndex);
3751 oldButtons = infoPtr->buttons;
3752 infoPtr->nNumButtons++;
3753 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3754 /* pre insert copy */
3756 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3757 nIndex * sizeof(TBUTTON_INFO));
3760 /* insert new button */
3761 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3762 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3763 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3764 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3765 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3766 /* if passed string and not index, then add string */
3767 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3768 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3771 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3773 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3776 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3777 ti.cbSize = sizeof (TTTOOLINFOW);
3779 ti.uId = lpTbb->idCommand;
3781 ti.lpszText = LPSTR_TEXTCALLBACKW;
3783 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3787 /* post insert copy */
3788 if (nIndex < infoPtr->nNumButtons - 1) {
3789 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3790 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3795 TOOLBAR_CalcToolbar (hwnd);
3797 InvalidateRect (hwnd, NULL, TRUE);
3803 /* << TOOLBAR_InsertMarkHitTest >> */
3807 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3812 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3816 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3821 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3826 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3830 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3835 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3840 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3844 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3849 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3854 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3858 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3863 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3868 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3872 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3877 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3882 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3886 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3891 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3894 tbab.hInst = (HINSTANCE)lParam;
3895 tbab.nID = (UINT_PTR)wParam;
3897 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3899 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3904 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3906 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3907 WCHAR wAccel = (WCHAR)wParam;
3908 UINT* pIDButton = (UINT*)lParam;
3909 WCHAR wszAccel[] = {'&',wAccel,0};
3912 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3913 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3915 for (i = 0; i < infoPtr->nNumButtons; i++)
3917 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3918 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3919 !(btnPtr->fsState & TBSTATE_HIDDEN))
3921 int iLen = strlenW(wszAccel);
3922 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3929 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3934 if (!strncmpiW(lpszStr, wszAccel, iLen))
3936 *pIDButton = btnPtr->idCommand;
3948 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3953 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3955 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3960 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3962 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3968 /* fixes up an index of a button affected by a move */
3969 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3973 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3975 else if (*pIndex == nIndex)
3976 *pIndex = nMoveIndex;
3980 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3982 else if (*pIndex == nIndex)
3983 *pIndex = nMoveIndex;
3989 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3991 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3994 INT nMoveIndex = (INT)lParam;
3995 TBUTTON_INFO button;
3997 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
3999 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4000 if ((nIndex == -1) || (nMoveIndex < 0))
4003 if (nMoveIndex > infoPtr->nNumButtons - 1)
4004 nMoveIndex = infoPtr->nNumButtons - 1;
4006 button = infoPtr->buttons[nIndex];
4008 /* move button right */
4009 if (nIndex < nMoveIndex)
4011 nCount = nMoveIndex - nIndex;
4012 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4013 infoPtr->buttons[nMoveIndex] = button;
4015 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4016 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4017 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4018 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4020 else if (nIndex > nMoveIndex) /* move button left */
4022 nCount = nIndex - nMoveIndex;
4023 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4024 infoPtr->buttons[nMoveIndex] = button;
4026 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4027 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4028 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4029 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4032 TOOLBAR_CalcToolbar(hwnd);
4033 InvalidateRect(hwnd, NULL, TRUE);
4040 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4042 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4043 TBUTTON_INFO *btnPtr;
4047 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4051 btnPtr = &infoPtr->buttons[nIndex];
4052 oldState = btnPtr->fsState;
4053 if (LOWORD(lParam) == FALSE)
4054 btnPtr->fsState &= ~TBSTATE_PRESSED;
4056 btnPtr->fsState |= TBSTATE_PRESSED;
4058 if(oldState != btnPtr->fsState)
4059 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4064 /* FIXME: there might still be some confusion her between number of buttons
4065 * and number of bitmaps */
4067 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4070 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4072 int i = 0, nOldButtons = 0, pos = 0;
4073 int nOldBitmaps, nNewBitmaps;
4074 HIMAGELIST himlDef = 0;
4076 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4077 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4078 lpReplace->nButtons);
4080 if (lpReplace->hInstOld == HINST_COMMCTRL)
4082 FIXME("changing standard bitmaps not implemented\n");
4085 else if (lpReplace->hInstOld != 0)
4087 FIXME("resources not in the current module not implemented\n");
4092 hBitmap = (HBITMAP) lpReplace->nIDNew;
4095 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4096 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4097 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4098 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4099 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4101 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4102 nOldButtons = tbi->nButtons;
4103 tbi->nButtons = lpReplace->nButtons;
4104 tbi->hInst = lpReplace->hInstNew;
4105 tbi->nID = lpReplace->nIDNew;
4106 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4109 pos += tbi->nButtons;
4112 if (nOldButtons == 0)
4114 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4118 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4119 nOldBitmaps = ImageList_GetImageCount(himlDef);
4121 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4123 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4124 ImageList_Remove(himlDef, i);
4128 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4129 HDC hdcImage, hdcBitmap;
4131 /* copy the bitmap before adding it so that the user's bitmap
4132 * doesn't get modified.
4134 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4136 hdcImage = CreateCompatibleDC(0);
4137 hdcBitmap = CreateCompatibleDC(0);
4139 /* create new bitmap */
4140 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4141 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4142 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4144 /* Copy the user's image */
4145 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4146 hdcBitmap, 0, 0, SRCCOPY);
4148 SelectObject (hdcImage, hOldBitmapLoad);
4149 SelectObject (hdcBitmap, hOldBitmapBitmap);
4150 DeleteDC (hdcImage);
4151 DeleteDC (hdcBitmap);
4153 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4154 nNewBitmaps = ImageList_GetImageCount(himlDef);
4155 DeleteObject (hbmLoad);
4158 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4160 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4161 pos, nOldBitmaps, nNewBitmaps);
4163 InvalidateRect(hwnd, NULL, TRUE);
4169 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4173 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4175 if (lpSave == NULL) return 0;
4178 /* save toolbar information */
4179 FIXME("save to \"%s\" \"%s\"\n",
4180 lpSave->pszSubKey, lpSave->pszValueName);
4185 /* restore toolbar information */
4187 FIXME("restore from \"%s\" \"%s\"\n",
4188 lpSave->pszSubKey, lpSave->pszValueName);
4199 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4202 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4203 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4209 /* save toolbar information */
4210 FIXME("save to \"%s\" \"%s\"\n",
4211 lpSave->pszSubKey, lpSave->pszValueName);
4216 /* restore toolbar information */
4218 FIXME("restore from \"%s\" \"%s\"\n",
4219 lpSave->pszSubKey, lpSave->pszValueName);
4230 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4233 BOOL bOldAnchor = infoPtr->bAnchor;
4235 infoPtr->bAnchor = (BOOL)wParam;
4237 return (LRESULT)bOldAnchor;
4242 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4244 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4245 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4247 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4250 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4252 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4255 if (infoPtr->nNumButtons > 0)
4256 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4257 infoPtr->nNumButtons,
4258 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4259 LOWORD(lParam), HIWORD(lParam));
4261 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4262 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4265 if ((himlDef == infoPtr->himlInt) &&
4266 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4268 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4269 infoPtr->nBitmapHeight);
4277 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4280 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4281 TBUTTON_INFO *btnPtr;
4287 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4290 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4291 lptbbi->dwMask & 0x80000000);
4295 btnPtr = &infoPtr->buttons[nIndex];
4296 if (lptbbi->dwMask & TBIF_COMMAND)
4297 btnPtr->idCommand = lptbbi->idCommand;
4298 if (lptbbi->dwMask & TBIF_IMAGE)
4299 btnPtr->iBitmap = lptbbi->iImage;
4300 if (lptbbi->dwMask & TBIF_LPARAM)
4301 btnPtr->dwData = lptbbi->lParam;
4302 if (lptbbi->dwMask & TBIF_SIZE)
4303 btnPtr->cx = lptbbi->cx;
4304 if (lptbbi->dwMask & TBIF_STATE)
4305 btnPtr->fsState = lptbbi->fsState;
4306 if (lptbbi->dwMask & TBIF_STYLE)
4307 btnPtr->fsStyle = lptbbi->fsStyle;
4309 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4310 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4311 /* iString is index, zero it to make Str_SetPtr succeed */
4314 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4317 /* save the button rect to see if we need to redraw the whole toolbar */
4318 oldBtnRect = btnPtr->rect;
4319 TOOLBAR_CalcToolbar(hwnd);
4321 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4322 InvalidateRect(hwnd, NULL, TRUE);
4324 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4331 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4334 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4335 TBUTTON_INFO *btnPtr;
4341 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4344 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4345 lptbbi->dwMask & 0x80000000);
4349 btnPtr = &infoPtr->buttons[nIndex];
4350 if (lptbbi->dwMask & TBIF_COMMAND)
4351 btnPtr->idCommand = lptbbi->idCommand;
4352 if (lptbbi->dwMask & TBIF_IMAGE)
4353 btnPtr->iBitmap = lptbbi->iImage;
4354 if (lptbbi->dwMask & TBIF_LPARAM)
4355 btnPtr->dwData = lptbbi->lParam;
4356 if (lptbbi->dwMask & TBIF_SIZE)
4357 btnPtr->cx = lptbbi->cx;
4358 if (lptbbi->dwMask & TBIF_STATE)
4359 btnPtr->fsState = lptbbi->fsState;
4360 if (lptbbi->dwMask & TBIF_STYLE)
4361 btnPtr->fsStyle = lptbbi->fsStyle;
4363 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4364 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4365 /* iString is index, zero it to make Str_SetPtr succeed */
4367 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4370 /* save the button rect to see if we need to redraw the whole toolbar */
4371 oldBtnRect = btnPtr->rect;
4372 TOOLBAR_CalcToolbar(hwnd);
4374 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4375 InvalidateRect(hwnd, NULL, TRUE);
4377 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4384 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4386 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4387 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4389 if ((cx < 0) || (cy < 0))
4391 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4395 /* The documentation claims you can only change the button size before
4396 * any button has been added. But this is wrong.
4397 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4398 * it to the toolbar, and it checks that the return value is nonzero - mjm
4399 * Further testing shows that we must actually perform the change too.
4402 * The documentation also does not mention that if 0 is supplied for
4403 * either size, the system changes it to the default of 24 wide and
4404 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4406 infoPtr->nButtonWidth = (cx) ? cx : 24;
4407 infoPtr->nButtonHeight = (cy) ? cy : 22;
4413 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4415 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4417 if (infoPtr == NULL) {
4418 TRACE("Toolbar not initialized yet?????\n");
4422 /* if setting to current values, ignore */
4423 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4424 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4425 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4426 infoPtr->cxMin, infoPtr->cxMax);
4430 /* save new values */
4431 infoPtr->cxMin = (INT)LOWORD(lParam);
4432 infoPtr->cxMax = (INT)HIWORD(lParam);
4434 /* if both values are 0 then we are done */
4436 TRACE("setting both min and max to 0, norecalc\n");
4440 /* otherwise we need to recalc the toolbar and in some cases
4441 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4442 which doesn't actually draw - GA). */
4443 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4444 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4446 TOOLBAR_CalcToolbar (hwnd);
4448 InvalidateRect (hwnd, NULL, TRUE);
4455 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4457 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4458 INT nIndex = (INT)wParam;
4460 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4463 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4465 if (infoPtr->hwndToolTip) {
4467 FIXME("change tool tip!\n");
4476 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4479 HIMAGELIST himl = (HIMAGELIST)lParam;
4480 HIMAGELIST himlTemp;
4483 if (infoPtr->iVersion >= 5)
4486 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4487 &infoPtr->cimlDis, himl, id);
4489 /* FIXME: redraw ? */
4491 return (LRESULT)himlTemp;
4496 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4498 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4501 dwTemp = infoPtr->dwDTFlags;
4502 infoPtr->dwDTFlags =
4503 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4505 return (LRESULT)dwTemp;
4508 /* This function differs a bit from what MSDN says it does:
4509 * 1. lParam contains extended style flags to OR with current style
4510 * (MSDN isn't clear on the OR bit)
4511 * 2. wParam appears to contain extended style flags to be reset
4512 * (MSDN says that this parameter is reserved)
4515 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4517 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4520 dwTemp = infoPtr->dwExStyle;
4521 infoPtr->dwExStyle &= ~wParam;
4522 infoPtr->dwExStyle |= (DWORD)lParam;
4524 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4526 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4527 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4528 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4530 TOOLBAR_CalcToolbar (hwnd);
4532 TOOLBAR_AutoSize(hwnd);
4534 InvalidateRect(hwnd, NULL, TRUE);
4536 return (LRESULT)dwTemp;
4541 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4544 HIMAGELIST himlTemp;
4545 HIMAGELIST himl = (HIMAGELIST)lParam;
4548 if (infoPtr->iVersion >= 5)
4551 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4553 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4554 &infoPtr->cimlHot, himl, id);
4556 /* FIXME: redraw ? */
4558 return (LRESULT)himlTemp;
4562 /* Makes previous hot button no longer hot, makes the specified
4563 * button hot and sends appropriate notifications. dwReason is one or
4564 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4565 * NOTE 1: this function does not validate nHit
4566 * NOTE 2: the name of this function is completely made up and
4567 * not based on any documentation from Microsoft. */
4569 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4571 if (infoPtr->nHotItem != nHit)
4573 NMTBHOTITEM nmhotitem;
4574 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4575 LRESULT no_highlight;
4577 /* Remove the effect of an old hot button if the button was
4578 drawn with the hot button effect */
4579 if(infoPtr->nHotItem >= 0)
4581 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4582 oldBtnPtr->bHot = FALSE;
4585 infoPtr->nHotItem = nHit;
4587 /* It's not a separator or in nowhere. It's a hot button. */
4589 btnPtr = &infoPtr->buttons[nHit];
4591 nmhotitem.dwFlags = dwReason;
4593 nmhotitem.idOld = oldBtnPtr->idCommand;
4595 nmhotitem.dwFlags |= HICF_ENTERING;
4597 nmhotitem.idNew = btnPtr->idCommand;
4599 nmhotitem.dwFlags |= HICF_LEAVING;
4601 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4603 /* now invalidate the old and new buttons so they will be painted */
4605 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4606 if (btnPtr && !no_highlight)
4608 btnPtr->bHot = TRUE;
4609 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4615 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4618 INT nOldHotItem = infoPtr->nHotItem;
4620 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4623 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4624 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4626 if (nOldHotItem < 0)
4629 return (LRESULT)nOldHotItem;
4634 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4636 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4637 HIMAGELIST himlTemp;
4638 HIMAGELIST himl = (HIMAGELIST)lParam;
4641 if (infoPtr->iVersion >= 5)
4644 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4645 &infoPtr->cimlDef, himl, id);
4647 infoPtr->nNumBitmaps = 0;
4648 for (i = 0; i < infoPtr->cimlDef; i++)
4649 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4651 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4652 &infoPtr->nBitmapHeight);
4653 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4654 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4655 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4657 InvalidateRect(hwnd, NULL, TRUE);
4659 return (LRESULT)himlTemp;
4664 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4668 infoPtr->nIndent = (INT)wParam;
4672 /* process only on indent changing */
4673 if(infoPtr->nIndent != (INT)wParam)
4675 infoPtr->nIndent = (INT)wParam;
4676 TOOLBAR_CalcToolbar (hwnd);
4677 InvalidateRect(hwnd, NULL, FALSE);
4684 /* << TOOLBAR_SetInsertMark >> */
4688 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4692 infoPtr->clrInsertMark = (COLORREF)lParam;
4694 /* FIXME : redraw ??*/
4701 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4705 if (infoPtr == NULL)
4708 infoPtr->nMaxTextRows = (INT)wParam;
4710 TOOLBAR_CalcToolbar(hwnd);
4715 /* MSDN gives slightly wrong info on padding.
4716 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4717 * 2. It is not used to create a blank area between the edge of the button
4718 * and the text or image if TBSTYLE_LIST is set. It is used to control
4719 * the gap between the image and text.
4720 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4721 * to control the bottom and right borders [with the border being
4722 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4723 * is shared evenly on both sides of the button.
4726 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4731 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4732 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4733 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4734 TRACE("cx=%ld, cy=%ld\n",
4735 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4736 return (LRESULT) oldPad;
4741 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4743 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4748 if (infoPtr == NULL)
4750 hwndOldNotify = infoPtr->hwndNotify;
4751 infoPtr->hwndNotify = (HWND)wParam;
4753 return (LRESULT)hwndOldNotify;
4758 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4760 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4761 LPRECT lprc = (LPRECT)lParam;
4765 if (LOWORD(wParam) > 1) {
4766 FIXME("multiple rows not supported!\n");
4769 if(infoPtr->nRows != LOWORD(wParam))
4771 infoPtr->nRows = LOWORD(wParam);
4773 /* recalculate toolbar */
4774 TOOLBAR_CalcToolbar (hwnd);
4776 /* repaint toolbar */
4777 InvalidateRect(hwnd, NULL, TRUE);
4780 /* return bounding rectangle */
4782 lprc->left = infoPtr->rcBound.left;
4783 lprc->right = infoPtr->rcBound.right;
4784 lprc->top = infoPtr->rcBound.top;
4785 lprc->bottom = infoPtr->rcBound.bottom;
4793 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4796 TBUTTON_INFO *btnPtr;
4799 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4803 btnPtr = &infoPtr->buttons[nIndex];
4805 /* if hidden state has changed the invalidate entire window and recalc */
4806 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4807 btnPtr->fsState = LOWORD(lParam);
4808 TOOLBAR_CalcToolbar (hwnd);
4809 InvalidateRect(hwnd, 0, TRUE);
4813 /* process state changing if current state doesn't match new state */
4814 if(btnPtr->fsState != LOWORD(lParam))
4816 btnPtr->fsState = LOWORD(lParam);
4817 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4825 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4827 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4833 inline static LRESULT
4834 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4836 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4838 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4840 if (infoPtr == NULL)
4842 infoPtr->hwndToolTip = (HWND)wParam;
4848 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4853 TRACE("%s hwnd=%p stub!\n",
4854 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4856 bTemp = infoPtr->bUnicode;
4857 infoPtr->bUnicode = (BOOL)wParam;
4864 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4868 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4869 comctl32_color.clrBtnHighlight :
4870 infoPtr->clrBtnHighlight;
4871 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4872 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4878 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4882 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4883 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4884 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4886 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4887 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4888 InvalidateRect(hwnd, NULL, TRUE);
4894 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4897 INT iOldVersion = infoPtr->iVersion;
4899 infoPtr->iVersion = iVersion;
4901 if (infoPtr->iVersion >= 5)
4902 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4909 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4911 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4912 WORD iString = HIWORD(wParam);
4913 WORD buffersize = LOWORD(wParam);
4914 LPSTR str = (LPSTR)lParam;
4917 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4919 if (iString < infoPtr->nNumStrings)
4921 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4923 TRACE("returning %s\n", debugstr_a(str));
4926 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4933 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4935 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4936 WORD iString = HIWORD(wParam);
4937 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4938 LPWSTR str = (LPWSTR)lParam;
4941 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4943 if (iString < infoPtr->nNumStrings)
4945 len = min(len, strlenW(infoPtr->strings[iString]));
4946 ret = (len+1)*sizeof(WCHAR);
4947 memcpy(str, infoPtr->strings[iString], ret);
4950 TRACE("returning %s\n", debugstr_w(str));
4953 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4958 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4959 * is the maximum size of the toolbar? */
4960 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4962 SIZE * pSize = (SIZE*)lParam;
4963 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4968 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4969 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4970 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4973 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4976 INT nOldHotItem = infoPtr->nHotItem;
4978 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4979 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4981 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4984 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4988 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4991 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4992 * which controls the amount of spacing between the image and the text
4993 * of buttons for TBSTYLE_LIST toolbars. */
4994 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4996 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4998 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5001 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5003 infoPtr->iListGap = (INT)wParam;
5005 TOOLBAR_CalcToolbar(hwnd);
5006 InvalidateRect(hwnd, NULL, TRUE);
5011 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5012 * of image lists associated with the various states. */
5013 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5015 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5017 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5019 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5023 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5026 LPSIZE lpsize = (LPSIZE)lParam;
5032 * Testing shows the following:
5033 * wParam = 0 adjust cx value
5034 * = 1 set cy value to max size.
5035 * lParam pointer to SIZE structure
5038 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5039 wParam, lParam, lpsize->cx, lpsize->cy);
5043 if (lpsize->cx == -1) {
5044 /* **** this is wrong, native measures each button and sets it */
5045 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5047 else if(HIWORD(lpsize->cx)) {
5049 HWND hwndParent = GetParent(hwnd);
5051 GetWindowRect(hwnd, &rc);
5052 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5053 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5054 rc.left, rc.top, rc.right, rc.bottom);
5055 lpsize->cx = max(rc.right-rc.left,
5056 infoPtr->rcBound.right - infoPtr->rcBound.left);
5059 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5063 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5064 /* lpsize->cy = infoPtr->nHeight; */
5067 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5071 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5072 lpsize->cx, lpsize->cy);
5076 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5078 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5080 InvalidateRect(hwnd, NULL, TRUE);
5086 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5089 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5092 TRACE("hwnd = %p\n", hwnd);
5094 /* initialize info structure */
5095 infoPtr->nButtonHeight = 22;
5096 infoPtr->nButtonWidth = 24;
5097 infoPtr->nBitmapHeight = 15;
5098 infoPtr->nBitmapWidth = 16;
5100 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5101 infoPtr->nMaxTextRows = 1;
5102 infoPtr->cxMin = -1;
5103 infoPtr->cxMax = -1;
5104 infoPtr->nNumBitmaps = 0;
5105 infoPtr->nNumStrings = 0;
5107 infoPtr->bCaptured = FALSE;
5108 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5109 infoPtr->nButtonDown = -1;
5110 infoPtr->nButtonDrag = -1;
5111 infoPtr->nOldHit = -1;
5112 infoPtr->nHotItem = -1;
5113 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5114 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5115 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5116 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5117 infoPtr->bDragOutSent = FALSE;
5118 infoPtr->iVersion = 0;
5119 infoPtr->hwndSelf = hwnd;
5120 infoPtr->bDoRedraw = TRUE;
5121 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5122 infoPtr->clrBtnShadow = CLR_DEFAULT;
5123 /* not sure where the +1 comes from, but this comes to the same value
5124 * as native so this is probably correct */
5125 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5126 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5127 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5128 infoPtr->dwStyle = dwStyle;
5129 GetClientRect(hwnd, &infoPtr->client_rect);
5130 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5132 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5133 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5135 if (dwStyle & TBSTYLE_TOOLTIPS) {
5136 /* Create tooltip control */
5137 infoPtr->hwndToolTip =
5138 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5139 CW_USEDEFAULT, CW_USEDEFAULT,
5140 CW_USEDEFAULT, CW_USEDEFAULT,
5143 /* Send NM_TOOLTIPSCREATED notification */
5144 if (infoPtr->hwndToolTip) {
5145 NMTOOLTIPSCREATED nmttc;
5147 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5149 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5150 NM_TOOLTIPSCREATED);
5154 TOOLBAR_CheckStyle (hwnd, dwStyle);
5156 TOOLBAR_CalcToolbar(hwnd);
5163 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5167 /* delete tooltip control */
5168 if (infoPtr->hwndToolTip)
5169 DestroyWindow (infoPtr->hwndToolTip);
5171 /* delete temporary buffer for tooltip text */
5172 if (infoPtr->pszTooltipText)
5173 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5175 /* delete button data */
5176 if (infoPtr->buttons)
5177 Free (infoPtr->buttons);
5179 /* delete strings */
5180 if (infoPtr->strings) {
5182 for (i = 0; i < infoPtr->nNumStrings; i++)
5183 if (infoPtr->strings[i])
5184 Free (infoPtr->strings[i]);
5186 Free (infoPtr->strings);
5189 /* destroy internal image list */
5190 if (infoPtr->himlInt)
5191 ImageList_Destroy (infoPtr->himlInt);
5193 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5194 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5195 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5197 /* delete default font */
5199 DeleteObject (infoPtr->hDefaultFont);
5201 /* free toolbar info data */
5203 SetWindowLongPtrW (hwnd, 0, 0);
5210 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5213 NMTBCUSTOMDRAW tbcd;
5217 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5218 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5219 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5220 tbcd.nmcd.hdc = (HDC)wParam;
5221 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5222 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5224 /* FIXME: in general the return flags *can* be or'ed together */
5225 switch (infoPtr->dwBaseCustDraw)
5227 case CDRF_DODEFAULT:
5229 case CDRF_SKIPDEFAULT:
5232 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5237 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5238 * to my parent for processing.
5240 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5242 HDC hdc = (HDC)wParam;
5247 parent = GetParent(hwnd);
5248 MapWindowPoints(hwnd, parent, &pt, 1);
5249 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5250 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5251 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5254 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5256 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5257 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5258 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5259 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5260 tbcd.nmcd.hdc = (HDC)wParam;
5261 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5262 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5263 switch (infoPtr->dwBaseCustDraw)
5265 case CDRF_DODEFAULT:
5267 case CDRF_SKIPDEFAULT:
5270 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5279 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5281 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5283 return (LRESULT)infoPtr->hFont;
5288 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5293 pt.x = (INT)LOWORD(lParam);
5294 pt.y = (INT)HIWORD(lParam);
5295 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5298 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5299 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5300 TOOLBAR_Customize (hwnd);
5307 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5310 TBUTTON_INFO *btnPtr;
5314 BOOL bDragKeyPressed;
5318 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5319 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5321 bDragKeyPressed = (wParam & MK_SHIFT);
5323 if (infoPtr->hwndToolTip)
5324 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5325 WM_LBUTTONDOWN, wParam, lParam);
5327 pt.x = (INT)LOWORD(lParam);
5328 pt.y = (INT)HIWORD(lParam);
5329 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5331 btnPtr = &infoPtr->buttons[nHit];
5333 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5335 infoPtr->nButtonDrag = nHit;
5338 /* If drag cursor has not been loaded, load it.
5339 * Note: it doesn't need to be freed */
5341 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5342 SetCursor(hCursorDrag);
5347 infoPtr->nOldHit = nHit;
5349 CopyRect(&arrowRect, &btnPtr->rect);
5350 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5352 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5353 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5354 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5355 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5356 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5357 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5361 /* draw in pressed state */
5362 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5363 btnPtr->fsState |= TBSTATE_PRESSED;
5365 btnPtr->bDropDownPressed = TRUE;
5366 RedrawWindow(hwnd,&btnPtr->rect,0,
5367 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5369 nmtb.iItem = btnPtr->idCommand;
5370 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5373 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5374 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5376 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5378 if (res != TBDDRET_TREATPRESSED)
5382 /* redraw button in unpressed state */
5383 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5384 btnPtr->fsState &= ~TBSTATE_PRESSED;
5386 btnPtr->bDropDownPressed = FALSE;
5387 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5389 /* find and set hot item
5390 * NOTE: native doesn't do this, but that is a bug */
5392 ScreenToClient(hwnd, &pt);
5393 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5394 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5396 /* remove any left mouse button down or double-click messages
5397 * so that we can get a toggle effect on the button */
5398 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5399 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5404 /* otherwise drop through and process as pushed */
5406 infoPtr->bCaptured = TRUE;
5407 infoPtr->nButtonDown = nHit;
5408 infoPtr->bDragOutSent = FALSE;
5410 btnPtr->fsState |= TBSTATE_PRESSED;
5412 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5414 if (btnPtr->fsState & TBSTATE_ENABLED)
5415 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5422 nmtb.iItem = btnPtr->idCommand;
5423 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5424 nmtb.tbButton.idCommand = btnPtr->idCommand;
5425 nmtb.tbButton.fsState = btnPtr->fsState;
5426 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5427 nmtb.tbButton.dwData = btnPtr->dwData;
5428 nmtb.tbButton.iString = btnPtr->iString;
5429 nmtb.cchText = 0; /* !!! not correct */
5430 nmtb.pszText = 0; /* !!! not correct */
5431 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5438 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5440 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5441 TBUTTON_INFO *btnPtr;
5445 BOOL bSendMessage = TRUE;
5450 if (infoPtr->hwndToolTip)
5451 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5452 WM_LBUTTONUP, wParam, lParam);
5454 pt.x = (INT)LOWORD(lParam);
5455 pt.y = (INT)HIWORD(lParam);
5456 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5458 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5460 if (infoPtr->nButtonDrag >= 0) {
5464 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5467 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5469 GetClientRect(hwnd, &rcClient);
5470 if (PtInRect(&rcClient, pt))
5477 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5480 if (nButton == infoPtr->nButtonDrag)
5482 /* if the button is moved sightly left and we have a
5483 * separator there then remove it */
5484 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5486 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5487 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5489 else /* else insert a separator before the dragged button */
5492 memset(&tbb, 0, sizeof(tbb));
5493 tbb.fsStyle = BTNS_SEP;
5495 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5502 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5503 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5505 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5508 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5513 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5514 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5517 /* button under cursor changed so need to re-set hot item */
5518 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5519 infoPtr->nButtonDrag = -1;
5521 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5523 else if (infoPtr->nButtonDown >= 0) {
5524 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5525 btnPtr->fsState &= ~TBSTATE_PRESSED;
5527 if (btnPtr->fsStyle & BTNS_CHECK) {
5528 if (btnPtr->fsStyle & BTNS_GROUP) {
5529 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5531 if (nOldIndex == nHit)
5532 bSendMessage = FALSE;
5533 if ((nOldIndex != nHit) &&
5535 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5536 btnPtr->fsState |= TBSTATE_CHECKED;
5539 if (btnPtr->fsState & TBSTATE_CHECKED)
5540 btnPtr->fsState &= ~TBSTATE_CHECKED;
5542 btnPtr->fsState |= TBSTATE_CHECKED;
5546 if (nOldIndex != -1)
5547 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5550 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5551 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5552 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5554 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5556 infoPtr->nButtonDown = -1;
5558 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5559 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5560 NM_RELEASEDCAPTURE);
5562 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5565 nmtb.iItem = btnPtr->idCommand;
5566 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5567 nmtb.tbButton.idCommand = btnPtr->idCommand;
5568 nmtb.tbButton.fsState = btnPtr->fsState;
5569 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5570 nmtb.tbButton.dwData = btnPtr->dwData;
5571 nmtb.tbButton.iString = btnPtr->iString;
5572 nmtb.cchText = 0; /* !!! not correct */
5573 nmtb.pszText = 0; /* !!! not correct */
5574 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5577 if (btnPtr->fsState & TBSTATE_ENABLED)
5579 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5580 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5582 /* !!! Undocumented - toolbar at 4.71 level and above sends
5583 * either NM_RCLICK or NM_CLICK with the NMMOUSE structure.
5584 * Only NM_RCLICK is documented.
5586 nmmouse.dwItemSpec = btnPtr->idCommand;
5587 nmmouse.dwItemData = btnPtr->dwData;
5588 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5595 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5602 pt.x = LOWORD(lParam);
5603 pt.y = HIWORD(lParam);
5605 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5607 if (nmmouse.dwHitInfo < 0) {
5608 nmmouse.dwItemSpec = -1;
5610 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5611 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5614 ClientToScreen(hwnd, &pt);
5615 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5617 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5623 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5630 pt.x = LOWORD(lParam);
5631 pt.y = HIWORD(lParam);
5633 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5635 if (nmmouse.dwHitInfo < 0)
5636 nmmouse.dwItemSpec = -1;
5638 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5639 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5642 ClientToScreen(hwnd, &pt);
5643 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5645 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RDBLCLK);
5651 TOOLBAR_CaptureChanged(HWND hwnd)
5653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5654 TBUTTON_INFO *btnPtr;
5656 infoPtr->bCaptured = FALSE;
5658 if (infoPtr->nButtonDown >= 0)
5660 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5661 btnPtr->fsState &= ~TBSTATE_PRESSED;
5663 infoPtr->nOldHit = -1;
5665 if (btnPtr->fsState & TBSTATE_ENABLED)
5666 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5672 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5674 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5675 TBUTTON_INFO *hotBtnPtr;
5677 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5679 /* don't remove hot effects when in drop-down */
5680 if (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed)
5681 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5683 if (infoPtr->nOldHit < 0)
5686 /* If the last button we were over is depressed then make it not */
5687 /* depressed and redraw it */
5688 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5690 TBUTTON_INFO *btnPtr;
5693 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5695 btnPtr->fsState &= ~TBSTATE_PRESSED;
5697 rc1 = hotBtnPtr->rect;
5698 InflateRect (&rc1, 1, 1);
5699 InvalidateRect (hwnd, &rc1, TRUE);
5702 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5705 ZeroMemory(&nmt, sizeof(nmt));
5706 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5707 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5708 infoPtr->bDragOutSent = TRUE;
5711 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5717 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5719 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5721 TRACKMOUSEEVENT trackinfo;
5723 TBUTTON_INFO *btnPtr;
5725 /* fill in the TRACKMOUSEEVENT struct */
5726 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5727 trackinfo.dwFlags = TME_QUERY;
5728 trackinfo.hwndTrack = hwnd;
5729 trackinfo.dwHoverTime = HOVER_DEFAULT;
5731 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5732 _TrackMouseEvent(&trackinfo);
5734 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5735 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5736 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5738 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5739 /* and can properly deactivate the hot toolbar button */
5740 _TrackMouseEvent(&trackinfo);
5743 if (infoPtr->hwndToolTip)
5744 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5745 WM_MOUSEMOVE, wParam, lParam);
5747 pt.x = (INT)LOWORD(lParam);
5748 pt.y = (INT)HIWORD(lParam);
5750 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5752 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5754 if (infoPtr->nOldHit != nHit)
5756 if (infoPtr->bCaptured)
5758 if (!infoPtr->bDragOutSent)
5761 ZeroMemory(&nmt, sizeof(nmt));
5762 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5763 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5764 infoPtr->bDragOutSent = TRUE;
5767 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5768 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5769 btnPtr->fsState &= ~TBSTATE_PRESSED;
5770 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5772 else if (nHit == infoPtr->nButtonDown) {
5773 btnPtr->fsState |= TBSTATE_PRESSED;
5774 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5776 infoPtr->nOldHit = nHit;
5784 inline static LRESULT
5785 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5787 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5788 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5790 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5794 inline static LRESULT
5795 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5797 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5798 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5800 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5805 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5807 TOOLBAR_INFO *infoPtr;
5808 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5811 /* allocate memory for info structure */
5812 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5813 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5816 infoPtr->dwStructSize = sizeof(TBBUTTON);
5819 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5820 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5821 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5822 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5825 /* native control does:
5826 * Get a lot of colors and brushes
5828 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5829 * CreateFontIndirectA(adr1)
5830 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5831 * hdc = GetDC(toolbar)
5832 * GetSystemMetrics(0x48)
5833 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5834 * 0, 0, 0, 0, "MARLETT")
5835 * oldfnt = SelectObject(hdc, fnt2)
5836 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5837 * GetTextMetricsA(hdc, adr3)
5838 * SelectObject(hdc, oldfnt)
5839 * DeleteObject(fnt2)
5841 * InvalidateRect(toolbar, 0, 1)
5842 * SetWindowLongA(toolbar, 0, addr)
5843 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5846 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5847 * ie 2 0x4600094c 0x4600094c 0x4600894d
5848 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5849 * rebar 0x50008844 0x40008844 0x50008845
5850 * pager 0x50000844 0x40000844 0x50008845
5851 * IC35mgr 0x5400084e **nochange**
5852 * on entry to _NCCREATE 0x5400084e
5853 * rowlist 0x5400004e **nochange**
5854 * on entry to _NCCREATE 0x5400004e
5858 /* I think the code below is a bug, but it is the way that the native
5859 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5860 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5861 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5862 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5863 * Some how, the only cases of this seem to be MFC programs.
5865 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5866 * does not occur in the WM_STYLECHANGING routine.
5867 * (Guy Albertelli 9/2001)
5870 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5871 styleadd |= TBSTYLE_TRANSPARENT;
5872 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5873 styleadd |= CCS_TOP; /* default to top */
5874 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5877 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5882 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5884 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5888 if (dwStyle & WS_MINIMIZE)
5889 return 0; /* Nothing to do */
5891 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5893 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5896 if (!(dwStyle & CCS_NODIVIDER))
5898 GetWindowRect (hwnd, &rcWindow);
5899 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5900 if( dwStyle & WS_BORDER )
5901 OffsetRect (&rcWindow, 1, 1);
5902 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5905 ReleaseDC( hwnd, hdc );
5911 /* handles requests from the tooltip control on what text to display */
5912 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5914 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5916 TRACE("button index = %d\n", index);
5918 if (infoPtr->pszTooltipText)
5920 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5921 infoPtr->pszTooltipText = NULL;
5927 if (infoPtr->bNtfUnicode)
5929 WCHAR wszBuffer[INFOTIPSIZE+1];
5930 NMTBGETINFOTIPW tbgit;
5931 int len; /* in chars */
5933 wszBuffer[0] = '\0';
5934 wszBuffer[INFOTIPSIZE] = '\0';
5936 tbgit.pszText = wszBuffer;
5937 tbgit.cchTextMax = INFOTIPSIZE;
5938 tbgit.iItem = lpnmtdi->hdr.idFrom;
5939 tbgit.lParam = infoPtr->buttons[index].dwData;
5941 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5943 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5945 len = strlenW(tbgit.pszText);
5946 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5948 /* need to allocate temporary buffer in infoPtr as there
5949 * isn't enough space in buffer passed to us by the
5950 * tooltip control */
5951 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5952 if (infoPtr->pszTooltipText)
5954 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5955 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5961 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5967 CHAR szBuffer[INFOTIPSIZE+1];
5968 NMTBGETINFOTIPA tbgit;
5969 int len; /* in chars */
5972 szBuffer[INFOTIPSIZE] = '\0';
5974 tbgit.pszText = szBuffer;
5975 tbgit.cchTextMax = INFOTIPSIZE;
5976 tbgit.iItem = lpnmtdi->hdr.idFrom;
5977 tbgit.lParam = infoPtr->buttons[index].dwData;
5979 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5981 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5983 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5984 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5986 /* need to allocate temporary buffer in infoPtr as there
5987 * isn't enough space in buffer passed to us by the
5988 * tooltip control */
5989 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5990 if (infoPtr->pszTooltipText)
5992 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5993 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5999 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6004 /* if button has text, but it is not shown then automatically
6005 * use that text as tooltip */
6006 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6007 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6009 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6010 int len = pszText ? strlenW(pszText) : 0;
6012 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6014 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6016 /* need to allocate temporary buffer in infoPtr as there
6017 * isn't enough space in buffer passed to us by the
6018 * tooltip control */
6019 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6020 if (infoPtr->pszTooltipText)
6022 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6023 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6029 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6034 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6036 /* last resort: send notification on to app */
6037 /* FIXME: find out what is really used here */
6038 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6042 inline static LRESULT
6043 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6045 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6046 LPNMHDR lpnmh = (LPNMHDR)lParam;
6048 switch (lpnmh->code)
6052 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6054 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6055 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6056 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6060 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6061 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6069 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6071 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6072 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6073 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6074 lppgs->iScroll, lppgs->iDir);
6078 case TTN_GETDISPINFOW:
6079 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6081 case TTN_GETDISPINFOA:
6082 FIXME("TTN_GETDISPINFOA - stub\n");
6092 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6094 /* remove this routine when Toolbar is improved to pass infoPtr
6095 * around instead of hwnd.
6097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6098 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6103 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6107 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6109 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6112 if (lParam == NF_REQUERY) {
6113 i = SendMessageA(infoPtr->hwndNotify,
6114 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6115 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6116 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6120 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6123 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6128 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6130 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6134 /* fill ps.rcPaint with a default rect */
6135 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6137 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6139 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6140 ps.rcPaint.left, ps.rcPaint.top,
6141 ps.rcPaint.right, ps.rcPaint.bottom);
6143 TOOLBAR_Refresh (hwnd, hdc, &ps);
6144 if (!wParam) EndPaint (hwnd, &ps);
6151 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6152 /*****************************************************
6155 * Handles the WM_SETREDRAW message.
6158 * According to testing V4.71 of COMCTL32 returns the
6159 * *previous* status of the redraw flag (either 0 or 1)
6160 * instead of the MSDN documented value of 0 if handled.
6161 * (For laughs see the "consistency" with same function
6164 *****************************************************/
6166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6167 BOOL oldredraw = infoPtr->bDoRedraw;
6169 TRACE("set to %s\n",
6170 (wParam) ? "TRUE" : "FALSE");
6171 infoPtr->bDoRedraw = (BOOL) wParam;
6173 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6175 return (oldredraw) ? 1 : 0;
6180 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6182 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6183 DWORD dwStyle = infoPtr->dwStyle;
6192 /* Resize deadlock check */
6193 if (infoPtr->bAutoSize) {
6194 infoPtr->bAutoSize = FALSE;
6198 /* FIXME: optimize to only update size if the new size doesn't */
6199 /* match the current size */
6201 flags = (INT) wParam;
6203 /* FIXME for flags =
6204 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6207 TRACE("sizing toolbar!\n");
6209 if (flags == SIZE_RESTORED) {
6210 /* width and height don't apply */
6211 parent = GetParent (hwnd);
6212 GetClientRect(parent, &parent_rect);
6213 x = parent_rect.left;
6214 y = parent_rect.top;
6216 if (dwStyle & CCS_NORESIZE) {
6217 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6220 * this sets the working width of the toolbar, and
6221 * Calc Toolbar will not adjust it, only the height
6223 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6224 cy = infoPtr->nHeight;
6225 cx = infoPtr->nWidth;
6226 TOOLBAR_CalcToolbar (hwnd);
6227 infoPtr->nWidth = cx;
6228 infoPtr->nHeight = cy;
6231 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6232 TOOLBAR_CalcToolbar (hwnd);
6233 cy = infoPtr->nHeight;
6234 cx = infoPtr->nWidth;
6236 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6237 GetWindowRect(hwnd, &window_rect);
6238 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6239 y = window_rect.top;
6241 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6242 GetWindowRect(hwnd, &window_rect);
6243 y = parent_rect.bottom -
6244 ( window_rect.bottom - window_rect.top);
6248 if (dwStyle & CCS_NOPARENTALIGN) {
6249 uPosFlags |= SWP_NOMOVE;
6250 cy = infoPtr->nHeight;
6251 cx = infoPtr->nWidth;
6254 if (!(dwStyle & CCS_NODIVIDER))
6255 cy += GetSystemMetrics(SM_CYEDGE);
6257 if (dwStyle & WS_BORDER)
6260 cy += GetSystemMetrics(SM_CYEDGE);
6261 cx += GetSystemMetrics(SM_CYEDGE);
6264 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6266 RECT delta_width, delta_height, client, dummy;
6267 DWORD min_x, max_x, min_y, max_y;
6268 TBUTTON_INFO *btnPtr;
6271 GetClientRect(hwnd, &client);
6272 if(client.right > infoPtr->client_rect.right)
6274 min_x = infoPtr->client_rect.right;
6275 max_x = client.right;
6279 max_x = infoPtr->client_rect.right;
6280 min_x = client.right;
6282 if(client.bottom > infoPtr->client_rect.bottom)
6284 min_y = infoPtr->client_rect.bottom;
6285 max_y = client.bottom;
6289 max_y = infoPtr->client_rect.bottom;
6290 min_y = client.bottom;
6293 SetRect(&delta_width, min_x, 0, max_x, min_y);
6294 SetRect(&delta_height, 0, min_y, max_x, max_y);
6296 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6297 btnPtr = infoPtr->buttons;
6298 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6299 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6300 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6301 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6304 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6305 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6307 GetClientRect(hwnd, &infoPtr->client_rect);
6313 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6317 if (nType == GWL_STYLE) {
6318 if (lpStyle->styleNew & TBSTYLE_LIST) {
6319 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6322 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6324 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6325 (TBSTYLE_FLAT | TBSTYLE_LIST));
6326 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6328 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6330 infoPtr->dwStyle = lpStyle->styleNew;
6333 TOOLBAR_CalcToolbar(hwnd);
6335 TOOLBAR_AutoSize (hwnd);
6337 InvalidateRect(hwnd, NULL, TRUE);
6344 TOOLBAR_SysColorChange (HWND hwnd)
6346 COMCTL32_RefreshSysColors();
6353 static LRESULT WINAPI
6354 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6358 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6359 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6361 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6362 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6367 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6369 case TB_ADDBUTTONSA:
6370 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6372 case TB_ADDBUTTONSW:
6373 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6376 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6379 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6382 return TOOLBAR_AutoSize (hwnd);
6384 case TB_BUTTONCOUNT:
6385 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6387 case TB_BUTTONSTRUCTSIZE:
6388 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6390 case TB_CHANGEBITMAP:
6391 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6393 case TB_CHECKBUTTON:
6394 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6396 case TB_COMMANDTOINDEX:
6397 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6400 return TOOLBAR_Customize (hwnd);
6402 case TB_DELETEBUTTON:
6403 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6405 case TB_ENABLEBUTTON:
6406 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6408 case TB_GETANCHORHIGHLIGHT:
6409 return TOOLBAR_GetAnchorHighlight (hwnd);
6412 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6414 case TB_GETBITMAPFLAGS:
6415 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6418 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6420 case TB_GETBUTTONINFOA:
6421 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6423 case TB_GETBUTTONINFOW:
6424 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6426 case TB_GETBUTTONSIZE:
6427 return TOOLBAR_GetButtonSize (hwnd);
6429 case TB_GETBUTTONTEXTA:
6430 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6432 case TB_GETBUTTONTEXTW:
6433 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6435 case TB_GETDISABLEDIMAGELIST:
6436 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6438 case TB_GETEXTENDEDSTYLE:
6439 return TOOLBAR_GetExtendedStyle (hwnd);
6441 case TB_GETHOTIMAGELIST:
6442 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6445 return TOOLBAR_GetHotItem (hwnd);
6447 case TB_GETIMAGELIST:
6448 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6450 /* case TB_GETINSERTMARK: */ /* 4.71 */
6451 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6453 case TB_GETITEMRECT:
6454 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6457 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6459 /* case TB_GETOBJECT: */ /* 4.71 */
6462 return TOOLBAR_GetPadding (hwnd);
6465 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6468 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6471 return TOOLBAR_GetState (hwnd, wParam, lParam);
6474 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6477 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6480 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6482 case TB_GETTEXTROWS:
6483 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6485 case TB_GETTOOLTIPS:
6486 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6488 case TB_GETUNICODEFORMAT:
6489 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6492 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6495 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6497 case TB_INDETERMINATE:
6498 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6500 case TB_INSERTBUTTONA:
6501 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6503 case TB_INSERTBUTTONW:
6504 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6506 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6508 case TB_ISBUTTONCHECKED:
6509 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6511 case TB_ISBUTTONENABLED:
6512 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6514 case TB_ISBUTTONHIDDEN:
6515 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6517 case TB_ISBUTTONHIGHLIGHTED:
6518 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6520 case TB_ISBUTTONINDETERMINATE:
6521 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6523 case TB_ISBUTTONPRESSED:
6524 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6527 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6529 case TB_MAPACCELERATORA:
6530 case TB_MAPACCELERATORW:
6531 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6534 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6537 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6539 case TB_PRESSBUTTON:
6540 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6542 case TB_REPLACEBITMAP:
6543 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6545 case TB_SAVERESTOREA:
6546 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6548 case TB_SAVERESTOREW:
6549 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6551 case TB_SETANCHORHIGHLIGHT:
6552 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6554 case TB_SETBITMAPSIZE:
6555 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6557 case TB_SETBUTTONINFOA:
6558 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6560 case TB_SETBUTTONINFOW:
6561 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6563 case TB_SETBUTTONSIZE:
6564 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6566 case TB_SETBUTTONWIDTH:
6567 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6570 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6572 case TB_SETDISABLEDIMAGELIST:
6573 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6575 case TB_SETDRAWTEXTFLAGS:
6576 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6578 case TB_SETEXTENDEDSTYLE:
6579 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6581 case TB_SETHOTIMAGELIST:
6582 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6585 return TOOLBAR_SetHotItem (hwnd, wParam);
6587 case TB_SETIMAGELIST:
6588 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6591 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6593 /* case TB_SETINSERTMARK: */ /* 4.71 */
6595 case TB_SETINSERTMARKCOLOR:
6596 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6598 case TB_SETMAXTEXTROWS:
6599 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6602 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6605 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6608 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6611 return TOOLBAR_SetState (hwnd, wParam, lParam);
6614 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6616 case TB_SETTOOLTIPS:
6617 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6619 case TB_SETUNICODEFORMAT:
6620 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6623 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6626 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6629 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6632 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6635 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6638 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6640 /* Common Control Messages */
6642 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6643 case CCM_GETCOLORSCHEME:
6644 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6646 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6647 case CCM_SETCOLORSCHEME:
6648 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6650 case CCM_GETVERSION:
6651 return TOOLBAR_GetVersion (hwnd);
6653 case CCM_SETVERSION:
6654 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6660 return TOOLBAR_Create (hwnd, wParam, lParam);
6663 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6666 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6669 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6671 /* case WM_KEYDOWN: */
6672 /* case WM_KILLFOCUS: */
6674 case WM_LBUTTONDBLCLK:
6675 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6677 case WM_LBUTTONDOWN:
6678 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6681 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6684 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6686 case WM_RBUTTONDBLCLK:
6687 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6690 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6693 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6695 case WM_CAPTURECHANGED:
6696 return TOOLBAR_CaptureChanged(hwnd);
6699 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6702 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6705 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6708 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6711 return TOOLBAR_Notify (hwnd, wParam, lParam);
6713 case WM_NOTIFYFORMAT:
6714 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6717 return TOOLBAR_Paint (hwnd, wParam);
6720 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6723 return TOOLBAR_Size (hwnd, wParam, lParam);
6725 case WM_STYLECHANGED:
6726 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6728 case WM_SYSCOLORCHANGE:
6729 return TOOLBAR_SysColorChange (hwnd);
6731 /* case WM_WININICHANGE: */
6736 case WM_MEASUREITEM:
6738 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6740 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6741 case PGM_FORWARDMOUSE:
6742 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6745 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6746 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6747 uMsg, wParam, lParam);
6748 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6755 TOOLBAR_Register (void)
6759 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6760 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6761 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6762 wndClass.cbClsExtra = 0;
6763 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6764 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6765 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6766 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6768 RegisterClassA (&wndClass);
6773 TOOLBAR_Unregister (void)
6775 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6778 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6783 /* Check if the entry already exists */
6784 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6786 /* If this is a new entry we must create it and insert into the array */
6791 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6794 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6795 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6810 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6814 for (i = 0; i < *cies; i++)
6824 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6832 for (i = 0; i < cies; i++)
6834 if (pies[i]->id == id)
6846 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6848 HIMAGELIST himlDef = 0;
6849 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6852 himlDef = pie->himl;
6858 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6860 if (infoPtr->bUnicode)
6861 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6868 nmtba.iItem = nmtb->iItem;
6869 nmtba.pszText = Buffer;
6870 nmtba.cchText = 256;
6871 ZeroMemory(nmtba.pszText, nmtba.cchText);
6873 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6875 int ccht = strlen(nmtba.pszText);
6877 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6878 nmtb->pszText, nmtb->cchText);
6880 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6889 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6890 int iItem, PCUSTOMBUTTON btnInfo)
6895 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6897 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);