4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Differences between MSDN and actual native control operation:
22 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
23 * to the right of the bitmap. Otherwise, this style is
24 * identical to TBSTYLE_FLAT."
25 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
26 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
27 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
28 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
32 * - Button wrapping (under construction).
40 * - TBN_DELETINGBUTTON
47 * - Tooltip support (almost complete).
48 * - Fix TOOLBAR_SetButtonInfo32A/W.
49 * - iString of -1 is undocumented
50 * - Customization dialog:
52 * - Minor buglet in 'available buttons' list:
53 * Buttons are not listed in M$-like order. M$ seems to use a single
54 * internal list to store the button information of both listboxes.
55 * - Drag list support.
58 * - Run tests using Waite Group Windows95 API Bible Volume 2.
59 * The second cdrom contains executables addstr.exe, btncount.exe,
60 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
61 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
62 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
63 * setparnt.exe, setrows.exe, toolwnd.exe.
64 * - Microsofts controlspy examples.
65 * - Charles Petzold's 'Programming Windows': gadgets.exe
75 #include "wine/unicode.h"
78 #include "imagelist.h"
80 #include "wine/debug.h"
82 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
109 } IMLENTRY, *PIMLENTRY;
113 DWORD dwStructSize; /* size of TBBUTTON struct */
114 INT nHeight; /* height of the toolbar */
115 INT nWidth; /* width of the toolbar */
122 INT nRows; /* number of button rows */
123 INT nMaxTextRows; /* maximum number of text rows */
124 INT cxMin; /* minimum button width */
125 INT cxMax; /* maximum button width */
126 INT nNumButtons; /* number of buttons */
127 INT nNumBitmaps; /* number of bitmaps */
128 INT nNumStrings; /* number of strings */
130 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
131 BOOL bCaptured; /* mouse captured? */
134 INT nHotItem; /* index of the "hot" item */
135 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
136 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
137 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
138 SIZE szPadding; /* padding values around button */
140 HFONT hFont; /* text font */
141 HIMAGELIST himlInt; /* image list created internally */
142 PIMLENTRY *himlDef; /* default image list array */
143 INT cimlDef; /* default image list array count */
144 PIMLENTRY *himlHot; /* hot image list array */
145 INT cimlHot; /* hot image list array count */
146 PIMLENTRY *himlDis; /* disabled image list array */
147 INT cimlDis; /* disabled image list array count */
148 HWND hwndToolTip; /* handle to tool tip control */
149 HWND hwndNotify; /* handle to the window that gets notifications */
150 HWND hwndSelf; /* my own handle */
151 BOOL bTransparent; /* background transparency flag */
152 BOOL bBtnTranspnt; /* button transparency flag */
153 BOOL bAutoSize; /* auto size deadlock indicator */
154 BOOL bAnchor; /* anchor highlight enabled */
155 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
156 BOOL bDoRedraw; /* Redraw status */
157 DWORD dwExStyle; /* extended toolbar style */
158 DWORD dwDTFlags; /* DrawText flags */
160 COLORREF clrInsertMark; /* insert mark color */
161 COLORREF clrBtnHighlight; /* color for Flat Separator */
162 COLORREF clrBtnShadow; /* color for Flag Separator */
163 RECT rcBound; /* bounding rectangle */
166 TBUTTON_INFO *buttons; /* pointer to button array */
167 LPWSTR *strings; /* pointer to string array */
168 TBITMAP_INFO *bitmaps;
169 } TOOLBAR_INFO, *PTOOLBAR_INFO;
172 /* used by customization dialog */
175 PTOOLBAR_INFO tbInfo;
177 } CUSTDLG_INFO, *PCUSTDLG_INFO;
185 } CUSTOMBUTTON, *PCUSTOMBUTTON;
194 #define SEPARATOR_WIDTH 8
196 #define BOTTOM_BORDER 2
197 #define DDARROW_WIDTH 11
198 #define ARROW_HEIGHT 3
200 /* gap between edge of button and image with TBSTYLE_LIST */
201 #define LIST_IMAGE_OFFSET 3
202 /* gap between bitmap and text (always present) */
203 #define LIST_TEXT_OFFSET 2
204 /* how wide to treat the bitmap if it isn't present */
205 #define LIST_IMAGE_ABSENT_WIDTH 2
207 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
208 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
209 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
211 /* Used to find undocumented extended styles */
212 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
213 TBSTYLE_EX_UNDOC1 | \
214 TBSTYLE_EX_MIXEDBUTTONS | \
215 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
217 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
218 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
219 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
220 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
221 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
223 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
224 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
225 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
226 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
227 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
228 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
231 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
235 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
237 LPWSTR lpText = NULL;
239 /* FIXME: iString == -1 is undocumented */
240 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
241 lpText = (LPWSTR)btnPtr->iString;
242 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
243 lpText = infoPtr->strings[btnPtr->iString];
249 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
251 if (TRACE_ON(toolbar)){
252 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
253 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
254 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
255 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
257 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
258 btn_num, bP->idCommand,
259 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
260 bP->rect.left, bP->rect.top,
261 bP->rect.right, bP->rect.bottom);
267 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
269 if (TRACE_ON(toolbar)) {
273 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
274 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
276 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
277 iP->nNumStrings, dwStyle);
278 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
280 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
281 (iP->bDoRedraw) ? "TRUE" : "FALSE");
282 for(i=0; i<iP->nNumButtons; i++) {
283 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
289 /***********************************************************************
292 * This function validates that the styles set are implemented and
293 * issues FIXME's warning of possible problems. In a perfect world this
294 * function should be null.
297 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
299 if (dwStyle & TBSTYLE_ALTDRAG)
300 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
301 if (dwStyle & TBSTYLE_REGISTERDROP)
302 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
307 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
309 if(!IsWindow(infoPtr->hwndSelf))
310 return 0; /* we have just been destroyed */
312 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
313 nmhdr->hwndFrom = infoPtr->hwndSelf;
316 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
317 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
319 if (infoPtr->bNtfUnicode)
320 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
321 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
323 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
324 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
327 /***********************************************************************
328 * TOOLBAR_GetBitmapIndex
330 * This function returns the bitmap index associated with a button.
331 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
332 * is issued to retrieve the index.
335 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
337 INT ret = btnPtr->iBitmap;
339 if (ret == I_IMAGECALLBACK) {
340 /* issue TBN_GETDISPINFO */
343 nmgd.idCommand = btnPtr->idCommand;
344 nmgd.lParam = btnPtr->dwData;
345 nmgd.dwMask = TBNF_IMAGE;
346 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
347 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
349 if (nmgd.dwMask & TBNF_DI_SETITEM) {
350 btnPtr->iBitmap = nmgd.iImage;
353 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
354 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
357 if (ret != I_IMAGENONE)
358 ret = GETIBITMAP(infoPtr, ret);
365 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
368 INT id = GETHIMLID(infoPtr, index);
369 INT iBitmap = GETIBITMAP(infoPtr, index);
371 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
372 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
373 (index == I_IMAGECALLBACK))
380 /***********************************************************************
381 * TOOLBAR_GetImageListForDrawing
383 * This function validates the bitmap index (including I_IMAGECALLBACK
384 * functionality) and returns the corresponding image list.
387 TOOLBAR_GetImageListForDrawing (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist, INT * index)
391 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
392 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
393 ERR("index %d,%d is not valid, max %d\n",
394 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
398 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
399 if ((*index == I_IMAGECALLBACK) ||
400 (*index == I_IMAGENONE)) return NULL;
401 ERR("TBN_GETDISPINFO returned invalid index %d\n",
408 case IMAGE_LIST_DEFAULT:
409 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
412 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
414 case IMAGE_LIST_DISABLED:
415 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
419 FIXME("Shouldn't reach here\n");
423 TRACE("no image list\n");
429 /***********************************************************************
430 * TOOLBAR_TestImageExist
432 * This function is similar to TOOLBAR_GetImageListForDrawing, except it does not
433 * return the image list. The I_IMAGECALLBACK functionality is implemented.
436 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
440 if (!himl) return FALSE;
442 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
443 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
444 ERR("index %d is not valid, max %d\n",
445 btnPtr->iBitmap, infoPtr->nNumBitmaps);
449 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
450 if ((index == I_IMAGECALLBACK) ||
451 (index == I_IMAGENONE)) return FALSE;
452 ERR("TBN_GETDISPINFO returned invalid index %d\n",
461 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
464 COLORREF oldcolor, newcolor;
466 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
467 myrect.right = myrect.left + 1;
468 myrect.top = lpRect->top + 2;
469 myrect.bottom = lpRect->bottom - 2;
471 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
472 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
473 oldcolor = SetBkColor (hdc, newcolor);
474 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
476 myrect.left = myrect.right;
477 myrect.right = myrect.left + 1;
479 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
480 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
481 SetBkColor (hdc, newcolor);
482 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
484 SetBkColor (hdc, oldcolor);
488 /***********************************************************************
489 * TOOLBAR_DrawDDFlatSeparator
491 * This function draws the separator that was flagged as BTNS_DROPDOWN.
492 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
493 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
494 * are horizontal as opposed to the vertical separators for not dropdown
497 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
500 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
503 COLORREF oldcolor, newcolor;
505 myrect.left = lpRect->left;
506 myrect.right = lpRect->right;
507 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
508 myrect.bottom = myrect.top + 1;
510 InflateRect (&myrect, -2, 0);
512 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
513 myrect.left, myrect.top, myrect.right, myrect.bottom);
515 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
516 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
517 oldcolor = SetBkColor (hdc, newcolor);
518 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
520 myrect.top = myrect.bottom;
521 myrect.bottom = myrect.top + 1;
523 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
524 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
525 SetBkColor (hdc, newcolor);
526 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
528 SetBkColor (hdc, oldcolor);
533 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
538 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
539 hOldPen = SelectObject ( hdc, hPen );
542 MoveToEx (hdc, x, y, NULL);
543 LineTo (hdc, x+5, y++); x++;
544 MoveToEx (hdc, x, y, NULL);
545 LineTo (hdc, x+3, y++); x++;
546 MoveToEx (hdc, x, y, NULL);
547 LineTo (hdc, x+1, y++);
548 SelectObject( hdc, hOldPen );
549 DeleteObject( hPen );
553 * Draw the text string for this button.
554 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
555 * is non-zero, so we can simply check himlDef to see if we have
559 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
560 NMTBCUSTOMDRAW *tbcd)
562 HDC hdc = tbcd->nmcd.hdc;
565 COLORREF clrOldBk = 0;
566 UINT state = tbcd->nmcd.uItemState;
570 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
571 rcText->left, rcText->top, rcText->right, rcText->bottom);
573 hOldFont = SelectObject (hdc, infoPtr->hFont);
574 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
575 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
577 else if (state & CDIS_DISABLED) {
578 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
579 OffsetRect (rcText, 1, 1);
580 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
581 SetTextColor (hdc, comctl32_color.clr3dShadow);
582 OffsetRect (rcText, -1, -1);
584 else if (state & CDIS_INDETERMINATE) {
585 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
587 else if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK)) {
588 clrOld = SetTextColor (hdc, tbcd->clrText);
589 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
592 clrOld = SetTextColor (hdc, tbcd->clrText);
595 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
596 SetTextColor (hdc, clrOld);
597 if ((state & CDIS_MARKED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOMARK))
598 SetBkColor (hdc, clrOldBk);
599 SelectObject (hdc, hOldFont);
605 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
607 HDC hdc = tbcd->nmcd.hdc;
608 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
611 INT cx = lpRect->right - lpRect->left;
612 INT cy = lpRect->bottom - lpRect->top;
613 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
614 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
615 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
616 SetBkColor(hdc, clrBkOld);
617 SetTextColor(hdc, clrTextOld);
618 SelectObject (hdc, hbr);
622 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
623 HDC hdc, INT x, INT y)
625 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0);
630 HBITMAP hbmMask, hbmImage;
631 HDC hdcMask, hdcImage;
633 ImageList_GetIconSize(himl, &cx, &cy);
635 /* Create src image */
636 hdcImage = CreateCompatibleDC(hdc);
637 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
638 GetDeviceCaps(hdc,BITSPIXEL), NULL);
639 SelectObject(hdcImage, hbmImage);
640 ImageList_DrawEx(himl, btnPtr->iBitmap, hdcImage, 0, 0, cx, cy,
641 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
644 hdcMask = CreateCompatibleDC(0);
645 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
646 SelectObject(hdcMask, hbmMask);
648 /* Remove the background and all white pixels */
649 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
650 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
651 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
652 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
654 /* draw the new mask 'etched' to hdc */
655 SetBkColor(hdc, RGB(255, 255, 255));
656 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
657 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
658 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
659 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
662 DeleteObject(hbmImage);
664 DeleteObject (hbmMask);
671 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
675 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
676 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
677 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
678 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
679 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
680 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
681 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
682 /* don't test TBSTATE_HIDDEN */
686 /* draws the image on a toolbar button */
688 TOOLBAR_DrawImage(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top, const NMTBCUSTOMDRAW *tbcd)
690 HIMAGELIST himl = NULL;
691 BOOL draw_masked = FALSE;
694 UINT draw_flags = ILD_NORMAL;
696 if (tbcd->nmcd.uItemState & CDIS_DISABLED)
698 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
702 else if (tbcd->nmcd.uItemState & CDIS_INDETERMINATE)
704 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & TBSTYLE_FLAT))
706 /* if hot, attempt to draw with hot image list, if fails,
707 use default image list */
708 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
713 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
715 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) &&
716 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
719 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOMARK) &&
720 (tbcd->nmcd.uItemState & CDIS_MARKED))
721 draw_flags |= ILD_BLEND50;
723 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
724 index, himl, left, top, offset);
727 TOOLBAR_DrawMasked (infoPtr, btnPtr, tbcd->nmcd.hdc, left + offset, top + offset);
729 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
732 /* draws a blank frame for a toolbar button */
734 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd)
736 HDC hdc = tbcd->nmcd.hdc;
737 RECT rc = tbcd->nmcd.rc;
738 /* if the state is disabled or indeterminate then the button
739 * cannot have an interactive look like pressed or hot */
740 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
741 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
742 BOOL pressed_look = !non_interactive_state &&
743 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
744 (tbcd->nmcd.uItemState & CDIS_CHECKED));
746 /* app don't want us to draw any edges */
747 if (infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)
753 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
754 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
755 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
760 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE);
768 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, BOOL flat, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow)
770 HDC hdc = tbcd->nmcd.hdc;
775 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
776 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
777 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
778 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
779 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
780 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
784 if ((tbcd->nmcd.uItemState & CDIS_SELECTED) || (tbcd->nmcd.uItemState & CDIS_CHECKED))
785 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
787 DrawEdge (hdc, rcArrow, EDGE_RAISED,
788 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
791 if (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
792 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
794 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
796 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
797 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
800 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
803 /* draws a complete toolbar button */
805 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
807 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
808 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
809 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
810 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
811 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
812 BOOL drawSepDropDownArrow = hasDropDownArrow &&
813 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
814 RECT rc, rcArrow, rcBitmap, rcText;
815 LPWSTR lpText = NULL;
821 CopyRect (&rcArrow, &rc);
822 CopyRect(&rcBitmap, &rc);
824 /* get a pointer to the text */
825 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
827 if (hasDropDownArrow)
831 if (dwStyle & TBSTYLE_FLAT)
832 right = max(rc.left, rc.right - DDARROW_WIDTH);
834 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
836 if (drawSepDropDownArrow)
839 rcArrow.left = right;
842 /* copy text rect after adjusting for drop-down arrow
843 * so that text is centred in the rectangle not containing
845 CopyRect(&rcText, &rc);
847 /* Center the bitmap horizontally and vertically */
848 if (dwStyle & TBSTYLE_LIST)
849 rcBitmap.left += LIST_IMAGE_OFFSET;
851 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
854 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
856 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
858 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
859 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
860 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
861 TRACE ("iString: %x\n", btnPtr->iString);
862 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
867 InflateRect (&rcText, -3, -3);
869 if (GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,btnPtr->iBitmap)) &&
870 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
872 if (dwStyle & TBSTYLE_LIST)
873 rcText.left += (infoPtr->nBitmapWidth + LIST_TEXT_OFFSET);
875 rcText.top += infoPtr->nBitmapHeight + 1;
878 if (dwStyle & TBSTYLE_LIST)
879 rcText.left += LIST_IMAGE_ABSENT_WIDTH + LIST_TEXT_OFFSET;
881 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
882 OffsetRect (&rcText, 1, 1);
885 /* Initialize fields in all cases, because we use these later
886 * NOTE: applications can and do alter these to customize their
888 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
889 tbcd.clrText = comctl32_color.clrBtnText;
890 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
891 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
892 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
893 tbcd.clrMark = comctl32_color.clrHighlight;
894 tbcd.clrHighlightHotTrack = 0;
895 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
896 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
897 /* MSDN says that this is the text rectangle.
898 * But (why always a but) tracing of v5.7 of native shows
899 * that this is really a *relative* rectangle based on the
900 * the nmcd.rc. Also the left and top are always 0 ignoring
901 * any bitmap that might be present. */
902 tbcd.rcText.left = 0;
904 tbcd.rcText.right = rcText.right - rc.left;
905 tbcd.rcText.bottom = rcText.bottom - rc.top;
906 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
909 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
911 /* FIXME: what are these used for? */
915 /* Issue Item Prepaint notify */
916 infoPtr->dwItemCustDraw = 0;
917 infoPtr->dwItemCDFlag = 0;
918 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
920 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
921 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
922 tbcd.nmcd.lItemlParam = btnPtr->dwData;
923 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
924 /* reset these fields so the user can't alter the behaviour like native */
928 infoPtr->dwItemCustDraw = ntfret & 0xffff;
929 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
930 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
932 /* save the only part of the rect that the user can change */
933 rcText.right = tbcd.rcText.right + rc.left;
934 rcText.bottom = tbcd.rcText.bottom + rc.top;
938 if (btnPtr->fsStyle & BTNS_SEP) {
939 /* with the FLAT style, iBitmap is the width and has already */
940 /* been taken into consideration in calculating the width */
941 /* so now we need to draw the vertical separator */
942 /* empirical tests show that iBitmap can/will be non-zero */
943 /* when drawing the vertical bar... */
944 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
945 if (btnPtr->fsStyle & BTNS_DROPDOWN)
946 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
948 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
950 else if (btnPtr->fsStyle != BTNS_SEP) {
951 FIXME("Draw some kind of separator: fsStyle=%x\n",
957 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
958 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
959 TOOLBAR_DrawPattern (&rc, &tbcd);
961 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
963 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
967 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
968 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
969 if (hasDropDownArrow)
970 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
971 SetBkColor(hdc, oldclr);
975 TOOLBAR_DrawFrame(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd);
977 if (drawSepDropDownArrow)
978 TOOLBAR_DrawSepDDArrow(infoPtr, dwStyle & TBSTYLE_FLAT, &tbcd, &rcArrow);
980 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
981 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
983 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd);
985 if (hasDropDownArrow && !drawSepDropDownArrow)
987 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
989 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
990 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
992 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
994 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
995 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
998 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1002 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1004 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1005 tbcd.nmcd.hdc = hdc;
1007 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1008 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1009 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1010 tbcd.rcText = rcText;
1011 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1012 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1013 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1020 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1022 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1023 TBUTTON_INFO *btnPtr;
1024 INT i, oldBKmode = 0;
1025 RECT rcTemp, rcClient;
1026 NMTBCUSTOMDRAW tbcd;
1029 /* if imagelist belongs to the app, it can be changed
1030 by the app after setting it */
1031 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1033 infoPtr->nNumBitmaps = 0;
1034 for (i = 0; i < infoPtr->cimlDef; i++)
1035 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1038 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1040 /* Send initial notify */
1041 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1042 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1043 tbcd.nmcd.hdc = hdc;
1044 tbcd.nmcd.rc = ps->rcPaint;
1045 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1046 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1048 if (infoPtr->bBtnTranspnt)
1049 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1051 GetClientRect(hwnd, &rcClient);
1053 /* redraw necessary buttons */
1054 btnPtr = infoPtr->buttons;
1055 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1058 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1060 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1061 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1065 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1066 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1068 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1071 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1072 SetBkMode (hdc, oldBKmode);
1074 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1076 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1077 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1078 tbcd.nmcd.hdc = hdc;
1079 tbcd.nmcd.rc = ps->rcPaint;
1080 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1084 /***********************************************************************
1085 * TOOLBAR_MeasureString
1087 * This function gets the width and height of a string in pixels. This
1088 * is done first by using GetTextExtentPoint to get the basic width
1089 * and height. The DrawText is called with DT_CALCRECT to get the exact
1090 * width. The reason is because the text may have more than one "&" (or
1091 * prefix characters as M$ likes to call them). The prefix character
1092 * indicates where the underline goes, except for the string "&&" which
1093 * is reduced to a single "&". GetTextExtentPoint does not process these
1094 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1097 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1098 HDC hdc, LPSIZE lpSize)
1105 if (infoPtr->nMaxTextRows > 0 &&
1106 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1107 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1108 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1110 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1112 if(lpText != NULL) {
1113 /* first get size of all the text */
1114 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1116 /* feed above size into the rectangle for DrawText */
1117 myrect.left = myrect.top = 0;
1118 myrect.right = lpSize->cx;
1119 myrect.bottom = lpSize->cy;
1121 /* Use DrawText to get true size as drawn (less pesky "&") */
1122 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1123 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1126 /* feed back to caller */
1127 lpSize->cx = myrect.right;
1128 lpSize->cy = myrect.bottom;
1132 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1135 /***********************************************************************
1136 * TOOLBAR_CalcStrings
1138 * This function walks through each string and measures it and returns
1139 * the largest height and width to caller.
1142 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1144 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1145 TBUTTON_INFO *btnPtr;
1154 if(infoPtr->nMaxTextRows == 0)
1158 hOldFont = SelectObject (hdc, infoPtr->hFont);
1160 btnPtr = infoPtr->buttons;
1161 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1162 if(TOOLBAR_HasText(infoPtr, btnPtr))
1164 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1165 if (sz.cx > lpSize->cx)
1167 if (sz.cy > lpSize->cy)
1172 SelectObject (hdc, hOldFont);
1173 ReleaseDC (hwnd, hdc);
1175 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1178 /***********************************************************************
1179 * TOOLBAR_WrapToolbar
1181 * This function walks through the buttons and separators in the
1182 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1183 * wrapping should occur based on the width of the toolbar window.
1184 * It does *not* calculate button placement itself. That task
1185 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1186 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1187 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1189 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1190 * vertical toolbar lists.
1194 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1197 TBUTTON_INFO *btnPtr;
1200 BOOL bWrap, bButtonWrap;
1202 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1203 /* no layout is necessary. Applications may use this style */
1204 /* to perform their own layout on the toolbar. */
1205 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1206 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1208 btnPtr = infoPtr->buttons;
1209 x = infoPtr->nIndent;
1211 /* this can get the parents width, to know how far we can extend
1212 * this toolbar. We cannot use its height, as there may be multiple
1213 * toolbars in a rebar control
1215 GetClientRect( GetParent(hwnd), &rc );
1216 infoPtr->nWidth = rc.right - rc.left;
1217 bButtonWrap = FALSE;
1219 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1220 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1223 for (i = 0; i < infoPtr->nNumButtons; i++ )
1226 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1228 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1231 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1232 /* it is the actual width of the separator. This is used for */
1233 /* custom controls in toolbars. */
1235 /* BTNS_DROPDOWN separators are treated as buttons for */
1236 /* width. - GA 8/01 */
1237 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1238 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1239 cx = (btnPtr[i].iBitmap > 0) ?
1240 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1242 cx = infoPtr->nButtonWidth;
1244 /* Two or more adjacent separators form a separator group. */
1245 /* The first separator in a group should be wrapped to the */
1246 /* next row if the previous wrapping is on a button. */
1248 (btnPtr[i].fsStyle & BTNS_SEP) &&
1249 (i + 1 < infoPtr->nNumButtons ) &&
1250 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1252 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1253 btnPtr[i].fsState |= TBSTATE_WRAP;
1254 x = infoPtr->nIndent;
1256 bButtonWrap = FALSE;
1260 /* The layout makes sure the bitmap is visible, but not the button. */
1261 /* Test added to also wrap after a button that starts a row but */
1262 /* is bigger than the area. - GA 8/01 */
1263 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1264 > infoPtr->nWidth ) ||
1265 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1267 BOOL bFound = FALSE;
1269 /* If the current button is a separator and not hidden, */
1270 /* go to the next until it reaches a non separator. */
1271 /* Wrap the last separator if it is before a button. */
1272 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1273 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1274 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1275 i < infoPtr->nNumButtons )
1281 if( bFound && i < infoPtr->nNumButtons )
1284 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1285 i, btnPtr[i].fsStyle, x, cx);
1286 btnPtr[i].fsState |= TBSTATE_WRAP;
1287 x = infoPtr->nIndent;
1288 bButtonWrap = FALSE;
1291 else if ( i >= infoPtr->nNumButtons)
1294 /* If the current button is not a separator, find the last */
1295 /* separator and wrap it. */
1296 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1298 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1299 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1303 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1304 i, btnPtr[i].fsStyle, x, cx);
1305 x = infoPtr->nIndent;
1306 btnPtr[j].fsState |= TBSTATE_WRAP;
1307 bButtonWrap = FALSE;
1312 /* If no separator available for wrapping, wrap one of */
1313 /* non-hidden previous button. */
1317 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1319 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1324 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1325 i, btnPtr[i].fsStyle, x, cx);
1326 x = infoPtr->nIndent;
1327 btnPtr[j].fsState |= TBSTATE_WRAP;
1333 /* If all above failed, wrap the current button. */
1336 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1337 i, btnPtr[i].fsStyle, x, cx);
1338 btnPtr[i].fsState |= TBSTATE_WRAP;
1340 x = infoPtr->nIndent;
1341 if (btnPtr[i].fsStyle & BTNS_SEP )
1342 bButtonWrap = FALSE;
1348 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1349 i, btnPtr[i].fsStyle, x, cx);
1356 /***********************************************************************
1357 * TOOLBAR_CalcToolbar
1359 * This function calculates button and separator placement. It first
1360 * calculates the button sizes, gets the toolbar window width and then
1361 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1362 * on. It assigns a new location to each item and sends this location to
1363 * the tooltip window if appropriate. Finally, it updates the rcBound
1364 * rect and calculates the new required toolbar window height.
1368 TOOLBAR_CalcToolbar (HWND hwnd)
1370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1371 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1372 TBUTTON_INFO *btnPtr;
1373 INT i, nRows, nSepRows;
1377 BOOL usesBitmaps = FALSE;
1378 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1380 TOOLBAR_CalcStrings (hwnd, &sizeString);
1382 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1384 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1387 if (dwStyle & TBSTYLE_LIST)
1389 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1390 0, sizeString.cy) + infoPtr->szPadding.cy;
1391 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1392 0) + sizeString.cx + 6;
1393 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1394 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1395 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1396 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1399 if (sizeString.cy > 0)
1402 infoPtr->nButtonHeight = sizeString.cy +
1403 2 + /* this is the space to separate text from bitmap */
1404 infoPtr->nBitmapHeight + 6;
1406 infoPtr->nButtonHeight = sizeString.cy + 6;
1409 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1411 if (sizeString.cx > infoPtr->nBitmapWidth)
1412 infoPtr->nButtonWidth = sizeString.cx + 6;
1414 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1417 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1418 infoPtr->nButtonWidth = infoPtr->cxMin;
1419 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1420 infoPtr->nButtonWidth = infoPtr->cxMax;
1422 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1424 x = infoPtr->nIndent;
1428 * We will set the height below, and we set the width on entry
1429 * so we do not reset them here..
1432 GetClientRect( hwnd, &rc );
1433 /* get initial values for toolbar */
1434 infoPtr->nWidth = rc.right - rc.left;
1435 infoPtr->nHeight = rc.bottom - rc.top;
1438 /* from above, minimum is a button, and possible text */
1439 cx = infoPtr->nButtonWidth;
1441 /* cannot use just ButtonHeight, we may have no buttons! */
1442 if (infoPtr->nNumButtons > 0)
1443 infoPtr->nHeight = infoPtr->nButtonHeight;
1445 cy = infoPtr->nHeight;
1447 nRows = nSepRows = 0;
1449 infoPtr->rcBound.top = y;
1450 infoPtr->rcBound.left = x;
1451 infoPtr->rcBound.bottom = y + cy;
1452 infoPtr->rcBound.right = x;
1454 btnPtr = infoPtr->buttons;
1456 /* do not base height/width on parent, if the parent is a */
1457 /* rebar control it could have multiple rows of toolbars */
1458 /* GetClientRect( GetParent(hwnd), &rc ); */
1459 /* cx = rc.right - rc.left; */
1460 /* cy = rc.bottom - rc.top; */
1462 TRACE("cy=%d\n", cy);
1464 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1467 if (btnPtr->fsState & TBSTATE_HIDDEN)
1469 SetRectEmpty (&btnPtr->rect);
1473 cy = infoPtr->nHeight;
1475 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1476 /* it is the actual width of the separator. This is used for */
1477 /* custom controls in toolbars. */
1478 if (btnPtr->fsStyle & BTNS_SEP) {
1479 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1480 cy = (btnPtr->iBitmap > 0) ?
1481 btnPtr->iBitmap : SEPARATOR_WIDTH;
1482 cx = infoPtr->nButtonWidth;
1485 cx = (btnPtr->iBitmap > 0) ?
1486 btnPtr->iBitmap : SEPARATOR_WIDTH;
1490 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1491 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1498 hOldFont = SelectObject (hdc, infoPtr->hFont);
1500 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1502 SelectObject (hdc, hOldFont);
1503 ReleaseDC (hwnd, hdc);
1506 sz.cx += 2*LIST_TEXT_OFFSET;
1507 cx = sz.cx + 2*LIST_IMAGE_OFFSET;
1508 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1510 if (dwStyle & TBSTYLE_LIST)
1511 cx += infoPtr->nBitmapWidth;
1512 else if (cx < (infoPtr->nBitmapWidth+7))
1513 cx = infoPtr->nBitmapWidth+7;
1515 else if (dwStyle & TBSTYLE_LIST)
1516 cx += LIST_IMAGE_ABSENT_WIDTH;
1519 cx = infoPtr->nButtonWidth;
1521 if ((hasDropDownArrows && (btnPtr->fsStyle & BTNS_DROPDOWN)) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN))
1522 cx += DDARROW_WIDTH;
1524 if (btnPtr->fsState & TBSTATE_WRAP )
1527 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1529 if (infoPtr->rcBound.left > x)
1530 infoPtr->rcBound.left = x;
1531 if (infoPtr->rcBound.right < x + cx)
1532 infoPtr->rcBound.right = x + cx;
1533 if (infoPtr->rcBound.bottom < y + cy)
1534 infoPtr->rcBound.bottom = y + cy;
1536 /* Set the toolTip only for non-hidden, non-separator button */
1537 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1541 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1542 ti.cbSize = sizeof(TTTOOLINFOA);
1544 ti.uId = btnPtr->idCommand;
1545 ti.rect = btnPtr->rect;
1546 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1550 /* btnPtr->nRow is zero based. The space between the rows is */
1551 /* also considered as a row. */
1552 btnPtr->nRow = nRows + nSepRows;
1554 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1555 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1560 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1564 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1565 /* it is the actual width of the separator. This is used for */
1566 /* custom controls in toolbars. */
1567 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1568 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1569 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1573 /* nSepRows is used to calculate the extra height follwoing */
1577 x = infoPtr->nIndent;
1579 /* Increment row number unless this is the last button */
1580 /* and it has Wrap set. */
1581 if (i != infoPtr->nNumButtons-1)
1588 /* infoPtr->nRows is the number of rows on the toolbar */
1589 infoPtr->nRows = nRows + nSepRows + 1;
1592 /********************************************************************
1593 * The following while interesting, does not match the values *
1594 * created above for the button rectangles, nor the rcBound rect. *
1595 * We will comment it out and remove it later. *
1597 * The problem showed up as heights in the pager control that was *
1599 ********************************************************************/
1601 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1603 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1604 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1605 nSepRows * (infoPtr->nBitmapHeight + 1) +
1609 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1611 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1616 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1619 TBUTTON_INFO *btnPtr;
1622 btnPtr = infoPtr->buttons;
1623 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1624 if (btnPtr->fsState & TBSTATE_HIDDEN)
1627 if (btnPtr->fsStyle & BTNS_SEP) {
1628 if (PtInRect (&btnPtr->rect, *lpPt)) {
1629 TRACE(" ON SEPARATOR %d!\n", i);
1634 if (PtInRect (&btnPtr->rect, *lpPt)) {
1635 TRACE(" ON BUTTON %d!\n", i);
1641 TRACE(" NOWHERE!\n");
1647 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1649 TBUTTON_INFO *btnPtr;
1652 if (CommandIsIndex) {
1653 TRACE("command is really index command=%d\n", idCommand);
1654 if (idCommand >= infoPtr->nNumButtons) return -1;
1657 btnPtr = infoPtr->buttons;
1658 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1659 if (btnPtr->idCommand == idCommand) {
1660 TRACE("command=%d index=%d\n", idCommand, i);
1664 TRACE("no index found for command=%d\n", idCommand);
1670 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1672 TBUTTON_INFO *btnPtr;
1675 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1678 /* check index button */
1679 btnPtr = &infoPtr->buttons[nIndex];
1680 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1681 if (btnPtr->fsState & TBSTATE_CHECKED)
1685 /* check previous buttons */
1686 nRunIndex = nIndex - 1;
1687 while (nRunIndex >= 0) {
1688 btnPtr = &infoPtr->buttons[nRunIndex];
1689 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1690 if (btnPtr->fsState & TBSTATE_CHECKED)
1698 /* check next buttons */
1699 nRunIndex = nIndex + 1;
1700 while (nRunIndex < infoPtr->nNumButtons) {
1701 btnPtr = &infoPtr->buttons[nRunIndex];
1702 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1703 if (btnPtr->fsState & TBSTATE_CHECKED)
1716 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1717 WPARAM wParam, LPARAM lParam)
1723 msg.wParam = wParam;
1724 msg.lParam = lParam;
1725 msg.time = GetMessageTime ();
1726 msg.pt.x = LOWORD(GetMessagePos ());
1727 msg.pt.y = HIWORD(GetMessagePos ());
1729 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1733 /***********************************************************************
1734 * TOOLBAR_CustomizeDialogProc
1735 * This function implements the toolbar customization dialog.
1737 static INT_PTR CALLBACK
1738 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1740 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1741 PCUSTOMBUTTON btnInfo;
1743 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1748 custInfo = (PCUSTDLG_INFO)lParam;
1749 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1757 infoPtr = custInfo->tbInfo;
1759 /* send TBN_QUERYINSERT notification */
1760 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1762 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1765 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1766 nmtb.iItem = (int)hwnd;
1767 /* Send TBN_INITCUSTOMIZE notification */
1768 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1771 TRACE("TBNRF_HIDEHELP requested\n");
1772 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1775 /* add items to 'toolbar buttons' list and check if removable */
1776 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1778 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1779 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1780 btnInfo->btn.fsStyle = BTNS_SEP;
1781 btnInfo->bVirtual = FALSE;
1782 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1784 /* send TBN_QUERYDELETE notification */
1785 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1787 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1788 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1791 /* insert separator button into 'available buttons' list */
1792 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1793 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1794 btnInfo->btn.fsStyle = BTNS_SEP;
1795 btnInfo->bVirtual = FALSE;
1796 btnInfo->bRemovable = TRUE;
1797 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1798 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1799 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1801 /* insert all buttons into dsa */
1804 /* send TBN_GETBUTTONINFO notification */
1807 nmtb.pszText = Buffer;
1810 /* Clear previous button's text */
1811 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1813 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1816 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1817 nmtb.tbButton.fsStyle, i,
1818 nmtb.tbButton.idCommand,
1819 nmtb.tbButton.iString,
1820 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1823 /* insert button into the apropriate list */
1824 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1827 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1828 btnInfo->bVirtual = FALSE;
1829 btnInfo->bRemovable = TRUE;
1831 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1832 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1833 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1837 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1838 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1841 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1842 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1844 if (lstrlenW(nmtb.pszText))
1845 lstrcpyW(btnInfo->text, nmtb.pszText);
1846 else if (nmtb.tbButton.iString >= 0 &&
1847 nmtb.tbButton.iString < infoPtr->nNumStrings)
1849 lstrcpyW(btnInfo->text,
1850 infoPtr->strings[nmtb.tbButton.iString]);
1855 /* select first item in the 'available' list */
1856 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1858 /* append 'virtual' separator button to the 'toolbar buttons' list */
1859 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1860 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1861 btnInfo->btn.fsStyle = BTNS_SEP;
1862 btnInfo->bVirtual = TRUE;
1863 btnInfo->bRemovable = FALSE;
1864 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1865 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1866 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1868 /* select last item in the 'toolbar' list */
1869 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1870 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1872 /* set focus and disable buttons */
1873 PostMessageA (hwnd, WM_USER, 0, 0);
1878 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1879 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1880 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1881 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1885 EndDialog(hwnd, FALSE);
1889 switch (LOWORD(wParam))
1891 case IDC_TOOLBARBTN_LBOX:
1892 if (HIWORD(wParam) == LBN_SELCHANGE)
1894 PCUSTOMBUTTON btnInfo;
1899 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1900 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1902 /* send TBN_QUERYINSERT notification */
1904 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1907 /* get list box item */
1908 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1910 if (index == (count - 1))
1912 /* last item (virtual separator) */
1913 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1914 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1916 else if (index == (count - 2))
1918 /* second last item (last non-virtual item) */
1919 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1920 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1922 else if (index == 0)
1925 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1926 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1930 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1931 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1934 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1938 case IDC_MOVEUP_BTN:
1940 PCUSTOMBUTTON btnInfo;
1944 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1945 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1946 TRACE("Move up: index %d\n", index);
1948 /* send TBN_QUERYINSERT notification */
1951 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1954 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1956 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1957 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1958 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1959 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1962 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1963 else if (index >= (count - 3))
1964 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1966 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1967 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1972 case IDC_MOVEDN_BTN: /* move down */
1974 PCUSTOMBUTTON btnInfo;
1978 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1979 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1980 TRACE("Move up: index %d\n", index);
1982 /* send TBN_QUERYINSERT notification */
1984 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1987 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1989 /* move button down */
1990 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1991 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1992 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1993 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1996 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1997 else if (index >= (count - 3))
1998 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2000 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2001 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2006 case IDC_REMOVE_BTN: /* remove button */
2008 PCUSTOMBUTTON btnInfo;
2011 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2013 if (LB_ERR == index)
2016 TRACE("Remove: index %d\n", index);
2018 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2019 LB_GETITEMDATA, index, 0);
2021 /* send TBN_QUERYDELETE notification */
2022 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2024 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2025 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2026 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2028 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2030 /* insert into 'available button' list */
2031 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2033 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2034 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2042 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2045 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2048 case IDOK: /* Add button */
2053 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2054 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2055 TRACE("Add: index %d\n", index);
2057 /* send TBN_QUERYINSERT notification */
2059 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2062 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2066 /* remove from 'available buttons' list */
2067 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2068 if (index == count-1)
2069 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2071 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2075 PCUSTOMBUTTON btnNew;
2077 /* duplicate 'separator' button */
2078 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2079 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2083 /* insert into 'toolbar button' list */
2084 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2085 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2086 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2088 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2094 EndDialog(hwnd, FALSE);
2104 /* delete items from 'toolbar buttons' listbox*/
2105 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2106 for (i = 0; i < count; i++)
2108 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2110 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2112 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2115 /* delete items from 'available buttons' listbox*/
2116 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2117 for (i = 0; i < count; i++)
2119 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2121 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2123 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2128 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2130 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2131 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2136 COLORREF oldText = 0;
2140 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2141 if (btnInfo == NULL)
2143 FIXME("btnInfo invalid!\n");
2147 /* set colors and select objects */
2148 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2149 if (btnInfo->bVirtual)
2150 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2152 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2153 hPen = CreatePen( PS_SOLID, 1,
2154 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2155 hOldPen = SelectObject (lpdis->hDC, hPen );
2156 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2158 /* fill background rectangle */
2159 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2160 lpdis->rcItem.right, lpdis->rcItem.bottom);
2162 /* calculate button and text rectangles */
2163 CopyRect (&rcButton, &lpdis->rcItem);
2164 InflateRect (&rcButton, -1, -1);
2165 CopyRect (&rcText, &rcButton);
2166 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2167 rcText.left = rcButton.right + 2;
2169 /* draw focus rectangle */
2170 if (lpdis->itemState & ODS_FOCUS)
2171 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2174 if (!(dwStyle & TBSTYLE_FLAT))
2175 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2177 /* draw image and text */
2178 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2179 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2180 btnInfo->btn.iBitmap));
2181 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2182 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2184 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2185 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2187 /* delete objects and reset colors */
2188 SelectObject (lpdis->hDC, hOldBrush);
2189 SelectObject (lpdis->hDC, hOldPen);
2190 SetBkColor (lpdis->hDC, oldBk);
2191 SetTextColor (lpdis->hDC, oldText);
2192 DeleteObject( hPen );
2197 case WM_MEASUREITEM:
2198 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2200 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2202 if (custInfo && custInfo->tbInfo)
2203 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2205 lpmis->itemHeight = 15 + 8; /* default height */
2217 /***********************************************************************
2218 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2222 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2225 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2226 INT nIndex = 0, nButtons, nCount;
2230 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2234 if (lpAddBmp->hInst == HINST_COMMCTRL)
2236 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2238 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2240 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2245 TRACE ("adding %d internal bitmaps!\n", nButtons);
2247 /* Windows resize all the buttons to the size of a newly added standard image */
2248 if (lpAddBmp->nID & 1)
2251 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2252 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2254 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2255 MAKELPARAM((WORD)24, (WORD)24));
2256 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2257 MAKELPARAM((WORD)31, (WORD)30));
2262 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2263 MAKELPARAM((WORD)16, (WORD)16));
2264 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2265 MAKELPARAM((WORD)22, (WORD)22));
2268 TOOLBAR_CalcToolbar (hwnd);
2272 nButtons = (INT)wParam;
2276 TRACE ("adding %d bitmaps!\n", nButtons);
2279 if (!infoPtr->cimlDef) {
2280 /* create new default image list */
2281 TRACE ("creating default image list!\n");
2283 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2284 ILC_COLOR | ILC_MASK, nButtons, 2);
2285 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2286 infoPtr->himlInt = himlDef;
2289 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2293 WARN("No default image list available\n");
2297 nCount = ImageList_GetImageCount(himlDef);
2299 /* Add bitmaps to the default image list */
2300 if (lpAddBmp->hInst == NULL)
2303 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2304 HDC hdcImage, hdcBitmap;
2306 /* copy the bitmap before adding it so that the user's bitmap
2307 * doesn't get modified.
2309 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2311 hdcImage = CreateCompatibleDC(0);
2312 hdcBitmap = CreateCompatibleDC(0);
2314 /* create new bitmap */
2315 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2316 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2317 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2319 /* Copy the user's image */
2320 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2321 hdcBitmap, 0, 0, SRCCOPY);
2323 SelectObject (hdcImage, hOldBitmapLoad);
2324 SelectObject (hdcBitmap, hOldBitmapBitmap);
2325 DeleteDC (hdcImage);
2326 DeleteDC (hdcBitmap);
2328 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2329 DeleteObject (hbmLoad);
2331 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2333 /* Add system bitmaps */
2334 switch (lpAddBmp->nID)
2336 case IDB_STD_SMALL_COLOR:
2337 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2338 MAKEINTRESOURCEA(IDB_STD_SMALL));
2339 nIndex = ImageList_AddMasked (himlDef,
2340 hbmLoad, comctl32_color.clrBtnFace);
2341 DeleteObject (hbmLoad);
2344 case IDB_STD_LARGE_COLOR:
2345 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2346 MAKEINTRESOURCEA(IDB_STD_LARGE));
2347 nIndex = ImageList_AddMasked (himlDef,
2348 hbmLoad, comctl32_color.clrBtnFace);
2349 DeleteObject (hbmLoad);
2352 case IDB_VIEW_SMALL_COLOR:
2353 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2354 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2355 nIndex = ImageList_AddMasked (himlDef,
2356 hbmLoad, comctl32_color.clrBtnFace);
2357 DeleteObject (hbmLoad);
2360 case IDB_VIEW_LARGE_COLOR:
2361 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2362 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2363 nIndex = ImageList_AddMasked (himlDef,
2364 hbmLoad, comctl32_color.clrBtnFace);
2365 DeleteObject (hbmLoad);
2368 case IDB_HIST_SMALL_COLOR:
2369 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2370 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2371 nIndex = ImageList_AddMasked (himlDef,
2372 hbmLoad, comctl32_color.clrBtnFace);
2373 DeleteObject (hbmLoad);
2376 case IDB_HIST_LARGE_COLOR:
2377 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2378 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2379 nIndex = ImageList_AddMasked (himlDef,
2380 hbmLoad, comctl32_color.clrBtnFace);
2381 DeleteObject (hbmLoad);
2385 nIndex = ImageList_GetImageCount (himlDef);
2386 ERR ("invalid imagelist!\n");
2392 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2393 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2394 DeleteObject (hbmLoad);
2397 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2399 if (infoPtr->nNumBitmapInfos == 0)
2401 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2405 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2406 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2407 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2410 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2411 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2412 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2414 infoPtr->nNumBitmapInfos++;
2415 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2419 INT imagecount = ImageList_GetImageCount(himlDef);
2421 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2423 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",
2424 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2425 infoPtr->nNumBitmaps+nButtons,imagecount);
2427 infoPtr->nNumBitmaps = imagecount;
2430 infoPtr->nNumBitmaps += nButtons;
2433 InvalidateRect(hwnd, NULL, FALSE);
2440 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2443 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2444 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2446 TRACE("adding %d buttons!\n", wParam);
2448 nAddButtons = (UINT)wParam;
2449 nOldButtons = infoPtr->nNumButtons;
2450 nNewButtons = nOldButtons + nAddButtons;
2452 if (infoPtr->nNumButtons == 0) {
2454 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2457 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2459 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2460 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2461 nOldButtons * sizeof(TBUTTON_INFO));
2465 infoPtr->nNumButtons = nNewButtons;
2467 /* insert new button data */
2468 for (nCount = 0; nCount < nAddButtons; nCount++) {
2469 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2470 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2471 btnPtr->idCommand = lpTbb[nCount].idCommand;
2472 btnPtr->fsState = lpTbb[nCount].fsState;
2473 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2474 btnPtr->dwData = lpTbb[nCount].dwData;
2475 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2476 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2478 btnPtr->iString = lpTbb[nCount].iString;
2479 btnPtr->bHot = FALSE;
2481 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2484 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2485 ti.cbSize = sizeof (TTTOOLINFOA);
2487 ti.uId = btnPtr->idCommand;
2489 ti.lpszText = LPSTR_TEXTCALLBACKA;
2491 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2496 TOOLBAR_CalcToolbar (hwnd);
2498 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2500 InvalidateRect(hwnd, NULL, FALSE);
2507 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2509 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2510 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2511 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2513 TRACE("adding %d buttons!\n", wParam);
2515 nAddButtons = (UINT)wParam;
2516 nOldButtons = infoPtr->nNumButtons;
2517 nNewButtons = nOldButtons + nAddButtons;
2519 if (infoPtr->nNumButtons == 0) {
2521 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2524 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2526 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2527 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2528 nOldButtons * sizeof(TBUTTON_INFO));
2532 infoPtr->nNumButtons = nNewButtons;
2534 /* insert new button data */
2535 for (nCount = 0; nCount < nAddButtons; nCount++) {
2536 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2537 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2538 btnPtr->idCommand = lpTbb[nCount].idCommand;
2539 btnPtr->fsState = lpTbb[nCount].fsState;
2540 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2541 btnPtr->dwData = lpTbb[nCount].dwData;
2542 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2543 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2545 btnPtr->iString = lpTbb[nCount].iString;
2546 btnPtr->bHot = FALSE;
2548 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2551 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2552 ti.cbSize = sizeof (TTTOOLINFOW);
2554 ti.uId = btnPtr->idCommand;
2556 ti.lpszText = LPSTR_TEXTCALLBACKW;
2559 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2564 TOOLBAR_CalcToolbar (hwnd);
2566 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2568 InvalidateRect(hwnd, NULL, FALSE);
2575 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2577 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2580 if ((wParam) && (HIWORD(lParam) == 0)) {
2583 TRACE("adding string from resource!\n");
2585 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2588 TRACE("len=%d \"%s\"\n", len, szString);
2589 nIndex = infoPtr->nNumStrings;
2590 if (infoPtr->nNumStrings == 0) {
2592 Alloc (sizeof(LPWSTR));
2595 LPWSTR *oldStrings = infoPtr->strings;
2597 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2598 memcpy (&infoPtr->strings[0], &oldStrings[0],
2599 sizeof(LPWSTR) * infoPtr->nNumStrings);
2603 /*Alloc zeros out the allocated memory*/
2604 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2605 infoPtr->nNumStrings++;
2608 LPSTR p = (LPSTR)lParam;
2613 TRACE("adding string(s) from array!\n");
2615 nIndex = infoPtr->nNumStrings;
2618 TRACE("len=%d \"%s\"\n", len, p);
2620 if (infoPtr->nNumStrings == 0) {
2622 Alloc (sizeof(LPWSTR));
2625 LPWSTR *oldStrings = infoPtr->strings;
2627 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2628 memcpy (&infoPtr->strings[0], &oldStrings[0],
2629 sizeof(LPWSTR) * infoPtr->nNumStrings);
2633 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2634 infoPtr->nNumStrings++;
2645 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2647 #define MAX_RESOURCE_STRING_LENGTH 512
2648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2651 if ((wParam) && (HIWORD(lParam) == 0)) {
2652 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2654 TRACE("adding string from resource!\n");
2656 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2657 szString, MAX_RESOURCE_STRING_LENGTH);
2659 TRACE("len=%d %s\n", len, debugstr_w(szString));
2660 TRACE("First char: 0x%x\n", *szString);
2661 if (szString[0] == L'|')
2663 PWSTR p = szString + 1;
2665 nIndex = infoPtr->nNumStrings;
2666 while (*p != L'|' && *p != L'\0') {
2669 if (infoPtr->nNumStrings == 0) {
2670 infoPtr->strings = Alloc (sizeof(LPWSTR));
2674 LPWSTR *oldStrings = infoPtr->strings;
2675 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2676 memcpy(&infoPtr->strings[0], &oldStrings[0],
2677 sizeof(LPWSTR) * infoPtr->nNumStrings);
2681 np=strchrW (p, '|');
2689 TRACE("len=%d %s\n", len, debugstr_w(p));
2690 infoPtr->strings[infoPtr->nNumStrings] =
2691 Alloc (sizeof(WCHAR)*(len+1));
2692 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2693 infoPtr->nNumStrings++;
2700 nIndex = infoPtr->nNumStrings;
2701 if (infoPtr->nNumStrings == 0) {
2703 Alloc (sizeof(LPWSTR));
2706 LPWSTR *oldStrings = infoPtr->strings;
2708 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2709 memcpy (&infoPtr->strings[0], &oldStrings[0],
2710 sizeof(LPWSTR) * infoPtr->nNumStrings);
2714 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2715 infoPtr->nNumStrings++;
2719 LPWSTR p = (LPWSTR)lParam;
2724 TRACE("adding string(s) from array!\n");
2725 nIndex = infoPtr->nNumStrings;
2729 TRACE("len=%d %s\n", len, debugstr_w(p));
2730 if (infoPtr->nNumStrings == 0) {
2732 Alloc (sizeof(LPWSTR));
2735 LPWSTR *oldStrings = infoPtr->strings;
2737 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2738 memcpy (&infoPtr->strings[0], &oldStrings[0],
2739 sizeof(LPWSTR) * infoPtr->nNumStrings);
2743 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2744 infoPtr->nNumStrings++;
2755 TOOLBAR_AutoSize (HWND hwnd)
2757 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2758 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2764 UINT uPosFlags = SWP_NOZORDER;
2766 TRACE("resize forced, style=%lx!\n", dwStyle);
2768 parent = GetParent (hwnd);
2769 GetClientRect(parent, &parent_rect);
2771 x = parent_rect.left;
2772 y = parent_rect.top;
2774 /* FIXME: we should be able to early out if nothing */
2775 /* has changed with nWidth != parent_rect width */
2777 if (dwStyle & CCS_NORESIZE) {
2778 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2781 TOOLBAR_CalcToolbar (hwnd);
2784 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2785 TOOLBAR_CalcToolbar (hwnd);
2786 InvalidateRect( hwnd, NULL, TRUE );
2787 cy = infoPtr->nHeight;
2788 cx = infoPtr->nWidth;
2790 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2791 GetWindowRect(hwnd, &window_rect);
2792 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2793 y = window_rect.top;
2795 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2796 GetWindowRect(hwnd, &window_rect);
2797 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2801 if (dwStyle & CCS_NOPARENTALIGN)
2802 uPosFlags |= SWP_NOMOVE;
2804 if (!(dwStyle & CCS_NODIVIDER))
2805 cy += GetSystemMetrics(SM_CYEDGE);
2807 if (dwStyle & WS_BORDER)
2810 cy += GetSystemMetrics(SM_CYEDGE);
2811 cx += GetSystemMetrics(SM_CYEDGE);
2814 infoPtr->bAutoSize = TRUE;
2815 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2816 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2817 * after the setwindowpos calls */
2818 infoPtr->bAutoSize = FALSE;
2825 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2829 return infoPtr->nNumButtons;
2834 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2836 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2838 if (infoPtr == NULL) {
2839 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2840 ERR("infoPtr == NULL!\n");
2844 infoPtr->dwStructSize = (DWORD)wParam;
2851 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2854 TBUTTON_INFO *btnPtr;
2857 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2859 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2863 btnPtr = &infoPtr->buttons[nIndex];
2864 btnPtr->iBitmap = LOWORD(lParam);
2866 /* we HAVE to erase the background, the new bitmap could be */
2868 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2875 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2877 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2878 TBUTTON_INFO *btnPtr;
2881 BOOL bChecked = FALSE;
2883 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2887 btnPtr = &infoPtr->buttons[nIndex];
2889 if (!(btnPtr->fsStyle & BTNS_CHECK))
2892 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2894 if (LOWORD(lParam) == FALSE)
2895 btnPtr->fsState &= ~TBSTATE_CHECKED;
2897 if (btnPtr->fsStyle & BTNS_GROUP) {
2899 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2900 if (nOldIndex == nIndex)
2902 if (nOldIndex != -1)
2903 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2905 btnPtr->fsState |= TBSTATE_CHECKED;
2908 if( bChecked != LOWORD(lParam) )
2910 if (nOldIndex != -1)
2912 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2913 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2915 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2918 /* FIXME: Send a WM_NOTIFY?? */
2925 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2929 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2934 TOOLBAR_Customize (HWND hwnd)
2936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2937 CUSTDLG_INFO custInfo;
2943 custInfo.tbInfo = infoPtr;
2944 custInfo.tbHwnd = hwnd;
2946 /* send TBN_BEGINADJUST notification */
2947 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2950 if (!(hRes = FindResourceA (COMCTL32_hModule,
2951 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2955 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2958 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2959 (LPDLGTEMPLATEA)template,
2961 TOOLBAR_CustomizeDialogProc,
2964 /* send TBN_ENDADJUST notification */
2965 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2973 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2976 INT nIndex = (INT)wParam;
2978 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2981 if ((infoPtr->hwndToolTip) &&
2982 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
2985 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2986 ti.cbSize = sizeof (TTTOOLINFOA);
2988 ti.uId = infoPtr->buttons[nIndex].idCommand;
2990 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2993 if (infoPtr->nNumButtons == 1) {
2994 TRACE(" simple delete!\n");
2995 Free (infoPtr->buttons);
2996 infoPtr->buttons = NULL;
2997 infoPtr->nNumButtons = 0;
3000 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3001 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3003 infoPtr->nNumButtons--;
3004 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3006 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3007 nIndex * sizeof(TBUTTON_INFO));
3010 if (nIndex < infoPtr->nNumButtons) {
3011 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3012 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3018 TOOLBAR_CalcToolbar (hwnd);
3020 InvalidateRect (hwnd, NULL, TRUE);
3027 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3029 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3030 TBUTTON_INFO *btnPtr;
3034 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3038 btnPtr = &infoPtr->buttons[nIndex];
3040 bState = btnPtr->fsState & TBSTATE_ENABLED;
3042 /* update the toolbar button state */
3043 if(LOWORD(lParam) == FALSE) {
3044 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3046 btnPtr->fsState |= TBSTATE_ENABLED;
3049 /* redraw the button only if the state of the button changed */
3050 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3052 InvalidateRect(hwnd, &btnPtr->rect,
3053 TOOLBAR_HasText(infoPtr, btnPtr));
3060 static inline LRESULT
3061 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3063 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3065 return infoPtr->bAnchor;
3070 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3075 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3079 return infoPtr->buttons[nIndex].iBitmap;
3083 static inline LRESULT
3084 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3086 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3091 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3093 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3094 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3095 INT nIndex = (INT)wParam;
3096 TBUTTON_INFO *btnPtr;
3098 if (infoPtr == NULL)
3104 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3107 btnPtr = &infoPtr->buttons[nIndex];
3108 lpTbb->iBitmap = btnPtr->iBitmap;
3109 lpTbb->idCommand = btnPtr->idCommand;
3110 lpTbb->fsState = btnPtr->fsState;
3111 lpTbb->fsStyle = btnPtr->fsStyle;
3112 lpTbb->bReserved[0] = 0;
3113 lpTbb->bReserved[1] = 0;
3114 lpTbb->dwData = btnPtr->dwData;
3115 lpTbb->iString = btnPtr->iString;
3122 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3126 TBUTTON_INFO *btnPtr;
3129 if (infoPtr == NULL)
3131 if (lpTbInfo == NULL)
3133 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3136 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3137 lpTbInfo->dwMask & 0x80000000);
3141 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3143 if (lpTbInfo->dwMask & TBIF_COMMAND)
3144 lpTbInfo->idCommand = btnPtr->idCommand;
3145 if (lpTbInfo->dwMask & TBIF_IMAGE)
3146 lpTbInfo->iImage = btnPtr->iBitmap;
3147 if (lpTbInfo->dwMask & TBIF_LPARAM)
3148 lpTbInfo->lParam = btnPtr->dwData;
3149 if (lpTbInfo->dwMask & TBIF_SIZE)
3150 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3151 if (lpTbInfo->dwMask & TBIF_STATE)
3152 lpTbInfo->fsState = btnPtr->fsState;
3153 if (lpTbInfo->dwMask & TBIF_STYLE)
3154 lpTbInfo->fsStyle = btnPtr->fsStyle;
3155 if (lpTbInfo->dwMask & TBIF_TEXT) {
3156 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3157 can't use TOOLBAR_GetText here */
3159 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3160 lpText = (LPWSTR)btnPtr->iString;
3161 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3163 lpTbInfo->pszText[0] = '\0';
3170 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3172 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3173 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3174 TBUTTON_INFO *btnPtr;
3177 if (infoPtr == NULL)
3179 if (lpTbInfo == NULL)
3181 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3184 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3185 lpTbInfo->dwMask & 0x80000000);
3189 btnPtr = &infoPtr->buttons[nIndex];
3194 if (lpTbInfo->dwMask & TBIF_COMMAND)
3195 lpTbInfo->idCommand = btnPtr->idCommand;
3196 if (lpTbInfo->dwMask & TBIF_IMAGE)
3197 lpTbInfo->iImage = btnPtr->iBitmap;
3198 if (lpTbInfo->dwMask & TBIF_LPARAM)
3199 lpTbInfo->lParam = btnPtr->dwData;
3200 if (lpTbInfo->dwMask & TBIF_SIZE)
3201 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3202 if (lpTbInfo->dwMask & TBIF_STATE)
3203 lpTbInfo->fsState = btnPtr->fsState;
3204 if (lpTbInfo->dwMask & TBIF_STYLE)
3205 lpTbInfo->fsStyle = btnPtr->fsStyle;
3206 if (lpTbInfo->dwMask & TBIF_TEXT) {
3207 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3208 can't use TOOLBAR_GetText here */
3210 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3211 lpText = (LPWSTR)btnPtr->iString;
3212 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3214 lpTbInfo->pszText[0] = '\0';
3222 TOOLBAR_GetButtonSize (HWND hwnd)
3224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3226 if (infoPtr->nNumButtons > 0)
3227 return MAKELONG((WORD)infoPtr->nButtonWidth,
3228 (WORD)infoPtr->nButtonHeight);
3230 return MAKELONG(8,7);
3235 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3244 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3248 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3250 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3251 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3256 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3269 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3271 strcpyW ((LPWSTR)lParam, lpText);
3273 return strlenW (lpText);
3278 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3280 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3281 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3282 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3286 inline static LRESULT
3287 TOOLBAR_GetExtendedStyle (HWND hwnd)
3289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3293 return infoPtr->dwExStyle;
3298 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3300 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3301 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3302 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3307 TOOLBAR_GetHotItem (HWND hwnd)
3309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3311 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3314 if (infoPtr->nHotItem < 0)
3317 return (LRESULT)infoPtr->nHotItem;
3322 TOOLBAR_GetDefImageList (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) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3330 /* << TOOLBAR_GetInsertMark >> */
3331 /* << TOOLBAR_GetInsertMarkColor >> */
3335 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3338 TBUTTON_INFO *btnPtr;
3342 if (infoPtr == NULL)
3344 nIndex = (INT)wParam;
3345 btnPtr = &infoPtr->buttons[nIndex];
3346 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3348 lpRect = (LPRECT)lParam;
3351 if (btnPtr->fsState & TBSTATE_HIDDEN)
3354 lpRect->left = btnPtr->rect.left;
3355 lpRect->right = btnPtr->rect.right;
3356 lpRect->bottom = btnPtr->rect.bottom;
3357 lpRect->top = btnPtr->rect.top;
3364 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3366 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3367 LPSIZE lpSize = (LPSIZE)lParam;
3372 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3373 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3375 TRACE("maximum size %ld x %ld\n",
3376 infoPtr->rcBound.right - infoPtr->rcBound.left,
3377 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3383 /* << TOOLBAR_GetObject >> */
3387 TOOLBAR_GetPadding (HWND hwnd)
3389 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3392 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3393 return (LRESULT) oldPad;
3398 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3401 TBUTTON_INFO *btnPtr;
3405 if (infoPtr == NULL)
3407 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3408 btnPtr = &infoPtr->buttons[nIndex];
3409 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3411 lpRect = (LPRECT)lParam;
3415 lpRect->left = btnPtr->rect.left;
3416 lpRect->right = btnPtr->rect.right;
3417 lpRect->bottom = btnPtr->rect.bottom;
3418 lpRect->top = btnPtr->rect.top;
3425 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3429 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3430 return infoPtr->nRows;
3437 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3442 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3446 return infoPtr->buttons[nIndex].fsState;
3451 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3456 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3460 return infoPtr->buttons[nIndex].fsStyle;
3465 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3469 if (infoPtr == NULL)
3472 return infoPtr->nMaxTextRows;
3477 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3481 if (infoPtr == NULL)
3483 return (LRESULT)infoPtr->hwndToolTip;
3488 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3492 TRACE("%s hwnd=%p stub!\n",
3493 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3495 return infoPtr->bUnicode;
3499 inline static LRESULT
3500 TOOLBAR_GetVersion (HWND hwnd)
3502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3503 return infoPtr->iVersion;
3508 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3511 TBUTTON_INFO *btnPtr;
3516 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3520 btnPtr = &infoPtr->buttons[nIndex];
3521 if (LOWORD(lParam) == FALSE)
3522 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3524 btnPtr->fsState |= TBSTATE_HIDDEN;
3526 TOOLBAR_CalcToolbar (hwnd);
3528 InvalidateRect (hwnd, NULL, TRUE);
3534 inline static LRESULT
3535 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3537 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3542 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3544 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3545 TBUTTON_INFO *btnPtr;
3549 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3553 btnPtr = &infoPtr->buttons[nIndex];
3554 oldState = btnPtr->fsState;
3555 if (LOWORD(lParam) == FALSE)
3556 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3558 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3560 if(oldState != btnPtr->fsState)
3561 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3568 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3570 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3571 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3572 INT nIndex = (INT)wParam;
3573 TBUTTON_INFO *oldButtons;
3578 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3581 /* EPP: this seems to be an undocumented call (from my IE4)
3582 * I assume in that case that:
3583 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3584 * - index of insertion is at the end of existing buttons
3585 * I only see this happen with nIndex == -1, but it could have a special
3586 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3588 nIndex = infoPtr->nNumButtons;
3590 } else if (nIndex < 0)
3593 /* If the string passed is not an index, assume address of string
3594 and do our own AddString */
3595 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3599 TRACE("string %s passed instead of index, adding string\n",
3600 debugstr_a((LPSTR)lpTbb->iString));
3601 len = strlen((LPSTR)lpTbb->iString) + 2;
3603 strcpy(ptr, (LPSTR)lpTbb->iString);
3604 ptr[len - 1] = 0; /* ended by two '\0' */
3605 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3609 TRACE("inserting button index=%d\n", nIndex);
3610 if (nIndex > infoPtr->nNumButtons) {
3611 nIndex = infoPtr->nNumButtons;
3612 TRACE("adjust index=%d\n", nIndex);
3615 oldButtons = infoPtr->buttons;
3616 infoPtr->nNumButtons++;
3617 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3618 /* pre insert copy */
3620 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3621 nIndex * sizeof(TBUTTON_INFO));
3624 /* insert new button */
3625 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3626 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3627 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3628 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3629 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3630 /* if passed string and not index, then add string */
3631 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3632 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3635 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3637 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3640 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3641 ti.cbSize = sizeof (TTTOOLINFOA);
3643 ti.uId = lpTbb->idCommand;
3645 ti.lpszText = LPSTR_TEXTCALLBACKA;
3647 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3651 /* post insert copy */
3652 if (nIndex < infoPtr->nNumButtons - 1) {
3653 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3654 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3659 TOOLBAR_CalcToolbar (hwnd);
3661 InvalidateRect (hwnd, NULL, TRUE);
3668 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3670 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3671 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3672 INT nIndex = (INT)wParam;
3673 TBUTTON_INFO *oldButtons;
3678 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3681 /* EPP: this seems to be an undocumented call (from my IE4)
3682 * I assume in that case that:
3683 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3684 * - index of insertion is at the end of existing buttons
3685 * I only see this happen with nIndex == -1, but it could have a special
3686 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3688 nIndex = infoPtr->nNumButtons;
3690 } else if (nIndex < 0)
3693 /* If the string passed is not an index, assume address of string
3694 and do our own AddString */
3695 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3699 TRACE("string %s passed instead of index, adding string\n",
3700 debugstr_w((LPWSTR)lpTbb->iString));
3701 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3702 ptr = Alloc(len*sizeof(WCHAR));
3703 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3704 ptr[len - 1] = 0; /* ended by two '\0' */
3705 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3709 TRACE("inserting button index=%d\n", nIndex);
3710 if (nIndex > infoPtr->nNumButtons) {
3711 nIndex = infoPtr->nNumButtons;
3712 TRACE("adjust index=%d\n", nIndex);
3715 oldButtons = infoPtr->buttons;
3716 infoPtr->nNumButtons++;
3717 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3718 /* pre insert copy */
3720 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3721 nIndex * sizeof(TBUTTON_INFO));
3724 /* insert new button */
3725 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3726 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3727 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3728 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3729 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3730 /* if passed string and not index, then add string */
3731 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3732 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3735 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3737 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3740 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3741 ti.cbSize = sizeof (TTTOOLINFOW);
3743 ti.uId = lpTbb->idCommand;
3745 ti.lpszText = LPSTR_TEXTCALLBACKW;
3747 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3751 /* post insert copy */
3752 if (nIndex < infoPtr->nNumButtons - 1) {
3753 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3754 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3759 TOOLBAR_CalcToolbar (hwnd);
3761 InvalidateRect (hwnd, NULL, TRUE);
3767 /* << TOOLBAR_InsertMarkHitTest >> */
3771 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3776 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3780 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3785 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3790 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3794 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3799 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3801 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3804 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3808 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3813 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3815 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3818 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3822 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3827 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3829 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3832 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3836 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3841 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3846 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3850 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3854 /* << TOOLBAR_LoadImages >> */
3855 /* << TOOLBAR_MapAccelerator >> */
3856 /* << TOOLBAR_MarkButton >> */
3857 /* << TOOLBAR_MoveButton >> */
3861 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 TBUTTON_INFO *btnPtr;
3868 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3872 btnPtr = &infoPtr->buttons[nIndex];
3873 oldState = btnPtr->fsState;
3874 if (LOWORD(lParam) == FALSE)
3875 btnPtr->fsState &= ~TBSTATE_PRESSED;
3877 btnPtr->fsState |= TBSTATE_PRESSED;
3879 if(oldState != btnPtr->fsState)
3880 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3885 /* FIXME: there might still be some confusion her between number of buttons
3886 * and number of bitmaps */
3888 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3891 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3893 int i = 0, nOldButtons = 0, pos = 0;
3894 int nOldBitmaps, nNewBitmaps;
3895 HIMAGELIST himlDef = 0;
3897 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3898 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3899 lpReplace->nButtons);
3901 if (lpReplace->hInstOld == HINST_COMMCTRL)
3903 FIXME("changing standard bitmaps not implemented\n");
3906 else if (lpReplace->hInstOld != 0)
3908 FIXME("resources not in the current module not implemented\n");
3913 hBitmap = (HBITMAP) lpReplace->nIDNew;
3916 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3917 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3918 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3919 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3920 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3922 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3923 nOldButtons = tbi->nButtons;
3924 tbi->nButtons = lpReplace->nButtons;
3925 tbi->hInst = lpReplace->hInstNew;
3926 tbi->nID = lpReplace->nIDNew;
3927 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3930 pos += tbi->nButtons;
3933 if (nOldButtons == 0)
3935 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3939 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
3940 nOldBitmaps = ImageList_GetImageCount(himlDef);
3942 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
3944 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
3945 ImageList_Remove(himlDef, i);
3949 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
3950 HDC hdcImage, hdcBitmap;
3952 /* copy the bitmap before adding it so that the user's bitmap
3953 * doesn't get modified.
3955 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
3957 hdcImage = CreateCompatibleDC(0);
3958 hdcBitmap = CreateCompatibleDC(0);
3960 /* create new bitmap */
3961 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
3962 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
3963 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
3965 /* Copy the user's image */
3966 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
3967 hdcBitmap, 0, 0, SRCCOPY);
3969 SelectObject (hdcImage, hOldBitmapLoad);
3970 SelectObject (hdcBitmap, hOldBitmapBitmap);
3971 DeleteDC (hdcImage);
3972 DeleteDC (hdcBitmap);
3974 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
3975 nNewBitmaps = ImageList_GetImageCount(himlDef);
3976 DeleteObject (hbmLoad);
3979 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
3981 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
3982 pos, nOldBitmaps, nNewBitmaps);
3984 InvalidateRect(hwnd, NULL, FALSE);
3990 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3993 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3994 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3996 if (lpSave == NULL) return 0;
3999 /* save toolbar information */
4000 FIXME("save to \"%s\" \"%s\"\n",
4001 lpSave->pszSubKey, lpSave->pszValueName);
4006 /* restore toolbar information */
4008 FIXME("restore from \"%s\" \"%s\"\n",
4009 lpSave->pszSubKey, lpSave->pszValueName);
4020 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4024 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4030 /* save toolbar information */
4031 FIXME("save to \"%s\" \"%s\"\n",
4032 lpSave->pszSubKey, lpSave->pszValueName);
4037 /* restore toolbar information */
4039 FIXME("restore from \"%s\" \"%s\"\n",
4040 lpSave->pszSubKey, lpSave->pszValueName);
4051 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4054 BOOL bOldAnchor = infoPtr->bAnchor;
4056 infoPtr->bAnchor = (BOOL)wParam;
4058 return (LRESULT)bOldAnchor;
4063 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4066 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4068 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4071 if (infoPtr->nNumButtons > 0)
4072 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4073 infoPtr->nNumButtons,
4074 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4075 LOWORD(lParam), HIWORD(lParam));
4077 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4078 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4081 /* uses image list internals directly */
4083 himlDef->cx = infoPtr->nBitmapWidth;
4084 himlDef->cy = infoPtr->nBitmapHeight;
4092 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4095 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4096 TBUTTON_INFO *btnPtr;
4101 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4104 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4105 lptbbi->dwMask & 0x80000000);
4109 btnPtr = &infoPtr->buttons[nIndex];
4110 if (lptbbi->dwMask & TBIF_COMMAND)
4111 btnPtr->idCommand = lptbbi->idCommand;
4112 if (lptbbi->dwMask & TBIF_IMAGE)
4113 btnPtr->iBitmap = lptbbi->iImage;
4114 if (lptbbi->dwMask & TBIF_LPARAM)
4115 btnPtr->dwData = lptbbi->lParam;
4116 /* if (lptbbi->dwMask & TBIF_SIZE) */
4117 /* btnPtr->cx = lptbbi->cx; */
4118 if (lptbbi->dwMask & TBIF_STATE)
4119 btnPtr->fsState = lptbbi->fsState;
4120 if (lptbbi->dwMask & TBIF_STYLE)
4121 btnPtr->fsStyle = lptbbi->fsStyle;
4123 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4124 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4125 /* iString is index, zero it to make Str_SetPtr succeed */
4128 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4135 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4138 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4139 TBUTTON_INFO *btnPtr;
4144 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4147 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4148 lptbbi->dwMask & 0x80000000);
4152 btnPtr = &infoPtr->buttons[nIndex];
4153 if (lptbbi->dwMask & TBIF_COMMAND)
4154 btnPtr->idCommand = lptbbi->idCommand;
4155 if (lptbbi->dwMask & TBIF_IMAGE)
4156 btnPtr->iBitmap = lptbbi->iImage;
4157 if (lptbbi->dwMask & TBIF_LPARAM)
4158 btnPtr->dwData = lptbbi->lParam;
4159 /* if (lptbbi->dwMask & TBIF_SIZE) */
4160 /* btnPtr->cx = lptbbi->cx; */
4161 if (lptbbi->dwMask & TBIF_STATE)
4162 btnPtr->fsState = lptbbi->fsState;
4163 if (lptbbi->dwMask & TBIF_STYLE)
4164 btnPtr->fsStyle = lptbbi->fsStyle;
4166 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4167 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4168 /* iString is index, zero it to make Str_SetPtr succeed */
4170 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4177 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4179 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4180 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4182 if ((cx < 0) || (cy < 0))
4184 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4188 /* The documentation claims you can only change the button size before
4189 * any button has been added. But this is wrong.
4190 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4191 * it to the toolbar, and it checks that the return value is nonzero - mjm
4192 * Further testing shows that we must actually perform the change too.
4195 * The documentation also does not mention that if 0 is supplied for
4196 * either size, the system changes it to the default of 24 wide and
4197 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4199 infoPtr->nButtonWidth = (cx) ? cx : 24;
4200 infoPtr->nButtonHeight = (cy) ? cy : 22;
4206 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4210 if (infoPtr == NULL) {
4211 TRACE("Toolbar not initialized yet?????\n");
4215 /* if setting to current values, ignore */
4216 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4217 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4218 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4219 infoPtr->cxMin, infoPtr->cxMax);
4223 /* save new values */
4224 infoPtr->cxMin = (INT)LOWORD(lParam);
4225 infoPtr->cxMax = (INT)HIWORD(lParam);
4227 /* if both values are 0 then we are done */
4229 TRACE("setting both min and max to 0, norecalc\n");
4233 /* otherwise we need to recalc the toolbar and in some cases
4234 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4235 which doesn't actually draw - GA). */
4236 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4237 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4239 TOOLBAR_CalcToolbar (hwnd);
4241 InvalidateRect (hwnd, NULL, TRUE);
4248 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4250 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4251 INT nIndex = (INT)wParam;
4253 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4256 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4258 if (infoPtr->hwndToolTip) {
4260 FIXME("change tool tip!\n");
4269 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4272 HIMAGELIST himl = (HIMAGELIST)lParam;
4273 HIMAGELIST himlTemp;
4276 if (infoPtr->iVersion >= 5)
4279 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4280 &infoPtr->cimlDis, himl, id);
4282 /* FIXME: redraw ? */
4284 return (LRESULT)himlTemp;
4289 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4291 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4294 dwTemp = infoPtr->dwDTFlags;
4295 infoPtr->dwDTFlags =
4296 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4298 return (LRESULT)dwTemp;
4301 /* This function differs a bit from what MSDN says it does:
4302 * 1. lParam contains extended style flags to OR with current style
4303 * (MSDN isn't clear on the OR bit)
4304 * 2. wParam appears to contain extended style flags to be reset
4305 * (MSDN says that this parameter is reserved)
4308 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4310 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4313 dwTemp = infoPtr->dwExStyle;
4314 infoPtr->dwExStyle &= ~wParam;
4315 infoPtr->dwExStyle |= (DWORD)lParam;
4317 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4319 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4320 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4321 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4323 TOOLBAR_CalcToolbar (hwnd);
4325 TOOLBAR_AutoSize(hwnd);
4327 InvalidateRect(hwnd, NULL, FALSE);
4329 return (LRESULT)dwTemp;
4334 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4336 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4337 HIMAGELIST himlTemp;
4338 HIMAGELIST himl = (HIMAGELIST)lParam;
4341 if (infoPtr->iVersion >= 5)
4344 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4346 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4347 &infoPtr->cimlHot, himl, id);
4349 /* FIXME: redraw ? */
4351 return (LRESULT)himlTemp;
4356 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4358 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4359 INT nOldHotItem = infoPtr->nHotItem;
4360 TBUTTON_INFO *btnPtr;
4362 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4365 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4368 infoPtr->nHotItem = (INT)wParam;
4369 if ((INT)wParam >=0)
4371 btnPtr = &infoPtr->buttons[(INT)wParam];
4372 btnPtr->bHot = TRUE;
4373 InvalidateRect (hwnd, &btnPtr->rect,
4374 TOOLBAR_HasText(infoPtr, btnPtr));
4378 btnPtr = &infoPtr->buttons[nOldHotItem];
4379 btnPtr->bHot = FALSE;
4380 InvalidateRect (hwnd, &btnPtr->rect,
4381 TOOLBAR_HasText(infoPtr, btnPtr));
4385 if (nOldHotItem < 0)
4388 return (LRESULT)nOldHotItem;
4393 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4396 HIMAGELIST himlTemp;
4397 HIMAGELIST himl = (HIMAGELIST)lParam;
4400 if (infoPtr->iVersion >= 5)
4403 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4404 &infoPtr->cimlDef, himl, id);
4406 infoPtr->nNumBitmaps = 0;
4407 for (i = 0; i < infoPtr->cimlDef; i++)
4408 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4410 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4411 &infoPtr->nBitmapHeight);
4412 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4413 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4414 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4416 /* FIXME: redraw ? */
4417 InvalidateRect(hwnd, NULL, TRUE);
4419 return (LRESULT)himlTemp;
4424 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4428 infoPtr->nIndent = (INT)wParam;
4432 /* process only on indent changing */
4433 if(infoPtr->nIndent != (INT)wParam)
4435 infoPtr->nIndent = (INT)wParam;
4436 TOOLBAR_CalcToolbar (hwnd);
4437 InvalidateRect(hwnd, NULL, FALSE);
4444 /* << TOOLBAR_SetInsertMark >> */
4448 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4452 infoPtr->clrInsertMark = (COLORREF)lParam;
4454 /* FIXME : redraw ??*/
4461 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4465 if (infoPtr == NULL)
4468 infoPtr->nMaxTextRows = (INT)wParam;
4470 TOOLBAR_CalcToolbar(hwnd);
4476 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4478 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4481 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4482 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4483 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4484 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4485 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4486 return (LRESULT) oldPad;
4491 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4498 if (infoPtr == NULL)
4500 hwndOldNotify = infoPtr->hwndNotify;
4501 infoPtr->hwndNotify = (HWND)wParam;
4503 return (LRESULT)hwndOldNotify;
4508 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4511 LPRECT lprc = (LPRECT)lParam;
4515 if (LOWORD(wParam) > 1) {
4516 FIXME("multiple rows not supported!\n");
4519 if(infoPtr->nRows != LOWORD(wParam))
4521 infoPtr->nRows = LOWORD(wParam);
4523 /* recalculate toolbar */
4524 TOOLBAR_CalcToolbar (hwnd);
4526 /* repaint toolbar */
4527 InvalidateRect(hwnd, NULL, FALSE);
4530 /* return bounding rectangle */
4532 lprc->left = infoPtr->rcBound.left;
4533 lprc->right = infoPtr->rcBound.right;
4534 lprc->top = infoPtr->rcBound.top;
4535 lprc->bottom = infoPtr->rcBound.bottom;
4543 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4546 TBUTTON_INFO *btnPtr;
4549 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4553 btnPtr = &infoPtr->buttons[nIndex];
4555 /* if hidden state has changed the invalidate entire window and recalc */
4556 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4557 btnPtr->fsState = LOWORD(lParam);
4558 TOOLBAR_CalcToolbar (hwnd);
4559 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4563 /* process state changing if current state doesn't match new state */
4564 if(btnPtr->fsState != LOWORD(lParam))
4566 btnPtr->fsState = LOWORD(lParam);
4567 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4576 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4578 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4584 inline static LRESULT
4585 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4587 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4589 if (infoPtr == NULL)
4591 infoPtr->hwndToolTip = (HWND)wParam;
4597 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4602 TRACE("%s hwnd=%p stub!\n",
4603 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4605 bTemp = infoPtr->bUnicode;
4606 infoPtr->bUnicode = (BOOL)wParam;
4613 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4615 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4617 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4618 comctl32_color.clrBtnHighlight :
4619 infoPtr->clrBtnHighlight;
4620 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4621 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4627 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4629 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4631 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4632 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4633 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4635 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4636 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4637 InvalidateRect(hwnd, 0, 0);
4643 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4645 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4646 INT iOldVersion = infoPtr->iVersion;
4648 infoPtr->iVersion = iVersion;
4650 if (infoPtr->iVersion >= 5)
4651 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4658 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4661 WORD iString = HIWORD(wParam);
4662 WORD buffersize = LOWORD(wParam);
4663 LPSTR str = (LPSTR)lParam;
4666 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4668 if (iString < infoPtr->nNumStrings)
4670 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4672 TRACE("returning %s\n", debugstr_a(str));
4675 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4682 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4684 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4685 WORD iString = HIWORD(wParam);
4686 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4687 LPWSTR str = (LPWSTR)lParam;
4690 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4692 if (iString < infoPtr->nNumStrings)
4694 len = min(len, strlenW(infoPtr->strings[iString]));
4695 ret = (len+1)*sizeof(WCHAR);
4696 memcpy(str, infoPtr->strings[iString], ret);
4699 TRACE("returning %s\n", debugstr_w(str));
4702 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4707 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4709 FIXME("hwnd=%p wParam %08x lParam %08lx stub!\n", hwnd, wParam, lParam);
4713 /*********************************************************************/
4715 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4716 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4717 /* based on relay traces of the native control and IE 5.5 */
4719 /*********************************************************************/
4721 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4724 INT nOldHotItem = infoPtr->nHotItem;
4725 TBUTTON_INFO *btnPtr;
4727 NMTBHOTITEM nmhotitem;
4729 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4732 infoPtr->nHotItem = (INT)wParam;
4733 if (nOldHotItem != infoPtr->nHotItem) {
4734 nmhotitem.dwFlags = (DWORD)lParam;
4735 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4736 nmhotitem.idOld = (nOldHotItem >= 0) ?
4737 infoPtr->buttons[nOldHotItem].idCommand : 0;
4738 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4739 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4740 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4741 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4743 if ((INT)wParam >=0) {
4744 btnPtr = &infoPtr->buttons[(INT)wParam];
4745 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4746 InvalidateRect (hwnd, &btnPtr->rect,
4747 TOOLBAR_HasText(infoPtr, btnPtr));
4749 if (nOldHotItem>=0) {
4750 btnPtr = &infoPtr->buttons[nOldHotItem];
4751 btnPtr->bHot = FALSE;
4752 InvalidateRect (hwnd, &btnPtr->rect,
4753 TOOLBAR_HasText(infoPtr, btnPtr));
4756 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4757 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4759 if (nOldHotItem < 0)
4762 return (LRESULT)nOldHotItem;
4765 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4767 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4769 InvalidateRect(hwnd, NULL, TRUE);
4773 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4774 * of image lists associated with the various states. */
4775 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
4777 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4779 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4781 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
4785 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4788 LPSIZE lpsize = (LPSIZE)lParam;
4794 * Testing shows the following:
4795 * wParam = 0 adjust cx value
4796 * = 1 set cy value to max size.
4797 * lParam pointer to SIZE structure
4800 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4801 wParam, lParam, lpsize->cx, lpsize->cy);
4805 if (lpsize->cx == -1) {
4806 /* **** this is wrong, native measures each button and sets it */
4807 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4809 else if(HIWORD(lpsize->cx)) {
4811 HWND hwndParent = GetParent(hwnd);
4813 GetWindowRect(hwnd, &rc);
4814 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4815 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4816 rc.left, rc.top, rc.right, rc.bottom);
4817 lpsize->cx = max(rc.right-rc.left,
4818 infoPtr->rcBound.right - infoPtr->rcBound.left);
4821 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4825 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4826 /* lpsize->cy = infoPtr->nHeight; */
4829 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4833 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4834 lpsize->cx, lpsize->cy);
4838 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
4840 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4842 InvalidateRect(hwnd, NULL, TRUE);
4848 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4851 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4854 TRACE("hwnd = %p\n", hwnd);
4856 /* initialize info structure */
4857 infoPtr->nButtonHeight = 22;
4858 infoPtr->nButtonWidth = 24;
4859 infoPtr->nBitmapHeight = 15;
4860 infoPtr->nBitmapWidth = 16;
4862 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4863 infoPtr->nMaxTextRows = 1;
4864 infoPtr->cxMin = -1;
4865 infoPtr->cxMax = -1;
4866 infoPtr->nNumBitmaps = 0;
4867 infoPtr->nNumStrings = 0;
4869 infoPtr->bCaptured = FALSE;
4870 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4871 infoPtr->nButtonDown = -1;
4872 infoPtr->nOldHit = -1;
4873 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4874 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
4875 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4876 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4877 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4878 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4879 infoPtr->iVersion = 0;
4880 infoPtr->hwndSelf = hwnd;
4881 infoPtr->bDoRedraw = TRUE;
4882 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4883 infoPtr->clrBtnShadow = CLR_DEFAULT;
4884 infoPtr->szPadding.cx = 7;
4885 infoPtr->szPadding.cy = 6;
4886 GetClientRect(hwnd, &infoPtr->client_rect);
4887 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4889 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4890 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4892 if (dwStyle & TBSTYLE_TOOLTIPS) {
4893 /* Create tooltip control */
4894 infoPtr->hwndToolTip =
4895 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4896 CW_USEDEFAULT, CW_USEDEFAULT,
4897 CW_USEDEFAULT, CW_USEDEFAULT,
4900 /* Send NM_TOOLTIPSCREATED notification */
4901 if (infoPtr->hwndToolTip) {
4902 NMTOOLTIPSCREATED nmttc;
4904 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4906 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4907 NM_TOOLTIPSCREATED);
4911 TOOLBAR_CheckStyle (hwnd, dwStyle);
4913 TOOLBAR_CalcToolbar(hwnd);
4920 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4924 /* delete tooltip control */
4925 if (infoPtr->hwndToolTip)
4926 DestroyWindow (infoPtr->hwndToolTip);
4928 /* delete button data */
4929 if (infoPtr->buttons)
4930 Free (infoPtr->buttons);
4932 /* delete strings */
4933 if (infoPtr->strings) {
4935 for (i = 0; i < infoPtr->nNumStrings; i++)
4936 if (infoPtr->strings[i])
4937 Free (infoPtr->strings[i]);
4939 Free (infoPtr->strings);
4942 /* destroy internal image list */
4943 if (infoPtr->himlInt)
4944 ImageList_Destroy (infoPtr->himlInt);
4946 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
4947 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
4948 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
4950 /* delete default font */
4952 DeleteObject (infoPtr->hDefaultFont);
4954 /* free toolbar info data */
4956 SetWindowLongA (hwnd, 0, 0);
4963 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4966 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4967 NMTBCUSTOMDRAW tbcd;
4971 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4972 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4973 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4974 tbcd.nmcd.hdc = (HDC)wParam;
4975 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4976 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4978 /* FIXME: in general the return flags *can* be or'ed together */
4979 switch (infoPtr->dwBaseCustDraw)
4981 case CDRF_DODEFAULT:
4983 case CDRF_SKIPDEFAULT:
4986 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4991 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4992 * to my parent for processing.
4994 if (infoPtr->bTransparent) {
4996 HDC hdc = (HDC)wParam;
5001 parent = GetParent(hwnd);
5002 MapWindowPoints(hwnd, parent, &pt, 1);
5003 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5004 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5005 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5008 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5010 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5011 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5012 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5013 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5014 tbcd.nmcd.hdc = (HDC)wParam;
5015 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5016 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5017 switch (infoPtr->dwBaseCustDraw)
5019 case CDRF_DODEFAULT:
5021 case CDRF_SKIPDEFAULT:
5024 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5033 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5035 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5037 return (LRESULT)infoPtr->hFont;
5042 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5045 TBUTTON_INFO *btnPtr;
5049 pt.x = (INT)LOWORD(lParam);
5050 pt.y = (INT)HIWORD(lParam);
5051 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5054 btnPtr = &infoPtr->buttons[nHit];
5055 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5058 infoPtr->bCaptured = TRUE;
5059 infoPtr->nButtonDown = nHit;
5061 btnPtr->fsState |= TBSTATE_PRESSED;
5063 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5066 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5067 TOOLBAR_Customize (hwnd);
5074 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5076 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5077 TBUTTON_INFO *btnPtr;
5082 if (infoPtr->hwndToolTip)
5083 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5084 WM_LBUTTONDOWN, wParam, lParam);
5086 pt.x = (INT)LOWORD(lParam);
5087 pt.y = (INT)HIWORD(lParam);
5088 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5092 btnPtr = &infoPtr->buttons[nHit];
5093 infoPtr->nOldHit = nHit;
5095 CopyRect(&arrowRect, &btnPtr->rect);
5096 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5098 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5099 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5100 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5101 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5102 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5103 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5107 * this time we must force a Redraw, so the btn is
5108 * painted down before CaptureChanged repaints it up
5110 RedrawWindow(hwnd,&btnPtr->rect,0,
5111 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5113 nmtb.iItem = btnPtr->idCommand;
5114 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5117 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5118 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5120 if (res != TBDDRET_TREATPRESSED)
5121 /* ??? guess (GA) */
5123 /* otherwise drop through and process as pushed */
5125 /* SetCapture (hwnd); */
5126 infoPtr->bCaptured = TRUE;
5127 infoPtr->nButtonDown = nHit;
5129 btnPtr->fsState |= TBSTATE_PRESSED;
5130 btnPtr->bHot = FALSE;
5132 if (btnPtr->fsState & TBSTATE_ENABLED)
5133 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
5137 /* native issues the TBN_BEGINDRAG here */
5138 nmtb.iItem = btnPtr->idCommand;
5139 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5140 nmtb.tbButton.idCommand = btnPtr->idCommand;
5141 nmtb.tbButton.fsState = btnPtr->fsState;
5142 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5143 nmtb.tbButton.dwData = btnPtr->dwData;
5144 nmtb.tbButton.iString = btnPtr->iString;
5145 nmtb.cchText = 0; /* !!! not correct */
5146 nmtb.pszText = 0; /* !!! not correct */
5147 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5155 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5157 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5158 TBUTTON_INFO *btnPtr;
5162 BOOL bSendMessage = TRUE;
5167 if (infoPtr->hwndToolTip)
5168 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5169 WM_LBUTTONUP, wParam, lParam);
5171 pt.x = (INT)LOWORD(lParam);
5172 pt.y = (INT)HIWORD(lParam);
5173 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5175 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
5176 /* if the cursor is still inside of the toolbar */
5177 if((infoPtr->nHotItem >= 0) && (nHit != -1))
5178 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
5180 if (0 <= infoPtr->nButtonDown) {
5181 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5182 btnPtr->fsState &= ~TBSTATE_PRESSED;
5184 if (btnPtr->fsStyle & BTNS_CHECK) {
5185 if (btnPtr->fsStyle & BTNS_GROUP) {
5186 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5188 if (nOldIndex == nHit)
5189 bSendMessage = FALSE;
5190 if ((nOldIndex != nHit) &&
5192 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5193 btnPtr->fsState |= TBSTATE_CHECKED;
5196 if (btnPtr->fsState & TBSTATE_CHECKED)
5197 btnPtr->fsState &= ~TBSTATE_CHECKED;
5199 btnPtr->fsState |= TBSTATE_CHECKED;
5203 if (nOldIndex != -1)
5205 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
5206 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
5210 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5211 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5212 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5214 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5216 infoPtr->nButtonDown = -1;
5218 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5219 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5220 NM_RELEASEDCAPTURE);
5222 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5225 nmtb.iItem = btnPtr->idCommand;
5226 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5227 nmtb.tbButton.idCommand = btnPtr->idCommand;
5228 nmtb.tbButton.fsState = btnPtr->fsState;
5229 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5230 nmtb.tbButton.dwData = btnPtr->dwData;
5231 nmtb.tbButton.iString = btnPtr->iString;
5232 nmtb.cchText = 0; /* !!! not correct */
5233 nmtb.pszText = 0; /* !!! not correct */
5234 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5237 if (btnPtr->fsState & TBSTATE_ENABLED)
5239 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5240 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5242 /* !!! Undocumented - toolbar at 4.71 level and above sends
5243 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5244 * Only NM_RCLICK is documented.
5246 nmmouse.dwItemSpec = btnPtr->idCommand;
5247 nmmouse.dwItemData = btnPtr->dwData;
5248 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5255 TOOLBAR_CaptureChanged(HWND hwnd)
5257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5258 TBUTTON_INFO *btnPtr;
5260 infoPtr->bCaptured = FALSE;
5262 if (infoPtr->nButtonDown >= 0)
5264 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5265 btnPtr->fsState &= ~TBSTATE_PRESSED;
5267 infoPtr->nOldHit = -1;
5269 if (btnPtr->fsState & TBSTATE_ENABLED)
5270 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5277 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5280 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5283 if (infoPtr->nOldHit < 0)
5286 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5288 /* Redraw the button if the last button we were over is the hot button and it
5290 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
5292 hotBtnPtr->bHot = FALSE;
5293 rc1 = hotBtnPtr->rect;
5294 InflateRect (&rc1, 1, 1);
5295 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
5299 /* If the last button we were over is depressed then make it not */
5300 /* depressed and redraw it */
5301 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5303 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5305 btnPtr->fsState &= ~TBSTATE_PRESSED;
5307 rc1 = hotBtnPtr->rect;
5308 InflateRect (&rc1, 1, 1);
5309 InvalidateRect (hwnd, &rc1, TRUE);
5312 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5313 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
5319 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5321 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5322 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5325 TRACKMOUSEEVENT trackinfo;
5326 NMTBHOTITEM nmhotitem;
5328 /* fill in the TRACKMOUSEEVENT struct */
5329 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5330 trackinfo.dwFlags = TME_QUERY;
5331 trackinfo.hwndTrack = hwnd;
5332 trackinfo.dwHoverTime = HOVER_DEFAULT;
5334 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5335 _TrackMouseEvent(&trackinfo);
5337 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5338 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5339 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5341 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5342 /* and can properly deactivate the hot toolbar button */
5343 _TrackMouseEvent(&trackinfo);
5346 if (infoPtr->hwndToolTip)
5347 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5348 WM_MOUSEMOVE, wParam, lParam);
5350 pt.x = (INT)LOWORD(lParam);
5351 pt.y = (INT)HIWORD(lParam);
5353 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5355 if (infoPtr->nOldHit != nHit)
5357 /* Remove the effect of an old hot button if the button was
5358 drawn with the hot button effect */
5359 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem)
5361 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5362 oldBtnPtr->bHot = FALSE;
5365 /* It's not a separator or in nowhere. It's a hot button. */
5368 btnPtr = &infoPtr->buttons[nHit];
5370 infoPtr->nHotItem = nHit;
5372 btnPtr->bHot = TRUE;
5375 nmhotitem.dwFlags = HICF_MOUSE;
5377 nmhotitem.idOld = oldBtnPtr->idCommand;
5379 nmhotitem.dwFlags |= HICF_ENTERING;
5381 nmhotitem.idNew = btnPtr->idCommand;
5383 nmhotitem.dwFlags |= HICF_LEAVING;
5384 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5386 /* now invalidate the old and new buttons so they will be painted */
5388 InvalidateRect (hwnd, &oldBtnPtr->rect,
5389 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5391 InvalidateRect(hwnd, &btnPtr->rect,
5392 TOOLBAR_HasText(infoPtr, btnPtr));
5394 if (infoPtr->bCaptured) {
5395 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5396 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5397 btnPtr->fsState &= ~TBSTATE_PRESSED;
5398 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5400 else if (nHit == infoPtr->nButtonDown) {
5401 btnPtr->fsState |= TBSTATE_PRESSED;
5402 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5405 infoPtr->nOldHit = nHit;
5411 inline static LRESULT
5412 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5414 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5415 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5417 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5421 inline static LRESULT
5422 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5424 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5425 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5427 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5432 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5434 TOOLBAR_INFO *infoPtr;
5435 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5438 /* allocate memory for info structure */
5439 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5440 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5443 infoPtr->dwStructSize = sizeof(TBBUTTON);
5446 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5447 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5448 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5449 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5452 /* native control does:
5453 * Get a lot of colors and brushes
5455 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5456 * CreateFontIndirectA(adr1)
5457 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5458 * hdc = GetDC(toolbar)
5459 * GetSystemMetrics(0x48)
5460 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5461 * 0, 0, 0, 0, "MARLETT")
5462 * oldfnt = SelectObject(hdc, fnt2)
5463 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5464 * GetTextMetricsA(hdc, adr3)
5465 * SelectObject(hdc, oldfnt)
5466 * DeleteObject(fnt2)
5468 * InvalidateRect(toolbar, 0, 1)
5469 * SetWindowLongA(toolbar, 0, addr)
5470 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5473 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5474 * ie 2 0x4600094c 0x4600094c 0x4600894d
5475 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5476 * rebar 0x50008844 0x40008844 0x50008845
5477 * pager 0x50000844 0x40000844 0x50008845
5478 * IC35mgr 0x5400084e **nochange**
5479 * on entry to _NCCREATE 0x5400084e
5480 * rowlist 0x5400004e **nochange**
5481 * on entry to _NCCREATE 0x5400004e
5485 /* I think the code below is a bug, but it is the way that the native
5486 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5487 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5488 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5489 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5490 * Some how, the only cases of this seem to be MFC programs.
5492 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5493 * does not occur in the WM_STYLECHANGING routine.
5494 * (Guy Albertelli 9/2001)
5497 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5498 styleadd |= TBSTYLE_TRANSPARENT;
5499 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5500 styleadd |= CCS_TOP; /* default to top */
5501 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5504 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5509 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5511 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5515 if (dwStyle & WS_MINIMIZE)
5516 return 0; /* Nothing to do */
5518 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5520 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5523 if (!(dwStyle & CCS_NODIVIDER))
5525 GetWindowRect (hwnd, &rcWindow);
5526 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5527 if( dwStyle & WS_BORDER )
5528 OffsetRect (&rcWindow, 1, 1);
5529 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5532 ReleaseDC( hwnd, hdc );
5538 inline static LRESULT
5539 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5542 LPNMHDR lpnmh = (LPNMHDR)lParam;
5544 if (lpnmh->code == PGN_CALCSIZE) {
5545 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5547 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5548 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5549 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5553 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5554 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5560 if (lpnmh->code == PGN_SCROLL) {
5561 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5563 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5564 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5565 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5566 lppgs->iScroll, lppgs->iDir);
5571 TRACE("passing WM_NOTIFY!\n");
5573 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5574 if (infoPtr->bNtfUnicode)
5575 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5578 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5582 if (lpnmh->code == TTN_GETDISPINFOA) {
5583 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5585 FIXME("retrieving ASCII string\n");
5588 else if (lpnmh->code == TTN_GETDISPINFOW) {
5589 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5591 FIXME("retrieving UNICODE string\n");
5602 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5604 /* remove this routine when Toolbar is improved to pass infoPtr
5605 * around instead of hwnd.
5607 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5608 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5613 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5617 if (lParam == NF_REQUERY) {
5618 i = SendMessageA(infoPtr->hwndNotify,
5619 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5620 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5621 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5625 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5628 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5633 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5639 /* fill ps.rcPaint with a default rect */
5640 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5642 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5644 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5645 ps.rcPaint.left, ps.rcPaint.top,
5646 ps.rcPaint.right, ps.rcPaint.bottom);
5648 TOOLBAR_Refresh (hwnd, hdc, &ps);
5649 if (!wParam) EndPaint (hwnd, &ps);
5656 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5657 /*****************************************************
5660 * Handles the WM_SETREDRAW message.
5663 * According to testing V4.71 of COMCTL32 returns the
5664 * *previous* status of the redraw flag (either 0 or 1)
5665 * instead of the MSDN documented value of 0 if handled.
5666 * (For laughs see the "consistency" with same function
5669 *****************************************************/
5671 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5672 BOOL oldredraw = infoPtr->bDoRedraw;
5674 TRACE("set to %s\n",
5675 (wParam) ? "TRUE" : "FALSE");
5676 infoPtr->bDoRedraw = (BOOL) wParam;
5678 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5680 return (oldredraw) ? 1 : 0;
5685 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5688 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5697 /* Resize deadlock check */
5698 if (infoPtr->bAutoSize) {
5699 infoPtr->bAutoSize = FALSE;
5703 /* FIXME: optimize to only update size if the new size doesn't */
5704 /* match the current size */
5706 flags = (INT) wParam;
5708 /* FIXME for flags =
5709 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5712 TRACE("sizing toolbar!\n");
5714 if (flags == SIZE_RESTORED) {
5715 /* width and height don't apply */
5716 parent = GetParent (hwnd);
5717 GetClientRect(parent, &parent_rect);
5718 x = parent_rect.left;
5719 y = parent_rect.top;
5721 if (dwStyle & CCS_NORESIZE) {
5722 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5725 * this sets the working width of the toolbar, and
5726 * Calc Toolbar will not adjust it, only the height
5728 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5729 cy = infoPtr->nHeight;
5730 cx = infoPtr->nWidth;
5731 TOOLBAR_CalcToolbar (hwnd);
5732 infoPtr->nWidth = cx;
5733 infoPtr->nHeight = cy;
5736 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5737 TOOLBAR_CalcToolbar (hwnd);
5738 cy = infoPtr->nHeight;
5739 cx = infoPtr->nWidth;
5741 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
5742 GetWindowRect(hwnd, &window_rect);
5743 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5744 y = window_rect.top;
5746 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
5747 GetWindowRect(hwnd, &window_rect);
5748 y = parent_rect.bottom -
5749 ( window_rect.bottom - window_rect.top);
5753 if (dwStyle & CCS_NOPARENTALIGN) {
5754 uPosFlags |= SWP_NOMOVE;
5755 cy = infoPtr->nHeight;
5756 cx = infoPtr->nWidth;
5759 if (!(dwStyle & CCS_NODIVIDER))
5760 cy += GetSystemMetrics(SM_CYEDGE);
5762 if (dwStyle & WS_BORDER)
5765 cy += GetSystemMetrics(SM_CYEDGE);
5766 cx += GetSystemMetrics(SM_CYEDGE);
5769 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
5771 RECT delta_width, delta_height, client, dummy;
5772 DWORD min_x, max_x, min_y, max_y;
5773 TBUTTON_INFO *btnPtr;
5776 GetClientRect(hwnd, &client);
5777 if(client.right > infoPtr->client_rect.right)
5779 min_x = infoPtr->client_rect.right;
5780 max_x = client.right;
5784 max_x = infoPtr->client_rect.right;
5785 min_x = client.right;
5787 if(client.bottom > infoPtr->client_rect.bottom)
5789 min_y = infoPtr->client_rect.bottom;
5790 max_y = client.bottom;
5794 max_y = infoPtr->client_rect.bottom;
5795 min_y = client.bottom;
5798 SetRect(&delta_width, min_x, 0, max_x, min_y);
5799 SetRect(&delta_height, 0, min_y, max_x, max_y);
5801 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
5802 btnPtr = infoPtr->buttons;
5803 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
5804 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
5805 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
5806 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5809 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
5810 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
5812 GetClientRect(hwnd, &infoPtr->client_rect);
5818 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5820 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5822 if (nType == GWL_STYLE) {
5823 if (lpStyle->styleNew & TBSTYLE_LIST) {
5824 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5827 infoPtr->dwDTFlags = DT_CENTER;
5829 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5830 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5831 (TBSTYLE_FLAT | TBSTYLE_LIST));
5832 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5834 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
5837 TOOLBAR_CalcToolbar(hwnd);
5839 TOOLBAR_AutoSize (hwnd);
5841 InvalidateRect(hwnd, NULL, FALSE);
5848 TOOLBAR_SysColorChange (HWND hwnd)
5850 COMCTL32_RefreshSysColors();
5857 static LRESULT WINAPI
5858 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5860 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5862 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
5863 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5865 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5866 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5871 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5873 case TB_ADDBUTTONSA:
5874 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5876 case TB_ADDBUTTONSW:
5877 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5880 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5883 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5886 return TOOLBAR_AutoSize (hwnd);
5888 case TB_BUTTONCOUNT:
5889 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5891 case TB_BUTTONSTRUCTSIZE:
5892 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5894 case TB_CHANGEBITMAP:
5895 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5897 case TB_CHECKBUTTON:
5898 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5900 case TB_COMMANDTOINDEX:
5901 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5904 return TOOLBAR_Customize (hwnd);
5906 case TB_DELETEBUTTON:
5907 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5909 case TB_ENABLEBUTTON:
5910 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5912 case TB_GETANCHORHIGHLIGHT:
5913 return TOOLBAR_GetAnchorHighlight (hwnd);
5916 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5918 case TB_GETBITMAPFLAGS:
5919 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5922 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5924 case TB_GETBUTTONINFOA:
5925 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5927 case TB_GETBUTTONINFOW:
5928 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5930 case TB_GETBUTTONSIZE:
5931 return TOOLBAR_GetButtonSize (hwnd);
5933 case TB_GETBUTTONTEXTA:
5934 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5936 case TB_GETBUTTONTEXTW:
5937 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5939 case TB_GETDISABLEDIMAGELIST:
5940 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5942 case TB_GETEXTENDEDSTYLE:
5943 return TOOLBAR_GetExtendedStyle (hwnd);
5945 case TB_GETHOTIMAGELIST:
5946 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5949 return TOOLBAR_GetHotItem (hwnd);
5951 case TB_GETIMAGELIST:
5952 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
5954 /* case TB_GETINSERTMARK: */ /* 4.71 */
5955 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5957 case TB_GETITEMRECT:
5958 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5961 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5963 /* case TB_GETOBJECT: */ /* 4.71 */
5966 return TOOLBAR_GetPadding (hwnd);
5969 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5972 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5975 return TOOLBAR_GetState (hwnd, wParam, lParam);
5978 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
5981 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
5984 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5986 case TB_GETTEXTROWS:
5987 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5989 case TB_GETTOOLTIPS:
5990 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5992 case TB_GETUNICODEFORMAT:
5993 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5996 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5999 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6001 case TB_INDETERMINATE:
6002 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6004 case TB_INSERTBUTTONA:
6005 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6007 case TB_INSERTBUTTONW:
6008 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6010 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6012 case TB_ISBUTTONCHECKED:
6013 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6015 case TB_ISBUTTONENABLED:
6016 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6018 case TB_ISBUTTONHIDDEN:
6019 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6021 case TB_ISBUTTONHIGHLIGHTED:
6022 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6024 case TB_ISBUTTONINDETERMINATE:
6025 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6027 case TB_ISBUTTONPRESSED:
6028 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6030 case TB_LOADIMAGES: /* 4.70 */
6031 FIXME("missing standard imagelists\n");
6034 /* case TB_MAPACCELERATORA: */ /* 4.71 */
6035 /* case TB_MAPACCELERATORW: */ /* 4.71 */
6036 /* case TB_MARKBUTTON: */ /* 4.71 */
6037 /* case TB_MOVEBUTTON: */ /* 4.71 */
6039 case TB_PRESSBUTTON:
6040 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6042 case TB_REPLACEBITMAP:
6043 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6045 case TB_SAVERESTOREA:
6046 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6048 case TB_SAVERESTOREW:
6049 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6051 case TB_SETANCHORHIGHLIGHT:
6052 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6054 case TB_SETBITMAPSIZE:
6055 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6057 case TB_SETBUTTONINFOA:
6058 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6060 case TB_SETBUTTONINFOW:
6061 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6063 case TB_SETBUTTONSIZE:
6064 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6066 case TB_SETBUTTONWIDTH:
6067 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6070 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6072 case TB_SETDISABLEDIMAGELIST:
6073 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6075 case TB_SETDRAWTEXTFLAGS:
6076 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6078 case TB_SETEXTENDEDSTYLE:
6079 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6081 case TB_SETHOTIMAGELIST:
6082 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6085 return TOOLBAR_SetHotItem (hwnd, wParam);
6087 case TB_SETIMAGELIST:
6088 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6091 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6093 /* case TB_SETINSERTMARK: */ /* 4.71 */
6095 case TB_SETINSERTMARKCOLOR:
6096 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6098 case TB_SETMAXTEXTROWS:
6099 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6102 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6105 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6108 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6111 return TOOLBAR_SetState (hwnd, wParam, lParam);
6114 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6116 case TB_SETTOOLTIPS:
6117 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6119 case TB_SETUNICODEFORMAT:
6120 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6123 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6126 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6129 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6132 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6135 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6138 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6140 /* Common Control Messages */
6142 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6143 case CCM_GETCOLORSCHEME:
6144 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6146 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6147 case CCM_SETCOLORSCHEME:
6148 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6150 case CCM_GETVERSION:
6151 return TOOLBAR_GetVersion (hwnd);
6153 case CCM_SETVERSION:
6154 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6160 return TOOLBAR_Create (hwnd, wParam, lParam);
6163 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6166 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6169 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6171 /* case WM_KEYDOWN: */
6172 /* case WM_KILLFOCUS: */
6174 case WM_LBUTTONDBLCLK:
6175 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6177 case WM_LBUTTONDOWN:
6178 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6181 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6184 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6187 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6189 case WM_CAPTURECHANGED:
6190 return TOOLBAR_CaptureChanged(hwnd);
6193 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6196 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6199 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6202 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6205 return TOOLBAR_Notify (hwnd, wParam, lParam);
6207 case WM_NOTIFYFORMAT:
6208 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6211 return TOOLBAR_Paint (hwnd, wParam);
6214 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6217 return TOOLBAR_Size (hwnd, wParam, lParam);
6219 case WM_STYLECHANGED:
6220 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6222 case WM_SYSCOLORCHANGE:
6223 return TOOLBAR_SysColorChange (hwnd);
6225 /* case WM_WININICHANGE: */
6230 case WM_MEASUREITEM:
6232 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6234 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6235 case PGM_FORWARDMOUSE:
6236 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6239 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6240 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6241 uMsg, wParam, lParam);
6242 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6249 TOOLBAR_Register (void)
6253 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6254 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6255 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6256 wndClass.cbClsExtra = 0;
6257 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6258 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6259 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6260 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6262 RegisterClassA (&wndClass);
6267 TOOLBAR_Unregister (void)
6269 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6272 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6277 /* Check if the entry already exists */
6278 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6280 /* If this is a new entry we must create it and insert into the array */
6285 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6288 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6289 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6304 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6308 for (i = 0; i < *cies; i++)
6318 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6326 for (i = 0; i < cies; i++)
6328 if (pies[i]->id == id)
6340 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6342 HIMAGELIST himlDef = 0;
6343 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6346 himlDef = pie->himl;
6352 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6354 if (infoPtr->bUnicode)
6355 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6362 nmtba.iItem = nmtb->iItem;
6363 nmtba.pszText = Buffer;
6364 nmtba.cchText = 256;
6365 ZeroMemory(nmtba.pszText, nmtba.cchText);
6367 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6369 int ccht = strlen(nmtba.pszText);
6371 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6372 nmtb->pszText, nmtb->cchText);
6374 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6383 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6384 int iItem, PCUSTOMBUTTON btnInfo)
6389 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6391 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);