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 */
99 HFONT hFont; /* text font */
100 HIMAGELIST himlInt; /* image list created internally */
101 HIMAGELIST himlDef; /* default image list */
102 HIMAGELIST himlHot; /* hot image list */
103 HIMAGELIST himlDis; /* disabled image list */
104 HWND hwndToolTip; /* handle to tool tip control */
105 HWND hwndNotify; /* handle to the window that gets notifications */
106 HWND hwndSelf; /* my own handle */
107 BOOL bTransparent; /* background transparency flag */
108 BOOL bBtnTranspnt; /* button transparency flag */
109 BOOL bAutoSize; /* auto size deadlock indicator */
110 BOOL bAnchor; /* anchor highlight enabled */
111 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
112 BOOL bDoRedraw; /* Redraw status */
113 DWORD dwExStyle; /* extended toolbar style */
114 DWORD dwDTFlags; /* DrawText flags */
116 COLORREF clrInsertMark; /* insert mark color */
117 RECT rcBound; /* bounding rectangle */
120 TBUTTON_INFO *buttons; /* pointer to button array */
121 LPWSTR *strings; /* pointer to string array */
122 } TOOLBAR_INFO, *PTOOLBAR_INFO;
125 /* used by customization dialog */
128 PTOOLBAR_INFO tbInfo;
130 } CUSTDLG_INFO, *PCUSTDLG_INFO;
138 } CUSTOMBUTTON, *PCUSTOMBUTTON;
141 #define SEPARATOR_WIDTH 8
143 #define BOTTOM_BORDER 2
144 #define DDARROW_WIDTH 11
146 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
147 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
148 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
152 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
154 LPWSTR lpText = NULL;
156 /* FIXME: iString == -1 is undocumented */
157 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
158 lpText = (LPWSTR)btnPtr->iString;
159 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
160 lpText = infoPtr->strings[btnPtr->iString];
166 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
168 if (TRACE_ON(toolbar)){
169 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=%x\n",
170 btn_num, bP->idCommand,
171 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
172 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
174 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
175 btn_num, bP->idCommand,
176 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
177 bP->rect.left, bP->rect.top,
178 bP->rect.right, bP->rect.bottom);
184 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
186 if (TRACE_ON(toolbar)) {
190 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
191 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
193 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
194 iP->nNumStrings, dwStyle);
195 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
197 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
198 (iP->bDoRedraw) ? "TRUE" : "FALSE");
199 for(i=0; i<iP->nNumButtons; i++) {
200 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
206 /***********************************************************************
209 * This function validates that the styles set are implemented and
210 * issues FIXME's warning of possible problems. In a perfect world this
211 * function should be null.
214 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
216 if (dwStyle & TBSTYLE_ALTDRAG)
217 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
218 if (dwStyle & TBSTYLE_REGISTERDROP)
219 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
224 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
226 if(!IsWindow(infoPtr->hwndSelf))
227 return 0; /* we have just been destroyed */
229 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
230 nmhdr->hwndFrom = infoPtr->hwndSelf;
233 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
234 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
236 if (infoPtr->bNtfUnicode)
237 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
238 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
240 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
241 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
244 /***********************************************************************
245 * TOOLBAR_GetBitmapIndex
247 * This function returns the bitmap index associated with a button.
248 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
249 * is issued to retrieve the index.
252 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
254 INT ret = btnPtr->iBitmap;
256 if (ret == I_IMAGECALLBACK) {
257 /* issue TBN_GETDISPINFO */
260 nmgd.idCommand = btnPtr->idCommand;
261 nmgd.lParam = btnPtr->dwData;
262 nmgd.dwMask = TBNF_IMAGE;
263 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
264 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
266 if (nmgd.dwMask & TBNF_DI_SETITEM) {
267 btnPtr->iBitmap = nmgd.iImage;
270 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
271 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
278 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
280 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
281 (index == I_IMAGECALLBACK))
288 /***********************************************************************
289 * TOOLBAR_DrawImageList
291 * This function validates the bitmap index (including I_IMAGECALLBACK
292 * functionality). It then draws the image via the ImageList_Draw
293 * function. It returns TRUE if the image was drawn, FALSE otherwise.
296 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
297 HDC hdc, UINT left, UINT top, UINT draw_flags)
301 if (!himl) return FALSE;
303 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
304 ERR("index %d is not valid, max %d\n",
305 btnPtr->iBitmap, infoPtr->nNumBitmaps);
309 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
310 if (index == -1) return FALSE;
311 ERR("TBN_GETDISPINFO returned invalid index %d\n",
315 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
316 index, himl, left, top, draw_flags);
318 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
323 /***********************************************************************
324 * TOOLBAR_TestImageExist
326 * This function is similar to TOOLBAR_DrawImageList, except it does not
327 * draw the image. The I_IMAGECALLBACK functionality is implemented.
330 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
334 if (!himl) return FALSE;
336 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
337 ERR("index %d is not valid, max %d\n",
338 btnPtr->iBitmap, infoPtr->nNumBitmaps);
342 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
343 if (index == -1) return FALSE;
344 ERR("TBN_GETDISPINFO returned invalid index %d\n",
353 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
355 INT x = (lpRect->left + lpRect->right) / 2 - 1;
356 INT yBottom = lpRect->bottom - 3;
357 INT yTop = lpRect->top + 1;
359 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
360 MoveToEx (hdc, x, yBottom, NULL);
361 LineTo (hdc, x, yTop);
363 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
364 MoveToEx (hdc, x, yBottom, NULL);
365 LineTo (hdc, x, yTop);
369 /***********************************************************************
370 * TOOLBAR_DrawDDFlatSeparator
372 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
373 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
374 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
375 * are horizontal as opposed to the vertical separators for not dropdown
378 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
381 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr)
384 COLORREF oldcolor, newcolor;
386 myrect.left = lpRect->left;
387 myrect.right = lpRect->right;
388 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
389 myrect.bottom = myrect.top + 1;
391 InflateRect (&myrect, -2, 0);
393 TRACE("rect=(%d,%d)-(%d,%d)\n",
394 myrect.left, myrect.top, myrect.right, myrect.bottom);
396 newcolor = GetSysColor (COLOR_BTNSHADOW);
397 oldcolor = SetBkColor (hdc, newcolor);
398 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
400 myrect.top = myrect.bottom;
401 myrect.bottom = myrect.top + 1;
403 newcolor = GetSysColor (COLOR_BTNHIGHLIGHT);
404 SetBkColor (hdc, newcolor);
405 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
407 SetBkColor (hdc, oldcolor);
412 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
415 SelectObject ( hdc, GetSysColorPen (colorRef));
418 MoveToEx (hdc, x, y, NULL);
419 LineTo (hdc, x+5, y++); x++;
420 MoveToEx (hdc, x, y, NULL);
421 LineTo (hdc, x+3, y++); x++;
422 MoveToEx (hdc, x, y, NULL);
423 LineTo (hdc, x+1, y++);
427 * Draw the text string for this button.
428 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
429 * is non-zero, so we can simply check himlDef to see if we have
433 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
434 HDC hdc, INT nState, DWORD dwStyle)
436 RECT rcText = btnPtr->rect;
439 LPWSTR lpText = NULL;
440 HIMAGELIST himl = infoPtr->himlDef;
442 TRACE ("iString: %x\n", btnPtr->iString);
444 /* get a pointer to the text */
445 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
447 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
452 InflateRect (&rcText, -3, -3);
454 if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
455 /* The following test looked like this before
456 * I changed it. IE4 "Links" toolbar would not
457 * draw correctly with the original code. - GA 8/01
458 * ((dwStyle & TBSTYLE_LIST) &&
459 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
460 * (btnPtr->iBitmap != I_IMAGENONE))
462 if (dwStyle & TBSTYLE_LIST) {
463 /* LIST style w/ ICON offset is by matching native. */
464 /* Matches IE4 "Links" bar. - GA 8/01 */
465 rcText.left += (infoPtr->nBitmapWidth + 2);
468 rcText.top += infoPtr->nBitmapHeight + 1;
472 if (dwStyle & TBSTYLE_LIST) {
473 /* LIST style w/o ICON offset is by matching native. */
474 /* Matches IE4 "menu" bar. - GA 8/01 */
479 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
480 OffsetRect (&rcText, 1, 1);
482 TRACE("string rect=(%d,%d)-(%d,%d)\n",
483 rcText.left, rcText.top, rcText.right, rcText.bottom);
485 hOldFont = SelectObject (hdc, infoPtr->hFont);
486 if (!(nState & TBSTATE_ENABLED)) {
487 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
488 OffsetRect (&rcText, 1, 1);
489 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
490 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
491 OffsetRect (&rcText, -1, -1);
492 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
494 else if (nState & TBSTATE_INDETERMINATE) {
495 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
496 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
499 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
500 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
503 SetTextColor (hdc, clrOld);
504 SelectObject (hdc, hOldFont);
510 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
512 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
513 INT cx = lpRect->right - lpRect->left;
514 INT cy = lpRect->bottom - lpRect->top;
515 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
516 SelectObject (hdc, hbr);
521 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
522 HDC hdc, INT x, INT y)
524 /* FIXME: this function is a hack since it uses image list
525 internals directly */
527 HIMAGELIST himl = infoPtr->himlDef;
535 /* create new dc's */
536 hdcImageList = CreateCompatibleDC (0);
537 hdcMask = CreateCompatibleDC (0);
539 /* create new bitmap */
540 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
541 SelectObject (hdcMask, hbmMask);
543 /* copy the mask bitmap */
544 SelectObject (hdcImageList, himl->hbmMask);
545 SetBkColor (hdcImageList, RGB(255, 255, 255));
546 SetTextColor (hdcImageList, RGB(0, 0, 0));
547 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
548 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
550 /* draw the new mask */
551 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
552 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
553 hdcMask, 0, 0, 0xB8074A);
555 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
556 BitBlt (hdc, x, y, himl->cx, himl->cy,
557 hdcMask, 0, 0, 0xB8074A);
559 DeleteObject (hbmMask);
561 DeleteDC (hdcImageList);
566 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
568 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
569 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
570 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
571 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
572 RECT rc, rcArrow, rcBitmap;
574 if (btnPtr->fsState & TBSTATE_HIDDEN)
578 CopyRect (&rcArrow, &rc);
579 CopyRect(&rcBitmap, &rc);
581 if (!infoPtr->bBtnTranspnt)
582 FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
584 if (hasDropDownArrow)
586 if (dwStyle & TBSTYLE_FLAT)
587 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
589 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
590 rcArrow.left = rc.right;
593 /* Center the bitmap horizontally and vertically */
594 if (dwStyle & TBSTYLE_LIST)
597 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
599 if(TOOLBAR_HasText(infoPtr, btnPtr))
600 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
602 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
604 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
605 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
606 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
609 if (btnPtr->fsStyle & TBSTYLE_SEP) {
610 /* with the FLAT style, iBitmap is the width and has already */
611 /* been taken into consideration in calculating the width */
612 /* so now we need to draw the vertical separator */
613 /* empirical tests show that iBitmap can/will be non-zero */
614 /* when drawing the vertical bar... */
615 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
616 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
617 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr);
619 TOOLBAR_DrawFlatSeparator (&rc, hdc);
625 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
626 if (!(dwStyle & TBSTYLE_FLAT))
628 DrawEdge (hdc, &rc, EDGE_RAISED,
629 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
630 if (hasDropDownArrow)
631 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
632 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
635 if (hasDropDownArrow)
637 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
638 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
641 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
642 hdc, rcBitmap.left, rcBitmap.top,
644 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
646 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
650 /* pressed TBSTYLE_BUTTON */
651 if (btnPtr->fsState & TBSTATE_PRESSED) {
652 if (dwStyle & TBSTYLE_FLAT)
654 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
655 if (hasDropDownArrow)
656 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
660 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
661 if (hasDropDownArrow)
662 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
665 if (hasDropDownArrow)
666 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
668 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
669 hdc, rcBitmap.left+1, rcBitmap.top+1,
672 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
676 /* checked TBSTYLE_CHECK */
677 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
678 (btnPtr->fsState & TBSTATE_CHECKED)) {
679 if (dwStyle & TBSTYLE_FLAT)
680 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
681 BF_RECT | BF_ADJUST);
683 DrawEdge (hdc, &rc, EDGE_SUNKEN,
684 BF_RECT | BF_MIDDLE | BF_ADJUST);
686 TOOLBAR_DrawPattern (hdc, &rc);
688 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
689 hdc, rcBitmap.left+1, rcBitmap.top+1,
692 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
697 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
698 DrawEdge (hdc, &rc, EDGE_RAISED,
699 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
701 TOOLBAR_DrawPattern (hdc, &rc);
702 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
703 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
708 if (dwStyle & TBSTYLE_FLAT)
712 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
713 if (hasDropDownArrow)
714 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
717 else /* The following code needs to be removed after
718 * "hot item" support has been implemented for the
719 * case where it is being de-selected.
722 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
723 if (hasDropDownArrow)
724 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
728 if (hasDropDownArrow)
729 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
732 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
733 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
736 rcBitmap.top, ILD_NORMAL))
737 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
738 hdc, rcBitmap.left, rcBitmap.top,
742 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
743 hdc, rcBitmap.left, rcBitmap.top,
748 DrawEdge (hdc, &rc, EDGE_RAISED,
749 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
751 if (hasDropDownArrow)
753 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
754 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
755 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
758 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
759 hdc, rcBitmap.left, rcBitmap.top,
763 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
768 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
770 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
771 TBUTTON_INFO *btnPtr;
772 INT i, oldBKmode = 0;
775 /* if imagelist belongs to the app, it can be changed
776 by the app after setting it */
777 if (infoPtr->himlDef != infoPtr->himlInt)
778 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
780 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
782 if (infoPtr->bBtnTranspnt)
783 oldBKmode = SetBkMode (hdc, TRANSPARENT);
785 /* redraw necessary buttons */
786 btnPtr = infoPtr->buttons;
787 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
789 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
790 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
793 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
794 SetBkMode (hdc, oldBKmode);
797 /***********************************************************************
798 * TOOLBAR_MeasureString
800 * This function gets the width and height of a string in pixels. This
801 * is done first by using GetTextExtentPoint to get the basic width
802 * and height. The DrawText is called with DT_CALCRECT to get the exact
803 * width. The reason is because the text may have more than one "&" (or
804 * prefix characters as M$ likes to call them). The prefix character
805 * indicates where the underline goes, except for the string "&&" which
806 * is reduced to a single "&". GetTextExtentPoint does not process these
807 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
810 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
811 HDC hdc, LPSIZE lpSize)
818 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
820 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
822 /* first get size of all the text */
823 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
825 /* feed above size into the rectangle for DrawText */
826 myrect.left = myrect.top = 0;
827 myrect.right = lpSize->cx;
828 myrect.bottom = lpSize->cy;
830 /* Use DrawText to get true size as drawn (less pesky "&") */
831 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
832 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
835 /* feed back to caller */
836 lpSize->cx = myrect.right;
837 lpSize->cy = myrect.bottom;
840 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
843 /***********************************************************************
844 * TOOLBAR_CalcStrings
846 * This function walks through each string and measures it and returns
847 * the largest height and width to caller.
850 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
853 TBUTTON_INFO *btnPtr;
863 hOldFont = SelectObject (hdc, infoPtr->hFont);
865 btnPtr = infoPtr->buttons;
866 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
867 if(TOOLBAR_HasText(infoPtr, btnPtr))
869 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
870 if (sz.cx > lpSize->cx)
872 if (sz.cy > lpSize->cy)
877 SelectObject (hdc, hOldFont);
878 ReleaseDC (hwnd, hdc);
880 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
883 /***********************************************************************
884 * TOOLBAR_WrapToolbar
886 * This function walks through the buttons and seperators in the
887 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
888 * wrapping should occur based on the width of the toolbar window.
889 * It does *not* calculate button placement itself. That task
890 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
891 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
892 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
896 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
898 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
899 TBUTTON_INFO *btnPtr;
902 BOOL bWrap, bButtonWrap;
904 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
905 /* no layout is necessary. Applications may use this style */
906 /* to perform their own layout on the toolbar. */
907 if( !(dwStyle & TBSTYLE_WRAPABLE) )
910 btnPtr = infoPtr->buttons;
911 x = infoPtr->nIndent;
913 /* this can get the parents width, to know how far we can extend
914 * this toolbar. We cannot use its height, as there may be multiple
915 * toolbars in a rebar control
917 GetClientRect( GetParent(hwnd), &rc );
918 infoPtr->nWidth = rc.right - rc.left;
921 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
922 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
925 for (i = 0; i < infoPtr->nNumButtons; i++ )
928 btnPtr[i].fsState &= ~TBSTATE_WRAP;
930 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
933 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
934 /* it is the actual width of the separator. This is used for */
935 /* custom controls in toolbars. */
937 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
938 /* width. - GA 8/01 */
939 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
940 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
941 cx = (btnPtr[i].iBitmap > 0) ?
942 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
944 cx = infoPtr->nButtonWidth;
946 /* Two or more adjacent separators form a separator group. */
947 /* The first separator in a group should be wrapped to the */
948 /* next row if the previous wrapping is on a button. */
950 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
951 (i + 1 < infoPtr->nNumButtons ) &&
952 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
954 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
955 btnPtr[i].fsState |= TBSTATE_WRAP;
956 x = infoPtr->nIndent;
962 /* The layout makes sure the bitmap is visible, but not the button. */
963 /* Test added to also wrap after a button that starts a row but */
964 /* is bigger than the area. - GA 8/01 */
965 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
966 > infoPtr->nWidth ) ||
967 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
971 /* If the current button is a separator and not hidden, */
972 /* go to the next until it reaches a non separator. */
973 /* Wrap the last separator if it is before a button. */
974 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
975 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
976 i < infoPtr->nNumButtons )
982 if( bFound && i < infoPtr->nNumButtons )
985 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
986 i, btnPtr[i].fsStyle, x, cx);
987 btnPtr[i].fsState |= TBSTATE_WRAP;
988 x = infoPtr->nIndent;
992 else if ( i >= infoPtr->nNumButtons)
995 /* If the current button is not a separator, find the last */
996 /* separator and wrap it. */
997 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
999 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1000 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1004 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1005 i, btnPtr[i].fsStyle, x, cx);
1006 x = infoPtr->nIndent;
1007 btnPtr[j].fsState |= TBSTATE_WRAP;
1008 bButtonWrap = FALSE;
1013 /* If no separator available for wrapping, wrap one of */
1014 /* non-hidden previous button. */
1018 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1020 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1025 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1026 i, btnPtr[i].fsStyle, x, cx);
1027 x = infoPtr->nIndent;
1028 btnPtr[j].fsState |= TBSTATE_WRAP;
1034 /* If all above failed, wrap the current button. */
1037 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1038 i, btnPtr[i].fsStyle, x, cx);
1039 btnPtr[i].fsState |= TBSTATE_WRAP;
1041 x = infoPtr->nIndent;
1042 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1043 bButtonWrap = FALSE;
1049 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1050 i, btnPtr[i].fsStyle, x, cx);
1057 /***********************************************************************
1058 * TOOLBAR_CalcToolbar
1060 * This function calculates button and separator placement. It first
1061 * calculates the button sizes, gets the toolbar window width and then
1062 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1063 * on. It assigns a new location to each item and sends this location to
1064 * the tooltip window if appropriate. Finally, it updates the rcBound
1065 * rect and calculates the new required toolbar window height.
1069 TOOLBAR_CalcToolbar (HWND hwnd)
1071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1072 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1073 TBUTTON_INFO *btnPtr;
1074 INT i, nRows, nSepRows;
1078 BOOL usesBitmaps = FALSE;
1079 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1081 TOOLBAR_CalcStrings (hwnd, &sizeString);
1083 if (dwStyle & TBSTYLE_LIST)
1085 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1087 if (infoPtr->buttons[i].iBitmap >= 0)
1090 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1091 0, sizeString.cy) + 6;
1092 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1093 0) + sizeString.cx + 6;
1094 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1095 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1096 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1097 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1100 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1102 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1106 if (sizeString.cy > 0)
1109 infoPtr->nButtonHeight = sizeString.cy +
1110 2 + /* this is the space to separate text from bitmap */
1111 infoPtr->nBitmapHeight + 6;
1113 infoPtr->nButtonHeight = sizeString.cy + 6;
1115 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1116 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1118 if (sizeString.cx > infoPtr->nBitmapWidth)
1119 infoPtr->nButtonWidth = sizeString.cx + 6;
1120 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1121 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1124 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1125 infoPtr->nButtonWidth = infoPtr->cxMin;
1126 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1127 infoPtr->nButtonWidth = infoPtr->cxMax;
1129 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1131 x = infoPtr->nIndent;
1135 * We will set the height below, and we set the width on entry
1136 * so we do not reset them here..
1139 GetClientRect( hwnd, &rc );
1140 /* get initial values for toolbar */
1141 infoPtr->nWidth = rc.right - rc.left;
1142 infoPtr->nHeight = rc.bottom - rc.top;
1145 /* from above, minimum is a button, and possible text */
1146 cx = infoPtr->nButtonWidth;
1148 /* cannot use just ButtonHeight, we may have no buttons! */
1149 if (infoPtr->nNumButtons > 0)
1150 infoPtr->nHeight = infoPtr->nButtonHeight;
1152 cy = infoPtr->nHeight;
1154 nRows = nSepRows = 0;
1156 infoPtr->rcBound.top = y;
1157 infoPtr->rcBound.left = x;
1158 infoPtr->rcBound.bottom = y + cy;
1159 infoPtr->rcBound.right = x;
1161 btnPtr = infoPtr->buttons;
1163 /* do not base height/width on parent, if the parent is a */
1164 /* rebar control it could have multiple rows of toolbars */
1165 /* GetClientRect( GetParent(hwnd), &rc ); */
1166 /* cx = rc.right - rc.left; */
1167 /* cy = rc.bottom - rc.top; */
1169 TRACE("cy=%d\n", cy);
1171 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1174 if (btnPtr->fsState & TBSTATE_HIDDEN)
1176 SetRectEmpty (&btnPtr->rect);
1180 cy = infoPtr->nHeight;
1182 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1183 /* it is the actual width of the separator. This is used for */
1184 /* custom controls in toolbars. */
1185 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1186 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1187 cy = (btnPtr->iBitmap > 0) ?
1188 btnPtr->iBitmap : SEPARATOR_WIDTH;
1189 cx = infoPtr->nButtonWidth;
1192 cx = (btnPtr->iBitmap > 0) ?
1193 btnPtr->iBitmap : SEPARATOR_WIDTH;
1197 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1204 hOldFont = SelectObject (hdc, infoPtr->hFont);
1206 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1208 SelectObject (hdc, hOldFont);
1209 ReleaseDC (hwnd, hdc);
1211 /* Fudge amount measured against IE4 "menu" and "Links" */
1212 /* toolbars with native control (v4.71). - GA 8/01 */
1213 cx = sz.cx + 6 + 5 + 5;
1214 if ((dwStyle & TBSTYLE_LIST) &&
1215 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1216 cx += infoPtr->nBitmapWidth;
1219 cx = infoPtr->nButtonWidth;
1221 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1222 cx += DDARROW_WIDTH;
1224 if (btnPtr->fsState & TBSTATE_WRAP )
1227 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1229 if (infoPtr->rcBound.left > x)
1230 infoPtr->rcBound.left = x;
1231 if (infoPtr->rcBound.right < x + cx)
1232 infoPtr->rcBound.right = x + cx;
1233 if (infoPtr->rcBound.bottom < y + cy)
1234 infoPtr->rcBound.bottom = y + cy;
1236 /* Set the toolTip only for non-hidden, non-separator button */
1237 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1241 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1242 ti.cbSize = sizeof(TTTOOLINFOA);
1244 ti.uId = btnPtr->idCommand;
1245 ti.rect = btnPtr->rect;
1246 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1250 /* btnPtr->nRow is zero based. The space between the rows is */
1251 /* also considered as a row. */
1252 btnPtr->nRow = nRows + nSepRows;
1254 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d\n",
1255 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow);
1259 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1263 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1264 /* it is the actual width of the separator. This is used for */
1265 /* custom controls in toolbars. */
1266 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1267 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1268 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1272 /* nSepRows is used to calculate the extra height follwoing */
1276 x = infoPtr->nIndent;
1283 /* infoPtr->nRows is the number of rows on the toolbar */
1284 infoPtr->nRows = nRows + nSepRows + 1;
1286 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1288 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1289 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1290 nSepRows * (infoPtr->nBitmapHeight + 1) +
1292 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1297 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1300 TBUTTON_INFO *btnPtr;
1303 btnPtr = infoPtr->buttons;
1304 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1305 if (btnPtr->fsState & TBSTATE_HIDDEN)
1308 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1309 if (PtInRect (&btnPtr->rect, *lpPt)) {
1310 TRACE(" ON SEPARATOR %d!\n", i);
1315 if (PtInRect (&btnPtr->rect, *lpPt)) {
1316 TRACE(" ON BUTTON %d!\n", i);
1322 TRACE(" NOWHERE!\n");
1328 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1330 TBUTTON_INFO *btnPtr;
1333 if (CommandIsIndex) {
1334 TRACE("command is really index command=%d\n", idCommand);
1337 btnPtr = infoPtr->buttons;
1338 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1339 if (btnPtr->idCommand == idCommand) {
1340 TRACE("command=%d index=%d\n", idCommand, i);
1344 TRACE("no index found for command=%d\n", idCommand);
1350 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1352 TBUTTON_INFO *btnPtr;
1355 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1358 /* check index button */
1359 btnPtr = &infoPtr->buttons[nIndex];
1360 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1361 if (btnPtr->fsState & TBSTATE_CHECKED)
1365 /* check previous buttons */
1366 nRunIndex = nIndex - 1;
1367 while (nRunIndex >= 0) {
1368 btnPtr = &infoPtr->buttons[nRunIndex];
1369 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1370 if (btnPtr->fsState & TBSTATE_CHECKED)
1378 /* check next buttons */
1379 nRunIndex = nIndex + 1;
1380 while (nRunIndex < infoPtr->nNumButtons) {
1381 btnPtr = &infoPtr->buttons[nRunIndex];
1382 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1383 if (btnPtr->fsState & TBSTATE_CHECKED)
1396 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1397 WPARAM wParam, LPARAM lParam)
1403 msg.wParam = wParam;
1404 msg.lParam = lParam;
1405 msg.time = GetMessageTime ();
1406 msg.pt.x = LOWORD(GetMessagePos ());
1407 msg.pt.y = HIWORD(GetMessagePos ());
1409 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1413 /***********************************************************************
1414 * TOOLBAR_CustomizeDialogProc
1415 * This function implements the toolbar customization dialog.
1418 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1420 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1421 PCUSTOMBUTTON btnInfo;
1423 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1428 custInfo = (PCUSTDLG_INFO)lParam;
1429 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1437 infoPtr = custInfo->tbInfo;
1439 /* send TBN_QUERYINSERT notification */
1440 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1442 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1445 /* add items to 'toolbar buttons' list and check if removable */
1446 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1448 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1449 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1450 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1451 btnInfo->bVirtual = FALSE;
1452 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1454 /* send TBN_QUERYDELETE notification */
1456 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1460 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1461 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1464 /* insert separator button into 'available buttons' list */
1465 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1466 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1467 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1468 btnInfo->bVirtual = FALSE;
1469 btnInfo->bRemovable = TRUE;
1470 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1471 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1472 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1474 /* insert all buttons into dsa */
1477 /* send TBN_GETBUTTONINFO notification */
1479 nmtb.pszText = Buffer;
1482 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1485 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1487 /* insert button into the apropriate list */
1488 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1491 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1492 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1493 btnInfo->bVirtual = FALSE;
1494 btnInfo->bRemovable = TRUE;
1495 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1496 strcpy (btnInfo->text, nmtb.pszText);
1498 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1499 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1503 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1504 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1505 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1506 strcpy (btnInfo->text, nmtb.pszText);
1508 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1512 /* select first item in the 'available' list */
1513 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1515 /* append 'virtual' separator button to the 'toolbar buttons' list */
1516 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1517 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1518 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1519 btnInfo->bVirtual = TRUE;
1520 btnInfo->bRemovable = FALSE;
1521 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1522 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1523 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1525 /* select last item in the 'toolbar' list */
1526 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1527 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1529 /* set focus and disable buttons */
1530 PostMessageA (hwnd, WM_USER, 0, 0);
1535 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1536 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1537 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1538 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1542 EndDialog(hwnd, FALSE);
1546 switch (LOWORD(wParam))
1548 case IDC_TOOLBARBTN_LBOX:
1549 if (HIWORD(wParam) == LBN_SELCHANGE)
1551 PCUSTOMBUTTON btnInfo;
1556 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1557 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1559 /* send TBN_QUERYINSERT notification */
1561 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1564 /* get list box item */
1565 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1567 if (index == (count - 1))
1569 /* last item (virtual separator) */
1570 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1571 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1573 else if (index == (count - 2))
1575 /* second last item (last non-virtual item) */
1576 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1577 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1579 else if (index == 0)
1582 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1583 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1587 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1588 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1591 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1595 case IDC_MOVEUP_BTN:
1597 PCUSTOMBUTTON btnInfo;
1601 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1602 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1603 TRACE("Move up: index %d\n", index);
1605 /* send TBN_QUERYINSERT notification */
1608 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1611 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1613 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1614 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1615 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1616 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1619 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1620 else if (index >= (count - 3))
1621 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1623 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1624 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1629 case IDC_MOVEDN_BTN: /* move down */
1631 PCUSTOMBUTTON btnInfo;
1635 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1636 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1637 TRACE("Move up: index %d\n", index);
1639 /* send TBN_QUERYINSERT notification */
1641 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1644 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1646 /* move button down */
1647 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1648 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1649 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1650 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1653 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1654 else if (index >= (count - 3))
1655 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1657 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1658 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1663 case IDC_REMOVE_BTN: /* remove button */
1665 PCUSTOMBUTTON btnInfo;
1668 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1669 TRACE("Remove: index %d\n", index);
1671 /* send TBN_QUERYDELETE notification */
1673 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1676 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1677 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1678 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1680 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1682 /* insert into 'available button' list */
1683 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1685 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1686 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1689 COMCTL32_Free (btnInfo);
1694 case IDOK: /* Add button */
1699 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1700 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1701 TRACE("Add: index %d\n", index);
1703 /* send TBN_QUERYINSERT notification */
1705 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1708 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1712 /* remove from 'available buttons' list */
1713 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1714 if (index == count-1)
1715 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1717 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1721 PCUSTOMBUTTON btnNew;
1723 /* duplicate 'separator' button */
1724 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1725 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1729 /* insert into 'toolbar button' list */
1730 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1731 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1732 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1734 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1740 EndDialog(hwnd, FALSE);
1750 /* delete items from 'toolbar buttons' listbox*/
1751 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1752 for (i = 0; i < count; i++)
1754 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1755 COMCTL32_Free(btnInfo);
1756 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1758 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1761 /* delete items from 'available buttons' listbox*/
1762 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1763 for (i = 0; i < count; i++)
1765 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1766 COMCTL32_Free(btnInfo);
1767 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1769 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1774 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1776 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1781 COLORREF oldText = 0;
1785 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1786 if (btnInfo == NULL)
1788 FIXME("btnInfo invalid!\n");
1792 /* set colors and select objects */
1793 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1794 if (btnInfo->bVirtual)
1795 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
1797 oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
1798 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1799 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1801 /* fill background rectangle */
1802 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
1803 lpdis->rcItem.right, lpdis->rcItem.bottom);
1805 /* calculate button and text rectangles */
1806 CopyRect (&rcButton, &lpdis->rcItem);
1807 InflateRect (&rcButton, -1, -1);
1808 CopyRect (&rcText, &rcButton);
1809 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
1810 rcText.left = rcButton.right + 2;
1812 /* draw focus rectangle */
1813 if (lpdis->itemState & ODS_FOCUS)
1814 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1817 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
1819 /* draw image and text */
1820 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
1821 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
1822 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
1823 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
1824 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1826 /* delete objects and reset colors */
1827 SelectObject (lpdis->hDC, hOldBrush);
1828 SelectObject (lpdis->hDC, hOldPen);
1829 SetBkColor (lpdis->hDC, oldBk);
1830 SetTextColor (lpdis->hDC, oldText);
1836 case WM_MEASUREITEM:
1837 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1839 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1841 if (custInfo && custInfo->tbInfo)
1842 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
1844 lpmis->itemHeight = 15 + 8; /* default height */
1856 /***********************************************************************
1857 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1861 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1863 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1864 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1865 INT nIndex = 0, nButtons, nCount;
1868 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1872 if (lpAddBmp->hInst == HINST_COMMCTRL)
1874 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1876 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1878 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1883 TRACE ("adding %d internal bitmaps!\n", nButtons);
1885 /* Windows resize all the buttons to the size of a newly added standard image */
1886 if (lpAddBmp->nID & 1)
1889 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
1890 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
1892 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1893 MAKELPARAM((WORD)24, (WORD)24));
1894 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1895 MAKELPARAM((WORD)31, (WORD)30));
1900 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1901 MAKELPARAM((WORD)16, (WORD)16));
1902 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1903 MAKELPARAM((WORD)22, (WORD)22));
1906 TOOLBAR_CalcToolbar (hwnd);
1910 nButtons = (INT)wParam;
1914 TRACE ("adding %d bitmaps!\n", nButtons);
1917 if (!(infoPtr->himlDef)) {
1918 /* create new default image list */
1919 TRACE ("creating default image list!\n");
1922 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1923 ILC_COLOR | ILC_MASK, nButtons, 2);
1924 infoPtr->himlInt = infoPtr->himlDef;
1927 nCount = ImageList_GetImageCount(infoPtr->himlDef);
1929 /* Add bitmaps to the default image list */
1930 if (lpAddBmp->hInst == (HINSTANCE)0)
1933 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1936 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1938 /* Add system bitmaps */
1939 switch (lpAddBmp->nID)
1941 case IDB_STD_SMALL_COLOR:
1942 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1943 MAKEINTRESOURCEA(IDB_STD_SMALL));
1944 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1945 hbmLoad, CLR_DEFAULT);
1946 DeleteObject (hbmLoad);
1949 case IDB_STD_LARGE_COLOR:
1950 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1951 MAKEINTRESOURCEA(IDB_STD_LARGE));
1952 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1953 hbmLoad, CLR_DEFAULT);
1954 DeleteObject (hbmLoad);
1957 case IDB_VIEW_SMALL_COLOR:
1958 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1959 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1960 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1961 hbmLoad, CLR_DEFAULT);
1962 DeleteObject (hbmLoad);
1965 case IDB_VIEW_LARGE_COLOR:
1966 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1967 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1968 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1969 hbmLoad, CLR_DEFAULT);
1970 DeleteObject (hbmLoad);
1973 case IDB_HIST_SMALL_COLOR:
1974 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1975 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1976 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1977 hbmLoad, CLR_DEFAULT);
1978 DeleteObject (hbmLoad);
1981 case IDB_HIST_LARGE_COLOR:
1982 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1983 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1984 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1985 hbmLoad, CLR_DEFAULT);
1986 DeleteObject (hbmLoad);
1990 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1991 ERR ("invalid imagelist!\n");
1997 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1998 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1999 DeleteObject (hbmLoad);
2004 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2006 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2008 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",
2009 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2010 infoPtr->nNumBitmaps+nButtons,imagecount);
2012 infoPtr->nNumBitmaps = imagecount;
2015 infoPtr->nNumBitmaps += nButtons;
2018 InvalidateRect(hwnd, NULL, FALSE);
2025 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2027 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2028 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2029 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2031 TRACE("adding %d buttons!\n", wParam);
2033 nAddButtons = (UINT)wParam;
2034 nOldButtons = infoPtr->nNumButtons;
2035 nNewButtons = nOldButtons + nAddButtons;
2037 if (infoPtr->nNumButtons == 0) {
2039 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2042 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2044 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2045 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2046 nOldButtons * sizeof(TBUTTON_INFO));
2047 COMCTL32_Free (oldButtons);
2050 infoPtr->nNumButtons = nNewButtons;
2052 /* insert new button data */
2053 for (nCount = 0; nCount < nAddButtons; nCount++) {
2054 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2055 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2056 btnPtr->idCommand = lpTbb[nCount].idCommand;
2057 btnPtr->fsState = lpTbb[nCount].fsState;
2058 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2059 btnPtr->dwData = lpTbb[nCount].dwData;
2060 btnPtr->iString = lpTbb[nCount].iString;
2061 btnPtr->bHot = FALSE;
2063 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2066 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2067 ti.cbSize = sizeof (TTTOOLINFOA);
2069 ti.uId = btnPtr->idCommand;
2071 ti.lpszText = LPSTR_TEXTCALLBACKA;
2073 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2078 TOOLBAR_CalcToolbar (hwnd);
2080 InvalidateRect(hwnd, NULL, FALSE);
2087 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2090 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2091 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2093 TRACE("adding %d buttons!\n", wParam);
2095 nAddButtons = (UINT)wParam;
2096 nOldButtons = infoPtr->nNumButtons;
2097 nNewButtons = nOldButtons + nAddButtons;
2099 if (infoPtr->nNumButtons == 0) {
2101 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2104 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2106 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2107 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2108 nOldButtons * sizeof(TBUTTON_INFO));
2109 COMCTL32_Free (oldButtons);
2112 infoPtr->nNumButtons = nNewButtons;
2114 /* insert new button data */
2115 for (nCount = 0; nCount < nAddButtons; nCount++) {
2116 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2117 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2118 btnPtr->idCommand = lpTbb[nCount].idCommand;
2119 btnPtr->fsState = lpTbb[nCount].fsState;
2120 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2121 btnPtr->dwData = lpTbb[nCount].dwData;
2122 btnPtr->iString = lpTbb[nCount].iString;
2123 btnPtr->bHot = FALSE;
2125 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2128 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2129 ti.cbSize = sizeof (TTTOOLINFOW);
2131 ti.uId = btnPtr->idCommand;
2133 ti.lpszText = LPSTR_TEXTCALLBACKW;
2135 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2140 TOOLBAR_CalcToolbar (hwnd);
2142 InvalidateRect(hwnd, NULL, FALSE);
2149 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2154 if ((wParam) && (HIWORD(lParam) == 0)) {
2157 TRACE("adding string from resource!\n");
2159 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2162 TRACE("len=%d \"%s\"\n", len, szString);
2163 nIndex = infoPtr->nNumStrings;
2164 if (infoPtr->nNumStrings == 0) {
2166 COMCTL32_Alloc (sizeof(LPWSTR));
2169 LPWSTR *oldStrings = infoPtr->strings;
2171 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2172 memcpy (&infoPtr->strings[0], &oldStrings[0],
2173 sizeof(LPWSTR) * infoPtr->nNumStrings);
2174 COMCTL32_Free (oldStrings);
2177 /*COMCTL32_Alloc zeros out the allocated memory*/
2178 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
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 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2208 infoPtr->nNumStrings++;
2219 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2221 #define MAX_RESOURCE_STRING_LENGTH 512
2222 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2225 if ((wParam) && (HIWORD(lParam) == 0)) {
2226 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2228 TRACE("adding string from resource!\n");
2230 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2231 szString, MAX_RESOURCE_STRING_LENGTH);
2233 TRACE("len=%d %s\n", len, debugstr_w(szString));
2234 TRACE("First char: 0x%x\n", *szString);
2235 if (szString[0] == L'|')
2237 PWSTR p = szString + 1;
2239 nIndex = infoPtr->nNumStrings;
2240 while (*p != L'|') {
2242 if (infoPtr->nNumStrings == 0) {
2244 COMCTL32_Alloc (sizeof(LPWSTR));
2247 LPWSTR *oldStrings = infoPtr->strings;
2249 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2250 memcpy (&infoPtr->strings[0], &oldStrings[0],
2251 sizeof(LPWSTR) * infoPtr->nNumStrings);
2252 COMCTL32_Free (oldStrings);
2255 len = COMCTL32_StrChrW (p, L'|') - p;
2256 TRACE("len=%d %s\n", len, debugstr_w(p));
2257 infoPtr->strings[infoPtr->nNumStrings] =
2258 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2259 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2260 infoPtr->nNumStrings++;
2267 nIndex = infoPtr->nNumStrings;
2268 if (infoPtr->nNumStrings == 0) {
2270 COMCTL32_Alloc (sizeof(LPWSTR));
2273 LPWSTR *oldStrings = infoPtr->strings;
2275 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2276 memcpy (&infoPtr->strings[0], &oldStrings[0],
2277 sizeof(LPWSTR) * infoPtr->nNumStrings);
2278 COMCTL32_Free (oldStrings);
2281 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2282 infoPtr->nNumStrings++;
2286 LPWSTR p = (LPWSTR)lParam;
2291 TRACE("adding string(s) from array!\n");
2292 nIndex = infoPtr->nNumStrings;
2296 TRACE("len=%d %s\n", len, debugstr_w(p));
2297 if (infoPtr->nNumStrings == 0) {
2299 COMCTL32_Alloc (sizeof(LPWSTR));
2302 LPWSTR *oldStrings = infoPtr->strings;
2304 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2305 memcpy (&infoPtr->strings[0], &oldStrings[0],
2306 sizeof(LPWSTR) * infoPtr->nNumStrings);
2307 COMCTL32_Free (oldStrings);
2310 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2311 infoPtr->nNumStrings++;
2322 TOOLBAR_AutoSize (HWND hwnd)
2324 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2325 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2331 UINT uPosFlags = SWP_NOZORDER;
2333 TRACE("resize forced, style=%lx!\n", dwStyle);
2335 parent = GetParent (hwnd);
2336 GetClientRect(parent, &parent_rect);
2338 x = parent_rect.left;
2339 y = parent_rect.top;
2341 /* FIXME: we should be able to early out if nothing */
2342 /* has changed with nWidth != parent_rect width */
2344 if (dwStyle & CCS_NORESIZE) {
2345 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2348 TOOLBAR_CalcToolbar (hwnd);
2351 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2352 TOOLBAR_CalcToolbar (hwnd);
2353 InvalidateRect( hwnd, NULL, TRUE );
2354 cy = infoPtr->nHeight;
2355 cx = infoPtr->nWidth;
2357 if (dwStyle & CCS_NOMOVEY) {
2358 GetWindowRect(hwnd, &window_rect);
2359 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2360 y = window_rect.top;
2364 if (dwStyle & CCS_NOPARENTALIGN)
2365 uPosFlags |= SWP_NOMOVE;
2367 if (!(dwStyle & CCS_NODIVIDER))
2368 cy += GetSystemMetrics(SM_CYEDGE);
2370 if (dwStyle & WS_BORDER)
2373 cy += GetSystemMetrics(SM_CYEDGE);
2374 cx += GetSystemMetrics(SM_CYEDGE);
2377 infoPtr->bAutoSize = TRUE;
2378 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2380 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2381 * the setwindowpos calls */
2382 infoPtr->bAutoSize = FALSE;
2389 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2391 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2393 return infoPtr->nNumButtons;
2398 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2402 if (infoPtr == NULL) {
2403 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2404 ERR("infoPtr == NULL!\n");
2408 infoPtr->dwStructSize = (DWORD)wParam;
2415 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2418 TBUTTON_INFO *btnPtr;
2421 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2425 btnPtr = &infoPtr->buttons[nIndex];
2426 btnPtr->iBitmap = LOWORD(lParam);
2428 /* we HAVE to erase the background, the new bitmap could be */
2430 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2437 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2439 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2440 TBUTTON_INFO *btnPtr;
2443 BOOL bChecked = FALSE;
2445 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2449 btnPtr = &infoPtr->buttons[nIndex];
2451 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2454 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2456 if (LOWORD(lParam) == FALSE)
2457 btnPtr->fsState &= ~TBSTATE_CHECKED;
2459 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2461 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2462 if (nOldIndex == nIndex)
2464 if (nOldIndex != -1)
2465 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2467 btnPtr->fsState |= TBSTATE_CHECKED;
2470 if( bChecked != LOWORD(lParam) )
2472 if (nOldIndex != -1)
2474 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2475 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2477 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2480 /* FIXME: Send a WM_NOTIFY?? */
2487 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2489 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2491 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2496 TOOLBAR_Customize (HWND hwnd)
2498 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2499 CUSTDLG_INFO custInfo;
2505 custInfo.tbInfo = infoPtr;
2506 custInfo.tbHwnd = hwnd;
2508 /* send TBN_BEGINADJUST notification */
2509 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2512 if (!(hRes = FindResourceA (COMCTL32_hModule,
2513 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2517 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2520 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2521 (LPDLGTEMPLATEA)template,
2523 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2526 /* send TBN_ENDADJUST notification */
2527 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2535 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2538 INT nIndex = (INT)wParam;
2540 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2543 if ((infoPtr->hwndToolTip) &&
2544 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2547 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2548 ti.cbSize = sizeof (TTTOOLINFOA);
2550 ti.uId = infoPtr->buttons[nIndex].idCommand;
2552 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2555 if (infoPtr->nNumButtons == 1) {
2556 TRACE(" simple delete!\n");
2557 COMCTL32_Free (infoPtr->buttons);
2558 infoPtr->buttons = NULL;
2559 infoPtr->nNumButtons = 0;
2562 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2563 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2565 infoPtr->nNumButtons--;
2566 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2568 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2569 nIndex * sizeof(TBUTTON_INFO));
2572 if (nIndex < infoPtr->nNumButtons) {
2573 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2574 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2577 COMCTL32_Free (oldButtons);
2580 TOOLBAR_CalcToolbar (hwnd);
2582 InvalidateRect (hwnd, NULL, TRUE);
2589 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2591 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2592 TBUTTON_INFO *btnPtr;
2596 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2600 btnPtr = &infoPtr->buttons[nIndex];
2602 bState = btnPtr->fsState & TBSTATE_ENABLED;
2604 /* update the toolbar button state */
2605 if(LOWORD(lParam) == FALSE) {
2606 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2608 btnPtr->fsState |= TBSTATE_ENABLED;
2611 /* redraw the button only if the state of the button changed */
2612 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2614 InvalidateRect(hwnd, &btnPtr->rect,
2615 TOOLBAR_HasText(infoPtr, btnPtr));
2622 static inline LRESULT
2623 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2625 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2627 return infoPtr->bAnchor;
2632 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2637 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2641 return infoPtr->buttons[nIndex].iBitmap;
2645 static inline LRESULT
2646 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2648 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2653 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2656 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2657 INT nIndex = (INT)wParam;
2658 TBUTTON_INFO *btnPtr;
2660 if (infoPtr == NULL)
2666 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2669 btnPtr = &infoPtr->buttons[nIndex];
2670 lpTbb->iBitmap = btnPtr->iBitmap;
2671 lpTbb->idCommand = btnPtr->idCommand;
2672 lpTbb->fsState = btnPtr->fsState;
2673 lpTbb->fsStyle = btnPtr->fsStyle;
2674 lpTbb->dwData = btnPtr->dwData;
2675 lpTbb->iString = btnPtr->iString;
2682 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2684 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2685 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2686 TBUTTON_INFO *btnPtr;
2689 if (infoPtr == NULL)
2691 if (lpTbInfo == NULL)
2693 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2696 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2697 lpTbInfo->dwMask & 0x80000000);
2701 btnPtr = &infoPtr->buttons[nIndex];
2703 if (lpTbInfo->dwMask & TBIF_COMMAND)
2704 lpTbInfo->idCommand = btnPtr->idCommand;
2705 if (lpTbInfo->dwMask & TBIF_IMAGE)
2706 lpTbInfo->iImage = btnPtr->iBitmap;
2707 if (lpTbInfo->dwMask & TBIF_LPARAM)
2708 lpTbInfo->lParam = btnPtr->dwData;
2709 if (lpTbInfo->dwMask & TBIF_SIZE)
2710 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2711 if (lpTbInfo->dwMask & TBIF_STATE)
2712 lpTbInfo->fsState = btnPtr->fsState;
2713 if (lpTbInfo->dwMask & TBIF_STYLE)
2714 lpTbInfo->fsStyle = btnPtr->fsStyle;
2715 if (lpTbInfo->dwMask & TBIF_TEXT) {
2716 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2717 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
2724 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2726 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2727 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2728 TBUTTON_INFO *btnPtr;
2731 if (infoPtr == NULL)
2733 if (lpTbInfo == NULL)
2735 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2738 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2739 lpTbInfo->dwMask & 0x80000000);
2743 btnPtr = &infoPtr->buttons[nIndex];
2745 if (lpTbInfo->dwMask & TBIF_COMMAND)
2746 lpTbInfo->idCommand = btnPtr->idCommand;
2747 if (lpTbInfo->dwMask & TBIF_IMAGE)
2748 lpTbInfo->iImage = btnPtr->iBitmap;
2749 if (lpTbInfo->dwMask & TBIF_LPARAM)
2750 lpTbInfo->lParam = btnPtr->dwData;
2751 if (lpTbInfo->dwMask & TBIF_SIZE)
2752 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2753 if (lpTbInfo->dwMask & TBIF_STATE)
2754 lpTbInfo->fsState = btnPtr->fsState;
2755 if (lpTbInfo->dwMask & TBIF_STYLE)
2756 lpTbInfo->fsStyle = btnPtr->fsStyle;
2757 if (lpTbInfo->dwMask & TBIF_TEXT) {
2758 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2759 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
2767 TOOLBAR_GetButtonSize (HWND hwnd)
2769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2771 if (infoPtr->nNumButtons > 0)
2772 return MAKELONG((WORD)infoPtr->nButtonWidth,
2773 (WORD)infoPtr->nButtonHeight);
2775 return MAKELONG(8,7);
2780 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2782 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2789 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2793 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
2795 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
2796 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
2801 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2803 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2810 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2814 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
2816 strcpyW ((LPWSTR)lParam, lpText);
2818 return strlenW (lpText);
2822 /* << TOOLBAR_GetColorScheme >> */
2826 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2828 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2830 return (LRESULT)infoPtr->himlDis;
2834 inline static LRESULT
2835 TOOLBAR_GetExtendedStyle (HWND hwnd)
2837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2839 return infoPtr->dwExStyle;
2844 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2848 return (LRESULT)infoPtr->himlHot;
2853 TOOLBAR_GetHotItem (HWND hwnd)
2855 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2857 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
2860 if (infoPtr->nHotItem < 0)
2863 return (LRESULT)infoPtr->nHotItem;
2868 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2872 return (LRESULT)infoPtr->himlDef;
2876 /* << TOOLBAR_GetInsertMark >> */
2877 /* << TOOLBAR_GetInsertMarkColor >> */
2881 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2883 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2884 TBUTTON_INFO *btnPtr;
2888 if (infoPtr == NULL)
2890 nIndex = (INT)wParam;
2891 btnPtr = &infoPtr->buttons[nIndex];
2892 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2894 lpRect = (LPRECT)lParam;
2897 if (btnPtr->fsState & TBSTATE_HIDDEN)
2900 lpRect->left = btnPtr->rect.left;
2901 lpRect->right = btnPtr->rect.right;
2902 lpRect->bottom = btnPtr->rect.bottom;
2903 lpRect->top = btnPtr->rect.top;
2910 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2912 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2913 LPSIZE lpSize = (LPSIZE)lParam;
2918 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2919 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2921 TRACE("maximum size %d x %d\n",
2922 infoPtr->rcBound.right - infoPtr->rcBound.left,
2923 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2929 /* << TOOLBAR_GetObject >> */
2930 /* << TOOLBAR_GetPadding >> */
2934 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2937 TBUTTON_INFO *btnPtr;
2941 if (infoPtr == NULL)
2943 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2944 btnPtr = &infoPtr->buttons[nIndex];
2945 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2947 lpRect = (LPRECT)lParam;
2951 lpRect->left = btnPtr->rect.left;
2952 lpRect->right = btnPtr->rect.right;
2953 lpRect->bottom = btnPtr->rect.bottom;
2954 lpRect->top = btnPtr->rect.top;
2961 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2963 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2965 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2966 return infoPtr->nRows;
2973 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2978 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2982 return infoPtr->buttons[nIndex].fsState;
2987 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2989 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2992 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2996 return infoPtr->buttons[nIndex].fsStyle;
3001 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3005 if (infoPtr == NULL)
3008 return infoPtr->nMaxTextRows;
3013 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3015 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3017 if (infoPtr == NULL)
3019 return infoPtr->hwndToolTip;
3024 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3028 TRACE("%s hwnd=0x%x stub!\n",
3029 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3031 return infoPtr->bUnicode;
3035 inline static LRESULT
3036 TOOLBAR_GetVersion (HWND hwnd)
3038 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3039 return infoPtr->iVersion;
3044 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3046 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3047 TBUTTON_INFO *btnPtr;
3052 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3056 btnPtr = &infoPtr->buttons[nIndex];
3057 if (LOWORD(lParam) == FALSE)
3058 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3060 btnPtr->fsState |= TBSTATE_HIDDEN;
3062 TOOLBAR_CalcToolbar (hwnd);
3064 InvalidateRect (hwnd, NULL, TRUE);
3070 inline static LRESULT
3071 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3073 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3078 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3081 TBUTTON_INFO *btnPtr;
3084 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3088 btnPtr = &infoPtr->buttons[nIndex];
3089 if (LOWORD(lParam) == FALSE)
3090 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3092 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3094 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3101 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3104 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3105 INT nIndex = (INT)wParam;
3106 TBUTTON_INFO *oldButtons;
3111 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3114 /* EPP: this seems to be an undocumented call (from my IE4)
3115 * I assume in that case that:
3116 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3117 * - index of insertion is at the end of existing buttons
3118 * I only see this happen with nIndex == -1, but it could have a special
3119 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3121 nIndex = infoPtr->nNumButtons;
3123 } else if (nIndex < 0)
3126 TRACE("inserting button index=%d\n", nIndex);
3127 if (nIndex > infoPtr->nNumButtons) {
3128 nIndex = infoPtr->nNumButtons;
3129 TRACE("adjust index=%d\n", nIndex);
3132 oldButtons = infoPtr->buttons;
3133 infoPtr->nNumButtons++;
3134 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3135 /* pre insert copy */
3137 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3138 nIndex * sizeof(TBUTTON_INFO));
3141 /* insert new button */
3142 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3143 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3144 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3145 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3146 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3147 /* if passed string and not index, then add string */
3148 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3149 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3152 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3154 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3157 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3158 ti.cbSize = sizeof (TTTOOLINFOA);
3160 ti.uId = lpTbb->idCommand;
3162 ti.lpszText = LPSTR_TEXTCALLBACKA;
3164 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3168 /* post insert copy */
3169 if (nIndex < infoPtr->nNumButtons - 1) {
3170 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3171 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3174 COMCTL32_Free (oldButtons);
3176 TOOLBAR_CalcToolbar (hwnd);
3178 InvalidateRect (hwnd, NULL, TRUE);
3185 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3187 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3188 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3189 INT nIndex = (INT)wParam;
3190 TBUTTON_INFO *oldButtons;
3197 TRACE("inserting button index=%d\n", nIndex);
3198 if (nIndex > infoPtr->nNumButtons) {
3199 nIndex = infoPtr->nNumButtons;
3200 TRACE("adjust index=%d\n", nIndex);
3203 oldButtons = infoPtr->buttons;
3204 infoPtr->nNumButtons++;
3205 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3206 /* pre insert copy */
3208 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3209 nIndex * sizeof(TBUTTON_INFO));
3213 /* insert new button */
3214 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3215 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3216 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3217 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3218 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3219 /* if passed string and not index, then add string */
3220 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3221 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3224 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3226 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3229 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3230 ti.cbSize = sizeof (TTTOOLINFOW);
3232 ti.uId = lpTbb->idCommand;
3234 ti.lpszText = LPSTR_TEXTCALLBACKW;
3236 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3240 /* post insert copy */
3241 if (nIndex < infoPtr->nNumButtons - 1) {
3242 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3243 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3246 COMCTL32_Free (oldButtons);
3248 InvalidateRect (hwnd, NULL, TRUE);
3254 /* << TOOLBAR_InsertMarkHitTest >> */
3258 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3260 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3263 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3267 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3272 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3277 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3281 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3286 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3288 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3291 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3295 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3300 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3309 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3314 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3319 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3323 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3328 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3330 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3333 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3337 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3341 /* << TOOLBAR_LoadImages >> */
3342 /* << TOOLBAR_MapAccelerator >> */
3343 /* << TOOLBAR_MarkButton >> */
3344 /* << TOOLBAR_MoveButton >> */
3348 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3350 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 TBUTTON_INFO *btnPtr;
3354 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3358 btnPtr = &infoPtr->buttons[nIndex];
3359 if (LOWORD(lParam) == FALSE)
3360 btnPtr->fsState &= ~TBSTATE_PRESSED;
3362 btnPtr->fsState |= TBSTATE_PRESSED;
3364 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3370 /* << TOOLBAR_ReplaceBitmap >> */
3374 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3378 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3380 if (lpSave == NULL) return 0;
3383 /* save toolbar information */
3384 FIXME("save to \"%s\" \"%s\"\n",
3385 lpSave->pszSubKey, lpSave->pszValueName);
3390 /* restore toolbar information */
3392 FIXME("restore from \"%s\" \"%s\"\n",
3393 lpSave->pszSubKey, lpSave->pszValueName);
3404 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3408 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3414 /* save toolbar information */
3415 FIXME("save to \"%s\" \"%s\"\n",
3416 lpSave->pszSubKey, lpSave->pszValueName);
3421 /* restore toolbar information */
3423 FIXME("restore from \"%s\" \"%s\"\n",
3424 lpSave->pszSubKey, lpSave->pszValueName);
3435 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3438 BOOL bOldAnchor = infoPtr->bAnchor;
3440 infoPtr->bAnchor = (BOOL)wParam;
3442 return (LRESULT)bOldAnchor;
3447 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3451 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3454 if (infoPtr->nNumButtons > 0)
3455 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3456 infoPtr->nNumButtons,
3457 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3458 LOWORD(lParam), HIWORD(lParam));
3460 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3461 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3463 /* uses image list internals directly */
3464 if (infoPtr->himlDef) {
3465 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3466 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3474 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3476 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3477 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3478 TBUTTON_INFO *btnPtr;
3483 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3486 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3487 lptbbi->dwMask & 0x80000000);
3491 btnPtr = &infoPtr->buttons[nIndex];
3492 if (lptbbi->dwMask & TBIF_COMMAND)
3493 btnPtr->idCommand = lptbbi->idCommand;
3494 if (lptbbi->dwMask & TBIF_IMAGE)
3495 btnPtr->iBitmap = lptbbi->iImage;
3496 if (lptbbi->dwMask & TBIF_LPARAM)
3497 btnPtr->dwData = lptbbi->lParam;
3498 /* if (lptbbi->dwMask & TBIF_SIZE) */
3499 /* btnPtr->cx = lptbbi->cx; */
3500 if (lptbbi->dwMask & TBIF_STATE)
3501 btnPtr->fsState = lptbbi->fsState;
3502 if (lptbbi->dwMask & TBIF_STYLE)
3503 btnPtr->fsStyle = lptbbi->fsStyle;
3505 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3506 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3507 /* iString is index, zero it to make Str_SetPtr succeed */
3510 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3517 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3520 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3521 TBUTTON_INFO *btnPtr;
3526 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3529 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3530 lptbbi->dwMask & 0x80000000);
3534 btnPtr = &infoPtr->buttons[nIndex];
3535 if (lptbbi->dwMask & TBIF_COMMAND)
3536 btnPtr->idCommand = lptbbi->idCommand;
3537 if (lptbbi->dwMask & TBIF_IMAGE)
3538 btnPtr->iBitmap = lptbbi->iImage;
3539 if (lptbbi->dwMask & TBIF_LPARAM)
3540 btnPtr->dwData = lptbbi->lParam;
3541 /* if (lptbbi->dwMask & TBIF_SIZE) */
3542 /* btnPtr->cx = lptbbi->cx; */
3543 if (lptbbi->dwMask & TBIF_STATE)
3544 btnPtr->fsState = lptbbi->fsState;
3545 if (lptbbi->dwMask & TBIF_STYLE)
3546 btnPtr->fsStyle = lptbbi->fsStyle;
3548 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3549 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3550 /* iString is index, zero it to make Str_SetPtr succeed */
3552 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3559 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3563 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3565 ERR("invalid parameter\n");
3569 /* The documentation claims you can only change the button size before
3570 * any button has been added. But this is wrong.
3571 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3572 * it to the toolbar, and it checks that the return value is nonzero - mjm
3573 * Further testing shows that we must actually perform the change too.
3575 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3576 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3582 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3584 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3586 if (infoPtr == NULL) {
3587 TRACE("Toolbar not initialized yet?????\n");
3591 /* if setting to current values, ignore */
3592 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3593 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3594 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3595 infoPtr->cxMin, infoPtr->cxMax);
3599 /* save new values */
3600 infoPtr->cxMin = (INT)LOWORD(lParam);
3601 infoPtr->cxMax = (INT)HIWORD(lParam);
3603 /* if both values are 0 then we are done */
3605 TRACE("setting both min and max to 0, norecalc\n");
3609 /* otherwise we need to recalc the toolbar and in some cases
3610 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3611 which doesn't actually draw - GA). */
3612 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3613 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3615 TOOLBAR_CalcToolbar (hwnd);
3617 InvalidateRect (hwnd, NULL, TRUE);
3624 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3626 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3627 INT nIndex = (INT)wParam;
3629 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3632 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3634 if (infoPtr->hwndToolTip) {
3636 FIXME("change tool tip!\n");
3644 /* << TOOLBAR_SetColorScheme >> */
3648 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3650 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3651 HIMAGELIST himlTemp;
3654 himlTemp = infoPtr->himlDis;
3655 infoPtr->himlDis = (HIMAGELIST)lParam;
3657 /* FIXME: redraw ? */
3659 return (LRESULT)himlTemp;
3664 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3669 dwTemp = infoPtr->dwDTFlags;
3670 infoPtr->dwDTFlags =
3671 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3673 return (LRESULT)dwTemp;
3678 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3683 dwTemp = infoPtr->dwExStyle;
3684 infoPtr->dwExStyle = (DWORD)lParam;
3686 return (LRESULT)dwTemp;
3691 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3694 HIMAGELIST himlTemp;
3696 himlTemp = infoPtr->himlHot;
3697 infoPtr->himlHot = (HIMAGELIST)lParam;
3699 /* FIXME: redraw ? */
3701 return (LRESULT)himlTemp;
3706 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
3708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3709 INT nOldHotItem = infoPtr->nHotItem;
3710 TBUTTON_INFO *btnPtr;
3712 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
3715 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
3718 infoPtr->nHotItem = (INT)wParam;
3719 if ((INT)wParam >=0)
3721 btnPtr = &infoPtr->buttons[(INT)wParam];
3722 btnPtr->bHot = TRUE;
3723 InvalidateRect (hwnd, &btnPtr->rect,
3724 TOOLBAR_HasText(infoPtr, btnPtr));
3728 btnPtr = &infoPtr->buttons[nOldHotItem];
3729 btnPtr->bHot = FALSE;
3730 InvalidateRect (hwnd, &btnPtr->rect,
3731 TOOLBAR_HasText(infoPtr, btnPtr));
3735 if (nOldHotItem < 0)
3738 return (LRESULT)nOldHotItem;
3743 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3746 HIMAGELIST himlTemp;
3748 himlTemp = infoPtr->himlDef;
3749 infoPtr->himlDef = (HIMAGELIST)lParam;
3751 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
3753 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
3754 &infoPtr->nBitmapHeight);
3755 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
3756 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
3757 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
3759 /* FIXME: redraw ? */
3760 InvalidateRect(hwnd, NULL, TRUE);
3762 return (LRESULT)himlTemp;
3767 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3771 infoPtr->nIndent = (INT)wParam;
3775 /* process only on indent changing */
3776 if(infoPtr->nIndent != (INT)wParam)
3778 infoPtr->nIndent = (INT)wParam;
3779 TOOLBAR_CalcToolbar (hwnd);
3780 InvalidateRect(hwnd, NULL, FALSE);
3787 /* << TOOLBAR_SetInsertMark >> */
3791 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3793 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3795 infoPtr->clrInsertMark = (COLORREF)lParam;
3797 /* FIXME : redraw ??*/
3804 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3806 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3808 if (infoPtr == NULL)
3811 infoPtr->nMaxTextRows = (INT)wParam;
3817 /* << TOOLBAR_SetPadding >> */
3821 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3823 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3828 if (infoPtr == NULL)
3830 hwndOldNotify = infoPtr->hwndNotify;
3831 infoPtr->hwndNotify = (HWND)wParam;
3833 return hwndOldNotify;
3838 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3840 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3841 LPRECT lprc = (LPRECT)lParam;
3845 if (LOWORD(wParam) > 1) {
3846 FIXME("multiple rows not supported!\n");
3849 if(infoPtr->nRows != LOWORD(wParam))
3851 infoPtr->nRows = LOWORD(wParam);
3853 /* recalculate toolbar */
3854 TOOLBAR_CalcToolbar (hwnd);
3856 /* repaint toolbar */
3857 InvalidateRect(hwnd, NULL, FALSE);
3860 /* return bounding rectangle */
3862 lprc->left = infoPtr->rcBound.left;
3863 lprc->right = infoPtr->rcBound.right;
3864 lprc->top = infoPtr->rcBound.top;
3865 lprc->bottom = infoPtr->rcBound.bottom;
3873 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3876 TBUTTON_INFO *btnPtr;
3879 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3883 btnPtr = &infoPtr->buttons[nIndex];
3885 /* if hidden state has changed the invalidate entire window and recalc */
3886 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
3887 btnPtr->fsState = LOWORD(lParam);
3888 TOOLBAR_CalcToolbar (hwnd);
3889 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
3893 /* process state changing if current state doesn't match new state */
3894 if(btnPtr->fsState != LOWORD(lParam))
3896 btnPtr->fsState = LOWORD(lParam);
3897 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3906 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3909 TBUTTON_INFO *btnPtr;
3912 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3916 btnPtr = &infoPtr->buttons[nIndex];
3918 /* process style change if current style doesn't match new style */
3919 if(btnPtr->fsStyle != LOWORD(lParam))
3921 btnPtr->fsStyle = LOWORD(lParam);
3922 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3925 if (infoPtr->hwndToolTip) {
3926 FIXME("change tool tip!\n");
3934 inline static LRESULT
3935 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3939 if (infoPtr == NULL)
3941 infoPtr->hwndToolTip = (HWND)wParam;
3947 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3952 TRACE("%s hwnd=0x%04x stub!\n",
3953 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3955 bTemp = infoPtr->bUnicode;
3956 infoPtr->bUnicode = (BOOL)wParam;
3963 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
3965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3966 INT iOldVersion = infoPtr->iVersion;
3968 infoPtr->iVersion = iVersion;
3975 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
3977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3978 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3981 /* initialize info structure */
3982 infoPtr->nButtonHeight = 22;
3983 infoPtr->nButtonWidth = 24;
3984 infoPtr->nBitmapHeight = 15;
3985 infoPtr->nBitmapWidth = 16;
3987 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
3989 infoPtr->nMaxTextRows = 1;
3990 infoPtr->cxMin = -1;
3991 infoPtr->cxMax = -1;
3992 infoPtr->nNumBitmaps = 0;
3993 infoPtr->nNumStrings = 0;
3995 infoPtr->bCaptured = FALSE;
3996 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3997 infoPtr->nButtonDown = -1;
3998 infoPtr->nOldHit = -1;
3999 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4000 infoPtr->hwndNotify = GetParent (hwnd);
4001 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4002 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4003 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4004 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4005 infoPtr->iVersion = 0;
4006 infoPtr->bNtfUnicode = FALSE;
4007 infoPtr->hwndSelf = hwnd;
4008 infoPtr->bDoRedraw = TRUE;
4010 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4011 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4013 if (dwStyle & TBSTYLE_TOOLTIPS) {
4014 /* Create tooltip control */
4015 infoPtr->hwndToolTip =
4016 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4017 CW_USEDEFAULT, CW_USEDEFAULT,
4018 CW_USEDEFAULT, CW_USEDEFAULT,
4021 /* Send NM_TOOLTIPSCREATED notification */
4022 if (infoPtr->hwndToolTip) {
4023 NMTOOLTIPSCREATED nmttc;
4025 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4027 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4028 NM_TOOLTIPSCREATED);
4032 TOOLBAR_CheckStyle (hwnd, dwStyle);
4034 TOOLBAR_CalcToolbar(hwnd);
4041 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4043 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4045 /* delete tooltip control */
4046 if (infoPtr->hwndToolTip)
4047 DestroyWindow (infoPtr->hwndToolTip);
4049 /* delete button data */
4050 if (infoPtr->buttons)
4051 COMCTL32_Free (infoPtr->buttons);
4053 /* delete strings */
4054 if (infoPtr->strings) {
4056 for (i = 0; i < infoPtr->nNumStrings; i++)
4057 if (infoPtr->strings[i])
4058 COMCTL32_Free (infoPtr->strings[i]);
4060 COMCTL32_Free (infoPtr->strings);
4063 /* destroy internal image list */
4064 if (infoPtr->himlInt)
4065 ImageList_Destroy (infoPtr->himlInt);
4067 /* delete default font */
4069 DeleteObject (infoPtr->hDefaultFont);
4071 /* free toolbar info data */
4072 COMCTL32_Free (infoPtr);
4073 SetWindowLongA (hwnd, 0, 0);
4080 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4082 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4083 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4084 NMTBCUSTOMDRAW tbcd;
4087 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4088 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4089 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4090 tbcd.nmcd.hdc = (HDC)wParam;
4091 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4092 /* FIXME: in general the return flags *can* be or'ed together */
4095 case CDRF_DODEFAULT:
4097 case CDRF_SKIPDEFAULT:
4100 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4105 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4106 * to my parent for processing.
4108 if (infoPtr->bTransparent) {
4110 HDC hdc = (HDC)wParam;
4115 parent = GetParent(hwnd);
4116 MapWindowPoints(hwnd, parent, &pt, 1);
4117 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4118 SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4119 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4122 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4124 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4125 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4126 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4127 tbcd.nmcd.hdc = (HDC)wParam;
4128 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4131 case CDRF_DODEFAULT:
4133 case CDRF_SKIPDEFAULT:
4136 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4145 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4147 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4149 return infoPtr->hFont;
4154 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4156 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4157 TBUTTON_INFO *btnPtr;
4161 pt.x = (INT)LOWORD(lParam);
4162 pt.y = (INT)HIWORD(lParam);
4163 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4166 btnPtr = &infoPtr->buttons[nHit];
4167 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4170 infoPtr->bCaptured = TRUE;
4171 infoPtr->nButtonDown = nHit;
4173 btnPtr->fsState |= TBSTATE_PRESSED;
4175 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4178 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4179 TOOLBAR_Customize (hwnd);
4186 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4188 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4189 TBUTTON_INFO *btnPtr;
4194 if (infoPtr->hwndToolTip)
4195 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4196 WM_LBUTTONDOWN, wParam, lParam);
4198 pt.x = (INT)LOWORD(lParam);
4199 pt.y = (INT)HIWORD(lParam);
4200 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4204 btnPtr = &infoPtr->buttons[nHit];
4205 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4208 infoPtr->nOldHit = nHit;
4210 CopyRect(&arrowRect, &btnPtr->rect);
4211 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4213 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4214 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4215 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4216 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4220 * this time we must force a Redraw, so the btn is
4221 * painted down before CaptureChanged repaints it up
4223 RedrawWindow(hwnd,&btnPtr->rect,0,
4224 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4226 nmtb.iItem = btnPtr->idCommand;
4227 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4230 memset(&nmtb.rcButton, 0, sizeof(RECT));
4231 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4233 if (res != TBDDRET_TREATPRESSED)
4234 /* ??? guess (GA) */
4236 /* otherwise drop through and process as pushed */
4238 /* SetCapture (hwnd); */
4239 infoPtr->bCaptured = TRUE;
4240 infoPtr->nButtonDown = nHit;
4242 btnPtr->fsState |= TBSTATE_PRESSED;
4243 btnPtr->bHot = FALSE;
4245 InvalidateRect(hwnd, &btnPtr->rect,
4246 TOOLBAR_HasText(infoPtr, btnPtr));
4250 /* native issues the TBN_BEGINDRAG here */
4251 nmtb.iItem = btnPtr->idCommand;
4252 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4253 nmtb.tbButton.idCommand = btnPtr->idCommand;
4254 nmtb.tbButton.fsState = btnPtr->fsState;
4255 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4256 nmtb.tbButton.dwData = btnPtr->dwData;
4257 nmtb.tbButton.iString = btnPtr->iString;
4258 nmtb.cchText = 0; /* !!! not correct */
4259 nmtb.pszText = 0; /* !!! not correct */
4260 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4268 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4271 TBUTTON_INFO *btnPtr;
4275 BOOL bSendMessage = TRUE;
4280 if (infoPtr->hwndToolTip)
4281 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4282 WM_LBUTTONUP, wParam, lParam);
4284 pt.x = (INT)LOWORD(lParam);
4285 pt.y = (INT)HIWORD(lParam);
4286 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4288 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4289 /* if the cursor is still inside of the toolbar */
4290 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4291 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4293 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
4294 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4295 btnPtr->fsState &= ~TBSTATE_PRESSED;
4297 if (nHit == infoPtr->nButtonDown) {
4298 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4299 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4300 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4301 infoPtr->nButtonDown);
4302 if (nOldIndex == infoPtr->nButtonDown)
4303 bSendMessage = FALSE;
4304 if ((nOldIndex != infoPtr->nButtonDown) &&
4306 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4307 btnPtr->fsState |= TBSTATE_CHECKED;
4310 if (btnPtr->fsState & TBSTATE_CHECKED)
4311 btnPtr->fsState &= ~TBSTATE_CHECKED;
4313 btnPtr->fsState |= TBSTATE_CHECKED;
4318 bSendMessage = FALSE;
4320 if (nOldIndex != -1)
4322 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4323 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4327 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4328 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4329 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4333 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4334 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4335 NM_RELEASEDCAPTURE);
4337 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4340 nmtb.iItem = btnPtr->idCommand;
4341 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4342 nmtb.tbButton.idCommand = btnPtr->idCommand;
4343 nmtb.tbButton.fsState = btnPtr->fsState;
4344 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4345 nmtb.tbButton.dwData = btnPtr->dwData;
4346 nmtb.tbButton.iString = btnPtr->iString;
4347 nmtb.cchText = 0; /* !!! not correct */
4348 nmtb.pszText = 0; /* !!! not correct */
4349 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4353 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4354 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
4356 /* !!! Undocumented - toolbar at 4.71 level and above sends
4357 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4358 * Only NM_RCLICK is documented.
4360 nmmouse.dwItemSpec = btnPtr->idCommand;
4361 nmmouse.dwItemData = btnPtr->dwData;
4362 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4370 TOOLBAR_CaptureChanged(HWND hwnd)
4372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4373 TBUTTON_INFO *btnPtr;
4375 infoPtr->bCaptured = FALSE;
4377 if (infoPtr->nButtonDown >= 0)
4379 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4380 btnPtr->fsState &= ~TBSTATE_PRESSED;
4382 infoPtr->nButtonDown = -1;
4383 infoPtr->nOldHit = -1;
4385 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4392 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4394 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4395 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4398 if (infoPtr->nOldHit < 0)
4401 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4403 /* Redraw the button if the last button we were over is the hot button and it
4405 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4407 hotBtnPtr->bHot = FALSE;
4408 rc1 = hotBtnPtr->rect;
4409 InflateRect (&rc1, 1, 1);
4410 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4414 /* If the last button we were over is depressed then make it not */
4415 /* depressed and redraw it */
4416 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4418 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4420 btnPtr->fsState &= ~TBSTATE_PRESSED;
4422 rc1 = hotBtnPtr->rect;
4423 InflateRect (&rc1, 1, 1);
4424 InvalidateRect (hwnd, &rc1, TRUE);
4427 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4428 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4434 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4436 TBUTTON_INFO *btnPtr, *oldBtnPtr;
4437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4440 TRACKMOUSEEVENT trackinfo;
4442 /* fill in the TRACKMOUSEEVENT struct */
4443 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4444 trackinfo.dwFlags = TME_QUERY;
4445 trackinfo.hwndTrack = hwnd;
4446 trackinfo.dwHoverTime = HOVER_DEFAULT;
4448 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4449 _TrackMouseEvent(&trackinfo);
4451 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4452 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4453 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4455 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4456 /* and can properly deactivate the hot toolbar button */
4457 _TrackMouseEvent(&trackinfo);
4460 if (infoPtr->hwndToolTip)
4461 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4462 WM_MOUSEMOVE, wParam, lParam);
4464 pt.x = (INT)LOWORD(lParam);
4465 pt.y = (INT)HIWORD(lParam);
4467 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4469 if (infoPtr->nOldHit != nHit)
4471 /* Remove the effect of an old hot button if the button was enabled and was
4472 drawn with the hot button effect */
4473 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
4474 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
4476 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4477 oldBtnPtr->bHot = FALSE;
4479 InvalidateRect (hwnd, &oldBtnPtr->rect,
4480 TOOLBAR_HasText(infoPtr, oldBtnPtr));
4483 /* It's not a separator or in nowhere. It's a hot button. */
4486 btnPtr = &infoPtr->buttons[nHit];
4488 infoPtr->nHotItem = nHit;
4490 /* only enabled buttons show hot effect */
4491 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
4493 btnPtr->bHot = TRUE;
4494 InvalidateRect(hwnd, &btnPtr->rect,
4495 TOOLBAR_HasText(infoPtr, btnPtr));
4500 if (infoPtr->bCaptured) {
4501 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4502 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
4503 btnPtr->fsState &= ~TBSTATE_PRESSED;
4504 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4506 else if (nHit == infoPtr->nButtonDown) {
4507 btnPtr->fsState |= TBSTATE_PRESSED;
4508 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4511 infoPtr->nOldHit = nHit;
4517 inline static LRESULT
4518 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4520 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
4521 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
4523 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
4527 inline static LRESULT
4528 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4530 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
4531 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
4533 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
4538 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4540 TOOLBAR_INFO *infoPtr;
4541 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
4544 /* allocate memory for info structure */
4545 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
4546 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4549 infoPtr->dwStructSize = sizeof(TBBUTTON);
4551 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
4552 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
4553 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
4554 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
4557 /* native control does:
4558 * Get a lot of colors and brushes
4560 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
4561 * CreateFontIndirectA(adr1)
4562 * CreateBitmap(0x27, 0x24, 1, 1, 0)
4563 * hdc = GetDC(toolbar)
4564 * GetSystemMetrics(0x48)
4565 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
4566 * 0, 0, 0, 0, "MARLETT")
4567 * oldfnt = SelectObject(hdc, fnt2)
4568 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
4569 * GetTextMetricsA(hdc, adr3)
4570 * SelectObject(hdc, oldfnt)
4571 * DeleteObject(fnt2)
4573 * InvalidateRect(toolbar, 0, 1)
4574 * SetWindowLongA(toolbar, 0, addr)
4575 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
4578 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
4579 * ie 2 0x4600094c 0x4600094c 0x4600894d
4580 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
4581 * rebar 0x50008844 0x40008844 0x50008845
4582 * pager 0x50000844 0x40000844 0x50008845
4583 * IC35mgr 0x5400084e **nochange**
4584 * on entry to _NCCREATE 0x5400084e
4585 * rowlist 0x5400004e **nochange**
4586 * on entry to _NCCREATE 0x5400004e
4590 /* I think the code below is a bug, but it is the way that the native
4591 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
4592 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
4593 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
4594 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
4595 * Some how, the only cases of this seem to be MFC programs.
4597 * Note also that the addition of _TRANSPARENT occurs *only* here. It
4598 * does not occur in the WM_STYLECHANGING routine.
4599 * (Guy Albertelli 9/2001)
4602 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
4603 styleadd |= TBSTYLE_TRANSPARENT;
4604 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
4605 styleadd |= CCS_TOP; /* default to top */
4606 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
4609 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
4614 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
4616 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4620 if (dwStyle & WS_MINIMIZE)
4621 return 0; /* Nothing to do */
4623 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
4625 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
4628 if (!(dwStyle & CCS_NODIVIDER))
4630 GetWindowRect (hwnd, &rcWindow);
4631 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4632 if( dwStyle & WS_BORDER )
4633 OffsetRect (&rcWindow, 1, 1);
4634 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
4637 ReleaseDC( hwnd, hdc );
4643 inline static LRESULT
4644 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
4646 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4647 LPNMHDR lpnmh = (LPNMHDR)lParam;
4649 if (lpnmh->code == PGN_CALCSIZE) {
4650 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
4652 if (lppgc->dwFlag == PGF_CALCWIDTH) {
4653 lppgc->iWidth = infoPtr->nWidth;
4654 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
4658 lppgc->iHeight = infoPtr->nHeight;
4659 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
4666 TRACE("passing WM_NOTIFY!\n");
4668 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
4669 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
4672 if (lpnmh->code == TTN_GETDISPINFOA) {
4673 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
4675 FIXME("retrieving ASCII string\n");
4678 else if (lpnmh->code == TTN_GETDISPINFOW) {
4679 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
4681 FIXME("retrieving UNICODE string\n");
4692 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
4694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4698 /* fill ps.rcPaint with a default rect */
4699 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
4701 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
4703 TRACE("psrect=(%d,%d)-(%d,%d)\n",
4704 ps.rcPaint.left, ps.rcPaint.top,
4705 ps.rcPaint.right, ps.rcPaint.bottom);
4707 TOOLBAR_Refresh (hwnd, hdc, &ps);
4708 if (!wParam) EndPaint (hwnd, &ps);
4715 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
4716 /*****************************************************
4719 * Handles the WM_SETREDRAW message.
4722 * According to testing V4.71 of COMCTL32 returns the
4723 * *previous* status of the redraw flag (either 0 or 1)
4724 * instead of the MSDN documented value of 0 if handled.
4725 * (For laughs see the "consistancy" with same function
4728 *****************************************************/
4730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4731 BOOL oldredraw = infoPtr->bDoRedraw;
4733 TRACE("set to %s\n",
4734 (wParam) ? "TRUE" : "FALSE");
4735 infoPtr->bDoRedraw = (BOOL) wParam;
4737 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4739 return (oldredraw) ? 1 : 0;
4744 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
4746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4747 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4756 /* Resize deadlock check */
4757 if (infoPtr->bAutoSize) {
4758 infoPtr->bAutoSize = FALSE;
4762 /* FIXME: optimize to only update size if the new size doesn't */
4763 /* match the current size */
4765 flags = (INT) wParam;
4767 /* FIXME for flags =
4768 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
4771 TRACE("sizing toolbar!\n");
4773 if (flags == SIZE_RESTORED) {
4774 /* width and height don't apply */
4775 parent = GetParent (hwnd);
4776 GetClientRect(parent, &parent_rect);
4777 x = parent_rect.left;
4778 y = parent_rect.top;
4780 if (dwStyle & CCS_NORESIZE) {
4781 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
4784 * this sets the working width of the toolbar, and
4785 * Calc Toolbar will not adjust it, only the height
4787 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4788 cy = infoPtr->nHeight;
4789 cx = infoPtr->nWidth;
4790 TOOLBAR_CalcToolbar (hwnd);
4791 infoPtr->nWidth = cx;
4792 infoPtr->nHeight = cy;
4795 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4796 TOOLBAR_CalcToolbar (hwnd);
4797 cy = infoPtr->nHeight;
4798 cx = infoPtr->nWidth;
4800 if (dwStyle & CCS_NOMOVEY) {
4801 GetWindowRect(hwnd, &window_rect);
4802 ScreenToClient(parent, (LPPOINT)&window_rect.left);
4803 y = window_rect.top;
4807 if (dwStyle & CCS_NOPARENTALIGN) {
4808 uPosFlags |= SWP_NOMOVE;
4809 cy = infoPtr->nHeight;
4810 cx = infoPtr->nWidth;
4813 if (!(dwStyle & CCS_NODIVIDER))
4814 cy += GetSystemMetrics(SM_CYEDGE);
4816 if (dwStyle & WS_BORDER)
4819 cy += GetSystemMetrics(SM_CYEDGE);
4820 cx += GetSystemMetrics(SM_CYEDGE);
4823 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
4824 cx, cy, uPosFlags | SWP_NOZORDER);
4831 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
4833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4835 if (nType == GWL_STYLE) {
4836 if (lpStyle->styleNew & TBSTYLE_LIST) {
4837 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
4840 infoPtr->dwDTFlags = DT_CENTER;
4842 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
4843 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
4844 (TBSTYLE_FLAT | TBSTYLE_LIST));
4845 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
4848 TOOLBAR_AutoSize (hwnd);
4850 InvalidateRect(hwnd, NULL, FALSE);
4857 static LRESULT WINAPI
4858 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4860 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4861 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4863 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
4864 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
4869 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
4871 case TB_ADDBUTTONSA:
4872 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
4874 case TB_ADDBUTTONSW:
4875 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
4878 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
4881 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
4884 return TOOLBAR_AutoSize (hwnd);
4886 case TB_BUTTONCOUNT:
4887 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
4889 case TB_BUTTONSTRUCTSIZE:
4890 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
4892 case TB_CHANGEBITMAP:
4893 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
4895 case TB_CHECKBUTTON:
4896 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
4898 case TB_COMMANDTOINDEX:
4899 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
4902 return TOOLBAR_Customize (hwnd);
4904 case TB_DELETEBUTTON:
4905 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
4907 case TB_ENABLEBUTTON:
4908 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
4910 case TB_GETANCHORHIGHLIGHT:
4911 return TOOLBAR_GetAnchorHighlight (hwnd);
4914 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
4916 case TB_GETBITMAPFLAGS:
4917 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
4920 return TOOLBAR_GetButton (hwnd, wParam, lParam);
4922 case TB_GETBUTTONINFOA:
4923 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
4925 case TB_GETBUTTONINFOW:
4926 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
4928 case TB_GETBUTTONSIZE:
4929 return TOOLBAR_GetButtonSize (hwnd);
4931 case TB_GETBUTTONTEXTA:
4932 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
4934 case TB_GETBUTTONTEXTW:
4935 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
4937 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
4939 case TB_GETDISABLEDIMAGELIST:
4940 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
4942 case TB_GETEXTENDEDSTYLE:
4943 return TOOLBAR_GetExtendedStyle (hwnd);
4945 case TB_GETHOTIMAGELIST:
4946 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
4949 return TOOLBAR_GetHotItem (hwnd);
4951 case TB_GETIMAGELIST:
4952 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
4954 /* case TB_GETINSERTMARK: */ /* 4.71 */
4955 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
4957 case TB_GETITEMRECT:
4958 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
4961 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
4963 /* case TB_GETOBJECT: */ /* 4.71 */
4964 /* case TB_GETPADDING: */ /* 4.71 */
4967 return TOOLBAR_GetRect (hwnd, wParam, lParam);
4970 return TOOLBAR_GetRows (hwnd, wParam, lParam);
4973 return TOOLBAR_GetState (hwnd, wParam, lParam);
4976 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
4978 case TB_GETTEXTROWS:
4979 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
4981 case TB_GETTOOLTIPS:
4982 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
4984 case TB_GETUNICODEFORMAT:
4985 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
4987 case CCM_GETVERSION:
4988 return TOOLBAR_GetVersion (hwnd);
4991 return TOOLBAR_HideButton (hwnd, wParam, lParam);
4994 return TOOLBAR_HitTest (hwnd, wParam, lParam);
4996 case TB_INDETERMINATE:
4997 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
4999 case TB_INSERTBUTTONA:
5000 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5002 case TB_INSERTBUTTONW:
5003 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5005 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5007 case TB_ISBUTTONCHECKED:
5008 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5010 case TB_ISBUTTONENABLED:
5011 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5013 case TB_ISBUTTONHIDDEN:
5014 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5016 case TB_ISBUTTONHIGHLIGHTED:
5017 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5019 case TB_ISBUTTONINDETERMINATE:
5020 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5022 case TB_ISBUTTONPRESSED:
5023 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5025 case TB_LOADIMAGES: /* 4.70 */
5026 FIXME("missing standard imagelists\n");
5029 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5030 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5031 /* case TB_MARKBUTTON: */ /* 4.71 */
5032 /* case TB_MOVEBUTTON: */ /* 4.71 */
5034 case TB_PRESSBUTTON:
5035 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5037 /* case TB_REPLACEBITMAP: */
5039 case TB_SAVERESTOREA:
5040 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5042 case TB_SAVERESTOREW:
5043 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5045 case TB_SETANCHORHIGHLIGHT:
5046 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5048 case TB_SETBITMAPSIZE:
5049 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5051 case TB_SETBUTTONINFOA:
5052 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5054 case TB_SETBUTTONINFOW:
5055 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5057 case TB_SETBUTTONSIZE:
5058 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5060 case TB_SETBUTTONWIDTH:
5061 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5064 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5066 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
5068 case TB_SETDISABLEDIMAGELIST:
5069 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5071 case TB_SETDRAWTEXTFLAGS:
5072 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5074 case TB_SETEXTENDEDSTYLE:
5075 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5077 case TB_SETHOTIMAGELIST:
5078 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5081 return TOOLBAR_SetHotItem (hwnd, wParam);
5083 case TB_SETIMAGELIST:
5084 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5087 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5089 /* case TB_SETINSERTMARK: */ /* 4.71 */
5091 case TB_SETINSERTMARKCOLOR:
5092 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5094 case TB_SETMAXTEXTROWS:
5095 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5097 /* case TB_SETPADDING: */ /* 4.71 */
5100 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5103 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5106 return TOOLBAR_SetState (hwnd, wParam, lParam);
5109 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5111 case TB_SETTOOLTIPS:
5112 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5114 case TB_SETUNICODEFORMAT:
5115 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5117 case CCM_SETVERSION:
5118 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5124 return TOOLBAR_Create (hwnd, wParam, lParam);
5127 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5130 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5133 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5135 /* case WM_KEYDOWN: */
5136 /* case WM_KILLFOCUS: */
5138 case WM_LBUTTONDBLCLK:
5139 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5141 case WM_LBUTTONDOWN:
5142 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5145 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5148 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5151 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5153 case WM_CAPTURECHANGED:
5154 return TOOLBAR_CaptureChanged(hwnd);
5157 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5160 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5163 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5166 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5169 return TOOLBAR_Notify (hwnd, wParam, lParam);
5171 /* case WM_NOTIFYFORMAT: */
5174 return TOOLBAR_Paint (hwnd, wParam);
5177 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5180 return TOOLBAR_Size (hwnd, wParam, lParam);
5182 case WM_STYLECHANGED:
5183 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5185 /* case WM_SYSCOLORCHANGE: */
5187 /* case WM_WININICHANGE: */
5192 case WM_MEASUREITEM:
5195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5197 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5199 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5203 if (uMsg >= WM_USER)
5204 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5205 uMsg, wParam, lParam);
5206 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5213 TOOLBAR_Register (void)
5217 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5218 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5219 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5220 wndClass.cbClsExtra = 0;
5221 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5222 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5223 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5224 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5226 RegisterClassA (&wndClass);
5231 TOOLBAR_Unregister (void)
5233 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);