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 * - A little bug in TOOLBAR_DrawMasked()
33 * - Button wrapping (under construction).
35 * - Notifications (under construction).
37 * - Tooltip support (almost complete).
38 * - Unicode suppport (under construction).
39 * - Fix TOOLBAR_SetButtonInfo32A/W.
40 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
41 * - I_IMAGECALLBACK support.
42 * - iString of -1 is undocumented
43 * - Customization dialog:
45 * - Minor buglet in 'available buttons' list:
46 * Buttons are not listed in M$-like order. M$ seems to use a single
47 * internal list to store the button information of both listboxes.
48 * - Drag list support.
49 * - Help and Reset button support.
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsofts controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
68 #include "wine/unicode.h"
70 #include "imagelist.h"
72 #include "wine/debug.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
99 DWORD dwStructSize; /* size of TBBUTTON struct */
100 INT nHeight; /* height of the toolbar */
101 INT nWidth; /* width of the toolbar */
107 INT nRows; /* number of button rows */
108 INT nMaxTextRows; /* maximum number of text rows */
109 INT cxMin; /* minimum button width */
110 INT cxMax; /* maximum button width */
111 INT nNumButtons; /* number of buttons */
112 INT nNumBitmaps; /* number of bitmaps */
113 INT nNumStrings; /* number of strings */
115 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
116 BOOL bCaptured; /* mouse captured? */
119 INT nHotItem; /* index of the "hot" item */
120 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
121 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
122 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
123 SIZE szPadding; /* padding values around button */
125 HFONT hFont; /* text font */
126 HIMAGELIST himlInt; /* image list created internally */
127 HIMAGELIST himlDef; /* default image list */
128 HIMAGELIST himlHot; /* hot image list */
129 HIMAGELIST himlDis; /* disabled image list */
130 HWND hwndToolTip; /* handle to tool tip control */
131 HWND hwndNotify; /* handle to the window that gets notifications */
132 HWND hwndSelf; /* my own handle */
133 BOOL bTransparent; /* background transparency flag */
134 BOOL bBtnTranspnt; /* button transparency flag */
135 BOOL bAutoSize; /* auto size deadlock indicator */
136 BOOL bAnchor; /* anchor highlight enabled */
137 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
138 BOOL bDoRedraw; /* Redraw status */
139 DWORD dwExStyle; /* extended toolbar style */
140 DWORD dwDTFlags; /* DrawText flags */
142 COLORREF clrInsertMark; /* insert mark color */
143 COLORREF clrBtnHighlight; /* color for Flat Separator */
144 COLORREF clrBtnShadow; /* color for Flag Separator */
145 RECT rcBound; /* bounding rectangle */
148 TBUTTON_INFO *buttons; /* pointer to button array */
149 LPWSTR *strings; /* pointer to string array */
150 TBITMAP_INFO *bitmaps;
151 } TOOLBAR_INFO, *PTOOLBAR_INFO;
154 /* used by customization dialog */
157 PTOOLBAR_INFO tbInfo;
159 } CUSTDLG_INFO, *PCUSTDLG_INFO;
167 } CUSTOMBUTTON, *PCUSTOMBUTTON;
170 #define SEPARATOR_WIDTH 8
172 #define BOTTOM_BORDER 2
173 #define DDARROW_WIDTH 11
175 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
176 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
177 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
179 /* Used to find undocumented extended styles */
180 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
181 TBSTYLE_EX_UNDOC1 | \
182 TBSTYLE_EX_MIXEDBUTTONS | \
183 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
186 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
190 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
192 LPWSTR lpText = NULL;
194 /* FIXME: iString == -1 is undocumented */
195 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
196 lpText = (LPWSTR)btnPtr->iString;
197 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
198 lpText = infoPtr->strings[btnPtr->iString];
204 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
206 if (TRACE_ON(toolbar)){
207 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
208 btn_num, bP->idCommand,
209 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
210 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
212 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
213 btn_num, bP->idCommand,
214 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
215 bP->rect.left, bP->rect.top,
216 bP->rect.right, bP->rect.bottom);
222 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
224 if (TRACE_ON(toolbar)) {
228 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
229 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
231 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
232 iP->nNumStrings, dwStyle);
233 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
235 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
236 (iP->bDoRedraw) ? "TRUE" : "FALSE");
237 for(i=0; i<iP->nNumButtons; i++) {
238 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
244 /***********************************************************************
247 * This function validates that the styles set are implemented and
248 * issues FIXME's warning of possible problems. In a perfect world this
249 * function should be null.
252 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
254 if (dwStyle & TBSTYLE_ALTDRAG)
255 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
256 if (dwStyle & TBSTYLE_REGISTERDROP)
257 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
262 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
264 if(!IsWindow(infoPtr->hwndSelf))
265 return 0; /* we have just been destroyed */
267 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
268 nmhdr->hwndFrom = infoPtr->hwndSelf;
271 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
272 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
274 if (infoPtr->bNtfUnicode)
275 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
276 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
278 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
279 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
282 /***********************************************************************
283 * TOOLBAR_GetBitmapIndex
285 * This function returns the bitmap index associated with a button.
286 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
287 * is issued to retrieve the index.
290 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
292 INT ret = btnPtr->iBitmap;
294 if (ret == I_IMAGECALLBACK) {
295 /* issue TBN_GETDISPINFO */
298 nmgd.idCommand = btnPtr->idCommand;
299 nmgd.lParam = btnPtr->dwData;
300 nmgd.dwMask = TBNF_IMAGE;
301 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
302 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
304 if (nmgd.dwMask & TBNF_DI_SETITEM) {
305 btnPtr->iBitmap = nmgd.iImage;
308 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
309 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
316 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
318 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
319 (index == I_IMAGECALLBACK))
326 /***********************************************************************
327 * TOOLBAR_DrawImageList
329 * This function validates the bitmap index (including I_IMAGECALLBACK
330 * functionality). It then draws the image via the ImageList_Draw
331 * function. It returns TRUE if the image was drawn, FALSE otherwise.
334 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
335 HDC hdc, UINT left, UINT top, UINT draw_flags)
339 if (!himl) return FALSE;
341 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
342 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
343 ERR("index %d is not valid, max %d\n",
344 btnPtr->iBitmap, infoPtr->nNumBitmaps);
348 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
349 if ((index == I_IMAGECALLBACK) ||
350 (index == I_IMAGENONE)) return FALSE;
351 ERR("TBN_GETDISPINFO returned invalid index %d\n",
355 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
356 index, himl, left, top, draw_flags);
358 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
363 /***********************************************************************
364 * TOOLBAR_TestImageExist
366 * This function is similar to TOOLBAR_DrawImageList, except it does not
367 * draw the image. The I_IMAGECALLBACK functionality is implemented.
370 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
374 if (!himl) return FALSE;
376 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
377 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
378 ERR("index %d is not valid, max %d\n",
379 btnPtr->iBitmap, infoPtr->nNumBitmaps);
383 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
384 if ((index == I_IMAGECALLBACK) ||
385 (index == I_IMAGENONE)) return FALSE;
386 ERR("TBN_GETDISPINFO returned invalid index %d\n",
395 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
398 COLORREF oldcolor, newcolor;
400 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
401 myrect.right = myrect.left + 1;
402 myrect.top = lpRect->top + 2;
403 myrect.bottom = lpRect->bottom - 2;
405 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
406 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
407 oldcolor = SetBkColor (hdc, newcolor);
408 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
410 myrect.left = myrect.right;
411 myrect.right = myrect.left + 1;
413 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
414 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
415 SetBkColor (hdc, newcolor);
416 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
418 SetBkColor (hdc, oldcolor);
422 /***********************************************************************
423 * TOOLBAR_DrawDDFlatSeparator
425 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
426 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
427 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
428 * are horizontal as opposed to the vertical separators for not dropdown
431 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
434 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
437 COLORREF oldcolor, newcolor;
439 myrect.left = lpRect->left;
440 myrect.right = lpRect->right;
441 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
442 myrect.bottom = myrect.top + 1;
444 InflateRect (&myrect, -2, 0);
446 TRACE("rect=(%d,%d)-(%d,%d)\n",
447 myrect.left, myrect.top, myrect.right, myrect.bottom);
449 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
450 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
451 oldcolor = SetBkColor (hdc, newcolor);
452 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
454 myrect.top = myrect.bottom;
455 myrect.bottom = myrect.top + 1;
457 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
458 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
459 SetBkColor (hdc, newcolor);
460 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
462 SetBkColor (hdc, oldcolor);
467 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
470 SelectObject ( hdc, GetSysColorPen (colorRef));
473 MoveToEx (hdc, x, y, NULL);
474 LineTo (hdc, x+5, y++); x++;
475 MoveToEx (hdc, x, y, NULL);
476 LineTo (hdc, x+3, y++); x++;
477 MoveToEx (hdc, x, y, NULL);
478 LineTo (hdc, x+1, y++);
482 * Draw the text string for this button.
483 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
484 * is non-zero, so we can simply check himlDef to see if we have
488 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
489 HDC hdc, INT nState, DWORD dwStyle,
490 RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
497 TRACE("string rect=(%d,%d)-(%d,%d)\n",
498 rcText->left, rcText->top, rcText->right, rcText->bottom);
500 hOldFont = SelectObject (hdc, infoPtr->hFont);
501 if (!(nState & TBSTATE_ENABLED)) {
502 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
503 OffsetRect (rcText, 1, 1);
504 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
505 SetTextColor (hdc, comctl32_color.clr3dShadow);
506 OffsetRect (rcText, -1, -1);
508 else if (nState & TBSTATE_INDETERMINATE) {
509 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
511 else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
512 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
515 clrOld = SetTextColor (hdc, tbcd->clrText);
518 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
519 SetTextColor (hdc, clrOld);
520 SelectObject (hdc, hOldFont);
526 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
528 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
529 INT cx = lpRect->right - lpRect->left;
530 INT cy = lpRect->bottom - lpRect->top;
531 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
532 SelectObject (hdc, hbr);
537 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
538 HDC hdc, INT x, INT y)
540 /* FIXME: this function is a hack since it uses image list
541 internals directly */
543 HIMAGELIST himl = infoPtr->himlDef;
551 /* create new dc's */
552 hdcImageList = CreateCompatibleDC (0);
553 hdcMask = CreateCompatibleDC (0);
555 /* create new bitmap */
556 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
557 SelectObject (hdcMask, hbmMask);
559 /* copy the mask bitmap */
560 SelectObject (hdcImageList, himl->hbmMask);
561 SetBkColor (hdcImageList, RGB(255, 255, 255));
562 SetTextColor (hdcImageList, RGB(0, 0, 0));
563 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
564 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
566 /* draw the new mask */
567 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
568 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
569 hdcMask, 0, 0, 0xB8074A);
571 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
572 BitBlt (hdc, x, y, himl->cx, himl->cy,
573 hdcMask, 0, 0, 0xB8074A);
575 DeleteObject (hbmMask);
577 DeleteDC (hdcImageList);
582 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
586 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
587 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
588 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
589 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
590 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
591 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
592 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
593 /* don't test TBSTATE_HIDDEN */
599 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
602 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
603 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
604 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
605 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
606 LPWSTR lpText = NULL;
611 if (btnPtr->fsState & TBSTATE_HIDDEN)
615 CopyRect (&rcFill, &rc);
616 CopyRect (&rcArrow, &rc);
617 CopyRect(&rcBitmap, &rc);
618 CopyRect(&rcText, &rc);
620 /* get a pointer to the text */
621 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
623 if (hasDropDownArrow)
625 if (dwStyle & TBSTYLE_FLAT)
626 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
628 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
629 rcArrow.left = rc.right;
632 /* Center the bitmap horizontally and vertically */
633 if (dwStyle & TBSTYLE_LIST)
636 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
639 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
641 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
643 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
644 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
645 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
646 TRACE ("iString: %x\n", btnPtr->iString);
647 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
652 InflateRect (&rcText, -3, -3);
654 if (infoPtr->himlDef &&
655 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
656 /* The following test looked like this before
657 * I changed it. IE4 "Links" toolbar would not
658 * draw correctly with the original code. - GA 8/01
659 * ((dwStyle & TBSTYLE_LIST) &&
660 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
661 * (btnPtr->iBitmap != I_IMAGENONE))
663 if (dwStyle & TBSTYLE_LIST) {
664 /* LIST style w/ ICON offset is by matching native. */
665 /* Matches IE4 "Links" bar. - GA 8/01 */
666 rcText.left += (infoPtr->nBitmapWidth + 2);
669 rcText.top += infoPtr->nBitmapHeight + 1;
673 if (dwStyle & TBSTYLE_LIST) {
674 /* LIST style w/o ICON offset is by matching native. */
675 /* Matches IE4 "menu" bar. - GA 8/01 */
680 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
681 OffsetRect (&rcText, 1, 1);
684 /* Initialize fields in all cases, because we use these later */
685 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
686 tbcd.clrText = comctl32_color.clrBtnText;
687 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
688 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
689 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
690 tbcd.clrMark = comctl32_color.clrHighlight;
691 tbcd.clrHighlightHotTrack = 0;
692 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
693 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
694 /* MSDN says that this is the text rectangle. */
695 /* But (why always a but) tracing of v5.7 of native shows */
696 /* that this is really a *relative* rectangle based on the */
697 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
698 /* any bitmap that might be present. */
699 tbcd.rcText.left = 0;
701 tbcd.rcText.right = rcText.right - rc.left;
702 tbcd.rcText.bottom = rcText.bottom - rc.top;
704 /* FIXME: what should these be set to ????? */
705 tbcd.hbrMonoDither = 0;
709 /* Issue Item Prepaint notify */
710 infoPtr->dwItemCustDraw = 0;
711 infoPtr->dwItemCDFlag = 0;
712 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
714 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
717 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
718 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
719 tbcd.nmcd.lItemlParam = btnPtr->dwData;
720 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
721 infoPtr->dwItemCustDraw = ntfret & 0xffff;
722 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
723 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
725 /* save the only part of the rect that the user can change */
726 rcText.right = tbcd.rcText.right + rc.left;
727 rcText.bottom = tbcd.rcText.bottom + rc.top;
730 if (!infoPtr->bBtnTranspnt)
731 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
734 if (btnPtr->fsStyle & TBSTYLE_SEP) {
735 /* with the FLAT style, iBitmap is the width and has already */
736 /* been taken into consideration in calculating the width */
737 /* so now we need to draw the vertical separator */
738 /* empirical tests show that iBitmap can/will be non-zero */
739 /* when drawing the vertical bar... */
740 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
741 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
742 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
744 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
746 else if (btnPtr->fsStyle != TBSTYLE_SEP) {
747 FIXME("Draw some kind of separator: fsStyle=%x\n",
754 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
755 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
757 DrawEdge (hdc, &rc, EDGE_RAISED,
758 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
759 if (hasDropDownArrow)
760 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
761 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
764 if (hasDropDownArrow)
766 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
767 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
770 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
771 hdc, rcBitmap.left, rcBitmap.top,
773 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
775 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
779 /* pressed TBSTYLE_BUTTON */
780 if (btnPtr->fsState & TBSTATE_PRESSED) {
781 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
782 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
784 if (dwStyle & TBSTYLE_FLAT)
786 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
787 if (hasDropDownArrow)
788 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
792 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
793 if (hasDropDownArrow)
794 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
798 if (hasDropDownArrow)
799 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
801 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
802 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
805 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
809 /* checked TBSTYLE_CHECK */
810 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
811 (btnPtr->fsState & TBSTATE_CHECKED)) {
812 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
814 if (dwStyle & TBSTYLE_FLAT)
815 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
816 BF_RECT | BF_ADJUST);
818 DrawEdge (hdc, &rc, EDGE_SUNKEN,
819 BF_RECT | BF_MIDDLE | BF_ADJUST);
822 TOOLBAR_DrawPattern (hdc, &rc);
824 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
825 hdc, rcBitmap.left+1, rcBitmap.top+1,
828 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
833 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
834 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
835 DrawEdge (hdc, &rc, EDGE_RAISED,
836 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
838 TOOLBAR_DrawPattern (hdc, &rc);
839 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
840 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
845 if (dwStyle & TBSTYLE_FLAT)
849 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
853 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
854 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
855 if (hasDropDownArrow)
856 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
857 SetBkColor(hdc, oldclr);
861 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
863 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
864 if (hasDropDownArrow)
865 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
870 else /* The following code needs to be removed after
871 * "hot item" support has been implemented for the
872 * case where it is being de-selected.
875 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
876 if (hasDropDownArrow)
877 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
881 if (hasDropDownArrow)
882 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
885 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
886 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
889 rcBitmap.top, ILD_NORMAL))
890 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
891 hdc, rcBitmap.left, rcBitmap.top,
895 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
896 hdc, rcBitmap.left, rcBitmap.top,
901 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
902 DrawEdge (hdc, &rc, EDGE_RAISED,
903 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
905 if (hasDropDownArrow)
907 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
908 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
909 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
910 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
913 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
914 hdc, rcBitmap.left, rcBitmap.top,
918 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
921 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
923 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
926 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
927 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
928 tbcd.nmcd.lItemlParam = btnPtr->dwData;
929 tbcd.rcText = rcText;
930 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
931 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
932 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
939 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
942 TBUTTON_INFO *btnPtr;
943 INT i, oldBKmode = 0;
948 /* if imagelist belongs to the app, it can be changed
949 by the app after setting it */
950 if (infoPtr->himlDef != infoPtr->himlInt)
951 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
953 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
955 /* Send initial notify */
956 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
957 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
959 tbcd.nmcd.rc = ps->rcPaint;
960 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
961 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
963 if (infoPtr->bBtnTranspnt)
964 oldBKmode = SetBkMode (hdc, TRANSPARENT);
966 /* redraw necessary buttons */
967 btnPtr = infoPtr->buttons;
968 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
970 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
971 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
974 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
975 SetBkMode (hdc, oldBKmode);
977 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
979 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
980 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
982 tbcd.nmcd.rc = ps->rcPaint;
983 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
987 /***********************************************************************
988 * TOOLBAR_MeasureString
990 * This function gets the width and height of a string in pixels. This
991 * is done first by using GetTextExtentPoint to get the basic width
992 * and height. The DrawText is called with DT_CALCRECT to get the exact
993 * width. The reason is because the text may have more than one "&" (or
994 * prefix characters as M$ likes to call them). The prefix character
995 * indicates where the underline goes, except for the string "&&" which
996 * is reduced to a single "&". GetTextExtentPoint does not process these
997 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
1000 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1001 HDC hdc, LPSIZE lpSize)
1008 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
1010 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1012 if(lpText != NULL) {
1013 /* first get size of all the text */
1014 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1016 /* feed above size into the rectangle for DrawText */
1017 myrect.left = myrect.top = 0;
1018 myrect.right = lpSize->cx;
1019 myrect.bottom = lpSize->cy;
1021 /* Use DrawText to get true size as drawn (less pesky "&") */
1022 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1023 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
1026 /* feed back to caller */
1027 lpSize->cx = myrect.right;
1028 lpSize->cy = myrect.bottom;
1032 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1035 /***********************************************************************
1036 * TOOLBAR_CalcStrings
1038 * This function walks through each string and measures it and returns
1039 * the largest height and width to caller.
1042 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1045 TBUTTON_INFO *btnPtr;
1055 hOldFont = SelectObject (hdc, infoPtr->hFont);
1057 btnPtr = infoPtr->buttons;
1058 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1059 if(TOOLBAR_HasText(infoPtr, btnPtr))
1061 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1062 if (sz.cx > lpSize->cx)
1064 if (sz.cy > lpSize->cy)
1069 SelectObject (hdc, hOldFont);
1070 ReleaseDC (hwnd, hdc);
1072 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1075 /***********************************************************************
1076 * TOOLBAR_WrapToolbar
1078 * This function walks through the buttons and seperators in the
1079 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1080 * wrapping should occur based on the width of the toolbar window.
1081 * It does *not* calculate button placement itself. That task
1082 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1083 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1084 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1086 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1087 * vertical toolbar lists.
1091 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1093 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1094 TBUTTON_INFO *btnPtr;
1097 BOOL bWrap, bButtonWrap;
1099 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1100 /* no layout is necessary. Applications may use this style */
1101 /* to perform their own layout on the toolbar. */
1102 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1103 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1105 btnPtr = infoPtr->buttons;
1106 x = infoPtr->nIndent;
1108 /* this can get the parents width, to know how far we can extend
1109 * this toolbar. We cannot use its height, as there may be multiple
1110 * toolbars in a rebar control
1112 GetClientRect( GetParent(hwnd), &rc );
1113 infoPtr->nWidth = rc.right - rc.left;
1114 bButtonWrap = FALSE;
1116 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1117 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1120 for (i = 0; i < infoPtr->nNumButtons; i++ )
1123 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1125 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1128 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1129 /* it is the actual width of the separator. This is used for */
1130 /* custom controls in toolbars. */
1132 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
1133 /* width. - GA 8/01 */
1134 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1135 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
1136 cx = (btnPtr[i].iBitmap > 0) ?
1137 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1139 cx = infoPtr->nButtonWidth;
1141 /* Two or more adjacent separators form a separator group. */
1142 /* The first separator in a group should be wrapped to the */
1143 /* next row if the previous wrapping is on a button. */
1145 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1146 (i + 1 < infoPtr->nNumButtons ) &&
1147 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
1149 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1150 btnPtr[i].fsState |= TBSTATE_WRAP;
1151 x = infoPtr->nIndent;
1153 bButtonWrap = FALSE;
1157 /* The layout makes sure the bitmap is visible, but not the button. */
1158 /* Test added to also wrap after a button that starts a row but */
1159 /* is bigger than the area. - GA 8/01 */
1160 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1161 > infoPtr->nWidth ) ||
1162 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1164 BOOL bFound = FALSE;
1166 /* If the current button is a separator and not hidden, */
1167 /* go to the next until it reaches a non separator. */
1168 /* Wrap the last separator if it is before a button. */
1169 while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1170 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
1171 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1172 i < infoPtr->nNumButtons )
1178 if( bFound && i < infoPtr->nNumButtons )
1181 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1182 i, btnPtr[i].fsStyle, x, cx);
1183 btnPtr[i].fsState |= TBSTATE_WRAP;
1184 x = infoPtr->nIndent;
1185 bButtonWrap = FALSE;
1188 else if ( i >= infoPtr->nNumButtons)
1191 /* If the current button is not a separator, find the last */
1192 /* separator and wrap it. */
1193 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1195 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1196 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1200 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1201 i, btnPtr[i].fsStyle, x, cx);
1202 x = infoPtr->nIndent;
1203 btnPtr[j].fsState |= TBSTATE_WRAP;
1204 bButtonWrap = FALSE;
1209 /* If no separator available for wrapping, wrap one of */
1210 /* non-hidden previous button. */
1214 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1216 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1221 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1222 i, btnPtr[i].fsStyle, x, cx);
1223 x = infoPtr->nIndent;
1224 btnPtr[j].fsState |= TBSTATE_WRAP;
1230 /* If all above failed, wrap the current button. */
1233 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1234 i, btnPtr[i].fsStyle, x, cx);
1235 btnPtr[i].fsState |= TBSTATE_WRAP;
1237 x = infoPtr->nIndent;
1238 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1239 bButtonWrap = FALSE;
1245 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1246 i, btnPtr[i].fsStyle, x, cx);
1253 /***********************************************************************
1254 * TOOLBAR_CalcToolbar
1256 * This function calculates button and separator placement. It first
1257 * calculates the button sizes, gets the toolbar window width and then
1258 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1259 * on. It assigns a new location to each item and sends this location to
1260 * the tooltip window if appropriate. Finally, it updates the rcBound
1261 * rect and calculates the new required toolbar window height.
1265 TOOLBAR_CalcToolbar (HWND hwnd)
1267 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1268 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1269 TBUTTON_INFO *btnPtr;
1270 INT i, nRows, nSepRows;
1274 BOOL usesBitmaps = FALSE;
1275 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1277 TOOLBAR_CalcStrings (hwnd, &sizeString);
1279 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1281 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1284 if (dwStyle & TBSTYLE_LIST)
1286 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1287 0, sizeString.cy) + infoPtr->szPadding.cy;
1288 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1289 0) + sizeString.cx + 6;
1290 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1291 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1292 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1293 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1296 if (sizeString.cy > 0)
1299 infoPtr->nButtonHeight = sizeString.cy +
1300 2 + /* this is the space to separate text from bitmap */
1301 infoPtr->nBitmapHeight + 6;
1303 infoPtr->nButtonHeight = sizeString.cy + 6;
1305 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1306 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1308 if (sizeString.cx > infoPtr->nBitmapWidth)
1309 infoPtr->nButtonWidth = sizeString.cx + 6;
1310 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1311 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1314 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1315 infoPtr->nButtonWidth = infoPtr->cxMin;
1316 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1317 infoPtr->nButtonWidth = infoPtr->cxMax;
1319 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1321 x = infoPtr->nIndent;
1325 * We will set the height below, and we set the width on entry
1326 * so we do not reset them here..
1329 GetClientRect( hwnd, &rc );
1330 /* get initial values for toolbar */
1331 infoPtr->nWidth = rc.right - rc.left;
1332 infoPtr->nHeight = rc.bottom - rc.top;
1335 /* from above, minimum is a button, and possible text */
1336 cx = infoPtr->nButtonWidth;
1338 /* cannot use just ButtonHeight, we may have no buttons! */
1339 if (infoPtr->nNumButtons > 0)
1340 infoPtr->nHeight = infoPtr->nButtonHeight;
1342 cy = infoPtr->nHeight;
1344 nRows = nSepRows = 0;
1346 infoPtr->rcBound.top = y;
1347 infoPtr->rcBound.left = x;
1348 infoPtr->rcBound.bottom = y + cy;
1349 infoPtr->rcBound.right = x;
1351 btnPtr = infoPtr->buttons;
1353 /* do not base height/width on parent, if the parent is a */
1354 /* rebar control it could have multiple rows of toolbars */
1355 /* GetClientRect( GetParent(hwnd), &rc ); */
1356 /* cx = rc.right - rc.left; */
1357 /* cy = rc.bottom - rc.top; */
1359 TRACE("cy=%d\n", cy);
1361 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1364 if (btnPtr->fsState & TBSTATE_HIDDEN)
1366 SetRectEmpty (&btnPtr->rect);
1370 cy = infoPtr->nHeight;
1372 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1373 /* it is the actual width of the separator. This is used for */
1374 /* custom controls in toolbars. */
1375 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1376 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1377 cy = (btnPtr->iBitmap > 0) ?
1378 btnPtr->iBitmap : SEPARATOR_WIDTH;
1379 cx = infoPtr->nButtonWidth;
1382 cx = (btnPtr->iBitmap > 0) ?
1383 btnPtr->iBitmap : SEPARATOR_WIDTH;
1387 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1394 hOldFont = SelectObject (hdc, infoPtr->hFont);
1396 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1398 SelectObject (hdc, hOldFont);
1399 ReleaseDC (hwnd, hdc);
1401 /* Fudge amount measured against IE4 "menu" and "Links" */
1402 /* toolbars with native control (v4.71). - GA 8/01 */
1403 cx = sz.cx + 6 + 5 + 5;
1404 if ((dwStyle & TBSTYLE_LIST) &&
1405 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1406 cx += infoPtr->nBitmapWidth;
1409 cx = infoPtr->nButtonWidth;
1411 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1412 cx += DDARROW_WIDTH;
1414 if (btnPtr->fsState & TBSTATE_WRAP )
1417 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1419 if (infoPtr->rcBound.left > x)
1420 infoPtr->rcBound.left = x;
1421 if (infoPtr->rcBound.right < x + cx)
1422 infoPtr->rcBound.right = x + cx;
1423 if (infoPtr->rcBound.bottom < y + cy)
1424 infoPtr->rcBound.bottom = y + cy;
1426 /* Set the toolTip only for non-hidden, non-separator button */
1427 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1431 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1432 ti.cbSize = sizeof(TTTOOLINFOA);
1434 ti.uId = btnPtr->idCommand;
1435 ti.rect = btnPtr->rect;
1436 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1440 /* btnPtr->nRow is zero based. The space between the rows is */
1441 /* also considered as a row. */
1442 btnPtr->nRow = nRows + nSepRows;
1444 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1445 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1450 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1454 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1455 /* it is the actual width of the separator. This is used for */
1456 /* custom controls in toolbars. */
1457 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1458 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1459 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1463 /* nSepRows is used to calculate the extra height follwoing */
1467 x = infoPtr->nIndent;
1469 /* Increment row number unless this is the last button */
1470 /* and it has Wrap set. */
1471 if (i != infoPtr->nNumButtons-1)
1478 /* infoPtr->nRows is the number of rows on the toolbar */
1479 infoPtr->nRows = nRows + nSepRows + 1;
1482 /********************************************************************
1483 * The following while interesting, does not match the values *
1484 * created above for the button rectangles, nor the rcBound rect. *
1485 * We will comment it out and remove it later. *
1487 * The problem showed up as heights in the pager control that was *
1489 ********************************************************************/
1491 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1493 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1494 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1495 nSepRows * (infoPtr->nBitmapHeight + 1) +
1499 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1501 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1506 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1509 TBUTTON_INFO *btnPtr;
1512 btnPtr = infoPtr->buttons;
1513 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1514 if (btnPtr->fsState & TBSTATE_HIDDEN)
1517 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1518 if (PtInRect (&btnPtr->rect, *lpPt)) {
1519 TRACE(" ON SEPARATOR %d!\n", i);
1524 if (PtInRect (&btnPtr->rect, *lpPt)) {
1525 TRACE(" ON BUTTON %d!\n", i);
1531 TRACE(" NOWHERE!\n");
1537 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1539 TBUTTON_INFO *btnPtr;
1542 if (CommandIsIndex) {
1543 TRACE("command is really index command=%d\n", idCommand);
1544 if (idCommand >= infoPtr->nNumButtons) return -1;
1547 btnPtr = infoPtr->buttons;
1548 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1549 if (btnPtr->idCommand == idCommand) {
1550 TRACE("command=%d index=%d\n", idCommand, i);
1554 TRACE("no index found for command=%d\n", idCommand);
1560 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1562 TBUTTON_INFO *btnPtr;
1565 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1568 /* check index button */
1569 btnPtr = &infoPtr->buttons[nIndex];
1570 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1571 if (btnPtr->fsState & TBSTATE_CHECKED)
1575 /* check previous buttons */
1576 nRunIndex = nIndex - 1;
1577 while (nRunIndex >= 0) {
1578 btnPtr = &infoPtr->buttons[nRunIndex];
1579 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1580 if (btnPtr->fsState & TBSTATE_CHECKED)
1588 /* check next buttons */
1589 nRunIndex = nIndex + 1;
1590 while (nRunIndex < infoPtr->nNumButtons) {
1591 btnPtr = &infoPtr->buttons[nRunIndex];
1592 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1593 if (btnPtr->fsState & TBSTATE_CHECKED)
1606 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1607 WPARAM wParam, LPARAM lParam)
1613 msg.wParam = wParam;
1614 msg.lParam = lParam;
1615 msg.time = GetMessageTime ();
1616 msg.pt.x = LOWORD(GetMessagePos ());
1617 msg.pt.y = HIWORD(GetMessagePos ());
1619 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1623 /***********************************************************************
1624 * TOOLBAR_CustomizeDialogProc
1625 * This function implements the toolbar customization dialog.
1628 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1630 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1631 PCUSTOMBUTTON btnInfo;
1633 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1638 custInfo = (PCUSTDLG_INFO)lParam;
1639 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1647 infoPtr = custInfo->tbInfo;
1649 /* send TBN_QUERYINSERT notification */
1650 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1652 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1655 /* add items to 'toolbar buttons' list and check if removable */
1656 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1658 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1659 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1660 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1661 btnInfo->bVirtual = FALSE;
1662 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1664 /* send TBN_QUERYDELETE notification */
1666 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1670 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1671 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1674 /* insert separator button into 'available buttons' list */
1675 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1676 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1677 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1678 btnInfo->bVirtual = FALSE;
1679 btnInfo->bRemovable = TRUE;
1680 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1681 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1682 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1684 /* insert all buttons into dsa */
1687 /* send TBN_GETBUTTONINFO notification */
1689 nmtb.pszText = Buffer;
1692 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1695 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1697 /* insert button into the apropriate list */
1698 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1701 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1702 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1703 btnInfo->bVirtual = FALSE;
1704 btnInfo->bRemovable = TRUE;
1705 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1706 strcpy (btnInfo->text, nmtb.pszText);
1708 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1709 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1713 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1714 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1715 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1716 strcpy (btnInfo->text, nmtb.pszText);
1718 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1722 /* select first item in the 'available' list */
1723 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1725 /* append 'virtual' separator button to the 'toolbar buttons' list */
1726 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1727 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1728 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1729 btnInfo->bVirtual = TRUE;
1730 btnInfo->bRemovable = FALSE;
1731 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1732 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1733 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1735 /* select last item in the 'toolbar' list */
1736 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1737 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1739 /* set focus and disable buttons */
1740 PostMessageA (hwnd, WM_USER, 0, 0);
1745 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1746 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1747 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1748 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1752 EndDialog(hwnd, FALSE);
1756 switch (LOWORD(wParam))
1758 case IDC_TOOLBARBTN_LBOX:
1759 if (HIWORD(wParam) == LBN_SELCHANGE)
1761 PCUSTOMBUTTON btnInfo;
1766 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1767 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1769 /* send TBN_QUERYINSERT notification */
1771 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1774 /* get list box item */
1775 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1777 if (index == (count - 1))
1779 /* last item (virtual separator) */
1780 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1781 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1783 else if (index == (count - 2))
1785 /* second last item (last non-virtual item) */
1786 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1787 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1789 else if (index == 0)
1792 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1793 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1797 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1798 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1801 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1805 case IDC_MOVEUP_BTN:
1807 PCUSTOMBUTTON btnInfo;
1811 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1812 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1813 TRACE("Move up: index %d\n", index);
1815 /* send TBN_QUERYINSERT notification */
1818 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1821 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1823 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1824 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1825 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1826 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1829 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1830 else if (index >= (count - 3))
1831 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1833 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1834 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1839 case IDC_MOVEDN_BTN: /* move down */
1841 PCUSTOMBUTTON btnInfo;
1845 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1846 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1847 TRACE("Move up: index %d\n", index);
1849 /* send TBN_QUERYINSERT notification */
1851 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1854 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1856 /* move button down */
1857 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1858 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1859 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1860 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1863 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1864 else if (index >= (count - 3))
1865 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1867 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1868 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1873 case IDC_REMOVE_BTN: /* remove button */
1875 PCUSTOMBUTTON btnInfo;
1878 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1879 TRACE("Remove: index %d\n", index);
1881 /* send TBN_QUERYDELETE notification */
1883 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1886 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1887 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1888 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1890 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1892 /* insert into 'available button' list */
1893 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1895 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1896 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1899 COMCTL32_Free (btnInfo);
1904 case IDOK: /* Add button */
1909 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1910 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1911 TRACE("Add: index %d\n", index);
1913 /* send TBN_QUERYINSERT notification */
1915 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1918 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1922 /* remove from 'available buttons' list */
1923 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1924 if (index == count-1)
1925 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1927 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1931 PCUSTOMBUTTON btnNew;
1933 /* duplicate 'separator' button */
1934 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1935 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1939 /* insert into 'toolbar button' list */
1940 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1941 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1942 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1944 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1950 EndDialog(hwnd, FALSE);
1960 /* delete items from 'toolbar buttons' listbox*/
1961 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1962 for (i = 0; i < count; i++)
1964 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1965 COMCTL32_Free(btnInfo);
1966 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1968 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1971 /* delete items from 'available buttons' listbox*/
1972 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1973 for (i = 0; i < count; i++)
1975 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1976 COMCTL32_Free(btnInfo);
1977 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1979 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1984 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1986 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1991 COLORREF oldText = 0;
1995 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1996 if (btnInfo == NULL)
1998 FIXME("btnInfo invalid!\n");
2002 /* set colors and select objects */
2003 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2004 if (btnInfo->bVirtual)
2005 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2007 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2008 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2009 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2011 /* fill background rectangle */
2012 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2013 lpdis->rcItem.right, lpdis->rcItem.bottom);
2015 /* calculate button and text rectangles */
2016 CopyRect (&rcButton, &lpdis->rcItem);
2017 InflateRect (&rcButton, -1, -1);
2018 CopyRect (&rcText, &rcButton);
2019 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2020 rcText.left = rcButton.right + 2;
2022 /* draw focus rectangle */
2023 if (lpdis->itemState & ODS_FOCUS)
2024 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2027 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2029 /* draw image and text */
2030 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
2031 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
2032 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2033 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
2034 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2036 /* delete objects and reset colors */
2037 SelectObject (lpdis->hDC, hOldBrush);
2038 SelectObject (lpdis->hDC, hOldPen);
2039 SetBkColor (lpdis->hDC, oldBk);
2040 SetTextColor (lpdis->hDC, oldText);
2046 case WM_MEASUREITEM:
2047 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2049 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2051 if (custInfo && custInfo->tbInfo)
2052 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2054 lpmis->itemHeight = 15 + 8; /* default height */
2066 /***********************************************************************
2067 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2071 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2074 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2075 INT nIndex = 0, nButtons, nCount;
2078 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2082 if (lpAddBmp->hInst == HINST_COMMCTRL)
2084 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2086 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2088 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2093 TRACE ("adding %d internal bitmaps!\n", nButtons);
2095 /* Windows resize all the buttons to the size of a newly added standard image */
2096 if (lpAddBmp->nID & 1)
2099 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2100 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2102 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2103 MAKELPARAM((WORD)24, (WORD)24));
2104 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2105 MAKELPARAM((WORD)31, (WORD)30));
2110 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2111 MAKELPARAM((WORD)16, (WORD)16));
2112 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2113 MAKELPARAM((WORD)22, (WORD)22));
2116 TOOLBAR_CalcToolbar (hwnd);
2120 nButtons = (INT)wParam;
2124 TRACE ("adding %d bitmaps!\n", nButtons);
2127 if (!(infoPtr->himlDef)) {
2128 /* create new default image list */
2129 TRACE ("creating default image list!\n");
2132 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2133 ILC_COLOR | ILC_MASK, nButtons, 2);
2134 infoPtr->himlInt = infoPtr->himlDef;
2137 nCount = ImageList_GetImageCount(infoPtr->himlDef);
2139 /* Add bitmaps to the default image list */
2140 if (lpAddBmp->hInst == (HINSTANCE)0)
2143 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
2146 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2148 /* Add system bitmaps */
2149 switch (lpAddBmp->nID)
2151 case IDB_STD_SMALL_COLOR:
2152 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2153 MAKEINTRESOURCEA(IDB_STD_SMALL));
2154 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2155 hbmLoad, CLR_DEFAULT);
2156 DeleteObject (hbmLoad);
2159 case IDB_STD_LARGE_COLOR:
2160 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2161 MAKEINTRESOURCEA(IDB_STD_LARGE));
2162 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2163 hbmLoad, CLR_DEFAULT);
2164 DeleteObject (hbmLoad);
2167 case IDB_VIEW_SMALL_COLOR:
2168 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2169 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2170 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2171 hbmLoad, CLR_DEFAULT);
2172 DeleteObject (hbmLoad);
2175 case IDB_VIEW_LARGE_COLOR:
2176 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2177 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2178 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2179 hbmLoad, CLR_DEFAULT);
2180 DeleteObject (hbmLoad);
2183 case IDB_HIST_SMALL_COLOR:
2184 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2185 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2186 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2187 hbmLoad, CLR_DEFAULT);
2188 DeleteObject (hbmLoad);
2191 case IDB_HIST_LARGE_COLOR:
2192 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2193 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2194 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2195 hbmLoad, CLR_DEFAULT);
2196 DeleteObject (hbmLoad);
2200 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
2201 ERR ("invalid imagelist!\n");
2207 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2208 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
2209 DeleteObject (hbmLoad);
2212 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2214 if (infoPtr->nNumBitmapInfos == 0)
2216 infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
2220 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2221 infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2222 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2225 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2226 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2227 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2229 infoPtr->nNumBitmapInfos++;
2230 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2234 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2236 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2238 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",
2239 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2240 infoPtr->nNumBitmaps+nButtons,imagecount);
2242 infoPtr->nNumBitmaps = imagecount;
2245 infoPtr->nNumBitmaps += nButtons;
2248 InvalidateRect(hwnd, NULL, FALSE);
2255 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2257 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2258 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2259 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2261 TRACE("adding %d buttons!\n", wParam);
2263 nAddButtons = (UINT)wParam;
2264 nOldButtons = infoPtr->nNumButtons;
2265 nNewButtons = nOldButtons + nAddButtons;
2267 if (infoPtr->nNumButtons == 0) {
2269 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2272 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2274 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2275 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2276 nOldButtons * sizeof(TBUTTON_INFO));
2277 COMCTL32_Free (oldButtons);
2280 infoPtr->nNumButtons = nNewButtons;
2282 /* insert new button data */
2283 for (nCount = 0; nCount < nAddButtons; nCount++) {
2284 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2285 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2286 btnPtr->idCommand = lpTbb[nCount].idCommand;
2287 btnPtr->fsState = lpTbb[nCount].fsState;
2288 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2289 btnPtr->dwData = lpTbb[nCount].dwData;
2290 btnPtr->iString = lpTbb[nCount].iString;
2291 btnPtr->bHot = FALSE;
2293 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2296 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2297 ti.cbSize = sizeof (TTTOOLINFOA);
2299 ti.uId = btnPtr->idCommand;
2301 ti.lpszText = LPSTR_TEXTCALLBACKA;
2303 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2308 TOOLBAR_CalcToolbar (hwnd);
2310 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2312 InvalidateRect(hwnd, NULL, FALSE);
2319 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2322 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2323 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2325 TRACE("adding %d buttons!\n", wParam);
2327 nAddButtons = (UINT)wParam;
2328 nOldButtons = infoPtr->nNumButtons;
2329 nNewButtons = nOldButtons + nAddButtons;
2331 if (infoPtr->nNumButtons == 0) {
2333 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2336 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2338 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2339 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2340 nOldButtons * sizeof(TBUTTON_INFO));
2341 COMCTL32_Free (oldButtons);
2344 infoPtr->nNumButtons = nNewButtons;
2346 /* insert new button data */
2347 for (nCount = 0; nCount < nAddButtons; nCount++) {
2348 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2349 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2350 btnPtr->idCommand = lpTbb[nCount].idCommand;
2351 btnPtr->fsState = lpTbb[nCount].fsState;
2352 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2353 btnPtr->dwData = lpTbb[nCount].dwData;
2354 btnPtr->iString = lpTbb[nCount].iString;
2355 btnPtr->bHot = FALSE;
2357 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2360 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2361 ti.cbSize = sizeof (TTTOOLINFOW);
2363 ti.uId = btnPtr->idCommand;
2365 ti.lpszText = LPSTR_TEXTCALLBACKW;
2367 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2372 TOOLBAR_CalcToolbar (hwnd);
2374 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2376 InvalidateRect(hwnd, NULL, FALSE);
2383 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2388 if ((wParam) && (HIWORD(lParam) == 0)) {
2391 TRACE("adding string from resource!\n");
2393 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2396 TRACE("len=%d \"%s\"\n", len, szString);
2397 nIndex = infoPtr->nNumStrings;
2398 if (infoPtr->nNumStrings == 0) {
2400 COMCTL32_Alloc (sizeof(LPWSTR));
2403 LPWSTR *oldStrings = infoPtr->strings;
2405 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2406 memcpy (&infoPtr->strings[0], &oldStrings[0],
2407 sizeof(LPWSTR) * infoPtr->nNumStrings);
2408 COMCTL32_Free (oldStrings);
2411 /*COMCTL32_Alloc zeros out the allocated memory*/
2412 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2413 infoPtr->nNumStrings++;
2416 LPSTR p = (LPSTR)lParam;
2421 TRACE("adding string(s) from array!\n");
2423 nIndex = infoPtr->nNumStrings;
2426 TRACE("len=%d \"%s\"\n", len, p);
2428 if (infoPtr->nNumStrings == 0) {
2430 COMCTL32_Alloc (sizeof(LPWSTR));
2433 LPWSTR *oldStrings = infoPtr->strings;
2435 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2436 memcpy (&infoPtr->strings[0], &oldStrings[0],
2437 sizeof(LPWSTR) * infoPtr->nNumStrings);
2438 COMCTL32_Free (oldStrings);
2441 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2442 infoPtr->nNumStrings++;
2453 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2455 #define MAX_RESOURCE_STRING_LENGTH 512
2456 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2459 if ((wParam) && (HIWORD(lParam) == 0)) {
2460 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2462 TRACE("adding string from resource!\n");
2464 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2465 szString, MAX_RESOURCE_STRING_LENGTH);
2467 TRACE("len=%d %s\n", len, debugstr_w(szString));
2468 TRACE("First char: 0x%x\n", *szString);
2469 if (szString[0] == L'|')
2471 PWSTR p = szString + 1;
2473 nIndex = infoPtr->nNumStrings;
2474 while (*p != L'|') {
2476 if (infoPtr->nNumStrings == 0) {
2478 COMCTL32_Alloc (sizeof(LPWSTR));
2481 LPWSTR *oldStrings = infoPtr->strings;
2483 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2484 memcpy (&infoPtr->strings[0], &oldStrings[0],
2485 sizeof(LPWSTR) * infoPtr->nNumStrings);
2486 COMCTL32_Free (oldStrings);
2489 len = COMCTL32_StrChrW (p, L'|') - p;
2490 TRACE("len=%d %s\n", len, debugstr_w(p));
2491 infoPtr->strings[infoPtr->nNumStrings] =
2492 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2493 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2494 infoPtr->nNumStrings++;
2501 nIndex = infoPtr->nNumStrings;
2502 if (infoPtr->nNumStrings == 0) {
2504 COMCTL32_Alloc (sizeof(LPWSTR));
2507 LPWSTR *oldStrings = infoPtr->strings;
2509 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2510 memcpy (&infoPtr->strings[0], &oldStrings[0],
2511 sizeof(LPWSTR) * infoPtr->nNumStrings);
2512 COMCTL32_Free (oldStrings);
2515 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2516 infoPtr->nNumStrings++;
2520 LPWSTR p = (LPWSTR)lParam;
2525 TRACE("adding string(s) from array!\n");
2526 nIndex = infoPtr->nNumStrings;
2530 TRACE("len=%d %s\n", len, debugstr_w(p));
2531 if (infoPtr->nNumStrings == 0) {
2533 COMCTL32_Alloc (sizeof(LPWSTR));
2536 LPWSTR *oldStrings = infoPtr->strings;
2538 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2539 memcpy (&infoPtr->strings[0], &oldStrings[0],
2540 sizeof(LPWSTR) * infoPtr->nNumStrings);
2541 COMCTL32_Free (oldStrings);
2544 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2545 infoPtr->nNumStrings++;
2556 TOOLBAR_AutoSize (HWND hwnd)
2558 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2559 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2565 UINT uPosFlags = SWP_NOZORDER;
2567 TRACE("resize forced, style=%lx!\n", dwStyle);
2569 parent = GetParent (hwnd);
2570 GetClientRect(parent, &parent_rect);
2572 x = parent_rect.left;
2573 y = parent_rect.top;
2575 /* FIXME: we should be able to early out if nothing */
2576 /* has changed with nWidth != parent_rect width */
2578 if (dwStyle & CCS_NORESIZE) {
2579 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2582 TOOLBAR_CalcToolbar (hwnd);
2585 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2586 TOOLBAR_CalcToolbar (hwnd);
2587 InvalidateRect( hwnd, NULL, TRUE );
2588 cy = infoPtr->nHeight;
2589 cx = infoPtr->nWidth;
2591 if (dwStyle & CCS_NOMOVEY) {
2592 GetWindowRect(hwnd, &window_rect);
2593 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2594 y = window_rect.top;
2598 if (dwStyle & CCS_NOPARENTALIGN)
2599 uPosFlags |= SWP_NOMOVE;
2601 if (!(dwStyle & CCS_NODIVIDER))
2602 cy += GetSystemMetrics(SM_CYEDGE);
2604 if (dwStyle & WS_BORDER)
2607 cy += GetSystemMetrics(SM_CYEDGE);
2608 cx += GetSystemMetrics(SM_CYEDGE);
2611 infoPtr->bAutoSize = TRUE;
2612 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2614 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2615 * the setwindowpos calls */
2616 infoPtr->bAutoSize = FALSE;
2623 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2627 return infoPtr->nNumButtons;
2632 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2636 if (infoPtr == NULL) {
2637 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2638 ERR("infoPtr == NULL!\n");
2642 infoPtr->dwStructSize = (DWORD)wParam;
2649 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2651 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2652 TBUTTON_INFO *btnPtr;
2655 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2659 btnPtr = &infoPtr->buttons[nIndex];
2660 btnPtr->iBitmap = LOWORD(lParam);
2662 /* we HAVE to erase the background, the new bitmap could be */
2664 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2671 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2674 TBUTTON_INFO *btnPtr;
2677 BOOL bChecked = FALSE;
2679 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2683 btnPtr = &infoPtr->buttons[nIndex];
2685 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2688 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2690 if (LOWORD(lParam) == FALSE)
2691 btnPtr->fsState &= ~TBSTATE_CHECKED;
2693 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2695 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2696 if (nOldIndex == nIndex)
2698 if (nOldIndex != -1)
2699 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2701 btnPtr->fsState |= TBSTATE_CHECKED;
2704 if( bChecked != LOWORD(lParam) )
2706 if (nOldIndex != -1)
2708 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2709 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2711 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2714 /* FIXME: Send a WM_NOTIFY?? */
2721 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2723 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2725 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2730 TOOLBAR_Customize (HWND hwnd)
2732 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2733 CUSTDLG_INFO custInfo;
2739 custInfo.tbInfo = infoPtr;
2740 custInfo.tbHwnd = hwnd;
2742 /* send TBN_BEGINADJUST notification */
2743 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2746 if (!(hRes = FindResourceA (COMCTL32_hModule,
2747 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2751 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2754 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2755 (LPDLGTEMPLATEA)template,
2757 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2760 /* send TBN_ENDADJUST notification */
2761 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2769 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2772 INT nIndex = (INT)wParam;
2774 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2777 if ((infoPtr->hwndToolTip) &&
2778 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2781 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2782 ti.cbSize = sizeof (TTTOOLINFOA);
2784 ti.uId = infoPtr->buttons[nIndex].idCommand;
2786 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2789 if (infoPtr->nNumButtons == 1) {
2790 TRACE(" simple delete!\n");
2791 COMCTL32_Free (infoPtr->buttons);
2792 infoPtr->buttons = NULL;
2793 infoPtr->nNumButtons = 0;
2796 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2797 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2799 infoPtr->nNumButtons--;
2800 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2802 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2803 nIndex * sizeof(TBUTTON_INFO));
2806 if (nIndex < infoPtr->nNumButtons) {
2807 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2808 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2811 COMCTL32_Free (oldButtons);
2814 TOOLBAR_CalcToolbar (hwnd);
2816 InvalidateRect (hwnd, NULL, TRUE);
2823 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2826 TBUTTON_INFO *btnPtr;
2830 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2834 btnPtr = &infoPtr->buttons[nIndex];
2836 bState = btnPtr->fsState & TBSTATE_ENABLED;
2838 /* update the toolbar button state */
2839 if(LOWORD(lParam) == FALSE) {
2840 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2842 btnPtr->fsState |= TBSTATE_ENABLED;
2845 /* redraw the button only if the state of the button changed */
2846 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2848 InvalidateRect(hwnd, &btnPtr->rect,
2849 TOOLBAR_HasText(infoPtr, btnPtr));
2856 static inline LRESULT
2857 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2861 return infoPtr->bAnchor;
2866 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2871 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2875 return infoPtr->buttons[nIndex].iBitmap;
2879 static inline LRESULT
2880 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2882 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2887 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2890 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2891 INT nIndex = (INT)wParam;
2892 TBUTTON_INFO *btnPtr;
2894 if (infoPtr == NULL)
2900 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2903 btnPtr = &infoPtr->buttons[nIndex];
2904 lpTbb->iBitmap = btnPtr->iBitmap;
2905 lpTbb->idCommand = btnPtr->idCommand;
2906 lpTbb->fsState = btnPtr->fsState;
2907 lpTbb->fsStyle = btnPtr->fsStyle;
2908 lpTbb->dwData = btnPtr->dwData;
2909 lpTbb->iString = btnPtr->iString;
2916 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2919 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2920 TBUTTON_INFO *btnPtr;
2923 if (infoPtr == NULL)
2925 if (lpTbInfo == NULL)
2927 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2930 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2931 lpTbInfo->dwMask & 0x80000000);
2935 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
2937 if (lpTbInfo->dwMask & TBIF_COMMAND)
2938 lpTbInfo->idCommand = btnPtr->idCommand;
2939 if (lpTbInfo->dwMask & TBIF_IMAGE)
2940 lpTbInfo->iImage = btnPtr->iBitmap;
2941 if (lpTbInfo->dwMask & TBIF_LPARAM)
2942 lpTbInfo->lParam = btnPtr->dwData;
2943 if (lpTbInfo->dwMask & TBIF_SIZE)
2944 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2945 if (lpTbInfo->dwMask & TBIF_STATE)
2946 lpTbInfo->fsState = btnPtr->fsState;
2947 if (lpTbInfo->dwMask & TBIF_STYLE)
2948 lpTbInfo->fsStyle = btnPtr->fsStyle;
2949 if (lpTbInfo->dwMask & TBIF_TEXT) {
2950 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2951 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
2958 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2961 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2962 TBUTTON_INFO *btnPtr;
2965 if (infoPtr == NULL)
2967 if (lpTbInfo == NULL)
2969 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2972 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2973 lpTbInfo->dwMask & 0x80000000);
2977 btnPtr = &infoPtr->buttons[nIndex];
2979 if (lpTbInfo->dwMask & TBIF_COMMAND)
2980 lpTbInfo->idCommand = btnPtr->idCommand;
2981 if (lpTbInfo->dwMask & TBIF_IMAGE)
2982 lpTbInfo->iImage = btnPtr->iBitmap;
2983 if (lpTbInfo->dwMask & TBIF_LPARAM)
2984 lpTbInfo->lParam = btnPtr->dwData;
2985 if (lpTbInfo->dwMask & TBIF_SIZE)
2986 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2987 if (lpTbInfo->dwMask & TBIF_STATE)
2988 lpTbInfo->fsState = btnPtr->fsState;
2989 if (lpTbInfo->dwMask & TBIF_STYLE)
2990 lpTbInfo->fsStyle = btnPtr->fsStyle;
2991 if (lpTbInfo->dwMask & TBIF_TEXT) {
2992 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2993 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3001 TOOLBAR_GetButtonSize (HWND hwnd)
3003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3005 if (infoPtr->nNumButtons > 0)
3006 return MAKELONG((WORD)infoPtr->nButtonWidth,
3007 (WORD)infoPtr->nButtonHeight);
3009 return MAKELONG(8,7);
3014 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3016 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3023 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3027 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3029 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3030 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3035 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3037 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3044 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3048 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3050 strcpyW ((LPWSTR)lParam, lpText);
3052 return strlenW (lpText);
3057 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3059 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3061 return (LRESULT)infoPtr->himlDis;
3065 inline static LRESULT
3066 TOOLBAR_GetExtendedStyle (HWND hwnd)
3068 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3070 return infoPtr->dwExStyle;
3075 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3079 return (LRESULT)infoPtr->himlHot;
3084 TOOLBAR_GetHotItem (HWND hwnd)
3086 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3088 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3091 if (infoPtr->nHotItem < 0)
3094 return (LRESULT)infoPtr->nHotItem;
3099 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3103 return (LRESULT)infoPtr->himlDef;
3107 /* << TOOLBAR_GetInsertMark >> */
3108 /* << TOOLBAR_GetInsertMarkColor >> */
3112 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3114 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3115 TBUTTON_INFO *btnPtr;
3119 if (infoPtr == NULL)
3121 nIndex = (INT)wParam;
3122 btnPtr = &infoPtr->buttons[nIndex];
3123 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3125 lpRect = (LPRECT)lParam;
3128 if (btnPtr->fsState & TBSTATE_HIDDEN)
3131 lpRect->left = btnPtr->rect.left;
3132 lpRect->right = btnPtr->rect.right;
3133 lpRect->bottom = btnPtr->rect.bottom;
3134 lpRect->top = btnPtr->rect.top;
3141 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3144 LPSIZE lpSize = (LPSIZE)lParam;
3149 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3150 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3152 TRACE("maximum size %d x %d\n",
3153 infoPtr->rcBound.right - infoPtr->rcBound.left,
3154 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3160 /* << TOOLBAR_GetObject >> */
3164 TOOLBAR_GetPadding (HWND hwnd)
3166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3169 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3170 return (LRESULT) oldPad;
3175 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3178 TBUTTON_INFO *btnPtr;
3182 if (infoPtr == NULL)
3184 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3185 btnPtr = &infoPtr->buttons[nIndex];
3186 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3188 lpRect = (LPRECT)lParam;
3192 lpRect->left = btnPtr->rect.left;
3193 lpRect->right = btnPtr->rect.right;
3194 lpRect->bottom = btnPtr->rect.bottom;
3195 lpRect->top = btnPtr->rect.top;
3202 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3204 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3206 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3207 return infoPtr->nRows;
3214 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3216 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3219 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3223 return infoPtr->buttons[nIndex].fsState;
3228 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3230 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3233 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3237 return infoPtr->buttons[nIndex].fsStyle;
3242 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3244 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3246 if (infoPtr == NULL)
3249 return infoPtr->nMaxTextRows;
3254 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3256 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3258 if (infoPtr == NULL)
3260 return infoPtr->hwndToolTip;
3265 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3267 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3269 TRACE("%s hwnd=0x%x stub!\n",
3270 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3272 return infoPtr->bUnicode;
3276 inline static LRESULT
3277 TOOLBAR_GetVersion (HWND hwnd)
3279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3280 return infoPtr->iVersion;
3285 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3288 TBUTTON_INFO *btnPtr;
3293 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3297 btnPtr = &infoPtr->buttons[nIndex];
3298 if (LOWORD(lParam) == FALSE)
3299 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3301 btnPtr->fsState |= TBSTATE_HIDDEN;
3303 TOOLBAR_CalcToolbar (hwnd);
3305 InvalidateRect (hwnd, NULL, TRUE);
3311 inline static LRESULT
3312 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3319 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3322 TBUTTON_INFO *btnPtr;
3325 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3329 btnPtr = &infoPtr->buttons[nIndex];
3330 if (LOWORD(lParam) == FALSE)
3331 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3333 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3335 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3342 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3344 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3345 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3346 INT nIndex = (INT)wParam;
3347 TBUTTON_INFO *oldButtons;
3352 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3355 /* EPP: this seems to be an undocumented call (from my IE4)
3356 * I assume in that case that:
3357 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3358 * - index of insertion is at the end of existing buttons
3359 * I only see this happen with nIndex == -1, but it could have a special
3360 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3362 nIndex = infoPtr->nNumButtons;
3364 } else if (nIndex < 0)
3367 /* If the string passed is not an index, assume address of string
3368 and do our own AddString */
3369 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3373 TRACE("string %s passed instead of index, adding string\n",
3374 debugstr_a((LPSTR)lpTbb->iString));
3375 len = strlen((LPSTR)lpTbb->iString) + 2;
3376 ptr = COMCTL32_Alloc(len);
3377 strcpy(ptr, (LPSTR)lpTbb->iString);
3378 ptr[len - 1] = 0; /* ended by two '\0' */
3379 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3383 TRACE("inserting button index=%d\n", nIndex);
3384 if (nIndex > infoPtr->nNumButtons) {
3385 nIndex = infoPtr->nNumButtons;
3386 TRACE("adjust index=%d\n", nIndex);
3389 oldButtons = infoPtr->buttons;
3390 infoPtr->nNumButtons++;
3391 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3392 /* pre insert copy */
3394 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3395 nIndex * sizeof(TBUTTON_INFO));
3398 /* insert new button */
3399 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3400 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3401 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3402 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3403 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3404 /* if passed string and not index, then add string */
3405 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3406 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3409 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3411 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3414 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3415 ti.cbSize = sizeof (TTTOOLINFOA);
3417 ti.uId = lpTbb->idCommand;
3419 ti.lpszText = LPSTR_TEXTCALLBACKA;
3421 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3425 /* post insert copy */
3426 if (nIndex < infoPtr->nNumButtons - 1) {
3427 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3428 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3431 COMCTL32_Free (oldButtons);
3433 TOOLBAR_CalcToolbar (hwnd);
3435 InvalidateRect (hwnd, NULL, TRUE);
3442 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3445 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3446 INT nIndex = (INT)wParam;
3447 TBUTTON_INFO *oldButtons;
3452 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3455 /* EPP: this seems to be an undocumented call (from my IE4)
3456 * I assume in that case that:
3457 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3458 * - index of insertion is at the end of existing buttons
3459 * I only see this happen with nIndex == -1, but it could have a special
3460 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3462 nIndex = infoPtr->nNumButtons;
3464 } else if (nIndex < 0)
3467 /* If the string passed is not an index, assume address of string
3468 and do our own AddString */
3469 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3473 TRACE("string %s passed instead of index, adding string\n",
3474 debugstr_w((LPWSTR)lpTbb->iString));
3475 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3476 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3477 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3478 ptr[len - 1] = 0; /* ended by two '\0' */
3479 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3483 TRACE("inserting button index=%d\n", nIndex);
3484 if (nIndex > infoPtr->nNumButtons) {
3485 nIndex = infoPtr->nNumButtons;
3486 TRACE("adjust index=%d\n", nIndex);
3489 oldButtons = infoPtr->buttons;
3490 infoPtr->nNumButtons++;
3491 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3492 /* pre insert copy */
3494 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3495 nIndex * sizeof(TBUTTON_INFO));
3498 /* insert new button */
3499 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3500 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3501 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3502 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3503 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3504 /* if passed string and not index, then add string */
3505 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3506 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3509 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3511 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3514 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3515 ti.cbSize = sizeof (TTTOOLINFOW);
3517 ti.uId = lpTbb->idCommand;
3519 ti.lpszText = LPSTR_TEXTCALLBACKW;
3521 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3525 /* post insert copy */
3526 if (nIndex < infoPtr->nNumButtons - 1) {
3527 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3528 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3531 COMCTL32_Free (oldButtons);
3533 TOOLBAR_CalcToolbar (hwnd);
3535 InvalidateRect (hwnd, NULL, TRUE);
3541 /* << TOOLBAR_InsertMarkHitTest >> */
3545 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3550 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3554 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3559 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3564 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3568 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3573 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3575 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3578 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3582 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3587 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3589 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3592 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3596 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3601 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3606 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3610 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3615 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3620 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3624 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3628 /* << TOOLBAR_LoadImages >> */
3629 /* << TOOLBAR_MapAccelerator >> */
3630 /* << TOOLBAR_MarkButton >> */
3631 /* << TOOLBAR_MoveButton >> */
3635 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3638 TBUTTON_INFO *btnPtr;
3641 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3645 btnPtr = &infoPtr->buttons[nIndex];
3646 if (LOWORD(lParam) == FALSE)
3647 btnPtr->fsState &= ~TBSTATE_PRESSED;
3649 btnPtr->fsState |= TBSTATE_PRESSED;
3651 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3658 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3660 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3661 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3663 int i = 0, nOldButtons = 0, pos = 0;
3665 TRACE("hInstOld %x nIDOld %x hInstNew %x nIDNew %x nButtons %x\n",
3666 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3667 lpReplace->nButtons);
3669 if (lpReplace->hInstOld == -1)
3671 FIXME("changing standard bitmaps not implemented\n");
3674 else if (lpReplace->hInstOld != 0)
3676 FIXME("resources not in the current module not implemented\n");
3681 hBitmap = (HBITMAP) lpReplace->nIDNew;
3684 TRACE("To be replaced hInstOld %x nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3685 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3686 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3687 TRACE("tbimapinfo %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3688 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3690 TRACE("Found: nButtons %d hInst %x nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3691 nOldButtons = tbi->nButtons;
3692 tbi->nButtons = lpReplace->nButtons;
3693 tbi->hInst = lpReplace->hInstNew;
3694 tbi->nID = lpReplace->nIDNew;
3695 TRACE("tbimapinfo changed %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3698 pos += tbi->nButtons;
3701 if (nOldButtons == 0)
3703 WARN("No hinst/bitmap found! hInst %x nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3707 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
3709 /* ImageList_Replace(infoPtr->himlDef, pos, hBitmap, NULL); */
3712 for (i = pos + nOldButtons - 1; i >= pos; i--) {
3713 ImageList_Remove(infoPtr->himlDef, i);
3716 ImageList_AddMasked(infoPtr->himlDef, hBitmap, CLR_DEFAULT);
3718 InvalidateRect(hwnd, NULL, FALSE);
3724 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3728 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3730 if (lpSave == NULL) return 0;
3733 /* save toolbar information */
3734 FIXME("save to \"%s\" \"%s\"\n",
3735 lpSave->pszSubKey, lpSave->pszValueName);
3740 /* restore toolbar information */
3742 FIXME("restore from \"%s\" \"%s\"\n",
3743 lpSave->pszSubKey, lpSave->pszValueName);
3754 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3757 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3758 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3764 /* save toolbar information */
3765 FIXME("save to \"%s\" \"%s\"\n",
3766 lpSave->pszSubKey, lpSave->pszValueName);
3771 /* restore toolbar information */
3773 FIXME("restore from \"%s\" \"%s\"\n",
3774 lpSave->pszSubKey, lpSave->pszValueName);
3785 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3788 BOOL bOldAnchor = infoPtr->bAnchor;
3790 infoPtr->bAnchor = (BOOL)wParam;
3792 return (LRESULT)bOldAnchor;
3797 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3801 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3804 if (infoPtr->nNumButtons > 0)
3805 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3806 infoPtr->nNumButtons,
3807 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3808 LOWORD(lParam), HIWORD(lParam));
3810 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3811 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3813 /* uses image list internals directly */
3814 if (infoPtr->himlDef) {
3815 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3816 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3824 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3827 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3828 TBUTTON_INFO *btnPtr;
3833 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3836 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3837 lptbbi->dwMask & 0x80000000);
3841 btnPtr = &infoPtr->buttons[nIndex];
3842 if (lptbbi->dwMask & TBIF_COMMAND)
3843 btnPtr->idCommand = lptbbi->idCommand;
3844 if (lptbbi->dwMask & TBIF_IMAGE)
3845 btnPtr->iBitmap = lptbbi->iImage;
3846 if (lptbbi->dwMask & TBIF_LPARAM)
3847 btnPtr->dwData = lptbbi->lParam;
3848 /* if (lptbbi->dwMask & TBIF_SIZE) */
3849 /* btnPtr->cx = lptbbi->cx; */
3850 if (lptbbi->dwMask & TBIF_STATE)
3851 btnPtr->fsState = lptbbi->fsState;
3852 if (lptbbi->dwMask & TBIF_STYLE)
3853 btnPtr->fsStyle = lptbbi->fsStyle;
3855 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3856 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3857 /* iString is index, zero it to make Str_SetPtr succeed */
3860 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3867 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3869 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3870 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3871 TBUTTON_INFO *btnPtr;
3876 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3879 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3880 lptbbi->dwMask & 0x80000000);
3884 btnPtr = &infoPtr->buttons[nIndex];
3885 if (lptbbi->dwMask & TBIF_COMMAND)
3886 btnPtr->idCommand = lptbbi->idCommand;
3887 if (lptbbi->dwMask & TBIF_IMAGE)
3888 btnPtr->iBitmap = lptbbi->iImage;
3889 if (lptbbi->dwMask & TBIF_LPARAM)
3890 btnPtr->dwData = lptbbi->lParam;
3891 /* if (lptbbi->dwMask & TBIF_SIZE) */
3892 /* btnPtr->cx = lptbbi->cx; */
3893 if (lptbbi->dwMask & TBIF_STATE)
3894 btnPtr->fsState = lptbbi->fsState;
3895 if (lptbbi->dwMask & TBIF_STYLE)
3896 btnPtr->fsStyle = lptbbi->fsStyle;
3898 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3899 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3900 /* iString is index, zero it to make Str_SetPtr succeed */
3902 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3909 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3911 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3912 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
3914 if ((cx < 0) || (cy < 0))
3916 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
3920 /* The documentation claims you can only change the button size before
3921 * any button has been added. But this is wrong.
3922 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3923 * it to the toolbar, and it checks that the return value is nonzero - mjm
3924 * Further testing shows that we must actually perform the change too.
3927 * The documentation also does not mention that if 0 is supplied for
3928 * either size, the system changes it to the default of 24 wide and
3929 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
3931 infoPtr->nButtonWidth = (cx) ? cx : 24;
3932 infoPtr->nButtonHeight = (cy) ? cy : 22;
3938 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3942 if (infoPtr == NULL) {
3943 TRACE("Toolbar not initialized yet?????\n");
3947 /* if setting to current values, ignore */
3948 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3949 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3950 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3951 infoPtr->cxMin, infoPtr->cxMax);
3955 /* save new values */
3956 infoPtr->cxMin = (INT)LOWORD(lParam);
3957 infoPtr->cxMax = (INT)HIWORD(lParam);
3959 /* if both values are 0 then we are done */
3961 TRACE("setting both min and max to 0, norecalc\n");
3965 /* otherwise we need to recalc the toolbar and in some cases
3966 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3967 which doesn't actually draw - GA). */
3968 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3969 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3971 TOOLBAR_CalcToolbar (hwnd);
3973 InvalidateRect (hwnd, NULL, TRUE);
3980 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3982 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3983 INT nIndex = (INT)wParam;
3985 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3988 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3990 if (infoPtr->hwndToolTip) {
3992 FIXME("change tool tip!\n");
4001 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4004 HIMAGELIST himlTemp;
4008 FIXME("no support for multiple image lists\n");
4012 himlTemp = infoPtr->himlDis;
4013 infoPtr->himlDis = (HIMAGELIST)lParam;
4015 /* FIXME: redraw ? */
4017 return (LRESULT)himlTemp;
4022 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4024 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4027 dwTemp = infoPtr->dwDTFlags;
4028 infoPtr->dwDTFlags =
4029 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4031 return (LRESULT)dwTemp;
4035 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4037 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4040 dwTemp = infoPtr->dwExStyle;
4041 infoPtr->dwExStyle = (DWORD)lParam;
4043 if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
4044 TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
4045 FIXME("Extended style not implemented %s %s\n",
4046 (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
4047 "TBSTYLE_EX_MIXEDBUTTONS" : "",
4048 (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
4049 "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
4052 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4053 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4054 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4056 return (LRESULT)dwTemp;
4061 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4063 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4064 HIMAGELIST himlTemp;
4067 FIXME("no support for multiple image lists\n");
4071 himlTemp = infoPtr->himlHot;
4072 infoPtr->himlHot = (HIMAGELIST)lParam;
4074 /* FIXME: redraw ? */
4076 return (LRESULT)himlTemp;
4081 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4084 INT nOldHotItem = infoPtr->nHotItem;
4085 TBUTTON_INFO *btnPtr;
4087 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4090 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4093 infoPtr->nHotItem = (INT)wParam;
4094 if ((INT)wParam >=0)
4096 btnPtr = &infoPtr->buttons[(INT)wParam];
4097 btnPtr->bHot = TRUE;
4098 InvalidateRect (hwnd, &btnPtr->rect,
4099 TOOLBAR_HasText(infoPtr, btnPtr));
4103 btnPtr = &infoPtr->buttons[nOldHotItem];
4104 btnPtr->bHot = FALSE;
4105 InvalidateRect (hwnd, &btnPtr->rect,
4106 TOOLBAR_HasText(infoPtr, btnPtr));
4110 if (nOldHotItem < 0)
4113 return (LRESULT)nOldHotItem;
4118 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4120 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4121 HIMAGELIST himlTemp;
4124 FIXME("no support for multiple image lists\n");
4128 himlTemp = infoPtr->himlDef;
4129 infoPtr->himlDef = (HIMAGELIST)lParam;
4131 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
4133 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
4134 &infoPtr->nBitmapHeight);
4135 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4136 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4137 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4139 /* FIXME: redraw ? */
4140 InvalidateRect(hwnd, NULL, TRUE);
4142 return (LRESULT)himlTemp;
4147 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4151 infoPtr->nIndent = (INT)wParam;
4155 /* process only on indent changing */
4156 if(infoPtr->nIndent != (INT)wParam)
4158 infoPtr->nIndent = (INT)wParam;
4159 TOOLBAR_CalcToolbar (hwnd);
4160 InvalidateRect(hwnd, NULL, FALSE);
4167 /* << TOOLBAR_SetInsertMark >> */
4171 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4175 infoPtr->clrInsertMark = (COLORREF)lParam;
4177 /* FIXME : redraw ??*/
4184 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4186 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4188 if (infoPtr == NULL)
4191 infoPtr->nMaxTextRows = (INT)wParam;
4198 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4200 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4203 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4204 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4205 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4206 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4207 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4208 return (LRESULT) oldPad;
4213 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4220 if (infoPtr == NULL)
4222 hwndOldNotify = infoPtr->hwndNotify;
4223 infoPtr->hwndNotify = (HWND)wParam;
4225 return hwndOldNotify;
4230 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4233 LPRECT lprc = (LPRECT)lParam;
4237 if (LOWORD(wParam) > 1) {
4238 FIXME("multiple rows not supported!\n");
4241 if(infoPtr->nRows != LOWORD(wParam))
4243 infoPtr->nRows = LOWORD(wParam);
4245 /* recalculate toolbar */
4246 TOOLBAR_CalcToolbar (hwnd);
4248 /* repaint toolbar */
4249 InvalidateRect(hwnd, NULL, FALSE);
4252 /* return bounding rectangle */
4254 lprc->left = infoPtr->rcBound.left;
4255 lprc->right = infoPtr->rcBound.right;
4256 lprc->top = infoPtr->rcBound.top;
4257 lprc->bottom = infoPtr->rcBound.bottom;
4265 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4267 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4268 TBUTTON_INFO *btnPtr;
4271 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4275 btnPtr = &infoPtr->buttons[nIndex];
4277 /* if hidden state has changed the invalidate entire window and recalc */
4278 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4279 btnPtr->fsState = LOWORD(lParam);
4280 TOOLBAR_CalcToolbar (hwnd);
4281 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4285 /* process state changing if current state doesn't match new state */
4286 if(btnPtr->fsState != LOWORD(lParam))
4288 btnPtr->fsState = LOWORD(lParam);
4289 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4298 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4301 TBUTTON_INFO *btnPtr;
4304 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4308 btnPtr = &infoPtr->buttons[nIndex];
4310 /* process style change if current style doesn't match new style */
4311 if(btnPtr->fsStyle != LOWORD(lParam))
4313 btnPtr->fsStyle = LOWORD(lParam);
4314 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4317 if (infoPtr->hwndToolTip) {
4318 FIXME("change tool tip!\n");
4326 inline static LRESULT
4327 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4331 if (infoPtr == NULL)
4333 infoPtr->hwndToolTip = (HWND)wParam;
4339 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4341 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4344 TRACE("%s hwnd=0x%04x stub!\n",
4345 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4347 bTemp = infoPtr->bUnicode;
4348 infoPtr->bUnicode = (BOOL)wParam;
4355 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4357 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4359 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4360 comctl32_color.clrBtnHighlight :
4361 infoPtr->clrBtnHighlight;
4362 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4363 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4369 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4373 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4374 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4375 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4377 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4378 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4379 InvalidateRect(hwnd, 0, 0);
4385 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4388 INT iOldVersion = infoPtr->iVersion;
4390 infoPtr->iVersion = iVersion;
4396 /*********************************************************************/
4398 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4399 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4400 /* based on relay traces of the native control and IE 5.5 */
4402 /*********************************************************************/
4404 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4406 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4407 INT nOldHotItem = infoPtr->nHotItem;
4408 TBUTTON_INFO *btnPtr;
4410 NMTBHOTITEM nmhotitem;
4412 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4415 infoPtr->nHotItem = (INT)wParam;
4416 if (nOldHotItem != infoPtr->nHotItem) {
4417 nmhotitem.dwFlags = (DWORD)lParam;
4418 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4419 nmhotitem.idOld = (nOldHotItem >= 0) ?
4420 infoPtr->buttons[nOldHotItem].idCommand : 0;
4421 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4422 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4423 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4424 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4426 if ((INT)wParam >=0) {
4427 btnPtr = &infoPtr->buttons[(INT)wParam];
4428 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4429 InvalidateRect (hwnd, &btnPtr->rect,
4430 TOOLBAR_HasText(infoPtr, btnPtr));
4432 if (nOldHotItem>=0) {
4433 btnPtr = &infoPtr->buttons[nOldHotItem];
4434 btnPtr->bHot = FALSE;
4435 InvalidateRect (hwnd, &btnPtr->rect,
4436 TOOLBAR_HasText(infoPtr, btnPtr));
4439 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4440 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4442 if (nOldHotItem < 0)
4445 return (LRESULT)nOldHotItem;
4450 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4453 LPSIZE lpsize = (LPSIZE)lParam;
4459 * Testing shows the following:
4460 * wParam = 0 adjust cx value
4461 * = 1 set cy value to max size.
4462 * lParam pointer to SIZE structure
4465 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4466 wParam, lParam, lpsize->cx, lpsize->cy);
4470 if (lpsize->cx == -1) {
4471 /* **** this is wrong, native measures each button and sets it */
4472 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4474 else if(HIWORD(lpsize->cx)) {
4476 HWND hwndParent = GetParent(hwnd);
4478 InvalidateRect(hwnd, 0, 1);
4479 GetWindowRect(hwnd, &rc);
4480 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4481 TRACE("mapped to (%d,%d)-(%d,%d)\n",
4482 rc.left, rc.top, rc.right, rc.bottom);
4483 lpsize->cx = max(rc.right-rc.left,
4484 infoPtr->rcBound.right - infoPtr->rcBound.left);
4487 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4491 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4492 /* lpsize->cy = infoPtr->nHeight; */
4495 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4499 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4500 lpsize->cx, lpsize->cy);
4506 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4509 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4512 /* initialize info structure */
4513 infoPtr->nButtonHeight = 22;
4514 infoPtr->nButtonWidth = 24;
4515 infoPtr->nBitmapHeight = 15;
4516 infoPtr->nBitmapWidth = 16;
4518 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4520 infoPtr->nMaxTextRows = 1;
4521 infoPtr->cxMin = -1;
4522 infoPtr->cxMax = -1;
4523 infoPtr->nNumBitmaps = 0;
4524 infoPtr->nNumStrings = 0;
4526 infoPtr->bCaptured = FALSE;
4527 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4528 infoPtr->nButtonDown = -1;
4529 infoPtr->nOldHit = -1;
4530 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4531 infoPtr->hwndNotify = GetParent (hwnd);
4532 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4533 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4534 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4535 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4536 infoPtr->iVersion = 0;
4537 infoPtr->hwndSelf = hwnd;
4538 infoPtr->bDoRedraw = TRUE;
4539 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4540 infoPtr->clrBtnShadow = CLR_DEFAULT;
4541 infoPtr->szPadding.cx = 7;
4542 infoPtr->szPadding.cy = 6;
4543 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4545 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4546 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4548 if (dwStyle & TBSTYLE_TOOLTIPS) {
4549 /* Create tooltip control */
4550 infoPtr->hwndToolTip =
4551 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4552 CW_USEDEFAULT, CW_USEDEFAULT,
4553 CW_USEDEFAULT, CW_USEDEFAULT,
4556 /* Send NM_TOOLTIPSCREATED notification */
4557 if (infoPtr->hwndToolTip) {
4558 NMTOOLTIPSCREATED nmttc;
4560 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4562 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4563 NM_TOOLTIPSCREATED);
4567 TOOLBAR_CheckStyle (hwnd, dwStyle);
4569 TOOLBAR_CalcToolbar(hwnd);
4576 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4580 /* delete tooltip control */
4581 if (infoPtr->hwndToolTip)
4582 DestroyWindow (infoPtr->hwndToolTip);
4584 /* delete button data */
4585 if (infoPtr->buttons)
4586 COMCTL32_Free (infoPtr->buttons);
4588 /* delete strings */
4589 if (infoPtr->strings) {
4591 for (i = 0; i < infoPtr->nNumStrings; i++)
4592 if (infoPtr->strings[i])
4593 COMCTL32_Free (infoPtr->strings[i]);
4595 COMCTL32_Free (infoPtr->strings);
4598 /* destroy internal image list */
4599 if (infoPtr->himlInt)
4600 ImageList_Destroy (infoPtr->himlInt);
4602 /* delete default font */
4604 DeleteObject (infoPtr->hDefaultFont);
4606 /* free toolbar info data */
4607 COMCTL32_Free (infoPtr);
4608 SetWindowLongA (hwnd, 0, 0);
4615 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4618 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4619 NMTBCUSTOMDRAW tbcd;
4623 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4624 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4625 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4626 tbcd.nmcd.hdc = (HDC)wParam;
4627 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4628 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4630 /* FIXME: in general the return flags *can* be or'ed together */
4631 switch (infoPtr->dwBaseCustDraw)
4633 case CDRF_DODEFAULT:
4635 case CDRF_SKIPDEFAULT:
4638 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4643 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4644 * to my parent for processing.
4646 if (infoPtr->bTransparent) {
4648 HDC hdc = (HDC)wParam;
4653 parent = GetParent(hwnd);
4654 MapWindowPoints(hwnd, parent, &pt, 1);
4655 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4656 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4657 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4660 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4662 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
4663 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
4664 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4665 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4666 tbcd.nmcd.hdc = (HDC)wParam;
4667 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4668 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4669 switch (infoPtr->dwBaseCustDraw)
4671 case CDRF_DODEFAULT:
4673 case CDRF_SKIPDEFAULT:
4676 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4685 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4689 return infoPtr->hFont;
4694 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4696 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4697 TBUTTON_INFO *btnPtr;
4701 pt.x = (INT)LOWORD(lParam);
4702 pt.y = (INT)HIWORD(lParam);
4703 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4706 btnPtr = &infoPtr->buttons[nHit];
4707 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4710 infoPtr->bCaptured = TRUE;
4711 infoPtr->nButtonDown = nHit;
4713 btnPtr->fsState |= TBSTATE_PRESSED;
4715 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4718 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4719 TOOLBAR_Customize (hwnd);
4726 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4728 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4729 TBUTTON_INFO *btnPtr;
4734 if (infoPtr->hwndToolTip)
4735 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4736 WM_LBUTTONDOWN, wParam, lParam);
4738 pt.x = (INT)LOWORD(lParam);
4739 pt.y = (INT)HIWORD(lParam);
4740 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4744 btnPtr = &infoPtr->buttons[nHit];
4745 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4748 infoPtr->nOldHit = nHit;
4750 CopyRect(&arrowRect, &btnPtr->rect);
4751 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4753 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4754 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4755 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4756 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4760 * this time we must force a Redraw, so the btn is
4761 * painted down before CaptureChanged repaints it up
4763 RedrawWindow(hwnd,&btnPtr->rect,0,
4764 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4766 nmtb.iItem = btnPtr->idCommand;
4767 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4770 memset(&nmtb.rcButton, 0, sizeof(RECT));
4771 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4773 if (res != TBDDRET_TREATPRESSED)
4774 /* ??? guess (GA) */
4776 /* otherwise drop through and process as pushed */
4778 /* SetCapture (hwnd); */
4779 infoPtr->bCaptured = TRUE;
4780 infoPtr->nButtonDown = nHit;
4782 btnPtr->fsState |= TBSTATE_PRESSED;
4783 btnPtr->bHot = FALSE;
4785 InvalidateRect(hwnd, &btnPtr->rect,
4786 TOOLBAR_HasText(infoPtr, btnPtr));
4790 /* native issues the TBN_BEGINDRAG here */
4791 nmtb.iItem = btnPtr->idCommand;
4792 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4793 nmtb.tbButton.idCommand = btnPtr->idCommand;
4794 nmtb.tbButton.fsState = btnPtr->fsState;
4795 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4796 nmtb.tbButton.dwData = btnPtr->dwData;
4797 nmtb.tbButton.iString = btnPtr->iString;
4798 nmtb.cchText = 0; /* !!! not correct */
4799 nmtb.pszText = 0; /* !!! not correct */
4800 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4808 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4811 TBUTTON_INFO *btnPtr;
4815 BOOL bSendMessage = TRUE;
4820 if (infoPtr->hwndToolTip)
4821 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4822 WM_LBUTTONUP, wParam, lParam);
4824 pt.x = (INT)LOWORD(lParam);
4825 pt.y = (INT)HIWORD(lParam);
4826 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4828 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4829 /* if the cursor is still inside of the toolbar */
4830 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4831 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4833 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4834 btnPtr->fsState &= ~TBSTATE_PRESSED;
4836 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4837 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4838 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4840 if (nOldIndex == nHit)
4841 bSendMessage = FALSE;
4842 if ((nOldIndex != nHit) &&
4844 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4845 btnPtr->fsState |= TBSTATE_CHECKED;
4848 if (btnPtr->fsState & TBSTATE_CHECKED)
4849 btnPtr->fsState &= ~TBSTATE_CHECKED;
4851 btnPtr->fsState |= TBSTATE_CHECKED;
4855 if (nOldIndex != -1)
4857 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4858 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4862 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4863 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4864 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4866 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
4869 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4870 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4871 NM_RELEASEDCAPTURE);
4873 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4876 nmtb.iItem = btnPtr->idCommand;
4877 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4878 nmtb.tbButton.idCommand = btnPtr->idCommand;
4879 nmtb.tbButton.fsState = btnPtr->fsState;
4880 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4881 nmtb.tbButton.dwData = btnPtr->dwData;
4882 nmtb.tbButton.iString = btnPtr->iString;
4883 nmtb.cchText = 0; /* !!! not correct */
4884 nmtb.pszText = 0; /* !!! not correct */
4885 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4888 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4889 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
4891 /* !!! Undocumented - toolbar at 4.71 level and above sends
4892 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4893 * Only NM_RCLICK is documented.
4895 nmmouse.dwItemSpec = btnPtr->idCommand;
4896 nmmouse.dwItemData = btnPtr->dwData;
4897 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4903 TOOLBAR_CaptureChanged(HWND hwnd)
4905 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4906 TBUTTON_INFO *btnPtr;
4908 infoPtr->bCaptured = FALSE;
4910 if (infoPtr->nButtonDown >= 0)
4912 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4913 btnPtr->fsState &= ~TBSTATE_PRESSED;
4915 infoPtr->nButtonDown = -1;
4916 infoPtr->nOldHit = -1;
4918 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4925 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4927 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4928 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4931 if (infoPtr->nOldHit < 0)
4934 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4936 /* Redraw the button if the last button we were over is the hot button and it
4938 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4940 hotBtnPtr->bHot = FALSE;
4941 rc1 = hotBtnPtr->rect;
4942 InflateRect (&rc1, 1, 1);
4943 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4947 /* If the last button we were over is depressed then make it not */
4948 /* depressed and redraw it */
4949 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4951 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4953 btnPtr->fsState &= ~TBSTATE_PRESSED;
4955 rc1 = hotBtnPtr->rect;
4956 InflateRect (&rc1, 1, 1);
4957 InvalidateRect (hwnd, &rc1, TRUE);
4960 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4961 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4967 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4969 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4970 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4973 TRACKMOUSEEVENT trackinfo;
4974 NMTBHOTITEM nmhotitem;
4976 /* fill in the TRACKMOUSEEVENT struct */
4977 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4978 trackinfo.dwFlags = TME_QUERY;
4979 trackinfo.hwndTrack = hwnd;
4980 trackinfo.dwHoverTime = HOVER_DEFAULT;
4982 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4983 _TrackMouseEvent(&trackinfo);
4985 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4986 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4987 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4989 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4990 /* and can properly deactivate the hot toolbar button */
4991 _TrackMouseEvent(&trackinfo);
4994 if (infoPtr->hwndToolTip)
4995 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4996 WM_MOUSEMOVE, wParam, lParam);
4998 pt.x = (INT)LOWORD(lParam);
4999 pt.y = (INT)HIWORD(lParam);
5001 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5003 if (infoPtr->nOldHit != nHit)
5005 /* Remove the effect of an old hot button if the button was enabled and was
5006 drawn with the hot button effect */
5007 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
5008 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
5010 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5011 oldBtnPtr->bHot = FALSE;
5014 /* It's not a separator or in nowhere. It's a hot button. */
5017 btnPtr = &infoPtr->buttons[nHit];
5019 infoPtr->nHotItem = nHit;
5021 /* only enabled buttons show hot effect */
5022 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
5024 btnPtr->bHot = TRUE;
5028 nmhotitem.dwFlags = HICF_MOUSE;
5030 nmhotitem.idOld = oldBtnPtr->idCommand;
5032 nmhotitem.dwFlags |= HICF_ENTERING;
5034 nmhotitem.idNew = btnPtr->idCommand;
5036 nmhotitem.dwFlags |= HICF_LEAVING;
5037 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5039 /* now invalidate the old and new buttons so they will be painted */
5041 InvalidateRect (hwnd, &oldBtnPtr->rect,
5042 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5043 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
5044 InvalidateRect(hwnd, &btnPtr->rect,
5045 TOOLBAR_HasText(infoPtr, btnPtr));
5047 if (infoPtr->bCaptured) {
5048 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5049 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5050 btnPtr->fsState &= ~TBSTATE_PRESSED;
5051 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5053 else if (nHit == infoPtr->nButtonDown) {
5054 btnPtr->fsState |= TBSTATE_PRESSED;
5055 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5058 infoPtr->nOldHit = nHit;
5064 inline static LRESULT
5065 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5067 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5068 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5070 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5074 inline static LRESULT
5075 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5077 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5078 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5080 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5085 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5087 TOOLBAR_INFO *infoPtr;
5088 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5091 /* allocate memory for info structure */
5092 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
5093 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5096 infoPtr->dwStructSize = sizeof(TBBUTTON);
5098 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5099 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5100 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5101 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5104 /* native control does:
5105 * Get a lot of colors and brushes
5107 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5108 * CreateFontIndirectA(adr1)
5109 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5110 * hdc = GetDC(toolbar)
5111 * GetSystemMetrics(0x48)
5112 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5113 * 0, 0, 0, 0, "MARLETT")
5114 * oldfnt = SelectObject(hdc, fnt2)
5115 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5116 * GetTextMetricsA(hdc, adr3)
5117 * SelectObject(hdc, oldfnt)
5118 * DeleteObject(fnt2)
5120 * InvalidateRect(toolbar, 0, 1)
5121 * SetWindowLongA(toolbar, 0, addr)
5122 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5125 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5126 * ie 2 0x4600094c 0x4600094c 0x4600894d
5127 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5128 * rebar 0x50008844 0x40008844 0x50008845
5129 * pager 0x50000844 0x40000844 0x50008845
5130 * IC35mgr 0x5400084e **nochange**
5131 * on entry to _NCCREATE 0x5400084e
5132 * rowlist 0x5400004e **nochange**
5133 * on entry to _NCCREATE 0x5400004e
5137 /* I think the code below is a bug, but it is the way that the native
5138 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5139 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5140 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5141 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5142 * Some how, the only cases of this seem to be MFC programs.
5144 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5145 * does not occur in the WM_STYLECHANGING routine.
5146 * (Guy Albertelli 9/2001)
5149 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5150 styleadd |= TBSTYLE_TRANSPARENT;
5151 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5152 styleadd |= CCS_TOP; /* default to top */
5153 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5156 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5161 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5163 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5167 if (dwStyle & WS_MINIMIZE)
5168 return 0; /* Nothing to do */
5170 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5172 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5175 if (!(dwStyle & CCS_NODIVIDER))
5177 GetWindowRect (hwnd, &rcWindow);
5178 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5179 if( dwStyle & WS_BORDER )
5180 OffsetRect (&rcWindow, 1, 1);
5181 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5184 ReleaseDC( hwnd, hdc );
5190 inline static LRESULT
5191 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5194 LPNMHDR lpnmh = (LPNMHDR)lParam;
5196 if (lpnmh->code == PGN_CALCSIZE) {
5197 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5199 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5200 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5201 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5205 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5206 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5212 if (lpnmh->code == PGN_SCROLL) {
5213 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5215 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5216 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5217 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5218 lppgs->iScroll, lppgs->iDir);
5223 TRACE("passing WM_NOTIFY!\n");
5225 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5226 if (infoPtr->bNtfUnicode)
5227 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5230 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5234 if (lpnmh->code == TTN_GETDISPINFOA) {
5235 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5237 FIXME("retrieving ASCII string\n");
5240 else if (lpnmh->code == TTN_GETDISPINFOW) {
5241 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5243 FIXME("retrieving UNICODE string\n");
5254 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5256 /* remove this routine when Toolbar is improved to pass infoPtr
5257 * around instead of hwnd.
5259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5260 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5265 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5269 if (lParam == NF_REQUERY) {
5270 i = SendMessageA(GetParent(infoPtr->hwndSelf),
5271 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
5272 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5273 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5277 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5280 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5285 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5291 /* fill ps.rcPaint with a default rect */
5292 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5294 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5296 TRACE("psrect=(%d,%d)-(%d,%d)\n",
5297 ps.rcPaint.left, ps.rcPaint.top,
5298 ps.rcPaint.right, ps.rcPaint.bottom);
5300 TOOLBAR_Refresh (hwnd, hdc, &ps);
5301 if (!wParam) EndPaint (hwnd, &ps);
5308 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5309 /*****************************************************
5312 * Handles the WM_SETREDRAW message.
5315 * According to testing V4.71 of COMCTL32 returns the
5316 * *previous* status of the redraw flag (either 0 or 1)
5317 * instead of the MSDN documented value of 0 if handled.
5318 * (For laughs see the "consistancy" with same function
5321 *****************************************************/
5323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5324 BOOL oldredraw = infoPtr->bDoRedraw;
5326 TRACE("set to %s\n",
5327 (wParam) ? "TRUE" : "FALSE");
5328 infoPtr->bDoRedraw = (BOOL) wParam;
5330 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5332 return (oldredraw) ? 1 : 0;
5337 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5339 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5340 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5349 /* Resize deadlock check */
5350 if (infoPtr->bAutoSize) {
5351 infoPtr->bAutoSize = FALSE;
5355 /* FIXME: optimize to only update size if the new size doesn't */
5356 /* match the current size */
5358 flags = (INT) wParam;
5360 /* FIXME for flags =
5361 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5364 TRACE("sizing toolbar!\n");
5366 if (flags == SIZE_RESTORED) {
5367 /* width and height don't apply */
5368 parent = GetParent (hwnd);
5369 GetClientRect(parent, &parent_rect);
5370 x = parent_rect.left;
5371 y = parent_rect.top;
5373 if (dwStyle & CCS_NORESIZE) {
5374 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5377 * this sets the working width of the toolbar, and
5378 * Calc Toolbar will not adjust it, only the height
5380 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5381 cy = infoPtr->nHeight;
5382 cx = infoPtr->nWidth;
5383 TOOLBAR_CalcToolbar (hwnd);
5384 infoPtr->nWidth = cx;
5385 infoPtr->nHeight = cy;
5388 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5389 TOOLBAR_CalcToolbar (hwnd);
5390 cy = infoPtr->nHeight;
5391 cx = infoPtr->nWidth;
5393 if (dwStyle & CCS_NOMOVEY) {
5394 GetWindowRect(hwnd, &window_rect);
5395 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5396 y = window_rect.top;
5400 if (dwStyle & CCS_NOPARENTALIGN) {
5401 uPosFlags |= SWP_NOMOVE;
5402 cy = infoPtr->nHeight;
5403 cx = infoPtr->nWidth;
5406 if (!(dwStyle & CCS_NODIVIDER))
5407 cy += GetSystemMetrics(SM_CYEDGE);
5409 if (dwStyle & WS_BORDER)
5412 cy += GetSystemMetrics(SM_CYEDGE);
5413 cx += GetSystemMetrics(SM_CYEDGE);
5416 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
5417 cx, cy, uPosFlags | SWP_NOZORDER);
5424 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5428 if (nType == GWL_STYLE) {
5429 if (lpStyle->styleNew & TBSTYLE_LIST) {
5430 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5433 infoPtr->dwDTFlags = DT_CENTER;
5435 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5436 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5437 (TBSTYLE_FLAT | TBSTYLE_LIST));
5438 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5441 TOOLBAR_AutoSize (hwnd);
5443 InvalidateRect(hwnd, NULL, FALSE);
5450 TOOLBAR_SysColorChange (HWND hwnd)
5452 COMCTL32_RefreshSysColors();
5459 static LRESULT WINAPI
5460 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5462 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
5463 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5465 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5466 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5471 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5473 case TB_ADDBUTTONSA:
5474 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5476 case TB_ADDBUTTONSW:
5477 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5480 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5483 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5486 return TOOLBAR_AutoSize (hwnd);
5488 case TB_BUTTONCOUNT:
5489 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5491 case TB_BUTTONSTRUCTSIZE:
5492 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5494 case TB_CHANGEBITMAP:
5495 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5497 case TB_CHECKBUTTON:
5498 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5500 case TB_COMMANDTOINDEX:
5501 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5504 return TOOLBAR_Customize (hwnd);
5506 case TB_DELETEBUTTON:
5507 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5509 case TB_ENABLEBUTTON:
5510 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5512 case TB_GETANCHORHIGHLIGHT:
5513 return TOOLBAR_GetAnchorHighlight (hwnd);
5516 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5518 case TB_GETBITMAPFLAGS:
5519 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5522 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5524 case TB_GETBUTTONINFOA:
5525 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5527 case TB_GETBUTTONINFOW:
5528 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5530 case TB_GETBUTTONSIZE:
5531 return TOOLBAR_GetButtonSize (hwnd);
5533 case TB_GETBUTTONTEXTA:
5534 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5536 case TB_GETBUTTONTEXTW:
5537 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5539 case TB_GETDISABLEDIMAGELIST:
5540 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5542 case TB_GETEXTENDEDSTYLE:
5543 return TOOLBAR_GetExtendedStyle (hwnd);
5545 case TB_GETHOTIMAGELIST:
5546 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5549 return TOOLBAR_GetHotItem (hwnd);
5551 case TB_GETIMAGELIST:
5552 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
5554 /* case TB_GETINSERTMARK: */ /* 4.71 */
5555 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5557 case TB_GETITEMRECT:
5558 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5561 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5563 /* case TB_GETOBJECT: */ /* 4.71 */
5566 return TOOLBAR_GetPadding (hwnd);
5569 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5572 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5575 return TOOLBAR_GetState (hwnd, wParam, lParam);
5578 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5580 case TB_GETTEXTROWS:
5581 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5583 case TB_GETTOOLTIPS:
5584 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5586 case TB_GETUNICODEFORMAT:
5587 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5590 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5593 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5595 case TB_INDETERMINATE:
5596 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5598 case TB_INSERTBUTTONA:
5599 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5601 case TB_INSERTBUTTONW:
5602 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5604 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5606 case TB_ISBUTTONCHECKED:
5607 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5609 case TB_ISBUTTONENABLED:
5610 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5612 case TB_ISBUTTONHIDDEN:
5613 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5615 case TB_ISBUTTONHIGHLIGHTED:
5616 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5618 case TB_ISBUTTONINDETERMINATE:
5619 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5621 case TB_ISBUTTONPRESSED:
5622 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5624 case TB_LOADIMAGES: /* 4.70 */
5625 FIXME("missing standard imagelists\n");
5628 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5629 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5630 /* case TB_MARKBUTTON: */ /* 4.71 */
5631 /* case TB_MOVEBUTTON: */ /* 4.71 */
5633 case TB_PRESSBUTTON:
5634 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5636 case TB_REPLACEBITMAP:
5637 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
5639 case TB_SAVERESTOREA:
5640 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5642 case TB_SAVERESTOREW:
5643 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5645 case TB_SETANCHORHIGHLIGHT:
5646 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5648 case TB_SETBITMAPSIZE:
5649 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5651 case TB_SETBUTTONINFOA:
5652 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5654 case TB_SETBUTTONINFOW:
5655 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5657 case TB_SETBUTTONSIZE:
5658 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5660 case TB_SETBUTTONWIDTH:
5661 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5664 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5666 case TB_SETDISABLEDIMAGELIST:
5667 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5669 case TB_SETDRAWTEXTFLAGS:
5670 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5672 case TB_SETEXTENDEDSTYLE:
5673 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5675 case TB_SETHOTIMAGELIST:
5676 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5679 return TOOLBAR_SetHotItem (hwnd, wParam);
5681 case TB_SETIMAGELIST:
5682 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5685 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5687 /* case TB_SETINSERTMARK: */ /* 4.71 */
5689 case TB_SETINSERTMARKCOLOR:
5690 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5692 case TB_SETMAXTEXTROWS:
5693 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5696 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
5699 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5702 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5705 return TOOLBAR_SetState (hwnd, wParam, lParam);
5708 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5710 case TB_SETTOOLTIPS:
5711 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5713 case TB_SETUNICODEFORMAT:
5714 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5717 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
5720 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
5723 /* Common Control Messages */
5725 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
5726 case CCM_GETCOLORSCHEME:
5727 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5729 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
5730 case CCM_SETCOLORSCHEME:
5731 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5733 case CCM_GETVERSION:
5734 return TOOLBAR_GetVersion (hwnd);
5736 case CCM_SETVERSION:
5737 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5743 return TOOLBAR_Create (hwnd, wParam, lParam);
5746 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5749 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5752 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5754 /* case WM_KEYDOWN: */
5755 /* case WM_KILLFOCUS: */
5757 case WM_LBUTTONDBLCLK:
5758 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5760 case WM_LBUTTONDOWN:
5761 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5764 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5767 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5770 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5772 case WM_CAPTURECHANGED:
5773 return TOOLBAR_CaptureChanged(hwnd);
5776 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5779 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5782 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5785 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5788 return TOOLBAR_Notify (hwnd, wParam, lParam);
5790 case WM_NOTIFYFORMAT:
5791 TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
5794 return TOOLBAR_Paint (hwnd, wParam);
5797 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5800 return TOOLBAR_Size (hwnd, wParam, lParam);
5802 case WM_STYLECHANGED:
5803 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5805 case WM_SYSCOLORCHANGE:
5806 return TOOLBAR_SysColorChange (hwnd);
5808 /* case WM_WININICHANGE: */
5813 case WM_MEASUREITEM:
5816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5818 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5820 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5823 /* We see this in Outlook Express 5.x and just does DefWindowProc */
5824 case PGM_FORWARDMOUSE:
5825 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5828 if (uMsg >= WM_USER)
5829 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5830 uMsg, wParam, lParam);
5831 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5838 TOOLBAR_Register (void)
5842 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5843 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5844 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5845 wndClass.cbClsExtra = 0;
5846 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5847 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5848 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5849 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5851 RegisterClassA (&wndClass);
5856 TOOLBAR_Unregister (void)
5858 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);