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_DrawImageList
383 * This function validates the bitmap index (including I_IMAGECALLBACK
384 * functionality). It then draws the image via the ImageList_Draw
385 * function. It returns TRUE if the image was drawn, FALSE otherwise.
388 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, IMAGE_LIST_TYPE imagelist,
389 HDC hdc, UINT left, UINT top, UINT draw_flags)
394 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
395 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
396 ERR("index %d,%d is not valid, max %d\n",
397 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
401 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
402 if ((index == I_IMAGECALLBACK) ||
403 (index == I_IMAGENONE)) return FALSE;
404 ERR("TBN_GETDISPINFO returned invalid index %d\n",
411 case IMAGE_LIST_DEFAULT:
412 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
415 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
417 case IMAGE_LIST_DISABLED:
418 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
422 FIXME("Shouldn't reach here\n");
427 TRACE("no image list, returning FALSE\n");
431 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
432 index, himl, left, top, draw_flags);
434 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
439 /***********************************************************************
440 * TOOLBAR_TestImageExist
442 * This function is similar to TOOLBAR_DrawImageList, except it does not
443 * draw the image. The I_IMAGECALLBACK functionality is implemented.
446 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
450 if (!himl) return FALSE;
452 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
453 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
454 ERR("index %d is not valid, max %d\n",
455 btnPtr->iBitmap, infoPtr->nNumBitmaps);
459 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
460 if ((index == I_IMAGECALLBACK) ||
461 (index == I_IMAGENONE)) return FALSE;
462 ERR("TBN_GETDISPINFO returned invalid index %d\n",
471 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
474 COLORREF oldcolor, newcolor;
476 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
477 myrect.right = myrect.left + 1;
478 myrect.top = lpRect->top + 2;
479 myrect.bottom = lpRect->bottom - 2;
481 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
482 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
483 oldcolor = SetBkColor (hdc, newcolor);
484 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
486 myrect.left = myrect.right;
487 myrect.right = myrect.left + 1;
489 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
490 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
491 SetBkColor (hdc, newcolor);
492 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
494 SetBkColor (hdc, oldcolor);
498 /***********************************************************************
499 * TOOLBAR_DrawDDFlatSeparator
501 * This function draws the separator that was flagged as BTNS_DROPDOWN.
502 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
503 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
504 * are horizontal as opposed to the vertical separators for not dropdown
507 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
510 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
513 COLORREF oldcolor, newcolor;
515 myrect.left = lpRect->left;
516 myrect.right = lpRect->right;
517 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
518 myrect.bottom = myrect.top + 1;
520 InflateRect (&myrect, -2, 0);
522 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
523 myrect.left, myrect.top, myrect.right, myrect.bottom);
525 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
526 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
527 oldcolor = SetBkColor (hdc, newcolor);
528 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
530 myrect.top = myrect.bottom;
531 myrect.bottom = myrect.top + 1;
533 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
534 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
535 SetBkColor (hdc, newcolor);
536 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
538 SetBkColor (hdc, oldcolor);
543 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
548 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
549 hOldPen = SelectObject ( hdc, hPen );
552 MoveToEx (hdc, x, y, NULL);
553 LineTo (hdc, x+5, y++); x++;
554 MoveToEx (hdc, x, y, NULL);
555 LineTo (hdc, x+3, y++); x++;
556 MoveToEx (hdc, x, y, NULL);
557 LineTo (hdc, x+1, y++);
558 SelectObject( hdc, hOldPen );
559 DeleteObject( hPen );
563 * Draw the text string for this button.
564 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
565 * is non-zero, so we can simply check himlDef to see if we have
569 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, RECT *rcText, LPWSTR lpText,
570 NMTBCUSTOMDRAW *tbcd)
574 UINT state = tbcd->nmcd.uItemState;
575 HDC hdc = tbcd->nmcd.hdc;
579 TRACE("string=%s rect=(%ld,%ld)-(%ld,%ld)\n", debugstr_w(lpText),
580 rcText->left, rcText->top, rcText->right, rcText->bottom);
582 hOldFont = SelectObject (hdc, infoPtr->hFont);
583 if ((state & CDIS_HOT) && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
584 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
586 else if (state & CDIS_DISABLED) {
587 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
588 OffsetRect (rcText, 1, 1);
589 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
590 SetTextColor (hdc, comctl32_color.clr3dShadow);
591 OffsetRect (rcText, -1, -1);
593 else if (state & CDIS_INDETERMINATE) {
594 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
597 clrOld = SetTextColor (hdc, tbcd->clrText);
600 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
601 SetTextColor (hdc, clrOld);
602 SelectObject (hdc, hOldFont);
608 TOOLBAR_DrawPattern (LPRECT lpRect, NMTBCUSTOMDRAW *tbcd)
610 HDC hdc = tbcd->nmcd.hdc;
611 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
612 INT cx = lpRect->right - lpRect->left;
613 INT cy = lpRect->bottom - lpRect->top;
614 SetTextColor(hdc, tbcd->clrBtnHighlight);
615 SetBkColor(hdc, tbcd->clrBtnFace);
616 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, PATCOPY);
617 SelectObject (hdc, hbr);
621 static void TOOLBAR_DrawMasked(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
622 HDC hdc, INT x, INT y)
624 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0);
629 HBITMAP hbmMask, hbmImage;
630 HDC hdcMask, hdcImage;
632 ImageList_GetIconSize(himl, &cx, &cy);
634 /* Create src image */
635 hdcImage = CreateCompatibleDC(hdc);
636 hbmImage = CreateBitmap(cx, cy, GetDeviceCaps(hdc,PLANES),
637 GetDeviceCaps(hdc,BITSPIXEL), NULL);
638 SelectObject(hdcImage, hbmImage);
639 ImageList_DrawEx(himl, btnPtr->iBitmap, hdcImage, 0, 0, cx, cy,
640 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_NORMAL);
643 hdcMask = CreateCompatibleDC(0);
644 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
645 SelectObject(hdcMask, hbmMask);
647 /* Remove the background and all white pixels */
648 SetBkColor(hdcImage, ImageList_GetBkColor(himl));
649 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, SRCCOPY);
650 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
651 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
653 /* draw the new mask 'etched' to hdc */
654 SetBkColor(hdc, RGB(255, 255, 255));
655 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
656 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
657 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
658 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
661 DeleteObject(hbmImage);
663 DeleteObject (hbmMask);
670 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
674 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
675 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
676 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
677 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
678 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
679 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
680 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
681 /* don't test TBSTATE_HIDDEN */
687 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
689 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
690 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
691 BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
692 (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
693 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
694 BOOL drawSepDropDownArrow = hasDropDownArrow &&
695 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
696 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
697 LPWSTR lpText = NULL;
702 if (btnPtr->fsState & TBSTATE_HIDDEN)
706 CopyRect (&rcFill, &rc);
707 CopyRect (&rcArrow, &rc);
708 CopyRect(&rcBitmap, &rc);
710 /* get a pointer to the text */
711 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
713 if (hasDropDownArrow)
717 if (dwStyle & TBSTYLE_FLAT)
718 right = max(rc.left, rc.right - DDARROW_WIDTH);
720 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
722 if (drawSepDropDownArrow)
725 rcArrow.left = right;
728 /* copy text rect after adjusting for drop-down arrow
729 * so that text is centred in the rectangle not containing
731 CopyRect(&rcText, &rc);
733 /* Center the bitmap horizontally and vertically */
734 if (dwStyle & TBSTYLE_LIST)
735 rcBitmap.left += LIST_IMAGE_OFFSET;
737 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
740 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
742 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
744 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
745 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
746 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
747 TRACE ("iString: %x\n", btnPtr->iString);
748 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
753 InflateRect (&rcText, -3, -3);
755 if (GETDEFIMAGELIST(infoPtr, 0) &&
756 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
757 /* The following test looked like this before
758 * I changed it. IE4 "Links" toolbar would not
759 * draw correctly with the original code. - GA 8/01
760 * ((dwStyle & TBSTYLE_LIST) &&
761 * ((btnPtr->fsStyle & BTNS_AUTOSIZE) == 0) &&
762 * (btnPtr->iBitmap != I_IMAGENONE))
764 if (dwStyle & TBSTYLE_LIST) {
765 /* LIST style w/ ICON offset is by matching native. */
766 /* Matches IE4 "Links" bar. - GA 8/01 */
767 rcText.left += (infoPtr->nBitmapWidth + LIST_TEXT_OFFSET);
770 rcText.top += infoPtr->nBitmapHeight + 1;
774 if (dwStyle & TBSTYLE_LIST) {
775 /* LIST style w/o ICON offset is by matching native. */
776 /* Matches IE4 "menu" bar. - GA 8/01 */
777 rcText.left += LIST_IMAGE_ABSENT_WIDTH + LIST_TEXT_OFFSET;
781 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
782 OffsetRect (&rcText, 1, 1);
785 /* Initialize fields in all cases, because we use these later */
786 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
787 tbcd.clrText = comctl32_color.clrBtnText;
788 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
789 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
790 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
791 tbcd.clrMark = comctl32_color.clrHighlight;
792 tbcd.clrHighlightHotTrack = 0;
793 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
794 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
795 /* MSDN says that this is the text rectangle. */
796 /* But (why always a but) tracing of v5.7 of native shows */
797 /* that this is really a *relative* rectangle based on the */
798 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
799 /* any bitmap that might be present. */
800 tbcd.rcText.left = 0;
802 tbcd.rcText.right = rcText.right - rc.left;
803 tbcd.rcText.bottom = rcText.bottom - rc.top;
804 /* we use this state later on to decide how to draw the buttons */
805 /* NOTE: applications can and do alter this to customize their */
807 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
809 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
811 /* FIXME: what should these be set to ????? */
815 /* Issue Item Prepaint notify */
816 infoPtr->dwItemCustDraw = 0;
817 infoPtr->dwItemCDFlag = 0;
818 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
820 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
822 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
823 tbcd.nmcd.lItemlParam = btnPtr->dwData;
824 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
825 infoPtr->dwItemCustDraw = ntfret & 0xffff;
826 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
827 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
829 /* save the only part of the rect that the user can change */
830 rcText.right = tbcd.rcText.right + rc.left;
831 rcText.bottom = tbcd.rcText.bottom + rc.top;
834 if (!infoPtr->bBtnTranspnt)
835 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
838 if (btnPtr->fsStyle & BTNS_SEP) {
839 /* with the FLAT style, iBitmap is the width and has already */
840 /* been taken into consideration in calculating the width */
841 /* so now we need to draw the vertical separator */
842 /* empirical tests show that iBitmap can/will be non-zero */
843 /* when drawing the vertical bar... */
844 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
845 if (btnPtr->fsStyle & BTNS_DROPDOWN)
846 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
848 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
850 else if (btnPtr->fsStyle != BTNS_SEP) {
851 FIXME("Draw some kind of separator: fsStyle=%x\n",
857 if ((dwStyle & TBSTYLE_FLAT) && (tbcd.nmcd.uItemState & CDIS_HOT))
859 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
863 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
864 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
865 if (hasDropDownArrow)
866 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
867 SetBkColor(hdc, oldclr);
871 if (!(tbcd.nmcd.uItemState & CDIS_DISABLED) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
873 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
874 if (hasDropDownArrow)
875 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
881 if (tbcd.nmcd.uItemState & CDIS_DISABLED) {
882 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
884 DrawEdge (hdc, &rc, EDGE_RAISED,
885 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
886 if (drawSepDropDownArrow)
887 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
888 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
891 if (hasDropDownArrow)
893 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_3DHIGHLIGHT);
894 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_3DSHADOW);
897 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DISABLED,
898 hdc, rcBitmap.left, rcBitmap.top,
900 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
902 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
903 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
907 /* pressed BTNS_BUTTON */
908 if (tbcd.nmcd.uItemState & CDIS_SELECTED) {
909 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
910 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
912 if (dwStyle & TBSTYLE_FLAT)
914 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
915 if (drawSepDropDownArrow)
916 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
920 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
921 if (drawSepDropDownArrow)
922 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
926 if (hasDropDownArrow)
927 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_WINDOWFRAME);
929 TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DEFAULT,
930 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
933 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
934 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
938 /* checked BTNS_CHECK */
939 if ((tbcd.nmcd.uItemState & CDIS_CHECKED) &&
940 (btnPtr->fsStyle & BTNS_CHECK)) {
941 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
943 if (dwStyle & TBSTYLE_FLAT)
944 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
945 BF_RECT | BF_ADJUST);
947 DrawEdge (hdc, &rc, EDGE_SUNKEN,
948 BF_RECT | BF_MIDDLE | BF_ADJUST);
951 TOOLBAR_DrawPattern (&rc, &tbcd);
953 TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DEFAULT,
954 hdc, rcBitmap.left+1, rcBitmap.top+1,
957 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
958 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
963 if (tbcd.nmcd.uItemState & CDIS_INDETERMINATE) {
964 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
965 DrawEdge (hdc, &rc, EDGE_RAISED,
966 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
968 TOOLBAR_DrawPattern (&rc, &tbcd);
969 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
970 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
971 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
976 if (dwStyle & TBSTYLE_FLAT)
978 if (hasDropDownArrow)
979 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_WINDOWFRAME);
981 if (tbcd.nmcd.uItemState & CDIS_HOT) {
982 /* if hot, attempt to draw with hot image list, if fails,
983 use default image list */
984 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
987 rcBitmap.top, ILD_NORMAL))
988 TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DEFAULT,
989 hdc, rcBitmap.left, rcBitmap.top,
993 TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DEFAULT,
994 hdc, rcBitmap.left, rcBitmap.top,
999 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
1000 DrawEdge (hdc, &rc, EDGE_RAISED,
1001 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
1003 if (hasDropDownArrow)
1005 if (drawSepDropDownArrow && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
1006 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
1007 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
1008 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_WINDOWFRAME);
1011 TOOLBAR_DrawImageList (infoPtr, btnPtr, IMAGE_LIST_DEFAULT,
1012 hdc, rcBitmap.left, rcBitmap.top,
1017 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1018 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd);
1021 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1023 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1024 tbcd.nmcd.hdc = hdc;
1026 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1027 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1028 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1029 tbcd.rcText = rcText;
1030 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1031 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
1032 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1039 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
1041 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1042 TBUTTON_INFO *btnPtr;
1043 INT i, oldBKmode = 0;
1044 RECT rcTemp, rcClient;
1045 NMTBCUSTOMDRAW tbcd;
1048 /* if imagelist belongs to the app, it can be changed
1049 by the app after setting it */
1050 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1052 infoPtr->nNumBitmaps = 0;
1053 for (i = 0; i < infoPtr->cimlDef; i++)
1054 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1057 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1059 /* Send initial notify */
1060 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1061 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1062 tbcd.nmcd.hdc = hdc;
1063 tbcd.nmcd.rc = ps->rcPaint;
1064 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1065 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1067 if (infoPtr->bBtnTranspnt)
1068 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1070 GetClientRect(hwnd, &rcClient);
1072 /* redraw necessary buttons */
1073 btnPtr = infoPtr->buttons;
1074 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1077 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1079 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1080 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1084 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1086 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1089 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1090 SetBkMode (hdc, oldBKmode);
1092 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1094 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1095 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1096 tbcd.nmcd.hdc = hdc;
1097 tbcd.nmcd.rc = ps->rcPaint;
1098 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1102 /***********************************************************************
1103 * TOOLBAR_MeasureString
1105 * This function gets the width and height of a string in pixels. This
1106 * is done first by using GetTextExtentPoint to get the basic width
1107 * and height. The DrawText is called with DT_CALCRECT to get the exact
1108 * width. The reason is because the text may have more than one "&" (or
1109 * prefix characters as M$ likes to call them). The prefix character
1110 * indicates where the underline goes, except for the string "&&" which
1111 * is reduced to a single "&". GetTextExtentPoint does not process these
1112 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1115 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1116 HDC hdc, LPSIZE lpSize)
1123 if (infoPtr->nMaxTextRows > 0 &&
1124 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1125 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1126 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1128 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1130 if(lpText != NULL) {
1131 /* first get size of all the text */
1132 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1134 /* feed above size into the rectangle for DrawText */
1135 myrect.left = myrect.top = 0;
1136 myrect.right = lpSize->cx;
1137 myrect.bottom = lpSize->cy;
1139 /* Use DrawText to get true size as drawn (less pesky "&") */
1140 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1141 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1144 /* feed back to caller */
1145 lpSize->cx = myrect.right;
1146 lpSize->cy = myrect.bottom;
1150 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1153 /***********************************************************************
1154 * TOOLBAR_CalcStrings
1156 * This function walks through each string and measures it and returns
1157 * the largest height and width to caller.
1160 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1162 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1163 TBUTTON_INFO *btnPtr;
1172 if(infoPtr->nMaxTextRows == 0)
1176 hOldFont = SelectObject (hdc, infoPtr->hFont);
1178 btnPtr = infoPtr->buttons;
1179 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1180 if(TOOLBAR_HasText(infoPtr, btnPtr))
1182 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1183 if (sz.cx > lpSize->cx)
1185 if (sz.cy > lpSize->cy)
1190 SelectObject (hdc, hOldFont);
1191 ReleaseDC (hwnd, hdc);
1193 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1196 /***********************************************************************
1197 * TOOLBAR_WrapToolbar
1199 * This function walks through the buttons and separators in the
1200 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1201 * wrapping should occur based on the width of the toolbar window.
1202 * It does *not* calculate button placement itself. That task
1203 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1204 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1205 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1207 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1208 * vertical toolbar lists.
1212 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1214 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1215 TBUTTON_INFO *btnPtr;
1218 BOOL bWrap, bButtonWrap;
1220 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1221 /* no layout is necessary. Applications may use this style */
1222 /* to perform their own layout on the toolbar. */
1223 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1224 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1226 btnPtr = infoPtr->buttons;
1227 x = infoPtr->nIndent;
1229 /* this can get the parents width, to know how far we can extend
1230 * this toolbar. We cannot use its height, as there may be multiple
1231 * toolbars in a rebar control
1233 GetClientRect( GetParent(hwnd), &rc );
1234 infoPtr->nWidth = rc.right - rc.left;
1235 bButtonWrap = FALSE;
1237 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1238 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1241 for (i = 0; i < infoPtr->nNumButtons; i++ )
1244 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1246 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1249 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1250 /* it is the actual width of the separator. This is used for */
1251 /* custom controls in toolbars. */
1253 /* BTNS_DROPDOWN separators are treated as buttons for */
1254 /* width. - GA 8/01 */
1255 if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1256 !(btnPtr[i].fsStyle & BTNS_DROPDOWN))
1257 cx = (btnPtr[i].iBitmap > 0) ?
1258 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1260 cx = infoPtr->nButtonWidth;
1262 /* Two or more adjacent separators form a separator group. */
1263 /* The first separator in a group should be wrapped to the */
1264 /* next row if the previous wrapping is on a button. */
1266 (btnPtr[i].fsStyle & BTNS_SEP) &&
1267 (i + 1 < infoPtr->nNumButtons ) &&
1268 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1270 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1271 btnPtr[i].fsState |= TBSTATE_WRAP;
1272 x = infoPtr->nIndent;
1274 bButtonWrap = FALSE;
1278 /* The layout makes sure the bitmap is visible, but not the button. */
1279 /* Test added to also wrap after a button that starts a row but */
1280 /* is bigger than the area. - GA 8/01 */
1281 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1282 > infoPtr->nWidth ) ||
1283 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1285 BOOL bFound = FALSE;
1287 /* If the current button is a separator and not hidden, */
1288 /* go to the next until it reaches a non separator. */
1289 /* Wrap the last separator if it is before a button. */
1290 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1291 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1292 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1293 i < infoPtr->nNumButtons )
1299 if( bFound && i < infoPtr->nNumButtons )
1302 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1303 i, btnPtr[i].fsStyle, x, cx);
1304 btnPtr[i].fsState |= TBSTATE_WRAP;
1305 x = infoPtr->nIndent;
1306 bButtonWrap = FALSE;
1309 else if ( i >= infoPtr->nNumButtons)
1312 /* If the current button is not a separator, find the last */
1313 /* separator and wrap it. */
1314 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1316 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1317 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1321 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1322 i, btnPtr[i].fsStyle, x, cx);
1323 x = infoPtr->nIndent;
1324 btnPtr[j].fsState |= TBSTATE_WRAP;
1325 bButtonWrap = FALSE;
1330 /* If no separator available for wrapping, wrap one of */
1331 /* non-hidden previous button. */
1335 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1337 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1342 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1343 i, btnPtr[i].fsStyle, x, cx);
1344 x = infoPtr->nIndent;
1345 btnPtr[j].fsState |= TBSTATE_WRAP;
1351 /* If all above failed, wrap the current button. */
1354 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1355 i, btnPtr[i].fsStyle, x, cx);
1356 btnPtr[i].fsState |= TBSTATE_WRAP;
1358 x = infoPtr->nIndent;
1359 if (btnPtr[i].fsStyle & BTNS_SEP )
1360 bButtonWrap = FALSE;
1366 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1367 i, btnPtr[i].fsStyle, x, cx);
1374 /***********************************************************************
1375 * TOOLBAR_CalcToolbar
1377 * This function calculates button and separator placement. It first
1378 * calculates the button sizes, gets the toolbar window width and then
1379 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1380 * on. It assigns a new location to each item and sends this location to
1381 * the tooltip window if appropriate. Finally, it updates the rcBound
1382 * rect and calculates the new required toolbar window height.
1386 TOOLBAR_CalcToolbar (HWND hwnd)
1388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1389 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1390 TBUTTON_INFO *btnPtr;
1391 INT i, nRows, nSepRows;
1395 BOOL usesBitmaps = FALSE;
1396 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1398 TOOLBAR_CalcStrings (hwnd, &sizeString);
1400 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1402 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1405 if (dwStyle & TBSTYLE_LIST)
1407 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1408 0, sizeString.cy) + infoPtr->szPadding.cy;
1409 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1410 0) + sizeString.cx + 6;
1411 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1412 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1413 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1414 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1417 if (sizeString.cy > 0)
1420 infoPtr->nButtonHeight = sizeString.cy +
1421 2 + /* this is the space to separate text from bitmap */
1422 infoPtr->nBitmapHeight + 6;
1424 infoPtr->nButtonHeight = sizeString.cy + 6;
1427 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1429 if (sizeString.cx > infoPtr->nBitmapWidth)
1430 infoPtr->nButtonWidth = sizeString.cx + 6;
1432 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1435 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1436 infoPtr->nButtonWidth = infoPtr->cxMin;
1437 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1438 infoPtr->nButtonWidth = infoPtr->cxMax;
1440 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1442 x = infoPtr->nIndent;
1446 * We will set the height below, and we set the width on entry
1447 * so we do not reset them here..
1450 GetClientRect( hwnd, &rc );
1451 /* get initial values for toolbar */
1452 infoPtr->nWidth = rc.right - rc.left;
1453 infoPtr->nHeight = rc.bottom - rc.top;
1456 /* from above, minimum is a button, and possible text */
1457 cx = infoPtr->nButtonWidth;
1459 /* cannot use just ButtonHeight, we may have no buttons! */
1460 if (infoPtr->nNumButtons > 0)
1461 infoPtr->nHeight = infoPtr->nButtonHeight;
1463 cy = infoPtr->nHeight;
1465 nRows = nSepRows = 0;
1467 infoPtr->rcBound.top = y;
1468 infoPtr->rcBound.left = x;
1469 infoPtr->rcBound.bottom = y + cy;
1470 infoPtr->rcBound.right = x;
1472 btnPtr = infoPtr->buttons;
1474 /* do not base height/width on parent, if the parent is a */
1475 /* rebar control it could have multiple rows of toolbars */
1476 /* GetClientRect( GetParent(hwnd), &rc ); */
1477 /* cx = rc.right - rc.left; */
1478 /* cy = rc.bottom - rc.top; */
1480 TRACE("cy=%d\n", cy);
1482 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1485 if (btnPtr->fsState & TBSTATE_HIDDEN)
1487 SetRectEmpty (&btnPtr->rect);
1491 cy = infoPtr->nHeight;
1493 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1494 /* it is the actual width of the separator. This is used for */
1495 /* custom controls in toolbars. */
1496 if (btnPtr->fsStyle & BTNS_SEP) {
1497 if (btnPtr->fsStyle & BTNS_DROPDOWN) {
1498 cy = (btnPtr->iBitmap > 0) ?
1499 btnPtr->iBitmap : SEPARATOR_WIDTH;
1500 cx = infoPtr->nButtonWidth;
1503 cx = (btnPtr->iBitmap > 0) ?
1504 btnPtr->iBitmap : SEPARATOR_WIDTH;
1508 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1509 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1516 hOldFont = SelectObject (hdc, infoPtr->hFont);
1518 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1520 SelectObject (hdc, hOldFont);
1521 ReleaseDC (hwnd, hdc);
1524 sz.cx += 2*LIST_TEXT_OFFSET;
1525 cx = sz.cx + 2*LIST_IMAGE_OFFSET;
1526 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1528 if (dwStyle & TBSTYLE_LIST)
1529 cx += infoPtr->nBitmapWidth;
1530 else if (cx < (infoPtr->nBitmapWidth+7))
1531 cx = infoPtr->nBitmapWidth+7;
1533 else if (dwStyle & TBSTYLE_LIST)
1534 cx += LIST_IMAGE_ABSENT_WIDTH;
1537 cx = infoPtr->nButtonWidth;
1539 if ((hasDropDownArrows && (btnPtr->fsStyle & BTNS_DROPDOWN)) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN))
1540 cx += DDARROW_WIDTH;
1542 if (btnPtr->fsState & TBSTATE_WRAP )
1545 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1547 if (infoPtr->rcBound.left > x)
1548 infoPtr->rcBound.left = x;
1549 if (infoPtr->rcBound.right < x + cx)
1550 infoPtr->rcBound.right = x + cx;
1551 if (infoPtr->rcBound.bottom < y + cy)
1552 infoPtr->rcBound.bottom = y + cy;
1554 /* Set the toolTip only for non-hidden, non-separator button */
1555 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & BTNS_SEP ))
1559 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1560 ti.cbSize = sizeof(TTTOOLINFOA);
1562 ti.uId = btnPtr->idCommand;
1563 ti.rect = btnPtr->rect;
1564 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1568 /* btnPtr->nRow is zero based. The space between the rows is */
1569 /* also considered as a row. */
1570 btnPtr->nRow = nRows + nSepRows;
1572 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1573 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1578 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1582 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1583 /* it is the actual width of the separator. This is used for */
1584 /* custom controls in toolbars. */
1585 if ( !(btnPtr->fsStyle & BTNS_DROPDOWN))
1586 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1587 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1591 /* nSepRows is used to calculate the extra height follwoing */
1595 x = infoPtr->nIndent;
1597 /* Increment row number unless this is the last button */
1598 /* and it has Wrap set. */
1599 if (i != infoPtr->nNumButtons-1)
1606 /* infoPtr->nRows is the number of rows on the toolbar */
1607 infoPtr->nRows = nRows + nSepRows + 1;
1610 /********************************************************************
1611 * The following while interesting, does not match the values *
1612 * created above for the button rectangles, nor the rcBound rect. *
1613 * We will comment it out and remove it later. *
1615 * The problem showed up as heights in the pager control that was *
1617 ********************************************************************/
1619 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1621 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1622 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1623 nSepRows * (infoPtr->nBitmapHeight + 1) +
1627 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1629 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1634 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1636 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1637 TBUTTON_INFO *btnPtr;
1640 btnPtr = infoPtr->buttons;
1641 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1642 if (btnPtr->fsState & TBSTATE_HIDDEN)
1645 if (btnPtr->fsStyle & BTNS_SEP) {
1646 if (PtInRect (&btnPtr->rect, *lpPt)) {
1647 TRACE(" ON SEPARATOR %d!\n", i);
1652 if (PtInRect (&btnPtr->rect, *lpPt)) {
1653 TRACE(" ON BUTTON %d!\n", i);
1659 TRACE(" NOWHERE!\n");
1665 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1667 TBUTTON_INFO *btnPtr;
1670 if (CommandIsIndex) {
1671 TRACE("command is really index command=%d\n", idCommand);
1672 if (idCommand >= infoPtr->nNumButtons) return -1;
1675 btnPtr = infoPtr->buttons;
1676 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1677 if (btnPtr->idCommand == idCommand) {
1678 TRACE("command=%d index=%d\n", idCommand, i);
1682 TRACE("no index found for command=%d\n", idCommand);
1688 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1690 TBUTTON_INFO *btnPtr;
1693 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1696 /* check index button */
1697 btnPtr = &infoPtr->buttons[nIndex];
1698 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1699 if (btnPtr->fsState & TBSTATE_CHECKED)
1703 /* check previous buttons */
1704 nRunIndex = nIndex - 1;
1705 while (nRunIndex >= 0) {
1706 btnPtr = &infoPtr->buttons[nRunIndex];
1707 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1708 if (btnPtr->fsState & TBSTATE_CHECKED)
1716 /* check next buttons */
1717 nRunIndex = nIndex + 1;
1718 while (nRunIndex < infoPtr->nNumButtons) {
1719 btnPtr = &infoPtr->buttons[nRunIndex];
1720 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1721 if (btnPtr->fsState & TBSTATE_CHECKED)
1734 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1735 WPARAM wParam, LPARAM lParam)
1741 msg.wParam = wParam;
1742 msg.lParam = lParam;
1743 msg.time = GetMessageTime ();
1744 msg.pt.x = LOWORD(GetMessagePos ());
1745 msg.pt.y = HIWORD(GetMessagePos ());
1747 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1751 /***********************************************************************
1752 * TOOLBAR_CustomizeDialogProc
1753 * This function implements the toolbar customization dialog.
1755 static INT_PTR CALLBACK
1756 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1758 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1759 PCUSTOMBUTTON btnInfo;
1761 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1766 custInfo = (PCUSTDLG_INFO)lParam;
1767 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1775 infoPtr = custInfo->tbInfo;
1777 /* send TBN_QUERYINSERT notification */
1778 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1780 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1783 /* UNDOCUMENTED: dialog hwnd immediately follows NMHDR */
1784 nmtb.iItem = (int)hwnd;
1785 /* Send TBN_INITCUSTOMIZE notification */
1786 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1789 TRACE("TBNRF_HIDEHELP requested\n");
1790 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
1793 /* add items to 'toolbar buttons' list and check if removable */
1794 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1796 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1797 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1798 btnInfo->btn.fsStyle = BTNS_SEP;
1799 btnInfo->bVirtual = FALSE;
1800 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1802 /* send TBN_QUERYDELETE notification */
1803 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1805 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1806 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1809 /* insert separator button into 'available buttons' list */
1810 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1811 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1812 btnInfo->btn.fsStyle = BTNS_SEP;
1813 btnInfo->bVirtual = FALSE;
1814 btnInfo->bRemovable = TRUE;
1815 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1816 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1817 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1819 /* insert all buttons into dsa */
1822 /* send TBN_GETBUTTONINFO notification */
1825 nmtb.pszText = Buffer;
1828 /* Clear previous button's text */
1829 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1831 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1834 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1835 nmtb.tbButton.fsStyle, i,
1836 nmtb.tbButton.idCommand,
1837 nmtb.tbButton.iString,
1838 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1841 /* insert button into the apropriate list */
1842 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1845 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1846 btnInfo->bVirtual = FALSE;
1847 btnInfo->bRemovable = TRUE;
1849 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1850 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1851 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1855 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1856 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1859 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1860 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
1862 if (lstrlenW(nmtb.pszText))
1863 lstrcpyW(btnInfo->text, nmtb.pszText);
1864 else if (nmtb.tbButton.iString >= 0 &&
1865 nmtb.tbButton.iString < infoPtr->nNumStrings)
1867 lstrcpyW(btnInfo->text,
1868 infoPtr->strings[nmtb.tbButton.iString]);
1873 /* select first item in the 'available' list */
1874 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1876 /* append 'virtual' separator button to the 'toolbar buttons' list */
1877 btnInfo = (PCUSTOMBUTTON)Alloc(sizeof(CUSTOMBUTTON));
1878 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1879 btnInfo->btn.fsStyle = BTNS_SEP;
1880 btnInfo->bVirtual = TRUE;
1881 btnInfo->bRemovable = FALSE;
1882 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1883 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1884 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1886 /* select last item in the 'toolbar' list */
1887 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1888 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1890 /* set focus and disable buttons */
1891 PostMessageA (hwnd, WM_USER, 0, 0);
1896 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1897 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1898 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1899 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1903 EndDialog(hwnd, FALSE);
1907 switch (LOWORD(wParam))
1909 case IDC_TOOLBARBTN_LBOX:
1910 if (HIWORD(wParam) == LBN_SELCHANGE)
1912 PCUSTOMBUTTON btnInfo;
1917 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1918 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1920 /* send TBN_QUERYINSERT notification */
1922 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1925 /* get list box item */
1926 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1928 if (index == (count - 1))
1930 /* last item (virtual separator) */
1931 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1932 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1934 else if (index == (count - 2))
1936 /* second last item (last non-virtual item) */
1937 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1938 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1940 else if (index == 0)
1943 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1944 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1948 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1949 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1952 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1956 case IDC_MOVEUP_BTN:
1958 PCUSTOMBUTTON btnInfo;
1962 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1963 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1964 TRACE("Move up: index %d\n", index);
1966 /* send TBN_QUERYINSERT notification */
1969 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1972 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1974 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1975 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1976 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1977 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1980 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1981 else if (index >= (count - 3))
1982 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1984 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1985 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1990 case IDC_MOVEDN_BTN: /* move down */
1992 PCUSTOMBUTTON btnInfo;
1996 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1997 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1998 TRACE("Move up: index %d\n", index);
2000 /* send TBN_QUERYINSERT notification */
2002 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2005 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2007 /* move button down */
2008 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2009 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
2010 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
2011 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
2014 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2015 else if (index >= (count - 3))
2016 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2018 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2019 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
2024 case IDC_REMOVE_BTN: /* remove button */
2026 PCUSTOMBUTTON btnInfo;
2029 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2031 if (LB_ERR == index)
2034 TRACE("Remove: index %d\n", index);
2036 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
2037 LB_GETITEMDATA, index, 0);
2039 /* send TBN_QUERYDELETE notification */
2040 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
2042 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2043 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
2044 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
2046 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2048 /* insert into 'available button' list */
2049 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2051 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
2052 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2060 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2063 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2066 case IDOK: /* Add button */
2071 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2072 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2073 TRACE("Add: index %d\n", index);
2075 /* send TBN_QUERYINSERT notification */
2077 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
2080 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
2084 /* remove from 'available buttons' list */
2085 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
2086 if (index == count-1)
2087 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2089 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2093 PCUSTOMBUTTON btnNew;
2095 /* duplicate 'separator' button */
2096 btnNew = (PCUSTOMBUTTON)Alloc (sizeof(CUSTOMBUTTON));
2097 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2101 /* insert into 'toolbar button' list */
2102 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2103 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2104 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2106 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2112 EndDialog(hwnd, FALSE);
2122 /* delete items from 'toolbar buttons' listbox*/
2123 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2124 for (i = 0; i < count; i++)
2126 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2128 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2130 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2133 /* delete items from 'available buttons' listbox*/
2134 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2135 for (i = 0; i < count; i++)
2137 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2139 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2141 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2146 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2148 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2149 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2154 COLORREF oldText = 0;
2158 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2159 if (btnInfo == NULL)
2161 FIXME("btnInfo invalid!\n");
2165 /* set colors and select objects */
2166 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2167 if (btnInfo->bVirtual)
2168 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2170 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2171 hPen = CreatePen( PS_SOLID, 1,
2172 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2173 hOldPen = SelectObject (lpdis->hDC, hPen );
2174 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2176 /* fill background rectangle */
2177 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2178 lpdis->rcItem.right, lpdis->rcItem.bottom);
2180 /* calculate button and text rectangles */
2181 CopyRect (&rcButton, &lpdis->rcItem);
2182 InflateRect (&rcButton, -1, -1);
2183 CopyRect (&rcText, &rcButton);
2184 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2185 rcText.left = rcButton.right + 2;
2187 /* draw focus rectangle */
2188 if (lpdis->itemState & ODS_FOCUS)
2189 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2192 if (!(dwStyle & TBSTYLE_FLAT))
2193 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2195 /* draw image and text */
2196 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2197 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2198 btnInfo->btn.iBitmap));
2199 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2200 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2202 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2203 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2205 /* delete objects and reset colors */
2206 SelectObject (lpdis->hDC, hOldBrush);
2207 SelectObject (lpdis->hDC, hOldPen);
2208 SetBkColor (lpdis->hDC, oldBk);
2209 SetTextColor (lpdis->hDC, oldText);
2210 DeleteObject( hPen );
2215 case WM_MEASUREITEM:
2216 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2218 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2220 if (custInfo && custInfo->tbInfo)
2221 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2223 lpmis->itemHeight = 15 + 8; /* default height */
2235 /***********************************************************************
2236 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2240 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2243 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2244 INT nIndex = 0, nButtons, nCount;
2248 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2252 if (lpAddBmp->hInst == HINST_COMMCTRL)
2254 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2256 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2258 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2263 TRACE ("adding %d internal bitmaps!\n", nButtons);
2265 /* Windows resize all the buttons to the size of a newly added standard image */
2266 if (lpAddBmp->nID & 1)
2269 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2270 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2272 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2273 MAKELPARAM((WORD)24, (WORD)24));
2274 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2275 MAKELPARAM((WORD)31, (WORD)30));
2280 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2281 MAKELPARAM((WORD)16, (WORD)16));
2282 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2283 MAKELPARAM((WORD)22, (WORD)22));
2286 TOOLBAR_CalcToolbar (hwnd);
2290 nButtons = (INT)wParam;
2294 TRACE ("adding %d bitmaps!\n", nButtons);
2297 if (!infoPtr->cimlDef) {
2298 /* create new default image list */
2299 TRACE ("creating default image list!\n");
2301 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2302 ILC_COLOR | ILC_MASK, nButtons, 2);
2303 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2304 infoPtr->himlInt = himlDef;
2307 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2311 WARN("No default image list available\n");
2315 nCount = ImageList_GetImageCount(himlDef);
2317 /* Add bitmaps to the default image list */
2318 if (lpAddBmp->hInst == NULL)
2321 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2322 HDC hdcImage, hdcBitmap;
2324 /* copy the bitmap before adding it so that the user's bitmap
2325 * doesn't get modified.
2327 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2329 hdcImage = CreateCompatibleDC(0);
2330 hdcBitmap = CreateCompatibleDC(0);
2332 /* create new bitmap */
2333 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2334 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2335 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2337 /* Copy the user's image */
2338 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2339 hdcBitmap, 0, 0, SRCCOPY);
2341 SelectObject (hdcImage, hOldBitmapLoad);
2342 SelectObject (hdcBitmap, hOldBitmapBitmap);
2343 DeleteDC (hdcImage);
2344 DeleteDC (hdcBitmap);
2346 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2347 DeleteObject (hbmLoad);
2349 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2351 /* Add system bitmaps */
2352 switch (lpAddBmp->nID)
2354 case IDB_STD_SMALL_COLOR:
2355 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2356 MAKEINTRESOURCEA(IDB_STD_SMALL));
2357 nIndex = ImageList_AddMasked (himlDef,
2358 hbmLoad, comctl32_color.clrBtnFace);
2359 DeleteObject (hbmLoad);
2362 case IDB_STD_LARGE_COLOR:
2363 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2364 MAKEINTRESOURCEA(IDB_STD_LARGE));
2365 nIndex = ImageList_AddMasked (himlDef,
2366 hbmLoad, comctl32_color.clrBtnFace);
2367 DeleteObject (hbmLoad);
2370 case IDB_VIEW_SMALL_COLOR:
2371 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2372 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2373 nIndex = ImageList_AddMasked (himlDef,
2374 hbmLoad, comctl32_color.clrBtnFace);
2375 DeleteObject (hbmLoad);
2378 case IDB_VIEW_LARGE_COLOR:
2379 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2380 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2381 nIndex = ImageList_AddMasked (himlDef,
2382 hbmLoad, comctl32_color.clrBtnFace);
2383 DeleteObject (hbmLoad);
2386 case IDB_HIST_SMALL_COLOR:
2387 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2388 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2389 nIndex = ImageList_AddMasked (himlDef,
2390 hbmLoad, comctl32_color.clrBtnFace);
2391 DeleteObject (hbmLoad);
2394 case IDB_HIST_LARGE_COLOR:
2395 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2396 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2397 nIndex = ImageList_AddMasked (himlDef,
2398 hbmLoad, comctl32_color.clrBtnFace);
2399 DeleteObject (hbmLoad);
2403 nIndex = ImageList_GetImageCount (himlDef);
2404 ERR ("invalid imagelist!\n");
2410 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2411 nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
2412 DeleteObject (hbmLoad);
2415 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2417 if (infoPtr->nNumBitmapInfos == 0)
2419 infoPtr->bitmaps = Alloc(sizeof(TBITMAP_INFO));
2423 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2424 infoPtr->bitmaps = Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2425 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2428 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2429 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2430 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2432 infoPtr->nNumBitmapInfos++;
2433 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2437 INT imagecount = ImageList_GetImageCount(himlDef);
2439 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2441 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",
2442 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2443 infoPtr->nNumBitmaps+nButtons,imagecount);
2445 infoPtr->nNumBitmaps = imagecount;
2448 infoPtr->nNumBitmaps += nButtons;
2451 InvalidateRect(hwnd, NULL, FALSE);
2458 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2460 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2461 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2462 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2464 TRACE("adding %d buttons!\n", wParam);
2466 nAddButtons = (UINT)wParam;
2467 nOldButtons = infoPtr->nNumButtons;
2468 nNewButtons = nOldButtons + nAddButtons;
2470 if (infoPtr->nNumButtons == 0) {
2472 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2475 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2477 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2478 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2479 nOldButtons * sizeof(TBUTTON_INFO));
2483 infoPtr->nNumButtons = nNewButtons;
2485 /* insert new button data */
2486 for (nCount = 0; nCount < nAddButtons; nCount++) {
2487 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2488 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2489 btnPtr->idCommand = lpTbb[nCount].idCommand;
2490 btnPtr->fsState = lpTbb[nCount].fsState;
2491 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2492 btnPtr->dwData = lpTbb[nCount].dwData;
2493 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2494 Str_SetPtrAtoW ((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[nCount].iString );
2496 btnPtr->iString = lpTbb[nCount].iString;
2497 btnPtr->bHot = FALSE;
2499 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2502 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2503 ti.cbSize = sizeof (TTTOOLINFOA);
2505 ti.uId = btnPtr->idCommand;
2507 ti.lpszText = LPSTR_TEXTCALLBACKA;
2509 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2514 TOOLBAR_CalcToolbar (hwnd);
2516 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2518 InvalidateRect(hwnd, NULL, FALSE);
2525 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2527 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2528 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2529 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2531 TRACE("adding %d buttons!\n", wParam);
2533 nAddButtons = (UINT)wParam;
2534 nOldButtons = infoPtr->nNumButtons;
2535 nNewButtons = nOldButtons + nAddButtons;
2537 if (infoPtr->nNumButtons == 0) {
2539 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2542 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2544 Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2545 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2546 nOldButtons * sizeof(TBUTTON_INFO));
2550 infoPtr->nNumButtons = nNewButtons;
2552 /* insert new button data */
2553 for (nCount = 0; nCount < nAddButtons; nCount++) {
2554 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2555 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2556 btnPtr->idCommand = lpTbb[nCount].idCommand;
2557 btnPtr->fsState = lpTbb[nCount].fsState;
2558 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2559 btnPtr->dwData = lpTbb[nCount].dwData;
2560 if(HIWORD(lpTbb[nCount].iString) && lpTbb[nCount].iString != -1)
2561 Str_SetPtrW ((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[nCount].iString );
2563 btnPtr->iString = lpTbb[nCount].iString;
2564 btnPtr->bHot = FALSE;
2566 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & BTNS_SEP)) {
2569 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2570 ti.cbSize = sizeof (TTTOOLINFOW);
2572 ti.uId = btnPtr->idCommand;
2574 ti.lpszText = LPSTR_TEXTCALLBACKW;
2577 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2582 TOOLBAR_CalcToolbar (hwnd);
2584 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2586 InvalidateRect(hwnd, NULL, FALSE);
2593 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2598 if ((wParam) && (HIWORD(lParam) == 0)) {
2601 TRACE("adding string from resource!\n");
2603 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2606 TRACE("len=%d \"%s\"\n", len, szString);
2607 nIndex = infoPtr->nNumStrings;
2608 if (infoPtr->nNumStrings == 0) {
2610 Alloc (sizeof(LPWSTR));
2613 LPWSTR *oldStrings = infoPtr->strings;
2615 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2616 memcpy (&infoPtr->strings[0], &oldStrings[0],
2617 sizeof(LPWSTR) * infoPtr->nNumStrings);
2621 /*Alloc zeros out the allocated memory*/
2622 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2623 infoPtr->nNumStrings++;
2626 LPSTR p = (LPSTR)lParam;
2631 TRACE("adding string(s) from array!\n");
2633 nIndex = infoPtr->nNumStrings;
2636 TRACE("len=%d \"%s\"\n", len, p);
2638 if (infoPtr->nNumStrings == 0) {
2640 Alloc (sizeof(LPWSTR));
2643 LPWSTR *oldStrings = infoPtr->strings;
2645 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2646 memcpy (&infoPtr->strings[0], &oldStrings[0],
2647 sizeof(LPWSTR) * infoPtr->nNumStrings);
2651 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2652 infoPtr->nNumStrings++;
2663 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2665 #define MAX_RESOURCE_STRING_LENGTH 512
2666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2669 if ((wParam) && (HIWORD(lParam) == 0)) {
2670 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2672 TRACE("adding string from resource!\n");
2674 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2675 szString, MAX_RESOURCE_STRING_LENGTH);
2677 TRACE("len=%d %s\n", len, debugstr_w(szString));
2678 TRACE("First char: 0x%x\n", *szString);
2679 if (szString[0] == L'|')
2681 PWSTR p = szString + 1;
2683 nIndex = infoPtr->nNumStrings;
2684 while (*p != L'|' && *p != L'\0') {
2687 if (infoPtr->nNumStrings == 0) {
2688 infoPtr->strings = Alloc (sizeof(LPWSTR));
2692 LPWSTR *oldStrings = infoPtr->strings;
2693 infoPtr->strings = Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2694 memcpy(&infoPtr->strings[0], &oldStrings[0],
2695 sizeof(LPWSTR) * infoPtr->nNumStrings);
2699 np=strchrW (p, '|');
2707 TRACE("len=%d %s\n", len, debugstr_w(p));
2708 infoPtr->strings[infoPtr->nNumStrings] =
2709 Alloc (sizeof(WCHAR)*(len+1));
2710 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2711 infoPtr->nNumStrings++;
2718 nIndex = infoPtr->nNumStrings;
2719 if (infoPtr->nNumStrings == 0) {
2721 Alloc (sizeof(LPWSTR));
2724 LPWSTR *oldStrings = infoPtr->strings;
2726 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2727 memcpy (&infoPtr->strings[0], &oldStrings[0],
2728 sizeof(LPWSTR) * infoPtr->nNumStrings);
2732 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2733 infoPtr->nNumStrings++;
2737 LPWSTR p = (LPWSTR)lParam;
2742 TRACE("adding string(s) from array!\n");
2743 nIndex = infoPtr->nNumStrings;
2747 TRACE("len=%d %s\n", len, debugstr_w(p));
2748 if (infoPtr->nNumStrings == 0) {
2750 Alloc (sizeof(LPWSTR));
2753 LPWSTR *oldStrings = infoPtr->strings;
2755 Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2756 memcpy (&infoPtr->strings[0], &oldStrings[0],
2757 sizeof(LPWSTR) * infoPtr->nNumStrings);
2761 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2762 infoPtr->nNumStrings++;
2773 TOOLBAR_AutoSize (HWND hwnd)
2775 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2776 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2782 UINT uPosFlags = SWP_NOZORDER;
2784 TRACE("resize forced, style=%lx!\n", dwStyle);
2786 parent = GetParent (hwnd);
2787 GetClientRect(parent, &parent_rect);
2789 x = parent_rect.left;
2790 y = parent_rect.top;
2792 /* FIXME: we should be able to early out if nothing */
2793 /* has changed with nWidth != parent_rect width */
2795 if (dwStyle & CCS_NORESIZE) {
2796 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2799 TOOLBAR_CalcToolbar (hwnd);
2802 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2803 TOOLBAR_CalcToolbar (hwnd);
2804 InvalidateRect( hwnd, NULL, TRUE );
2805 cy = infoPtr->nHeight;
2806 cx = infoPtr->nWidth;
2808 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
2809 GetWindowRect(hwnd, &window_rect);
2810 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2811 y = window_rect.top;
2813 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
2814 GetWindowRect(hwnd, &window_rect);
2815 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
2819 if (dwStyle & CCS_NOPARENTALIGN)
2820 uPosFlags |= SWP_NOMOVE;
2822 if (!(dwStyle & CCS_NODIVIDER))
2823 cy += GetSystemMetrics(SM_CYEDGE);
2825 if (dwStyle & WS_BORDER)
2828 cy += GetSystemMetrics(SM_CYEDGE);
2829 cx += GetSystemMetrics(SM_CYEDGE);
2832 infoPtr->bAutoSize = TRUE;
2833 SetWindowPos (hwnd, HWND_TOP, x, y, cx, cy, uPosFlags);
2834 /* The following line makes sure that the infoPtr->bAutoSize is turned off
2835 * after the setwindowpos calls */
2836 infoPtr->bAutoSize = FALSE;
2843 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2845 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2847 return infoPtr->nNumButtons;
2852 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2856 if (infoPtr == NULL) {
2857 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2858 ERR("infoPtr == NULL!\n");
2862 infoPtr->dwStructSize = (DWORD)wParam;
2869 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2872 TBUTTON_INFO *btnPtr;
2875 TRACE("button %d, iBitmap now %d\n", wParam, LOWORD(lParam));
2877 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2881 btnPtr = &infoPtr->buttons[nIndex];
2882 btnPtr->iBitmap = LOWORD(lParam);
2884 /* we HAVE to erase the background, the new bitmap could be */
2886 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2893 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2896 TBUTTON_INFO *btnPtr;
2899 BOOL bChecked = FALSE;
2901 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2905 btnPtr = &infoPtr->buttons[nIndex];
2907 if (!(btnPtr->fsStyle & BTNS_CHECK))
2910 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2912 if (LOWORD(lParam) == FALSE)
2913 btnPtr->fsState &= ~TBSTATE_CHECKED;
2915 if (btnPtr->fsStyle & BTNS_GROUP) {
2917 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2918 if (nOldIndex == nIndex)
2920 if (nOldIndex != -1)
2921 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2923 btnPtr->fsState |= TBSTATE_CHECKED;
2926 if( bChecked != LOWORD(lParam) )
2928 if (nOldIndex != -1)
2930 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2931 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2933 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2936 /* FIXME: Send a WM_NOTIFY?? */
2943 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2945 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2947 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2952 TOOLBAR_Customize (HWND hwnd)
2954 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2955 CUSTDLG_INFO custInfo;
2961 custInfo.tbInfo = infoPtr;
2962 custInfo.tbHwnd = hwnd;
2964 /* send TBN_BEGINADJUST notification */
2965 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2968 if (!(hRes = FindResourceA (COMCTL32_hModule,
2969 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2973 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2976 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2977 (LPDLGTEMPLATEA)template,
2979 TOOLBAR_CustomizeDialogProc,
2982 /* send TBN_ENDADJUST notification */
2983 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2991 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2993 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2994 INT nIndex = (INT)wParam;
2996 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2999 if ((infoPtr->hwndToolTip) &&
3000 !(infoPtr->buttons[nIndex].fsStyle & BTNS_SEP)) {
3003 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3004 ti.cbSize = sizeof (TTTOOLINFOA);
3006 ti.uId = infoPtr->buttons[nIndex].idCommand;
3008 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
3011 if (infoPtr->nNumButtons == 1) {
3012 TRACE(" simple delete!\n");
3013 Free (infoPtr->buttons);
3014 infoPtr->buttons = NULL;
3015 infoPtr->nNumButtons = 0;
3018 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3019 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3021 infoPtr->nNumButtons--;
3022 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3024 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3025 nIndex * sizeof(TBUTTON_INFO));
3028 if (nIndex < infoPtr->nNumButtons) {
3029 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3030 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3036 TOOLBAR_CalcToolbar (hwnd);
3038 InvalidateRect (hwnd, NULL, TRUE);
3045 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3048 TBUTTON_INFO *btnPtr;
3052 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3056 btnPtr = &infoPtr->buttons[nIndex];
3058 bState = btnPtr->fsState & TBSTATE_ENABLED;
3060 /* update the toolbar button state */
3061 if(LOWORD(lParam) == FALSE) {
3062 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3064 btnPtr->fsState |= TBSTATE_ENABLED;
3067 /* redraw the button only if the state of the button changed */
3068 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3070 InvalidateRect(hwnd, &btnPtr->rect,
3071 TOOLBAR_HasText(infoPtr, btnPtr));
3078 static inline LRESULT
3079 TOOLBAR_GetAnchorHighlight (HWND hwnd)
3081 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3083 return infoPtr->bAnchor;
3088 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3093 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3097 return infoPtr->buttons[nIndex].iBitmap;
3101 static inline LRESULT
3102 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3104 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3109 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3112 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3113 INT nIndex = (INT)wParam;
3114 TBUTTON_INFO *btnPtr;
3116 if (infoPtr == NULL)
3122 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3125 btnPtr = &infoPtr->buttons[nIndex];
3126 lpTbb->iBitmap = btnPtr->iBitmap;
3127 lpTbb->idCommand = btnPtr->idCommand;
3128 lpTbb->fsState = btnPtr->fsState;
3129 lpTbb->fsStyle = btnPtr->fsStyle;
3130 lpTbb->bReserved[0] = 0;
3131 lpTbb->bReserved[1] = 0;
3132 lpTbb->dwData = btnPtr->dwData;
3133 lpTbb->iString = btnPtr->iString;
3140 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3143 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3144 TBUTTON_INFO *btnPtr;
3147 if (infoPtr == NULL)
3149 if (lpTbInfo == NULL)
3151 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3154 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3155 lpTbInfo->dwMask & 0x80000000);
3159 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3161 if (lpTbInfo->dwMask & TBIF_COMMAND)
3162 lpTbInfo->idCommand = btnPtr->idCommand;
3163 if (lpTbInfo->dwMask & TBIF_IMAGE)
3164 lpTbInfo->iImage = btnPtr->iBitmap;
3165 if (lpTbInfo->dwMask & TBIF_LPARAM)
3166 lpTbInfo->lParam = btnPtr->dwData;
3167 if (lpTbInfo->dwMask & TBIF_SIZE)
3168 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3169 if (lpTbInfo->dwMask & TBIF_STATE)
3170 lpTbInfo->fsState = btnPtr->fsState;
3171 if (lpTbInfo->dwMask & TBIF_STYLE)
3172 lpTbInfo->fsStyle = btnPtr->fsStyle;
3173 if (lpTbInfo->dwMask & TBIF_TEXT) {
3174 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3175 can't use TOOLBAR_GetText here */
3177 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3178 lpText = (LPWSTR)btnPtr->iString;
3179 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3181 lpTbInfo->pszText[0] = '\0';
3188 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3191 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3192 TBUTTON_INFO *btnPtr;
3195 if (infoPtr == NULL)
3197 if (lpTbInfo == NULL)
3199 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3202 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3203 lpTbInfo->dwMask & 0x80000000);
3207 btnPtr = &infoPtr->buttons[nIndex];
3212 if (lpTbInfo->dwMask & TBIF_COMMAND)
3213 lpTbInfo->idCommand = btnPtr->idCommand;
3214 if (lpTbInfo->dwMask & TBIF_IMAGE)
3215 lpTbInfo->iImage = btnPtr->iBitmap;
3216 if (lpTbInfo->dwMask & TBIF_LPARAM)
3217 lpTbInfo->lParam = btnPtr->dwData;
3218 if (lpTbInfo->dwMask & TBIF_SIZE)
3219 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3220 if (lpTbInfo->dwMask & TBIF_STATE)
3221 lpTbInfo->fsState = btnPtr->fsState;
3222 if (lpTbInfo->dwMask & TBIF_STYLE)
3223 lpTbInfo->fsStyle = btnPtr->fsStyle;
3224 if (lpTbInfo->dwMask & TBIF_TEXT) {
3225 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3226 can't use TOOLBAR_GetText here */
3228 if (HIWORD(btnPtr->iString) && (btnPtr->iString != -1)) {
3229 lpText = (LPWSTR)btnPtr->iString;
3230 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3232 lpTbInfo->pszText[0] = '\0';
3240 TOOLBAR_GetButtonSize (HWND hwnd)
3242 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3244 if (infoPtr->nNumButtons > 0)
3245 return MAKELONG((WORD)infoPtr->nButtonWidth,
3246 (WORD)infoPtr->nButtonHeight);
3248 return MAKELONG(8,7);
3253 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3255 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3262 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3266 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3268 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3269 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3274 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3283 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3287 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3289 strcpyW ((LPWSTR)lParam, lpText);
3291 return strlenW (lpText);
3296 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3298 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3299 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3300 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3304 inline static LRESULT
3305 TOOLBAR_GetExtendedStyle (HWND hwnd)
3307 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3311 return infoPtr->dwExStyle;
3316 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3318 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3319 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3320 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), wParam);
3325 TOOLBAR_GetHotItem (HWND hwnd)
3327 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3329 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3332 if (infoPtr->nHotItem < 0)
3335 return (LRESULT)infoPtr->nHotItem;
3340 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3342 TRACE("hwnd=%p, wParam=%d, lParam=0x%lx\n", hwnd, wParam, lParam);
3343 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3344 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), wParam);
3348 /* << TOOLBAR_GetInsertMark >> */
3349 /* << TOOLBAR_GetInsertMarkColor >> */
3353 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3356 TBUTTON_INFO *btnPtr;
3360 if (infoPtr == NULL)
3362 nIndex = (INT)wParam;
3363 btnPtr = &infoPtr->buttons[nIndex];
3364 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3366 lpRect = (LPRECT)lParam;
3369 if (btnPtr->fsState & TBSTATE_HIDDEN)
3372 lpRect->left = btnPtr->rect.left;
3373 lpRect->right = btnPtr->rect.right;
3374 lpRect->bottom = btnPtr->rect.bottom;
3375 lpRect->top = btnPtr->rect.top;
3382 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3384 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3385 LPSIZE lpSize = (LPSIZE)lParam;
3390 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3391 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3393 TRACE("maximum size %ld x %ld\n",
3394 infoPtr->rcBound.right - infoPtr->rcBound.left,
3395 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3401 /* << TOOLBAR_GetObject >> */
3405 TOOLBAR_GetPadding (HWND hwnd)
3407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3410 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3411 return (LRESULT) oldPad;
3416 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3418 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3419 TBUTTON_INFO *btnPtr;
3423 if (infoPtr == NULL)
3425 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3426 btnPtr = &infoPtr->buttons[nIndex];
3427 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3429 lpRect = (LPRECT)lParam;
3433 lpRect->left = btnPtr->rect.left;
3434 lpRect->right = btnPtr->rect.right;
3435 lpRect->bottom = btnPtr->rect.bottom;
3436 lpRect->top = btnPtr->rect.top;
3443 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3447 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3448 return infoPtr->nRows;
3455 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3457 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3460 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3464 return infoPtr->buttons[nIndex].fsState;
3469 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3471 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3478 return infoPtr->buttons[nIndex].fsStyle;
3483 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3487 if (infoPtr == NULL)
3490 return infoPtr->nMaxTextRows;
3495 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3497 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3499 if (infoPtr == NULL)
3501 return (LRESULT)infoPtr->hwndToolTip;
3506 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3510 TRACE("%s hwnd=%p stub!\n",
3511 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3513 return infoPtr->bUnicode;
3517 inline static LRESULT
3518 TOOLBAR_GetVersion (HWND hwnd)
3520 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3521 return infoPtr->iVersion;
3526 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3529 TBUTTON_INFO *btnPtr;
3534 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3538 btnPtr = &infoPtr->buttons[nIndex];
3539 if (LOWORD(lParam) == FALSE)
3540 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3542 btnPtr->fsState |= TBSTATE_HIDDEN;
3544 TOOLBAR_CalcToolbar (hwnd);
3546 InvalidateRect (hwnd, NULL, TRUE);
3552 inline static LRESULT
3553 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3555 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3560 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3562 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3563 TBUTTON_INFO *btnPtr;
3567 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3571 btnPtr = &infoPtr->buttons[nIndex];
3572 oldState = btnPtr->fsState;
3573 if (LOWORD(lParam) == FALSE)
3574 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3576 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3578 if(oldState != btnPtr->fsState)
3579 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3586 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3589 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3590 INT nIndex = (INT)wParam;
3591 TBUTTON_INFO *oldButtons;
3596 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3599 /* EPP: this seems to be an undocumented call (from my IE4)
3600 * I assume in that case that:
3601 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3602 * - index of insertion is at the end of existing buttons
3603 * I only see this happen with nIndex == -1, but it could have a special
3604 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3606 nIndex = infoPtr->nNumButtons;
3608 } else if (nIndex < 0)
3611 /* If the string passed is not an index, assume address of string
3612 and do our own AddString */
3613 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3617 TRACE("string %s passed instead of index, adding string\n",
3618 debugstr_a((LPSTR)lpTbb->iString));
3619 len = strlen((LPSTR)lpTbb->iString) + 2;
3621 strcpy(ptr, (LPSTR)lpTbb->iString);
3622 ptr[len - 1] = 0; /* ended by two '\0' */
3623 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3627 TRACE("inserting button index=%d\n", nIndex);
3628 if (nIndex > infoPtr->nNumButtons) {
3629 nIndex = infoPtr->nNumButtons;
3630 TRACE("adjust index=%d\n", nIndex);
3633 oldButtons = infoPtr->buttons;
3634 infoPtr->nNumButtons++;
3635 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3636 /* pre insert copy */
3638 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3639 nIndex * sizeof(TBUTTON_INFO));
3642 /* insert new button */
3643 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3644 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3645 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3646 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3647 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3648 /* if passed string and not index, then add string */
3649 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3650 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3653 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3655 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3658 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3659 ti.cbSize = sizeof (TTTOOLINFOA);
3661 ti.uId = lpTbb->idCommand;
3663 ti.lpszText = LPSTR_TEXTCALLBACKA;
3665 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3669 /* post insert copy */
3670 if (nIndex < infoPtr->nNumButtons - 1) {
3671 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3672 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3677 TOOLBAR_CalcToolbar (hwnd);
3679 InvalidateRect (hwnd, NULL, TRUE);
3686 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3688 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3689 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3690 INT nIndex = (INT)wParam;
3691 TBUTTON_INFO *oldButtons;
3696 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3699 /* EPP: this seems to be an undocumented call (from my IE4)
3700 * I assume in that case that:
3701 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3702 * - index of insertion is at the end of existing buttons
3703 * I only see this happen with nIndex == -1, but it could have a special
3704 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3706 nIndex = infoPtr->nNumButtons;
3708 } else if (nIndex < 0)
3711 /* If the string passed is not an index, assume address of string
3712 and do our own AddString */
3713 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3717 TRACE("string %s passed instead of index, adding string\n",
3718 debugstr_w((LPWSTR)lpTbb->iString));
3719 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3720 ptr = Alloc(len*sizeof(WCHAR));
3721 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3722 ptr[len - 1] = 0; /* ended by two '\0' */
3723 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3727 TRACE("inserting button index=%d\n", nIndex);
3728 if (nIndex > infoPtr->nNumButtons) {
3729 nIndex = infoPtr->nNumButtons;
3730 TRACE("adjust index=%d\n", nIndex);
3733 oldButtons = infoPtr->buttons;
3734 infoPtr->nNumButtons++;
3735 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3736 /* pre insert copy */
3738 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3739 nIndex * sizeof(TBUTTON_INFO));
3742 /* insert new button */
3743 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3744 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3745 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3746 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3747 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3748 /* if passed string and not index, then add string */
3749 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3750 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3753 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3755 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & BTNS_SEP)) {
3758 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3759 ti.cbSize = sizeof (TTTOOLINFOW);
3761 ti.uId = lpTbb->idCommand;
3763 ti.lpszText = LPSTR_TEXTCALLBACKW;
3765 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3769 /* post insert copy */
3770 if (nIndex < infoPtr->nNumButtons - 1) {
3771 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3772 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3777 TOOLBAR_CalcToolbar (hwnd);
3779 InvalidateRect (hwnd, NULL, TRUE);
3785 /* << TOOLBAR_InsertMarkHitTest >> */
3789 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3794 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3798 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3803 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3805 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3808 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3812 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3817 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3822 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3826 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3831 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3836 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3840 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3845 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3850 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3854 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3859 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3868 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3872 /* << TOOLBAR_LoadImages >> */
3873 /* << TOOLBAR_MapAccelerator >> */
3874 /* << TOOLBAR_MarkButton >> */
3875 /* << TOOLBAR_MoveButton >> */
3879 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3882 TBUTTON_INFO *btnPtr;
3886 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3890 btnPtr = &infoPtr->buttons[nIndex];
3891 oldState = btnPtr->fsState;
3892 if (LOWORD(lParam) == FALSE)
3893 btnPtr->fsState &= ~TBSTATE_PRESSED;
3895 btnPtr->fsState |= TBSTATE_PRESSED;
3897 if(oldState != btnPtr->fsState)
3898 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3903 /* FIXME: there might still be some confusion her between number of buttons
3904 * and number of bitmaps */
3906 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3909 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3911 int i = 0, nOldButtons = 0, pos = 0;
3912 int nOldBitmaps, nNewBitmaps;
3913 HIMAGELIST himlDef = 0;
3915 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3916 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3917 lpReplace->nButtons);
3919 if (lpReplace->hInstOld == HINST_COMMCTRL)
3921 FIXME("changing standard bitmaps not implemented\n");
3924 else if (lpReplace->hInstOld != 0)
3926 FIXME("resources not in the current module not implemented\n");
3931 hBitmap = (HBITMAP) lpReplace->nIDNew;
3934 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3935 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3936 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3937 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3938 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3940 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3941 nOldButtons = tbi->nButtons;
3942 tbi->nButtons = lpReplace->nButtons;
3943 tbi->hInst = lpReplace->hInstNew;
3944 tbi->nID = lpReplace->nIDNew;
3945 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3948 pos += tbi->nButtons;
3951 if (nOldButtons == 0)
3953 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3957 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
3958 nOldBitmaps = ImageList_GetImageCount(himlDef);
3960 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
3962 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
3963 ImageList_Remove(himlDef, i);
3967 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
3968 HDC hdcImage, hdcBitmap;
3970 /* copy the bitmap before adding it so that the user's bitmap
3971 * doesn't get modified.
3973 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
3975 hdcImage = CreateCompatibleDC(0);
3976 hdcBitmap = CreateCompatibleDC(0);
3978 /* create new bitmap */
3979 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
3980 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
3981 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
3983 /* Copy the user's image */
3984 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
3985 hdcBitmap, 0, 0, SRCCOPY);
3987 SelectObject (hdcImage, hOldBitmapLoad);
3988 SelectObject (hdcBitmap, hOldBitmapBitmap);
3989 DeleteDC (hdcImage);
3990 DeleteDC (hdcBitmap);
3992 ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace);
3993 nNewBitmaps = ImageList_GetImageCount(himlDef);
3994 DeleteObject (hbmLoad);
3997 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
3999 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4000 pos, nOldBitmaps, nNewBitmaps);
4002 InvalidateRect(hwnd, NULL, FALSE);
4008 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4012 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
4014 if (lpSave == NULL) return 0;
4017 /* save toolbar information */
4018 FIXME("save to \"%s\" \"%s\"\n",
4019 lpSave->pszSubKey, lpSave->pszValueName);
4024 /* restore toolbar information */
4026 FIXME("restore from \"%s\" \"%s\"\n",
4027 lpSave->pszSubKey, lpSave->pszValueName);
4038 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4041 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4042 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
4048 /* save toolbar information */
4049 FIXME("save to \"%s\" \"%s\"\n",
4050 lpSave->pszSubKey, lpSave->pszValueName);
4055 /* restore toolbar information */
4057 FIXME("restore from \"%s\" \"%s\"\n",
4058 lpSave->pszSubKey, lpSave->pszValueName);
4069 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
4071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4072 BOOL bOldAnchor = infoPtr->bAnchor;
4074 infoPtr->bAnchor = (BOOL)wParam;
4076 return (LRESULT)bOldAnchor;
4081 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4084 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4086 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
4089 if (infoPtr->nNumButtons > 0)
4090 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
4091 infoPtr->nNumButtons,
4092 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
4093 LOWORD(lParam), HIWORD(lParam));
4095 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
4096 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
4099 /* uses image list internals directly */
4101 himlDef->cx = infoPtr->nBitmapWidth;
4102 himlDef->cy = infoPtr->nBitmapHeight;
4110 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4112 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4113 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
4114 TBUTTON_INFO *btnPtr;
4119 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
4122 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4123 lptbbi->dwMask & 0x80000000);
4127 btnPtr = &infoPtr->buttons[nIndex];
4128 if (lptbbi->dwMask & TBIF_COMMAND)
4129 btnPtr->idCommand = lptbbi->idCommand;
4130 if (lptbbi->dwMask & TBIF_IMAGE)
4131 btnPtr->iBitmap = lptbbi->iImage;
4132 if (lptbbi->dwMask & TBIF_LPARAM)
4133 btnPtr->dwData = lptbbi->lParam;
4134 /* if (lptbbi->dwMask & TBIF_SIZE) */
4135 /* btnPtr->cx = lptbbi->cx; */
4136 if (lptbbi->dwMask & TBIF_STATE)
4137 btnPtr->fsState = lptbbi->fsState;
4138 if (lptbbi->dwMask & TBIF_STYLE)
4139 btnPtr->fsStyle = lptbbi->fsStyle;
4141 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4142 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4143 /* iString is index, zero it to make Str_SetPtr succeed */
4146 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4153 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4155 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4156 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4157 TBUTTON_INFO *btnPtr;
4162 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4165 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4166 lptbbi->dwMask & 0x80000000);
4170 btnPtr = &infoPtr->buttons[nIndex];
4171 if (lptbbi->dwMask & TBIF_COMMAND)
4172 btnPtr->idCommand = lptbbi->idCommand;
4173 if (lptbbi->dwMask & TBIF_IMAGE)
4174 btnPtr->iBitmap = lptbbi->iImage;
4175 if (lptbbi->dwMask & TBIF_LPARAM)
4176 btnPtr->dwData = lptbbi->lParam;
4177 /* if (lptbbi->dwMask & TBIF_SIZE) */
4178 /* btnPtr->cx = lptbbi->cx; */
4179 if (lptbbi->dwMask & TBIF_STATE)
4180 btnPtr->fsState = lptbbi->fsState;
4181 if (lptbbi->dwMask & TBIF_STYLE)
4182 btnPtr->fsStyle = lptbbi->fsStyle;
4184 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4185 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4186 /* iString is index, zero it to make Str_SetPtr succeed */
4188 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4195 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4198 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4200 if ((cx < 0) || (cy < 0))
4202 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4206 /* The documentation claims you can only change the button size before
4207 * any button has been added. But this is wrong.
4208 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4209 * it to the toolbar, and it checks that the return value is nonzero - mjm
4210 * Further testing shows that we must actually perform the change too.
4213 * The documentation also does not mention that if 0 is supplied for
4214 * either size, the system changes it to the default of 24 wide and
4215 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4217 infoPtr->nButtonWidth = (cx) ? cx : 24;
4218 infoPtr->nButtonHeight = (cy) ? cy : 22;
4224 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4226 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4228 if (infoPtr == NULL) {
4229 TRACE("Toolbar not initialized yet?????\n");
4233 /* if setting to current values, ignore */
4234 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4235 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4236 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4237 infoPtr->cxMin, infoPtr->cxMax);
4241 /* save new values */
4242 infoPtr->cxMin = (INT)LOWORD(lParam);
4243 infoPtr->cxMax = (INT)HIWORD(lParam);
4245 /* if both values are 0 then we are done */
4247 TRACE("setting both min and max to 0, norecalc\n");
4251 /* otherwise we need to recalc the toolbar and in some cases
4252 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4253 which doesn't actually draw - GA). */
4254 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4255 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4257 TOOLBAR_CalcToolbar (hwnd);
4259 InvalidateRect (hwnd, NULL, TRUE);
4266 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4268 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4269 INT nIndex = (INT)wParam;
4271 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4274 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4276 if (infoPtr->hwndToolTip) {
4278 FIXME("change tool tip!\n");
4287 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4290 HIMAGELIST himl = (HIMAGELIST)lParam;
4291 HIMAGELIST himlTemp;
4294 if (infoPtr->iVersion >= 5)
4297 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4298 &infoPtr->cimlDis, himl, id);
4300 /* FIXME: redraw ? */
4302 return (LRESULT)himlTemp;
4307 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4312 dwTemp = infoPtr->dwDTFlags;
4313 infoPtr->dwDTFlags =
4314 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4316 return (LRESULT)dwTemp;
4319 /* This function differs a bit from what MSDN says it does:
4320 * 1. lParam contains extended style flags to OR with current style
4321 * (MSDN isn't clear on the OR bit)
4322 * 2. wParam appears to contain extended style flags to be reset
4323 * (MSDN says that this parameter is reserved)
4326 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4331 dwTemp = infoPtr->dwExStyle;
4332 infoPtr->dwExStyle &= ~wParam;
4333 infoPtr->dwExStyle |= (DWORD)lParam;
4335 TRACE("new style 0x%08lx\n", infoPtr->dwExStyle);
4337 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4338 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4339 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4341 TOOLBAR_CalcToolbar (hwnd);
4343 TOOLBAR_AutoSize(hwnd);
4345 InvalidateRect(hwnd, NULL, FALSE);
4347 return (LRESULT)dwTemp;
4352 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4354 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4355 HIMAGELIST himlTemp;
4356 HIMAGELIST himl = (HIMAGELIST)lParam;
4359 if (infoPtr->iVersion >= 5)
4362 TRACE("hwnd = %p, himl = %p, id = %d\n", hwnd, himl, id);
4364 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4365 &infoPtr->cimlHot, himl, id);
4367 /* FIXME: redraw ? */
4369 return (LRESULT)himlTemp;
4374 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4376 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4377 INT nOldHotItem = infoPtr->nHotItem;
4378 TBUTTON_INFO *btnPtr;
4380 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4383 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4386 infoPtr->nHotItem = (INT)wParam;
4387 if ((INT)wParam >=0)
4389 btnPtr = &infoPtr->buttons[(INT)wParam];
4390 btnPtr->bHot = TRUE;
4391 InvalidateRect (hwnd, &btnPtr->rect,
4392 TOOLBAR_HasText(infoPtr, btnPtr));
4396 btnPtr = &infoPtr->buttons[nOldHotItem];
4397 btnPtr->bHot = FALSE;
4398 InvalidateRect (hwnd, &btnPtr->rect,
4399 TOOLBAR_HasText(infoPtr, btnPtr));
4403 if (nOldHotItem < 0)
4406 return (LRESULT)nOldHotItem;
4411 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4414 HIMAGELIST himlTemp;
4415 HIMAGELIST himl = (HIMAGELIST)lParam;
4418 if (infoPtr->iVersion >= 5)
4421 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4422 &infoPtr->cimlDef, himl, id);
4424 infoPtr->nNumBitmaps = 0;
4425 for (i = 0; i < infoPtr->cimlDef; i++)
4426 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4428 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4429 &infoPtr->nBitmapHeight);
4430 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4431 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4432 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4434 /* FIXME: redraw ? */
4435 InvalidateRect(hwnd, NULL, TRUE);
4437 return (LRESULT)himlTemp;
4442 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4446 infoPtr->nIndent = (INT)wParam;
4450 /* process only on indent changing */
4451 if(infoPtr->nIndent != (INT)wParam)
4453 infoPtr->nIndent = (INT)wParam;
4454 TOOLBAR_CalcToolbar (hwnd);
4455 InvalidateRect(hwnd, NULL, FALSE);
4462 /* << TOOLBAR_SetInsertMark >> */
4466 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4470 infoPtr->clrInsertMark = (COLORREF)lParam;
4472 /* FIXME : redraw ??*/
4479 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4481 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4483 if (infoPtr == NULL)
4486 infoPtr->nMaxTextRows = (INT)wParam;
4488 TOOLBAR_CalcToolbar(hwnd);
4494 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4499 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4500 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4501 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4502 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4503 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4504 return (LRESULT) oldPad;
4509 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4516 if (infoPtr == NULL)
4518 hwndOldNotify = infoPtr->hwndNotify;
4519 infoPtr->hwndNotify = (HWND)wParam;
4521 return (LRESULT)hwndOldNotify;
4526 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4528 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4529 LPRECT lprc = (LPRECT)lParam;
4533 if (LOWORD(wParam) > 1) {
4534 FIXME("multiple rows not supported!\n");
4537 if(infoPtr->nRows != LOWORD(wParam))
4539 infoPtr->nRows = LOWORD(wParam);
4541 /* recalculate toolbar */
4542 TOOLBAR_CalcToolbar (hwnd);
4544 /* repaint toolbar */
4545 InvalidateRect(hwnd, NULL, FALSE);
4548 /* return bounding rectangle */
4550 lprc->left = infoPtr->rcBound.left;
4551 lprc->right = infoPtr->rcBound.right;
4552 lprc->top = infoPtr->rcBound.top;
4553 lprc->bottom = infoPtr->rcBound.bottom;
4561 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4563 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4564 TBUTTON_INFO *btnPtr;
4567 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4571 btnPtr = &infoPtr->buttons[nIndex];
4573 /* if hidden state has changed the invalidate entire window and recalc */
4574 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4575 btnPtr->fsState = LOWORD(lParam);
4576 TOOLBAR_CalcToolbar (hwnd);
4577 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4581 /* process state changing if current state doesn't match new state */
4582 if(btnPtr->fsState != LOWORD(lParam))
4584 btnPtr->fsState = LOWORD(lParam);
4585 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4594 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4596 SetWindowLongW(hwnd, GWL_STYLE, lParam);
4602 inline static LRESULT
4603 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4605 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4607 if (infoPtr == NULL)
4609 infoPtr->hwndToolTip = (HWND)wParam;
4615 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4620 TRACE("%s hwnd=%p stub!\n",
4621 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4623 bTemp = infoPtr->bUnicode;
4624 infoPtr->bUnicode = (BOOL)wParam;
4631 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4633 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4635 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4636 comctl32_color.clrBtnHighlight :
4637 infoPtr->clrBtnHighlight;
4638 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4639 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4645 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4649 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4650 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4651 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4653 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4654 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4655 InvalidateRect(hwnd, 0, 0);
4661 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4663 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4664 INT iOldVersion = infoPtr->iVersion;
4666 infoPtr->iVersion = iVersion;
4668 if (infoPtr->iVersion >= 5)
4669 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4676 TOOLBAR_GetStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
4678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4679 WORD iString = HIWORD(wParam);
4680 WORD buffersize = LOWORD(wParam);
4681 LPSTR str = (LPSTR)lParam;
4684 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, buffersize, str);
4686 if (iString < infoPtr->nNumStrings)
4688 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4690 TRACE("returning %s\n", debugstr_a(str));
4693 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4700 TOOLBAR_GetStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4703 WORD iString = HIWORD(wParam);
4704 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
4705 LPWSTR str = (LPWSTR)lParam;
4708 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", hwnd, iString, LOWORD(wParam), str);
4710 if (iString < infoPtr->nNumStrings)
4712 len = min(len, strlenW(infoPtr->strings[iString]));
4713 ret = (len+1)*sizeof(WCHAR);
4714 memcpy(str, infoPtr->strings[iString], ret);
4717 TRACE("returning %s\n", debugstr_w(str));
4720 ERR("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4725 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
4727 FIXME("hwnd=%p wParam %08x lParam %08lx stub!\n", hwnd, wParam, lParam);
4731 /*********************************************************************/
4733 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4734 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4735 /* based on relay traces of the native control and IE 5.5 */
4737 /*********************************************************************/
4739 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4741 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4742 INT nOldHotItem = infoPtr->nHotItem;
4743 TBUTTON_INFO *btnPtr;
4745 NMTBHOTITEM nmhotitem;
4747 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4750 infoPtr->nHotItem = (INT)wParam;
4751 if (nOldHotItem != infoPtr->nHotItem) {
4752 nmhotitem.dwFlags = (DWORD)lParam;
4753 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4754 nmhotitem.idOld = (nOldHotItem >= 0) ?
4755 infoPtr->buttons[nOldHotItem].idCommand : 0;
4756 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4757 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4758 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4759 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4761 if ((INT)wParam >=0) {
4762 btnPtr = &infoPtr->buttons[(INT)wParam];
4763 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4764 InvalidateRect (hwnd, &btnPtr->rect,
4765 TOOLBAR_HasText(infoPtr, btnPtr));
4767 if (nOldHotItem>=0) {
4768 btnPtr = &infoPtr->buttons[nOldHotItem];
4769 btnPtr->bHot = FALSE;
4770 InvalidateRect (hwnd, &btnPtr->rect,
4771 TOOLBAR_HasText(infoPtr, btnPtr));
4774 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4775 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4777 if (nOldHotItem < 0)
4780 return (LRESULT)nOldHotItem;
4783 static LRESULT TOOLBAR_Unkwn460(HWND hwnd, WPARAM wParam, LPARAM lParam)
4785 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4787 InvalidateRect(hwnd, NULL, TRUE);
4791 /* UNDOCUMENTED MESSAGE: This returns the number of maximum number
4792 * of image lists associated with the various states. */
4793 static LRESULT TOOLBAR_Unkwn462(HWND hwnd, WPARAM wParam, LPARAM lParam)
4795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4797 TRACE("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4799 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
4803 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4805 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4806 LPSIZE lpsize = (LPSIZE)lParam;
4812 * Testing shows the following:
4813 * wParam = 0 adjust cx value
4814 * = 1 set cy value to max size.
4815 * lParam pointer to SIZE structure
4818 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4819 wParam, lParam, lpsize->cx, lpsize->cy);
4823 if (lpsize->cx == -1) {
4824 /* **** this is wrong, native measures each button and sets it */
4825 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4827 else if(HIWORD(lpsize->cx)) {
4829 HWND hwndParent = GetParent(hwnd);
4831 GetWindowRect(hwnd, &rc);
4832 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4833 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4834 rc.left, rc.top, rc.right, rc.bottom);
4835 lpsize->cx = max(rc.right-rc.left,
4836 infoPtr->rcBound.right - infoPtr->rcBound.left);
4839 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4843 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4844 /* lpsize->cy = infoPtr->nHeight; */
4847 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4851 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4852 lpsize->cx, lpsize->cy);
4856 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
4858 FIXME("hwnd=%p wParam %08x lParam %08lx\n", hwnd, wParam, lParam);
4860 InvalidateRect(hwnd, NULL, TRUE);
4866 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4869 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4872 TRACE("hwnd = %p\n", hwnd);
4874 /* initialize info structure */
4875 infoPtr->nButtonHeight = 22;
4876 infoPtr->nButtonWidth = 24;
4877 infoPtr->nBitmapHeight = 15;
4878 infoPtr->nBitmapWidth = 16;
4880 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4881 infoPtr->nMaxTextRows = 1;
4882 infoPtr->cxMin = -1;
4883 infoPtr->cxMax = -1;
4884 infoPtr->nNumBitmaps = 0;
4885 infoPtr->nNumStrings = 0;
4887 infoPtr->bCaptured = FALSE;
4888 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4889 infoPtr->nButtonDown = -1;
4890 infoPtr->nOldHit = -1;
4891 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4892 infoPtr->hwndNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
4893 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4894 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4895 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4896 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4897 infoPtr->iVersion = 0;
4898 infoPtr->hwndSelf = hwnd;
4899 infoPtr->bDoRedraw = TRUE;
4900 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4901 infoPtr->clrBtnShadow = CLR_DEFAULT;
4902 infoPtr->szPadding.cx = 7;
4903 infoPtr->szPadding.cy = 6;
4904 GetClientRect(hwnd, &infoPtr->client_rect);
4905 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4907 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4908 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4910 if (dwStyle & TBSTYLE_TOOLTIPS) {
4911 /* Create tooltip control */
4912 infoPtr->hwndToolTip =
4913 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4914 CW_USEDEFAULT, CW_USEDEFAULT,
4915 CW_USEDEFAULT, CW_USEDEFAULT,
4918 /* Send NM_TOOLTIPSCREATED notification */
4919 if (infoPtr->hwndToolTip) {
4920 NMTOOLTIPSCREATED nmttc;
4922 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4924 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4925 NM_TOOLTIPSCREATED);
4929 TOOLBAR_CheckStyle (hwnd, dwStyle);
4931 TOOLBAR_CalcToolbar(hwnd);
4938 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4942 /* delete tooltip control */
4943 if (infoPtr->hwndToolTip)
4944 DestroyWindow (infoPtr->hwndToolTip);
4946 /* delete button data */
4947 if (infoPtr->buttons)
4948 Free (infoPtr->buttons);
4950 /* delete strings */
4951 if (infoPtr->strings) {
4953 for (i = 0; i < infoPtr->nNumStrings; i++)
4954 if (infoPtr->strings[i])
4955 Free (infoPtr->strings[i]);
4957 Free (infoPtr->strings);
4960 /* destroy internal image list */
4961 if (infoPtr->himlInt)
4962 ImageList_Destroy (infoPtr->himlInt);
4964 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
4965 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
4966 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
4968 /* delete default font */
4970 DeleteObject (infoPtr->hDefaultFont);
4972 /* free toolbar info data */
4974 SetWindowLongA (hwnd, 0, 0);
4981 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4983 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4984 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4985 NMTBCUSTOMDRAW tbcd;
4989 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4990 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4991 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4992 tbcd.nmcd.hdc = (HDC)wParam;
4993 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4994 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4996 /* FIXME: in general the return flags *can* be or'ed together */
4997 switch (infoPtr->dwBaseCustDraw)
4999 case CDRF_DODEFAULT:
5001 case CDRF_SKIPDEFAULT:
5004 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5009 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5010 * to my parent for processing.
5012 if (infoPtr->bTransparent) {
5014 HDC hdc = (HDC)wParam;
5019 parent = GetParent(hwnd);
5020 MapWindowPoints(hwnd, parent, &pt, 1);
5021 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5022 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
5023 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5026 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
5028 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
5029 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
5030 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5031 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5032 tbcd.nmcd.hdc = (HDC)wParam;
5033 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
5034 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
5035 switch (infoPtr->dwBaseCustDraw)
5037 case CDRF_DODEFAULT:
5039 case CDRF_SKIPDEFAULT:
5042 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5051 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
5053 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5055 return (LRESULT)infoPtr->hFont;
5060 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
5062 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5063 TBUTTON_INFO *btnPtr;
5067 pt.x = (INT)LOWORD(lParam);
5068 pt.y = (INT)HIWORD(lParam);
5069 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5072 btnPtr = &infoPtr->buttons[nHit];
5073 if (!(btnPtr->fsState & TBSTATE_ENABLED))
5076 infoPtr->bCaptured = TRUE;
5077 infoPtr->nButtonDown = nHit;
5079 btnPtr->fsState |= TBSTATE_PRESSED;
5081 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5084 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
5085 TOOLBAR_Customize (hwnd);
5092 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
5094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5095 TBUTTON_INFO *btnPtr;
5100 if (infoPtr->hwndToolTip)
5101 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5102 WM_LBUTTONDOWN, wParam, lParam);
5104 pt.x = (INT)LOWORD(lParam);
5105 pt.y = (INT)HIWORD(lParam);
5106 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5110 btnPtr = &infoPtr->buttons[nHit];
5111 infoPtr->nOldHit = nHit;
5113 CopyRect(&arrowRect, &btnPtr->rect);
5114 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5116 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5117 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5118 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5119 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5120 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5121 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5125 * this time we must force a Redraw, so the btn is
5126 * painted down before CaptureChanged repaints it up
5128 RedrawWindow(hwnd,&btnPtr->rect,0,
5129 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5131 nmtb.iItem = btnPtr->idCommand;
5132 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
5135 CopyRect(&nmtb.rcButton, &btnPtr->rect);
5136 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5138 if (res != TBDDRET_TREATPRESSED)
5139 /* ??? guess (GA) */
5141 /* otherwise drop through and process as pushed */
5143 /* SetCapture (hwnd); */
5144 infoPtr->bCaptured = TRUE;
5145 infoPtr->nButtonDown = nHit;
5147 btnPtr->fsState |= TBSTATE_PRESSED;
5148 btnPtr->bHot = FALSE;
5150 if (btnPtr->fsState & TBSTATE_ENABLED)
5151 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
5155 /* native issues the TBN_BEGINDRAG here */
5156 nmtb.iItem = btnPtr->idCommand;
5157 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5158 nmtb.tbButton.idCommand = btnPtr->idCommand;
5159 nmtb.tbButton.fsState = btnPtr->fsState;
5160 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5161 nmtb.tbButton.dwData = btnPtr->dwData;
5162 nmtb.tbButton.iString = btnPtr->iString;
5163 nmtb.cchText = 0; /* !!! not correct */
5164 nmtb.pszText = 0; /* !!! not correct */
5165 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5173 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
5175 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5176 TBUTTON_INFO *btnPtr;
5180 BOOL bSendMessage = TRUE;
5185 if (infoPtr->hwndToolTip)
5186 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5187 WM_LBUTTONUP, wParam, lParam);
5189 pt.x = (INT)LOWORD(lParam);
5190 pt.y = (INT)HIWORD(lParam);
5191 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5193 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
5194 /* if the cursor is still inside of the toolbar */
5195 if((infoPtr->nHotItem >= 0) && (nHit != -1))
5196 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
5198 if (0 <= infoPtr->nButtonDown) {
5199 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5200 btnPtr->fsState &= ~TBSTATE_PRESSED;
5202 if (btnPtr->fsStyle & BTNS_CHECK) {
5203 if (btnPtr->fsStyle & BTNS_GROUP) {
5204 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5206 if (nOldIndex == nHit)
5207 bSendMessage = FALSE;
5208 if ((nOldIndex != nHit) &&
5210 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5211 btnPtr->fsState |= TBSTATE_CHECKED;
5214 if (btnPtr->fsState & TBSTATE_CHECKED)
5215 btnPtr->fsState &= ~TBSTATE_CHECKED;
5217 btnPtr->fsState |= TBSTATE_CHECKED;
5221 if (nOldIndex != -1)
5223 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
5224 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
5228 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5229 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5230 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5232 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5234 infoPtr->nButtonDown = -1;
5236 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5237 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5238 NM_RELEASEDCAPTURE);
5240 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5243 nmtb.iItem = btnPtr->idCommand;
5244 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5245 nmtb.tbButton.idCommand = btnPtr->idCommand;
5246 nmtb.tbButton.fsState = btnPtr->fsState;
5247 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5248 nmtb.tbButton.dwData = btnPtr->dwData;
5249 nmtb.tbButton.iString = btnPtr->iString;
5250 nmtb.cchText = 0; /* !!! not correct */
5251 nmtb.pszText = 0; /* !!! not correct */
5252 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5255 if (btnPtr->fsState & TBSTATE_ENABLED)
5257 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5258 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5260 /* !!! Undocumented - toolbar at 4.71 level and above sends
5261 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5262 * Only NM_RCLICK is documented.
5264 nmmouse.dwItemSpec = btnPtr->idCommand;
5265 nmmouse.dwItemData = btnPtr->dwData;
5266 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5273 TOOLBAR_CaptureChanged(HWND hwnd)
5275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5276 TBUTTON_INFO *btnPtr;
5278 infoPtr->bCaptured = FALSE;
5280 if (infoPtr->nButtonDown >= 0)
5282 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5283 btnPtr->fsState &= ~TBSTATE_PRESSED;
5285 infoPtr->nOldHit = -1;
5287 if (btnPtr->fsState & TBSTATE_ENABLED)
5288 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5295 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5298 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5301 if (infoPtr->nOldHit < 0)
5304 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5306 /* Redraw the button if the last button we were over is the hot button and it
5308 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
5310 hotBtnPtr->bHot = FALSE;
5311 rc1 = hotBtnPtr->rect;
5312 InflateRect (&rc1, 1, 1);
5313 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
5317 /* If the last button we were over is depressed then make it not */
5318 /* depressed and redraw it */
5319 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5321 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5323 btnPtr->fsState &= ~TBSTATE_PRESSED;
5325 rc1 = hotBtnPtr->rect;
5326 InflateRect (&rc1, 1, 1);
5327 InvalidateRect (hwnd, &rc1, TRUE);
5330 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5331 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
5337 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5339 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5343 TRACKMOUSEEVENT trackinfo;
5344 NMTBHOTITEM nmhotitem;
5346 /* fill in the TRACKMOUSEEVENT struct */
5347 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5348 trackinfo.dwFlags = TME_QUERY;
5349 trackinfo.hwndTrack = hwnd;
5350 trackinfo.dwHoverTime = HOVER_DEFAULT;
5352 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5353 _TrackMouseEvent(&trackinfo);
5355 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5356 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5357 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5359 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5360 /* and can properly deactivate the hot toolbar button */
5361 _TrackMouseEvent(&trackinfo);
5364 if (infoPtr->hwndToolTip)
5365 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5366 WM_MOUSEMOVE, wParam, lParam);
5368 pt.x = (INT)LOWORD(lParam);
5369 pt.y = (INT)HIWORD(lParam);
5371 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5373 if (infoPtr->nOldHit != nHit)
5375 /* Remove the effect of an old hot button if the button was
5376 drawn with the hot button effect */
5377 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem)
5379 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5380 oldBtnPtr->bHot = FALSE;
5383 /* It's not a separator or in nowhere. It's a hot button. */
5386 btnPtr = &infoPtr->buttons[nHit];
5388 infoPtr->nHotItem = nHit;
5390 btnPtr->bHot = TRUE;
5393 nmhotitem.dwFlags = HICF_MOUSE;
5395 nmhotitem.idOld = oldBtnPtr->idCommand;
5397 nmhotitem.dwFlags |= HICF_ENTERING;
5399 nmhotitem.idNew = btnPtr->idCommand;
5401 nmhotitem.dwFlags |= HICF_LEAVING;
5402 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5404 /* now invalidate the old and new buttons so they will be painted */
5406 InvalidateRect (hwnd, &oldBtnPtr->rect,
5407 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5409 InvalidateRect(hwnd, &btnPtr->rect,
5410 TOOLBAR_HasText(infoPtr, btnPtr));
5412 if (infoPtr->bCaptured) {
5413 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5414 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5415 btnPtr->fsState &= ~TBSTATE_PRESSED;
5416 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5418 else if (nHit == infoPtr->nButtonDown) {
5419 btnPtr->fsState |= TBSTATE_PRESSED;
5420 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5423 infoPtr->nOldHit = nHit;
5429 inline static LRESULT
5430 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5432 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5433 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5435 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5439 inline static LRESULT
5440 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5442 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5443 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5445 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5450 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5452 TOOLBAR_INFO *infoPtr;
5453 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5456 /* allocate memory for info structure */
5457 infoPtr = (TOOLBAR_INFO *)Alloc (sizeof(TOOLBAR_INFO));
5458 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5461 infoPtr->dwStructSize = sizeof(TBBUTTON);
5464 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5465 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5466 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5467 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5470 /* native control does:
5471 * Get a lot of colors and brushes
5473 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5474 * CreateFontIndirectA(adr1)
5475 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5476 * hdc = GetDC(toolbar)
5477 * GetSystemMetrics(0x48)
5478 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5479 * 0, 0, 0, 0, "MARLETT")
5480 * oldfnt = SelectObject(hdc, fnt2)
5481 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5482 * GetTextMetricsA(hdc, adr3)
5483 * SelectObject(hdc, oldfnt)
5484 * DeleteObject(fnt2)
5486 * InvalidateRect(toolbar, 0, 1)
5487 * SetWindowLongA(toolbar, 0, addr)
5488 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5491 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5492 * ie 2 0x4600094c 0x4600094c 0x4600894d
5493 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5494 * rebar 0x50008844 0x40008844 0x50008845
5495 * pager 0x50000844 0x40000844 0x50008845
5496 * IC35mgr 0x5400084e **nochange**
5497 * on entry to _NCCREATE 0x5400084e
5498 * rowlist 0x5400004e **nochange**
5499 * on entry to _NCCREATE 0x5400004e
5503 /* I think the code below is a bug, but it is the way that the native
5504 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5505 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5506 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5507 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5508 * Some how, the only cases of this seem to be MFC programs.
5510 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5511 * does not occur in the WM_STYLECHANGING routine.
5512 * (Guy Albertelli 9/2001)
5515 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5516 styleadd |= TBSTYLE_TRANSPARENT;
5517 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5518 styleadd |= CCS_TOP; /* default to top */
5519 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5522 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5527 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5529 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5533 if (dwStyle & WS_MINIMIZE)
5534 return 0; /* Nothing to do */
5536 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5538 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5541 if (!(dwStyle & CCS_NODIVIDER))
5543 GetWindowRect (hwnd, &rcWindow);
5544 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5545 if( dwStyle & WS_BORDER )
5546 OffsetRect (&rcWindow, 1, 1);
5547 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5550 ReleaseDC( hwnd, hdc );
5556 inline static LRESULT
5557 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5559 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5560 LPNMHDR lpnmh = (LPNMHDR)lParam;
5562 if (lpnmh->code == PGN_CALCSIZE) {
5563 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5565 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5566 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5567 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5571 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5572 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5578 if (lpnmh->code == PGN_SCROLL) {
5579 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5581 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5582 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5583 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5584 lppgs->iScroll, lppgs->iDir);
5589 TRACE("passing WM_NOTIFY!\n");
5591 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5592 if (infoPtr->bNtfUnicode)
5593 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5596 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5600 if (lpnmh->code == TTN_GETDISPINFOA) {
5601 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5603 FIXME("retrieving ASCII string\n");
5606 else if (lpnmh->code == TTN_GETDISPINFOW) {
5607 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5609 FIXME("retrieving UNICODE string\n");
5620 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5622 /* remove this routine when Toolbar is improved to pass infoPtr
5623 * around instead of hwnd.
5625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5626 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5631 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5635 if (lParam == NF_REQUERY) {
5636 i = SendMessageA(infoPtr->hwndNotify,
5637 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5638 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5639 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5643 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5646 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5651 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5653 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5657 /* fill ps.rcPaint with a default rect */
5658 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5660 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5662 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5663 ps.rcPaint.left, ps.rcPaint.top,
5664 ps.rcPaint.right, ps.rcPaint.bottom);
5666 TOOLBAR_Refresh (hwnd, hdc, &ps);
5667 if (!wParam) EndPaint (hwnd, &ps);
5674 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5675 /*****************************************************
5678 * Handles the WM_SETREDRAW message.
5681 * According to testing V4.71 of COMCTL32 returns the
5682 * *previous* status of the redraw flag (either 0 or 1)
5683 * instead of the MSDN documented value of 0 if handled.
5684 * (For laughs see the "consistency" with same function
5687 *****************************************************/
5689 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5690 BOOL oldredraw = infoPtr->bDoRedraw;
5692 TRACE("set to %s\n",
5693 (wParam) ? "TRUE" : "FALSE");
5694 infoPtr->bDoRedraw = (BOOL) wParam;
5696 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5698 return (oldredraw) ? 1 : 0;
5703 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5705 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5706 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5715 /* Resize deadlock check */
5716 if (infoPtr->bAutoSize) {
5717 infoPtr->bAutoSize = FALSE;
5721 /* FIXME: optimize to only update size if the new size doesn't */
5722 /* match the current size */
5724 flags = (INT) wParam;
5726 /* FIXME for flags =
5727 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5730 TRACE("sizing toolbar!\n");
5732 if (flags == SIZE_RESTORED) {
5733 /* width and height don't apply */
5734 parent = GetParent (hwnd);
5735 GetClientRect(parent, &parent_rect);
5736 x = parent_rect.left;
5737 y = parent_rect.top;
5739 if (dwStyle & CCS_NORESIZE) {
5740 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5743 * this sets the working width of the toolbar, and
5744 * Calc Toolbar will not adjust it, only the height
5746 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5747 cy = infoPtr->nHeight;
5748 cx = infoPtr->nWidth;
5749 TOOLBAR_CalcToolbar (hwnd);
5750 infoPtr->nWidth = cx;
5751 infoPtr->nHeight = cy;
5754 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5755 TOOLBAR_CalcToolbar (hwnd);
5756 cy = infoPtr->nHeight;
5757 cx = infoPtr->nWidth;
5759 if ((dwStyle & CCS_BOTTOM) == CCS_NOMOVEY) {
5760 GetWindowRect(hwnd, &window_rect);
5761 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5762 y = window_rect.top;
5764 if ((dwStyle & CCS_BOTTOM) == CCS_BOTTOM) {
5765 GetWindowRect(hwnd, &window_rect);
5766 y = parent_rect.bottom -
5767 ( window_rect.bottom - window_rect.top);
5771 if (dwStyle & CCS_NOPARENTALIGN) {
5772 uPosFlags |= SWP_NOMOVE;
5773 cy = infoPtr->nHeight;
5774 cx = infoPtr->nWidth;
5777 if (!(dwStyle & CCS_NODIVIDER))
5778 cy += GetSystemMetrics(SM_CYEDGE);
5780 if (dwStyle & WS_BORDER)
5783 cy += GetSystemMetrics(SM_CYEDGE);
5784 cx += GetSystemMetrics(SM_CYEDGE);
5787 if(infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
5789 RECT delta_width, delta_height, client, dummy;
5790 DWORD min_x, max_x, min_y, max_y;
5791 TBUTTON_INFO *btnPtr;
5794 GetClientRect(hwnd, &client);
5795 if(client.right > infoPtr->client_rect.right)
5797 min_x = infoPtr->client_rect.right;
5798 max_x = client.right;
5802 max_x = infoPtr->client_rect.right;
5803 min_x = client.right;
5805 if(client.bottom > infoPtr->client_rect.bottom)
5807 min_y = infoPtr->client_rect.bottom;
5808 max_y = client.bottom;
5812 max_y = infoPtr->client_rect.bottom;
5813 min_y = client.bottom;
5816 SetRect(&delta_width, min_x, 0, max_x, min_y);
5817 SetRect(&delta_height, 0, min_y, max_x, max_y);
5819 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
5820 btnPtr = infoPtr->buttons;
5821 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
5822 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
5823 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
5824 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5827 if((uPosFlags & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE))
5828 SetWindowPos (hwnd, 0, x, y, cx, cy, uPosFlags | SWP_NOZORDER);
5830 GetClientRect(hwnd, &infoPtr->client_rect);
5836 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5840 if (nType == GWL_STYLE) {
5841 if (lpStyle->styleNew & TBSTYLE_LIST) {
5842 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5845 infoPtr->dwDTFlags = DT_CENTER;
5847 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5848 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5849 (TBSTYLE_FLAT | TBSTYLE_LIST));
5850 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5852 TRACE("new style 0x%08lx\n", lpStyle->styleNew);
5855 TOOLBAR_CalcToolbar(hwnd);
5857 TOOLBAR_AutoSize (hwnd);
5859 InvalidateRect(hwnd, NULL, FALSE);
5866 TOOLBAR_SysColorChange (HWND hwnd)
5868 COMCTL32_RefreshSysColors();
5875 static LRESULT WINAPI
5876 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5878 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5880 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
5881 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5883 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5884 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5889 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5891 case TB_ADDBUTTONSA:
5892 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5894 case TB_ADDBUTTONSW:
5895 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5898 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5901 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5904 return TOOLBAR_AutoSize (hwnd);
5906 case TB_BUTTONCOUNT:
5907 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5909 case TB_BUTTONSTRUCTSIZE:
5910 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5912 case TB_CHANGEBITMAP:
5913 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5915 case TB_CHECKBUTTON:
5916 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5918 case TB_COMMANDTOINDEX:
5919 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5922 return TOOLBAR_Customize (hwnd);
5924 case TB_DELETEBUTTON:
5925 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5927 case TB_ENABLEBUTTON:
5928 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5930 case TB_GETANCHORHIGHLIGHT:
5931 return TOOLBAR_GetAnchorHighlight (hwnd);
5934 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5936 case TB_GETBITMAPFLAGS:
5937 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5940 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5942 case TB_GETBUTTONINFOA:
5943 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5945 case TB_GETBUTTONINFOW:
5946 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5948 case TB_GETBUTTONSIZE:
5949 return TOOLBAR_GetButtonSize (hwnd);
5951 case TB_GETBUTTONTEXTA:
5952 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5954 case TB_GETBUTTONTEXTW:
5955 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5957 case TB_GETDISABLEDIMAGELIST:
5958 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5960 case TB_GETEXTENDEDSTYLE:
5961 return TOOLBAR_GetExtendedStyle (hwnd);
5963 case TB_GETHOTIMAGELIST:
5964 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5967 return TOOLBAR_GetHotItem (hwnd);
5969 case TB_GETIMAGELIST:
5970 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
5972 /* case TB_GETINSERTMARK: */ /* 4.71 */
5973 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5975 case TB_GETITEMRECT:
5976 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5979 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5981 /* case TB_GETOBJECT: */ /* 4.71 */
5984 return TOOLBAR_GetPadding (hwnd);
5987 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5990 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5993 return TOOLBAR_GetState (hwnd, wParam, lParam);
5996 return TOOLBAR_GetStringA (hwnd, wParam, lParam);
5999 return TOOLBAR_GetStringW (hwnd, wParam, lParam);
6002 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
6004 case TB_GETTEXTROWS:
6005 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
6007 case TB_GETTOOLTIPS:
6008 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
6010 case TB_GETUNICODEFORMAT:
6011 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
6014 return TOOLBAR_HideButton (hwnd, wParam, lParam);
6017 return TOOLBAR_HitTest (hwnd, wParam, lParam);
6019 case TB_INDETERMINATE:
6020 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
6022 case TB_INSERTBUTTONA:
6023 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
6025 case TB_INSERTBUTTONW:
6026 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
6028 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6030 case TB_ISBUTTONCHECKED:
6031 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
6033 case TB_ISBUTTONENABLED:
6034 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
6036 case TB_ISBUTTONHIDDEN:
6037 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
6039 case TB_ISBUTTONHIGHLIGHTED:
6040 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
6042 case TB_ISBUTTONINDETERMINATE:
6043 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
6045 case TB_ISBUTTONPRESSED:
6046 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
6048 case TB_LOADIMAGES: /* 4.70 */
6049 FIXME("missing standard imagelists\n");
6052 /* case TB_MAPACCELERATORA: */ /* 4.71 */
6053 /* case TB_MAPACCELERATORW: */ /* 4.71 */
6054 /* case TB_MARKBUTTON: */ /* 4.71 */
6055 /* case TB_MOVEBUTTON: */ /* 4.71 */
6057 case TB_PRESSBUTTON:
6058 return TOOLBAR_PressButton (hwnd, wParam, lParam);
6060 case TB_REPLACEBITMAP:
6061 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
6063 case TB_SAVERESTOREA:
6064 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
6066 case TB_SAVERESTOREW:
6067 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
6069 case TB_SETANCHORHIGHLIGHT:
6070 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
6072 case TB_SETBITMAPSIZE:
6073 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
6075 case TB_SETBUTTONINFOA:
6076 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
6078 case TB_SETBUTTONINFOW:
6079 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
6081 case TB_SETBUTTONSIZE:
6082 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
6084 case TB_SETBUTTONWIDTH:
6085 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
6088 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
6090 case TB_SETDISABLEDIMAGELIST:
6091 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
6093 case TB_SETDRAWTEXTFLAGS:
6094 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
6096 case TB_SETEXTENDEDSTYLE:
6097 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
6099 case TB_SETHOTIMAGELIST:
6100 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
6103 return TOOLBAR_SetHotItem (hwnd, wParam);
6105 case TB_SETIMAGELIST:
6106 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
6109 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
6111 /* case TB_SETINSERTMARK: */ /* 4.71 */
6113 case TB_SETINSERTMARKCOLOR:
6114 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
6116 case TB_SETMAXTEXTROWS:
6117 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
6120 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
6123 return TOOLBAR_SetParent (hwnd, wParam, lParam);
6126 return TOOLBAR_SetRows (hwnd, wParam, lParam);
6129 return TOOLBAR_SetState (hwnd, wParam, lParam);
6132 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
6134 case TB_SETTOOLTIPS:
6135 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
6137 case TB_SETUNICODEFORMAT:
6138 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
6141 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6144 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
6147 return TOOLBAR_Unkwn460(hwnd, wParam, lParam);
6150 return TOOLBAR_Unkwn462(hwnd, wParam, lParam);
6153 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
6156 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6158 /* Common Control Messages */
6160 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6161 case CCM_GETCOLORSCHEME:
6162 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6164 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6165 case CCM_SETCOLORSCHEME:
6166 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
6168 case CCM_GETVERSION:
6169 return TOOLBAR_GetVersion (hwnd);
6171 case CCM_SETVERSION:
6172 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
6178 return TOOLBAR_Create (hwnd, wParam, lParam);
6181 return TOOLBAR_Destroy (hwnd, wParam, lParam);
6184 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
6187 return TOOLBAR_GetFont (hwnd, wParam, lParam);
6189 /* case WM_KEYDOWN: */
6190 /* case WM_KILLFOCUS: */
6192 case WM_LBUTTONDBLCLK:
6193 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
6195 case WM_LBUTTONDOWN:
6196 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
6199 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
6202 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
6205 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
6207 case WM_CAPTURECHANGED:
6208 return TOOLBAR_CaptureChanged(hwnd);
6211 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6214 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6217 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
6220 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6223 return TOOLBAR_Notify (hwnd, wParam, lParam);
6225 case WM_NOTIFYFORMAT:
6226 return TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
6229 return TOOLBAR_Paint (hwnd, wParam);
6232 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
6235 return TOOLBAR_Size (hwnd, wParam, lParam);
6237 case WM_STYLECHANGED:
6238 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
6240 case WM_SYSCOLORCHANGE:
6241 return TOOLBAR_SysColorChange (hwnd);
6243 /* case WM_WININICHANGE: */
6248 case WM_MEASUREITEM:
6250 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
6252 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6253 case PGM_FORWARDMOUSE:
6254 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6257 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
6258 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
6259 uMsg, wParam, lParam);
6260 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6267 TOOLBAR_Register (void)
6271 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6272 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6273 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6274 wndClass.cbClsExtra = 0;
6275 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6276 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
6277 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6278 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6280 RegisterClassA (&wndClass);
6285 TOOLBAR_Unregister (void)
6287 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6290 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6295 /* Check if the entry already exists */
6296 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6298 /* If this is a new entry we must create it and insert into the array */
6303 c = (PIMLENTRY) Alloc(sizeof(IMLENTRY));
6306 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6307 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6322 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6326 for (i = 0; i < *cies; i++)
6336 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6344 for (i = 0; i < cies; i++)
6346 if (pies[i]->id == id)
6358 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6360 HIMAGELIST himlDef = 0;
6361 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6364 himlDef = pie->himl;
6370 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6372 if (infoPtr->bUnicode)
6373 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6380 nmtba.iItem = nmtb->iItem;
6381 nmtba.pszText = Buffer;
6382 nmtba.cchText = 256;
6383 ZeroMemory(nmtba.pszText, nmtba.cchText);
6385 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6387 int ccht = strlen(nmtba.pszText);
6389 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6390 nmtb->pszText, nmtb->cchText);
6392 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6401 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6402 int iItem, PCUSTOMBUTTON btnInfo)
6407 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6409 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);