4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * Differences between MSDN and actual native control operation:
8 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
9 * to the right of the bitmap. Otherwise, this style is
10 * identical to TBSTYLE_FLAT."
11 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
12 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
13 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
14 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
18 * - A little bug in TOOLBAR_DrawMasked()
19 * - Button wrapping (under construction).
21 * - Notifications (under construction).
23 * - Tooltip support (almost complete).
24 * - Unicode suppport (under construction).
25 * - Fix TOOLBAR_SetButtonInfo32A/W.
26 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
27 * - I_IMAGECALLBACK support.
28 * - iString of -1 is undocumented
29 * - Customization dialog:
31 * - Minor buglet in 'available buttons' list:
32 * Buttons are not listed in M$-like order. M$ seems to use a single
33 * internal list to store the button information of both listboxes.
34 * - Drag list support.
35 * - Help and Reset button support.
38 * - Run tests using Waite Group Windows95 API Bible Volume 2.
39 * The second cdrom contains executables addstr.exe, btncount.exe,
40 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
41 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
42 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
43 * setparnt.exe, setrows.exe, toolwnd.exe.
44 * - Microsofts controlspy examples.
45 * - Charles Petzold's 'Programming Windows': gadgets.exe
54 #include "wine/unicode.h"
56 #include "imagelist.h"
58 #include "debugtools.h"
60 DEFAULT_DEBUG_CHANNEL(toolbar);
78 DWORD dwStructSize; /* size of TBBUTTON struct */
79 INT nHeight; /* height of the toolbar */
80 INT nWidth; /* width of the toolbar */
86 INT nRows; /* number of button rows */
87 INT nMaxTextRows; /* maximum number of text rows */
88 INT cxMin; /* minimum button width */
89 INT cxMax; /* maximum button width */
90 INT nNumButtons; /* number of buttons */
91 INT nNumBitmaps; /* number of bitmaps */
92 INT nNumStrings; /* number of strings */
93 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
94 BOOL bCaptured; /* mouse captured? */
97 INT nHotItem; /* index of the "hot" item */
98 HFONT hFont; /* text font */
99 HIMAGELIST himlInt; /* image list created internally */
100 HIMAGELIST himlDef; /* default image list */
101 HIMAGELIST himlHot; /* hot image list */
102 HIMAGELIST himlDis; /* disabled image list */
103 HWND hwndToolTip; /* handle to tool tip control */
104 HWND hwndNotify; /* handle to the window that gets notifications */
105 HWND hwndSelf; /* my own handle */
106 BOOL bTransparent; /* background transparency flag */
107 BOOL bBtnTranspnt; /* button transparency flag */
108 BOOL bAutoSize; /* auto size deadlock indicator */
109 BOOL bAnchor; /* anchor highlight enabled */
110 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
111 DWORD dwExStyle; /* extended toolbar style */
112 DWORD dwDTFlags; /* DrawText flags */
114 COLORREF clrInsertMark; /* insert mark color */
115 RECT rcBound; /* bounding rectangle */
118 TBUTTON_INFO *buttons; /* pointer to button array */
119 LPWSTR *strings; /* pointer to string array */
120 } TOOLBAR_INFO, *PTOOLBAR_INFO;
123 /* used by customization dialog */
126 PTOOLBAR_INFO tbInfo;
128 } CUSTDLG_INFO, *PCUSTDLG_INFO;
136 } CUSTOMBUTTON, *PCUSTOMBUTTON;
139 #define SEPARATOR_WIDTH 8
141 #define BOTTOM_BORDER 2
142 #define DDARROW_WIDTH 11
144 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
145 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
146 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
150 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
152 if (TRACE_ON(toolbar)){
153 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, string=%d\n",
154 btn_num, bP->idCommand,
155 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
157 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
158 btn_num, bP->idCommand,
159 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
160 bP->rect.left, bP->rect.top,
161 bP->rect.right, bP->rect.bottom);
167 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
169 if (TRACE_ON(toolbar)) {
173 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
174 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
176 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
177 iP->nNumStrings, dwStyle);
178 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p\n",
180 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis);
181 for(i=0; i<iP->nNumButtons; i++) {
182 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
188 /***********************************************************************
191 * This function validates that the styles set are implemented and
192 * issues FIXME's warning of possible problems. In a perfect world this
193 * function should be null.
196 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
198 if (dwStyle & TBSTYLE_ALTDRAG)
199 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
200 if (dwStyle & TBSTYLE_REGISTERDROP)
201 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
206 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
208 if(!IsWindow(infoPtr->hwndSelf))
209 return 0; /* we have just been destroyed */
211 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
212 nmhdr->hwndFrom = infoPtr->hwndSelf;
215 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
216 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
218 if (infoPtr->bNtfUnicode)
219 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
220 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
222 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
223 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
227 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
229 LPWSTR lpText = NULL;
231 /* FIXME: iString == -1 is undocumented */
232 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
233 lpText = (LPWSTR)btnPtr->iString;
234 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
235 lpText = infoPtr->strings[btnPtr->iString];
240 /***********************************************************************
241 * TOOLBAR_GetBitmapIndex
243 * This function returns the bitmap index associated with a button.
244 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
245 * is issued to retrieve the index.
248 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
250 INT ret = btnPtr->iBitmap;
252 if (ret == I_IMAGECALLBACK) {
253 /* issue TBN_GETDISPINFO */
256 nmgd.idCommand = btnPtr->idCommand;
257 nmgd.lParam = btnPtr->dwData;
258 nmgd.dwMask = TBNF_IMAGE;
259 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
260 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
262 if (nmgd.dwMask & TBNF_DI_SETITEM) {
263 btnPtr->iBitmap = nmgd.iImage;
266 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
267 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
274 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
276 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
277 (index == I_IMAGECALLBACK))
284 /***********************************************************************
285 * TOOLBAR_DrawImageList
287 * This function validates the bitmap index (including I_IMAGECALLBACK
288 * functionality). It then draws the image via the ImageList_Draw
289 * function. It returns TRUE if the image was drawn, FALSE otherwise.
292 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
293 HDC hdc, UINT left, UINT top, UINT draw_flags)
297 if (!himl) return FALSE;
299 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
300 ERR("index %d is not valid, max %d\n",
301 btnPtr->iBitmap, infoPtr->nNumBitmaps);
305 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
306 if (index == -1) return FALSE;
307 ERR("TBN_GETDISPINFO returned invalid index %d\n",
311 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
312 index, himl, left, top, draw_flags);
314 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
319 /***********************************************************************
320 * TOOLBAR_TestImageExist
322 * This function is similar to TOOLBAR_DrawImageList, except it does not
323 * draw the image. The I_IMAGECALLBACK functionality is implemented.
326 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
330 if (!himl) return FALSE;
332 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
333 ERR("index %d is not valid, max %d\n",
334 btnPtr->iBitmap, infoPtr->nNumBitmaps);
338 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
339 if (index == -1) return FALSE;
340 ERR("TBN_GETDISPINFO returned invalid index %d\n",
349 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
351 INT x = (lpRect->left + lpRect->right) / 2 - 1;
352 INT yBottom = lpRect->bottom - 3;
353 INT yTop = lpRect->top + 1;
355 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
356 MoveToEx (hdc, x, yBottom, NULL);
357 LineTo (hdc, x, yTop);
359 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
360 MoveToEx (hdc, x, yBottom, NULL);
361 LineTo (hdc, x, yTop);
365 /***********************************************************************
366 * TOOLBAR_DrawDDFlatSeparator
368 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
369 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
370 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
371 * are horizontal as opposed to the vertical separators for not dropdown
374 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
377 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr)
380 COLORREF oldcolor, newcolor;
382 myrect.left = lpRect->left;
383 myrect.right = lpRect->right;
384 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
385 myrect.bottom = myrect.top + 1;
387 InflateRect (&myrect, -2, 0);
389 TRACE("rect=(%d,%d)-(%d,%d)\n",
390 myrect.left, myrect.top, myrect.right, myrect.bottom);
392 newcolor = GetSysColor (COLOR_BTNSHADOW);
393 oldcolor = SetBkColor (hdc, newcolor);
394 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
396 myrect.top = myrect.bottom;
397 myrect.bottom = myrect.top + 1;
399 newcolor = GetSysColor (COLOR_BTNHIGHLIGHT);
400 SetBkColor (hdc, newcolor);
401 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
403 SetBkColor (hdc, oldcolor);
408 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
411 SelectObject ( hdc, GetSysColorPen (colorRef));
414 MoveToEx (hdc, x, y, NULL);
415 LineTo (hdc, x+5, y++); x++;
416 MoveToEx (hdc, x, y, NULL);
417 LineTo (hdc, x+3, y++); x++;
418 MoveToEx (hdc, x, y, NULL);
419 LineTo (hdc, x+1, y++);
423 * Draw the text string for this button.
424 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
425 * is non-zero, so we can simply check himlDef to see if we have
429 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
430 HDC hdc, INT nState, DWORD dwStyle)
432 RECT rcText = btnPtr->rect;
435 LPWSTR lpText = NULL;
436 HIMAGELIST himl = infoPtr->himlDef;
438 TRACE ("iString: %x\n", btnPtr->iString);
440 /* get a pointer to the text */
441 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
443 TRACE ("lpText: %s\n", debugstr_w(lpText));
448 InflateRect (&rcText, -3, -3);
450 if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
451 /* The following test looked like this before
452 * I changed it. IE4 "Links" toolbar would not
453 * draw correctly with the original code. - GA 8/01
454 * ((dwStyle & TBSTYLE_LIST) &&
455 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
456 * (btnPtr->iBitmap != I_IMAGENONE))
458 if (dwStyle & TBSTYLE_LIST) {
459 /* LIST style w/ ICON offset is by matching native. */
460 /* Matches IE4 "Links" bar. - GA 8/01 */
461 rcText.left += (infoPtr->nBitmapWidth + 2);
464 rcText.top += infoPtr->nBitmapHeight + 1;
468 if (dwStyle & TBSTYLE_LIST) {
469 /* LIST style w/o ICON offset is by matching native. */
470 /* Matches IE4 "menu" bar. - GA 8/01 */
475 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
476 OffsetRect (&rcText, 1, 1);
478 TRACE("string rect=(%d,%d)-(%d,%d)\n",
479 rcText.left, rcText.top, rcText.right, rcText.bottom);
481 hOldFont = SelectObject (hdc, infoPtr->hFont);
482 if (!(nState & TBSTATE_ENABLED)) {
483 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
484 OffsetRect (&rcText, 1, 1);
485 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
486 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
487 OffsetRect (&rcText, -1, -1);
488 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
490 else if (nState & TBSTATE_INDETERMINATE) {
491 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
492 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
495 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
496 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
499 SetTextColor (hdc, clrOld);
500 SelectObject (hdc, hOldFont);
506 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
508 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
509 INT cx = lpRect->right - lpRect->left;
510 INT cy = lpRect->bottom - lpRect->top;
511 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
512 SelectObject (hdc, hbr);
517 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
518 HDC hdc, INT x, INT y)
520 /* FIXME: this function is a hack since it uses image list
521 internals directly */
523 HIMAGELIST himl = infoPtr->himlDef;
531 /* create new dc's */
532 hdcImageList = CreateCompatibleDC (0);
533 hdcMask = CreateCompatibleDC (0);
535 /* create new bitmap */
536 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
537 SelectObject (hdcMask, hbmMask);
539 /* copy the mask bitmap */
540 SelectObject (hdcImageList, himl->hbmMask);
541 SetBkColor (hdcImageList, RGB(255, 255, 255));
542 SetTextColor (hdcImageList, RGB(0, 0, 0));
543 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
544 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
546 /* draw the new mask */
547 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
548 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
549 hdcMask, 0, 0, 0xB8074A);
551 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
552 BitBlt (hdc, x, y, himl->cx, himl->cy,
553 hdcMask, 0, 0, 0xB8074A);
555 DeleteObject (hbmMask);
557 DeleteDC (hdcImageList);
562 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
565 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
566 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
567 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
568 RECT rc, rcArrow, rcBitmap;
570 if (btnPtr->fsState & TBSTATE_HIDDEN)
574 CopyRect (&rcArrow, &rc);
575 CopyRect(&rcBitmap, &rc);
577 if (!infoPtr->bBtnTranspnt)
578 FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
580 if (hasDropDownArrow)
582 if (dwStyle & TBSTYLE_FLAT)
583 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
585 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
586 rcArrow.left = rc.right;
589 /* Center the bitmap horizontally and vertically */
590 if (dwStyle & TBSTYLE_LIST)
593 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
595 if(TOOLBAR_HasText(infoPtr, btnPtr))
596 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
598 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
600 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
601 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
602 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
605 if (btnPtr->fsStyle & TBSTYLE_SEP) {
606 /* with the FLAT style, iBitmap is the width and has already */
607 /* been taken into consideration in calculating the width */
608 /* so now we need to draw the vertical separator */
609 /* empirical tests show that iBitmap can/will be non-zero */
610 /* when drawing the vertical bar... */
611 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
612 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
613 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr);
615 TOOLBAR_DrawFlatSeparator (&rc, hdc);
621 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
622 if (!(dwStyle & TBSTYLE_FLAT))
624 DrawEdge (hdc, &rc, EDGE_RAISED,
625 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
626 if (hasDropDownArrow)
627 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
628 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
631 if (hasDropDownArrow)
633 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
634 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
637 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
638 hdc, rcBitmap.left, rcBitmap.top,
640 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
642 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
646 /* pressed TBSTYLE_BUTTON */
647 if (btnPtr->fsState & TBSTATE_PRESSED) {
648 if (dwStyle & TBSTYLE_FLAT)
650 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
651 if (hasDropDownArrow)
652 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
656 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
657 if (hasDropDownArrow)
658 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
661 if (hasDropDownArrow)
662 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
664 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
665 hdc, rcBitmap.left+1, rcBitmap.top+1,
668 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
672 /* checked TBSTYLE_CHECK */
673 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
674 (btnPtr->fsState & TBSTATE_CHECKED)) {
675 if (dwStyle & TBSTYLE_FLAT)
676 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
677 BF_RECT | BF_ADJUST);
679 DrawEdge (hdc, &rc, EDGE_SUNKEN,
680 BF_RECT | BF_MIDDLE | BF_ADJUST);
682 TOOLBAR_DrawPattern (hdc, &rc);
684 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
685 hdc, rcBitmap.left+1, rcBitmap.top+1,
688 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
693 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
694 DrawEdge (hdc, &rc, EDGE_RAISED,
695 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
697 TOOLBAR_DrawPattern (hdc, &rc);
698 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
699 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
704 if (dwStyle & TBSTYLE_FLAT)
708 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
709 if (hasDropDownArrow)
710 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
713 else /* The following code needs to be removed after
714 * "hot item" support has been implemented for the
715 * case where it is being de-selected.
718 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
719 if (hasDropDownArrow)
720 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
724 if (hasDropDownArrow)
725 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
728 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
729 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
732 rcBitmap.top, ILD_NORMAL))
733 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
734 hdc, rcBitmap.left, rcBitmap.top,
738 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
739 hdc, rcBitmap.left, rcBitmap.top,
744 DrawEdge (hdc, &rc, EDGE_RAISED,
745 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
747 if (hasDropDownArrow)
749 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
750 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
751 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
754 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
755 hdc, rcBitmap.left, rcBitmap.top,
759 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
764 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
766 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
767 TBUTTON_INFO *btnPtr;
768 INT i, oldBKmode = 0;
771 /* if imagelist belongs to the app, it can be changed
772 by the app after setting it */
773 if (infoPtr->himlDef != infoPtr->himlInt)
774 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
776 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
778 if (infoPtr->bBtnTranspnt)
779 oldBKmode = SetBkMode (hdc, TRANSPARENT);
781 /* redraw necessary buttons */
782 btnPtr = infoPtr->buttons;
783 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
785 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
786 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
789 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
790 SetBkMode (hdc, oldBKmode);
793 /***********************************************************************
794 * TOOLBAR_MeasureString
796 * This function gets the width and height of a string in pixels. This
797 * is done first by using GetTextExtentPoint to get the basic width
798 * and height. The DrawText is called with DT_CALCRECT to get the exact
799 * width. The reason is because the text may have more than one "&" (or
800 * prefix characters as M$ likes to call them). The prefix character
801 * indicates where the underline goes, except for the string "&&" which
802 * is reduced to a single "&". GetTextExtentPoint does not process these
803 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
806 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
807 HDC hdc, LPSIZE lpSize)
814 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
815 (btnPtr->iString > -1) &&
816 (btnPtr->iString < infoPtr->nNumStrings))
818 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
820 /* first get size of all the text */
821 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
823 /* feed above size into the rectangle for DrawText */
824 myrect.left = myrect.top = 0;
825 myrect.right = lpSize->cx;
826 myrect.bottom = lpSize->cy;
828 /* Use DrawText to get true size as drawn (less pesky "&") */
829 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
830 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
833 /* feed back to caller */
834 lpSize->cx = myrect.right;
835 lpSize->cy = myrect.bottom;
838 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
841 /***********************************************************************
842 * TOOLBAR_CalcStrings
844 * This function walks through each string and measures it and returns
845 * the largest height and width to caller.
848 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
850 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
851 TBUTTON_INFO *btnPtr;
861 hOldFont = SelectObject (hdc, infoPtr->hFont);
863 btnPtr = infoPtr->buttons;
864 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
865 if(TOOLBAR_HasText(infoPtr, btnPtr))
867 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
868 if (sz.cx > lpSize->cx)
870 if (sz.cy > lpSize->cy)
875 SelectObject (hdc, hOldFont);
876 ReleaseDC (hwnd, hdc);
878 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
881 /***********************************************************************
882 * TOOLBAR_WrapToolbar
884 * This function walks through the buttons and seperators in the
885 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
886 * wrapping should occur based on the width of the toolbar window.
887 * It does *not* calculate button placement itself. That task
888 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
889 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
890 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
894 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
897 TBUTTON_INFO *btnPtr;
900 BOOL bWrap, bButtonWrap;
902 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
903 /* no layout is necessary. Applications may use this style */
904 /* to perform their own layout on the toolbar. */
905 if( !(dwStyle & TBSTYLE_WRAPABLE) )
908 btnPtr = infoPtr->buttons;
909 x = infoPtr->nIndent;
911 /* this can get the parents width, to know how far we can extend
912 * this toolbar. We cannot use its height, as there may be multiple
913 * toolbars in a rebar control
915 GetClientRect( GetParent(hwnd), &rc );
916 infoPtr->nWidth = rc.right - rc.left;
919 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
920 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
923 for (i = 0; i < infoPtr->nNumButtons; i++ )
926 btnPtr[i].fsState &= ~TBSTATE_WRAP;
928 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
931 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
932 /* it is the actual width of the separator. This is used for */
933 /* custom controls in toolbars. */
935 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
936 /* width. - GA 8/01 */
937 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
938 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
939 cx = (btnPtr[i].iBitmap > 0) ?
940 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
942 cx = infoPtr->nButtonWidth;
944 /* Two or more adjacent separators form a separator group. */
945 /* The first separator in a group should be wrapped to the */
946 /* next row if the previous wrapping is on a button. */
948 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
949 (i + 1 < infoPtr->nNumButtons ) &&
950 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
952 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
953 btnPtr[i].fsState |= TBSTATE_WRAP;
954 x = infoPtr->nIndent;
960 /* The layout makes sure the bitmap is visible, but not the button. */
961 /* Test added to also wrap after a button that starts a row but */
962 /* is bigger than the area. - GA 8/01 */
963 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
964 > infoPtr->nWidth ) ||
965 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
969 /* If the current button is a separator and not hidden, */
970 /* go to the next until it reaches a non separator. */
971 /* Wrap the last separator if it is before a button. */
972 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
973 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
974 i < infoPtr->nNumButtons )
980 if( bFound && i < infoPtr->nNumButtons )
983 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
984 i, btnPtr[i].fsStyle, x, cx);
985 btnPtr[i].fsState |= TBSTATE_WRAP;
986 x = infoPtr->nIndent;
990 else if ( i >= infoPtr->nNumButtons)
993 /* If the current button is not a separator, find the last */
994 /* separator and wrap it. */
995 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
997 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
998 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1002 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1003 i, btnPtr[i].fsStyle, x, cx);
1004 x = infoPtr->nIndent;
1005 btnPtr[j].fsState |= TBSTATE_WRAP;
1006 bButtonWrap = FALSE;
1011 /* If no separator available for wrapping, wrap one of */
1012 /* non-hidden previous button. */
1016 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1018 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1023 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1024 i, btnPtr[i].fsStyle, x, cx);
1025 x = infoPtr->nIndent;
1026 btnPtr[j].fsState |= TBSTATE_WRAP;
1032 /* If all above failed, wrap the current button. */
1035 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1036 i, btnPtr[i].fsStyle, x, cx);
1037 btnPtr[i].fsState |= TBSTATE_WRAP;
1039 x = infoPtr->nIndent;
1040 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1041 bButtonWrap = FALSE;
1047 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1048 i, btnPtr[i].fsStyle, x, cx);
1055 /***********************************************************************
1056 * TOOLBAR_CalcToolbar
1058 * This function calculates button and separator placement. It first
1059 * calculates the button sizes, gets the toolbar window width and then
1060 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1061 * on. It assigns a new location to each item and sends this location to
1062 * the tooltip window if appropriate. Finally, it updates the rcBound
1063 * rect and calculates the new required toolbar window height.
1067 TOOLBAR_CalcToolbar (HWND hwnd)
1069 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1070 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1071 TBUTTON_INFO *btnPtr;
1072 INT i, nRows, nSepRows;
1076 BOOL usesBitmaps = FALSE;
1077 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1079 TOOLBAR_CalcStrings (hwnd, &sizeString);
1081 if (dwStyle & TBSTYLE_LIST)
1083 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1085 if (infoPtr->buttons[i].iBitmap >= 0)
1088 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1089 0, sizeString.cy) + 6;
1090 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1091 0) + sizeString.cx + 6;
1092 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1093 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1094 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1095 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1098 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1100 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1104 if (sizeString.cy > 0)
1107 infoPtr->nButtonHeight = sizeString.cy +
1108 2 + /* this is the space to separate text from bitmap */
1109 infoPtr->nBitmapHeight + 6;
1111 infoPtr->nButtonHeight = sizeString.cy + 6;
1113 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1114 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1116 if (sizeString.cx > infoPtr->nBitmapWidth)
1117 infoPtr->nButtonWidth = sizeString.cx + 6;
1118 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1119 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1122 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1123 infoPtr->nButtonWidth = infoPtr->cxMin;
1124 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1125 infoPtr->nButtonWidth = infoPtr->cxMax;
1127 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1129 x = infoPtr->nIndent;
1133 * We will set the height below, and we set the width on entry
1134 * so we do not reset them here..
1137 GetClientRect( hwnd, &rc );
1138 /* get initial values for toolbar */
1139 infoPtr->nWidth = rc.right - rc.left;
1140 infoPtr->nHeight = rc.bottom - rc.top;
1143 /* from above, minimum is a button, and possible text */
1144 cx = infoPtr->nButtonWidth;
1146 /* cannot use just ButtonHeight, we may have no buttons! */
1147 if (infoPtr->nNumButtons > 0)
1148 infoPtr->nHeight = infoPtr->nButtonHeight;
1150 cy = infoPtr->nHeight;
1152 nRows = nSepRows = 0;
1154 infoPtr->rcBound.top = y;
1155 infoPtr->rcBound.left = x;
1156 infoPtr->rcBound.bottom = y + cy;
1157 infoPtr->rcBound.right = x;
1159 btnPtr = infoPtr->buttons;
1161 /* do not base height/width on parent, if the parent is a */
1162 /* rebar control it could have multiple rows of toolbars */
1163 /* GetClientRect( GetParent(hwnd), &rc ); */
1164 /* cx = rc.right - rc.left; */
1165 /* cy = rc.bottom - rc.top; */
1167 TRACE("cy=%d\n", cy);
1169 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1172 if (btnPtr->fsState & TBSTATE_HIDDEN)
1174 SetRectEmpty (&btnPtr->rect);
1178 cy = infoPtr->nHeight;
1180 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1181 /* it is the actual width of the separator. This is used for */
1182 /* custom controls in toolbars. */
1183 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1184 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1185 cy = (btnPtr->iBitmap > 0) ?
1186 btnPtr->iBitmap : SEPARATOR_WIDTH;
1187 cx = infoPtr->nButtonWidth;
1190 cx = (btnPtr->iBitmap > 0) ?
1191 btnPtr->iBitmap : SEPARATOR_WIDTH;
1195 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1202 hOldFont = SelectObject (hdc, infoPtr->hFont);
1204 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1206 SelectObject (hdc, hOldFont);
1207 ReleaseDC (hwnd, hdc);
1209 /* Fudge amount measured against IE4 "menu" and "Links" */
1210 /* toolbars with native control (v4.71). - GA 8/01 */
1211 cx = sz.cx + 6 + 5 + 5;
1212 if ((dwStyle & TBSTYLE_LIST) &&
1213 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1214 cx += infoPtr->nBitmapWidth;
1217 cx = infoPtr->nButtonWidth;
1219 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1220 cx += DDARROW_WIDTH;
1222 if (btnPtr->fsState & TBSTATE_WRAP )
1225 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1227 if (infoPtr->rcBound.left > x)
1228 infoPtr->rcBound.left = x;
1229 if (infoPtr->rcBound.right < x + cx)
1230 infoPtr->rcBound.right = x + cx;
1231 if (infoPtr->rcBound.bottom < y + cy)
1232 infoPtr->rcBound.bottom = y + cy;
1234 /* Set the toolTip only for non-hidden, non-separator button */
1235 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1239 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1240 ti.cbSize = sizeof(TTTOOLINFOA);
1242 ti.uId = btnPtr->idCommand;
1243 ti.rect = btnPtr->rect;
1244 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1248 /* btnPtr->nRow is zero based. The space between the rows is */
1249 /* also considered as a row. */
1250 btnPtr->nRow = nRows + nSepRows;
1252 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d\n",
1253 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow);
1257 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1261 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1262 /* it is the actual width of the separator. This is used for */
1263 /* custom controls in toolbars. */
1264 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1265 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1266 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1270 /* nSepRows is used to calculate the extra height follwoing */
1274 x = infoPtr->nIndent;
1281 /* infoPtr->nRows is the number of rows on the toolbar */
1282 infoPtr->nRows = nRows + nSepRows + 1;
1284 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1286 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1287 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1288 nSepRows * (infoPtr->nBitmapHeight + 1) +
1290 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1295 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1298 TBUTTON_INFO *btnPtr;
1301 btnPtr = infoPtr->buttons;
1302 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1303 if (btnPtr->fsState & TBSTATE_HIDDEN)
1306 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1307 if (PtInRect (&btnPtr->rect, *lpPt)) {
1308 TRACE(" ON SEPARATOR %d!\n", i);
1313 if (PtInRect (&btnPtr->rect, *lpPt)) {
1314 TRACE(" ON BUTTON %d!\n", i);
1320 TRACE(" NOWHERE!\n");
1326 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1328 TBUTTON_INFO *btnPtr;
1331 if (CommandIsIndex) {
1332 TRACE("command is really index command=%d\n", idCommand);
1335 btnPtr = infoPtr->buttons;
1336 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1337 if (btnPtr->idCommand == idCommand) {
1338 TRACE("command=%d index=%d\n", idCommand, i);
1342 TRACE("no index found for command=%d\n", idCommand);
1348 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1350 TBUTTON_INFO *btnPtr;
1353 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1356 /* check index button */
1357 btnPtr = &infoPtr->buttons[nIndex];
1358 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1359 if (btnPtr->fsState & TBSTATE_CHECKED)
1363 /* check previous buttons */
1364 nRunIndex = nIndex - 1;
1365 while (nRunIndex >= 0) {
1366 btnPtr = &infoPtr->buttons[nRunIndex];
1367 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1368 if (btnPtr->fsState & TBSTATE_CHECKED)
1376 /* check next buttons */
1377 nRunIndex = nIndex + 1;
1378 while (nRunIndex < infoPtr->nNumButtons) {
1379 btnPtr = &infoPtr->buttons[nRunIndex];
1380 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1381 if (btnPtr->fsState & TBSTATE_CHECKED)
1394 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1395 WPARAM wParam, LPARAM lParam)
1401 msg.wParam = wParam;
1402 msg.lParam = lParam;
1403 msg.time = GetMessageTime ();
1404 msg.pt.x = LOWORD(GetMessagePos ());
1405 msg.pt.y = HIWORD(GetMessagePos ());
1407 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1411 /***********************************************************************
1412 * TOOLBAR_CustomizeDialogProc
1413 * This function implements the toolbar customization dialog.
1416 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1418 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1419 PCUSTOMBUTTON btnInfo;
1421 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1426 custInfo = (PCUSTDLG_INFO)lParam;
1427 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1435 infoPtr = custInfo->tbInfo;
1437 /* send TBN_QUERYINSERT notification */
1438 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1440 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1443 /* add items to 'toolbar buttons' list and check if removable */
1444 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1446 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1447 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1448 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1449 btnInfo->bVirtual = FALSE;
1450 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1452 /* send TBN_QUERYDELETE notification */
1454 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1458 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1459 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1462 /* insert separator button into 'available buttons' list */
1463 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1464 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1465 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1466 btnInfo->bVirtual = FALSE;
1467 btnInfo->bRemovable = TRUE;
1468 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1469 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1470 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1472 /* insert all buttons into dsa */
1475 /* send TBN_GETBUTTONINFO notification */
1477 nmtb.pszText = Buffer;
1480 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1483 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1485 /* insert button into the apropriate list */
1486 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1489 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1490 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1491 btnInfo->bVirtual = FALSE;
1492 btnInfo->bRemovable = TRUE;
1493 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1494 strcpy (btnInfo->text, nmtb.pszText);
1496 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1497 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1501 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1502 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1503 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1504 strcpy (btnInfo->text, nmtb.pszText);
1506 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1510 /* select first item in the 'available' list */
1511 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1513 /* append 'virtual' separator button to the 'toolbar buttons' list */
1514 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1515 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1516 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1517 btnInfo->bVirtual = TRUE;
1518 btnInfo->bRemovable = FALSE;
1519 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1520 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1521 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1523 /* select last item in the 'toolbar' list */
1524 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1525 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1527 /* set focus and disable buttons */
1528 PostMessageA (hwnd, WM_USER, 0, 0);
1533 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1534 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1535 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1536 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1540 EndDialog(hwnd, FALSE);
1544 switch (LOWORD(wParam))
1546 case IDC_TOOLBARBTN_LBOX:
1547 if (HIWORD(wParam) == LBN_SELCHANGE)
1549 PCUSTOMBUTTON btnInfo;
1554 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1555 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1557 /* send TBN_QUERYINSERT notification */
1559 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1562 /* get list box item */
1563 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1565 if (index == (count - 1))
1567 /* last item (virtual separator) */
1568 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1569 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1571 else if (index == (count - 2))
1573 /* second last item (last non-virtual item) */
1574 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1575 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1577 else if (index == 0)
1580 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1581 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1585 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1586 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1589 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1593 case IDC_MOVEUP_BTN:
1595 PCUSTOMBUTTON btnInfo;
1599 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1600 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1601 TRACE("Move up: index %d\n", index);
1603 /* send TBN_QUERYINSERT notification */
1606 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1609 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1611 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1612 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1613 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1614 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1617 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1618 else if (index >= (count - 3))
1619 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1621 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1622 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1627 case IDC_MOVEDN_BTN: /* move down */
1629 PCUSTOMBUTTON btnInfo;
1633 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1634 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1635 TRACE("Move up: index %d\n", index);
1637 /* send TBN_QUERYINSERT notification */
1639 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1642 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1644 /* move button down */
1645 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1646 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1647 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1648 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1651 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1652 else if (index >= (count - 3))
1653 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1655 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1656 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1661 case IDC_REMOVE_BTN: /* remove button */
1663 PCUSTOMBUTTON btnInfo;
1666 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1667 TRACE("Remove: index %d\n", index);
1669 /* send TBN_QUERYDELETE notification */
1671 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1674 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1675 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1676 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1678 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1680 /* insert into 'available button' list */
1681 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1683 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1684 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1687 COMCTL32_Free (btnInfo);
1692 case IDOK: /* Add button */
1697 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1698 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1699 TRACE("Add: index %d\n", index);
1701 /* send TBN_QUERYINSERT notification */
1703 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1706 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1710 /* remove from 'available buttons' list */
1711 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1712 if (index == count-1)
1713 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1715 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1719 PCUSTOMBUTTON btnNew;
1721 /* duplicate 'separator' button */
1722 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1723 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1727 /* insert into 'toolbar button' list */
1728 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1729 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1730 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1732 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1738 EndDialog(hwnd, FALSE);
1748 /* delete items from 'toolbar buttons' listbox*/
1749 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1750 for (i = 0; i < count; i++)
1752 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1753 COMCTL32_Free(btnInfo);
1754 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1756 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1759 /* delete items from 'available buttons' listbox*/
1760 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1761 for (i = 0; i < count; i++)
1763 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1764 COMCTL32_Free(btnInfo);
1765 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1767 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1772 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1774 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1779 COLORREF oldText = 0;
1783 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1784 if (btnInfo == NULL)
1786 FIXME("btnInfo invalid!\n");
1790 /* set colors and select objects */
1791 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1792 if (btnInfo->bVirtual)
1793 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
1795 oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
1796 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1797 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1799 /* fill background rectangle */
1800 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
1801 lpdis->rcItem.right, lpdis->rcItem.bottom);
1803 /* calculate button and text rectangles */
1804 CopyRect (&rcButton, &lpdis->rcItem);
1805 InflateRect (&rcButton, -1, -1);
1806 CopyRect (&rcText, &rcButton);
1807 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
1808 rcText.left = rcButton.right + 2;
1810 /* draw focus rectangle */
1811 if (lpdis->itemState & ODS_FOCUS)
1812 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1815 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
1817 /* draw image and text */
1818 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
1819 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
1820 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
1821 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
1822 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1824 /* delete objects and reset colors */
1825 SelectObject (lpdis->hDC, hOldBrush);
1826 SelectObject (lpdis->hDC, hOldPen);
1827 SetBkColor (lpdis->hDC, oldBk);
1828 SetTextColor (lpdis->hDC, oldText);
1834 case WM_MEASUREITEM:
1835 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1837 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1839 if (custInfo && custInfo->tbInfo)
1840 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
1842 lpmis->itemHeight = 15 + 8; /* default height */
1854 /***********************************************************************
1855 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1859 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1861 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1862 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1863 INT nIndex = 0, nButtons, nCount;
1866 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1870 if (lpAddBmp->hInst == HINST_COMMCTRL)
1872 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1874 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1876 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1881 TRACE ("adding %d internal bitmaps!\n", nButtons);
1883 /* Windows resize all the buttons to the size of a newly added standard image */
1884 if (lpAddBmp->nID & 1)
1887 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
1888 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
1890 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1891 MAKELPARAM((WORD)24, (WORD)24));
1892 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1893 MAKELPARAM((WORD)31, (WORD)30));
1898 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1899 MAKELPARAM((WORD)16, (WORD)16));
1900 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1901 MAKELPARAM((WORD)22, (WORD)22));
1904 TOOLBAR_CalcToolbar (hwnd);
1908 nButtons = (INT)wParam;
1912 TRACE ("adding %d bitmaps!\n", nButtons);
1915 if (!(infoPtr->himlDef)) {
1916 /* create new default image list */
1917 TRACE ("creating default image list!\n");
1920 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1921 ILC_COLOR | ILC_MASK, nButtons, 2);
1922 infoPtr->himlInt = infoPtr->himlDef;
1925 nCount = ImageList_GetImageCount(infoPtr->himlDef);
1927 /* Add bitmaps to the default image list */
1928 if (lpAddBmp->hInst == (HINSTANCE)0)
1931 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1934 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1936 /* Add system bitmaps */
1937 switch (lpAddBmp->nID)
1939 case IDB_STD_SMALL_COLOR:
1940 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1941 MAKEINTRESOURCEA(IDB_STD_SMALL));
1942 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1943 hbmLoad, CLR_DEFAULT);
1944 DeleteObject (hbmLoad);
1947 case IDB_STD_LARGE_COLOR:
1948 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1949 MAKEINTRESOURCEA(IDB_STD_LARGE));
1950 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1951 hbmLoad, CLR_DEFAULT);
1952 DeleteObject (hbmLoad);
1955 case IDB_VIEW_SMALL_COLOR:
1956 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1957 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1958 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1959 hbmLoad, CLR_DEFAULT);
1960 DeleteObject (hbmLoad);
1963 case IDB_VIEW_LARGE_COLOR:
1964 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1965 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1966 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1967 hbmLoad, CLR_DEFAULT);
1968 DeleteObject (hbmLoad);
1971 case IDB_HIST_SMALL_COLOR:
1972 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1973 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1974 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1975 hbmLoad, CLR_DEFAULT);
1976 DeleteObject (hbmLoad);
1979 case IDB_HIST_LARGE_COLOR:
1980 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1981 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1982 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1983 hbmLoad, CLR_DEFAULT);
1984 DeleteObject (hbmLoad);
1988 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1989 ERR ("invalid imagelist!\n");
1995 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1996 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1997 DeleteObject (hbmLoad);
2002 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2004 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2006 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",
2007 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2008 infoPtr->nNumBitmaps+nButtons,imagecount);
2010 infoPtr->nNumBitmaps = imagecount;
2013 infoPtr->nNumBitmaps += nButtons;
2016 InvalidateRect(hwnd, NULL, FALSE);
2023 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2026 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2027 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2029 TRACE("adding %d buttons!\n", wParam);
2031 nAddButtons = (UINT)wParam;
2032 nOldButtons = infoPtr->nNumButtons;
2033 nNewButtons = nOldButtons + nAddButtons;
2035 if (infoPtr->nNumButtons == 0) {
2037 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2040 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2042 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2043 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2044 nOldButtons * sizeof(TBUTTON_INFO));
2045 COMCTL32_Free (oldButtons);
2048 infoPtr->nNumButtons = nNewButtons;
2050 /* insert new button data */
2051 for (nCount = 0; nCount < nAddButtons; nCount++) {
2052 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2053 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2054 btnPtr->idCommand = lpTbb[nCount].idCommand;
2055 btnPtr->fsState = lpTbb[nCount].fsState;
2056 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2057 btnPtr->dwData = lpTbb[nCount].dwData;
2058 btnPtr->iString = lpTbb[nCount].iString;
2059 btnPtr->bHot = FALSE;
2061 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2064 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2065 ti.cbSize = sizeof (TTTOOLINFOA);
2067 ti.uId = btnPtr->idCommand;
2069 ti.lpszText = LPSTR_TEXTCALLBACKA;
2071 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2076 TOOLBAR_CalcToolbar (hwnd);
2078 InvalidateRect(hwnd, NULL, FALSE);
2085 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2087 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2088 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2089 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2091 TRACE("adding %d buttons!\n", wParam);
2093 nAddButtons = (UINT)wParam;
2094 nOldButtons = infoPtr->nNumButtons;
2095 nNewButtons = nOldButtons + nAddButtons;
2097 if (infoPtr->nNumButtons == 0) {
2099 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2102 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2104 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2105 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2106 nOldButtons * sizeof(TBUTTON_INFO));
2107 COMCTL32_Free (oldButtons);
2110 infoPtr->nNumButtons = nNewButtons;
2112 /* insert new button data */
2113 for (nCount = 0; nCount < nAddButtons; nCount++) {
2114 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2115 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2116 btnPtr->idCommand = lpTbb[nCount].idCommand;
2117 btnPtr->fsState = lpTbb[nCount].fsState;
2118 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2119 btnPtr->dwData = lpTbb[nCount].dwData;
2120 btnPtr->iString = lpTbb[nCount].iString;
2121 btnPtr->bHot = FALSE;
2123 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2126 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2127 ti.cbSize = sizeof (TTTOOLINFOW);
2129 ti.uId = btnPtr->idCommand;
2131 ti.lpszText = LPSTR_TEXTCALLBACKW;
2133 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2138 TOOLBAR_CalcToolbar (hwnd);
2140 InvalidateRect(hwnd, NULL, FALSE);
2147 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2152 if ((wParam) && (HIWORD(lParam) == 0)) {
2155 TRACE("adding string from resource!\n");
2157 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2160 TRACE("len=%d \"%s\"\n", len, szString);
2161 nIndex = infoPtr->nNumStrings;
2162 if (infoPtr->nNumStrings == 0) {
2164 COMCTL32_Alloc (sizeof(LPWSTR));
2167 LPWSTR *oldStrings = infoPtr->strings;
2169 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2170 memcpy (&infoPtr->strings[0], &oldStrings[0],
2171 sizeof(LPWSTR) * infoPtr->nNumStrings);
2172 COMCTL32_Free (oldStrings);
2175 lenW = MultiByteToWideChar( CP_ACP, 0, szString, -1, NULL, 0 );
2176 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2177 MultiByteToWideChar( CP_ACP, 0, szString, -1,
2178 infoPtr->strings[infoPtr->nNumStrings], lenW );
2179 infoPtr->nNumStrings++;
2182 LPSTR p = (LPSTR)lParam;
2187 TRACE("adding string(s) from array!\n");
2189 nIndex = infoPtr->nNumStrings;
2192 TRACE("len=%d \"%s\"\n", len, p);
2194 if (infoPtr->nNumStrings == 0) {
2196 COMCTL32_Alloc (sizeof(LPWSTR));
2199 LPWSTR *oldStrings = infoPtr->strings;
2201 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2202 memcpy (&infoPtr->strings[0], &oldStrings[0],
2203 sizeof(LPWSTR) * infoPtr->nNumStrings);
2204 COMCTL32_Free (oldStrings);
2207 lenW = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
2208 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2209 MultiByteToWideChar( CP_ACP, 0, p, -1,
2210 infoPtr->strings[infoPtr->nNumStrings], lenW );
2211 infoPtr->nNumStrings++;
2222 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2224 #define MAX_RESOURCE_STRING_LENGTH 512
2225 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2228 if ((wParam) && (HIWORD(lParam) == 0)) {
2229 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2231 TRACE("adding string from resource!\n");
2233 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2234 szString, MAX_RESOURCE_STRING_LENGTH);
2236 TRACE("len=%d %s\n", len, debugstr_w(szString));
2237 TRACE("First char: 0x%x\n", *szString);
2238 if (szString[0] == L'|')
2240 PWSTR p = szString + 1;
2242 nIndex = infoPtr->nNumStrings;
2243 while (*p != L'|') {
2245 if (infoPtr->nNumStrings == 0) {
2247 COMCTL32_Alloc (sizeof(LPWSTR));
2250 LPWSTR *oldStrings = infoPtr->strings;
2252 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2253 memcpy (&infoPtr->strings[0], &oldStrings[0],
2254 sizeof(LPWSTR) * infoPtr->nNumStrings);
2255 COMCTL32_Free (oldStrings);
2258 len = COMCTL32_StrChrW (p, L'|') - p;
2259 TRACE("len=%d %s\n", len, debugstr_w(p));
2260 infoPtr->strings[infoPtr->nNumStrings] =
2261 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2262 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
2263 infoPtr->nNumStrings++;
2270 nIndex = infoPtr->nNumStrings;
2271 if (infoPtr->nNumStrings == 0) {
2273 COMCTL32_Alloc (sizeof(LPWSTR));
2276 LPWSTR *oldStrings = infoPtr->strings;
2278 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2279 memcpy (&infoPtr->strings[0], &oldStrings[0],
2280 sizeof(LPWSTR) * infoPtr->nNumStrings);
2281 COMCTL32_Free (oldStrings);
2284 infoPtr->strings[infoPtr->nNumStrings] =
2285 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2286 strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
2287 infoPtr->nNumStrings++;
2291 LPWSTR p = (LPWSTR)lParam;
2296 TRACE("adding string(s) from array!\n");
2297 nIndex = infoPtr->nNumStrings;
2301 TRACE("len=%d %s\n", len, debugstr_w(p));
2302 if (infoPtr->nNumStrings == 0) {
2304 COMCTL32_Alloc (sizeof(LPWSTR));
2307 LPWSTR *oldStrings = infoPtr->strings;
2309 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2310 memcpy (&infoPtr->strings[0], &oldStrings[0],
2311 sizeof(LPWSTR) * infoPtr->nNumStrings);
2312 COMCTL32_Free (oldStrings);
2315 infoPtr->strings[infoPtr->nNumStrings] =
2316 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2317 strcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
2318 infoPtr->nNumStrings++;
2329 TOOLBAR_AutoSize (HWND hwnd)
2331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2332 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2338 UINT uPosFlags = SWP_NOZORDER;
2340 TRACE("resize forced, style=%lx!\n", dwStyle);
2342 parent = GetParent (hwnd);
2343 GetClientRect(parent, &parent_rect);
2345 x = parent_rect.left;
2346 y = parent_rect.top;
2348 /* FIXME: we should be able to early out if nothing */
2349 /* has changed with nWidth != parent_rect width */
2351 if (dwStyle & CCS_NORESIZE) {
2352 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2357 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2358 TOOLBAR_CalcToolbar (hwnd);
2359 InvalidateRect( hwnd, NULL, TRUE );
2360 cy = infoPtr->nHeight;
2361 cx = infoPtr->nWidth;
2363 if (dwStyle & CCS_NOMOVEY) {
2364 GetWindowRect(hwnd, &window_rect);
2365 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2366 y = window_rect.top;
2370 if (dwStyle & CCS_NOPARENTALIGN)
2371 uPosFlags |= SWP_NOMOVE;
2373 if (!(dwStyle & CCS_NODIVIDER))
2374 cy += GetSystemMetrics(SM_CYEDGE);
2376 if (dwStyle & WS_BORDER)
2379 cy += GetSystemMetrics(SM_CYEDGE);
2380 cx += GetSystemMetrics(SM_CYEDGE);
2383 infoPtr->bAutoSize = TRUE;
2384 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2386 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2387 * the setwindowpos calls */
2388 infoPtr->bAutoSize = FALSE;
2395 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2399 return infoPtr->nNumButtons;
2404 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2406 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2408 if (infoPtr == NULL) {
2409 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2410 ERR("infoPtr == NULL!\n");
2414 infoPtr->dwStructSize = (DWORD)wParam;
2421 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2424 TBUTTON_INFO *btnPtr;
2427 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2431 btnPtr = &infoPtr->buttons[nIndex];
2432 btnPtr->iBitmap = LOWORD(lParam);
2434 /* we HAVE to erase the background, the new bitmap could be */
2436 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2443 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2446 TBUTTON_INFO *btnPtr;
2449 BOOL bChecked = FALSE;
2451 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2455 btnPtr = &infoPtr->buttons[nIndex];
2457 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2460 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2462 if (LOWORD(lParam) == FALSE)
2463 btnPtr->fsState &= ~TBSTATE_CHECKED;
2465 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2467 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2468 if (nOldIndex == nIndex)
2470 if (nOldIndex != -1)
2471 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2473 btnPtr->fsState |= TBSTATE_CHECKED;
2476 if( bChecked != LOWORD(lParam) )
2478 if (nOldIndex != -1)
2480 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2481 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2483 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2486 /* FIXME: Send a WM_NOTIFY?? */
2493 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2497 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2502 TOOLBAR_Customize (HWND hwnd)
2504 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2505 CUSTDLG_INFO custInfo;
2511 custInfo.tbInfo = infoPtr;
2512 custInfo.tbHwnd = hwnd;
2514 /* send TBN_BEGINADJUST notification */
2515 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2518 if (!(hRes = FindResourceA (COMCTL32_hModule,
2519 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2523 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2526 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2527 (LPDLGTEMPLATEA)template,
2529 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2532 /* send TBN_ENDADJUST notification */
2533 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2541 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2543 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2544 INT nIndex = (INT)wParam;
2546 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2549 if ((infoPtr->hwndToolTip) &&
2550 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2553 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2554 ti.cbSize = sizeof (TTTOOLINFOA);
2556 ti.uId = infoPtr->buttons[nIndex].idCommand;
2558 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2561 if (infoPtr->nNumButtons == 1) {
2562 TRACE(" simple delete!\n");
2563 COMCTL32_Free (infoPtr->buttons);
2564 infoPtr->buttons = NULL;
2565 infoPtr->nNumButtons = 0;
2568 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2569 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2571 infoPtr->nNumButtons--;
2572 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2574 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2575 nIndex * sizeof(TBUTTON_INFO));
2578 if (nIndex < infoPtr->nNumButtons) {
2579 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2580 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2583 COMCTL32_Free (oldButtons);
2586 TOOLBAR_CalcToolbar (hwnd);
2588 InvalidateRect (hwnd, NULL, TRUE);
2595 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2597 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2598 TBUTTON_INFO *btnPtr;
2602 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2606 btnPtr = &infoPtr->buttons[nIndex];
2608 bState = btnPtr->fsState & TBSTATE_ENABLED;
2610 /* update the toolbar button state */
2611 if(LOWORD(lParam) == FALSE) {
2612 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2614 btnPtr->fsState |= TBSTATE_ENABLED;
2617 /* redraw the button only if the state of the button changed */
2618 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2620 InvalidateRect(hwnd, &btnPtr->rect,
2621 TOOLBAR_HasText(infoPtr, btnPtr));
2628 static inline LRESULT
2629 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2633 return infoPtr->bAnchor;
2638 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2643 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2647 return infoPtr->buttons[nIndex].iBitmap;
2651 static inline LRESULT
2652 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2654 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2659 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2661 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2662 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2663 INT nIndex = (INT)wParam;
2664 TBUTTON_INFO *btnPtr;
2666 if (infoPtr == NULL)
2672 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2675 btnPtr = &infoPtr->buttons[nIndex];
2676 lpTbb->iBitmap = btnPtr->iBitmap;
2677 lpTbb->idCommand = btnPtr->idCommand;
2678 lpTbb->fsState = btnPtr->fsState;
2679 lpTbb->fsStyle = btnPtr->fsStyle;
2680 lpTbb->dwData = btnPtr->dwData;
2681 lpTbb->iString = btnPtr->iString;
2688 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2690 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2691 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2692 TBUTTON_INFO *btnPtr;
2695 if (infoPtr == NULL)
2697 if (lpTbInfo == NULL)
2699 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2702 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2703 lpTbInfo->dwMask & 0x80000000);
2707 btnPtr = &infoPtr->buttons[nIndex];
2709 if (lpTbInfo->dwMask & TBIF_COMMAND)
2710 lpTbInfo->idCommand = btnPtr->idCommand;
2711 if (lpTbInfo->dwMask & TBIF_IMAGE)
2712 lpTbInfo->iImage = btnPtr->iBitmap;
2713 if (lpTbInfo->dwMask & TBIF_LPARAM)
2714 lpTbInfo->lParam = btnPtr->dwData;
2715 if (lpTbInfo->dwMask & TBIF_SIZE)
2716 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2717 if (lpTbInfo->dwMask & TBIF_STATE)
2718 lpTbInfo->fsState = btnPtr->fsState;
2719 if (lpTbInfo->dwMask & TBIF_STYLE)
2720 lpTbInfo->fsStyle = btnPtr->fsStyle;
2721 if (lpTbInfo->dwMask & TBIF_TEXT) {
2722 if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
2724 if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[btnPtr->iString], -1,
2725 lpTbInfo->pszText, lpTbInfo->cchText, NULL, NULL ))
2726 lpTbInfo->pszText[lpTbInfo->cchText-1] = 0;
2728 else lpTbInfo->pszText[0]=0;
2735 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2738 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2739 TBUTTON_INFO *btnPtr;
2742 if (infoPtr == NULL)
2744 if (lpTbInfo == NULL)
2746 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2749 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2750 lpTbInfo->dwMask & 0x80000000);
2754 btnPtr = &infoPtr->buttons[nIndex];
2756 if (lpTbInfo->dwMask & TBIF_COMMAND)
2757 lpTbInfo->idCommand = btnPtr->idCommand;
2758 if (lpTbInfo->dwMask & TBIF_IMAGE)
2759 lpTbInfo->iImage = btnPtr->iBitmap;
2760 if (lpTbInfo->dwMask & TBIF_LPARAM)
2761 lpTbInfo->lParam = btnPtr->dwData;
2762 if (lpTbInfo->dwMask & TBIF_SIZE)
2763 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2764 if (lpTbInfo->dwMask & TBIF_STATE)
2765 lpTbInfo->fsState = btnPtr->fsState;
2766 if (lpTbInfo->dwMask & TBIF_STYLE)
2767 lpTbInfo->fsStyle = btnPtr->fsStyle;
2768 if (lpTbInfo->dwMask & TBIF_TEXT) {
2769 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2770 lstrcpynW (lpTbInfo->pszText,
2771 (LPWSTR)infoPtr->strings[btnPtr->iString],
2780 TOOLBAR_GetButtonSize (HWND hwnd)
2782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2784 if (infoPtr->nNumButtons > 0)
2785 return MAKELONG((WORD)infoPtr->nButtonWidth,
2786 (WORD)infoPtr->nButtonHeight);
2788 return MAKELONG(8,7);
2793 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2796 INT nIndex, nStringIndex;
2798 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2802 nStringIndex = infoPtr->buttons[nIndex].iString;
2804 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2806 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2812 return WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[nStringIndex], -1,
2813 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
2818 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2820 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2821 INT nIndex, nStringIndex;
2823 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2827 nStringIndex = infoPtr->buttons[nIndex].iString;
2829 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2831 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2837 strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
2839 return strlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
2843 /* << TOOLBAR_GetColorScheme >> */
2847 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2851 return (LRESULT)infoPtr->himlDis;
2855 inline static LRESULT
2856 TOOLBAR_GetExtendedStyle (HWND hwnd)
2858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2860 return infoPtr->dwExStyle;
2865 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2869 return (LRESULT)infoPtr->himlHot;
2874 TOOLBAR_GetHotItem (HWND hwnd)
2876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2878 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
2881 if (infoPtr->nHotItem < 0)
2884 return (LRESULT)infoPtr->nHotItem;
2889 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2891 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2893 return (LRESULT)infoPtr->himlDef;
2897 /* << TOOLBAR_GetInsertMark >> */
2898 /* << TOOLBAR_GetInsertMarkColor >> */
2902 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2905 TBUTTON_INFO *btnPtr;
2909 if (infoPtr == NULL)
2911 nIndex = (INT)wParam;
2912 btnPtr = &infoPtr->buttons[nIndex];
2913 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2915 lpRect = (LPRECT)lParam;
2918 if (btnPtr->fsState & TBSTATE_HIDDEN)
2921 lpRect->left = btnPtr->rect.left;
2922 lpRect->right = btnPtr->rect.right;
2923 lpRect->bottom = btnPtr->rect.bottom;
2924 lpRect->top = btnPtr->rect.top;
2931 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2934 LPSIZE lpSize = (LPSIZE)lParam;
2939 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2940 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2942 TRACE("maximum size %d x %d\n",
2943 infoPtr->rcBound.right - infoPtr->rcBound.left,
2944 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2950 /* << TOOLBAR_GetObject >> */
2951 /* << TOOLBAR_GetPadding >> */
2955 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2958 TBUTTON_INFO *btnPtr;
2962 if (infoPtr == NULL)
2964 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2965 btnPtr = &infoPtr->buttons[nIndex];
2966 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2968 lpRect = (LPRECT)lParam;
2972 lpRect->left = btnPtr->rect.left;
2973 lpRect->right = btnPtr->rect.right;
2974 lpRect->bottom = btnPtr->rect.bottom;
2975 lpRect->top = btnPtr->rect.top;
2982 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2986 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2987 return infoPtr->nRows;
2994 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2996 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2999 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3003 return infoPtr->buttons[nIndex].fsState;
3008 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3013 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3017 return infoPtr->buttons[nIndex].fsStyle;
3022 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3024 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3026 if (infoPtr == NULL)
3029 return infoPtr->nMaxTextRows;
3034 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3036 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3038 if (infoPtr == NULL)
3040 return infoPtr->hwndToolTip;
3045 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3049 TRACE("%s hwnd=0x%x stub!\n",
3050 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3052 return infoPtr->bUnicode;
3056 inline static LRESULT
3057 TOOLBAR_GetVersion (HWND hwnd)
3059 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3060 return infoPtr->iVersion;
3065 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3068 TBUTTON_INFO *btnPtr;
3073 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3077 btnPtr = &infoPtr->buttons[nIndex];
3078 if (LOWORD(lParam) == FALSE)
3079 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3081 btnPtr->fsState |= TBSTATE_HIDDEN;
3083 TOOLBAR_CalcToolbar (hwnd);
3085 InvalidateRect (hwnd, NULL, TRUE);
3091 inline static LRESULT
3092 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3094 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3099 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3102 TBUTTON_INFO *btnPtr;
3105 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3109 btnPtr = &infoPtr->buttons[nIndex];
3110 if (LOWORD(lParam) == FALSE)
3111 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3113 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3115 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3122 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3124 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3125 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3126 INT nIndex = (INT)wParam;
3127 TBUTTON_INFO *oldButtons;
3132 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3135 /* EPP: this seems to be an undocumented call (from my IE4)
3136 * I assume in that case that:
3137 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3138 * - index of insertion is at the end of existing buttons
3139 * I only see this happen with nIndex == -1, but it could have a special
3140 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3145 /* FIXME: iString == -1 is undocumented */
3146 if(lpTbb->iString && lpTbb->iString!=-1) {
3147 len = strlen((char*)lpTbb->iString) + 2;
3148 ptr = COMCTL32_Alloc(len);
3149 nIndex = infoPtr->nNumButtons;
3150 strcpy(ptr, (char*)lpTbb->iString);
3151 ptr[len - 1] = 0; /* ended by two '\0' */
3152 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3156 ERR("lpTbb->iString is NULL\n");
3160 } else if (nIndex < 0)
3163 TRACE("inserting button index=%d\n", nIndex);
3164 if (nIndex > infoPtr->nNumButtons) {
3165 nIndex = infoPtr->nNumButtons;
3166 TRACE("adjust index=%d\n", nIndex);
3169 oldButtons = infoPtr->buttons;
3170 infoPtr->nNumButtons++;
3171 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3172 /* pre insert copy */
3174 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3175 nIndex * sizeof(TBUTTON_INFO));
3178 /* insert new button */
3179 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3180 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3181 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3182 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3183 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3184 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3186 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3189 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3190 ti.cbSize = sizeof (TTTOOLINFOA);
3192 ti.uId = lpTbb->idCommand;
3194 ti.lpszText = LPSTR_TEXTCALLBACKA;
3196 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3200 /* post insert copy */
3201 if (nIndex < infoPtr->nNumButtons - 1) {
3202 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3203 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3206 COMCTL32_Free (oldButtons);
3208 TOOLBAR_CalcToolbar (hwnd);
3210 InvalidateRect (hwnd, NULL, FALSE);
3217 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3219 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3220 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3221 INT nIndex = (INT)wParam;
3222 TBUTTON_INFO *oldButtons;
3229 TRACE("inserting button index=%d\n", nIndex);
3230 if (nIndex > infoPtr->nNumButtons) {
3231 nIndex = infoPtr->nNumButtons;
3232 TRACE("adjust index=%d\n", nIndex);
3235 oldButtons = infoPtr->buttons;
3236 infoPtr->nNumButtons++;
3237 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3238 /* pre insert copy */
3240 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3241 nIndex * sizeof(TBUTTON_INFO));
3244 /* insert new button */
3245 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3246 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3247 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3248 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3249 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3250 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3252 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3255 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3256 ti.cbSize = sizeof (TTTOOLINFOW);
3258 ti.uId = lpTbb->idCommand;
3260 ti.lpszText = LPSTR_TEXTCALLBACKW;
3262 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3266 /* post insert copy */
3267 if (nIndex < infoPtr->nNumButtons - 1) {
3268 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3269 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3272 COMCTL32_Free (oldButtons);
3274 InvalidateRect (hwnd, NULL, FALSE);
3280 /* << TOOLBAR_InsertMarkHitTest >> */
3284 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3286 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3289 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3293 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3298 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3307 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3312 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3321 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3326 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3335 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3340 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3345 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3349 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3354 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3359 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3363 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3367 /* << TOOLBAR_LoadImages >> */
3368 /* << TOOLBAR_MapAccelerator >> */
3369 /* << TOOLBAR_MarkButton >> */
3370 /* << TOOLBAR_MoveButton >> */
3374 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3376 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3377 TBUTTON_INFO *btnPtr;
3380 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3384 btnPtr = &infoPtr->buttons[nIndex];
3385 if (LOWORD(lParam) == FALSE)
3386 btnPtr->fsState &= ~TBSTATE_PRESSED;
3388 btnPtr->fsState |= TBSTATE_PRESSED;
3390 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3396 /* << TOOLBAR_ReplaceBitmap >> */
3400 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3403 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3404 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3406 if (lpSave == NULL) return 0;
3409 /* save toolbar information */
3410 FIXME("save to \"%s\" \"%s\"\n",
3411 lpSave->pszSubKey, lpSave->pszValueName);
3416 /* restore toolbar information */
3418 FIXME("restore from \"%s\" \"%s\"\n",
3419 lpSave->pszSubKey, lpSave->pszValueName);
3430 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3433 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3434 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3440 /* save toolbar information */
3441 FIXME("save to \"%s\" \"%s\"\n",
3442 lpSave->pszSubKey, lpSave->pszValueName);
3447 /* restore toolbar information */
3449 FIXME("restore from \"%s\" \"%s\"\n",
3450 lpSave->pszSubKey, lpSave->pszValueName);
3461 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3464 BOOL bOldAnchor = infoPtr->bAnchor;
3466 infoPtr->bAnchor = (BOOL)wParam;
3468 return (LRESULT)bOldAnchor;
3473 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3475 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3477 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3480 if (infoPtr->nNumButtons > 0)
3481 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3482 infoPtr->nNumButtons,
3483 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3484 LOWORD(lParam), HIWORD(lParam));
3486 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3487 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3489 /* uses image list internals directly */
3490 if (infoPtr->himlDef) {
3491 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3492 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3500 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3503 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3504 TBUTTON_INFO *btnPtr;
3509 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3512 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3513 lptbbi->dwMask & 0x80000000);
3517 btnPtr = &infoPtr->buttons[nIndex];
3518 if (lptbbi->dwMask & TBIF_COMMAND)
3519 btnPtr->idCommand = lptbbi->idCommand;
3520 if (lptbbi->dwMask & TBIF_IMAGE)
3521 btnPtr->iBitmap = lptbbi->iImage;
3522 if (lptbbi->dwMask & TBIF_LPARAM)
3523 btnPtr->dwData = lptbbi->lParam;
3524 /* if (lptbbi->dwMask & TBIF_SIZE) */
3525 /* btnPtr->cx = lptbbi->cx; */
3526 if (lptbbi->dwMask & TBIF_STATE)
3527 btnPtr->fsState = lptbbi->fsState;
3528 if (lptbbi->dwMask & TBIF_STYLE)
3529 btnPtr->fsStyle = lptbbi->fsStyle;
3531 if (lptbbi->dwMask & TBIF_TEXT) {
3532 if ((btnPtr->iString >= 0) ||
3533 (btnPtr->iString < infoPtr->nNumStrings)) {
3534 TRACE("Ooooooch\n");
3536 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3537 INT len = lstrlenA (lptbbi->pszText);
3538 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3541 /* this is the ultimate sollution */
3542 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3551 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3554 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3555 TBUTTON_INFO *btnPtr;
3560 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3563 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3564 lptbbi->dwMask & 0x80000000);
3568 btnPtr = &infoPtr->buttons[nIndex];
3569 if (lptbbi->dwMask & TBIF_COMMAND)
3570 btnPtr->idCommand = lptbbi->idCommand;
3571 if (lptbbi->dwMask & TBIF_IMAGE)
3572 btnPtr->iBitmap = lptbbi->iImage;
3573 if (lptbbi->dwMask & TBIF_LPARAM)
3574 btnPtr->dwData = lptbbi->lParam;
3575 /* if (lptbbi->dwMask & TBIF_SIZE) */
3576 /* btnPtr->cx = lptbbi->cx; */
3577 if (lptbbi->dwMask & TBIF_STATE)
3578 btnPtr->fsState = lptbbi->fsState;
3579 if (lptbbi->dwMask & TBIF_STYLE)
3580 btnPtr->fsStyle = lptbbi->fsStyle;
3582 if (lptbbi->dwMask & TBIF_TEXT) {
3583 if ((btnPtr->iString >= 0) ||
3584 (btnPtr->iString < infoPtr->nNumStrings)) {
3586 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3587 INT len = lstrlenW (lptbbi->pszText);
3588 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3591 /* this is the ultimate solution */
3592 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3601 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3603 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3605 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3607 ERR("invalid parameter\n");
3611 /* The documentation claims you can only change the button size before
3612 * any button has been added. But this is wrong.
3613 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3614 * it to the toolbar, and it checks that the return value is nonzero - mjm
3615 * Further testing shows that we must actually perform the change too.
3617 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3618 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3624 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3628 if (infoPtr == NULL) {
3629 TRACE("Toolbar not initialized yet?????\n");
3633 /* if setting to current values, ignore */
3634 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3635 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3636 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3637 infoPtr->cxMin, infoPtr->cxMax);
3641 /* save new values */
3642 infoPtr->cxMin = (INT)LOWORD(lParam);
3643 infoPtr->cxMax = (INT)HIWORD(lParam);
3645 /* if both values are 0 then we are done */
3647 TRACE("setting both min and max to 0, norecalc\n");
3651 /* otherwise we need to recalc the toolbar and in some cases
3652 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3653 which doesn't actually draw - GA). */
3654 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3655 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3657 TOOLBAR_CalcToolbar (hwnd);
3659 InvalidateRect (hwnd, NULL, TRUE);
3666 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3669 INT nIndex = (INT)wParam;
3671 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3674 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3676 if (infoPtr->hwndToolTip) {
3678 FIXME("change tool tip!\n");
3686 /* << TOOLBAR_SetColorScheme >> */
3690 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3692 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3693 HIMAGELIST himlTemp;
3696 himlTemp = infoPtr->himlDis;
3697 infoPtr->himlDis = (HIMAGELIST)lParam;
3699 /* FIXME: redraw ? */
3701 return (LRESULT)himlTemp;
3706 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3711 dwTemp = infoPtr->dwDTFlags;
3712 infoPtr->dwDTFlags =
3713 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3715 return (LRESULT)dwTemp;
3720 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3725 dwTemp = infoPtr->dwExStyle;
3726 infoPtr->dwExStyle = (DWORD)lParam;
3728 return (LRESULT)dwTemp;
3733 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3735 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3736 HIMAGELIST himlTemp;
3738 himlTemp = infoPtr->himlHot;
3739 infoPtr->himlHot = (HIMAGELIST)lParam;
3741 /* FIXME: redraw ? */
3743 return (LRESULT)himlTemp;
3748 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3751 INT nOldHotItem = infoPtr->nHotItem;
3752 TBUTTON_INFO *btnPtr;
3754 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
3757 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
3760 infoPtr->nHotItem = (INT)wParam;
3761 if ((INT)wParam >=0)
3763 btnPtr = &infoPtr->buttons[(INT)wParam];
3764 btnPtr->bHot = TRUE;
3765 InvalidateRect (hwnd, &btnPtr->rect,
3766 TOOLBAR_HasText(infoPtr, btnPtr));
3770 btnPtr = &infoPtr->buttons[nOldHotItem];
3771 btnPtr->bHot = FALSE;
3772 InvalidateRect (hwnd, &btnPtr->rect,
3773 TOOLBAR_HasText(infoPtr, btnPtr));
3777 if (nOldHotItem < 0)
3780 return (LRESULT)nOldHotItem;
3785 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3787 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3788 HIMAGELIST himlTemp;
3790 himlTemp = infoPtr->himlDef;
3791 infoPtr->himlDef = (HIMAGELIST)lParam;
3793 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
3795 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
3796 &infoPtr->nBitmapHeight);
3797 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
3798 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
3799 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
3801 /* FIXME: redraw ? */
3803 return (LRESULT)himlTemp;
3808 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3810 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3812 infoPtr->nIndent = (INT)wParam;
3816 /* process only on indent changing */
3817 if(infoPtr->nIndent != (INT)wParam)
3819 infoPtr->nIndent = (INT)wParam;
3820 TOOLBAR_CalcToolbar (hwnd);
3821 InvalidateRect(hwnd, NULL, FALSE);
3828 /* << TOOLBAR_SetInsertMark >> */
3832 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3834 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3836 infoPtr->clrInsertMark = (COLORREF)lParam;
3838 /* FIXME : redraw ??*/
3845 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3849 if (infoPtr == NULL)
3852 infoPtr->nMaxTextRows = (INT)wParam;
3858 /* << TOOLBAR_SetPadding >> */
3862 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 if (infoPtr == NULL)
3871 hwndOldNotify = infoPtr->hwndNotify;
3872 infoPtr->hwndNotify = (HWND)wParam;
3874 return hwndOldNotify;
3879 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3882 LPRECT lprc = (LPRECT)lParam;
3886 if (LOWORD(wParam) > 1) {
3887 FIXME("multiple rows not supported!\n");
3890 if(infoPtr->nRows != LOWORD(wParam))
3892 infoPtr->nRows = LOWORD(wParam);
3894 /* recalculate toolbar */
3895 TOOLBAR_CalcToolbar (hwnd);
3897 /* repaint toolbar */
3898 InvalidateRect(hwnd, NULL, FALSE);
3901 /* return bounding rectangle */
3903 lprc->left = infoPtr->rcBound.left;
3904 lprc->right = infoPtr->rcBound.right;
3905 lprc->top = infoPtr->rcBound.top;
3906 lprc->bottom = infoPtr->rcBound.bottom;
3914 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3916 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3917 TBUTTON_INFO *btnPtr;
3920 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3924 btnPtr = &infoPtr->buttons[nIndex];
3926 /* if hidden state has changed the invalidate entire window and recalc */
3927 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
3928 btnPtr->fsState = LOWORD(lParam);
3929 TOOLBAR_CalcToolbar (hwnd);
3930 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
3934 /* process state changing if current state doesn't match new state */
3935 if(btnPtr->fsState != LOWORD(lParam))
3937 btnPtr->fsState = LOWORD(lParam);
3938 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3947 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3950 TBUTTON_INFO *btnPtr;
3953 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3957 btnPtr = &infoPtr->buttons[nIndex];
3959 /* process style change if current style doesn't match new style */
3960 if(btnPtr->fsStyle != LOWORD(lParam))
3962 btnPtr->fsStyle = LOWORD(lParam);
3963 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3966 if (infoPtr->hwndToolTip) {
3967 FIXME("change tool tip!\n");
3975 inline static LRESULT
3976 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3980 if (infoPtr == NULL)
3982 infoPtr->hwndToolTip = (HWND)wParam;
3988 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3990 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3993 TRACE("%s hwnd=0x%04x stub!\n",
3994 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3996 bTemp = infoPtr->bUnicode;
3997 infoPtr->bUnicode = (BOOL)wParam;
4004 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4006 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4007 INT iOldVersion = infoPtr->iVersion;
4009 infoPtr->iVersion = iVersion;
4016 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4018 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4019 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4022 /* initialize info structure */
4023 infoPtr->nButtonHeight = 22;
4024 infoPtr->nButtonWidth = 24;
4025 infoPtr->nBitmapHeight = 15;
4026 infoPtr->nBitmapWidth = 16;
4028 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4030 infoPtr->nMaxTextRows = 1;
4031 infoPtr->cxMin = -1;
4032 infoPtr->cxMax = -1;
4033 infoPtr->nNumBitmaps = 0;
4034 infoPtr->nNumStrings = 0;
4036 infoPtr->bCaptured = FALSE;
4037 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4038 infoPtr->nButtonDown = -1;
4039 infoPtr->nOldHit = -1;
4040 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4041 infoPtr->hwndNotify = GetParent (hwnd);
4042 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4043 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4044 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4045 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4046 infoPtr->iVersion = 0;
4047 infoPtr->bNtfUnicode = FALSE;
4048 infoPtr->hwndSelf = hwnd;
4050 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4051 infoPtr->hFont = CreateFontIndirectA (&logFont);
4053 if (dwStyle & TBSTYLE_TOOLTIPS) {
4054 /* Create tooltip control */
4055 infoPtr->hwndToolTip =
4056 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4057 CW_USEDEFAULT, CW_USEDEFAULT,
4058 CW_USEDEFAULT, CW_USEDEFAULT,
4061 /* Send NM_TOOLTIPSCREATED notification */
4062 if (infoPtr->hwndToolTip) {
4063 NMTOOLTIPSCREATED nmttc;
4065 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4067 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4068 NM_TOOLTIPSCREATED);
4072 TOOLBAR_CheckStyle (hwnd, dwStyle);
4074 TOOLBAR_CalcToolbar(hwnd);
4081 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4083 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4085 /* delete tooltip control */
4086 if (infoPtr->hwndToolTip)
4087 DestroyWindow (infoPtr->hwndToolTip);
4089 /* delete button data */
4090 if (infoPtr->buttons)
4091 COMCTL32_Free (infoPtr->buttons);
4093 /* delete strings */
4094 if (infoPtr->strings) {
4096 for (i = 0; i < infoPtr->nNumStrings; i++)
4097 if (infoPtr->strings[i])
4098 COMCTL32_Free (infoPtr->strings[i]);
4100 COMCTL32_Free (infoPtr->strings);
4103 /* destroy internal image list */
4104 if (infoPtr->himlInt)
4105 ImageList_Destroy (infoPtr->himlInt);
4107 /* delete default font */
4109 DeleteObject (infoPtr->hFont);
4111 /* free toolbar info data */
4112 COMCTL32_Free (infoPtr);
4113 SetWindowLongA (hwnd, 0, 0);
4120 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4123 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4124 NMTBCUSTOMDRAW tbcd;
4127 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4128 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4129 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4130 tbcd.nmcd.hdc = (HDC)wParam;
4131 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4132 /* FIXME: in general the return flags *can* be or'ed together */
4135 case CDRF_DODEFAULT:
4137 case CDRF_SKIPDEFAULT:
4140 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4145 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4146 * to my parent for processing.
4148 if (infoPtr->bTransparent) {
4150 HDC hdc = (HDC)wParam;
4155 parent = GetParent(hwnd);
4156 MapWindowPoints(hwnd, parent, &pt, 1);
4157 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4158 SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4159 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4162 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4164 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4165 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4166 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4167 tbcd.nmcd.hdc = (HDC)wParam;
4168 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4171 case CDRF_DODEFAULT:
4173 case CDRF_SKIPDEFAULT:
4176 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4185 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4187 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4189 return infoPtr->hFont;
4194 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4196 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4197 TBUTTON_INFO *btnPtr;
4201 pt.x = (INT)LOWORD(lParam);
4202 pt.y = (INT)HIWORD(lParam);
4203 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4206 btnPtr = &infoPtr->buttons[nHit];
4207 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4210 infoPtr->bCaptured = TRUE;
4211 infoPtr->nButtonDown = nHit;
4213 btnPtr->fsState |= TBSTATE_PRESSED;
4215 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4218 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4219 TOOLBAR_Customize (hwnd);
4226 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4229 TBUTTON_INFO *btnPtr;
4234 if (infoPtr->hwndToolTip)
4235 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4236 WM_LBUTTONDOWN, wParam, lParam);
4238 pt.x = (INT)LOWORD(lParam);
4239 pt.y = (INT)HIWORD(lParam);
4240 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4244 btnPtr = &infoPtr->buttons[nHit];
4245 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4248 infoPtr->nOldHit = nHit;
4250 CopyRect(&arrowRect, &btnPtr->rect);
4251 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4253 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4254 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4255 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4256 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4260 * this time we must force a Redraw, so the btn is
4261 * painted down before CaptureChanged repaints it up
4263 RedrawWindow(hwnd,&btnPtr->rect,0,
4264 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4266 nmtb.iItem = btnPtr->idCommand;
4267 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4270 memset(&nmtb.rcButton, 0, sizeof(RECT));
4271 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4273 if (res != TBDDRET_TREATPRESSED)
4274 /* ??? guess (GA) */
4276 /* otherwise drop through and process as pushed */
4278 /* SetCapture (hwnd); */
4279 infoPtr->bCaptured = TRUE;
4280 infoPtr->nButtonDown = nHit;
4282 btnPtr->fsState |= TBSTATE_PRESSED;
4283 btnPtr->bHot = FALSE;
4285 InvalidateRect(hwnd, &btnPtr->rect,
4286 TOOLBAR_HasText(infoPtr, btnPtr));
4290 /* native issues the TBN_BEGINDRAG here */
4291 nmtb.iItem = btnPtr->idCommand;
4292 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4293 nmtb.tbButton.idCommand = btnPtr->idCommand;
4294 nmtb.tbButton.fsState = btnPtr->fsState;
4295 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4296 nmtb.tbButton.dwData = btnPtr->dwData;
4297 nmtb.tbButton.iString = btnPtr->iString;
4298 nmtb.cchText = 0; /* !!! not correct */
4299 nmtb.pszText = 0; /* !!! not correct */
4300 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4308 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4310 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4311 TBUTTON_INFO *btnPtr;
4315 BOOL bSendMessage = TRUE;
4320 if (infoPtr->hwndToolTip)
4321 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4322 WM_LBUTTONUP, wParam, lParam);
4324 pt.x = (INT)LOWORD(lParam);
4325 pt.y = (INT)HIWORD(lParam);
4326 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4328 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4329 /* if the cursor is still inside of the toolbar */
4330 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4331 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4333 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
4334 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4335 btnPtr->fsState &= ~TBSTATE_PRESSED;
4337 if (nHit == infoPtr->nButtonDown) {
4338 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4339 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4340 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4341 infoPtr->nButtonDown);
4342 if (nOldIndex == infoPtr->nButtonDown)
4343 bSendMessage = FALSE;
4344 if ((nOldIndex != infoPtr->nButtonDown) &&
4346 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4347 btnPtr->fsState |= TBSTATE_CHECKED;
4350 if (btnPtr->fsState & TBSTATE_CHECKED)
4351 btnPtr->fsState &= ~TBSTATE_CHECKED;
4353 btnPtr->fsState |= TBSTATE_CHECKED;
4358 bSendMessage = FALSE;
4360 if (nOldIndex != -1)
4362 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4363 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4367 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4368 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4369 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4373 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4374 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4375 NM_RELEASEDCAPTURE);
4377 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4380 nmtb.iItem = btnPtr->idCommand;
4381 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4382 nmtb.tbButton.idCommand = btnPtr->idCommand;
4383 nmtb.tbButton.fsState = btnPtr->fsState;
4384 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4385 nmtb.tbButton.dwData = btnPtr->dwData;
4386 nmtb.tbButton.iString = btnPtr->iString;
4387 nmtb.cchText = 0; /* !!! not correct */
4388 nmtb.pszText = 0; /* !!! not correct */
4389 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4393 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4394 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
4396 /* !!! Undocumented - toolbar at 4.71 level and above sends
4397 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4398 * Only NM_RCLICK is documented.
4400 nmmouse.dwItemSpec = btnPtr->idCommand;
4401 nmmouse.dwItemData = btnPtr->dwData;
4402 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4410 TOOLBAR_CaptureChanged(HWND hwnd)
4412 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4413 TBUTTON_INFO *btnPtr;
4415 infoPtr->bCaptured = FALSE;
4417 if (infoPtr->nButtonDown >= 0)
4419 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4420 btnPtr->fsState &= ~TBSTATE_PRESSED;
4422 infoPtr->nButtonDown = -1;
4423 infoPtr->nOldHit = -1;
4425 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4432 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4434 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4435 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4438 if (infoPtr->nOldHit < 0)
4441 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4443 /* Redraw the button if the last button we were over is the hot button and it
4445 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4447 hotBtnPtr->bHot = FALSE;
4448 rc1 = hotBtnPtr->rect;
4449 InflateRect (&rc1, 1, 1);
4450 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4454 /* If the last button we were over is depressed then make it not */
4455 /* depressed and redraw it */
4456 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4458 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4460 btnPtr->fsState &= ~TBSTATE_PRESSED;
4462 rc1 = hotBtnPtr->rect;
4463 InflateRect (&rc1, 1, 1);
4464 InvalidateRect (hwnd, &rc1, TRUE);
4467 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4468 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4474 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4476 TBUTTON_INFO *btnPtr, *oldBtnPtr;
4477 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4480 TRACKMOUSEEVENT trackinfo;
4482 /* fill in the TRACKMOUSEEVENT struct */
4483 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4484 trackinfo.dwFlags = TME_QUERY;
4485 trackinfo.hwndTrack = hwnd;
4486 trackinfo.dwHoverTime = HOVER_DEFAULT;
4488 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4489 _TrackMouseEvent(&trackinfo);
4491 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4492 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4493 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4495 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4496 /* and can properly deactivate the hot toolbar button */
4497 _TrackMouseEvent(&trackinfo);
4500 if (infoPtr->hwndToolTip)
4501 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4502 WM_MOUSEMOVE, wParam, lParam);
4504 pt.x = (INT)LOWORD(lParam);
4505 pt.y = (INT)HIWORD(lParam);
4507 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4509 if (infoPtr->nOldHit != nHit)
4511 /* Remove the effect of an old hot button if the button was enabled and was
4512 drawn with the hot button effect */
4513 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
4514 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
4516 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4517 oldBtnPtr->bHot = FALSE;
4519 InvalidateRect (hwnd, &oldBtnPtr->rect,
4520 TOOLBAR_HasText(infoPtr, oldBtnPtr));
4523 /* It's not a separator or in nowhere. It's a hot button. */
4526 btnPtr = &infoPtr->buttons[nHit];
4528 infoPtr->nHotItem = nHit;
4530 /* only enabled buttons show hot effect */
4531 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
4533 btnPtr->bHot = TRUE;
4534 InvalidateRect(hwnd, &btnPtr->rect,
4535 TOOLBAR_HasText(infoPtr, btnPtr));
4540 if (infoPtr->bCaptured) {
4541 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4542 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
4543 btnPtr->fsState &= ~TBSTATE_PRESSED;
4544 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4546 else if (nHit == infoPtr->nButtonDown) {
4547 btnPtr->fsState |= TBSTATE_PRESSED;
4548 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4551 infoPtr->nOldHit = nHit;
4557 inline static LRESULT
4558 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4560 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
4561 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
4563 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
4567 inline static LRESULT
4568 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4570 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
4571 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
4573 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
4578 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4580 TOOLBAR_INFO *infoPtr;
4581 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
4584 /* allocate memory for info structure */
4585 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
4586 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4589 infoPtr->dwStructSize = sizeof(TBBUTTON);
4591 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
4592 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
4593 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
4594 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
4597 /* native control does:
4598 * Get a lot of colors and brushes
4600 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
4601 * CreateFontIndirectA(adr1)
4602 * CreateBitmap(0x27, 0x24, 1, 1, 0)
4603 * hdc = GetDC(toolbar)
4604 * GetSystemMetrics(0x48)
4605 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
4606 * 0, 0, 0, 0, "MARLETT")
4607 * oldfnt = SelectObject(hdc, fnt2)
4608 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
4609 * GetTextMetricsA(hdc, adr3)
4610 * SelectObject(hdc, oldfnt)
4611 * DeleteObject(fnt2)
4613 * InvalidateRect(toolbar, 0, 1)
4614 * SetWindowLongA(toolbar, 0, addr)
4615 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
4618 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
4619 * ie 2 0x4600094c 0x4600094c 0x4600894d
4620 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
4621 * rebar 0x50008844 0x40008844 0x50008845
4622 * pager 0x50000844 0x40000844 0x50008845
4623 * IC35mgr 0x5400084e **nochange**
4624 * on entry to _NCCREATE 0x5400084e
4625 * rowlist 0x5400004e **nochange**
4626 * on entry to _NCCREATE 0x5400004e
4630 /* I think the code below is a bug, but it is the way that the native
4631 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
4632 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
4633 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
4634 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
4635 * Some how, the only cases of this seem to be MFC programs.
4637 * Note also that the addition of _TRANSPARENT occurs *only* here. It
4638 * does not occur in the WM_STYLECHANGING routine.
4639 * (Guy Albertelli 9/2001)
4642 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
4643 styleadd |= TBSTYLE_TRANSPARENT;
4644 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
4645 styleadd |= CCS_TOP; /* default to top */
4646 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
4649 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
4654 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
4656 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4660 if (dwStyle & WS_MINIMIZE)
4661 return 0; /* Nothing to do */
4663 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
4665 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
4668 if (!(dwStyle & CCS_NODIVIDER))
4670 GetWindowRect (hwnd, &rcWindow);
4671 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4672 if( dwStyle & WS_BORDER )
4673 OffsetRect (&rcWindow, 1, 1);
4674 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
4677 ReleaseDC( hwnd, hdc );
4683 inline static LRESULT
4684 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
4686 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4687 LPNMHDR lpnmh = (LPNMHDR)lParam;
4689 if (lpnmh->code == PGN_CALCSIZE) {
4690 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
4692 if (lppgc->dwFlag == PGF_CALCWIDTH) {
4693 lppgc->iWidth = infoPtr->nWidth;
4694 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
4698 lppgc->iHeight = infoPtr->nHeight;
4699 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
4706 TRACE("passing WM_NOTIFY!\n");
4708 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
4709 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
4712 if (lpnmh->code == TTN_GETDISPINFOA) {
4713 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
4715 FIXME("retrieving ASCII string\n");
4718 else if (lpnmh->code == TTN_GETDISPINFOW) {
4719 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
4721 FIXME("retrieving UNICODE string\n");
4732 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
4734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4738 /* fill ps.rcPaint with a default rect */
4739 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
4741 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
4743 TRACE("psrect=(%d,%d)-(%d,%d)\n",
4744 ps.rcPaint.left, ps.rcPaint.top,
4745 ps.rcPaint.right, ps.rcPaint.bottom);
4747 TOOLBAR_Refresh (hwnd, hdc, &ps);
4748 if (!wParam) EndPaint (hwnd, &ps);
4755 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
4757 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4758 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4767 /* Resize deadlock check */
4768 if (infoPtr->bAutoSize) {
4769 infoPtr->bAutoSize = FALSE;
4773 /* FIXME: optimize to only update size if the new size doesn't */
4774 /* match the current size */
4776 flags = (INT) wParam;
4778 /* FIXME for flags =
4779 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
4782 TRACE("sizing toolbar!\n");
4784 if (flags == SIZE_RESTORED) {
4785 /* width and height don't apply */
4786 parent = GetParent (hwnd);
4787 GetClientRect(parent, &parent_rect);
4788 x = parent_rect.left;
4789 y = parent_rect.top;
4791 if (dwStyle & CCS_NORESIZE) {
4792 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
4795 * this sets the working width of the toolbar, and
4796 * Calc Toolbar will not adjust it, only the height
4798 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4799 cy = infoPtr->nHeight;
4800 cx = infoPtr->nWidth;
4801 TOOLBAR_CalcToolbar (hwnd);
4802 infoPtr->nWidth = cx;
4803 infoPtr->nHeight = cy;
4806 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4807 TOOLBAR_CalcToolbar (hwnd);
4808 cy = infoPtr->nHeight;
4809 cx = infoPtr->nWidth;
4811 if (dwStyle & CCS_NOMOVEY) {
4812 GetWindowRect(hwnd, &window_rect);
4813 ScreenToClient(parent, (LPPOINT)&window_rect.left);
4814 y = window_rect.top;
4818 if (dwStyle & CCS_NOPARENTALIGN) {
4819 uPosFlags |= SWP_NOMOVE;
4820 cy = infoPtr->nHeight;
4821 cx = infoPtr->nWidth;
4824 if (!(dwStyle & CCS_NODIVIDER))
4825 cy += GetSystemMetrics(SM_CYEDGE);
4827 if (dwStyle & WS_BORDER)
4830 cy += GetSystemMetrics(SM_CYEDGE);
4831 cx += GetSystemMetrics(SM_CYEDGE);
4834 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
4835 cx, cy, uPosFlags | SWP_NOZORDER);
4842 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
4844 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4846 if (nType == GWL_STYLE) {
4847 if (lpStyle->styleNew & TBSTYLE_LIST) {
4848 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
4851 infoPtr->dwDTFlags = DT_CENTER;
4853 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
4854 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
4855 (TBSTYLE_FLAT | TBSTYLE_LIST));
4856 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
4859 TOOLBAR_AutoSize (hwnd);
4861 InvalidateRect(hwnd, NULL, FALSE);
4868 static LRESULT WINAPI
4869 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4871 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4872 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4874 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
4875 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
4880 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
4882 case TB_ADDBUTTONSA:
4883 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
4885 case TB_ADDBUTTONSW:
4886 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
4889 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
4892 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
4895 return TOOLBAR_AutoSize (hwnd);
4897 case TB_BUTTONCOUNT:
4898 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
4900 case TB_BUTTONSTRUCTSIZE:
4901 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
4903 case TB_CHANGEBITMAP:
4904 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
4906 case TB_CHECKBUTTON:
4907 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
4909 case TB_COMMANDTOINDEX:
4910 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
4913 return TOOLBAR_Customize (hwnd);
4915 case TB_DELETEBUTTON:
4916 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
4918 case TB_ENABLEBUTTON:
4919 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
4921 case TB_GETANCHORHIGHLIGHT:
4922 return TOOLBAR_GetAnchorHighlight (hwnd);
4925 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
4927 case TB_GETBITMAPFLAGS:
4928 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
4931 return TOOLBAR_GetButton (hwnd, wParam, lParam);
4933 case TB_GETBUTTONINFOA:
4934 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
4936 case TB_GETBUTTONINFOW:
4937 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
4939 case TB_GETBUTTONSIZE:
4940 return TOOLBAR_GetButtonSize (hwnd);
4942 case TB_GETBUTTONTEXTA:
4943 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
4945 case TB_GETBUTTONTEXTW:
4946 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
4948 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
4950 case TB_GETDISABLEDIMAGELIST:
4951 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
4953 case TB_GETEXTENDEDSTYLE:
4954 return TOOLBAR_GetExtendedStyle (hwnd);
4956 case TB_GETHOTIMAGELIST:
4957 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
4960 return TOOLBAR_GetHotItem (hwnd);
4962 case TB_GETIMAGELIST:
4963 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
4965 /* case TB_GETINSERTMARK: */ /* 4.71 */
4966 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
4968 case TB_GETITEMRECT:
4969 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
4972 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
4974 /* case TB_GETOBJECT: */ /* 4.71 */
4975 /* case TB_GETPADDING: */ /* 4.71 */
4978 return TOOLBAR_GetRect (hwnd, wParam, lParam);
4981 return TOOLBAR_GetRows (hwnd, wParam, lParam);
4984 return TOOLBAR_GetState (hwnd, wParam, lParam);
4987 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
4989 case TB_GETTEXTROWS:
4990 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
4992 case TB_GETTOOLTIPS:
4993 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
4995 case TB_GETUNICODEFORMAT:
4996 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
4998 case CCM_GETVERSION:
4999 return TOOLBAR_GetVersion (hwnd);
5002 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5005 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5007 case TB_INDETERMINATE:
5008 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5010 case TB_INSERTBUTTONA:
5011 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5013 case TB_INSERTBUTTONW:
5014 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5016 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5018 case TB_ISBUTTONCHECKED:
5019 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5021 case TB_ISBUTTONENABLED:
5022 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5024 case TB_ISBUTTONHIDDEN:
5025 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5027 case TB_ISBUTTONHIGHLIGHTED:
5028 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5030 case TB_ISBUTTONINDETERMINATE:
5031 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5033 case TB_ISBUTTONPRESSED:
5034 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5036 case TB_LOADIMAGES: /* 4.70 */
5037 FIXME("missing standard imagelists\n");
5040 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5041 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5042 /* case TB_MARKBUTTON: */ /* 4.71 */
5043 /* case TB_MOVEBUTTON: */ /* 4.71 */
5045 case TB_PRESSBUTTON:
5046 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5048 /* case TB_REPLACEBITMAP: */
5050 case TB_SAVERESTOREA:
5051 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5053 case TB_SAVERESTOREW:
5054 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5056 case TB_SETANCHORHIGHLIGHT:
5057 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5059 case TB_SETBITMAPSIZE:
5060 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5062 case TB_SETBUTTONINFOA:
5063 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5065 case TB_SETBUTTONINFOW:
5066 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5068 case TB_SETBUTTONSIZE:
5069 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5071 case TB_SETBUTTONWIDTH:
5072 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5075 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5077 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
5079 case TB_SETDISABLEDIMAGELIST:
5080 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5082 case TB_SETDRAWTEXTFLAGS:
5083 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5085 case TB_SETEXTENDEDSTYLE:
5086 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5088 case TB_SETHOTIMAGELIST:
5089 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5092 return TOOLBAR_SetHotItem (hwnd, wParam);
5094 case TB_SETIMAGELIST:
5095 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5098 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5100 /* case TB_SETINSERTMARK: */ /* 4.71 */
5102 case TB_SETINSERTMARKCOLOR:
5103 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5105 case TB_SETMAXTEXTROWS:
5106 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5108 /* case TB_SETPADDING: */ /* 4.71 */
5111 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5114 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5117 return TOOLBAR_SetState (hwnd, wParam, lParam);
5120 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5122 case TB_SETTOOLTIPS:
5123 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5125 case TB_SETUNICODEFORMAT:
5126 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5128 case CCM_SETVERSION:
5129 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5135 return TOOLBAR_Create (hwnd, wParam, lParam);
5138 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5141 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5144 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5146 /* case WM_KEYDOWN: */
5147 /* case WM_KILLFOCUS: */
5149 case WM_LBUTTONDBLCLK:
5150 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5152 case WM_LBUTTONDOWN:
5153 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5156 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5159 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5162 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5164 case WM_CAPTURECHANGED:
5165 return TOOLBAR_CaptureChanged(hwnd);
5168 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5171 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5174 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5177 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5180 return TOOLBAR_Notify (hwnd, wParam, lParam);
5182 /* case WM_NOTIFYFORMAT: */
5185 return TOOLBAR_Paint (hwnd, wParam);
5188 return TOOLBAR_Size (hwnd, wParam, lParam);
5190 case WM_STYLECHANGED:
5191 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5193 /* case WM_SYSCOLORCHANGE: */
5195 /* case WM_WININICHANGE: */
5200 case WM_MEASUREITEM:
5203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5205 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5207 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5211 if (uMsg >= WM_USER)
5212 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5213 uMsg, wParam, lParam);
5214 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5221 TOOLBAR_Register (void)
5225 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5226 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5227 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5228 wndClass.cbClsExtra = 0;
5229 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5230 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5231 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5232 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5234 RegisterClassA (&wndClass);
5239 TOOLBAR_Unregister (void)
5241 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);