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 = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
658 GetDeviceCaps(hdc,BITSPIXEL), NULL);
659 SelectObject(hdcImage, hbmImage);
660 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
661 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
664 hdcMask = CreateCompatibleDC(0);
665 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
666 SelectObject(hdcMask, hbmMask);
668 /* Remove the background and all white pixels */
669 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
670 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
671 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
672 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
674 /* draw the new mask 'etched' to hdc */
675 SetBkColor(hdc, RGB(255, 255, 255));
676 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
677 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
678 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
679 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
680 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
683 DeleteObject(hbmImage);
685 DeleteObject (hbmMask);
691 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
695 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
696 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
697 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
698 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
699 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
700 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
701 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
705 /* draws the image on a toolbar button */
707 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
709 HIMAGELIST himl = NULL;
710 BOOL draw_masked = FALSE;
713 UINT draw_flags = ILD_NORMAL;
715 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
717 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
720 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
724 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (infoPtr->dwStyle & TBSTYLE_FLAT))
726 /* if hot, attempt to draw with hot image list, if fails,
727 use default image list */
728 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
730 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
733 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
738 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
739 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
742 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
743 (tbcd->nmcd.uItemState & CDIS_MARKED))
744 draw_flags |= ILD_BLEND50;
746 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
747 index, himl, left, top, offset);
750 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
752 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
755 /* draws a blank frame for a toolbar button */
757 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
759 HDC hdc = tbcd->nmcd.hdc;
760 RECT rc = tbcd->nmcd.rc;
761 /* if the state is disabled or indeterminate then the button
762 * cannot have an interactive look like pressed or hot */
763 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
764 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
765 BOOL pressed_look = !non_interactive_state &&
766 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
767 (tbcd->nmcd.uItemState & CDIS_CHECKED));
769 /* app don't want us to draw any edges */
770 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
776 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
777 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
778 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
783 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
785 DrawEdge (hdc, &rc, EDGE_RAISED,
786 BF_SOFT | BF_RECT | BF_MIDDLE);
791 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed)
793 HDC hdc = tbcd->nmcd.hdc;
795 BOOL pressed = bDropDownPressed ||
796 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
798 if (infoPtr->dwStyle & TBSTYLE_FLAT)
801 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
802 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
803 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
804 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
805 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
810 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
812 DrawEdge (hdc, rcArrow, EDGE_RAISED,
813 BF_SOFT | BF_RECT | BF_MIDDLE);
817 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
819 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
821 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
822 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
825 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
828 /* draws a complete toolbar button */
830 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
833 DWORD dwStyle = infoPtr->dwStyle;
834 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
835 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
836 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
837 BOOL drawSepDropDownArrow = hasDropDownArrow &&
838 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
839 RECT rc, rcArrow, rcBitmap, rcText;
840 LPWSTR lpText = NULL;
846 CopyRect (&rcArrow, &rc);
847 CopyRect(&rcBitmap, &rc);
849 /* get a pointer to the text */
850 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
852 if (hasDropDownArrow)
856 if (dwStyle & TBSTYLE_FLAT)
857 right = max(rc.left, rc.right - DDARROW_WIDTH);
859 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
861 if (drawSepDropDownArrow)
864 rcArrow.left = right;
867 /* copy text rect after adjusting for drop-down arrow
868 * so that text is centred in the rectangle not containing
870 CopyRect(&rcText, &rc);
872 /* Center the bitmap horizontally and vertically */
873 if (dwStyle & TBSTYLE_LIST)
874 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
876 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
879 rcBitmap.top+= GetSystemMetrics(SM_CYEDGE) + OFFSET_Y;
881 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
883 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
884 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
885 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
886 TRACE ("iString: %x\n", btnPtr->iString);
887 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
891 rcText.left += GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
892 rcText.right -= GetSystemMetrics(SM_CXEDGE) + OFFSET_X;
893 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
894 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
896 if (dwStyle & TBSTYLE_LIST)
897 rcText.left += infoPtr->nBitmapWidth + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
899 rcText.top += GetSystemMetrics(SM_CYEDGE) + OFFSET_Y + infoPtr->nBitmapHeight + infoPtr->szPadding.cy/2;
902 if (dwStyle & TBSTYLE_LIST)
903 rcText.left += LIST_IMAGE_ABSENT_WIDTH + TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap);
905 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
906 OffsetRect (&rcText, 1, 1);
909 /* Initialize fields in all cases, because we use these later
910 * NOTE: applications can and do alter these to customize their
912 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
913 tbcd.clrText = comctl32_color.clrBtnText;
914 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
915 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
916 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
917 tbcd.clrMark = comctl32_color.clrHighlight;
918 tbcd.clrHighlightHotTrack = 0;
919 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
920 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
921 /* MSDN says that this is the text rectangle.
922 * But (why always a but) tracing of v5.7 of native shows
923 * that this is really a *relative* rectangle based on the
924 * the nmcd.rc. Also the left and top are always 0 ignoring
925 * any bitmap that might be present. */
926 tbcd.rcText.left = 0;
928 tbcd.rcText.right = rcText.right - rc.left;
929 tbcd.rcText.bottom = rcText.bottom - rc.top;
930 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
933 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
935 /* FIXME: what are these used for? */
939 /* Issue Item Prepaint notify */
940 infoPtr->dwItemCustDraw = 0;
941 infoPtr->dwItemCDFlag = 0;
942 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
944 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
945 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
946 tbcd.nmcd.lItemlParam = btnPtr->dwData;
947 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
948 /* reset these fields so the user can't alter the behaviour like native */
952 infoPtr->dwItemCustDraw = ntfret & 0xffff;
953 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
954 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
956 /* save the only part of the rect that the user can change */
957 rcText.right = tbcd.rcText.right + rc.left;
958 rcText.bottom = tbcd.rcText.bottom + rc.top;
962 if (btnPtr->fsStyle & BTNS_SEP) {
963 /* with the FLAT style, iBitmap is the width and has already */
964 /* been taken into consideration in calculating the width */
965 /* so now we need to draw the vertical separator */
966 /* empirical tests show that iBitmap can/will be non-zero */
967 /* when drawing the vertical bar... */
968 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
969 if (btnPtr->fsStyle & BTNS_DROPDOWN)
970 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
972 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
974 else if (btnPtr->fsStyle != BTNS_SEP) {
975 FIXME("Draw some kind of separator: fsStyle=%x\n",
981 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
982 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
983 TOOLBAR_DrawPattern (&rc, &tbcd);
985 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
987 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
991 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
992 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
993 if (hasDropDownArrow)
994 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
995 SetBkColor(hdc, oldclr);
999 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
1001 if (drawSepDropDownArrow)
1002 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed);
1004 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1005 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1007 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
1009 if (hasDropDownArrow && !drawSepDropDownArrow)
1011 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1013 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1014 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1016 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1018 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1019 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1022 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1026 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1028 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1029 tbcd.nmcd.hdc = hdc;
1031 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1032 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1033 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1034 tbcd.rcText = rcText;
1035 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1036 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1037 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1044 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1047 TBUTTON_INFO *btnPtr;
1048 INT i, oldBKmode = 0;
1049 RECT rcTemp, rcClient;
1050 NMTBCUSTOMDRAW tbcd;
1053 /* the app has told us not to redraw the toolbar */
1054 if (!infoPtr->bDoRedraw)
1057 /* if imagelist belongs to the app, it can be changed
1058 by the app after setting it */
1059 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1061 infoPtr->nNumBitmaps = 0;
1062 for (i = 0; i < infoPtr->cimlDef; i++)
1063 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1066 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1068 /* Send initial notify */
1069 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1070 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1071 tbcd.nmcd.hdc = hdc;
1072 tbcd.nmcd.rc = ps->rcPaint;
1073 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1074 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1076 if (infoPtr->bBtnTranspnt)
1077 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1079 GetClientRect(hwnd, &rcClient);
1081 /* redraw necessary buttons */
1082 btnPtr = infoPtr->buttons;
1083 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1086 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1088 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1089 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1093 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1094 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1096 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1099 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1100 SetBkMode (hdc, oldBKmode);
1102 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1104 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1105 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1106 tbcd.nmcd.hdc = hdc;
1107 tbcd.nmcd.rc = ps->rcPaint;
1108 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1112 /***********************************************************************
1113 * TOOLBAR_MeasureString
1115 * This function gets the width and height of a string in pixels. This
1116 * is done first by using GetTextExtentPoint to get the basic width
1117 * and height. The DrawText is called with DT_CALCRECT to get the exact
1118 * width. The reason is because the text may have more than one "&" (or
1119 * prefix characters as M$ likes to call them). The prefix character
1120 * indicates where the underline goes, except for the string "&&" which
1121 * is reduced to a single "&". GetTextExtentPoint does not process these
1122 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1125 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1126 HDC hdc, LPSIZE lpSize)
1133 if (infoPtr->nMaxTextRows > 0 &&
1134 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1135 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1136 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1138 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1140 if(lpText != NULL) {
1141 /* first get size of all the text */
1142 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1144 /* feed above size into the rectangle for DrawText */
1145 myrect.left = myrect.top = 0;
1146 myrect.right = lpSize->cx;
1147 myrect.bottom = lpSize->cy;
1149 /* Use DrawText to get true size as drawn (less pesky "&") */
1150 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1151 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1154 /* feed back to caller */
1155 lpSize->cx = myrect.right;
1156 lpSize->cy = myrect.bottom;
1160 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1163 /***********************************************************************
1164 * TOOLBAR_CalcStrings
1166 * This function walks through each string and measures it and returns
1167 * the largest height and width to caller.
1170 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1173 TBUTTON_INFO *btnPtr;
1182 if(infoPtr->nMaxTextRows == 0)
1186 hOldFont = SelectObject (hdc, infoPtr->hFont);
1188 btnPtr = infoPtr->buttons;
1189 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1190 if(TOOLBAR_HasText(infoPtr, btnPtr))
1192 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1193 if (sz.cx > lpSize->cx)
1195 if (sz.cy > lpSize->cy)
1200 SelectObject (hdc, hOldFont);
1201 ReleaseDC (hwnd, hdc);
1203 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1206 /***********************************************************************
1207 * TOOLBAR_WrapToolbar
1209 * This function walks through the buttons and separators in the
1210 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1211 * wrapping should occur based on the width of the toolbar window.
1212 * It does *not* calculate button placement itself. That task
1213 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1214 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1215 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1217 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1218 * vertical toolbar lists.
1222 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1225 TBUTTON_INFO *btnPtr;
1228 BOOL bWrap, bButtonWrap;
1230 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1231 /* no layout is necessary. Applications may use this style */
1232 /* to perform their own layout on the toolbar. */
1233 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1234 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1236 btnPtr = infoPtr->buttons;
1237 x = infoPtr->nIndent;
1239 /* this can get the parents width, to know how far we can extend
1240 * this toolbar. We cannot use its height, as there may be multiple
1241 * toolbars in a rebar control
1243 GetClientRect( GetParent(hwnd), &rc );
1244 infoPtr->nWidth = rc.right - rc.left;
1245 bButtonWrap = FALSE;
1247 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1248 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1251 for (i = 0; i < infoPtr->nNumButtons; i++ )
1254 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1256 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1259 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1260 /* it is the actual width of the separator. This is used for */
1261 /* custom controls in toolbars. */
1263 /* BTNS_DROPDOWN separators are treated as buttons for */
1264 /* width. - GA 8/01 */
1265 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1266 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1267 cx = (btnPtr[i].iBitmap > 0) ?
1268 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1270 cx = infoPtr->nButtonWidth;
1272 /* Two or more adjacent separators form a separator group. */
1273 /* The first separator in a group should be wrapped to the */
1274 /* next row if the previous wrapping is on a button. */
1276 (btnPtr[i].fsStyle & BTNS_SEP) &&
1277 (i + 1 < infoPtr->nNumButtons ) &&
1278 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1280 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1281 btnPtr[i].fsState |= TBSTATE_WRAP;
1282 x = infoPtr->nIndent;
1284 bButtonWrap = FALSE;
1288 /* The layout makes sure the bitmap is visible, but not the button. */
1289 /* Test added to also wrap after a button that starts a row but */
1290 /* is bigger than the area. - GA 8/01 */
1291 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1292 > infoPtr->nWidth ) ||
1293 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1295 BOOL bFound = FALSE;
1297 /* If the current button is a separator and not hidden, */
1298 /* go to the next until it reaches a non separator. */
1299 /* Wrap the last separator if it is before a button. */
1300 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1301 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1302 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1303 i < infoPtr->nNumButtons )
1309 if( bFound && i < infoPtr->nNumButtons )
1312 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1313 i, btnPtr[i].fsStyle, x, cx);
1314 btnPtr[i].fsState |= TBSTATE_WRAP;
1315 x = infoPtr->nIndent;
1316 bButtonWrap = FALSE;
1319 else if ( i >= infoPtr->nNumButtons)
1322 /* If the current button is not a separator, find the last */
1323 /* separator and wrap it. */
1324 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1326 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1327 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1331 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1332 i, btnPtr[i].fsStyle, x, cx);
1333 x = infoPtr->nIndent;
1334 btnPtr[j].fsState |= TBSTATE_WRAP;
1335 bButtonWrap = FALSE;
1340 /* If no separator available for wrapping, wrap one of */
1341 /* non-hidden previous button. */
1345 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1347 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1352 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1353 i, btnPtr[i].fsStyle, x, cx);
1354 x = infoPtr->nIndent;
1355 btnPtr[j].fsState |= TBSTATE_WRAP;
1361 /* If all above failed, wrap the current button. */
1364 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1365 i, btnPtr[i].fsStyle, x, cx);
1366 btnPtr[i].fsState |= TBSTATE_WRAP;
1368 x = infoPtr->nIndent;
1369 if (btnPtr[i].fsStyle & BTNS_SEP )
1370 bButtonWrap = FALSE;
1376 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1377 i, btnPtr[i].fsStyle, x, cx);
1384 /***********************************************************************
1385 * TOOLBAR_CalcToolbar
1387 * This function calculates button and separator placement. It first
1388 * calculates the button sizes, gets the toolbar window width and then
1389 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1390 * on. It assigns a new location to each item and sends this location to
1391 * the tooltip window if appropriate. Finally, it updates the rcBound
1392 * rect and calculates the new required toolbar window height.
1396 TOOLBAR_CalcToolbar (HWND hwnd)
1398 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1399 DWORD dwStyle = infoPtr->dwStyle;
1400 TBUTTON_INFO *btnPtr;
1401 INT i, nRows, nSepRows;
1405 BOOL usesBitmaps = FALSE;
1406 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1408 TOOLBAR_CalcStrings (hwnd, &sizeString);
1410 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1412 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1414 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1417 if (dwStyle & TBSTYLE_LIST)
1419 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1420 0, sizeString.cy) + infoPtr->szPadding.cy;
1421 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1422 LIST_IMAGE_ABSENT_WIDTH) + sizeString.cx + infoPtr->szPadding.cx;
1423 if (sizeString.cx > 0)
1424 infoPtr->nButtonWidth += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1425 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1426 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1427 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1430 if (sizeString.cy > 0)
1433 infoPtr->nButtonHeight = sizeString.cy +
1434 infoPtr->szPadding.cy/2 + /* this is the space to separate text from bitmap */
1435 infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1437 infoPtr->nButtonHeight = sizeString.cy + infoPtr->szPadding.cy;
1440 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1442 if (sizeString.cx > infoPtr->nBitmapWidth)
1443 infoPtr->nButtonWidth = sizeString.cx + infoPtr->szPadding.cx;
1445 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + infoPtr->szPadding.cx;
1448 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1449 infoPtr->nButtonWidth = infoPtr->cxMin;
1450 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1451 infoPtr->nButtonWidth = infoPtr->cxMax;
1453 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1455 x = infoPtr->nIndent;
1458 /* from above, minimum is a button, and possible text */
1459 cx = infoPtr->nButtonWidth;
1461 /* cannot use just ButtonHeight, we may have no buttons! */
1462 if (infoPtr->nNumButtons > 0)
1463 infoPtr->nHeight = infoPtr->nButtonHeight;
1465 cy = infoPtr->nHeight;
1467 nRows = nSepRows = 0;
1469 infoPtr->rcBound.top = y;
1470 infoPtr->rcBound.left = x;
1471 infoPtr->rcBound.bottom = y + cy;
1472 infoPtr->rcBound.right = x;
1474 btnPtr = infoPtr->buttons;
1476 TRACE("cy=%d\n", cy);
1478 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1481 if (btnPtr->fsState & TBSTATE_HIDDEN)
1483 SetRectEmpty (&btnPtr->rect);
1487 cy = infoPtr->nHeight;
1489 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1490 /* it is the actual width of the separator. This is used for */
1491 /* custom controls in toolbars. */
1492 if (btnPtr->fsStyle & BTNS_SEP) {
1493 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1494 cy = (btnPtr->iBitmap > 0) ?
1495 btnPtr->iBitmap : SEPARATOR_WIDTH;
1496 cx = infoPtr->nButtonWidth;
1499 cx = (btnPtr->iBitmap > 0) ?
1500 btnPtr->iBitmap : SEPARATOR_WIDTH;
1506 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1507 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1514 hOldFont = SelectObject (hdc, infoPtr->hFont);
1516 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1518 SelectObject (hdc, hOldFont);
1519 ReleaseDC (hwnd, hdc);
1521 /* add space on for button frame, etc */
1522 cx = sz.cx + infoPtr->szPadding.cx;
1524 /* add list padding */
1525 if ((dwStyle & TBSTYLE_LIST) && sz.cx > 0)
1526 cx += TOOLBAR_GetListTextOffset(infoPtr, infoPtr->iListGap) + infoPtr->szPadding.cx/2;
1528 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1530 if (dwStyle & TBSTYLE_LIST)
1531 cx += infoPtr->nBitmapWidth;
1532 else if (cx < (infoPtr->nBitmapWidth+infoPtr->szPadding.cx))
1533 cx = infoPtr->nBitmapWidth+infoPtr->szPadding.cx;
1535 else if (dwStyle & TBSTYLE_LIST)
1536 cx += LIST_IMAGE_ABSENT_WIDTH;
1539 cx = infoPtr->nButtonWidth;
1541 /* if size has been set manually then don't add on extra space
1542 * for the drop down arrow */
1543 if (!btnPtr->cx && hasDropDownArrows &&
1544 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1545 cx += DDARROW_WIDTH;
1547 if (btnPtr->fsState & TBSTATE_WRAP )
1550 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1552 if (infoPtr->rcBound.left > x)
1553 infoPtr->rcBound.left = x;
1554 if (infoPtr->rcBound.right < x + cx)
1555 infoPtr->rcBound.right = x + cx;
1556 if (infoPtr->rcBound.bottom < y + cy)
1557 infoPtr->rcBound.bottom = y + cy;
1559 /* Set the toolTip only for non-hidden, non-separator button */
1560 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1564 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1565 ti.cbSize = sizeof(TTTOOLINFOA);
1567 ti.uId = btnPtr->idCommand;
1568 ti.rect = btnPtr->rect;
1569 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1573 /* btnPtr->nRow is zero based. The space between the rows is */
1574 /* also considered as a row. */
1575 btnPtr->nRow = nRows + nSepRows;
1577 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1578 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1583 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1587 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1588 /* it is the actual width of the separator. This is used for */
1589 /* custom controls in toolbars. */
1590 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1591 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1592 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1596 /* nSepRows is used to calculate the extra height follwoing */
1600 x = infoPtr->nIndent;
1602 /* Increment row number unless this is the last button */
1603 /* and it has Wrap set. */
1604 if (i != infoPtr->nNumButtons-1)
1611 /* infoPtr->nRows is the number of rows on the toolbar */
1612 infoPtr->nRows = nRows + nSepRows + 1;
1615 /********************************************************************
1616 * The following while interesting, does not match the values *
1617 * created above for the button rectangles, nor the rcBound rect. *
1618 * We will comment it out and remove it later. *
1620 * The problem showed up as heights in the pager control that was *
1622 ********************************************************************/
1624 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1626 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1627 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1628 nSepRows * (infoPtr->nBitmapHeight + 1) +
1632 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1634 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1639 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1642 TBUTTON_INFO *btnPtr;
1645 btnPtr = infoPtr->buttons;
1646 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1647 if (btnPtr->fsState & TBSTATE_HIDDEN)
1650 if (btnPtr->fsStyle & BTNS_SEP) {
1651 if (PtInRect (&btnPtr->rect, *lpPt)) {
1652 TRACE(" ON SEPARATOR %d!\n", i);
1657 if (PtInRect (&btnPtr->rect, *lpPt)) {
1658 TRACE(" ON BUTTON %d!\n", i);
1664 TRACE(" NOWHERE!\n");
1670 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1672 TBUTTON_INFO *btnPtr;
1675 if (CommandIsIndex) {
1676 TRACE("command is really index command=%d\n", idCommand);
1677 if (idCommand >= infoPtr->nNumButtons) return -1;
1680 btnPtr = infoPtr->buttons;
1681 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1682 if (btnPtr->idCommand == idCommand) {
1683 TRACE("command=%d index=%d\n", idCommand, i);
1687 TRACE("no index found for command=%d\n", idCommand);
1693 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1695 TBUTTON_INFO *btnPtr;
1698 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1701 /* check index button */
1702 btnPtr = &infoPtr->buttons[nIndex];
1703 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1704 if (btnPtr->fsState & TBSTATE_CHECKED)
1708 /* check previous buttons */
1709 nRunIndex = nIndex - 1;
1710 while (nRunIndex >= 0) {
1711 btnPtr = &infoPtr->buttons[nRunIndex];
1712 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1713 if (btnPtr->fsState & TBSTATE_CHECKED)
1721 /* check next buttons */
1722 nRunIndex = nIndex + 1;
1723 while (nRunIndex < infoPtr->nNumButtons) {
1724 btnPtr = &infoPtr->buttons[nRunIndex];
1725 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1726 if (btnPtr->fsState & TBSTATE_CHECKED)
1739 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1740 WPARAM wParam, LPARAM lParam)
1746 msg.wParam = wParam;
1747 msg.lParam = lParam;
1748 msg.time = GetMessageTime ();
1749 msg.pt.x = LOWORD(GetMessagePos ());
1750 msg.pt.y = HIWORD(GetMessagePos ());
1752 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1756 /***********************************************************************
1757 * TOOLBAR_CustomizeDialogProc
1758 * This function implements the toolbar customization dialog.
1760 static INT_PTR CALLBACK
1761 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1763 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
1764 PCUSTOMBUTTON btnInfo;
1766 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1771 custInfo = (PCUSTDLG_INFO)lParam;
1772 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
1780 infoPtr = custInfo->tbInfo;
1782 /* send TBN_QUERYINSERT notification */
1783 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1785 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1788 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1789 nmtb.iItem = (int)hwnd;
1790 /* Send TBN_INITCUSTOMIZE notification */
1791 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1794 TRACE("TBNRF_HIDEHELP requested\n");
1795 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1798 /* add items to 'toolbar buttons' list and check if removable */
1799 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1801 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1802 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1803 btnInfo->btn.fsStyle = BTNS_SEP;
1804 btnInfo->bVirtual = FALSE;
1805 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1807 /* send TBN_QUERYDELETE notification */
1808 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1810 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1811 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1814 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1816 /* insert separator button into 'available buttons' list */
1817 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1818 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1819 btnInfo->btn.fsStyle = BTNS_SEP;
1820 btnInfo->bVirtual = FALSE;
1821 btnInfo->bRemovable = TRUE;
1822 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1823 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1824 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1826 /* insert all buttons into dsa */
1829 /* send TBN_GETBUTTONINFO notification */
1832 nmtb.pszText = Buffer;
1835 /* Clear previous button's text */
1836 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1838 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1841 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1842 nmtb.tbButton.fsStyle, i,
1843 nmtb.tbButton.idCommand,
1844 nmtb.tbButton.iString,
1845 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1848 /* insert button into the apropriate list */
1849 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1852 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1853 btnInfo->bVirtual = FALSE;
1854 btnInfo->bRemovable = TRUE;
1856 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1857 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1858 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1862 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1863 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1866 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1867 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1869 if (lstrlenW(nmtb.pszText))
1870 lstrcpyW(btnInfo->text, nmtb.pszText);
1871 else if (nmtb.tbButton.iString >= 0 &&
1872 nmtb.tbButton.iString < infoPtr->nNumStrings)
1874 lstrcpyW(btnInfo->text,
1875 infoPtr->strings[nmtb.tbButton.iString]);
1880 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
1882 /* select first item in the 'available' list */
1883 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1885 /* append 'virtual' separator button to the 'toolbar buttons' list */
1886 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1887 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1888 btnInfo->btn.fsStyle = BTNS_SEP;
1889 btnInfo->bVirtual = TRUE;
1890 btnInfo->bRemovable = FALSE;
1891 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1892 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1895 /* select last item in the 'toolbar' list */
1896 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1897 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1899 /* set focus and disable buttons */
1900 PostMessageA (hwnd, WM_USER, 0, 0);
1905 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1906 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1907 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1908 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1912 EndDialog(hwnd, FALSE);
1916 switch (LOWORD(wParam))
1918 case IDC_TOOLBARBTN_LBOX:
1919 if (HIWORD(wParam) == LBN_SELCHANGE)
1921 PCUSTOMBUTTON btnInfo;
1926 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1927 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1929 /* send TBN_QUERYINSERT notification */
1931 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1934 /* get list box item */
1935 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1937 if (index == (count - 1))
1939 /* last item (virtual separator) */
1940 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1941 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1943 else if (index == (count - 2))
1945 /* second last item (last non-virtual item) */
1946 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1947 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1949 else if (index == 0)
1952 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1953 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1957 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1958 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1961 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1965 case IDC_MOVEUP_BTN:
1967 PCUSTOMBUTTON btnInfo;
1971 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1972 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1973 TRACE("Move up: index %d\n", index);
1975 /* send TBN_QUERYINSERT notification */
1978 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1983 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1985 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1986 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1987 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1988 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1991 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1992 else if (index >= (count - 3))
1993 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1995 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1996 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1998 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2003 case IDC_MOVEDN_BTN: /* move down */
2005 PCUSTOMBUTTON btnInfo;
2009 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2010 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2011 TRACE("Move up: index %d\n", index);
2013 /* send TBN_QUERYINSERT notification */
2015 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2020 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2022 /* move button down */
2023 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2024 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2025 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2026 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2029 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2030 else if (index >= (count - 3))
2031 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2033 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2034 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2036 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2041 case IDC_REMOVE_BTN: /* remove button */
2043 PCUSTOMBUTTON btnInfo;
2046 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2048 if (LB_ERR == index)
2051 TRACE("Remove: index %d\n", index);
2053 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2054 LB_GETITEMDATA, index, 0);
2056 /* send TBN_QUERYDELETE notification */
2057 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2061 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2062 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2063 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2065 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2067 /* insert into 'available button' list */
2068 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2070 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2071 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2076 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2081 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2084 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2087 case IDOK: /* Add button */
2092 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2093 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2094 TRACE("Add: index %d\n", index);
2096 /* send TBN_QUERYINSERT notification */
2098 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2103 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2107 /* remove from 'available buttons' list */
2108 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2109 if (index == count-1)
2110 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2112 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2116 PCUSTOMBUTTON btnNew;
2118 /* duplicate 'separator' button */
2119 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2120 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2124 /* insert into 'toolbar button' list */
2125 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2126 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2127 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2129 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2131 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
2137 EndDialog(hwnd, FALSE);
2147 /* delete items from 'toolbar buttons' listbox*/
2148 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2149 for (i = 0; i < count; i++)
2151 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2153 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2155 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2158 /* delete items from 'available buttons' listbox*/
2159 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2160 for (i = 0; i < count; i++)
2162 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2164 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2166 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2171 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2173 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2178 COLORREF oldText = 0;
2182 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2183 if (btnInfo == NULL)
2185 FIXME("btnInfo invalid!\n");
2189 /* set colors and select objects */
2190 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2191 if (btnInfo->bVirtual)
2192 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2194 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2195 hPen = CreatePen( PS_SOLID, 1,
2196 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2197 hOldPen = SelectObject (lpdis->hDC, hPen );
2198 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2200 /* fill background rectangle */
2201 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2202 lpdis->rcItem.right, lpdis->rcItem.bottom);
2204 /* calculate button and text rectangles */
2205 CopyRect (&rcButton, &lpdis->rcItem);
2206 InflateRect (&rcButton, -1, -1);
2207 CopyRect (&rcText, &rcButton);
2208 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2209 rcText.left = rcButton.right + 2;
2211 /* draw focus rectangle */
2212 if (lpdis->itemState & ODS_FOCUS)
2213 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2216 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2217 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2219 /* draw image and text */
2220 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2221 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2222 btnInfo->btn.iBitmap));
2223 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2224 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2226 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2227 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2229 /* delete objects and reset colors */
2230 SelectObject (lpdis->hDC, hOldBrush);
2231 SelectObject (lpdis->hDC, hOldPen);
2232 SetBkColor (lpdis->hDC, oldBk);
2233 SetTextColor (lpdis->hDC, oldText);
2234 DeleteObject( hPen );
2239 case WM_MEASUREITEM:
2240 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2242 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2244 lpmis->itemHeight = 15 + 8; /* default height */
2256 /***********************************************************************
2257 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2261 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2264 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2265 INT nIndex = 0, nButtons, nCount;
2269 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2273 if (lpAddBmp->hInst == HINST_COMMCTRL)
2275 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2277 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2279 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2284 TRACE ("adding %d internal bitmaps!\n", nButtons);
2286 /* Windows resize all the buttons to the size of a newly added standard image */
2287 if (lpAddBmp->nID & 1)
2290 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2291 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2293 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2294 MAKELPARAM((WORD)24, (WORD)24));
2295 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2296 MAKELPARAM((WORD)31, (WORD)30));
2301 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2302 MAKELPARAM((WORD)16, (WORD)16));
2303 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2304 MAKELPARAM((WORD)22, (WORD)22));
2307 TOOLBAR_CalcToolbar (hwnd);
2311 nButtons = (INT)wParam;
2315 TRACE ("adding %d bitmaps!\n", nButtons);
2318 if (!infoPtr->cimlDef) {
2319 /* create new default image list */
2320 TRACE ("creating default image list!\n");
2322 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2323 ILC_COLORDDB | ILC_MASK, nButtons, 2);
2324 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2325 infoPtr->himlInt = himlDef;
2328 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2332 WARN("No default image list available\n");
2336 nCount = ImageList_GetImageCount(himlDef);
2338 /* Add bitmaps to the default image list */
2339 if (lpAddBmp->hInst == NULL)
2342 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2343 HDC hdcImage, hdcBitmap;
2345 /* copy the bitmap before adding it so that the user's bitmap
2346 * doesn't get modified.
2348 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2350 hdcImage = CreateCompatibleDC(0);
2351 hdcBitmap = CreateCompatibleDC(0);
2353 /* create new bitmap */
2354 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2355 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2356 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2358 /* Copy the user's image */
2359 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2360 hdcBitmap, 0, 0, SRCCOPY);
2362 SelectObject (hdcImage, hOldBitmapLoad);
2363 SelectObject (hdcBitmap, hOldBitmapBitmap);
2364 DeleteDC (hdcImage);
2365 DeleteDC (hdcBitmap);
2367 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2368 DeleteObject (hbmLoad);
2370 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2372 /* Add system bitmaps */
2373 switch (lpAddBmp->nID)
2375 case IDB_STD_SMALL_COLOR:
2376 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2377 MAKEINTRESOURCEA(IDB_STD_SMALL));
2378 nIndex = ImageList_AddMasked (himlDef,
2379 hbmLoad, comctl32_color.clrBtnFace);
2380 DeleteObject (hbmLoad);
2383 case IDB_STD_LARGE_COLOR:
2384 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2385 MAKEINTRESOURCEA(IDB_STD_LARGE));
2386 nIndex = ImageList_AddMasked (himlDef,
2387 hbmLoad, comctl32_color.clrBtnFace);
2388 DeleteObject (hbmLoad);
2391 case IDB_VIEW_SMALL_COLOR:
2392 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2393 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2394 nIndex = ImageList_AddMasked (himlDef,
2395 hbmLoad, comctl32_color.clrBtnFace);
2396 DeleteObject (hbmLoad);
2399 case IDB_VIEW_LARGE_COLOR:
2400 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2401 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2402 nIndex = ImageList_AddMasked (himlDef,
2403 hbmLoad, comctl32_color.clrBtnFace);
2404 DeleteObject (hbmLoad);
2407 case IDB_HIST_SMALL_COLOR:
2408 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2409 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2410 nIndex = ImageList_AddMasked (himlDef,
2411 hbmLoad, comctl32_color.clrBtnFace);
2412 DeleteObject (hbmLoad);
2415 case IDB_HIST_LARGE_COLOR:
2416 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2417 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2418 nIndex = ImageList_AddMasked (himlDef,
2419 hbmLoad, comctl32_color.clrBtnFace);
2420 DeleteObject (hbmLoad);
2424 nIndex = ImageList_GetImageCount (himlDef);
2425 ERR ("invalid imagelist!\n");
2431 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2432 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2433 DeleteObject (hbmLoad);
2436 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2438 if (infoPtr->nNumBitmapInfos == 0)
2440 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2444 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2445 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2446 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2449 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2450 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2451 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2453 infoPtr->nNumBitmapInfos++;
2454 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2458 INT imagecount = ImageList_GetImageCount(himlDef);
2460 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2462 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",
2463 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2464 infoPtr->nNumBitmaps+nButtons,imagecount);
2466 infoPtr->nNumBitmaps = imagecount;
2469 infoPtr->nNumBitmaps += nButtons;
2472 InvalidateRect(hwnd, NULL, TRUE);
2479 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2482 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2483 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2485 TRACE("adding %d buttons!\n", wParam);
2487 nAddButtons = (UINT)wParam;
2488 nOldButtons = infoPtr->nNumButtons;
2489 nNewButtons = nOldButtons + nAddButtons;
2491 if (infoPtr->nNumButtons == 0) {
2493 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2496 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2498 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2499 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2500 nOldButtons * sizeof(TBUTTON_INFO));
2504 infoPtr->nNumButtons = nNewButtons;
2506 /* insert new button data */
2507 for (nCount = 0; nCount < nAddButtons; nCount++) {
2508 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2509 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2510 btnPtr->idCommand = lpTbb[nCount].idCommand;
2511 btnPtr->fsState = lpTbb[nCount].fsState;
2512 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2513 btnPtr->dwData = lpTbb[nCount].dwData;
2514 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2515 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2517 btnPtr->iString = lpTbb[nCount].iString;
2518 btnPtr->bHot = FALSE;
2520 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2523 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2524 ti.cbSize = sizeof (TTTOOLINFOA);
2526 ti.uId = btnPtr->idCommand;
2528 ti.lpszText = LPSTR_TEXTCALLBACKA;
2530 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2535 TOOLBAR_CalcToolbar (hwnd);
2537 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2539 InvalidateRect(hwnd, NULL, TRUE);
2546 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2549 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2550 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2552 TRACE("adding %d buttons!\n", wParam);
2554 nAddButtons = (UINT)wParam;
2555 nOldButtons = infoPtr->nNumButtons;
2556 nNewButtons = nOldButtons + nAddButtons;
2558 if (infoPtr->nNumButtons == 0) {
2560 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2563 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2565 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2566 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2567 nOldButtons * sizeof(TBUTTON_INFO));
2571 infoPtr->nNumButtons = nNewButtons;
2573 /* insert new button data */
2574 for (nCount = 0; nCount < nAddButtons; nCount++) {
2575 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2576 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2577 btnPtr->idCommand = lpTbb[nCount].idCommand;
2578 btnPtr->fsState = lpTbb[nCount].fsState;
2579 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2580 btnPtr->dwData = lpTbb[nCount].dwData;
2581 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2582 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2584 btnPtr->iString = lpTbb[nCount].iString;
2585 btnPtr->bHot = FALSE;
2587 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2590 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2591 ti.cbSize = sizeof (TTTOOLINFOW);
2593 ti.uId = btnPtr->idCommand;
2595 ti.lpszText = LPSTR_TEXTCALLBACKW;
2598 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2603 TOOLBAR_CalcToolbar (hwnd);
2605 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2607 InvalidateRect(hwnd, NULL, TRUE);
2614 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2616 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2619 if ((wParam) && (HIWORD(lParam) == 0)) {
2622 TRACE("adding string from resource!\n");
2624 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2627 TRACE("len=%d \"%s\"\n", len, szString);
2628 nIndex = infoPtr->nNumStrings;
2629 if (infoPtr->nNumStrings == 0) {
2631 Alloc (sizeof(LPWSTR));
2634 LPWSTR *oldStrings = infoPtr->strings;
2636 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2637 memcpy (&infoPtr->strings[0], &oldStrings[0],
2638 sizeof(LPWSTR) * infoPtr->nNumStrings);
2642 /*Alloc zeros out the allocated memory*/
2643 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2644 infoPtr->nNumStrings++;
2647 LPSTR p = (LPSTR)lParam;
2652 TRACE("adding string(s) from array!\n");
2654 nIndex = infoPtr->nNumStrings;
2657 TRACE("len=%d \"%s\"\n", len, p);
2659 if (infoPtr->nNumStrings == 0) {
2661 Alloc (sizeof(LPWSTR));
2664 LPWSTR *oldStrings = infoPtr->strings;
2666 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2667 memcpy (&infoPtr->strings[0], &oldStrings[0],
2668 sizeof(LPWSTR) * infoPtr->nNumStrings);
2672 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2673 infoPtr->nNumStrings++;
2684 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2686 #define MAX_RESOURCE_STRING_LENGTH 512
2687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2690 if ((wParam) && (HIWORD(lParam) == 0)) {
2691 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2693 TRACE("adding string from resource!\n");
2695 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2696 szString, MAX_RESOURCE_STRING_LENGTH);
2698 TRACE("len=%d %s\n", len, debugstr_w(szString));
2699 TRACE("First char: 0x%x\n", *szString);
2700 if (szString[0] == L'|')
2702 PWSTR p = szString + 1;
2704 nIndex = infoPtr->nNumStrings;
2705 while (*p != L'|' && *p != L'\0') {
2708 if (infoPtr->nNumStrings == 0) {
2709 infoPtr->strings = Alloc (sizeof(LPWSTR));
2713 LPWSTR *oldStrings = infoPtr->strings;
2714 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2715 memcpy(&infoPtr->strings[0], &oldStrings[0],
2716 sizeof(LPWSTR) * infoPtr->nNumStrings);
2720 np=strchrW (p, '|');
2728 TRACE("len=%d %s\n", len, debugstr_w(p));
2729 infoPtr->strings[infoPtr->nNumStrings] =
2730 Alloc (sizeof(WCHAR)*(len+1));
2731 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2732 infoPtr->nNumStrings++;
2739 nIndex = infoPtr->nNumStrings;
2740 if (infoPtr->nNumStrings == 0) {
2742 Alloc (sizeof(LPWSTR));
2745 LPWSTR *oldStrings = infoPtr->strings;
2747 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2748 memcpy (&infoPtr->strings[0], &oldStrings[0],
2749 sizeof(LPWSTR) * infoPtr->nNumStrings);
2753 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2754 infoPtr->nNumStrings++;
2758 LPWSTR p = (LPWSTR)lParam;
2763 TRACE("adding string(s) from array!\n");
2764 nIndex = infoPtr->nNumStrings;
2768 TRACE("len=%d %s\n", len, debugstr_w(p));
2769 if (infoPtr->nNumStrings == 0) {
2771 Alloc (sizeof(LPWSTR));
2774 LPWSTR *oldStrings = infoPtr->strings;
2776 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2777 memcpy (&infoPtr->strings[0], &oldStrings[0],
2778 sizeof(LPWSTR) * infoPtr->nNumStrings);
2782 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2783 infoPtr->nNumStrings++;
2794 TOOLBAR_AutoSize (HWND hwnd)
2796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2802 UINT uPosFlags = SWP_NOZORDER;
2804 TRACE("resize forced, style=%lx!\n", infoPtr->dwStyle);
2806 parent = GetParent (hwnd);
2807 GetClientRect(parent, &parent_rect);
2809 x = parent_rect.left;
2810 y = parent_rect.top;
2812 /* FIXME: we should be able to early out if nothing */
2813 /* has changed with nWidth != parent_rect width */
2815 if (infoPtr->dwStyle & CCS_NORESIZE) {
2816 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2819 TOOLBAR_CalcToolbar (hwnd);
2822 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2823 TOOLBAR_CalcToolbar (hwnd);
2824 InvalidateRect( hwnd, NULL, TRUE );
2825 cy = infoPtr->nHeight;
2826 cx = infoPtr->nWidth;
2828 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2829 GetWindowRect(hwnd, &window_rect);
2830 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2831 y = window_rect.top;
2833 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2834 GetWindowRect(hwnd, &window_rect);
2835 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2839 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
2840 uPosFlags |= SWP_NOMOVE;
2842 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
2843 cy += GetSystemMetrics(SM_CYEDGE);
2845 if (infoPtr->dwStyle & WS_BORDER)
2848 cy += GetSystemMetrics(SM_CYEDGE);
2849 cx += GetSystemMetrics(SM_CYEDGE);
2852 infoPtr->bAutoSize = TRUE;
2853 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2854 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2855 * after the setwindowpos calls */
2856 infoPtr->bAutoSize = FALSE;
2863 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2867 return infoPtr->nNumButtons;
2872 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2874 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2876 if (infoPtr == NULL) {
2877 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2878 ERR("infoPtr == NULL!\n");
2882 infoPtr->dwStructSize = (DWORD)wParam;
2889 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2892 TBUTTON_INFO *btnPtr;
2895 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2897 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2901 btnPtr = &infoPtr->buttons[nIndex];
2902 btnPtr->iBitmap = LOWORD(lParam);
2904 /* we HAVE to erase the background, the new bitmap could be */
2906 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2913 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2916 TBUTTON_INFO *btnPtr;
2919 BOOL bChecked = FALSE;
2921 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2923 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, nIndex, lParam);
2928 btnPtr = &infoPtr->buttons[nIndex];
2930 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2932 if (LOWORD(lParam) == FALSE)
2933 btnPtr->fsState &= ~TBSTATE_CHECKED;
2935 if (btnPtr->fsStyle & BTNS_GROUP) {
2937 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2938 if (nOldIndex == nIndex)
2940 if (nOldIndex != -1)
2941 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2943 btnPtr->fsState |= TBSTATE_CHECKED;
2946 if( bChecked != LOWORD(lParam) )
2948 if (nOldIndex != -1)
2949 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
2950 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2953 /* FIXME: Send a WM_NOTIFY?? */
2960 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2962 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2964 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2969 TOOLBAR_Customize (HWND hwnd)
2971 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2972 CUSTDLG_INFO custInfo;
2978 custInfo.tbInfo = infoPtr;
2979 custInfo.tbHwnd = hwnd;
2981 /* send TBN_BEGINADJUST notification */
2982 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2985 if (!(hRes = FindResourceA (COMCTL32_hModule,
2986 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2990 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2993 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE),
2994 (LPDLGTEMPLATEA)template,
2996 TOOLBAR_CustomizeDialogProc,
2999 /* send TBN_ENDADJUST notification */
3000 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
3008 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3011 INT nIndex = (INT)wParam;
3014 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3017 memset(&nmtb, 0, sizeof(nmtb));
3018 nmtb.iItem = nIndex;
3019 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_DELETINGBUTTON);
3021 if ((infoPtr->hwndToolTip) &&
3022 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3025 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3026 ti.cbSize = sizeof (TTTOOLINFOA);
3028 ti.uId = infoPtr->buttons[nIndex].idCommand;
3030 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3033 if (infoPtr->nNumButtons == 1) {
3034 TRACE(" simple delete!\n");
3035 Free (infoPtr->buttons);
3036 infoPtr->buttons = NULL;
3037 infoPtr->nNumButtons = 0;
3040 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3041 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3043 infoPtr->nNumButtons--;
3044 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3046 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3047 nIndex * sizeof(TBUTTON_INFO));
3050 if (nIndex < infoPtr->nNumButtons) {
3051 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3052 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3058 TOOLBAR_CalcToolbar (hwnd);
3060 InvalidateRect (hwnd, NULL, TRUE);
3067 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3070 TBUTTON_INFO *btnPtr;
3074 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3076 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", hwnd, wParam, lParam);
3081 btnPtr = &infoPtr->buttons[nIndex];
3083 bState = btnPtr->fsState & TBSTATE_ENABLED;
3085 /* update the toolbar button state */
3086 if(LOWORD(lParam) == FALSE) {
3087 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3089 btnPtr->fsState |= TBSTATE_ENABLED;
3092 /* redraw the button only if the state of the button changed */
3093 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3094 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3100 static inline LRESULT
3101 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3105 return infoPtr->bAnchor;
3110 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3115 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3119 return infoPtr->buttons[nIndex].iBitmap;
3123 static inline LRESULT
3124 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3126 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3131 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3133 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3134 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3135 INT nIndex = (INT)wParam;
3136 TBUTTON_INFO *btnPtr;
3138 if (infoPtr == NULL)
3144 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3147 btnPtr = &infoPtr->buttons[nIndex];
3148 lpTbb->iBitmap = btnPtr->iBitmap;
3149 lpTbb->idCommand = btnPtr->idCommand;
3150 lpTbb->fsState = btnPtr->fsState;
3151 lpTbb->fsStyle = btnPtr->fsStyle;
3152 lpTbb->bReserved[0] = 0;
3153 lpTbb->bReserved[1] = 0;
3154 lpTbb->dwData = btnPtr->dwData;
3155 lpTbb->iString = btnPtr->iString;
3162 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3164 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3165 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3166 TBUTTON_INFO *btnPtr;
3169 if (infoPtr == NULL)
3171 if (lpTbInfo == NULL)
3173 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3176 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3177 lpTbInfo->dwMask & 0x80000000);
3181 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3183 if (lpTbInfo->dwMask & TBIF_COMMAND)
3184 lpTbInfo->idCommand = btnPtr->idCommand;
3185 if (lpTbInfo->dwMask & TBIF_IMAGE)
3186 lpTbInfo->iImage = btnPtr->iBitmap;
3187 if (lpTbInfo->dwMask & TBIF_LPARAM)
3188 lpTbInfo->lParam = btnPtr->dwData;
3189 if (lpTbInfo->dwMask & TBIF_SIZE)
3190 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3191 if (lpTbInfo->dwMask & TBIF_STATE)
3192 lpTbInfo->fsState = btnPtr->fsState;
3193 if (lpTbInfo->dwMask & TBIF_STYLE)
3194 lpTbInfo->fsStyle = btnPtr->fsStyle;
3195 if (lpTbInfo->dwMask & TBIF_TEXT) {
3196 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3197 can't use TOOLBAR_GetText here */
3199 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3200 lpText = (LPWSTR)btnPtr->iString;
3201 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3203 lpTbInfo->pszText[0] = '\0';
3210 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3213 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3214 TBUTTON_INFO *btnPtr;
3217 if (infoPtr == NULL)
3219 if (lpTbInfo == NULL)
3221 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3224 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3225 lpTbInfo->dwMask & 0x80000000);
3229 btnPtr = &infoPtr->buttons[nIndex];
3234 if (lpTbInfo->dwMask & TBIF_COMMAND)
3235 lpTbInfo->idCommand = btnPtr->idCommand;
3236 if (lpTbInfo->dwMask & TBIF_IMAGE)
3237 lpTbInfo->iImage = btnPtr->iBitmap;
3238 if (lpTbInfo->dwMask & TBIF_LPARAM)
3239 lpTbInfo->lParam = btnPtr->dwData;
3240 if (lpTbInfo->dwMask & TBIF_SIZE)
3241 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3242 if (lpTbInfo->dwMask & TBIF_STATE)
3243 lpTbInfo->fsState = btnPtr->fsState;
3244 if (lpTbInfo->dwMask & TBIF_STYLE)
3245 lpTbInfo->fsStyle = btnPtr->fsStyle;
3246 if (lpTbInfo->dwMask & TBIF_TEXT) {
3247 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3248 can't use TOOLBAR_GetText here */
3250 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3251 lpText = (LPWSTR)btnPtr->iString;
3252 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3254 lpTbInfo->pszText[0] = '\0';
3262 TOOLBAR_GetButtonSize (HWND hwnd)
3264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3266 if (infoPtr->nNumButtons > 0)
3267 return MAKELONG((WORD)infoPtr->nButtonWidth,
3268 (WORD)infoPtr->nButtonHeight);
3270 return MAKELONG(8,7);
3275 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3277 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3284 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3288 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3290 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3291 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3296 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3298 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3307 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3311 ret = strlenW (lpText);
3314 strcpyW ((LPWSTR)lParam, lpText);
3322 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3324 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3325 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3326 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3330 inline static LRESULT
3331 TOOLBAR_GetExtendedStyle (HWND hwnd)
3333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3337 return infoPtr->dwExStyle;
3342 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3344 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3345 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3346 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3351 TOOLBAR_GetHotItem (HWND hwnd)
3353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3355 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
3358 if (infoPtr->nHotItem < 0)
3361 return (LRESULT)infoPtr->nHotItem;
3366 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3368 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3369 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3370 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3374 /* << TOOLBAR_GetInsertMark >> */
3375 /* << TOOLBAR_GetInsertMarkColor >> */
3379 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3381 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3382 TBUTTON_INFO *btnPtr;
3386 if (infoPtr == NULL)
3388 nIndex = (INT)wParam;
3389 btnPtr = &infoPtr->buttons[nIndex];
3390 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3392 lpRect = (LPRECT)lParam;
3395 if (btnPtr->fsState & TBSTATE_HIDDEN)
3398 lpRect->left = btnPtr->rect.left;
3399 lpRect->right = btnPtr->rect.right;
3400 lpRect->bottom = btnPtr->rect.bottom;
3401 lpRect->top = btnPtr->rect.top;
3408 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3411 LPSIZE lpSize = (LPSIZE)lParam;
3416 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3417 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3419 TRACE("maximum size %ld x %ld\n",
3420 infoPtr->rcBound.right - infoPtr->rcBound.left,
3421 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3427 /* << TOOLBAR_GetObject >> */
3431 TOOLBAR_GetPadding (HWND hwnd)
3433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3436 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3437 return (LRESULT) oldPad;
3442 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3445 TBUTTON_INFO *btnPtr;
3449 if (infoPtr == NULL)
3451 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3452 btnPtr = &infoPtr->buttons[nIndex];
3453 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3455 lpRect = (LPRECT)lParam;
3459 lpRect->left = btnPtr->rect.left;
3460 lpRect->right = btnPtr->rect.right;
3461 lpRect->bottom = btnPtr->rect.bottom;
3462 lpRect->top = btnPtr->rect.top;
3469 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3471 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3473 if (infoPtr->dwStyle & TBSTYLE_WRAPABLE)
3474 return infoPtr->nRows;
3481 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3483 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3490 return infoPtr->buttons[nIndex].fsState;
3495 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3497 return GetWindowLongW(hwnd, GWL_STYLE);
3502 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3504 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3506 if (infoPtr == NULL)
3509 return infoPtr->nMaxTextRows;
3514 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3518 if (infoPtr == NULL)
3520 return (LRESULT)infoPtr->hwndToolTip;
3525 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3529 TRACE("%s hwnd=%p stub!\n",
3530 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3532 return infoPtr->bUnicode;
3536 inline static LRESULT
3537 TOOLBAR_GetVersion (HWND hwnd)
3539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3540 return infoPtr->iVersion;
3545 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3548 TBUTTON_INFO *btnPtr;
3553 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3557 btnPtr = &infoPtr->buttons[nIndex];
3558 if (LOWORD(lParam) == FALSE)
3559 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3561 btnPtr->fsState |= TBSTATE_HIDDEN;
3563 TOOLBAR_CalcToolbar (hwnd);
3565 InvalidateRect (hwnd, NULL, TRUE);
3571 inline static LRESULT
3572 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3574 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3579 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3581 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3582 TBUTTON_INFO *btnPtr;
3586 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3590 btnPtr = &infoPtr->buttons[nIndex];
3591 oldState = btnPtr->fsState;
3592 if (LOWORD(lParam) == FALSE)
3593 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3595 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3597 if(oldState != btnPtr->fsState)
3598 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
3605 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3608 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3609 INT nIndex = (INT)wParam;
3610 TBUTTON_INFO *oldButtons;
3615 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3618 /* EPP: this seems to be an undocumented call (from my IE4)
3619 * I assume in that case that:
3620 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3621 * - index of insertion is at the end of existing buttons
3622 * I only see this happen with nIndex == -1, but it could have a special
3623 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3625 nIndex = infoPtr->nNumButtons;
3627 } else if (nIndex < 0)
3630 /* If the string passed is not an index, assume address of string
3631 and do our own AddString */
3632 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3636 TRACE("string %s passed instead of index, adding string\n",
3637 debugstr_a((LPSTR)lpTbb->iString));
3638 len = strlen((LPSTR)lpTbb->iString) + 2;
3640 strcpy(ptr, (LPSTR)lpTbb->iString);
3641 ptr[len - 1] = 0; /* ended by two '\0' */
3642 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3646 TRACE("inserting button index=%d\n", nIndex);
3647 if (nIndex > infoPtr->nNumButtons) {
3648 nIndex = infoPtr->nNumButtons;
3649 TRACE("adjust index=%d\n", nIndex);
3652 oldButtons = infoPtr->buttons;
3653 infoPtr->nNumButtons++;
3654 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3655 /* pre insert copy */
3657 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3658 nIndex * sizeof(TBUTTON_INFO));
3661 /* insert new button */
3662 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3663 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3664 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3665 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3666 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3667 /* if passed string and not index, then add string */
3668 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3669 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3672 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3674 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3677 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3678 ti.cbSize = sizeof (TTTOOLINFOA);
3680 ti.uId = lpTbb->idCommand;
3682 ti.lpszText = LPSTR_TEXTCALLBACKA;
3684 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3688 /* post insert copy */
3689 if (nIndex < infoPtr->nNumButtons - 1) {
3690 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3691 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3696 TOOLBAR_CalcToolbar (hwnd);
3698 InvalidateRect (hwnd, NULL, TRUE);
3705 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3707 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3708 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3709 INT nIndex = (INT)wParam;
3710 TBUTTON_INFO *oldButtons;
3715 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3718 /* EPP: this seems to be an undocumented call (from my IE4)
3719 * I assume in that case that:
3720 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3721 * - index of insertion is at the end of existing buttons
3722 * I only see this happen with nIndex == -1, but it could have a special
3723 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3725 nIndex = infoPtr->nNumButtons;
3727 } else if (nIndex < 0)
3730 /* If the string passed is not an index, assume address of string
3731 and do our own AddString */
3732 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3736 TRACE("string %s passed instead of index, adding string\n",
3737 debugstr_w((LPWSTR)lpTbb->iString));
3738 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3739 ptr = Alloc(len*sizeof(WCHAR));
3740 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3741 ptr[len - 1] = 0; /* ended by two '\0' */
3742 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3746 TRACE("inserting button index=%d\n", nIndex);
3747 if (nIndex > infoPtr->nNumButtons) {
3748 nIndex = infoPtr->nNumButtons;
3749 TRACE("adjust index=%d\n", nIndex);
3752 oldButtons = infoPtr->buttons;
3753 infoPtr->nNumButtons++;
3754 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3755 /* pre insert copy */
3757 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3758 nIndex * sizeof(TBUTTON_INFO));
3761 /* insert new button */
3762 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3763 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3764 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3765 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3766 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3767 /* if passed string and not index, then add string */
3768 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3769 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3772 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3774 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3777 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3778 ti.cbSize = sizeof (TTTOOLINFOW);
3780 ti.uId = lpTbb->idCommand;
3782 ti.lpszText = LPSTR_TEXTCALLBACKW;
3784 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3788 /* post insert copy */
3789 if (nIndex < infoPtr->nNumButtons - 1) {
3790 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3791 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3796 TOOLBAR_CalcToolbar (hwnd);
3798 InvalidateRect (hwnd, NULL, TRUE);
3804 /* << TOOLBAR_InsertMarkHitTest >> */
3808 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3813 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3817 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3822 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3824 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3827 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3831 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3836 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3841 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3845 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3850 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3855 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3859 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3864 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3873 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3878 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3883 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3887 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3892 TOOLBAR_LoadImages (HWND hwnd, WPARAM wParam, LPARAM lParam)
3895 tbab.hInst = (HINSTANCE)lParam;
3896 tbab.nID = (UINT_PTR)wParam;
3898 TRACE("hwnd = %p, hInst = %p, nID = %u\n", hwnd, tbab.hInst, tbab.nID);
3900 return TOOLBAR_AddBitmap(hwnd, 0, (LPARAM)&tbab);
3905 TOOLBAR_MapAccelerator (HWND hwnd, WPARAM wParam, LPARAM lParam)
3907 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3908 WCHAR wAccel = (WCHAR)wParam;
3909 UINT* pIDButton = (UINT*)lParam;
3910 WCHAR wszAccel[] = {'&',wAccel,0};
3913 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3914 hwnd, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3916 for (i = 0; i < infoPtr->nNumButtons; i++)
3918 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3919 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3920 !(btnPtr->fsState & TBSTATE_HIDDEN))
3922 int iLen = strlenW(wszAccel);
3923 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3930 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3935 if (!strncmpiW(lpszStr, wszAccel, iLen))
3937 *pIDButton = btnPtr->idCommand;
3949 TOOLBAR_MarkButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3951 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3954 TRACE("hwnd = %p, wParam = %d, lParam = 0x%08lx\n", hwnd, wParam, lParam);
3956 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3961 infoPtr->buttons[nIndex].fsState |= TBSTATE_MARKED;
3963 infoPtr->buttons[nIndex].fsState &= ~TBSTATE_MARKED;
3969 /* fixes up an index of a button affected by a move */
3970 inline static void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3974 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3976 else if (*pIndex == nIndex)
3977 *pIndex = nMoveIndex;
3981 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3983 else if (*pIndex == nIndex)
3984 *pIndex = nMoveIndex;
3990 TOOLBAR_MoveButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3992 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3995 INT nMoveIndex = (INT)lParam;
3996 TBUTTON_INFO button;
3998 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4000 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, TRUE);
4001 if ((nIndex == -1) || (nMoveIndex < 0))
4004 if (nMoveIndex > infoPtr->nNumButtons - 1)
4005 nMoveIndex = infoPtr->nNumButtons - 1;
4007 button = infoPtr->buttons[nIndex];
4009 /* move button right */
4010 if (nIndex < nMoveIndex)
4012 nCount = nMoveIndex - nIndex;
4013 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
4014 infoPtr->buttons[nMoveIndex] = button;
4016 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
4017 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
4018 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
4019 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
4021 else if (nIndex > nMoveIndex) /* move button left */
4023 nCount = nIndex - nMoveIndex;
4024 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
4025 infoPtr->buttons[nMoveIndex] = button;
4027 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
4028 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
4029 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
4030 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
4033 TOOLBAR_CalcToolbar(hwnd);
4034 InvalidateRect(hwnd, NULL, TRUE);
4041 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
4043 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4044 TBUTTON_INFO *btnPtr;
4048 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4052 btnPtr = &infoPtr->buttons[nIndex];
4053 oldState = btnPtr->fsState;
4054 if (LOWORD(lParam) == FALSE)
4055 btnPtr->fsState &= ~TBSTATE_PRESSED;
4057 btnPtr->fsState |= TBSTATE_PRESSED;
4059 if(oldState != btnPtr->fsState)
4060 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4065 /* FIXME: there might still be some confusion her between number of buttons
4066 * and number of bitmaps */
4068 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4071 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
4073 int i = 0, nOldButtons = 0, pos = 0;
4074 int nOldBitmaps, nNewBitmaps;
4075 HIMAGELIST himlDef = 0;
4077 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
4078 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
4079 lpReplace->nButtons);
4081 if (lpReplace->hInstOld == HINST_COMMCTRL)
4083 FIXME("changing standard bitmaps not implemented\n");
4086 else if (lpReplace->hInstOld != 0)
4088 FIXME("resources not in the current module not implemented\n");
4093 hBitmap = (HBITMAP) lpReplace->nIDNew;
4096 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4097 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
4098 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
4099 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4100 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4102 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4103 nOldButtons = tbi->nButtons;
4104 tbi->nButtons = lpReplace->nButtons;
4105 tbi->hInst = lpReplace->hInstNew;
4106 tbi->nID = lpReplace->nIDNew;
4107 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4110 pos += tbi->nButtons;
4113 if (nOldButtons == 0)
4115 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
4119 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4120 nOldBitmaps = ImageList_GetImageCount(himlDef);
4122 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4124 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4125 ImageList_Remove(himlDef, i);
4129 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
4130 HDC hdcImage, hdcBitmap;
4132 /* copy the bitmap before adding it so that the user's bitmap
4133 * doesn't get modified.
4135 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
4137 hdcImage = CreateCompatibleDC(0);
4138 hdcBitmap = CreateCompatibleDC(0);
4140 /* create new bitmap */
4141 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
4142 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
4143 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
4145 /* Copy the user's image */
4146 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
4147 hdcBitmap, 0, 0, SRCCOPY);
4149 SelectObject (hdcImage, hOldBitmapLoad);
4150 SelectObject (hdcBitmap, hOldBitmapBitmap);
4151 DeleteDC (hdcImage);
4152 DeleteDC (hdcBitmap);
4154 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
4155 nNewBitmaps = ImageList_GetImageCount(himlDef);
4156 DeleteObject (hbmLoad);
4159 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4161 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4162 pos, nOldBitmaps, nNewBitmaps);
4164 InvalidateRect(hwnd, NULL, TRUE);
4170 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4174 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4176 if (lpSave == NULL) return 0;
4179 /* save toolbar information */
4180 FIXME("save to \"%s\" \"%s\"\n",
4181 lpSave->pszSubKey, lpSave->pszValueName);
4186 /* restore toolbar information */
4188 FIXME("restore from \"%s\" \"%s\"\n",
4189 lpSave->pszSubKey, lpSave->pszValueName);
4200 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4204 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4210 /* save toolbar information */
4211 FIXME("save to \"%s\" \"%s\"\n",
4212 lpSave->pszSubKey, lpSave->pszValueName);
4217 /* restore toolbar information */
4219 FIXME("restore from \"%s\" \"%s\"\n",
4220 lpSave->pszSubKey, lpSave->pszValueName);
4231 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4234 BOOL bOldAnchor = infoPtr->bAnchor;
4236 infoPtr->bAnchor = (BOOL)wParam;
4238 return (LRESULT)bOldAnchor;
4243 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4245 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4246 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4248 TRACE("hwnd=%p, wParam=%d, lParam=%ld\n", hwnd, wParam, lParam);
4251 FIXME("wParam is %d. Perhaps image list index?\n", wParam);
4253 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4256 if (infoPtr->nNumButtons > 0)
4257 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4258 infoPtr->nNumButtons,
4259 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4260 LOWORD(lParam), HIWORD(lParam));
4262 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4263 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4266 if ((himlDef == infoPtr->himlInt) &&
4267 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4269 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4270 infoPtr->nBitmapHeight);
4278 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4280 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4281 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4282 TBUTTON_INFO *btnPtr;
4288 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4291 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4292 lptbbi->dwMask & 0x80000000);
4296 btnPtr = &infoPtr->buttons[nIndex];
4297 if (lptbbi->dwMask & TBIF_COMMAND)
4298 btnPtr->idCommand = lptbbi->idCommand;
4299 if (lptbbi->dwMask & TBIF_IMAGE)
4300 btnPtr->iBitmap = lptbbi->iImage;
4301 if (lptbbi->dwMask & TBIF_LPARAM)
4302 btnPtr->dwData = lptbbi->lParam;
4303 if (lptbbi->dwMask & TBIF_SIZE)
4304 btnPtr->cx = lptbbi->cx;
4305 if (lptbbi->dwMask & TBIF_STATE)
4306 btnPtr->fsState = lptbbi->fsState;
4307 if (lptbbi->dwMask & TBIF_STYLE)
4308 btnPtr->fsStyle = lptbbi->fsStyle;
4310 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4311 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4312 /* iString is index, zero it to make Str_SetPtr succeed */
4315 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4318 /* save the button rect to see if we need to redraw the whole toolbar */
4319 oldBtnRect = btnPtr->rect;
4320 TOOLBAR_CalcToolbar(hwnd);
4322 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4323 InvalidateRect(hwnd, NULL, TRUE);
4325 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4332 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4335 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4336 TBUTTON_INFO *btnPtr;
4342 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4345 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4346 lptbbi->dwMask & 0x80000000);
4350 btnPtr = &infoPtr->buttons[nIndex];
4351 if (lptbbi->dwMask & TBIF_COMMAND)
4352 btnPtr->idCommand = lptbbi->idCommand;
4353 if (lptbbi->dwMask & TBIF_IMAGE)
4354 btnPtr->iBitmap = lptbbi->iImage;
4355 if (lptbbi->dwMask & TBIF_LPARAM)
4356 btnPtr->dwData = lptbbi->lParam;
4357 if (lptbbi->dwMask & TBIF_SIZE)
4358 btnPtr->cx = lptbbi->cx;
4359 if (lptbbi->dwMask & TBIF_STATE)
4360 btnPtr->fsState = lptbbi->fsState;
4361 if (lptbbi->dwMask & TBIF_STYLE)
4362 btnPtr->fsStyle = lptbbi->fsStyle;
4364 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4365 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4366 /* iString is index, zero it to make Str_SetPtr succeed */
4368 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4371 /* save the button rect to see if we need to redraw the whole toolbar */
4372 oldBtnRect = btnPtr->rect;
4373 TOOLBAR_CalcToolbar(hwnd);
4375 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4376 InvalidateRect(hwnd, NULL, TRUE);
4378 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4385 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4388 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4390 if ((cx < 0) || (cy < 0))
4392 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4396 /* The documentation claims you can only change the button size before
4397 * any button has been added. But this is wrong.
4398 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4399 * it to the toolbar, and it checks that the return value is nonzero - mjm
4400 * Further testing shows that we must actually perform the change too.
4403 * The documentation also does not mention that if 0 is supplied for
4404 * either size, the system changes it to the default of 24 wide and
4405 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4407 infoPtr->nButtonWidth = (cx) ? cx : 24;
4408 infoPtr->nButtonHeight = (cy) ? cy : 22;
4414 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4416 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4418 if (infoPtr == NULL) {
4419 TRACE("Toolbar not initialized yet?????\n");
4423 /* if setting to current values, ignore */
4424 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4425 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4426 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4427 infoPtr->cxMin, infoPtr->cxMax);
4431 /* save new values */
4432 infoPtr->cxMin = (INT)LOWORD(lParam);
4433 infoPtr->cxMax = (INT)HIWORD(lParam);
4435 /* if both values are 0 then we are done */
4437 TRACE("setting both min and max to 0, norecalc\n");
4441 /* otherwise we need to recalc the toolbar and in some cases
4442 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4443 which doesn't actually draw - GA). */
4444 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4445 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4447 TOOLBAR_CalcToolbar (hwnd);
4449 InvalidateRect (hwnd, NULL, TRUE);
4456 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4459 INT nIndex = (INT)wParam;
4461 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4464 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4466 if (infoPtr->hwndToolTip) {
4468 FIXME("change tool tip!\n");
4477 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4480 HIMAGELIST himl = (HIMAGELIST)lParam;
4481 HIMAGELIST himlTemp;
4484 if (infoPtr->iVersion >= 5)
4487 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4488 &infoPtr->cimlDis, himl, id);
4490 /* FIXME: redraw ? */
4492 return (LRESULT)himlTemp;
4497 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4502 dwTemp = infoPtr->dwDTFlags;
4503 infoPtr->dwDTFlags =
4504 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4506 return (LRESULT)dwTemp;
4509 /* This function differs a bit from what MSDN says it does:
4510 * 1. lParam contains extended style flags to OR with current style
4511 * (MSDN isn't clear on the OR bit)
4512 * 2. wParam appears to contain extended style flags to be reset
4513 * (MSDN says that this parameter is reserved)
4516 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4518 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4521 dwTemp = infoPtr->dwExStyle;
4522 infoPtr->dwExStyle &= ~wParam;
4523 infoPtr->dwExStyle |= (DWORD)lParam;
4525 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4527 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4528 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4529 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4531 TOOLBAR_CalcToolbar (hwnd);
4533 TOOLBAR_AutoSize(hwnd);
4535 InvalidateRect(hwnd, NULL, TRUE);
4537 return (LRESULT)dwTemp;
4542 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4544 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4545 HIMAGELIST himlTemp;
4546 HIMAGELIST himl = (HIMAGELIST)lParam;
4549 if (infoPtr->iVersion >= 5)
4552 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4554 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4555 &infoPtr->cimlHot, himl, id);
4557 /* FIXME: redraw ? */
4559 return (LRESULT)himlTemp;
4563 /* Makes previous hot button no longer hot, makes the specified
4564 * button hot and sends appropriate notifications. dwReason is one or
4565 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4566 * NOTE 1: this function does not validate nHit
4567 * NOTE 2: the name of this function is completely made up and
4568 * not based on any documentation from Microsoft. */
4570 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4572 if (infoPtr->nHotItem != nHit)
4574 NMTBHOTITEM nmhotitem;
4575 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4576 LRESULT no_highlight;
4578 /* Remove the effect of an old hot button if the button was
4579 drawn with the hot button effect */
4580 if(infoPtr->nHotItem >= 0)
4582 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4583 oldBtnPtr->bHot = FALSE;
4586 infoPtr->nHotItem = nHit;
4588 /* It's not a separator or in nowhere. It's a hot button. */
4590 btnPtr = &infoPtr->buttons[nHit];
4592 nmhotitem.dwFlags = dwReason;
4594 nmhotitem.idOld = oldBtnPtr->idCommand;
4596 nmhotitem.dwFlags |= HICF_ENTERING;
4598 nmhotitem.idNew = btnPtr->idCommand;
4600 nmhotitem.dwFlags |= HICF_LEAVING;
4602 no_highlight = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4604 /* now invalidate the old and new buttons so they will be painted */
4606 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4607 if (btnPtr && !no_highlight)
4609 btnPtr->bHot = TRUE;
4610 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4616 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4619 INT nOldHotItem = infoPtr->nHotItem;
4621 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4624 if (infoPtr->dwStyle & TBSTYLE_FLAT)
4625 TOOLBAR_SetHotItemEx(infoPtr, wParam, HICF_OTHER);
4627 if (nOldHotItem < 0)
4630 return (LRESULT)nOldHotItem;
4635 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4638 HIMAGELIST himlTemp;
4639 HIMAGELIST himl = (HIMAGELIST)lParam;
4642 if (infoPtr->iVersion >= 5)
4645 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4646 &infoPtr->cimlDef, himl, id);
4648 infoPtr->nNumBitmaps = 0;
4649 for (i = 0; i < infoPtr->cimlDef; i++)
4650 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4652 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4653 &infoPtr->nBitmapHeight);
4654 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4655 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4656 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4658 InvalidateRect(hwnd, NULL, TRUE);
4660 return (LRESULT)himlTemp;
4665 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4669 infoPtr->nIndent = (INT)wParam;
4673 /* process only on indent changing */
4674 if(infoPtr->nIndent != (INT)wParam)
4676 infoPtr->nIndent = (INT)wParam;
4677 TOOLBAR_CalcToolbar (hwnd);
4678 InvalidateRect(hwnd, NULL, FALSE);
4685 /* << TOOLBAR_SetInsertMark >> */
4689 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4691 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4693 infoPtr->clrInsertMark = (COLORREF)lParam;
4695 /* FIXME : redraw ??*/
4702 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4706 if (infoPtr == NULL)
4709 infoPtr->nMaxTextRows = (INT)wParam;
4711 TOOLBAR_CalcToolbar(hwnd);
4716 /* MSDN gives slightly wrong info on padding.
4717 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4718 * 2. It is not used to create a blank area between the edge of the button
4719 * and the text or image if TBSTYLE_LIST is set. It is used to control
4720 * the gap between the image and text.
4721 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4722 * to control the bottom and right borders [with the border being
4723 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4724 * is shared evenly on both sides of the button.
4727 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4729 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4732 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4733 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4734 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4735 TRACE("cx=%ld, cy=%ld\n",
4736 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4737 return (LRESULT) oldPad;
4742 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4749 if (infoPtr == NULL)
4751 hwndOldNotify = infoPtr->hwndNotify;
4752 infoPtr->hwndNotify = (HWND)wParam;
4754 return (LRESULT)hwndOldNotify;
4759 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4761 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4762 LPRECT lprc = (LPRECT)lParam;
4766 if (LOWORD(wParam) > 1) {
4767 FIXME("multiple rows not supported!\n");
4770 if(infoPtr->nRows != LOWORD(wParam))
4772 infoPtr->nRows = LOWORD(wParam);
4774 /* recalculate toolbar */
4775 TOOLBAR_CalcToolbar (hwnd);
4777 /* repaint toolbar */
4778 InvalidateRect(hwnd, NULL, TRUE);
4781 /* return bounding rectangle */
4783 lprc->left = infoPtr->rcBound.left;
4784 lprc->right = infoPtr->rcBound.right;
4785 lprc->top = infoPtr->rcBound.top;
4786 lprc->bottom = infoPtr->rcBound.bottom;
4794 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4796 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4797 TBUTTON_INFO *btnPtr;
4800 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4804 btnPtr = &infoPtr->buttons[nIndex];
4806 /* if hidden state has changed the invalidate entire window and recalc */
4807 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4808 btnPtr->fsState = LOWORD(lParam);
4809 TOOLBAR_CalcToolbar (hwnd);
4810 InvalidateRect(hwnd, 0, TRUE);
4814 /* process state changing if current state doesn't match new state */
4815 if(btnPtr->fsState != LOWORD(lParam))
4817 btnPtr->fsState = LOWORD(lParam);
4818 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4826 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4828 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4834 inline static LRESULT
4835 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4839 TRACE("hwnd=%p, hwndTooltip=%p, lParam=0x%lx\n", hwnd, (HWND)wParam, lParam);
4841 if (infoPtr == NULL)
4843 infoPtr->hwndToolTip = (HWND)wParam;
4849 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4854 TRACE("%s hwnd=%p stub!\n",
4855 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4857 bTemp = infoPtr->bUnicode;
4858 infoPtr->bUnicode = (BOOL)wParam;
4865 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4869 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4870 comctl32_color.clrBtnHighlight :
4871 infoPtr->clrBtnHighlight;
4872 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4873 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4879 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4883 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4884 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4885 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4887 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4888 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4889 InvalidateRect(hwnd, NULL, TRUE);
4895 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4897 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4898 INT iOldVersion = infoPtr->iVersion;
4900 infoPtr->iVersion = iVersion;
4902 if (infoPtr->iVersion >= 5)
4903 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4910 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4913 WORD iString = HIWORD(wParam);
4914 WORD buffersize = LOWORD(wParam);
4915 LPSTR str = (LPSTR)lParam;
4918 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4920 if (iString < infoPtr->nNumStrings)
4922 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4924 TRACE("returning %s\n", debugstr_a(str));
4927 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4934 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4937 WORD iString = HIWORD(wParam);
4938 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4939 LPWSTR str = (LPWSTR)lParam;
4942 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4944 if (iString < infoPtr->nNumStrings)
4946 len = min(len, strlenW(infoPtr->strings[iString]));
4947 ret = (len+1)*sizeof(WCHAR);
4948 memcpy(str, infoPtr->strings[iString], ret);
4951 TRACE("returning %s\n", debugstr_w(str));
4954 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4959 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
4960 * is the maximum size of the toolbar? */
4961 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4963 SIZE * pSize = (SIZE*)lParam;
4964 FIXME("hwnd=%p, wParam=0x%08x, size.cx=%ld, size.cy=%ld stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
4969 /* UNDOCUMENTED MESSAGE: This is an extended version of the
4970 * TB_SETHOTITEM message. It allows the caller to specify a reason why the
4971 * hot item changed (rather than just the HICF_OTHER that TB_SETHOTITEM
4974 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4976 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4977 INT nOldHotItem = infoPtr->nHotItem;
4979 TRACE("old item=%d, new item=%d, flags=%08lx\n",
4980 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam);
4982 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4985 TOOLBAR_SetHotItemEx(infoPtr, wParam, lParam);
4989 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
4992 /* UNDOCUMENTED MESSAGE: This sets the toolbar global iListGap parameter
4993 * which controls the amount of spacing between the image and the text
4994 * of buttons for TBSTYLE_LIST toolbars. */
4995 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4999 TRACE("hwnd=%p iListGap=%d\n", hwnd, wParam);
5002 FIXME("lParam = 0x%08lx. Please report\n", lParam);
5004 infoPtr->iListGap = (INT)wParam;
5006 TOOLBAR_CalcToolbar(hwnd);
5007 InvalidateRect(hwnd, NULL, TRUE);
5012 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
5013 * of image lists associated with the various states. */
5014 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
5016 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5018 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5020 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5024 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
5026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5027 LPSIZE lpsize = (LPSIZE)lParam;
5033 * Testing shows the following:
5034 * wParam = 0 adjust cx value
5035 * = 1 set cy value to max size.
5036 * lParam pointer to SIZE structure
5039 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
5040 wParam, lParam, lpsize->cx, lpsize->cy);
5044 if (lpsize->cx == -1) {
5045 /* **** this is wrong, native measures each button and sets it */
5046 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5048 else if(HIWORD(lpsize->cx)) {
5050 HWND hwndParent = GetParent(hwnd);
5052 GetWindowRect(hwnd, &rc);
5053 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5054 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
5055 rc.left, rc.top, rc.right, rc.bottom);
5056 lpsize->cx = max(rc.right-rc.left,
5057 infoPtr->rcBound.right - infoPtr->rcBound.left);
5060 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5064 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5065 /* lpsize->cy = infoPtr->nHeight; */
5068 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
5072 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
5073 lpsize->cx, lpsize->cy);
5077 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5079 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
5081 InvalidateRect(hwnd, NULL, TRUE);
5087 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
5089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5090 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
5093 TRACE("hwnd = %p\n", hwnd);
5095 /* initialize info structure */
5096 infoPtr->nButtonHeight = 22;
5097 infoPtr->nButtonWidth = 24;
5098 infoPtr->nBitmapHeight = 15;
5099 infoPtr->nBitmapWidth = 16;
5101 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
5102 infoPtr->nMaxTextRows = 1;
5103 infoPtr->cxMin = -1;
5104 infoPtr->cxMax = -1;
5105 infoPtr->nNumBitmaps = 0;
5106 infoPtr->nNumStrings = 0;
5108 infoPtr->bCaptured = FALSE;
5109 infoPtr->bUnicode = IsWindowUnicode (hwnd);
5110 infoPtr->nButtonDown = -1;
5111 infoPtr->nButtonDrag = -1;
5112 infoPtr->nOldHit = -1;
5113 infoPtr->nHotItem = -1;
5114 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
5115 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
5116 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5117 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5118 infoPtr->bDragOutSent = FALSE;
5119 infoPtr->iVersion = 0;
5120 infoPtr->hwndSelf = hwnd;
5121 infoPtr->bDoRedraw = TRUE;
5122 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5123 infoPtr->clrBtnShadow = CLR_DEFAULT;
5124 /* not sure where the +1 comes from, but this comes to the same value
5125 * as native so this is probably correct */
5126 infoPtr->szPadding.cx = 2*(GetSystemMetrics(SM_CXEDGE)+OFFSET_X) + 1;
5127 infoPtr->szPadding.cy = 2*(GetSystemMetrics(SM_CYEDGE)+OFFSET_Y);
5128 infoPtr->iListGap = infoPtr->szPadding.cx / 2;
5129 infoPtr->dwStyle = dwStyle;
5130 GetClientRect(hwnd, &infoPtr->client_rect);
5131 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
5133 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5134 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
5136 if (dwStyle & TBSTYLE_TOOLTIPS) {
5137 /* Create tooltip control */
5138 infoPtr->hwndToolTip =
5139 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
5140 CW_USEDEFAULT, CW_USEDEFAULT,
5141 CW_USEDEFAULT, CW_USEDEFAULT,
5144 /* Send NM_TOOLTIPSCREATED notification */
5145 if (infoPtr->hwndToolTip) {
5146 NMTOOLTIPSCREATED nmttc;
5148 nmttc.hwndToolTips = infoPtr->hwndToolTip;
5150 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
5151 NM_TOOLTIPSCREATED);
5155 TOOLBAR_CheckStyle (hwnd, dwStyle);
5157 TOOLBAR_CalcToolbar(hwnd);
5164 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
5166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5168 /* delete tooltip control */
5169 if (infoPtr->hwndToolTip)
5170 DestroyWindow (infoPtr->hwndToolTip);
5172 /* delete temporary buffer for tooltip text */
5173 if (infoPtr->pszTooltipText)
5174 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5176 /* delete button data */
5177 if (infoPtr->buttons)
5178 Free (infoPtr->buttons);
5180 /* delete strings */
5181 if (infoPtr->strings) {
5183 for (i = 0; i < infoPtr->nNumStrings; i++)
5184 if (infoPtr->strings[i])
5185 Free (infoPtr->strings[i]);
5187 Free (infoPtr->strings);
5190 /* destroy internal image list */
5191 if (infoPtr->himlInt)
5192 ImageList_Destroy (infoPtr->himlInt);
5194 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5195 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5196 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5198 /* delete default font */
5200 DeleteObject (infoPtr->hDefaultFont);
5202 /* free toolbar info data */
5204 SetWindowLongPtrW (hwnd, 0, 0);
5211 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
5213 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5214 NMTBCUSTOMDRAW tbcd;
5218 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5219 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5220 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5221 tbcd.nmcd.hdc = (HDC)wParam;
5222 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5223 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5225 /* FIXME: in general the return flags *can* be or'ed together */
5226 switch (infoPtr->dwBaseCustDraw)
5228 case CDRF_DODEFAULT:
5230 case CDRF_SKIPDEFAULT:
5233 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5238 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5239 * to my parent for processing.
5241 if (infoPtr->dwStyle & TBSTYLE_TRANSPARENT) {
5243 HDC hdc = (HDC)wParam;
5248 parent = GetParent(hwnd);
5249 MapWindowPoints(hwnd, parent, &pt, 1);
5250 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5251 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5252 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5255 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5257 if ((infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) &&
5258 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5259 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5260 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5261 tbcd.nmcd.hdc = (HDC)wParam;
5262 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5263 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5264 switch (infoPtr->dwBaseCustDraw)
5266 case CDRF_DODEFAULT:
5268 case CDRF_SKIPDEFAULT:
5271 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5280 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5282 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5284 return (LRESULT)infoPtr->hFont;
5289 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5294 pt.x = (INT)LOWORD(lParam);
5295 pt.y = (INT)HIWORD(lParam);
5296 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5299 TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5300 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5301 TOOLBAR_Customize (hwnd);
5308 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5310 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5311 TBUTTON_INFO *btnPtr;
5315 BOOL bDragKeyPressed;
5319 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5320 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5322 bDragKeyPressed = (wParam & MK_SHIFT);
5324 if (infoPtr->hwndToolTip)
5325 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5326 WM_LBUTTONDOWN, wParam, lParam);
5328 pt.x = (INT)LOWORD(lParam);
5329 pt.y = (INT)HIWORD(lParam);
5330 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5332 btnPtr = &infoPtr->buttons[nHit];
5334 if ((nHit >= 0) && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5336 infoPtr->nButtonDrag = nHit;
5339 /* If drag cursor has not been loaded, load it.
5340 * Note: it doesn't need to be freed */
5342 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5343 SetCursor(hCursorDrag);
5348 infoPtr->nOldHit = nHit;
5350 CopyRect(&arrowRect, &btnPtr->rect);
5351 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5353 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5354 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5355 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5356 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5357 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5358 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5362 /* draw in pressed state */
5363 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5364 btnPtr->fsState |= TBSTATE_PRESSED;
5366 btnPtr->bDropDownPressed = TRUE;
5367 RedrawWindow(hwnd,&btnPtr->rect,0,
5368 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5370 nmtb.iItem = btnPtr->idCommand;
5371 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5374 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5375 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5377 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5379 if (res != TBDDRET_TREATPRESSED)
5383 /* redraw button in unpressed state */
5384 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5385 btnPtr->fsState &= ~TBSTATE_PRESSED;
5387 btnPtr->bDropDownPressed = FALSE;
5388 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5390 /* find and set hot item
5391 * NOTE: native doesn't do this, but that is a bug */
5393 ScreenToClient(hwnd, &pt);
5394 nHit = TOOLBAR_InternalHitTest(hwnd, &pt);
5395 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5397 /* remove any left mouse button down or double-click messages
5398 * so that we can get a toggle effect on the button */
5399 while (PeekMessageW(&msg, hwnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5400 PeekMessageW(&msg, hwnd, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5405 /* otherwise drop through and process as pushed */
5407 infoPtr->bCaptured = TRUE;
5408 infoPtr->nButtonDown = nHit;
5409 infoPtr->bDragOutSent = FALSE;
5411 btnPtr->fsState |= TBSTATE_PRESSED;
5413 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5415 if (btnPtr->fsState & TBSTATE_ENABLED)
5416 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5423 nmtb.iItem = btnPtr->idCommand;
5424 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5425 nmtb.tbButton.idCommand = btnPtr->idCommand;
5426 nmtb.tbButton.fsState = btnPtr->fsState;
5427 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5428 nmtb.tbButton.dwData = btnPtr->dwData;
5429 nmtb.tbButton.iString = btnPtr->iString;
5430 nmtb.cchText = 0; /* !!! not correct */
5431 nmtb.pszText = 0; /* !!! not correct */
5432 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5439 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5441 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5442 TBUTTON_INFO *btnPtr;
5446 BOOL bSendMessage = TRUE;
5451 if (infoPtr->hwndToolTip)
5452 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5453 WM_LBUTTONUP, wParam, lParam);
5455 pt.x = (INT)LOWORD(lParam);
5456 pt.y = (INT)HIWORD(lParam);
5457 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5459 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5461 if (infoPtr->nButtonDrag >= 0) {
5465 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5468 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5470 GetClientRect(hwnd, &rcClient);
5471 if (PtInRect(&rcClient, pt))
5478 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5481 if (nButton == infoPtr->nButtonDrag)
5483 /* if the button is moved sightly left and we have a
5484 * separator there then remove it */
5485 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5487 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5488 TOOLBAR_DeleteButton(hwnd, nButton - 1, 0);
5490 else /* else insert a separator before the dragged button */
5493 memset(&tbb, 0, sizeof(tbb));
5494 tbb.fsStyle = BTNS_SEP;
5496 TOOLBAR_InsertButtonW(hwnd, nButton, (LPARAM)&tbb);
5503 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5504 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, 0);
5506 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5509 TOOLBAR_MoveButton(hwnd, infoPtr->nButtonDrag, nButton);
5514 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5515 TOOLBAR_DeleteButton(hwnd, (WPARAM)infoPtr->nButtonDrag, 0);
5518 /* button under cursor changed so need to re-set hot item */
5519 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE | HICF_LMOUSE);
5520 infoPtr->nButtonDrag = -1;
5522 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5524 else if (infoPtr->nButtonDown >= 0) {
5525 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5526 btnPtr->fsState &= ~TBSTATE_PRESSED;
5528 if (btnPtr->fsStyle & BTNS_CHECK) {
5529 if (btnPtr->fsStyle & BTNS_GROUP) {
5530 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5532 if (nOldIndex == nHit)
5533 bSendMessage = FALSE;
5534 if ((nOldIndex != nHit) &&
5536 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5537 btnPtr->fsState |= TBSTATE_CHECKED;
5540 if (btnPtr->fsState & TBSTATE_CHECKED)
5541 btnPtr->fsState &= ~TBSTATE_CHECKED;
5543 btnPtr->fsState |= TBSTATE_CHECKED;
5547 if (nOldIndex != -1)
5548 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect, TRUE);
5551 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5552 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5553 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5555 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5557 infoPtr->nButtonDown = -1;
5559 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5560 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5561 NM_RELEASEDCAPTURE);
5563 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5566 nmtb.iItem = btnPtr->idCommand;
5567 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5568 nmtb.tbButton.idCommand = btnPtr->idCommand;
5569 nmtb.tbButton.fsState = btnPtr->fsState;
5570 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5571 nmtb.tbButton.dwData = btnPtr->dwData;
5572 nmtb.tbButton.iString = btnPtr->iString;
5573 nmtb.cchText = 0; /* !!! not correct */
5574 nmtb.pszText = 0; /* !!! not correct */
5575 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5578 if (btnPtr->fsState & TBSTATE_ENABLED)
5580 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5581 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5583 /* !!! Undocumented - toolbar at 4.71 level and above sends
5584 * either NM_RCLICK or NM_CLICK with the NMMOUSE structure.
5585 * Only NM_RCLICK is documented.
5587 nmmouse.dwItemSpec = btnPtr->idCommand;
5588 nmmouse.dwItemData = btnPtr->dwData;
5589 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5596 TOOLBAR_RButtonUp( HWND hwnd, WPARAM wParam, LPARAM lParam)
5598 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5603 pt.x = LOWORD(lParam);
5604 pt.y = HIWORD(lParam);
5606 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5608 if (nmmouse.dwHitInfo < 0) {
5609 nmmouse.dwItemSpec = -1;
5611 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5612 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5615 ClientToScreen(hwnd, &pt);
5616 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5618 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK);
5624 TOOLBAR_RButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam)
5626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5631 pt.x = LOWORD(lParam);
5632 pt.y = HIWORD(lParam);
5634 nmmouse.dwHitInfo = TOOLBAR_InternalHitTest(hwnd, &pt);
5636 if (nmmouse.dwHitInfo < 0)
5637 nmmouse.dwItemSpec = -1;
5639 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5640 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5643 ClientToScreen(hwnd, &pt);
5644 memcpy(&nmmouse.pt, &pt, sizeof(POINT));
5646 TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RDBLCLK);
5652 TOOLBAR_CaptureChanged(HWND hwnd)
5654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5655 TBUTTON_INFO *btnPtr;
5657 infoPtr->bCaptured = FALSE;
5659 if (infoPtr->nButtonDown >= 0)
5661 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5662 btnPtr->fsState &= ~TBSTATE_PRESSED;
5664 infoPtr->nOldHit = -1;
5666 if (btnPtr->fsState & TBSTATE_ENABLED)
5667 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5673 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5675 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5676 TBUTTON_INFO *hotBtnPtr;
5678 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5680 /* don't remove hot effects when in drop-down */
5681 if (infoPtr->nOldHit < 0 || !hotBtnPtr->bDropDownPressed)
5682 TOOLBAR_SetHotItemEx(infoPtr, -1, HICF_MOUSE);
5684 if (infoPtr->nOldHit < 0)
5687 /* If the last button we were over is depressed then make it not */
5688 /* depressed and redraw it */
5689 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5691 TBUTTON_INFO *btnPtr;
5694 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5696 btnPtr->fsState &= ~TBSTATE_PRESSED;
5698 rc1 = hotBtnPtr->rect;
5699 InflateRect (&rc1, 1, 1);
5700 InvalidateRect (hwnd, &rc1, TRUE);
5703 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5706 ZeroMemory(&nmt, sizeof(nmt));
5707 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5708 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5709 infoPtr->bDragOutSent = TRUE;
5712 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5718 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5720 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5722 TRACKMOUSEEVENT trackinfo;
5724 TBUTTON_INFO *btnPtr;
5726 /* fill in the TRACKMOUSEEVENT struct */
5727 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5728 trackinfo.dwFlags = TME_QUERY;
5729 trackinfo.hwndTrack = hwnd;
5730 trackinfo.dwHoverTime = HOVER_DEFAULT;
5732 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5733 _TrackMouseEvent(&trackinfo);
5735 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5736 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5737 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5739 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5740 /* and can properly deactivate the hot toolbar button */
5741 _TrackMouseEvent(&trackinfo);
5744 if (infoPtr->hwndToolTip)
5745 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5746 WM_MOUSEMOVE, wParam, lParam);
5748 pt.x = (INT)LOWORD(lParam);
5749 pt.y = (INT)HIWORD(lParam);
5751 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5753 TOOLBAR_SetHotItemEx(infoPtr, nHit, HICF_MOUSE);
5755 if (infoPtr->nOldHit != nHit)
5757 if (infoPtr->bCaptured)
5759 if (!infoPtr->bDragOutSent)
5762 ZeroMemory(&nmt, sizeof(nmt));
5763 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5764 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5765 infoPtr->bDragOutSent = TRUE;
5768 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5769 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5770 btnPtr->fsState &= ~TBSTATE_PRESSED;
5771 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5773 else if (nHit == infoPtr->nButtonDown) {
5774 btnPtr->fsState |= TBSTATE_PRESSED;
5775 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5777 infoPtr->nOldHit = nHit;
5785 inline static LRESULT
5786 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5788 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5789 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5791 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5795 inline static LRESULT
5796 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5798 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5799 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5801 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5806 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5808 TOOLBAR_INFO *infoPtr;
5809 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5812 /* allocate memory for info structure */
5813 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5814 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5817 infoPtr->dwStructSize = sizeof(TBBUTTON);
5820 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5821 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5822 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5823 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5826 /* native control does:
5827 * Get a lot of colors and brushes
5829 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5830 * CreateFontIndirectA(adr1)
5831 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5832 * hdc = GetDC(toolbar)
5833 * GetSystemMetrics(0x48)
5834 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5835 * 0, 0, 0, 0, "MARLETT")
5836 * oldfnt = SelectObject(hdc, fnt2)
5837 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5838 * GetTextMetricsA(hdc, adr3)
5839 * SelectObject(hdc, oldfnt)
5840 * DeleteObject(fnt2)
5842 * InvalidateRect(toolbar, 0, 1)
5843 * SetWindowLongA(toolbar, 0, addr)
5844 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5847 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5848 * ie 2 0x4600094c 0x4600094c 0x4600894d
5849 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5850 * rebar 0x50008844 0x40008844 0x50008845
5851 * pager 0x50000844 0x40000844 0x50008845
5852 * IC35mgr 0x5400084e **nochange**
5853 * on entry to _NCCREATE 0x5400084e
5854 * rowlist 0x5400004e **nochange**
5855 * on entry to _NCCREATE 0x5400004e
5859 /* I think the code below is a bug, but it is the way that the native
5860 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5861 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5862 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5863 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5864 * Some how, the only cases of this seem to be MFC programs.
5866 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5867 * does not occur in the WM_STYLECHANGING routine.
5868 * (Guy Albertelli 9/2001)
5871 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5872 styleadd |= TBSTYLE_TRANSPARENT;
5873 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5874 styleadd |= CCS_TOP; /* default to top */
5875 SetWindowLongW (hwnd, GWL_STYLE, cs->style | styleadd);
5878 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5883 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5885 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5889 if (dwStyle & WS_MINIMIZE)
5890 return 0; /* Nothing to do */
5892 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5894 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5897 if (!(dwStyle & CCS_NODIVIDER))
5899 GetWindowRect (hwnd, &rcWindow);
5900 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5901 if( dwStyle & WS_BORDER )
5902 OffsetRect (&rcWindow, 1, 1);
5903 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5906 ReleaseDC( hwnd, hdc );
5912 /* handles requests from the tooltip control on what text to display */
5913 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5915 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5917 TRACE("button index = %d\n", index);
5919 if (infoPtr->pszTooltipText)
5921 HeapFree(GetProcessHeap(), 0, infoPtr->pszTooltipText);
5922 infoPtr->pszTooltipText = NULL;
5928 if (infoPtr->bNtfUnicode)
5930 WCHAR wszBuffer[INFOTIPSIZE+1];
5931 NMTBGETINFOTIPW tbgit;
5932 int len; /* in chars */
5934 wszBuffer[0] = '\0';
5935 wszBuffer[INFOTIPSIZE] = '\0';
5937 tbgit.pszText = wszBuffer;
5938 tbgit.cchTextMax = INFOTIPSIZE;
5939 tbgit.iItem = lpnmtdi->hdr.idFrom;
5940 tbgit.lParam = infoPtr->buttons[index].dwData;
5942 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
5944 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
5946 len = strlenW(tbgit.pszText);
5947 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5949 /* need to allocate temporary buffer in infoPtr as there
5950 * isn't enough space in buffer passed to us by the
5951 * tooltip control */
5952 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5953 if (infoPtr->pszTooltipText)
5955 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5956 lpnmtdi->lpszText = infoPtr->pszTooltipText;
5962 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
5968 CHAR szBuffer[INFOTIPSIZE+1];
5969 NMTBGETINFOTIPA tbgit;
5970 int len; /* in chars */
5973 szBuffer[INFOTIPSIZE] = '\0';
5975 tbgit.pszText = szBuffer;
5976 tbgit.cchTextMax = INFOTIPSIZE;
5977 tbgit.iItem = lpnmtdi->hdr.idFrom;
5978 tbgit.lParam = infoPtr->buttons[index].dwData;
5980 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
5982 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
5984 len = -1 + MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
5985 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
5987 /* need to allocate temporary buffer in infoPtr as there
5988 * isn't enough space in buffer passed to us by the
5989 * tooltip control */
5990 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
5991 if (infoPtr->pszTooltipText)
5993 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, infoPtr->pszTooltipText, (len+1)*sizeof(WCHAR));
5994 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6000 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, len+1, lpnmtdi->lpszText, (len+1)*sizeof(WCHAR));
6005 /* if button has text, but it is not shown then automatically
6006 * use that text as tooltip */
6007 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6008 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6010 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6011 int len = pszText ? strlenW(pszText) : 0;
6013 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6015 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6017 /* need to allocate temporary buffer in infoPtr as there
6018 * isn't enough space in buffer passed to us by the
6019 * tooltip control */
6020 infoPtr->pszTooltipText = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
6021 if (infoPtr->pszTooltipText)
6023 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6024 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6030 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6035 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6037 /* last resort: send notification on to app */
6038 /* FIXME: find out what is really used here */
6039 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)lpnmtdi);
6043 inline static LRESULT
6044 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
6046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6047 LPNMHDR lpnmh = (LPNMHDR)lParam;
6049 switch (lpnmh->code)
6053 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
6055 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6056 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6057 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6061 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6062 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6070 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
6072 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6073 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6074 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6075 lppgs->iScroll, lppgs->iDir);
6079 case TTN_GETDISPINFOW:
6080 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lParam);
6082 case TTN_GETDISPINFOA:
6083 FIXME("TTN_GETDISPINFOA - stub\n");
6093 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
6095 /* remove this routine when Toolbar is improved to pass infoPtr
6096 * around instead of hwnd.
6098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6099 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
6104 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6108 TRACE("wParam = 0x%x, lParam = 0x%08lx\n", wParam, lParam);
6110 if ((lParam == NF_QUERY) && ((HWND)wParam == infoPtr->hwndToolTip))
6113 if (lParam == NF_REQUERY) {
6114 i = SendMessageA(infoPtr->hwndNotify,
6115 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6116 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
6117 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
6121 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
6124 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
6129 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
6131 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
6135 /* fill ps.rcPaint with a default rect */
6136 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
6138 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
6140 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
6141 ps.rcPaint.left, ps.rcPaint.top,
6142 ps.rcPaint.right, ps.rcPaint.bottom);
6144 TOOLBAR_Refresh (hwnd, hdc, &ps);
6145 if (!wParam) EndPaint (hwnd, &ps);
6152 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
6153 /*****************************************************
6156 * Handles the WM_SETREDRAW message.
6159 * According to testing V4.71 of COMCTL32 returns the
6160 * *previous* status of the redraw flag (either 0 or 1)
6161 * instead of the MSDN documented value of 0 if handled.
6162 * (For laughs see the "consistency" with same function
6165 *****************************************************/
6167 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6168 BOOL oldredraw = infoPtr->bDoRedraw;
6170 TRACE("set to %s\n",
6171 (wParam) ? "TRUE" : "FALSE");
6172 infoPtr->bDoRedraw = (BOOL) wParam;
6174 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6176 return (oldredraw) ? 1 : 0;
6181 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
6183 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6184 DWORD dwStyle = infoPtr->dwStyle;
6193 /* Resize deadlock check */
6194 if (infoPtr->bAutoSize) {
6195 infoPtr->bAutoSize = FALSE;
6199 /* FIXME: optimize to only update size if the new size doesn't */
6200 /* match the current size */
6202 flags = (INT) wParam;
6204 /* FIXME for flags =
6205 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
6208 TRACE("sizing toolbar!\n");
6210 if (flags == SIZE_RESTORED) {
6211 /* width and height don't apply */
6212 parent = GetParent (hwnd);
6213 GetClientRect(parent, &parent_rect);
6214 x = parent_rect.left;
6215 y = parent_rect.top;
6217 if (dwStyle & CCS_NORESIZE) {
6218 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
6221 * this sets the working width of the toolbar, and
6222 * Calc Toolbar will not adjust it, only the height
6224 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6225 cy = infoPtr->nHeight;
6226 cx = infoPtr->nWidth;
6227 TOOLBAR_CalcToolbar (hwnd);
6228 infoPtr->nWidth = cx;
6229 infoPtr->nHeight = cy;
6232 infoPtr->nWidth = parent_rect.right - parent_rect.left;
6233 TOOLBAR_CalcToolbar (hwnd);
6234 cy = infoPtr->nHeight;
6235 cx = infoPtr->nWidth;
6237 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
6238 GetWindowRect(hwnd, &window_rect);
6239 ScreenToClient(parent, (LPPOINT)&window_rect.left);
6240 y = window_rect.top;
6242 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
6243 GetWindowRect(hwnd, &window_rect);
6244 y = parent_rect.bottom -
6245 ( window_rect.bottom - window_rect.top);
6249 if (dwStyle & CCS_NOPARENTALIGN) {
6250 uPosFlags |= SWP_NOMOVE;
6251 cy = infoPtr->nHeight;
6252 cx = infoPtr->nWidth;
6255 if (!(dwStyle & CCS_NODIVIDER))
6256 cy += GetSystemMetrics(SM_CYEDGE);
6258 if (dwStyle & WS_BORDER)
6261 cy += GetSystemMetrics(SM_CYEDGE);
6262 cx += GetSystemMetrics(SM_CYEDGE);
6265 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6267 RECT delta_width, delta_height, client, dummy;
6268 DWORD min_x, max_x, min_y, max_y;
6269 TBUTTON_INFO *btnPtr;
6272 GetClientRect(hwnd, &client);
6273 if(client.right > infoPtr->client_rect.right)
6275 min_x = infoPtr->client_rect.right;
6276 max_x = client.right;
6280 max_x = infoPtr->client_rect.right;
6281 min_x = client.right;
6283 if(client.bottom > infoPtr->client_rect.bottom)
6285 min_y = infoPtr->client_rect.bottom;
6286 max_y = client.bottom;
6290 max_y = infoPtr->client_rect.bottom;
6291 min_y = client.bottom;
6294 SetRect(&delta_width, min_x, 0, max_x, min_y);
6295 SetRect(&delta_height, 0, min_y, max_x, max_y);
6297 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6298 btnPtr = infoPtr->buttons;
6299 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6300 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6301 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6302 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
6305 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
6306 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
6308 GetClientRect(hwnd, &infoPtr->client_rect);
6314 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
6316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6318 if (nType == GWL_STYLE) {
6319 if (lpStyle->styleNew & TBSTYLE_LIST) {
6320 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6323 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6325 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
6326 (TBSTYLE_FLAT | TBSTYLE_LIST));
6327 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
6329 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
6331 infoPtr->dwStyle = lpStyle->styleNew;
6334 TOOLBAR_CalcToolbar(hwnd);
6336 TOOLBAR_AutoSize (hwnd);
6338 InvalidateRect(hwnd, NULL, TRUE);
6345 TOOLBAR_SysColorChange (HWND hwnd)
6347 COMCTL32_RefreshSysColors();
6354 static LRESULT WINAPI
6355 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6357 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
6359 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
6360 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6362 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
6363 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
6368 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
6370 case TB_ADDBUTTONSA:
6371 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
6373 case TB_ADDBUTTONSW:
6374 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
6377 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
6380 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
6383 return TOOLBAR_AutoSize (hwnd);
6385 case TB_BUTTONCOUNT:
6386 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
6388 case TB_BUTTONSTRUCTSIZE:
6389 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
6391 case TB_CHANGEBITMAP:
6392 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
6394 case TB_CHECKBUTTON:
6395 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
6397 case TB_COMMANDTOINDEX:
6398 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
6401 return TOOLBAR_Customize (hwnd);
6403 case TB_DELETEBUTTON:
6404 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
6406 case TB_ENABLEBUTTON:
6407 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
6409 case TB_GETANCHORHIGHLIGHT:
6410 return TOOLBAR_GetAnchorHighlight (hwnd);
6413 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
6415 case TB_GETBITMAPFLAGS:
6416 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
6419 return TOOLBAR_GetButton (hwnd, wParam, lParam);
6421 case TB_GETBUTTONINFOA:
6422 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
6424 case TB_GETBUTTONINFOW:
6425 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
6427 case TB_GETBUTTONSIZE:
6428 return TOOLBAR_GetButtonSize (hwnd);
6430 case TB_GETBUTTONTEXTA:
6431 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
6433 case TB_GETBUTTONTEXTW:
6434 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
6436 case TB_GETDISABLEDIMAGELIST:
6437 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
6439 case TB_GETEXTENDEDSTYLE:
6440 return TOOLBAR_GetExtendedStyle (hwnd);
6442 case TB_GETHOTIMAGELIST:
6443 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
6446 return TOOLBAR_GetHotItem (hwnd);
6448 case TB_GETIMAGELIST:
6449 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
6451 /* case TB_GETINSERTMARK: */ /* 4.71 */
6452 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
6454 case TB_GETITEMRECT:
6455 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
6458 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
6460 /* case TB_GETOBJECT: */ /* 4.71 */
6463 return TOOLBAR_GetPadding (hwnd);
6466 return TOOLBAR_GetRect (hwnd, wParam, lParam);
6469 return TOOLBAR_GetRows (hwnd, wParam, lParam);
6472 return TOOLBAR_GetState (hwnd, wParam, lParam);
6475 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
6478 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6481 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6483 case TB_GETTEXTROWS:
6484 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6486 case TB_GETTOOLTIPS:
6487 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6489 case TB_GETUNICODEFORMAT:
6490 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6493 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6496 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6498 case TB_INDETERMINATE:
6499 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6501 case TB_INSERTBUTTONA:
6502 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6504 case TB_INSERTBUTTONW:
6505 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6507 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6509 case TB_ISBUTTONCHECKED:
6510 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6512 case TB_ISBUTTONENABLED:
6513 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6515 case TB_ISBUTTONHIDDEN:
6516 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6518 case TB_ISBUTTONHIGHLIGHTED:
6519 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6521 case TB_ISBUTTONINDETERMINATE:
6522 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6524 case TB_ISBUTTONPRESSED:
6525 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6528 return TOOLBAR_LoadImages (hwnd, wParam, lParam);
6530 case TB_MAPACCELERATORA:
6531 case TB_MAPACCELERATORW:
6532 return TOOLBAR_MapAccelerator (hwnd, wParam, lParam);
6535 return TOOLBAR_MarkButton (hwnd, wParam, lParam);
6538 return TOOLBAR_MoveButton (hwnd, wParam, lParam);
6540 case TB_PRESSBUTTON:
6541 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6543 case TB_REPLACEBITMAP:
6544 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6546 case TB_SAVERESTOREA:
6547 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6549 case TB_SAVERESTOREW:
6550 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6552 case TB_SETANCHORHIGHLIGHT:
6553 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6555 case TB_SETBITMAPSIZE:
6556 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6558 case TB_SETBUTTONINFOA:
6559 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6561 case TB_SETBUTTONINFOW:
6562 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6564 case TB_SETBUTTONSIZE:
6565 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6567 case TB_SETBUTTONWIDTH:
6568 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6571 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6573 case TB_SETDISABLEDIMAGELIST:
6574 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6576 case TB_SETDRAWTEXTFLAGS:
6577 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6579 case TB_SETEXTENDEDSTYLE:
6580 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6582 case TB_SETHOTIMAGELIST:
6583 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6586 return TOOLBAR_SetHotItem (hwnd, wParam);
6588 case TB_SETIMAGELIST:
6589 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6592 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6594 /* case TB_SETINSERTMARK: */ /* 4.71 */
6596 case TB_SETINSERTMARKCOLOR:
6597 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6599 case TB_SETMAXTEXTROWS:
6600 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6603 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6606 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6609 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6612 return TOOLBAR_SetState (hwnd, wParam, lParam);
6615 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6617 case TB_SETTOOLTIPS:
6618 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6620 case TB_SETUNICODEFORMAT:
6621 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6624 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6627 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6630 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6633 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6636 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6639 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6641 /* Common Control Messages */
6643 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6644 case CCM_GETCOLORSCHEME:
6645 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6647 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6648 case CCM_SETCOLORSCHEME:
6649 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6651 case CCM_GETVERSION:
6652 return TOOLBAR_GetVersion (hwnd);
6654 case CCM_SETVERSION:
6655 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6661 return TOOLBAR_Create (hwnd, wParam, lParam);
6664 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6667 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6670 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6672 /* case WM_KEYDOWN: */
6673 /* case WM_KILLFOCUS: */
6675 case WM_LBUTTONDBLCLK:
6676 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6678 case WM_LBUTTONDOWN:
6679 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6682 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6685 return TOOLBAR_RButtonUp (hwnd, wParam, lParam);
6687 case WM_RBUTTONDBLCLK:
6688 return TOOLBAR_RButtonDblClk (hwnd, wParam, lParam);
6691 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6694 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6696 case WM_CAPTURECHANGED:
6697 return TOOLBAR_CaptureChanged(hwnd);
6700 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6703 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6706 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6709 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6712 return TOOLBAR_Notify (hwnd, wParam, lParam);
6714 case WM_NOTIFYFORMAT:
6715 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6718 return TOOLBAR_Paint (hwnd, wParam);
6721 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6724 return TOOLBAR_Size (hwnd, wParam, lParam);
6726 case WM_STYLECHANGED:
6727 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6729 case WM_SYSCOLORCHANGE:
6730 return TOOLBAR_SysColorChange (hwnd);
6732 /* case WM_WININICHANGE: */
6737 case WM_MEASUREITEM:
6739 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6741 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6742 case PGM_FORWARDMOUSE:
6743 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6746 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6747 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6748 uMsg, wParam, lParam);
6749 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6756 TOOLBAR_Register (void)
6760 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6761 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6762 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6763 wndClass.cbClsExtra = 0;
6764 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6765 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6766 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6767 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6769 RegisterClassA (&wndClass);
6774 TOOLBAR_Unregister (void)
6776 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6779 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6784 /* Check if the entry already exists */
6785 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6787 /* If this is a new entry we must create it and insert into the array */
6792 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6795 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6796 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6811 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6815 for (i = 0; i < *cies; i++)
6825 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6833 for (i = 0; i < cies; i++)
6835 if (pies[i]->id == id)
6847 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6849 HIMAGELIST himlDef = 0;
6850 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6853 himlDef = pie->himl;
6859 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6861 if (infoPtr->bUnicode)
6862 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6869 nmtba.iItem = nmtb->iItem;
6870 nmtba.pszText = Buffer;
6871 nmtba.cchText = 256;
6872 ZeroMemory(nmtba.pszText, nmtba.cchText);
6874 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6876 int ccht = strlen(nmtba.pszText);
6878 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6879 nmtb->pszText, nmtb->cchText);
6881 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6890 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6891 int iItem, PCUSTOMBUTTON btnInfo)
6896 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6898 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);