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)
472 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
473 hOldPen = SelectObject ( hdc, hPen );
476 MoveToEx (hdc, x, y, NULL);
477 LineTo (hdc, x+5, y++); x++;
478 MoveToEx (hdc, x, y, NULL);
479 LineTo (hdc, x+3, y++); x++;
480 MoveToEx (hdc, x, y, NULL);
481 LineTo (hdc, x+1, y++);
482 SelectObject( hdc, hOldPen );
483 DeleteObject( hPen );
487 * Draw the text string for this button.
488 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
489 * is non-zero, so we can simply check himlDef to see if we have
493 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
494 HDC hdc, INT nState, DWORD dwStyle,
495 RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
502 TRACE("string rect=(%d,%d)-(%d,%d)\n",
503 rcText->left, rcText->top, rcText->right, rcText->bottom);
505 hOldFont = SelectObject (hdc, infoPtr->hFont);
506 if (!(nState & TBSTATE_ENABLED)) {
507 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
508 OffsetRect (rcText, 1, 1);
509 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
510 SetTextColor (hdc, comctl32_color.clr3dShadow);
511 OffsetRect (rcText, -1, -1);
513 else if (nState & TBSTATE_INDETERMINATE) {
514 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
516 else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
517 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
520 clrOld = SetTextColor (hdc, tbcd->clrText);
523 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
524 SetTextColor (hdc, clrOld);
525 SelectObject (hdc, hOldFont);
531 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
533 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
534 INT cx = lpRect->right - lpRect->left;
535 INT cy = lpRect->bottom - lpRect->top;
536 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
537 SelectObject (hdc, hbr);
542 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
543 HDC hdc, INT x, INT y)
545 /* FIXME: this function is a hack since it uses image list
546 internals directly */
548 HIMAGELIST himl = infoPtr->himlDef;
556 /* create new dc's */
557 hdcImageList = CreateCompatibleDC (0);
558 hdcMask = CreateCompatibleDC (0);
560 /* create new bitmap */
561 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
562 SelectObject (hdcMask, hbmMask);
564 /* copy the mask bitmap */
565 SelectObject (hdcImageList, himl->hbmMask);
566 SetBkColor (hdcImageList, RGB(255, 255, 255));
567 SetTextColor (hdcImageList, RGB(0, 0, 0));
568 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
569 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
571 /* draw the new mask */
572 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
573 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
574 hdcMask, 0, 0, 0xB8074A);
576 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
577 BitBlt (hdc, x, y, himl->cx, himl->cy,
578 hdcMask, 0, 0, 0xB8074A);
580 DeleteObject (hbmMask);
582 DeleteDC (hdcImageList);
587 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
591 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
592 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
593 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
594 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
595 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
596 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
597 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
598 /* don't test TBSTATE_HIDDEN */
604 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
607 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
608 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
609 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
610 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
611 LPWSTR lpText = NULL;
616 if (btnPtr->fsState & TBSTATE_HIDDEN)
620 CopyRect (&rcFill, &rc);
621 CopyRect (&rcArrow, &rc);
622 CopyRect(&rcBitmap, &rc);
623 CopyRect(&rcText, &rc);
625 /* get a pointer to the text */
626 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
628 if (hasDropDownArrow)
630 if (dwStyle & TBSTYLE_FLAT)
631 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
633 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
634 rcArrow.left = rc.right;
637 /* Center the bitmap horizontally and vertically */
638 if (dwStyle & TBSTYLE_LIST)
641 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
644 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
646 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
648 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
649 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
650 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
651 TRACE ("iString: %x\n", btnPtr->iString);
652 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
657 InflateRect (&rcText, -3, -3);
659 if (infoPtr->himlDef &&
660 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
661 /* The following test looked like this before
662 * I changed it. IE4 "Links" toolbar would not
663 * draw correctly with the original code. - GA 8/01
664 * ((dwStyle & TBSTYLE_LIST) &&
665 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
666 * (btnPtr->iBitmap != I_IMAGENONE))
668 if (dwStyle & TBSTYLE_LIST) {
669 /* LIST style w/ ICON offset is by matching native. */
670 /* Matches IE4 "Links" bar. - GA 8/01 */
671 rcText.left += (infoPtr->nBitmapWidth + 2);
674 rcText.top += infoPtr->nBitmapHeight + 1;
678 if (dwStyle & TBSTYLE_LIST) {
679 /* LIST style w/o ICON offset is by matching native. */
680 /* Matches IE4 "menu" bar. - GA 8/01 */
685 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
686 OffsetRect (&rcText, 1, 1);
689 /* Initialize fields in all cases, because we use these later */
690 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
691 tbcd.clrText = comctl32_color.clrBtnText;
692 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
693 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
694 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
695 tbcd.clrMark = comctl32_color.clrHighlight;
696 tbcd.clrHighlightHotTrack = 0;
697 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
698 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
699 /* MSDN says that this is the text rectangle. */
700 /* But (why always a but) tracing of v5.7 of native shows */
701 /* that this is really a *relative* rectangle based on the */
702 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
703 /* any bitmap that might be present. */
704 tbcd.rcText.left = 0;
706 tbcd.rcText.right = rcText.right - rc.left;
707 tbcd.rcText.bottom = rcText.bottom - rc.top;
709 /* FIXME: what should these be set to ????? */
710 tbcd.hbrMonoDither = 0;
714 /* Issue Item Prepaint notify */
715 infoPtr->dwItemCustDraw = 0;
716 infoPtr->dwItemCDFlag = 0;
717 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
719 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
722 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
723 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
724 tbcd.nmcd.lItemlParam = btnPtr->dwData;
725 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
726 infoPtr->dwItemCustDraw = ntfret & 0xffff;
727 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
728 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
730 /* save the only part of the rect that the user can change */
731 rcText.right = tbcd.rcText.right + rc.left;
732 rcText.bottom = tbcd.rcText.bottom + rc.top;
735 if (!infoPtr->bBtnTranspnt)
736 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
739 if (btnPtr->fsStyle & TBSTYLE_SEP) {
740 /* with the FLAT style, iBitmap is the width and has already */
741 /* been taken into consideration in calculating the width */
742 /* so now we need to draw the vertical separator */
743 /* empirical tests show that iBitmap can/will be non-zero */
744 /* when drawing the vertical bar... */
745 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
746 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
747 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
749 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
751 else if (btnPtr->fsStyle != TBSTYLE_SEP) {
752 FIXME("Draw some kind of separator: fsStyle=%x\n",
759 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
760 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
764 if (hasDropDownArrow)
765 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
766 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
769 if (hasDropDownArrow)
771 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
772 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
775 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
776 hdc, rcBitmap.left, rcBitmap.top,
778 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
780 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
784 /* pressed TBSTYLE_BUTTON */
785 if (btnPtr->fsState & TBSTATE_PRESSED) {
786 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
787 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
789 if (dwStyle & TBSTYLE_FLAT)
791 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
792 if (hasDropDownArrow)
793 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
797 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
798 if (hasDropDownArrow)
799 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
803 if (hasDropDownArrow)
804 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
806 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
807 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
810 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
814 /* checked TBSTYLE_CHECK */
815 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
816 (btnPtr->fsState & TBSTATE_CHECKED)) {
817 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
819 if (dwStyle & TBSTYLE_FLAT)
820 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
821 BF_RECT | BF_ADJUST);
823 DrawEdge (hdc, &rc, EDGE_SUNKEN,
824 BF_RECT | BF_MIDDLE | BF_ADJUST);
827 TOOLBAR_DrawPattern (hdc, &rc);
829 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
830 hdc, rcBitmap.left+1, rcBitmap.top+1,
833 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
838 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
839 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
840 DrawEdge (hdc, &rc, EDGE_RAISED,
841 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
843 TOOLBAR_DrawPattern (hdc, &rc);
844 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
845 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
850 if (dwStyle & TBSTYLE_FLAT)
854 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
858 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
859 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
860 if (hasDropDownArrow)
861 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
862 SetBkColor(hdc, oldclr);
866 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
868 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
869 if (hasDropDownArrow)
870 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
875 else /* The following code needs to be removed after
876 * "hot item" support has been implemented for the
877 * case where it is being de-selected.
880 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
881 if (hasDropDownArrow)
882 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
886 if (hasDropDownArrow)
887 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
890 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
891 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
894 rcBitmap.top, ILD_NORMAL))
895 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
896 hdc, rcBitmap.left, rcBitmap.top,
900 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
901 hdc, rcBitmap.left, rcBitmap.top,
906 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
907 DrawEdge (hdc, &rc, EDGE_RAISED,
908 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
910 if (hasDropDownArrow)
912 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
913 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
914 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
915 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
918 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
919 hdc, rcBitmap.left, rcBitmap.top,
923 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
926 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
928 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
931 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
932 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
933 tbcd.nmcd.lItemlParam = btnPtr->dwData;
934 tbcd.rcText = rcText;
935 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
936 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
937 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
944 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
947 TBUTTON_INFO *btnPtr;
948 INT i, oldBKmode = 0;
953 /* if imagelist belongs to the app, it can be changed
954 by the app after setting it */
955 if (infoPtr->himlDef != infoPtr->himlInt)
956 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
958 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
960 /* Send initial notify */
961 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
962 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
964 tbcd.nmcd.rc = ps->rcPaint;
965 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
966 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
968 if (infoPtr->bBtnTranspnt)
969 oldBKmode = SetBkMode (hdc, TRANSPARENT);
971 /* redraw necessary buttons */
972 btnPtr = infoPtr->buttons;
973 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
975 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
976 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
979 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
980 SetBkMode (hdc, oldBKmode);
982 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
984 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
985 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
987 tbcd.nmcd.rc = ps->rcPaint;
988 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
992 /***********************************************************************
993 * TOOLBAR_MeasureString
995 * This function gets the width and height of a string in pixels. This
996 * is done first by using GetTextExtentPoint to get the basic width
997 * and height. The DrawText is called with DT_CALCRECT to get the exact
998 * width. The reason is because the text may have more than one "&" (or
999 * prefix characters as M$ likes to call them). The prefix character
1000 * indicates where the underline goes, except for the string "&&" which
1001 * is reduced to a single "&". GetTextExtentPoint does not process these
1002 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
1005 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1006 HDC hdc, LPSIZE lpSize)
1013 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
1015 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1017 if(lpText != NULL) {
1018 /* first get size of all the text */
1019 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1021 /* feed above size into the rectangle for DrawText */
1022 myrect.left = myrect.top = 0;
1023 myrect.right = lpSize->cx;
1024 myrect.bottom = lpSize->cy;
1026 /* Use DrawText to get true size as drawn (less pesky "&") */
1027 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1028 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
1031 /* feed back to caller */
1032 lpSize->cx = myrect.right;
1033 lpSize->cy = myrect.bottom;
1037 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1040 /***********************************************************************
1041 * TOOLBAR_CalcStrings
1043 * This function walks through each string and measures it and returns
1044 * the largest height and width to caller.
1047 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1050 TBUTTON_INFO *btnPtr;
1060 hOldFont = SelectObject (hdc, infoPtr->hFont);
1062 btnPtr = infoPtr->buttons;
1063 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1064 if(TOOLBAR_HasText(infoPtr, btnPtr))
1066 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1067 if (sz.cx > lpSize->cx)
1069 if (sz.cy > lpSize->cy)
1074 SelectObject (hdc, hOldFont);
1075 ReleaseDC (hwnd, hdc);
1077 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1080 /***********************************************************************
1081 * TOOLBAR_WrapToolbar
1083 * This function walks through the buttons and seperators in the
1084 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1085 * wrapping should occur based on the width of the toolbar window.
1086 * It does *not* calculate button placement itself. That task
1087 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1088 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1089 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1091 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1092 * vertical toolbar lists.
1096 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1099 TBUTTON_INFO *btnPtr;
1102 BOOL bWrap, bButtonWrap;
1104 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1105 /* no layout is necessary. Applications may use this style */
1106 /* to perform their own layout on the toolbar. */
1107 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1108 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1110 btnPtr = infoPtr->buttons;
1111 x = infoPtr->nIndent;
1113 /* this can get the parents width, to know how far we can extend
1114 * this toolbar. We cannot use its height, as there may be multiple
1115 * toolbars in a rebar control
1117 GetClientRect( GetParent(hwnd), &rc );
1118 infoPtr->nWidth = rc.right - rc.left;
1119 bButtonWrap = FALSE;
1121 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1122 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1125 for (i = 0; i < infoPtr->nNumButtons; i++ )
1128 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1130 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1133 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1134 /* it is the actual width of the separator. This is used for */
1135 /* custom controls in toolbars. */
1137 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
1138 /* width. - GA 8/01 */
1139 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1140 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
1141 cx = (btnPtr[i].iBitmap > 0) ?
1142 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1144 cx = infoPtr->nButtonWidth;
1146 /* Two or more adjacent separators form a separator group. */
1147 /* The first separator in a group should be wrapped to the */
1148 /* next row if the previous wrapping is on a button. */
1150 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1151 (i + 1 < infoPtr->nNumButtons ) &&
1152 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
1154 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1155 btnPtr[i].fsState |= TBSTATE_WRAP;
1156 x = infoPtr->nIndent;
1158 bButtonWrap = FALSE;
1162 /* The layout makes sure the bitmap is visible, but not the button. */
1163 /* Test added to also wrap after a button that starts a row but */
1164 /* is bigger than the area. - GA 8/01 */
1165 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1166 > infoPtr->nWidth ) ||
1167 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1169 BOOL bFound = FALSE;
1171 /* If the current button is a separator and not hidden, */
1172 /* go to the next until it reaches a non separator. */
1173 /* Wrap the last separator if it is before a button. */
1174 while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1175 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
1176 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1177 i < infoPtr->nNumButtons )
1183 if( bFound && i < infoPtr->nNumButtons )
1186 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1187 i, btnPtr[i].fsStyle, x, cx);
1188 btnPtr[i].fsState |= TBSTATE_WRAP;
1189 x = infoPtr->nIndent;
1190 bButtonWrap = FALSE;
1193 else if ( i >= infoPtr->nNumButtons)
1196 /* If the current button is not a separator, find the last */
1197 /* separator and wrap it. */
1198 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1200 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1201 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1205 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1206 i, btnPtr[i].fsStyle, x, cx);
1207 x = infoPtr->nIndent;
1208 btnPtr[j].fsState |= TBSTATE_WRAP;
1209 bButtonWrap = FALSE;
1214 /* If no separator available for wrapping, wrap one of */
1215 /* non-hidden previous button. */
1219 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1221 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1226 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1227 i, btnPtr[i].fsStyle, x, cx);
1228 x = infoPtr->nIndent;
1229 btnPtr[j].fsState |= TBSTATE_WRAP;
1235 /* If all above failed, wrap the current button. */
1238 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1239 i, btnPtr[i].fsStyle, x, cx);
1240 btnPtr[i].fsState |= TBSTATE_WRAP;
1242 x = infoPtr->nIndent;
1243 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1244 bButtonWrap = FALSE;
1250 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1251 i, btnPtr[i].fsStyle, x, cx);
1258 /***********************************************************************
1259 * TOOLBAR_CalcToolbar
1261 * This function calculates button and separator placement. It first
1262 * calculates the button sizes, gets the toolbar window width and then
1263 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1264 * on. It assigns a new location to each item and sends this location to
1265 * the tooltip window if appropriate. Finally, it updates the rcBound
1266 * rect and calculates the new required toolbar window height.
1270 TOOLBAR_CalcToolbar (HWND hwnd)
1272 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1273 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1274 TBUTTON_INFO *btnPtr;
1275 INT i, nRows, nSepRows;
1279 BOOL usesBitmaps = FALSE;
1280 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1282 TOOLBAR_CalcStrings (hwnd, &sizeString);
1284 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1286 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1289 if (dwStyle & TBSTYLE_LIST)
1291 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1292 0, sizeString.cy) + infoPtr->szPadding.cy;
1293 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1294 0) + sizeString.cx + 6;
1295 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1296 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1297 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1298 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1301 if (sizeString.cy > 0)
1304 infoPtr->nButtonHeight = sizeString.cy +
1305 2 + /* this is the space to separate text from bitmap */
1306 infoPtr->nBitmapHeight + 6;
1308 infoPtr->nButtonHeight = sizeString.cy + 6;
1310 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1311 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1313 if (sizeString.cx > infoPtr->nBitmapWidth)
1314 infoPtr->nButtonWidth = sizeString.cx + 6;
1315 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1316 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1319 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1320 infoPtr->nButtonWidth = infoPtr->cxMin;
1321 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1322 infoPtr->nButtonWidth = infoPtr->cxMax;
1324 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1326 x = infoPtr->nIndent;
1330 * We will set the height below, and we set the width on entry
1331 * so we do not reset them here..
1334 GetClientRect( hwnd, &rc );
1335 /* get initial values for toolbar */
1336 infoPtr->nWidth = rc.right - rc.left;
1337 infoPtr->nHeight = rc.bottom - rc.top;
1340 /* from above, minimum is a button, and possible text */
1341 cx = infoPtr->nButtonWidth;
1343 /* cannot use just ButtonHeight, we may have no buttons! */
1344 if (infoPtr->nNumButtons > 0)
1345 infoPtr->nHeight = infoPtr->nButtonHeight;
1347 cy = infoPtr->nHeight;
1349 nRows = nSepRows = 0;
1351 infoPtr->rcBound.top = y;
1352 infoPtr->rcBound.left = x;
1353 infoPtr->rcBound.bottom = y + cy;
1354 infoPtr->rcBound.right = x;
1356 btnPtr = infoPtr->buttons;
1358 /* do not base height/width on parent, if the parent is a */
1359 /* rebar control it could have multiple rows of toolbars */
1360 /* GetClientRect( GetParent(hwnd), &rc ); */
1361 /* cx = rc.right - rc.left; */
1362 /* cy = rc.bottom - rc.top; */
1364 TRACE("cy=%d\n", cy);
1366 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1369 if (btnPtr->fsState & TBSTATE_HIDDEN)
1371 SetRectEmpty (&btnPtr->rect);
1375 cy = infoPtr->nHeight;
1377 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1378 /* it is the actual width of the separator. This is used for */
1379 /* custom controls in toolbars. */
1380 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1381 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1382 cy = (btnPtr->iBitmap > 0) ?
1383 btnPtr->iBitmap : SEPARATOR_WIDTH;
1384 cx = infoPtr->nButtonWidth;
1387 cx = (btnPtr->iBitmap > 0) ?
1388 btnPtr->iBitmap : SEPARATOR_WIDTH;
1392 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1399 hOldFont = SelectObject (hdc, infoPtr->hFont);
1401 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1403 SelectObject (hdc, hOldFont);
1404 ReleaseDC (hwnd, hdc);
1406 /* Fudge amount measured against IE4 "menu" and "Links" */
1407 /* toolbars with native control (v4.71). - GA 8/01 */
1408 cx = sz.cx + 6 + 5 + 5;
1409 if ((dwStyle & TBSTYLE_LIST) &&
1410 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1411 cx += infoPtr->nBitmapWidth;
1414 cx = infoPtr->nButtonWidth;
1416 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1417 cx += DDARROW_WIDTH;
1419 if (btnPtr->fsState & TBSTATE_WRAP )
1422 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1424 if (infoPtr->rcBound.left > x)
1425 infoPtr->rcBound.left = x;
1426 if (infoPtr->rcBound.right < x + cx)
1427 infoPtr->rcBound.right = x + cx;
1428 if (infoPtr->rcBound.bottom < y + cy)
1429 infoPtr->rcBound.bottom = y + cy;
1431 /* Set the toolTip only for non-hidden, non-separator button */
1432 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1436 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1437 ti.cbSize = sizeof(TTTOOLINFOA);
1439 ti.uId = btnPtr->idCommand;
1440 ti.rect = btnPtr->rect;
1441 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1445 /* btnPtr->nRow is zero based. The space between the rows is */
1446 /* also considered as a row. */
1447 btnPtr->nRow = nRows + nSepRows;
1449 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1450 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1455 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1459 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1460 /* it is the actual width of the separator. This is used for */
1461 /* custom controls in toolbars. */
1462 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1463 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1464 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1468 /* nSepRows is used to calculate the extra height follwoing */
1472 x = infoPtr->nIndent;
1474 /* Increment row number unless this is the last button */
1475 /* and it has Wrap set. */
1476 if (i != infoPtr->nNumButtons-1)
1483 /* infoPtr->nRows is the number of rows on the toolbar */
1484 infoPtr->nRows = nRows + nSepRows + 1;
1487 /********************************************************************
1488 * The following while interesting, does not match the values *
1489 * created above for the button rectangles, nor the rcBound rect. *
1490 * We will comment it out and remove it later. *
1492 * The problem showed up as heights in the pager control that was *
1494 ********************************************************************/
1496 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1498 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1499 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1500 nSepRows * (infoPtr->nBitmapHeight + 1) +
1504 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1506 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1511 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1514 TBUTTON_INFO *btnPtr;
1517 btnPtr = infoPtr->buttons;
1518 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1519 if (btnPtr->fsState & TBSTATE_HIDDEN)
1522 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1523 if (PtInRect (&btnPtr->rect, *lpPt)) {
1524 TRACE(" ON SEPARATOR %d!\n", i);
1529 if (PtInRect (&btnPtr->rect, *lpPt)) {
1530 TRACE(" ON BUTTON %d!\n", i);
1536 TRACE(" NOWHERE!\n");
1542 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1544 TBUTTON_INFO *btnPtr;
1547 if (CommandIsIndex) {
1548 TRACE("command is really index command=%d\n", idCommand);
1549 if (idCommand >= infoPtr->nNumButtons) return -1;
1552 btnPtr = infoPtr->buttons;
1553 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1554 if (btnPtr->idCommand == idCommand) {
1555 TRACE("command=%d index=%d\n", idCommand, i);
1559 TRACE("no index found for command=%d\n", idCommand);
1565 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1567 TBUTTON_INFO *btnPtr;
1570 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1573 /* check index button */
1574 btnPtr = &infoPtr->buttons[nIndex];
1575 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1576 if (btnPtr->fsState & TBSTATE_CHECKED)
1580 /* check previous buttons */
1581 nRunIndex = nIndex - 1;
1582 while (nRunIndex >= 0) {
1583 btnPtr = &infoPtr->buttons[nRunIndex];
1584 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1585 if (btnPtr->fsState & TBSTATE_CHECKED)
1593 /* check next buttons */
1594 nRunIndex = nIndex + 1;
1595 while (nRunIndex < infoPtr->nNumButtons) {
1596 btnPtr = &infoPtr->buttons[nRunIndex];
1597 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1598 if (btnPtr->fsState & TBSTATE_CHECKED)
1611 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1612 WPARAM wParam, LPARAM lParam)
1618 msg.wParam = wParam;
1619 msg.lParam = lParam;
1620 msg.time = GetMessageTime ();
1621 msg.pt.x = LOWORD(GetMessagePos ());
1622 msg.pt.y = HIWORD(GetMessagePos ());
1624 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1628 /***********************************************************************
1629 * TOOLBAR_CustomizeDialogProc
1630 * This function implements the toolbar customization dialog.
1633 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1635 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1636 PCUSTOMBUTTON btnInfo;
1638 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1643 custInfo = (PCUSTDLG_INFO)lParam;
1644 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1652 infoPtr = custInfo->tbInfo;
1654 /* send TBN_QUERYINSERT notification */
1655 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1657 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1660 /* add items to 'toolbar buttons' list and check if removable */
1661 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1663 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1664 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1665 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1666 btnInfo->bVirtual = FALSE;
1667 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1669 /* send TBN_QUERYDELETE notification */
1671 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1675 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1676 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1679 /* insert separator button into 'available buttons' list */
1680 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1681 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1682 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1683 btnInfo->bVirtual = FALSE;
1684 btnInfo->bRemovable = TRUE;
1685 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1686 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1687 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1689 /* insert all buttons into dsa */
1692 /* send TBN_GETBUTTONINFO notification */
1694 nmtb.pszText = Buffer;
1697 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1700 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1702 /* insert button into the apropriate list */
1703 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1706 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1707 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1708 btnInfo->bVirtual = FALSE;
1709 btnInfo->bRemovable = TRUE;
1710 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1711 strcpy (btnInfo->text, nmtb.pszText);
1713 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1714 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1718 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1719 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1720 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1721 strcpy (btnInfo->text, nmtb.pszText);
1723 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1727 /* select first item in the 'available' list */
1728 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1730 /* append 'virtual' separator button to the 'toolbar buttons' list */
1731 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1732 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1733 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1734 btnInfo->bVirtual = TRUE;
1735 btnInfo->bRemovable = FALSE;
1736 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1737 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1738 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1740 /* select last item in the 'toolbar' list */
1741 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1742 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1744 /* set focus and disable buttons */
1745 PostMessageA (hwnd, WM_USER, 0, 0);
1750 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1751 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1752 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1753 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1757 EndDialog(hwnd, FALSE);
1761 switch (LOWORD(wParam))
1763 case IDC_TOOLBARBTN_LBOX:
1764 if (HIWORD(wParam) == LBN_SELCHANGE)
1766 PCUSTOMBUTTON btnInfo;
1771 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1772 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1774 /* send TBN_QUERYINSERT notification */
1776 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1779 /* get list box item */
1780 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1782 if (index == (count - 1))
1784 /* last item (virtual separator) */
1785 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1786 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1788 else if (index == (count - 2))
1790 /* second last item (last non-virtual item) */
1791 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1792 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1794 else if (index == 0)
1797 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1798 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1802 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1803 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1806 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1810 case IDC_MOVEUP_BTN:
1812 PCUSTOMBUTTON btnInfo;
1816 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1817 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1818 TRACE("Move up: index %d\n", index);
1820 /* send TBN_QUERYINSERT notification */
1823 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1826 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1828 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1829 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1830 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1831 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1834 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1835 else if (index >= (count - 3))
1836 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1838 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1839 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1844 case IDC_MOVEDN_BTN: /* move down */
1846 PCUSTOMBUTTON btnInfo;
1850 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1851 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1852 TRACE("Move up: index %d\n", index);
1854 /* send TBN_QUERYINSERT notification */
1856 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1859 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1861 /* move button down */
1862 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1863 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1864 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1865 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1868 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1869 else if (index >= (count - 3))
1870 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1872 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1873 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1878 case IDC_REMOVE_BTN: /* remove button */
1880 PCUSTOMBUTTON btnInfo;
1883 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1884 TRACE("Remove: index %d\n", index);
1886 /* send TBN_QUERYDELETE notification */
1888 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1891 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1895 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1897 /* insert into 'available button' list */
1898 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1900 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1901 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1904 COMCTL32_Free (btnInfo);
1909 case IDOK: /* Add button */
1914 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1915 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1916 TRACE("Add: index %d\n", index);
1918 /* send TBN_QUERYINSERT notification */
1920 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1923 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1927 /* remove from 'available buttons' list */
1928 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1929 if (index == count-1)
1930 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1932 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1936 PCUSTOMBUTTON btnNew;
1938 /* duplicate 'separator' button */
1939 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1940 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1944 /* insert into 'toolbar button' list */
1945 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1946 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1947 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1949 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1955 EndDialog(hwnd, FALSE);
1965 /* delete items from 'toolbar buttons' listbox*/
1966 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1967 for (i = 0; i < count; i++)
1969 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1970 COMCTL32_Free(btnInfo);
1971 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1973 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1976 /* delete items from 'available buttons' listbox*/
1977 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1978 for (i = 0; i < count; i++)
1980 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1981 COMCTL32_Free(btnInfo);
1982 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1984 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1989 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1991 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1996 COLORREF oldText = 0;
2000 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2001 if (btnInfo == NULL)
2003 FIXME("btnInfo invalid!\n");
2007 /* set colors and select objects */
2008 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2009 if (btnInfo->bVirtual)
2010 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2012 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2013 hPen = CreatePen( PS_SOLID, 1,
2014 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2015 hOldPen = SelectObject (lpdis->hDC, hPen );
2016 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2018 /* fill background rectangle */
2019 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2020 lpdis->rcItem.right, lpdis->rcItem.bottom);
2022 /* calculate button and text rectangles */
2023 CopyRect (&rcButton, &lpdis->rcItem);
2024 InflateRect (&rcButton, -1, -1);
2025 CopyRect (&rcText, &rcButton);
2026 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2027 rcText.left = rcButton.right + 2;
2029 /* draw focus rectangle */
2030 if (lpdis->itemState & ODS_FOCUS)
2031 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2034 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2036 /* draw image and text */
2037 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
2038 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
2039 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2040 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
2041 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2043 /* delete objects and reset colors */
2044 SelectObject (lpdis->hDC, hOldBrush);
2045 SelectObject (lpdis->hDC, hOldPen);
2046 SetBkColor (lpdis->hDC, oldBk);
2047 SetTextColor (lpdis->hDC, oldText);
2048 DeleteObject( hPen );
2053 case WM_MEASUREITEM:
2054 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2056 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2058 if (custInfo && custInfo->tbInfo)
2059 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2061 lpmis->itemHeight = 15 + 8; /* default height */
2073 /***********************************************************************
2074 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2078 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2081 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2082 INT nIndex = 0, nButtons, nCount;
2085 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2089 if (lpAddBmp->hInst == HINST_COMMCTRL)
2091 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2093 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2095 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2100 TRACE ("adding %d internal bitmaps!\n", nButtons);
2102 /* Windows resize all the buttons to the size of a newly added standard image */
2103 if (lpAddBmp->nID & 1)
2106 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2107 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2109 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2110 MAKELPARAM((WORD)24, (WORD)24));
2111 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2112 MAKELPARAM((WORD)31, (WORD)30));
2117 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2118 MAKELPARAM((WORD)16, (WORD)16));
2119 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2120 MAKELPARAM((WORD)22, (WORD)22));
2123 TOOLBAR_CalcToolbar (hwnd);
2127 nButtons = (INT)wParam;
2131 TRACE ("adding %d bitmaps!\n", nButtons);
2134 if (!(infoPtr->himlDef)) {
2135 /* create new default image list */
2136 TRACE ("creating default image list!\n");
2139 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2140 ILC_COLOR | ILC_MASK, nButtons, 2);
2141 infoPtr->himlInt = infoPtr->himlDef;
2144 nCount = ImageList_GetImageCount(infoPtr->himlDef);
2146 /* Add bitmaps to the default image list */
2147 if (lpAddBmp->hInst == (HINSTANCE)0)
2150 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
2153 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2155 /* Add system bitmaps */
2156 switch (lpAddBmp->nID)
2158 case IDB_STD_SMALL_COLOR:
2159 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2160 MAKEINTRESOURCEA(IDB_STD_SMALL));
2161 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2162 hbmLoad, CLR_DEFAULT);
2163 DeleteObject (hbmLoad);
2166 case IDB_STD_LARGE_COLOR:
2167 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2168 MAKEINTRESOURCEA(IDB_STD_LARGE));
2169 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2170 hbmLoad, CLR_DEFAULT);
2171 DeleteObject (hbmLoad);
2174 case IDB_VIEW_SMALL_COLOR:
2175 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2176 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2177 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2178 hbmLoad, CLR_DEFAULT);
2179 DeleteObject (hbmLoad);
2182 case IDB_VIEW_LARGE_COLOR:
2183 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2184 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2185 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2186 hbmLoad, CLR_DEFAULT);
2187 DeleteObject (hbmLoad);
2190 case IDB_HIST_SMALL_COLOR:
2191 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2192 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2193 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2194 hbmLoad, CLR_DEFAULT);
2195 DeleteObject (hbmLoad);
2198 case IDB_HIST_LARGE_COLOR:
2199 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2200 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2201 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2202 hbmLoad, CLR_DEFAULT);
2203 DeleteObject (hbmLoad);
2207 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
2208 ERR ("invalid imagelist!\n");
2214 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2215 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
2216 DeleteObject (hbmLoad);
2219 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2221 if (infoPtr->nNumBitmapInfos == 0)
2223 infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
2227 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2228 infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2229 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2232 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2233 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2234 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2236 infoPtr->nNumBitmapInfos++;
2237 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2241 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2243 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2245 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",
2246 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2247 infoPtr->nNumBitmaps+nButtons,imagecount);
2249 infoPtr->nNumBitmaps = imagecount;
2252 infoPtr->nNumBitmaps += nButtons;
2255 InvalidateRect(hwnd, NULL, FALSE);
2262 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2265 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2266 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2268 TRACE("adding %d buttons!\n", wParam);
2270 nAddButtons = (UINT)wParam;
2271 nOldButtons = infoPtr->nNumButtons;
2272 nNewButtons = nOldButtons + nAddButtons;
2274 if (infoPtr->nNumButtons == 0) {
2276 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2279 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2281 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2282 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2283 nOldButtons * sizeof(TBUTTON_INFO));
2284 COMCTL32_Free (oldButtons);
2287 infoPtr->nNumButtons = nNewButtons;
2289 /* insert new button data */
2290 for (nCount = 0; nCount < nAddButtons; nCount++) {
2291 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2292 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2293 btnPtr->idCommand = lpTbb[nCount].idCommand;
2294 btnPtr->fsState = lpTbb[nCount].fsState;
2295 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2296 btnPtr->dwData = lpTbb[nCount].dwData;
2297 btnPtr->iString = lpTbb[nCount].iString;
2298 btnPtr->bHot = FALSE;
2300 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2303 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2304 ti.cbSize = sizeof (TTTOOLINFOA);
2306 ti.uId = btnPtr->idCommand;
2308 ti.lpszText = LPSTR_TEXTCALLBACKA;
2310 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2315 TOOLBAR_CalcToolbar (hwnd);
2317 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2319 InvalidateRect(hwnd, NULL, FALSE);
2326 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2329 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2330 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2332 TRACE("adding %d buttons!\n", wParam);
2334 nAddButtons = (UINT)wParam;
2335 nOldButtons = infoPtr->nNumButtons;
2336 nNewButtons = nOldButtons + nAddButtons;
2338 if (infoPtr->nNumButtons == 0) {
2340 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2343 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2345 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2346 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2347 nOldButtons * sizeof(TBUTTON_INFO));
2348 COMCTL32_Free (oldButtons);
2351 infoPtr->nNumButtons = nNewButtons;
2353 /* insert new button data */
2354 for (nCount = 0; nCount < nAddButtons; nCount++) {
2355 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2356 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2357 btnPtr->idCommand = lpTbb[nCount].idCommand;
2358 btnPtr->fsState = lpTbb[nCount].fsState;
2359 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2360 btnPtr->dwData = lpTbb[nCount].dwData;
2361 btnPtr->iString = lpTbb[nCount].iString;
2362 btnPtr->bHot = FALSE;
2364 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2367 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2368 ti.cbSize = sizeof (TTTOOLINFOW);
2370 ti.uId = btnPtr->idCommand;
2372 ti.lpszText = LPSTR_TEXTCALLBACKW;
2374 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2379 TOOLBAR_CalcToolbar (hwnd);
2381 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2383 InvalidateRect(hwnd, NULL, FALSE);
2390 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2395 if ((wParam) && (HIWORD(lParam) == 0)) {
2398 TRACE("adding string from resource!\n");
2400 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2403 TRACE("len=%d \"%s\"\n", len, szString);
2404 nIndex = infoPtr->nNumStrings;
2405 if (infoPtr->nNumStrings == 0) {
2407 COMCTL32_Alloc (sizeof(LPWSTR));
2410 LPWSTR *oldStrings = infoPtr->strings;
2412 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2413 memcpy (&infoPtr->strings[0], &oldStrings[0],
2414 sizeof(LPWSTR) * infoPtr->nNumStrings);
2415 COMCTL32_Free (oldStrings);
2418 /*COMCTL32_Alloc zeros out the allocated memory*/
2419 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2420 infoPtr->nNumStrings++;
2423 LPSTR p = (LPSTR)lParam;
2428 TRACE("adding string(s) from array!\n");
2430 nIndex = infoPtr->nNumStrings;
2433 TRACE("len=%d \"%s\"\n", len, p);
2435 if (infoPtr->nNumStrings == 0) {
2437 COMCTL32_Alloc (sizeof(LPWSTR));
2440 LPWSTR *oldStrings = infoPtr->strings;
2442 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2443 memcpy (&infoPtr->strings[0], &oldStrings[0],
2444 sizeof(LPWSTR) * infoPtr->nNumStrings);
2445 COMCTL32_Free (oldStrings);
2448 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2449 infoPtr->nNumStrings++;
2460 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2462 #define MAX_RESOURCE_STRING_LENGTH 512
2463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2466 if ((wParam) && (HIWORD(lParam) == 0)) {
2467 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2469 TRACE("adding string from resource!\n");
2471 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2472 szString, MAX_RESOURCE_STRING_LENGTH);
2474 TRACE("len=%d %s\n", len, debugstr_w(szString));
2475 TRACE("First char: 0x%x\n", *szString);
2476 if (szString[0] == L'|')
2478 PWSTR p = szString + 1;
2480 nIndex = infoPtr->nNumStrings;
2481 while (*p != L'|') {
2483 if (infoPtr->nNumStrings == 0) {
2485 COMCTL32_Alloc (sizeof(LPWSTR));
2488 LPWSTR *oldStrings = infoPtr->strings;
2490 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2491 memcpy (&infoPtr->strings[0], &oldStrings[0],
2492 sizeof(LPWSTR) * infoPtr->nNumStrings);
2493 COMCTL32_Free (oldStrings);
2496 len = COMCTL32_StrChrW (p, L'|') - p;
2497 TRACE("len=%d %s\n", len, debugstr_w(p));
2498 infoPtr->strings[infoPtr->nNumStrings] =
2499 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2500 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2501 infoPtr->nNumStrings++;
2508 nIndex = infoPtr->nNumStrings;
2509 if (infoPtr->nNumStrings == 0) {
2511 COMCTL32_Alloc (sizeof(LPWSTR));
2514 LPWSTR *oldStrings = infoPtr->strings;
2516 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2517 memcpy (&infoPtr->strings[0], &oldStrings[0],
2518 sizeof(LPWSTR) * infoPtr->nNumStrings);
2519 COMCTL32_Free (oldStrings);
2522 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2523 infoPtr->nNumStrings++;
2527 LPWSTR p = (LPWSTR)lParam;
2532 TRACE("adding string(s) from array!\n");
2533 nIndex = infoPtr->nNumStrings;
2537 TRACE("len=%d %s\n", len, debugstr_w(p));
2538 if (infoPtr->nNumStrings == 0) {
2540 COMCTL32_Alloc (sizeof(LPWSTR));
2543 LPWSTR *oldStrings = infoPtr->strings;
2545 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2546 memcpy (&infoPtr->strings[0], &oldStrings[0],
2547 sizeof(LPWSTR) * infoPtr->nNumStrings);
2548 COMCTL32_Free (oldStrings);
2551 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2552 infoPtr->nNumStrings++;
2563 TOOLBAR_AutoSize (HWND hwnd)
2565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2566 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2572 UINT uPosFlags = SWP_NOZORDER;
2574 TRACE("resize forced, style=%lx!\n", dwStyle);
2576 parent = GetParent (hwnd);
2577 GetClientRect(parent, &parent_rect);
2579 x = parent_rect.left;
2580 y = parent_rect.top;
2582 /* FIXME: we should be able to early out if nothing */
2583 /* has changed with nWidth != parent_rect width */
2585 if (dwStyle & CCS_NORESIZE) {
2586 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2589 TOOLBAR_CalcToolbar (hwnd);
2592 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2593 TOOLBAR_CalcToolbar (hwnd);
2594 InvalidateRect( hwnd, NULL, TRUE );
2595 cy = infoPtr->nHeight;
2596 cx = infoPtr->nWidth;
2598 if (dwStyle & CCS_NOMOVEY) {
2599 GetWindowRect(hwnd, &window_rect);
2600 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2601 y = window_rect.top;
2605 if (dwStyle & CCS_NOPARENTALIGN)
2606 uPosFlags |= SWP_NOMOVE;
2608 if (!(dwStyle & CCS_NODIVIDER))
2609 cy += GetSystemMetrics(SM_CYEDGE);
2611 if (dwStyle & WS_BORDER)
2614 cy += GetSystemMetrics(SM_CYEDGE);
2615 cx += GetSystemMetrics(SM_CYEDGE);
2618 infoPtr->bAutoSize = TRUE;
2619 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2621 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2622 * the setwindowpos calls */
2623 infoPtr->bAutoSize = FALSE;
2630 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2632 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2634 return infoPtr->nNumButtons;
2639 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2641 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2643 if (infoPtr == NULL) {
2644 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2645 ERR("infoPtr == NULL!\n");
2649 infoPtr->dwStructSize = (DWORD)wParam;
2656 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2659 TBUTTON_INFO *btnPtr;
2662 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2666 btnPtr = &infoPtr->buttons[nIndex];
2667 btnPtr->iBitmap = LOWORD(lParam);
2669 /* we HAVE to erase the background, the new bitmap could be */
2671 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2678 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2681 TBUTTON_INFO *btnPtr;
2684 BOOL bChecked = FALSE;
2686 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2690 btnPtr = &infoPtr->buttons[nIndex];
2692 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2695 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2697 if (LOWORD(lParam) == FALSE)
2698 btnPtr->fsState &= ~TBSTATE_CHECKED;
2700 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2702 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2703 if (nOldIndex == nIndex)
2705 if (nOldIndex != -1)
2706 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2708 btnPtr->fsState |= TBSTATE_CHECKED;
2711 if( bChecked != LOWORD(lParam) )
2713 if (nOldIndex != -1)
2715 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2716 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2718 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2721 /* FIXME: Send a WM_NOTIFY?? */
2728 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2737 TOOLBAR_Customize (HWND hwnd)
2739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2740 CUSTDLG_INFO custInfo;
2746 custInfo.tbInfo = infoPtr;
2747 custInfo.tbHwnd = hwnd;
2749 /* send TBN_BEGINADJUST notification */
2750 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2753 if (!(hRes = FindResourceA (COMCTL32_hModule,
2754 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2758 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2761 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2762 (LPDLGTEMPLATEA)template,
2764 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2767 /* send TBN_ENDADJUST notification */
2768 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2776 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2778 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2779 INT nIndex = (INT)wParam;
2781 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2784 if ((infoPtr->hwndToolTip) &&
2785 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2788 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2789 ti.cbSize = sizeof (TTTOOLINFOA);
2791 ti.uId = infoPtr->buttons[nIndex].idCommand;
2793 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2796 if (infoPtr->nNumButtons == 1) {
2797 TRACE(" simple delete!\n");
2798 COMCTL32_Free (infoPtr->buttons);
2799 infoPtr->buttons = NULL;
2800 infoPtr->nNumButtons = 0;
2803 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2804 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2806 infoPtr->nNumButtons--;
2807 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2809 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2810 nIndex * sizeof(TBUTTON_INFO));
2813 if (nIndex < infoPtr->nNumButtons) {
2814 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2815 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2818 COMCTL32_Free (oldButtons);
2821 TOOLBAR_CalcToolbar (hwnd);
2823 InvalidateRect (hwnd, NULL, TRUE);
2830 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2833 TBUTTON_INFO *btnPtr;
2837 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2841 btnPtr = &infoPtr->buttons[nIndex];
2843 bState = btnPtr->fsState & TBSTATE_ENABLED;
2845 /* update the toolbar button state */
2846 if(LOWORD(lParam) == FALSE) {
2847 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2849 btnPtr->fsState |= TBSTATE_ENABLED;
2852 /* redraw the button only if the state of the button changed */
2853 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2855 InvalidateRect(hwnd, &btnPtr->rect,
2856 TOOLBAR_HasText(infoPtr, btnPtr));
2863 static inline LRESULT
2864 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2868 return infoPtr->bAnchor;
2873 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2878 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2882 return infoPtr->buttons[nIndex].iBitmap;
2886 static inline LRESULT
2887 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2889 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2894 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2897 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2898 INT nIndex = (INT)wParam;
2899 TBUTTON_INFO *btnPtr;
2901 if (infoPtr == NULL)
2907 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2910 btnPtr = &infoPtr->buttons[nIndex];
2911 lpTbb->iBitmap = btnPtr->iBitmap;
2912 lpTbb->idCommand = btnPtr->idCommand;
2913 lpTbb->fsState = btnPtr->fsState;
2914 lpTbb->fsStyle = btnPtr->fsStyle;
2915 lpTbb->dwData = btnPtr->dwData;
2916 lpTbb->iString = btnPtr->iString;
2923 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2925 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2926 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2927 TBUTTON_INFO *btnPtr;
2930 if (infoPtr == NULL)
2932 if (lpTbInfo == NULL)
2934 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2937 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2938 lpTbInfo->dwMask & 0x80000000);
2942 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
2944 if (lpTbInfo->dwMask & TBIF_COMMAND)
2945 lpTbInfo->idCommand = btnPtr->idCommand;
2946 if (lpTbInfo->dwMask & TBIF_IMAGE)
2947 lpTbInfo->iImage = btnPtr->iBitmap;
2948 if (lpTbInfo->dwMask & TBIF_LPARAM)
2949 lpTbInfo->lParam = btnPtr->dwData;
2950 if (lpTbInfo->dwMask & TBIF_SIZE)
2951 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2952 if (lpTbInfo->dwMask & TBIF_STATE)
2953 lpTbInfo->fsState = btnPtr->fsState;
2954 if (lpTbInfo->dwMask & TBIF_STYLE)
2955 lpTbInfo->fsStyle = btnPtr->fsStyle;
2956 if (lpTbInfo->dwMask & TBIF_TEXT) {
2957 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2958 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
2965 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2967 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2968 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2969 TBUTTON_INFO *btnPtr;
2972 if (infoPtr == NULL)
2974 if (lpTbInfo == NULL)
2976 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2979 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2980 lpTbInfo->dwMask & 0x80000000);
2984 btnPtr = &infoPtr->buttons[nIndex];
2986 if (lpTbInfo->dwMask & TBIF_COMMAND)
2987 lpTbInfo->idCommand = btnPtr->idCommand;
2988 if (lpTbInfo->dwMask & TBIF_IMAGE)
2989 lpTbInfo->iImage = btnPtr->iBitmap;
2990 if (lpTbInfo->dwMask & TBIF_LPARAM)
2991 lpTbInfo->lParam = btnPtr->dwData;
2992 if (lpTbInfo->dwMask & TBIF_SIZE)
2993 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2994 if (lpTbInfo->dwMask & TBIF_STATE)
2995 lpTbInfo->fsState = btnPtr->fsState;
2996 if (lpTbInfo->dwMask & TBIF_STYLE)
2997 lpTbInfo->fsStyle = btnPtr->fsStyle;
2998 if (lpTbInfo->dwMask & TBIF_TEXT) {
2999 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3000 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3008 TOOLBAR_GetButtonSize (HWND hwnd)
3010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3012 if (infoPtr->nNumButtons > 0)
3013 return MAKELONG((WORD)infoPtr->nButtonWidth,
3014 (WORD)infoPtr->nButtonHeight);
3016 return MAKELONG(8,7);
3021 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3030 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3034 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3036 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3037 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3042 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3051 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3055 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3057 strcpyW ((LPWSTR)lParam, lpText);
3059 return strlenW (lpText);
3064 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3066 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3068 return (LRESULT)infoPtr->himlDis;
3072 inline static LRESULT
3073 TOOLBAR_GetExtendedStyle (HWND hwnd)
3075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3077 return infoPtr->dwExStyle;
3082 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3086 return (LRESULT)infoPtr->himlHot;
3091 TOOLBAR_GetHotItem (HWND hwnd)
3093 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3095 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3098 if (infoPtr->nHotItem < 0)
3101 return (LRESULT)infoPtr->nHotItem;
3106 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3108 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3110 return (LRESULT)infoPtr->himlDef;
3114 /* << TOOLBAR_GetInsertMark >> */
3115 /* << TOOLBAR_GetInsertMarkColor >> */
3119 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3121 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3122 TBUTTON_INFO *btnPtr;
3126 if (infoPtr == NULL)
3128 nIndex = (INT)wParam;
3129 btnPtr = &infoPtr->buttons[nIndex];
3130 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3132 lpRect = (LPRECT)lParam;
3135 if (btnPtr->fsState & TBSTATE_HIDDEN)
3138 lpRect->left = btnPtr->rect.left;
3139 lpRect->right = btnPtr->rect.right;
3140 lpRect->bottom = btnPtr->rect.bottom;
3141 lpRect->top = btnPtr->rect.top;
3148 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3150 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3151 LPSIZE lpSize = (LPSIZE)lParam;
3156 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3157 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3159 TRACE("maximum size %d x %d\n",
3160 infoPtr->rcBound.right - infoPtr->rcBound.left,
3161 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3167 /* << TOOLBAR_GetObject >> */
3171 TOOLBAR_GetPadding (HWND hwnd)
3173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3176 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3177 return (LRESULT) oldPad;
3182 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3184 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3185 TBUTTON_INFO *btnPtr;
3189 if (infoPtr == NULL)
3191 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3192 btnPtr = &infoPtr->buttons[nIndex];
3193 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3195 lpRect = (LPRECT)lParam;
3199 lpRect->left = btnPtr->rect.left;
3200 lpRect->right = btnPtr->rect.right;
3201 lpRect->bottom = btnPtr->rect.bottom;
3202 lpRect->top = btnPtr->rect.top;
3209 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3211 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3213 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3214 return infoPtr->nRows;
3221 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3223 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3226 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3230 return infoPtr->buttons[nIndex].fsState;
3235 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3240 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3244 return infoPtr->buttons[nIndex].fsStyle;
3249 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3251 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3253 if (infoPtr == NULL)
3256 return infoPtr->nMaxTextRows;
3261 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 if (infoPtr == NULL)
3267 return infoPtr->hwndToolTip;
3272 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3276 TRACE("%s hwnd=0x%x stub!\n",
3277 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3279 return infoPtr->bUnicode;
3283 inline static LRESULT
3284 TOOLBAR_GetVersion (HWND hwnd)
3286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3287 return infoPtr->iVersion;
3292 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3295 TBUTTON_INFO *btnPtr;
3300 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3304 btnPtr = &infoPtr->buttons[nIndex];
3305 if (LOWORD(lParam) == FALSE)
3306 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3308 btnPtr->fsState |= TBSTATE_HIDDEN;
3310 TOOLBAR_CalcToolbar (hwnd);
3312 InvalidateRect (hwnd, NULL, TRUE);
3318 inline static LRESULT
3319 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3321 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3326 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3329 TBUTTON_INFO *btnPtr;
3332 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3336 btnPtr = &infoPtr->buttons[nIndex];
3337 if (LOWORD(lParam) == FALSE)
3338 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3340 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3342 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3349 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3352 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3353 INT nIndex = (INT)wParam;
3354 TBUTTON_INFO *oldButtons;
3359 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3362 /* EPP: this seems to be an undocumented call (from my IE4)
3363 * I assume in that case that:
3364 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3365 * - index of insertion is at the end of existing buttons
3366 * I only see this happen with nIndex == -1, but it could have a special
3367 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3369 nIndex = infoPtr->nNumButtons;
3371 } else if (nIndex < 0)
3374 /* If the string passed is not an index, assume address of string
3375 and do our own AddString */
3376 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3380 TRACE("string %s passed instead of index, adding string\n",
3381 debugstr_a((LPSTR)lpTbb->iString));
3382 len = strlen((LPSTR)lpTbb->iString) + 2;
3383 ptr = COMCTL32_Alloc(len);
3384 strcpy(ptr, (LPSTR)lpTbb->iString);
3385 ptr[len - 1] = 0; /* ended by two '\0' */
3386 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3390 TRACE("inserting button index=%d\n", nIndex);
3391 if (nIndex > infoPtr->nNumButtons) {
3392 nIndex = infoPtr->nNumButtons;
3393 TRACE("adjust index=%d\n", nIndex);
3396 oldButtons = infoPtr->buttons;
3397 infoPtr->nNumButtons++;
3398 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3399 /* pre insert copy */
3401 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3402 nIndex * sizeof(TBUTTON_INFO));
3405 /* insert new button */
3406 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3407 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3408 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3409 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3410 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3411 /* if passed string and not index, then add string */
3412 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3413 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3416 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3418 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3421 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3422 ti.cbSize = sizeof (TTTOOLINFOA);
3424 ti.uId = lpTbb->idCommand;
3426 ti.lpszText = LPSTR_TEXTCALLBACKA;
3428 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3432 /* post insert copy */
3433 if (nIndex < infoPtr->nNumButtons - 1) {
3434 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3435 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3438 COMCTL32_Free (oldButtons);
3440 TOOLBAR_CalcToolbar (hwnd);
3442 InvalidateRect (hwnd, NULL, TRUE);
3449 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3451 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3452 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3453 INT nIndex = (INT)wParam;
3454 TBUTTON_INFO *oldButtons;
3459 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3462 /* EPP: this seems to be an undocumented call (from my IE4)
3463 * I assume in that case that:
3464 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3465 * - index of insertion is at the end of existing buttons
3466 * I only see this happen with nIndex == -1, but it could have a special
3467 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3469 nIndex = infoPtr->nNumButtons;
3471 } else if (nIndex < 0)
3474 /* If the string passed is not an index, assume address of string
3475 and do our own AddString */
3476 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3480 TRACE("string %s passed instead of index, adding string\n",
3481 debugstr_w((LPWSTR)lpTbb->iString));
3482 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3483 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3484 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3485 ptr[len - 1] = 0; /* ended by two '\0' */
3486 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3490 TRACE("inserting button index=%d\n", nIndex);
3491 if (nIndex > infoPtr->nNumButtons) {
3492 nIndex = infoPtr->nNumButtons;
3493 TRACE("adjust index=%d\n", nIndex);
3496 oldButtons = infoPtr->buttons;
3497 infoPtr->nNumButtons++;
3498 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3499 /* pre insert copy */
3501 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3502 nIndex * sizeof(TBUTTON_INFO));
3505 /* insert new button */
3506 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3507 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3508 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3509 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3510 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3511 /* if passed string and not index, then add string */
3512 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3513 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3516 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3518 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3521 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3522 ti.cbSize = sizeof (TTTOOLINFOW);
3524 ti.uId = lpTbb->idCommand;
3526 ti.lpszText = LPSTR_TEXTCALLBACKW;
3528 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3532 /* post insert copy */
3533 if (nIndex < infoPtr->nNumButtons - 1) {
3534 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3535 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3538 COMCTL32_Free (oldButtons);
3540 TOOLBAR_CalcToolbar (hwnd);
3542 InvalidateRect (hwnd, NULL, TRUE);
3548 /* << TOOLBAR_InsertMarkHitTest >> */
3552 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3554 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3557 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3561 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3566 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3568 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3571 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3575 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3580 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3585 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3589 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3594 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3596 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3599 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3603 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3608 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3613 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3617 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3622 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3624 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3627 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3631 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3635 /* << TOOLBAR_LoadImages >> */
3636 /* << TOOLBAR_MapAccelerator >> */
3637 /* << TOOLBAR_MarkButton >> */
3638 /* << TOOLBAR_MoveButton >> */
3642 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3645 TBUTTON_INFO *btnPtr;
3648 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3652 btnPtr = &infoPtr->buttons[nIndex];
3653 if (LOWORD(lParam) == FALSE)
3654 btnPtr->fsState &= ~TBSTATE_PRESSED;
3656 btnPtr->fsState |= TBSTATE_PRESSED;
3658 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3665 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3668 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3670 int i = 0, nOldButtons = 0, pos = 0;
3672 TRACE("hInstOld %x nIDOld %x hInstNew %x nIDNew %x nButtons %x\n",
3673 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3674 lpReplace->nButtons);
3676 if (lpReplace->hInstOld == -1)
3678 FIXME("changing standard bitmaps not implemented\n");
3681 else if (lpReplace->hInstOld != 0)
3683 FIXME("resources not in the current module not implemented\n");
3688 hBitmap = (HBITMAP) lpReplace->nIDNew;
3691 TRACE("To be replaced hInstOld %x nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3692 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3693 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3694 TRACE("tbimapinfo %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3695 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3697 TRACE("Found: nButtons %d hInst %x nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3698 nOldButtons = tbi->nButtons;
3699 tbi->nButtons = lpReplace->nButtons;
3700 tbi->hInst = lpReplace->hInstNew;
3701 tbi->nID = lpReplace->nIDNew;
3702 TRACE("tbimapinfo changed %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3705 pos += tbi->nButtons;
3708 if (nOldButtons == 0)
3710 WARN("No hinst/bitmap found! hInst %x nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3714 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
3716 /* ImageList_Replace(infoPtr->himlDef, pos, hBitmap, NULL); */
3719 for (i = pos + nOldButtons - 1; i >= pos; i--) {
3720 ImageList_Remove(infoPtr->himlDef, i);
3723 ImageList_AddMasked(infoPtr->himlDef, hBitmap, CLR_DEFAULT);
3725 InvalidateRect(hwnd, NULL, FALSE);
3731 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3735 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3737 if (lpSave == NULL) return 0;
3740 /* save toolbar information */
3741 FIXME("save to \"%s\" \"%s\"\n",
3742 lpSave->pszSubKey, lpSave->pszValueName);
3747 /* restore toolbar information */
3749 FIXME("restore from \"%s\" \"%s\"\n",
3750 lpSave->pszSubKey, lpSave->pszValueName);
3761 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3764 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3765 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3771 /* save toolbar information */
3772 FIXME("save to \"%s\" \"%s\"\n",
3773 lpSave->pszSubKey, lpSave->pszValueName);
3778 /* restore toolbar information */
3780 FIXME("restore from \"%s\" \"%s\"\n",
3781 lpSave->pszSubKey, lpSave->pszValueName);
3792 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3794 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3795 BOOL bOldAnchor = infoPtr->bAnchor;
3797 infoPtr->bAnchor = (BOOL)wParam;
3799 return (LRESULT)bOldAnchor;
3804 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3806 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3808 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3811 if (infoPtr->nNumButtons > 0)
3812 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3813 infoPtr->nNumButtons,
3814 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3815 LOWORD(lParam), HIWORD(lParam));
3817 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3818 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3820 /* uses image list internals directly */
3821 if (infoPtr->himlDef) {
3822 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3823 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3831 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3834 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3835 TBUTTON_INFO *btnPtr;
3840 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3843 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3844 lptbbi->dwMask & 0x80000000);
3848 btnPtr = &infoPtr->buttons[nIndex];
3849 if (lptbbi->dwMask & TBIF_COMMAND)
3850 btnPtr->idCommand = lptbbi->idCommand;
3851 if (lptbbi->dwMask & TBIF_IMAGE)
3852 btnPtr->iBitmap = lptbbi->iImage;
3853 if (lptbbi->dwMask & TBIF_LPARAM)
3854 btnPtr->dwData = lptbbi->lParam;
3855 /* if (lptbbi->dwMask & TBIF_SIZE) */
3856 /* btnPtr->cx = lptbbi->cx; */
3857 if (lptbbi->dwMask & TBIF_STATE)
3858 btnPtr->fsState = lptbbi->fsState;
3859 if (lptbbi->dwMask & TBIF_STYLE)
3860 btnPtr->fsStyle = lptbbi->fsStyle;
3862 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3863 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3864 /* iString is index, zero it to make Str_SetPtr succeed */
3867 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3874 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3877 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3878 TBUTTON_INFO *btnPtr;
3883 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3886 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3887 lptbbi->dwMask & 0x80000000);
3891 btnPtr = &infoPtr->buttons[nIndex];
3892 if (lptbbi->dwMask & TBIF_COMMAND)
3893 btnPtr->idCommand = lptbbi->idCommand;
3894 if (lptbbi->dwMask & TBIF_IMAGE)
3895 btnPtr->iBitmap = lptbbi->iImage;
3896 if (lptbbi->dwMask & TBIF_LPARAM)
3897 btnPtr->dwData = lptbbi->lParam;
3898 /* if (lptbbi->dwMask & TBIF_SIZE) */
3899 /* btnPtr->cx = lptbbi->cx; */
3900 if (lptbbi->dwMask & TBIF_STATE)
3901 btnPtr->fsState = lptbbi->fsState;
3902 if (lptbbi->dwMask & TBIF_STYLE)
3903 btnPtr->fsStyle = lptbbi->fsStyle;
3905 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3906 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3907 /* iString is index, zero it to make Str_SetPtr succeed */
3909 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3916 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3918 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3919 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
3921 if ((cx < 0) || (cy < 0))
3923 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
3927 /* The documentation claims you can only change the button size before
3928 * any button has been added. But this is wrong.
3929 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3930 * it to the toolbar, and it checks that the return value is nonzero - mjm
3931 * Further testing shows that we must actually perform the change too.
3934 * The documentation also does not mention that if 0 is supplied for
3935 * either size, the system changes it to the default of 24 wide and
3936 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
3938 infoPtr->nButtonWidth = (cx) ? cx : 24;
3939 infoPtr->nButtonHeight = (cy) ? cy : 22;
3945 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3949 if (infoPtr == NULL) {
3950 TRACE("Toolbar not initialized yet?????\n");
3954 /* if setting to current values, ignore */
3955 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3956 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3957 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3958 infoPtr->cxMin, infoPtr->cxMax);
3962 /* save new values */
3963 infoPtr->cxMin = (INT)LOWORD(lParam);
3964 infoPtr->cxMax = (INT)HIWORD(lParam);
3966 /* if both values are 0 then we are done */
3968 TRACE("setting both min and max to 0, norecalc\n");
3972 /* otherwise we need to recalc the toolbar and in some cases
3973 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3974 which doesn't actually draw - GA). */
3975 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3976 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3978 TOOLBAR_CalcToolbar (hwnd);
3980 InvalidateRect (hwnd, NULL, TRUE);
3987 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3989 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3990 INT nIndex = (INT)wParam;
3992 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3995 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3997 if (infoPtr->hwndToolTip) {
3999 FIXME("change tool tip!\n");
4008 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4011 HIMAGELIST himlTemp;
4015 FIXME("no support for multiple image lists\n");
4019 himlTemp = infoPtr->himlDis;
4020 infoPtr->himlDis = (HIMAGELIST)lParam;
4022 /* FIXME: redraw ? */
4024 return (LRESULT)himlTemp;
4029 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4031 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4034 dwTemp = infoPtr->dwDTFlags;
4035 infoPtr->dwDTFlags =
4036 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4038 return (LRESULT)dwTemp;
4042 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4044 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4047 dwTemp = infoPtr->dwExStyle;
4048 infoPtr->dwExStyle = (DWORD)lParam;
4050 if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
4051 TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
4052 FIXME("Extended style not implemented %s %s\n",
4053 (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
4054 "TBSTYLE_EX_MIXEDBUTTONS" : "",
4055 (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
4056 "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
4059 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4060 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4061 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4063 return (LRESULT)dwTemp;
4068 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4071 HIMAGELIST himlTemp;
4074 FIXME("no support for multiple image lists\n");
4078 himlTemp = infoPtr->himlHot;
4079 infoPtr->himlHot = (HIMAGELIST)lParam;
4081 /* FIXME: redraw ? */
4083 return (LRESULT)himlTemp;
4088 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4091 INT nOldHotItem = infoPtr->nHotItem;
4092 TBUTTON_INFO *btnPtr;
4094 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4097 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4100 infoPtr->nHotItem = (INT)wParam;
4101 if ((INT)wParam >=0)
4103 btnPtr = &infoPtr->buttons[(INT)wParam];
4104 btnPtr->bHot = TRUE;
4105 InvalidateRect (hwnd, &btnPtr->rect,
4106 TOOLBAR_HasText(infoPtr, btnPtr));
4110 btnPtr = &infoPtr->buttons[nOldHotItem];
4111 btnPtr->bHot = FALSE;
4112 InvalidateRect (hwnd, &btnPtr->rect,
4113 TOOLBAR_HasText(infoPtr, btnPtr));
4117 if (nOldHotItem < 0)
4120 return (LRESULT)nOldHotItem;
4125 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4127 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4128 HIMAGELIST himlTemp;
4131 FIXME("no support for multiple image lists\n");
4135 himlTemp = infoPtr->himlDef;
4136 infoPtr->himlDef = (HIMAGELIST)lParam;
4138 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
4140 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
4141 &infoPtr->nBitmapHeight);
4142 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4143 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4144 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4146 /* FIXME: redraw ? */
4147 InvalidateRect(hwnd, NULL, TRUE);
4149 return (LRESULT)himlTemp;
4154 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4156 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4158 infoPtr->nIndent = (INT)wParam;
4162 /* process only on indent changing */
4163 if(infoPtr->nIndent != (INT)wParam)
4165 infoPtr->nIndent = (INT)wParam;
4166 TOOLBAR_CalcToolbar (hwnd);
4167 InvalidateRect(hwnd, NULL, FALSE);
4174 /* << TOOLBAR_SetInsertMark >> */
4178 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4182 infoPtr->clrInsertMark = (COLORREF)lParam;
4184 /* FIXME : redraw ??*/
4191 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4195 if (infoPtr == NULL)
4198 infoPtr->nMaxTextRows = (INT)wParam;
4205 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4210 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4211 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4212 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4213 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4214 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4215 return (LRESULT) oldPad;
4220 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4227 if (infoPtr == NULL)
4229 hwndOldNotify = infoPtr->hwndNotify;
4230 infoPtr->hwndNotify = (HWND)wParam;
4232 return hwndOldNotify;
4237 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4240 LPRECT lprc = (LPRECT)lParam;
4244 if (LOWORD(wParam) > 1) {
4245 FIXME("multiple rows not supported!\n");
4248 if(infoPtr->nRows != LOWORD(wParam))
4250 infoPtr->nRows = LOWORD(wParam);
4252 /* recalculate toolbar */
4253 TOOLBAR_CalcToolbar (hwnd);
4255 /* repaint toolbar */
4256 InvalidateRect(hwnd, NULL, FALSE);
4259 /* return bounding rectangle */
4261 lprc->left = infoPtr->rcBound.left;
4262 lprc->right = infoPtr->rcBound.right;
4263 lprc->top = infoPtr->rcBound.top;
4264 lprc->bottom = infoPtr->rcBound.bottom;
4272 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4275 TBUTTON_INFO *btnPtr;
4278 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4282 btnPtr = &infoPtr->buttons[nIndex];
4284 /* if hidden state has changed the invalidate entire window and recalc */
4285 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4286 btnPtr->fsState = LOWORD(lParam);
4287 TOOLBAR_CalcToolbar (hwnd);
4288 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4292 /* process state changing if current state doesn't match new state */
4293 if(btnPtr->fsState != LOWORD(lParam))
4295 btnPtr->fsState = LOWORD(lParam);
4296 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4305 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4307 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4308 TBUTTON_INFO *btnPtr;
4311 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4315 btnPtr = &infoPtr->buttons[nIndex];
4317 /* process style change if current style doesn't match new style */
4318 if(btnPtr->fsStyle != LOWORD(lParam))
4320 btnPtr->fsStyle = LOWORD(lParam);
4321 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4324 if (infoPtr->hwndToolTip) {
4325 FIXME("change tool tip!\n");
4333 inline static LRESULT
4334 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4336 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4338 if (infoPtr == NULL)
4340 infoPtr->hwndToolTip = (HWND)wParam;
4346 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4348 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4351 TRACE("%s hwnd=0x%04x stub!\n",
4352 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4354 bTemp = infoPtr->bUnicode;
4355 infoPtr->bUnicode = (BOOL)wParam;
4362 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4364 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4366 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4367 comctl32_color.clrBtnHighlight :
4368 infoPtr->clrBtnHighlight;
4369 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4370 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4376 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4380 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4381 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4382 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4384 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4385 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4386 InvalidateRect(hwnd, 0, 0);
4392 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4394 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4395 INT iOldVersion = infoPtr->iVersion;
4397 infoPtr->iVersion = iVersion;
4403 /*********************************************************************/
4405 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4406 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4407 /* based on relay traces of the native control and IE 5.5 */
4409 /*********************************************************************/
4411 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4413 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4414 INT nOldHotItem = infoPtr->nHotItem;
4415 TBUTTON_INFO *btnPtr;
4417 NMTBHOTITEM nmhotitem;
4419 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4422 infoPtr->nHotItem = (INT)wParam;
4423 if (nOldHotItem != infoPtr->nHotItem) {
4424 nmhotitem.dwFlags = (DWORD)lParam;
4425 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4426 nmhotitem.idOld = (nOldHotItem >= 0) ?
4427 infoPtr->buttons[nOldHotItem].idCommand : 0;
4428 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4429 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4430 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4431 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4433 if ((INT)wParam >=0) {
4434 btnPtr = &infoPtr->buttons[(INT)wParam];
4435 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4436 InvalidateRect (hwnd, &btnPtr->rect,
4437 TOOLBAR_HasText(infoPtr, btnPtr));
4439 if (nOldHotItem>=0) {
4440 btnPtr = &infoPtr->buttons[nOldHotItem];
4441 btnPtr->bHot = FALSE;
4442 InvalidateRect (hwnd, &btnPtr->rect,
4443 TOOLBAR_HasText(infoPtr, btnPtr));
4446 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4447 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4449 if (nOldHotItem < 0)
4452 return (LRESULT)nOldHotItem;
4457 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4459 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4460 LPSIZE lpsize = (LPSIZE)lParam;
4466 * Testing shows the following:
4467 * wParam = 0 adjust cx value
4468 * = 1 set cy value to max size.
4469 * lParam pointer to SIZE structure
4472 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4473 wParam, lParam, lpsize->cx, lpsize->cy);
4477 if (lpsize->cx == -1) {
4478 /* **** this is wrong, native measures each button and sets it */
4479 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4481 else if(HIWORD(lpsize->cx)) {
4483 HWND hwndParent = GetParent(hwnd);
4485 InvalidateRect(hwnd, 0, 1);
4486 GetWindowRect(hwnd, &rc);
4487 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4488 TRACE("mapped to (%d,%d)-(%d,%d)\n",
4489 rc.left, rc.top, rc.right, rc.bottom);
4490 lpsize->cx = max(rc.right-rc.left,
4491 infoPtr->rcBound.right - infoPtr->rcBound.left);
4494 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4498 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4499 /* lpsize->cy = infoPtr->nHeight; */
4502 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4506 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4507 lpsize->cx, lpsize->cy);
4513 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4515 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4516 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4519 /* initialize info structure */
4520 infoPtr->nButtonHeight = 22;
4521 infoPtr->nButtonWidth = 24;
4522 infoPtr->nBitmapHeight = 15;
4523 infoPtr->nBitmapWidth = 16;
4525 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4527 infoPtr->nMaxTextRows = 1;
4528 infoPtr->cxMin = -1;
4529 infoPtr->cxMax = -1;
4530 infoPtr->nNumBitmaps = 0;
4531 infoPtr->nNumStrings = 0;
4533 infoPtr->bCaptured = FALSE;
4534 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4535 infoPtr->nButtonDown = -1;
4536 infoPtr->nOldHit = -1;
4537 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4538 infoPtr->hwndNotify = GetParent (hwnd);
4539 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4540 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4541 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4542 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4543 infoPtr->iVersion = 0;
4544 infoPtr->hwndSelf = hwnd;
4545 infoPtr->bDoRedraw = TRUE;
4546 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4547 infoPtr->clrBtnShadow = CLR_DEFAULT;
4548 infoPtr->szPadding.cx = 7;
4549 infoPtr->szPadding.cy = 6;
4550 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4552 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4553 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4555 if (dwStyle & TBSTYLE_TOOLTIPS) {
4556 /* Create tooltip control */
4557 infoPtr->hwndToolTip =
4558 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4559 CW_USEDEFAULT, CW_USEDEFAULT,
4560 CW_USEDEFAULT, CW_USEDEFAULT,
4563 /* Send NM_TOOLTIPSCREATED notification */
4564 if (infoPtr->hwndToolTip) {
4565 NMTOOLTIPSCREATED nmttc;
4567 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4569 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4570 NM_TOOLTIPSCREATED);
4574 TOOLBAR_CheckStyle (hwnd, dwStyle);
4576 TOOLBAR_CalcToolbar(hwnd);
4583 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4585 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4587 /* delete tooltip control */
4588 if (infoPtr->hwndToolTip)
4589 DestroyWindow (infoPtr->hwndToolTip);
4591 /* delete button data */
4592 if (infoPtr->buttons)
4593 COMCTL32_Free (infoPtr->buttons);
4595 /* delete strings */
4596 if (infoPtr->strings) {
4598 for (i = 0; i < infoPtr->nNumStrings; i++)
4599 if (infoPtr->strings[i])
4600 COMCTL32_Free (infoPtr->strings[i]);
4602 COMCTL32_Free (infoPtr->strings);
4605 /* destroy internal image list */
4606 if (infoPtr->himlInt)
4607 ImageList_Destroy (infoPtr->himlInt);
4609 /* delete default font */
4611 DeleteObject (infoPtr->hDefaultFont);
4613 /* free toolbar info data */
4614 COMCTL32_Free (infoPtr);
4615 SetWindowLongA (hwnd, 0, 0);
4622 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4624 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4625 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4626 NMTBCUSTOMDRAW tbcd;
4630 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4631 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4632 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4633 tbcd.nmcd.hdc = (HDC)wParam;
4634 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4635 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4637 /* FIXME: in general the return flags *can* be or'ed together */
4638 switch (infoPtr->dwBaseCustDraw)
4640 case CDRF_DODEFAULT:
4642 case CDRF_SKIPDEFAULT:
4645 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4650 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4651 * to my parent for processing.
4653 if (infoPtr->bTransparent) {
4655 HDC hdc = (HDC)wParam;
4660 parent = GetParent(hwnd);
4661 MapWindowPoints(hwnd, parent, &pt, 1);
4662 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4663 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4664 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4667 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4669 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
4670 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
4671 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4672 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4673 tbcd.nmcd.hdc = (HDC)wParam;
4674 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4675 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4676 switch (infoPtr->dwBaseCustDraw)
4678 case CDRF_DODEFAULT:
4680 case CDRF_SKIPDEFAULT:
4683 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4692 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4696 return infoPtr->hFont;
4701 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4703 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4704 TBUTTON_INFO *btnPtr;
4708 pt.x = (INT)LOWORD(lParam);
4709 pt.y = (INT)HIWORD(lParam);
4710 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4713 btnPtr = &infoPtr->buttons[nHit];
4714 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4717 infoPtr->bCaptured = TRUE;
4718 infoPtr->nButtonDown = nHit;
4720 btnPtr->fsState |= TBSTATE_PRESSED;
4722 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4725 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4726 TOOLBAR_Customize (hwnd);
4733 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4735 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4736 TBUTTON_INFO *btnPtr;
4741 if (infoPtr->hwndToolTip)
4742 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4743 WM_LBUTTONDOWN, wParam, lParam);
4745 pt.x = (INT)LOWORD(lParam);
4746 pt.y = (INT)HIWORD(lParam);
4747 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4751 btnPtr = &infoPtr->buttons[nHit];
4752 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4755 infoPtr->nOldHit = nHit;
4757 CopyRect(&arrowRect, &btnPtr->rect);
4758 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4760 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4761 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4762 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4763 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4767 * this time we must force a Redraw, so the btn is
4768 * painted down before CaptureChanged repaints it up
4770 RedrawWindow(hwnd,&btnPtr->rect,0,
4771 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4773 nmtb.iItem = btnPtr->idCommand;
4774 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4777 memset(&nmtb.rcButton, 0, sizeof(RECT));
4778 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4780 if (res != TBDDRET_TREATPRESSED)
4781 /* ??? guess (GA) */
4783 /* otherwise drop through and process as pushed */
4785 /* SetCapture (hwnd); */
4786 infoPtr->bCaptured = TRUE;
4787 infoPtr->nButtonDown = nHit;
4789 btnPtr->fsState |= TBSTATE_PRESSED;
4790 btnPtr->bHot = FALSE;
4792 InvalidateRect(hwnd, &btnPtr->rect,
4793 TOOLBAR_HasText(infoPtr, btnPtr));
4797 /* native issues the TBN_BEGINDRAG here */
4798 nmtb.iItem = btnPtr->idCommand;
4799 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4800 nmtb.tbButton.idCommand = btnPtr->idCommand;
4801 nmtb.tbButton.fsState = btnPtr->fsState;
4802 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4803 nmtb.tbButton.dwData = btnPtr->dwData;
4804 nmtb.tbButton.iString = btnPtr->iString;
4805 nmtb.cchText = 0; /* !!! not correct */
4806 nmtb.pszText = 0; /* !!! not correct */
4807 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4815 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4817 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4818 TBUTTON_INFO *btnPtr;
4822 BOOL bSendMessage = TRUE;
4827 if (infoPtr->hwndToolTip)
4828 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4829 WM_LBUTTONUP, wParam, lParam);
4831 pt.x = (INT)LOWORD(lParam);
4832 pt.y = (INT)HIWORD(lParam);
4833 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4835 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4836 /* if the cursor is still inside of the toolbar */
4837 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4838 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4840 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4841 btnPtr->fsState &= ~TBSTATE_PRESSED;
4843 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4844 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4845 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4847 if (nOldIndex == nHit)
4848 bSendMessage = FALSE;
4849 if ((nOldIndex != nHit) &&
4851 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4852 btnPtr->fsState |= TBSTATE_CHECKED;
4855 if (btnPtr->fsState & TBSTATE_CHECKED)
4856 btnPtr->fsState &= ~TBSTATE_CHECKED;
4858 btnPtr->fsState |= TBSTATE_CHECKED;
4862 if (nOldIndex != -1)
4864 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4865 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4869 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4870 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4871 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4873 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
4876 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4877 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4878 NM_RELEASEDCAPTURE);
4880 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4883 nmtb.iItem = btnPtr->idCommand;
4884 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4885 nmtb.tbButton.idCommand = btnPtr->idCommand;
4886 nmtb.tbButton.fsState = btnPtr->fsState;
4887 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4888 nmtb.tbButton.dwData = btnPtr->dwData;
4889 nmtb.tbButton.iString = btnPtr->iString;
4890 nmtb.cchText = 0; /* !!! not correct */
4891 nmtb.pszText = 0; /* !!! not correct */
4892 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4895 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4896 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
4898 /* !!! Undocumented - toolbar at 4.71 level and above sends
4899 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4900 * Only NM_RCLICK is documented.
4902 nmmouse.dwItemSpec = btnPtr->idCommand;
4903 nmmouse.dwItemData = btnPtr->dwData;
4904 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4910 TOOLBAR_CaptureChanged(HWND hwnd)
4912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4913 TBUTTON_INFO *btnPtr;
4915 infoPtr->bCaptured = FALSE;
4917 if (infoPtr->nButtonDown >= 0)
4919 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4920 btnPtr->fsState &= ~TBSTATE_PRESSED;
4922 infoPtr->nButtonDown = -1;
4923 infoPtr->nOldHit = -1;
4925 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4932 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4934 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4935 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4938 if (infoPtr->nOldHit < 0)
4941 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4943 /* Redraw the button if the last button we were over is the hot button and it
4945 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4947 hotBtnPtr->bHot = FALSE;
4948 rc1 = hotBtnPtr->rect;
4949 InflateRect (&rc1, 1, 1);
4950 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4954 /* If the last button we were over is depressed then make it not */
4955 /* depressed and redraw it */
4956 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4958 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4960 btnPtr->fsState &= ~TBSTATE_PRESSED;
4962 rc1 = hotBtnPtr->rect;
4963 InflateRect (&rc1, 1, 1);
4964 InvalidateRect (hwnd, &rc1, TRUE);
4967 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4968 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4974 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4976 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4980 TRACKMOUSEEVENT trackinfo;
4981 NMTBHOTITEM nmhotitem;
4983 /* fill in the TRACKMOUSEEVENT struct */
4984 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4985 trackinfo.dwFlags = TME_QUERY;
4986 trackinfo.hwndTrack = hwnd;
4987 trackinfo.dwHoverTime = HOVER_DEFAULT;
4989 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4990 _TrackMouseEvent(&trackinfo);
4992 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4993 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4994 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4996 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4997 /* and can properly deactivate the hot toolbar button */
4998 _TrackMouseEvent(&trackinfo);
5001 if (infoPtr->hwndToolTip)
5002 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5003 WM_MOUSEMOVE, wParam, lParam);
5005 pt.x = (INT)LOWORD(lParam);
5006 pt.y = (INT)HIWORD(lParam);
5008 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5010 if (infoPtr->nOldHit != nHit)
5012 /* Remove the effect of an old hot button if the button was enabled and was
5013 drawn with the hot button effect */
5014 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
5015 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
5017 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5018 oldBtnPtr->bHot = FALSE;
5021 /* It's not a separator or in nowhere. It's a hot button. */
5024 btnPtr = &infoPtr->buttons[nHit];
5026 infoPtr->nHotItem = nHit;
5028 /* only enabled buttons show hot effect */
5029 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
5031 btnPtr->bHot = TRUE;
5035 nmhotitem.dwFlags = HICF_MOUSE;
5037 nmhotitem.idOld = oldBtnPtr->idCommand;
5039 nmhotitem.dwFlags |= HICF_ENTERING;
5041 nmhotitem.idNew = btnPtr->idCommand;
5043 nmhotitem.dwFlags |= HICF_LEAVING;
5044 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5046 /* now invalidate the old and new buttons so they will be painted */
5048 InvalidateRect (hwnd, &oldBtnPtr->rect,
5049 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5050 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
5051 InvalidateRect(hwnd, &btnPtr->rect,
5052 TOOLBAR_HasText(infoPtr, btnPtr));
5054 if (infoPtr->bCaptured) {
5055 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5056 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5057 btnPtr->fsState &= ~TBSTATE_PRESSED;
5058 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5060 else if (nHit == infoPtr->nButtonDown) {
5061 btnPtr->fsState |= TBSTATE_PRESSED;
5062 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5065 infoPtr->nOldHit = nHit;
5071 inline static LRESULT
5072 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5074 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5075 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5077 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5081 inline static LRESULT
5082 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5084 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5085 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5087 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5092 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5094 TOOLBAR_INFO *infoPtr;
5095 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5098 /* allocate memory for info structure */
5099 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
5100 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5103 infoPtr->dwStructSize = sizeof(TBBUTTON);
5105 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5106 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5107 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5108 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5111 /* native control does:
5112 * Get a lot of colors and brushes
5114 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5115 * CreateFontIndirectA(adr1)
5116 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5117 * hdc = GetDC(toolbar)
5118 * GetSystemMetrics(0x48)
5119 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5120 * 0, 0, 0, 0, "MARLETT")
5121 * oldfnt = SelectObject(hdc, fnt2)
5122 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5123 * GetTextMetricsA(hdc, adr3)
5124 * SelectObject(hdc, oldfnt)
5125 * DeleteObject(fnt2)
5127 * InvalidateRect(toolbar, 0, 1)
5128 * SetWindowLongA(toolbar, 0, addr)
5129 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5132 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5133 * ie 2 0x4600094c 0x4600094c 0x4600894d
5134 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5135 * rebar 0x50008844 0x40008844 0x50008845
5136 * pager 0x50000844 0x40000844 0x50008845
5137 * IC35mgr 0x5400084e **nochange**
5138 * on entry to _NCCREATE 0x5400084e
5139 * rowlist 0x5400004e **nochange**
5140 * on entry to _NCCREATE 0x5400004e
5144 /* I think the code below is a bug, but it is the way that the native
5145 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5146 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5147 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5148 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5149 * Some how, the only cases of this seem to be MFC programs.
5151 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5152 * does not occur in the WM_STYLECHANGING routine.
5153 * (Guy Albertelli 9/2001)
5156 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5157 styleadd |= TBSTYLE_TRANSPARENT;
5158 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5159 styleadd |= CCS_TOP; /* default to top */
5160 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5163 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5168 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5170 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5174 if (dwStyle & WS_MINIMIZE)
5175 return 0; /* Nothing to do */
5177 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5179 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5182 if (!(dwStyle & CCS_NODIVIDER))
5184 GetWindowRect (hwnd, &rcWindow);
5185 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5186 if( dwStyle & WS_BORDER )
5187 OffsetRect (&rcWindow, 1, 1);
5188 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5191 ReleaseDC( hwnd, hdc );
5197 inline static LRESULT
5198 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5200 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5201 LPNMHDR lpnmh = (LPNMHDR)lParam;
5203 if (lpnmh->code == PGN_CALCSIZE) {
5204 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5206 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5207 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5208 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5212 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5213 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5219 if (lpnmh->code == PGN_SCROLL) {
5220 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5222 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5223 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5224 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5225 lppgs->iScroll, lppgs->iDir);
5230 TRACE("passing WM_NOTIFY!\n");
5232 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5233 if (infoPtr->bNtfUnicode)
5234 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5237 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5241 if (lpnmh->code == TTN_GETDISPINFOA) {
5242 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5244 FIXME("retrieving ASCII string\n");
5247 else if (lpnmh->code == TTN_GETDISPINFOW) {
5248 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5250 FIXME("retrieving UNICODE string\n");
5261 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5263 /* remove this routine when Toolbar is improved to pass infoPtr
5264 * around instead of hwnd.
5266 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5267 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5272 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5276 if (lParam == NF_REQUERY) {
5277 i = SendMessageA(GetParent(infoPtr->hwndSelf),
5278 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
5279 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5280 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5284 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5287 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5292 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5298 /* fill ps.rcPaint with a default rect */
5299 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5301 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5303 TRACE("psrect=(%d,%d)-(%d,%d)\n",
5304 ps.rcPaint.left, ps.rcPaint.top,
5305 ps.rcPaint.right, ps.rcPaint.bottom);
5307 TOOLBAR_Refresh (hwnd, hdc, &ps);
5308 if (!wParam) EndPaint (hwnd, &ps);
5315 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5316 /*****************************************************
5319 * Handles the WM_SETREDRAW message.
5322 * According to testing V4.71 of COMCTL32 returns the
5323 * *previous* status of the redraw flag (either 0 or 1)
5324 * instead of the MSDN documented value of 0 if handled.
5325 * (For laughs see the "consistancy" with same function
5328 *****************************************************/
5330 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5331 BOOL oldredraw = infoPtr->bDoRedraw;
5333 TRACE("set to %s\n",
5334 (wParam) ? "TRUE" : "FALSE");
5335 infoPtr->bDoRedraw = (BOOL) wParam;
5337 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5339 return (oldredraw) ? 1 : 0;
5344 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5346 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5347 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5356 /* Resize deadlock check */
5357 if (infoPtr->bAutoSize) {
5358 infoPtr->bAutoSize = FALSE;
5362 /* FIXME: optimize to only update size if the new size doesn't */
5363 /* match the current size */
5365 flags = (INT) wParam;
5367 /* FIXME for flags =
5368 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5371 TRACE("sizing toolbar!\n");
5373 if (flags == SIZE_RESTORED) {
5374 /* width and height don't apply */
5375 parent = GetParent (hwnd);
5376 GetClientRect(parent, &parent_rect);
5377 x = parent_rect.left;
5378 y = parent_rect.top;
5380 if (dwStyle & CCS_NORESIZE) {
5381 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5384 * this sets the working width of the toolbar, and
5385 * Calc Toolbar will not adjust it, only the height
5387 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5388 cy = infoPtr->nHeight;
5389 cx = infoPtr->nWidth;
5390 TOOLBAR_CalcToolbar (hwnd);
5391 infoPtr->nWidth = cx;
5392 infoPtr->nHeight = cy;
5395 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5396 TOOLBAR_CalcToolbar (hwnd);
5397 cy = infoPtr->nHeight;
5398 cx = infoPtr->nWidth;
5400 if (dwStyle & CCS_NOMOVEY) {
5401 GetWindowRect(hwnd, &window_rect);
5402 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5403 y = window_rect.top;
5407 if (dwStyle & CCS_NOPARENTALIGN) {
5408 uPosFlags |= SWP_NOMOVE;
5409 cy = infoPtr->nHeight;
5410 cx = infoPtr->nWidth;
5413 if (!(dwStyle & CCS_NODIVIDER))
5414 cy += GetSystemMetrics(SM_CYEDGE);
5416 if (dwStyle & WS_BORDER)
5419 cy += GetSystemMetrics(SM_CYEDGE);
5420 cx += GetSystemMetrics(SM_CYEDGE);
5423 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
5424 cx, cy, uPosFlags | SWP_NOZORDER);
5431 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5435 if (nType == GWL_STYLE) {
5436 if (lpStyle->styleNew & TBSTYLE_LIST) {
5437 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5440 infoPtr->dwDTFlags = DT_CENTER;
5442 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5443 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5444 (TBSTYLE_FLAT | TBSTYLE_LIST));
5445 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5448 TOOLBAR_AutoSize (hwnd);
5450 InvalidateRect(hwnd, NULL, FALSE);
5457 TOOLBAR_SysColorChange (HWND hwnd)
5459 COMCTL32_RefreshSysColors();
5466 static LRESULT WINAPI
5467 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5469 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
5470 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5472 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5473 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5478 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5480 case TB_ADDBUTTONSA:
5481 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5483 case TB_ADDBUTTONSW:
5484 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5487 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5490 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5493 return TOOLBAR_AutoSize (hwnd);
5495 case TB_BUTTONCOUNT:
5496 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5498 case TB_BUTTONSTRUCTSIZE:
5499 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5501 case TB_CHANGEBITMAP:
5502 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5504 case TB_CHECKBUTTON:
5505 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5507 case TB_COMMANDTOINDEX:
5508 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5511 return TOOLBAR_Customize (hwnd);
5513 case TB_DELETEBUTTON:
5514 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5516 case TB_ENABLEBUTTON:
5517 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5519 case TB_GETANCHORHIGHLIGHT:
5520 return TOOLBAR_GetAnchorHighlight (hwnd);
5523 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5525 case TB_GETBITMAPFLAGS:
5526 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5529 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5531 case TB_GETBUTTONINFOA:
5532 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5534 case TB_GETBUTTONINFOW:
5535 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5537 case TB_GETBUTTONSIZE:
5538 return TOOLBAR_GetButtonSize (hwnd);
5540 case TB_GETBUTTONTEXTA:
5541 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5543 case TB_GETBUTTONTEXTW:
5544 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5546 case TB_GETDISABLEDIMAGELIST:
5547 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5549 case TB_GETEXTENDEDSTYLE:
5550 return TOOLBAR_GetExtendedStyle (hwnd);
5552 case TB_GETHOTIMAGELIST:
5553 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5556 return TOOLBAR_GetHotItem (hwnd);
5558 case TB_GETIMAGELIST:
5559 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
5561 /* case TB_GETINSERTMARK: */ /* 4.71 */
5562 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5564 case TB_GETITEMRECT:
5565 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5568 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5570 /* case TB_GETOBJECT: */ /* 4.71 */
5573 return TOOLBAR_GetPadding (hwnd);
5576 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5579 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5582 return TOOLBAR_GetState (hwnd, wParam, lParam);
5585 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5587 case TB_GETTEXTROWS:
5588 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5590 case TB_GETTOOLTIPS:
5591 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5593 case TB_GETUNICODEFORMAT:
5594 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5597 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5600 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5602 case TB_INDETERMINATE:
5603 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5605 case TB_INSERTBUTTONA:
5606 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5608 case TB_INSERTBUTTONW:
5609 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5611 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5613 case TB_ISBUTTONCHECKED:
5614 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5616 case TB_ISBUTTONENABLED:
5617 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5619 case TB_ISBUTTONHIDDEN:
5620 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5622 case TB_ISBUTTONHIGHLIGHTED:
5623 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5625 case TB_ISBUTTONINDETERMINATE:
5626 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5628 case TB_ISBUTTONPRESSED:
5629 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5631 case TB_LOADIMAGES: /* 4.70 */
5632 FIXME("missing standard imagelists\n");
5635 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5636 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5637 /* case TB_MARKBUTTON: */ /* 4.71 */
5638 /* case TB_MOVEBUTTON: */ /* 4.71 */
5640 case TB_PRESSBUTTON:
5641 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5643 case TB_REPLACEBITMAP:
5644 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
5646 case TB_SAVERESTOREA:
5647 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5649 case TB_SAVERESTOREW:
5650 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5652 case TB_SETANCHORHIGHLIGHT:
5653 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5655 case TB_SETBITMAPSIZE:
5656 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5658 case TB_SETBUTTONINFOA:
5659 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5661 case TB_SETBUTTONINFOW:
5662 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5664 case TB_SETBUTTONSIZE:
5665 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5667 case TB_SETBUTTONWIDTH:
5668 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5671 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5673 case TB_SETDISABLEDIMAGELIST:
5674 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5676 case TB_SETDRAWTEXTFLAGS:
5677 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5679 case TB_SETEXTENDEDSTYLE:
5680 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5682 case TB_SETHOTIMAGELIST:
5683 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5686 return TOOLBAR_SetHotItem (hwnd, wParam);
5688 case TB_SETIMAGELIST:
5689 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5692 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5694 /* case TB_SETINSERTMARK: */ /* 4.71 */
5696 case TB_SETINSERTMARKCOLOR:
5697 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5699 case TB_SETMAXTEXTROWS:
5700 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5703 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
5706 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5709 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5712 return TOOLBAR_SetState (hwnd, wParam, lParam);
5715 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5717 case TB_SETTOOLTIPS:
5718 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5720 case TB_SETUNICODEFORMAT:
5721 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5724 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
5727 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
5730 /* Common Control Messages */
5732 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
5733 case CCM_GETCOLORSCHEME:
5734 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5736 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
5737 case CCM_SETCOLORSCHEME:
5738 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5740 case CCM_GETVERSION:
5741 return TOOLBAR_GetVersion (hwnd);
5743 case CCM_SETVERSION:
5744 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5750 return TOOLBAR_Create (hwnd, wParam, lParam);
5753 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5756 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5759 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5761 /* case WM_KEYDOWN: */
5762 /* case WM_KILLFOCUS: */
5764 case WM_LBUTTONDBLCLK:
5765 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5767 case WM_LBUTTONDOWN:
5768 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5771 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5774 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5777 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5779 case WM_CAPTURECHANGED:
5780 return TOOLBAR_CaptureChanged(hwnd);
5783 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5786 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5789 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5792 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5795 return TOOLBAR_Notify (hwnd, wParam, lParam);
5797 case WM_NOTIFYFORMAT:
5798 TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
5801 return TOOLBAR_Paint (hwnd, wParam);
5804 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5807 return TOOLBAR_Size (hwnd, wParam, lParam);
5809 case WM_STYLECHANGED:
5810 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5812 case WM_SYSCOLORCHANGE:
5813 return TOOLBAR_SysColorChange (hwnd);
5815 /* case WM_WININICHANGE: */
5820 case WM_MEASUREITEM:
5823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5825 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5827 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5830 /* We see this in Outlook Express 5.x and just does DefWindowProc */
5831 case PGM_FORWARDMOUSE:
5832 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5835 if (uMsg >= WM_USER)
5836 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5837 uMsg, wParam, lParam);
5838 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5845 TOOLBAR_Register (void)
5849 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5850 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5851 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5852 wndClass.cbClsExtra = 0;
5853 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5854 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5855 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5856 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5858 RegisterClassA (&wndClass);
5863 TOOLBAR_Unregister (void)
5865 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);