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_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
154 if (TRACE_ON(toolbar)){
155 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, string=%d\n",
156 btn_num, bP->idCommand,
157 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
159 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
160 btn_num, bP->idCommand,
161 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
162 bP->rect.left, bP->rect.top,
163 bP->rect.right, bP->rect.bottom);
169 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
171 if (TRACE_ON(toolbar)) {
175 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
176 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
178 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
179 iP->nNumStrings, dwStyle);
180 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
182 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
183 (iP->bDoRedraw) ? "TRUE" : "FALSE");
184 for(i=0; i<iP->nNumButtons; i++) {
185 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
191 /***********************************************************************
194 * This function validates that the styles set are implemented and
195 * issues FIXME's warning of possible problems. In a perfect world this
196 * function should be null.
199 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
201 if (dwStyle & TBSTYLE_ALTDRAG)
202 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
203 if (dwStyle & TBSTYLE_REGISTERDROP)
204 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
209 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
211 if(!IsWindow(infoPtr->hwndSelf))
212 return 0; /* we have just been destroyed */
214 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
215 nmhdr->hwndFrom = infoPtr->hwndSelf;
218 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
219 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
221 if (infoPtr->bNtfUnicode)
222 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
223 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
225 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
226 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
230 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
232 LPWSTR lpText = NULL;
234 /* FIXME: iString == -1 is undocumented */
235 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
236 lpText = (LPWSTR)btnPtr->iString;
237 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
238 lpText = infoPtr->strings[btnPtr->iString];
243 /***********************************************************************
244 * TOOLBAR_GetBitmapIndex
246 * This function returns the bitmap index associated with a button.
247 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
248 * is issued to retrieve the index.
251 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
253 INT ret = btnPtr->iBitmap;
255 if (ret == I_IMAGECALLBACK) {
256 /* issue TBN_GETDISPINFO */
259 nmgd.idCommand = btnPtr->idCommand;
260 nmgd.lParam = btnPtr->dwData;
261 nmgd.dwMask = TBNF_IMAGE;
262 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
263 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
265 if (nmgd.dwMask & TBNF_DI_SETITEM) {
266 btnPtr->iBitmap = nmgd.iImage;
269 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
270 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
277 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
279 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
280 (index == I_IMAGECALLBACK))
287 /***********************************************************************
288 * TOOLBAR_DrawImageList
290 * This function validates the bitmap index (including I_IMAGECALLBACK
291 * functionality). It then draws the image via the ImageList_Draw
292 * function. It returns TRUE if the image was drawn, FALSE otherwise.
295 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
296 HDC hdc, UINT left, UINT top, UINT draw_flags)
300 if (!himl) return FALSE;
302 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
303 ERR("index %d is not valid, max %d\n",
304 btnPtr->iBitmap, infoPtr->nNumBitmaps);
308 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
309 if (index == -1) return FALSE;
310 ERR("TBN_GETDISPINFO returned invalid index %d\n",
314 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
315 index, himl, left, top, draw_flags);
317 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
322 /***********************************************************************
323 * TOOLBAR_TestImageExist
325 * This function is similar to TOOLBAR_DrawImageList, except it does not
326 * draw the image. The I_IMAGECALLBACK functionality is implemented.
329 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
333 if (!himl) return FALSE;
335 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
336 ERR("index %d is not valid, max %d\n",
337 btnPtr->iBitmap, infoPtr->nNumBitmaps);
341 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
342 if (index == -1) return FALSE;
343 ERR("TBN_GETDISPINFO returned invalid index %d\n",
352 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
354 INT x = (lpRect->left + lpRect->right) / 2 - 1;
355 INT yBottom = lpRect->bottom - 3;
356 INT yTop = lpRect->top + 1;
358 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
359 MoveToEx (hdc, x, yBottom, NULL);
360 LineTo (hdc, x, yTop);
362 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
363 MoveToEx (hdc, x, yBottom, NULL);
364 LineTo (hdc, x, yTop);
368 /***********************************************************************
369 * TOOLBAR_DrawDDFlatSeparator
371 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
372 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
373 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
374 * are horizontal as opposed to the vertical separators for not dropdown
377 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
380 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr)
383 COLORREF oldcolor, newcolor;
385 myrect.left = lpRect->left;
386 myrect.right = lpRect->right;
387 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
388 myrect.bottom = myrect.top + 1;
390 InflateRect (&myrect, -2, 0);
392 TRACE("rect=(%d,%d)-(%d,%d)\n",
393 myrect.left, myrect.top, myrect.right, myrect.bottom);
395 newcolor = GetSysColor (COLOR_BTNSHADOW);
396 oldcolor = SetBkColor (hdc, newcolor);
397 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
399 myrect.top = myrect.bottom;
400 myrect.bottom = myrect.top + 1;
402 newcolor = GetSysColor (COLOR_BTNHIGHLIGHT);
403 SetBkColor (hdc, newcolor);
404 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
406 SetBkColor (hdc, oldcolor);
411 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
414 SelectObject ( hdc, GetSysColorPen (colorRef));
417 MoveToEx (hdc, x, y, NULL);
418 LineTo (hdc, x+5, y++); x++;
419 MoveToEx (hdc, x, y, NULL);
420 LineTo (hdc, x+3, y++); x++;
421 MoveToEx (hdc, x, y, NULL);
422 LineTo (hdc, x+1, y++);
426 * Draw the text string for this button.
427 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
428 * is non-zero, so we can simply check himlDef to see if we have
432 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
433 HDC hdc, INT nState, DWORD dwStyle)
435 RECT rcText = btnPtr->rect;
438 LPWSTR lpText = NULL;
439 HIMAGELIST himl = infoPtr->himlDef;
441 TRACE ("iString: %x\n", btnPtr->iString);
443 /* get a pointer to the text */
444 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
446 TRACE ("lpText: %s\n", debugstr_w(lpText));
451 InflateRect (&rcText, -3, -3);
453 if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
454 /* The following test looked like this before
455 * I changed it. IE4 "Links" toolbar would not
456 * draw correctly with the original code. - GA 8/01
457 * ((dwStyle & TBSTYLE_LIST) &&
458 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
459 * (btnPtr->iBitmap != I_IMAGENONE))
461 if (dwStyle & TBSTYLE_LIST) {
462 /* LIST style w/ ICON offset is by matching native. */
463 /* Matches IE4 "Links" bar. - GA 8/01 */
464 rcText.left += (infoPtr->nBitmapWidth + 2);
467 rcText.top += infoPtr->nBitmapHeight + 1;
471 if (dwStyle & TBSTYLE_LIST) {
472 /* LIST style w/o ICON offset is by matching native. */
473 /* Matches IE4 "menu" bar. - GA 8/01 */
478 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
479 OffsetRect (&rcText, 1, 1);
481 TRACE("string rect=(%d,%d)-(%d,%d)\n",
482 rcText.left, rcText.top, rcText.right, rcText.bottom);
484 hOldFont = SelectObject (hdc, infoPtr->hFont);
485 if (!(nState & TBSTATE_ENABLED)) {
486 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
487 OffsetRect (&rcText, 1, 1);
488 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
489 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
490 OffsetRect (&rcText, -1, -1);
491 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
493 else if (nState & TBSTATE_INDETERMINATE) {
494 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
495 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
498 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
499 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
502 SetTextColor (hdc, clrOld);
503 SelectObject (hdc, hOldFont);
509 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
511 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
512 INT cx = lpRect->right - lpRect->left;
513 INT cy = lpRect->bottom - lpRect->top;
514 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
515 SelectObject (hdc, hbr);
520 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
521 HDC hdc, INT x, INT y)
523 /* FIXME: this function is a hack since it uses image list
524 internals directly */
526 HIMAGELIST himl = infoPtr->himlDef;
534 /* create new dc's */
535 hdcImageList = CreateCompatibleDC (0);
536 hdcMask = CreateCompatibleDC (0);
538 /* create new bitmap */
539 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
540 SelectObject (hdcMask, hbmMask);
542 /* copy the mask bitmap */
543 SelectObject (hdcImageList, himl->hbmMask);
544 SetBkColor (hdcImageList, RGB(255, 255, 255));
545 SetTextColor (hdcImageList, RGB(0, 0, 0));
546 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
547 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
549 /* draw the new mask */
550 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
551 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
552 hdcMask, 0, 0, 0xB8074A);
554 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
555 BitBlt (hdc, x, y, himl->cx, himl->cy,
556 hdcMask, 0, 0, 0xB8074A);
558 DeleteObject (hbmMask);
560 DeleteDC (hdcImageList);
565 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
568 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
569 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
570 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
571 RECT rc, rcArrow, rcBitmap;
573 if (btnPtr->fsState & TBSTATE_HIDDEN)
577 CopyRect (&rcArrow, &rc);
578 CopyRect(&rcBitmap, &rc);
580 if (!infoPtr->bBtnTranspnt)
581 FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
583 if (hasDropDownArrow)
585 if (dwStyle & TBSTYLE_FLAT)
586 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
588 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
589 rcArrow.left = rc.right;
592 /* Center the bitmap horizontally and vertically */
593 if (dwStyle & TBSTYLE_LIST)
596 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
598 if(TOOLBAR_HasText(infoPtr, btnPtr))
599 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
601 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
603 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
604 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
605 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
608 if (btnPtr->fsStyle & TBSTYLE_SEP) {
609 /* with the FLAT style, iBitmap is the width and has already */
610 /* been taken into consideration in calculating the width */
611 /* so now we need to draw the vertical separator */
612 /* empirical tests show that iBitmap can/will be non-zero */
613 /* when drawing the vertical bar... */
614 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
615 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
616 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr);
618 TOOLBAR_DrawFlatSeparator (&rc, hdc);
624 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
625 if (!(dwStyle & TBSTYLE_FLAT))
627 DrawEdge (hdc, &rc, EDGE_RAISED,
628 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
629 if (hasDropDownArrow)
630 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
631 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
634 if (hasDropDownArrow)
636 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
637 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
640 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
641 hdc, rcBitmap.left, rcBitmap.top,
643 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
645 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
649 /* pressed TBSTYLE_BUTTON */
650 if (btnPtr->fsState & TBSTATE_PRESSED) {
651 if (dwStyle & TBSTYLE_FLAT)
653 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
654 if (hasDropDownArrow)
655 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
659 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
660 if (hasDropDownArrow)
661 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
664 if (hasDropDownArrow)
665 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
667 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
668 hdc, rcBitmap.left+1, rcBitmap.top+1,
671 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
675 /* checked TBSTYLE_CHECK */
676 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
677 (btnPtr->fsState & TBSTATE_CHECKED)) {
678 if (dwStyle & TBSTYLE_FLAT)
679 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
680 BF_RECT | BF_ADJUST);
682 DrawEdge (hdc, &rc, EDGE_SUNKEN,
683 BF_RECT | BF_MIDDLE | BF_ADJUST);
685 TOOLBAR_DrawPattern (hdc, &rc);
687 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
688 hdc, rcBitmap.left+1, rcBitmap.top+1,
691 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
696 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
697 DrawEdge (hdc, &rc, EDGE_RAISED,
698 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
700 TOOLBAR_DrawPattern (hdc, &rc);
701 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
702 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
707 if (dwStyle & TBSTYLE_FLAT)
711 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
712 if (hasDropDownArrow)
713 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
716 else /* The following code needs to be removed after
717 * "hot item" support has been implemented for the
718 * case where it is being de-selected.
721 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
722 if (hasDropDownArrow)
723 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
727 if (hasDropDownArrow)
728 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
731 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
732 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
735 rcBitmap.top, ILD_NORMAL))
736 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
737 hdc, rcBitmap.left, rcBitmap.top,
741 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
742 hdc, rcBitmap.left, rcBitmap.top,
747 DrawEdge (hdc, &rc, EDGE_RAISED,
748 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
750 if (hasDropDownArrow)
752 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
753 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
754 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
757 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
758 hdc, rcBitmap.left, rcBitmap.top,
762 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
767 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
770 TBUTTON_INFO *btnPtr;
771 INT i, oldBKmode = 0;
774 /* if imagelist belongs to the app, it can be changed
775 by the app after setting it */
776 if (infoPtr->himlDef != infoPtr->himlInt)
777 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
779 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
781 if (infoPtr->bBtnTranspnt)
782 oldBKmode = SetBkMode (hdc, TRANSPARENT);
784 /* redraw necessary buttons */
785 btnPtr = infoPtr->buttons;
786 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
788 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
789 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
792 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
793 SetBkMode (hdc, oldBKmode);
796 /***********************************************************************
797 * TOOLBAR_MeasureString
799 * This function gets the width and height of a string in pixels. This
800 * is done first by using GetTextExtentPoint to get the basic width
801 * and height. The DrawText is called with DT_CALCRECT to get the exact
802 * width. The reason is because the text may have more than one "&" (or
803 * prefix characters as M$ likes to call them). The prefix character
804 * indicates where the underline goes, except for the string "&&" which
805 * is reduced to a single "&". GetTextExtentPoint does not process these
806 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
809 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
810 HDC hdc, LPSIZE lpSize)
817 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
818 (btnPtr->iString > -1) &&
819 (btnPtr->iString < infoPtr->nNumStrings))
821 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
823 /* first get size of all the text */
824 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
826 /* feed above size into the rectangle for DrawText */
827 myrect.left = myrect.top = 0;
828 myrect.right = lpSize->cx;
829 myrect.bottom = lpSize->cy;
831 /* Use DrawText to get true size as drawn (less pesky "&") */
832 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
833 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
836 /* feed back to caller */
837 lpSize->cx = myrect.right;
838 lpSize->cy = myrect.bottom;
841 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
844 /***********************************************************************
845 * TOOLBAR_CalcStrings
847 * This function walks through each string and measures it and returns
848 * the largest height and width to caller.
851 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
854 TBUTTON_INFO *btnPtr;
864 hOldFont = SelectObject (hdc, infoPtr->hFont);
866 btnPtr = infoPtr->buttons;
867 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
868 if(TOOLBAR_HasText(infoPtr, btnPtr))
870 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
871 if (sz.cx > lpSize->cx)
873 if (sz.cy > lpSize->cy)
878 SelectObject (hdc, hOldFont);
879 ReleaseDC (hwnd, hdc);
881 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
884 /***********************************************************************
885 * TOOLBAR_WrapToolbar
887 * This function walks through the buttons and seperators in the
888 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
889 * wrapping should occur based on the width of the toolbar window.
890 * It does *not* calculate button placement itself. That task
891 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
892 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
893 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
897 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
899 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
900 TBUTTON_INFO *btnPtr;
903 BOOL bWrap, bButtonWrap;
905 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
906 /* no layout is necessary. Applications may use this style */
907 /* to perform their own layout on the toolbar. */
908 if( !(dwStyle & TBSTYLE_WRAPABLE) )
911 btnPtr = infoPtr->buttons;
912 x = infoPtr->nIndent;
914 /* this can get the parents width, to know how far we can extend
915 * this toolbar. We cannot use its height, as there may be multiple
916 * toolbars in a rebar control
918 GetClientRect( GetParent(hwnd), &rc );
919 infoPtr->nWidth = rc.right - rc.left;
922 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
923 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
926 for (i = 0; i < infoPtr->nNumButtons; i++ )
929 btnPtr[i].fsState &= ~TBSTATE_WRAP;
931 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
934 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
935 /* it is the actual width of the separator. This is used for */
936 /* custom controls in toolbars. */
938 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
939 /* width. - GA 8/01 */
940 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
941 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
942 cx = (btnPtr[i].iBitmap > 0) ?
943 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
945 cx = infoPtr->nButtonWidth;
947 /* Two or more adjacent separators form a separator group. */
948 /* The first separator in a group should be wrapped to the */
949 /* next row if the previous wrapping is on a button. */
951 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
952 (i + 1 < infoPtr->nNumButtons ) &&
953 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
955 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
956 btnPtr[i].fsState |= TBSTATE_WRAP;
957 x = infoPtr->nIndent;
963 /* The layout makes sure the bitmap is visible, but not the button. */
964 /* Test added to also wrap after a button that starts a row but */
965 /* is bigger than the area. - GA 8/01 */
966 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
967 > infoPtr->nWidth ) ||
968 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
972 /* If the current button is a separator and not hidden, */
973 /* go to the next until it reaches a non separator. */
974 /* Wrap the last separator if it is before a button. */
975 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
976 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
977 i < infoPtr->nNumButtons )
983 if( bFound && i < infoPtr->nNumButtons )
986 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
987 i, btnPtr[i].fsStyle, x, cx);
988 btnPtr[i].fsState |= TBSTATE_WRAP;
989 x = infoPtr->nIndent;
993 else if ( i >= infoPtr->nNumButtons)
996 /* If the current button is not a separator, find the last */
997 /* separator and wrap it. */
998 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1000 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1001 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1005 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1006 i, btnPtr[i].fsStyle, x, cx);
1007 x = infoPtr->nIndent;
1008 btnPtr[j].fsState |= TBSTATE_WRAP;
1009 bButtonWrap = FALSE;
1014 /* If no separator available for wrapping, wrap one of */
1015 /* non-hidden previous button. */
1019 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1021 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1026 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1027 i, btnPtr[i].fsStyle, x, cx);
1028 x = infoPtr->nIndent;
1029 btnPtr[j].fsState |= TBSTATE_WRAP;
1035 /* If all above failed, wrap the current button. */
1038 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1039 i, btnPtr[i].fsStyle, x, cx);
1040 btnPtr[i].fsState |= TBSTATE_WRAP;
1042 x = infoPtr->nIndent;
1043 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1044 bButtonWrap = FALSE;
1050 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1051 i, btnPtr[i].fsStyle, x, cx);
1058 /***********************************************************************
1059 * TOOLBAR_CalcToolbar
1061 * This function calculates button and separator placement. It first
1062 * calculates the button sizes, gets the toolbar window width and then
1063 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1064 * on. It assigns a new location to each item and sends this location to
1065 * the tooltip window if appropriate. Finally, it updates the rcBound
1066 * rect and calculates the new required toolbar window height.
1070 TOOLBAR_CalcToolbar (HWND hwnd)
1072 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1073 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1074 TBUTTON_INFO *btnPtr;
1075 INT i, nRows, nSepRows;
1079 BOOL usesBitmaps = FALSE;
1080 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1082 TOOLBAR_CalcStrings (hwnd, &sizeString);
1084 if (dwStyle & TBSTYLE_LIST)
1086 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1088 if (infoPtr->buttons[i].iBitmap >= 0)
1091 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1092 0, sizeString.cy) + 6;
1093 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1094 0) + sizeString.cx + 6;
1095 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1096 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1097 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1098 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1101 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1103 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1107 if (sizeString.cy > 0)
1110 infoPtr->nButtonHeight = sizeString.cy +
1111 2 + /* this is the space to separate text from bitmap */
1112 infoPtr->nBitmapHeight + 6;
1114 infoPtr->nButtonHeight = sizeString.cy + 6;
1116 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1117 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1119 if (sizeString.cx > infoPtr->nBitmapWidth)
1120 infoPtr->nButtonWidth = sizeString.cx + 6;
1121 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1122 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1125 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1126 infoPtr->nButtonWidth = infoPtr->cxMin;
1127 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1128 infoPtr->nButtonWidth = infoPtr->cxMax;
1130 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1132 x = infoPtr->nIndent;
1136 * We will set the height below, and we set the width on entry
1137 * so we do not reset them here..
1140 GetClientRect( hwnd, &rc );
1141 /* get initial values for toolbar */
1142 infoPtr->nWidth = rc.right - rc.left;
1143 infoPtr->nHeight = rc.bottom - rc.top;
1146 /* from above, minimum is a button, and possible text */
1147 cx = infoPtr->nButtonWidth;
1149 /* cannot use just ButtonHeight, we may have no buttons! */
1150 if (infoPtr->nNumButtons > 0)
1151 infoPtr->nHeight = infoPtr->nButtonHeight;
1153 cy = infoPtr->nHeight;
1155 nRows = nSepRows = 0;
1157 infoPtr->rcBound.top = y;
1158 infoPtr->rcBound.left = x;
1159 infoPtr->rcBound.bottom = y + cy;
1160 infoPtr->rcBound.right = x;
1162 btnPtr = infoPtr->buttons;
1164 /* do not base height/width on parent, if the parent is a */
1165 /* rebar control it could have multiple rows of toolbars */
1166 /* GetClientRect( GetParent(hwnd), &rc ); */
1167 /* cx = rc.right - rc.left; */
1168 /* cy = rc.bottom - rc.top; */
1170 TRACE("cy=%d\n", cy);
1172 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1175 if (btnPtr->fsState & TBSTATE_HIDDEN)
1177 SetRectEmpty (&btnPtr->rect);
1181 cy = infoPtr->nHeight;
1183 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1184 /* it is the actual width of the separator. This is used for */
1185 /* custom controls in toolbars. */
1186 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1187 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1188 cy = (btnPtr->iBitmap > 0) ?
1189 btnPtr->iBitmap : SEPARATOR_WIDTH;
1190 cx = infoPtr->nButtonWidth;
1193 cx = (btnPtr->iBitmap > 0) ?
1194 btnPtr->iBitmap : SEPARATOR_WIDTH;
1198 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1205 hOldFont = SelectObject (hdc, infoPtr->hFont);
1207 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1209 SelectObject (hdc, hOldFont);
1210 ReleaseDC (hwnd, hdc);
1212 /* Fudge amount measured against IE4 "menu" and "Links" */
1213 /* toolbars with native control (v4.71). - GA 8/01 */
1214 cx = sz.cx + 6 + 5 + 5;
1215 if ((dwStyle & TBSTYLE_LIST) &&
1216 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1217 cx += infoPtr->nBitmapWidth;
1220 cx = infoPtr->nButtonWidth;
1222 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1223 cx += DDARROW_WIDTH;
1225 if (btnPtr->fsState & TBSTATE_WRAP )
1228 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1230 if (infoPtr->rcBound.left > x)
1231 infoPtr->rcBound.left = x;
1232 if (infoPtr->rcBound.right < x + cx)
1233 infoPtr->rcBound.right = x + cx;
1234 if (infoPtr->rcBound.bottom < y + cy)
1235 infoPtr->rcBound.bottom = y + cy;
1237 /* Set the toolTip only for non-hidden, non-separator button */
1238 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1242 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1243 ti.cbSize = sizeof(TTTOOLINFOA);
1245 ti.uId = btnPtr->idCommand;
1246 ti.rect = btnPtr->rect;
1247 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1251 /* btnPtr->nRow is zero based. The space between the rows is */
1252 /* also considered as a row. */
1253 btnPtr->nRow = nRows + nSepRows;
1255 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d\n",
1256 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow);
1260 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1264 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1265 /* it is the actual width of the separator. This is used for */
1266 /* custom controls in toolbars. */
1267 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1268 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1269 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1273 /* nSepRows is used to calculate the extra height follwoing */
1277 x = infoPtr->nIndent;
1284 /* infoPtr->nRows is the number of rows on the toolbar */
1285 infoPtr->nRows = nRows + nSepRows + 1;
1287 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1289 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1290 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1291 nSepRows * (infoPtr->nBitmapHeight + 1) +
1293 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1298 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1301 TBUTTON_INFO *btnPtr;
1304 btnPtr = infoPtr->buttons;
1305 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1306 if (btnPtr->fsState & TBSTATE_HIDDEN)
1309 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1310 if (PtInRect (&btnPtr->rect, *lpPt)) {
1311 TRACE(" ON SEPARATOR %d!\n", i);
1316 if (PtInRect (&btnPtr->rect, *lpPt)) {
1317 TRACE(" ON BUTTON %d!\n", i);
1323 TRACE(" NOWHERE!\n");
1329 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1331 TBUTTON_INFO *btnPtr;
1334 if (CommandIsIndex) {
1335 TRACE("command is really index command=%d\n", idCommand);
1338 btnPtr = infoPtr->buttons;
1339 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1340 if (btnPtr->idCommand == idCommand) {
1341 TRACE("command=%d index=%d\n", idCommand, i);
1345 TRACE("no index found for command=%d\n", idCommand);
1351 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1353 TBUTTON_INFO *btnPtr;
1356 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1359 /* check index button */
1360 btnPtr = &infoPtr->buttons[nIndex];
1361 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1362 if (btnPtr->fsState & TBSTATE_CHECKED)
1366 /* check previous buttons */
1367 nRunIndex = nIndex - 1;
1368 while (nRunIndex >= 0) {
1369 btnPtr = &infoPtr->buttons[nRunIndex];
1370 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1371 if (btnPtr->fsState & TBSTATE_CHECKED)
1379 /* check next buttons */
1380 nRunIndex = nIndex + 1;
1381 while (nRunIndex < infoPtr->nNumButtons) {
1382 btnPtr = &infoPtr->buttons[nRunIndex];
1383 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1384 if (btnPtr->fsState & TBSTATE_CHECKED)
1397 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1398 WPARAM wParam, LPARAM lParam)
1404 msg.wParam = wParam;
1405 msg.lParam = lParam;
1406 msg.time = GetMessageTime ();
1407 msg.pt.x = LOWORD(GetMessagePos ());
1408 msg.pt.y = HIWORD(GetMessagePos ());
1410 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1414 /***********************************************************************
1415 * TOOLBAR_CustomizeDialogProc
1416 * This function implements the toolbar customization dialog.
1419 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1421 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1422 PCUSTOMBUTTON btnInfo;
1424 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1429 custInfo = (PCUSTDLG_INFO)lParam;
1430 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1438 infoPtr = custInfo->tbInfo;
1440 /* send TBN_QUERYINSERT notification */
1441 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1443 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1446 /* add items to 'toolbar buttons' list and check if removable */
1447 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1449 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1450 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1451 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1452 btnInfo->bVirtual = FALSE;
1453 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1455 /* send TBN_QUERYDELETE notification */
1457 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1461 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1462 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1465 /* insert separator button into 'available buttons' list */
1466 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1467 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1468 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1469 btnInfo->bVirtual = FALSE;
1470 btnInfo->bRemovable = TRUE;
1471 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1472 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1473 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1475 /* insert all buttons into dsa */
1478 /* send TBN_GETBUTTONINFO notification */
1480 nmtb.pszText = Buffer;
1483 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1486 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1488 /* insert button into the apropriate list */
1489 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1492 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1493 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1494 btnInfo->bVirtual = FALSE;
1495 btnInfo->bRemovable = TRUE;
1496 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1497 strcpy (btnInfo->text, nmtb.pszText);
1499 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1500 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1504 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1505 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1506 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1507 strcpy (btnInfo->text, nmtb.pszText);
1509 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1513 /* select first item in the 'available' list */
1514 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1516 /* append 'virtual' separator button to the 'toolbar buttons' list */
1517 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1518 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1519 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1520 btnInfo->bVirtual = TRUE;
1521 btnInfo->bRemovable = FALSE;
1522 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1523 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1524 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1526 /* select last item in the 'toolbar' list */
1527 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1528 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1530 /* set focus and disable buttons */
1531 PostMessageA (hwnd, WM_USER, 0, 0);
1536 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1537 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1538 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1539 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1543 EndDialog(hwnd, FALSE);
1547 switch (LOWORD(wParam))
1549 case IDC_TOOLBARBTN_LBOX:
1550 if (HIWORD(wParam) == LBN_SELCHANGE)
1552 PCUSTOMBUTTON btnInfo;
1557 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1558 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1560 /* send TBN_QUERYINSERT notification */
1562 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1565 /* get list box item */
1566 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1568 if (index == (count - 1))
1570 /* last item (virtual separator) */
1571 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1572 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1574 else if (index == (count - 2))
1576 /* second last item (last non-virtual item) */
1577 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1578 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1580 else if (index == 0)
1583 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1584 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1588 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1589 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1592 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1596 case IDC_MOVEUP_BTN:
1598 PCUSTOMBUTTON btnInfo;
1602 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1603 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1604 TRACE("Move up: index %d\n", index);
1606 /* send TBN_QUERYINSERT notification */
1609 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1612 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1614 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1615 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1616 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1617 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1620 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1621 else if (index >= (count - 3))
1622 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1624 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1625 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1630 case IDC_MOVEDN_BTN: /* move down */
1632 PCUSTOMBUTTON btnInfo;
1636 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1637 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1638 TRACE("Move up: index %d\n", index);
1640 /* send TBN_QUERYINSERT notification */
1642 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1645 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1647 /* move button down */
1648 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1649 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1650 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1651 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1654 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1655 else if (index >= (count - 3))
1656 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1658 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1659 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1664 case IDC_REMOVE_BTN: /* remove button */
1666 PCUSTOMBUTTON btnInfo;
1669 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1670 TRACE("Remove: index %d\n", index);
1672 /* send TBN_QUERYDELETE notification */
1674 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1677 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1678 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1679 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1681 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1683 /* insert into 'available button' list */
1684 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1686 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1687 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1690 COMCTL32_Free (btnInfo);
1695 case IDOK: /* Add button */
1700 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1701 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1702 TRACE("Add: index %d\n", index);
1704 /* send TBN_QUERYINSERT notification */
1706 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1709 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1713 /* remove from 'available buttons' list */
1714 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1715 if (index == count-1)
1716 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1718 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1722 PCUSTOMBUTTON btnNew;
1724 /* duplicate 'separator' button */
1725 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1726 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1730 /* insert into 'toolbar button' list */
1731 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1732 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1733 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1735 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1741 EndDialog(hwnd, FALSE);
1751 /* delete items from 'toolbar buttons' listbox*/
1752 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1753 for (i = 0; i < count; i++)
1755 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1756 COMCTL32_Free(btnInfo);
1757 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1759 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1762 /* delete items from 'available buttons' listbox*/
1763 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1764 for (i = 0; i < count; i++)
1766 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1767 COMCTL32_Free(btnInfo);
1768 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1770 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1775 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1777 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1782 COLORREF oldText = 0;
1786 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1787 if (btnInfo == NULL)
1789 FIXME("btnInfo invalid!\n");
1793 /* set colors and select objects */
1794 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1795 if (btnInfo->bVirtual)
1796 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
1798 oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
1799 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1800 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1802 /* fill background rectangle */
1803 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
1804 lpdis->rcItem.right, lpdis->rcItem.bottom);
1806 /* calculate button and text rectangles */
1807 CopyRect (&rcButton, &lpdis->rcItem);
1808 InflateRect (&rcButton, -1, -1);
1809 CopyRect (&rcText, &rcButton);
1810 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
1811 rcText.left = rcButton.right + 2;
1813 /* draw focus rectangle */
1814 if (lpdis->itemState & ODS_FOCUS)
1815 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1818 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
1820 /* draw image and text */
1821 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
1822 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
1823 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
1824 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
1825 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1827 /* delete objects and reset colors */
1828 SelectObject (lpdis->hDC, hOldBrush);
1829 SelectObject (lpdis->hDC, hOldPen);
1830 SetBkColor (lpdis->hDC, oldBk);
1831 SetTextColor (lpdis->hDC, oldText);
1837 case WM_MEASUREITEM:
1838 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1840 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1842 if (custInfo && custInfo->tbInfo)
1843 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
1845 lpmis->itemHeight = 15 + 8; /* default height */
1857 /***********************************************************************
1858 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1862 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1864 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1865 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1866 INT nIndex = 0, nButtons, nCount;
1869 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1873 if (lpAddBmp->hInst == HINST_COMMCTRL)
1875 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1877 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1879 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1884 TRACE ("adding %d internal bitmaps!\n", nButtons);
1886 /* Windows resize all the buttons to the size of a newly added standard image */
1887 if (lpAddBmp->nID & 1)
1890 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
1891 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
1893 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1894 MAKELPARAM((WORD)24, (WORD)24));
1895 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1896 MAKELPARAM((WORD)31, (WORD)30));
1901 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1902 MAKELPARAM((WORD)16, (WORD)16));
1903 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1904 MAKELPARAM((WORD)22, (WORD)22));
1907 TOOLBAR_CalcToolbar (hwnd);
1911 nButtons = (INT)wParam;
1915 TRACE ("adding %d bitmaps!\n", nButtons);
1918 if (!(infoPtr->himlDef)) {
1919 /* create new default image list */
1920 TRACE ("creating default image list!\n");
1923 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1924 ILC_COLOR | ILC_MASK, nButtons, 2);
1925 infoPtr->himlInt = infoPtr->himlDef;
1928 nCount = ImageList_GetImageCount(infoPtr->himlDef);
1930 /* Add bitmaps to the default image list */
1931 if (lpAddBmp->hInst == (HINSTANCE)0)
1934 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1937 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1939 /* Add system bitmaps */
1940 switch (lpAddBmp->nID)
1942 case IDB_STD_SMALL_COLOR:
1943 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1944 MAKEINTRESOURCEA(IDB_STD_SMALL));
1945 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1946 hbmLoad, CLR_DEFAULT);
1947 DeleteObject (hbmLoad);
1950 case IDB_STD_LARGE_COLOR:
1951 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1952 MAKEINTRESOURCEA(IDB_STD_LARGE));
1953 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1954 hbmLoad, CLR_DEFAULT);
1955 DeleteObject (hbmLoad);
1958 case IDB_VIEW_SMALL_COLOR:
1959 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1960 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1961 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1962 hbmLoad, CLR_DEFAULT);
1963 DeleteObject (hbmLoad);
1966 case IDB_VIEW_LARGE_COLOR:
1967 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1968 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1969 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1970 hbmLoad, CLR_DEFAULT);
1971 DeleteObject (hbmLoad);
1974 case IDB_HIST_SMALL_COLOR:
1975 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1976 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1977 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1978 hbmLoad, CLR_DEFAULT);
1979 DeleteObject (hbmLoad);
1982 case IDB_HIST_LARGE_COLOR:
1983 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1984 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1985 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1986 hbmLoad, CLR_DEFAULT);
1987 DeleteObject (hbmLoad);
1991 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1992 ERR ("invalid imagelist!\n");
1998 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1999 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
2000 DeleteObject (hbmLoad);
2005 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2007 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2009 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",
2010 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2011 infoPtr->nNumBitmaps+nButtons,imagecount);
2013 infoPtr->nNumBitmaps = imagecount;
2016 infoPtr->nNumBitmaps += nButtons;
2019 InvalidateRect(hwnd, NULL, FALSE);
2026 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2029 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2030 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2032 TRACE("adding %d buttons!\n", wParam);
2034 nAddButtons = (UINT)wParam;
2035 nOldButtons = infoPtr->nNumButtons;
2036 nNewButtons = nOldButtons + nAddButtons;
2038 if (infoPtr->nNumButtons == 0) {
2040 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2043 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2045 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2046 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2047 nOldButtons * sizeof(TBUTTON_INFO));
2048 COMCTL32_Free (oldButtons);
2051 infoPtr->nNumButtons = nNewButtons;
2053 /* insert new button data */
2054 for (nCount = 0; nCount < nAddButtons; nCount++) {
2055 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2056 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2057 btnPtr->idCommand = lpTbb[nCount].idCommand;
2058 btnPtr->fsState = lpTbb[nCount].fsState;
2059 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2060 btnPtr->dwData = lpTbb[nCount].dwData;
2061 btnPtr->iString = lpTbb[nCount].iString;
2062 btnPtr->bHot = FALSE;
2064 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2067 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2068 ti.cbSize = sizeof (TTTOOLINFOA);
2070 ti.uId = btnPtr->idCommand;
2072 ti.lpszText = LPSTR_TEXTCALLBACKA;
2074 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2079 TOOLBAR_CalcToolbar (hwnd);
2081 InvalidateRect(hwnd, NULL, FALSE);
2088 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2091 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2092 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2094 TRACE("adding %d buttons!\n", wParam);
2096 nAddButtons = (UINT)wParam;
2097 nOldButtons = infoPtr->nNumButtons;
2098 nNewButtons = nOldButtons + nAddButtons;
2100 if (infoPtr->nNumButtons == 0) {
2102 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2105 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2107 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2108 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2109 nOldButtons * sizeof(TBUTTON_INFO));
2110 COMCTL32_Free (oldButtons);
2113 infoPtr->nNumButtons = nNewButtons;
2115 /* insert new button data */
2116 for (nCount = 0; nCount < nAddButtons; nCount++) {
2117 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2118 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2119 btnPtr->idCommand = lpTbb[nCount].idCommand;
2120 btnPtr->fsState = lpTbb[nCount].fsState;
2121 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2122 btnPtr->dwData = lpTbb[nCount].dwData;
2123 btnPtr->iString = lpTbb[nCount].iString;
2124 btnPtr->bHot = FALSE;
2126 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2129 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2130 ti.cbSize = sizeof (TTTOOLINFOW);
2132 ti.uId = btnPtr->idCommand;
2134 ti.lpszText = LPSTR_TEXTCALLBACKW;
2136 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2141 TOOLBAR_CalcToolbar (hwnd);
2143 InvalidateRect(hwnd, NULL, FALSE);
2150 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2155 if ((wParam) && (HIWORD(lParam) == 0)) {
2158 TRACE("adding string from resource!\n");
2160 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2163 TRACE("len=%d \"%s\"\n", len, szString);
2164 nIndex = infoPtr->nNumStrings;
2165 if (infoPtr->nNumStrings == 0) {
2167 COMCTL32_Alloc (sizeof(LPWSTR));
2170 LPWSTR *oldStrings = infoPtr->strings;
2172 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2173 memcpy (&infoPtr->strings[0], &oldStrings[0],
2174 sizeof(LPWSTR) * infoPtr->nNumStrings);
2175 COMCTL32_Free (oldStrings);
2178 lenW = MultiByteToWideChar( CP_ACP, 0, szString, -1, NULL, 0 );
2179 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2180 MultiByteToWideChar( CP_ACP, 0, szString, -1,
2181 infoPtr->strings[infoPtr->nNumStrings], lenW );
2182 infoPtr->nNumStrings++;
2185 LPSTR p = (LPSTR)lParam;
2190 TRACE("adding string(s) from array!\n");
2192 nIndex = infoPtr->nNumStrings;
2195 TRACE("len=%d \"%s\"\n", len, p);
2197 if (infoPtr->nNumStrings == 0) {
2199 COMCTL32_Alloc (sizeof(LPWSTR));
2202 LPWSTR *oldStrings = infoPtr->strings;
2204 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2205 memcpy (&infoPtr->strings[0], &oldStrings[0],
2206 sizeof(LPWSTR) * infoPtr->nNumStrings);
2207 COMCTL32_Free (oldStrings);
2210 lenW = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
2211 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2212 MultiByteToWideChar( CP_ACP, 0, p, -1,
2213 infoPtr->strings[infoPtr->nNumStrings], lenW );
2214 infoPtr->nNumStrings++;
2225 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2227 #define MAX_RESOURCE_STRING_LENGTH 512
2228 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2231 if ((wParam) && (HIWORD(lParam) == 0)) {
2232 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2234 TRACE("adding string from resource!\n");
2236 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2237 szString, MAX_RESOURCE_STRING_LENGTH);
2239 TRACE("len=%d %s\n", len, debugstr_w(szString));
2240 TRACE("First char: 0x%x\n", *szString);
2241 if (szString[0] == L'|')
2243 PWSTR p = szString + 1;
2245 nIndex = infoPtr->nNumStrings;
2246 while (*p != L'|') {
2248 if (infoPtr->nNumStrings == 0) {
2250 COMCTL32_Alloc (sizeof(LPWSTR));
2253 LPWSTR *oldStrings = infoPtr->strings;
2255 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2256 memcpy (&infoPtr->strings[0], &oldStrings[0],
2257 sizeof(LPWSTR) * infoPtr->nNumStrings);
2258 COMCTL32_Free (oldStrings);
2261 len = COMCTL32_StrChrW (p, L'|') - p;
2262 TRACE("len=%d %s\n", len, debugstr_w(p));
2263 infoPtr->strings[infoPtr->nNumStrings] =
2264 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2265 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2266 infoPtr->nNumStrings++;
2273 nIndex = infoPtr->nNumStrings;
2274 if (infoPtr->nNumStrings == 0) {
2276 COMCTL32_Alloc (sizeof(LPWSTR));
2279 LPWSTR *oldStrings = infoPtr->strings;
2281 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2282 memcpy (&infoPtr->strings[0], &oldStrings[0],
2283 sizeof(LPWSTR) * infoPtr->nNumStrings);
2284 COMCTL32_Free (oldStrings);
2287 infoPtr->strings[infoPtr->nNumStrings] =
2288 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2289 strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
2290 infoPtr->nNumStrings++;
2294 LPWSTR p = (LPWSTR)lParam;
2299 TRACE("adding string(s) from array!\n");
2300 nIndex = infoPtr->nNumStrings;
2304 TRACE("len=%d %s\n", len, debugstr_w(p));
2305 if (infoPtr->nNumStrings == 0) {
2307 COMCTL32_Alloc (sizeof(LPWSTR));
2310 LPWSTR *oldStrings = infoPtr->strings;
2312 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2313 memcpy (&infoPtr->strings[0], &oldStrings[0],
2314 sizeof(LPWSTR) * infoPtr->nNumStrings);
2315 COMCTL32_Free (oldStrings);
2318 infoPtr->strings[infoPtr->nNumStrings] =
2319 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2320 strcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
2321 infoPtr->nNumStrings++;
2332 TOOLBAR_AutoSize (HWND hwnd)
2334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2335 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2341 UINT uPosFlags = SWP_NOZORDER;
2343 TRACE("resize forced, style=%lx!\n", dwStyle);
2345 parent = GetParent (hwnd);
2346 GetClientRect(parent, &parent_rect);
2348 x = parent_rect.left;
2349 y = parent_rect.top;
2351 /* FIXME: we should be able to early out if nothing */
2352 /* has changed with nWidth != parent_rect width */
2354 if (dwStyle & CCS_NORESIZE) {
2355 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2358 TOOLBAR_CalcToolbar (hwnd);
2361 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2362 TOOLBAR_CalcToolbar (hwnd);
2363 InvalidateRect( hwnd, NULL, TRUE );
2364 cy = infoPtr->nHeight;
2365 cx = infoPtr->nWidth;
2367 if (dwStyle & CCS_NOMOVEY) {
2368 GetWindowRect(hwnd, &window_rect);
2369 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2370 y = window_rect.top;
2374 if (dwStyle & CCS_NOPARENTALIGN)
2375 uPosFlags |= SWP_NOMOVE;
2377 if (!(dwStyle & CCS_NODIVIDER))
2378 cy += GetSystemMetrics(SM_CYEDGE);
2380 if (dwStyle & WS_BORDER)
2383 cy += GetSystemMetrics(SM_CYEDGE);
2384 cx += GetSystemMetrics(SM_CYEDGE);
2387 infoPtr->bAutoSize = TRUE;
2388 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2390 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2391 * the setwindowpos calls */
2392 infoPtr->bAutoSize = FALSE;
2399 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2401 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2403 return infoPtr->nNumButtons;
2408 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2410 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2412 if (infoPtr == NULL) {
2413 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2414 ERR("infoPtr == NULL!\n");
2418 infoPtr->dwStructSize = (DWORD)wParam;
2425 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2428 TBUTTON_INFO *btnPtr;
2431 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2435 btnPtr = &infoPtr->buttons[nIndex];
2436 btnPtr->iBitmap = LOWORD(lParam);
2438 /* we HAVE to erase the background, the new bitmap could be */
2440 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2447 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2450 TBUTTON_INFO *btnPtr;
2453 BOOL bChecked = FALSE;
2455 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2459 btnPtr = &infoPtr->buttons[nIndex];
2461 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2464 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2466 if (LOWORD(lParam) == FALSE)
2467 btnPtr->fsState &= ~TBSTATE_CHECKED;
2469 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2471 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2472 if (nOldIndex == nIndex)
2474 if (nOldIndex != -1)
2475 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2477 btnPtr->fsState |= TBSTATE_CHECKED;
2480 if( bChecked != LOWORD(lParam) )
2482 if (nOldIndex != -1)
2484 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2485 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2487 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2490 /* FIXME: Send a WM_NOTIFY?? */
2497 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2499 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2501 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2506 TOOLBAR_Customize (HWND hwnd)
2508 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2509 CUSTDLG_INFO custInfo;
2515 custInfo.tbInfo = infoPtr;
2516 custInfo.tbHwnd = hwnd;
2518 /* send TBN_BEGINADJUST notification */
2519 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2522 if (!(hRes = FindResourceA (COMCTL32_hModule,
2523 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2527 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2530 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2531 (LPDLGTEMPLATEA)template,
2533 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2536 /* send TBN_ENDADJUST notification */
2537 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2545 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2547 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2548 INT nIndex = (INT)wParam;
2550 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2553 if ((infoPtr->hwndToolTip) &&
2554 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2557 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2558 ti.cbSize = sizeof (TTTOOLINFOA);
2560 ti.uId = infoPtr->buttons[nIndex].idCommand;
2562 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2565 if (infoPtr->nNumButtons == 1) {
2566 TRACE(" simple delete!\n");
2567 COMCTL32_Free (infoPtr->buttons);
2568 infoPtr->buttons = NULL;
2569 infoPtr->nNumButtons = 0;
2572 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2573 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2575 infoPtr->nNumButtons--;
2576 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2578 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2579 nIndex * sizeof(TBUTTON_INFO));
2582 if (nIndex < infoPtr->nNumButtons) {
2583 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2584 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2587 COMCTL32_Free (oldButtons);
2590 TOOLBAR_CalcToolbar (hwnd);
2592 InvalidateRect (hwnd, NULL, TRUE);
2599 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2602 TBUTTON_INFO *btnPtr;
2606 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2610 btnPtr = &infoPtr->buttons[nIndex];
2612 bState = btnPtr->fsState & TBSTATE_ENABLED;
2614 /* update the toolbar button state */
2615 if(LOWORD(lParam) == FALSE) {
2616 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2618 btnPtr->fsState |= TBSTATE_ENABLED;
2621 /* redraw the button only if the state of the button changed */
2622 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2624 InvalidateRect(hwnd, &btnPtr->rect,
2625 TOOLBAR_HasText(infoPtr, btnPtr));
2632 static inline LRESULT
2633 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2637 return infoPtr->bAnchor;
2642 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2647 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2651 return infoPtr->buttons[nIndex].iBitmap;
2655 static inline LRESULT
2656 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2658 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2663 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2665 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2666 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2667 INT nIndex = (INT)wParam;
2668 TBUTTON_INFO *btnPtr;
2670 if (infoPtr == NULL)
2676 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2679 btnPtr = &infoPtr->buttons[nIndex];
2680 lpTbb->iBitmap = btnPtr->iBitmap;
2681 lpTbb->idCommand = btnPtr->idCommand;
2682 lpTbb->fsState = btnPtr->fsState;
2683 lpTbb->fsStyle = btnPtr->fsStyle;
2684 lpTbb->dwData = btnPtr->dwData;
2685 lpTbb->iString = btnPtr->iString;
2692 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2695 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2696 TBUTTON_INFO *btnPtr;
2699 if (infoPtr == NULL)
2701 if (lpTbInfo == NULL)
2703 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2706 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2707 lpTbInfo->dwMask & 0x80000000);
2711 btnPtr = &infoPtr->buttons[nIndex];
2713 if (lpTbInfo->dwMask & TBIF_COMMAND)
2714 lpTbInfo->idCommand = btnPtr->idCommand;
2715 if (lpTbInfo->dwMask & TBIF_IMAGE)
2716 lpTbInfo->iImage = btnPtr->iBitmap;
2717 if (lpTbInfo->dwMask & TBIF_LPARAM)
2718 lpTbInfo->lParam = btnPtr->dwData;
2719 if (lpTbInfo->dwMask & TBIF_SIZE)
2720 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2721 if (lpTbInfo->dwMask & TBIF_STATE)
2722 lpTbInfo->fsState = btnPtr->fsState;
2723 if (lpTbInfo->dwMask & TBIF_STYLE)
2724 lpTbInfo->fsStyle = btnPtr->fsStyle;
2725 if (lpTbInfo->dwMask & TBIF_TEXT) {
2726 if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
2728 if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[btnPtr->iString], -1,
2729 lpTbInfo->pszText, lpTbInfo->cchText, NULL, NULL ))
2730 lpTbInfo->pszText[lpTbInfo->cchText-1] = 0;
2732 else lpTbInfo->pszText[0]=0;
2739 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2741 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2742 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2743 TBUTTON_INFO *btnPtr;
2746 if (infoPtr == NULL)
2748 if (lpTbInfo == NULL)
2750 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2753 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2754 lpTbInfo->dwMask & 0x80000000);
2758 btnPtr = &infoPtr->buttons[nIndex];
2760 if (lpTbInfo->dwMask & TBIF_COMMAND)
2761 lpTbInfo->idCommand = btnPtr->idCommand;
2762 if (lpTbInfo->dwMask & TBIF_IMAGE)
2763 lpTbInfo->iImage = btnPtr->iBitmap;
2764 if (lpTbInfo->dwMask & TBIF_LPARAM)
2765 lpTbInfo->lParam = btnPtr->dwData;
2766 if (lpTbInfo->dwMask & TBIF_SIZE)
2767 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2768 if (lpTbInfo->dwMask & TBIF_STATE)
2769 lpTbInfo->fsState = btnPtr->fsState;
2770 if (lpTbInfo->dwMask & TBIF_STYLE)
2771 lpTbInfo->fsStyle = btnPtr->fsStyle;
2772 if (lpTbInfo->dwMask & TBIF_TEXT) {
2773 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2774 lstrcpynW (lpTbInfo->pszText,
2775 (LPWSTR)infoPtr->strings[btnPtr->iString],
2784 TOOLBAR_GetButtonSize (HWND hwnd)
2786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2788 if (infoPtr->nNumButtons > 0)
2789 return MAKELONG((WORD)infoPtr->nButtonWidth,
2790 (WORD)infoPtr->nButtonHeight);
2792 return MAKELONG(8,7);
2797 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2800 INT nIndex, nStringIndex;
2802 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2806 nStringIndex = infoPtr->buttons[nIndex].iString;
2808 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2810 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2816 return WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[nStringIndex], -1,
2817 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
2822 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2824 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2825 INT nIndex, nStringIndex;
2827 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2831 nStringIndex = infoPtr->buttons[nIndex].iString;
2833 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2835 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2841 strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
2843 return strlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
2847 /* << TOOLBAR_GetColorScheme >> */
2851 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2853 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2855 return (LRESULT)infoPtr->himlDis;
2859 inline static LRESULT
2860 TOOLBAR_GetExtendedStyle (HWND hwnd)
2862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2864 return infoPtr->dwExStyle;
2869 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2871 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2873 return (LRESULT)infoPtr->himlHot;
2878 TOOLBAR_GetHotItem (HWND hwnd)
2880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2882 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
2885 if (infoPtr->nHotItem < 0)
2888 return (LRESULT)infoPtr->nHotItem;
2893 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2895 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2897 return (LRESULT)infoPtr->himlDef;
2901 /* << TOOLBAR_GetInsertMark >> */
2902 /* << TOOLBAR_GetInsertMarkColor >> */
2906 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2909 TBUTTON_INFO *btnPtr;
2913 if (infoPtr == NULL)
2915 nIndex = (INT)wParam;
2916 btnPtr = &infoPtr->buttons[nIndex];
2917 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2919 lpRect = (LPRECT)lParam;
2922 if (btnPtr->fsState & TBSTATE_HIDDEN)
2925 lpRect->left = btnPtr->rect.left;
2926 lpRect->right = btnPtr->rect.right;
2927 lpRect->bottom = btnPtr->rect.bottom;
2928 lpRect->top = btnPtr->rect.top;
2935 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2937 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2938 LPSIZE lpSize = (LPSIZE)lParam;
2943 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2944 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2946 TRACE("maximum size %d x %d\n",
2947 infoPtr->rcBound.right - infoPtr->rcBound.left,
2948 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2954 /* << TOOLBAR_GetObject >> */
2955 /* << TOOLBAR_GetPadding >> */
2959 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2962 TBUTTON_INFO *btnPtr;
2966 if (infoPtr == NULL)
2968 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2969 btnPtr = &infoPtr->buttons[nIndex];
2970 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2972 lpRect = (LPRECT)lParam;
2976 lpRect->left = btnPtr->rect.left;
2977 lpRect->right = btnPtr->rect.right;
2978 lpRect->bottom = btnPtr->rect.bottom;
2979 lpRect->top = btnPtr->rect.top;
2986 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2988 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2990 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2991 return infoPtr->nRows;
2998 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3003 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3007 return infoPtr->buttons[nIndex].fsState;
3012 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3014 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3017 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3021 return infoPtr->buttons[nIndex].fsStyle;
3026 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3028 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3030 if (infoPtr == NULL)
3033 return infoPtr->nMaxTextRows;
3038 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3040 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3042 if (infoPtr == NULL)
3044 return infoPtr->hwndToolTip;
3049 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3051 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3053 TRACE("%s hwnd=0x%x stub!\n",
3054 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3056 return infoPtr->bUnicode;
3060 inline static LRESULT
3061 TOOLBAR_GetVersion (HWND hwnd)
3063 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3064 return infoPtr->iVersion;
3069 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3071 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3072 TBUTTON_INFO *btnPtr;
3077 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3081 btnPtr = &infoPtr->buttons[nIndex];
3082 if (LOWORD(lParam) == FALSE)
3083 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3085 btnPtr->fsState |= TBSTATE_HIDDEN;
3087 TOOLBAR_CalcToolbar (hwnd);
3089 InvalidateRect (hwnd, NULL, TRUE);
3095 inline static LRESULT
3096 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3098 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3103 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3105 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3106 TBUTTON_INFO *btnPtr;
3109 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3113 btnPtr = &infoPtr->buttons[nIndex];
3114 if (LOWORD(lParam) == FALSE)
3115 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3117 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3119 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3126 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3128 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3129 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3130 INT nIndex = (INT)wParam;
3131 TBUTTON_INFO *oldButtons;
3136 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3139 /* EPP: this seems to be an undocumented call (from my IE4)
3140 * I assume in that case that:
3141 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3142 * - index of insertion is at the end of existing buttons
3143 * I only see this happen with nIndex == -1, but it could have a special
3144 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3146 nIndex = infoPtr->nNumButtons;
3148 } else if (nIndex < 0)
3151 TRACE("inserting button index=%d\n", nIndex);
3152 if (nIndex > infoPtr->nNumButtons) {
3153 nIndex = infoPtr->nNumButtons;
3154 TRACE("adjust index=%d\n", nIndex);
3157 oldButtons = infoPtr->buttons;
3158 infoPtr->nNumButtons++;
3159 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3160 /* pre insert copy */
3162 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3163 nIndex * sizeof(TBUTTON_INFO));
3166 /* if passed string and not index, then add string */
3167 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3171 len = strlen((char*)lpTbb->iString) + 2;
3172 ptr = COMCTL32_Alloc(len*sizeof(char));
3173 strcpy(ptr, (char*)lpTbb->iString);
3174 ptr[len - 1] = 0; /* ended by two '\0' */
3175 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3179 /* insert new button */
3180 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3181 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3182 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3183 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3184 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3185 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3187 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3190 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3191 ti.cbSize = sizeof (TTTOOLINFOA);
3193 ti.uId = lpTbb->idCommand;
3195 ti.lpszText = LPSTR_TEXTCALLBACKA;
3197 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3201 /* post insert copy */
3202 if (nIndex < infoPtr->nNumButtons - 1) {
3203 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3204 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3207 COMCTL32_Free (oldButtons);
3209 TOOLBAR_CalcToolbar (hwnd);
3211 InvalidateRect (hwnd, NULL, TRUE);
3218 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3221 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3222 INT nIndex = (INT)wParam;
3223 TBUTTON_INFO *oldButtons;
3230 TRACE("inserting button index=%d\n", nIndex);
3231 if (nIndex > infoPtr->nNumButtons) {
3232 nIndex = infoPtr->nNumButtons;
3233 TRACE("adjust index=%d\n", nIndex);
3236 oldButtons = infoPtr->buttons;
3237 infoPtr->nNumButtons++;
3238 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3239 /* pre insert copy */
3241 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3242 nIndex * sizeof(TBUTTON_INFO));
3245 /* if passed string and not index, then add string */
3246 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3250 len = strlenW((WCHAR*)lpTbb->iString) + 2;
3251 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3252 strcpyW(ptr, (WCHAR*)lpTbb->iString);
3253 ptr[len - 1] = 0; /* ended by two '\0' */
3254 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3258 /* insert new button */
3259 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3260 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3261 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3262 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3263 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3264 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3266 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3269 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3270 ti.cbSize = sizeof (TTTOOLINFOW);
3272 ti.uId = lpTbb->idCommand;
3274 ti.lpszText = LPSTR_TEXTCALLBACKW;
3276 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3280 /* post insert copy */
3281 if (nIndex < infoPtr->nNumButtons - 1) {
3282 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3283 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3286 COMCTL32_Free (oldButtons);
3288 InvalidateRect (hwnd, NULL, TRUE);
3294 /* << TOOLBAR_InsertMarkHitTest >> */
3298 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3300 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3303 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3307 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3312 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3317 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3321 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3326 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3335 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3340 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3342 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3345 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3349 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3354 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3359 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3363 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3368 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3373 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3377 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3381 /* << TOOLBAR_LoadImages >> */
3382 /* << TOOLBAR_MapAccelerator >> */
3383 /* << TOOLBAR_MarkButton >> */
3384 /* << TOOLBAR_MoveButton >> */
3388 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3391 TBUTTON_INFO *btnPtr;
3394 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3398 btnPtr = &infoPtr->buttons[nIndex];
3399 if (LOWORD(lParam) == FALSE)
3400 btnPtr->fsState &= ~TBSTATE_PRESSED;
3402 btnPtr->fsState |= TBSTATE_PRESSED;
3404 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3410 /* << TOOLBAR_ReplaceBitmap >> */
3414 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3417 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3418 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3420 if (lpSave == NULL) return 0;
3423 /* save toolbar information */
3424 FIXME("save to \"%s\" \"%s\"\n",
3425 lpSave->pszSubKey, lpSave->pszValueName);
3430 /* restore toolbar information */
3432 FIXME("restore from \"%s\" \"%s\"\n",
3433 lpSave->pszSubKey, lpSave->pszValueName);
3444 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3448 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3454 /* save toolbar information */
3455 FIXME("save to \"%s\" \"%s\"\n",
3456 lpSave->pszSubKey, lpSave->pszValueName);
3461 /* restore toolbar information */
3463 FIXME("restore from \"%s\" \"%s\"\n",
3464 lpSave->pszSubKey, lpSave->pszValueName);
3475 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3477 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3478 BOOL bOldAnchor = infoPtr->bAnchor;
3480 infoPtr->bAnchor = (BOOL)wParam;
3482 return (LRESULT)bOldAnchor;
3487 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3489 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3491 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3494 if (infoPtr->nNumButtons > 0)
3495 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3496 infoPtr->nNumButtons,
3497 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3498 LOWORD(lParam), HIWORD(lParam));
3500 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3501 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3503 /* uses image list internals directly */
3504 if (infoPtr->himlDef) {
3505 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3506 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3514 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3517 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3518 TBUTTON_INFO *btnPtr;
3523 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3526 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3527 lptbbi->dwMask & 0x80000000);
3531 btnPtr = &infoPtr->buttons[nIndex];
3532 if (lptbbi->dwMask & TBIF_COMMAND)
3533 btnPtr->idCommand = lptbbi->idCommand;
3534 if (lptbbi->dwMask & TBIF_IMAGE)
3535 btnPtr->iBitmap = lptbbi->iImage;
3536 if (lptbbi->dwMask & TBIF_LPARAM)
3537 btnPtr->dwData = lptbbi->lParam;
3538 /* if (lptbbi->dwMask & TBIF_SIZE) */
3539 /* btnPtr->cx = lptbbi->cx; */
3540 if (lptbbi->dwMask & TBIF_STATE)
3541 btnPtr->fsState = lptbbi->fsState;
3542 if (lptbbi->dwMask & TBIF_STYLE)
3543 btnPtr->fsStyle = lptbbi->fsStyle;
3545 if (lptbbi->dwMask & TBIF_TEXT) {
3546 if ((btnPtr->iString >= 0) ||
3547 (btnPtr->iString < infoPtr->nNumStrings)) {
3548 TRACE("Ooooooch\n");
3550 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3551 INT len = lstrlenA (lptbbi->pszText);
3552 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3555 /* this is the ultimate sollution */
3556 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3565 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3567 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3568 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3569 TBUTTON_INFO *btnPtr;
3574 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3577 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3578 lptbbi->dwMask & 0x80000000);
3582 btnPtr = &infoPtr->buttons[nIndex];
3583 if (lptbbi->dwMask & TBIF_COMMAND)
3584 btnPtr->idCommand = lptbbi->idCommand;
3585 if (lptbbi->dwMask & TBIF_IMAGE)
3586 btnPtr->iBitmap = lptbbi->iImage;
3587 if (lptbbi->dwMask & TBIF_LPARAM)
3588 btnPtr->dwData = lptbbi->lParam;
3589 /* if (lptbbi->dwMask & TBIF_SIZE) */
3590 /* btnPtr->cx = lptbbi->cx; */
3591 if (lptbbi->dwMask & TBIF_STATE)
3592 btnPtr->fsState = lptbbi->fsState;
3593 if (lptbbi->dwMask & TBIF_STYLE)
3594 btnPtr->fsStyle = lptbbi->fsStyle;
3596 if (lptbbi->dwMask & TBIF_TEXT) {
3597 if ((btnPtr->iString >= 0) ||
3598 (btnPtr->iString < infoPtr->nNumStrings)) {
3600 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3601 INT len = lstrlenW (lptbbi->pszText);
3602 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3605 /* this is the ultimate solution */
3606 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3615 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3619 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3621 ERR("invalid parameter\n");
3625 /* The documentation claims you can only change the button size before
3626 * any button has been added. But this is wrong.
3627 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3628 * it to the toolbar, and it checks that the return value is nonzero - mjm
3629 * Further testing shows that we must actually perform the change too.
3631 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3632 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3638 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3642 if (infoPtr == NULL) {
3643 TRACE("Toolbar not initialized yet?????\n");
3647 /* if setting to current values, ignore */
3648 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3649 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3650 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3651 infoPtr->cxMin, infoPtr->cxMax);
3655 /* save new values */
3656 infoPtr->cxMin = (INT)LOWORD(lParam);
3657 infoPtr->cxMax = (INT)HIWORD(lParam);
3659 /* if both values are 0 then we are done */
3661 TRACE("setting both min and max to 0, norecalc\n");
3665 /* otherwise we need to recalc the toolbar and in some cases
3666 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3667 which doesn't actually draw - GA). */
3668 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3669 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3671 TOOLBAR_CalcToolbar (hwnd);
3673 InvalidateRect (hwnd, NULL, TRUE);
3680 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3683 INT nIndex = (INT)wParam;
3685 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3688 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3690 if (infoPtr->hwndToolTip) {
3692 FIXME("change tool tip!\n");
3700 /* << TOOLBAR_SetColorScheme >> */
3704 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3706 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3707 HIMAGELIST himlTemp;
3710 himlTemp = infoPtr->himlDis;
3711 infoPtr->himlDis = (HIMAGELIST)lParam;
3713 /* FIXME: redraw ? */
3715 return (LRESULT)himlTemp;
3720 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3725 dwTemp = infoPtr->dwDTFlags;
3726 infoPtr->dwDTFlags =
3727 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3729 return (LRESULT)dwTemp;
3734 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3739 dwTemp = infoPtr->dwExStyle;
3740 infoPtr->dwExStyle = (DWORD)lParam;
3742 return (LRESULT)dwTemp;
3747 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3749 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3750 HIMAGELIST himlTemp;
3752 himlTemp = infoPtr->himlHot;
3753 infoPtr->himlHot = (HIMAGELIST)lParam;
3755 /* FIXME: redraw ? */
3757 return (LRESULT)himlTemp;
3762 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
3764 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3765 INT nOldHotItem = infoPtr->nHotItem;
3766 TBUTTON_INFO *btnPtr;
3768 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
3771 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
3774 infoPtr->nHotItem = (INT)wParam;
3775 if ((INT)wParam >=0)
3777 btnPtr = &infoPtr->buttons[(INT)wParam];
3778 btnPtr->bHot = TRUE;
3779 InvalidateRect (hwnd, &btnPtr->rect,
3780 TOOLBAR_HasText(infoPtr, btnPtr));
3784 btnPtr = &infoPtr->buttons[nOldHotItem];
3785 btnPtr->bHot = FALSE;
3786 InvalidateRect (hwnd, &btnPtr->rect,
3787 TOOLBAR_HasText(infoPtr, btnPtr));
3791 if (nOldHotItem < 0)
3794 return (LRESULT)nOldHotItem;
3799 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3801 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3802 HIMAGELIST himlTemp;
3804 himlTemp = infoPtr->himlDef;
3805 infoPtr->himlDef = (HIMAGELIST)lParam;
3807 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
3809 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
3810 &infoPtr->nBitmapHeight);
3811 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
3812 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
3813 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
3815 /* FIXME: redraw ? */
3816 InvalidateRect(hwnd, NULL, TRUE);
3818 return (LRESULT)himlTemp;
3823 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3827 infoPtr->nIndent = (INT)wParam;
3831 /* process only on indent changing */
3832 if(infoPtr->nIndent != (INT)wParam)
3834 infoPtr->nIndent = (INT)wParam;
3835 TOOLBAR_CalcToolbar (hwnd);
3836 InvalidateRect(hwnd, NULL, FALSE);
3843 /* << TOOLBAR_SetInsertMark >> */
3847 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3851 infoPtr->clrInsertMark = (COLORREF)lParam;
3853 /* FIXME : redraw ??*/
3860 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3862 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3864 if (infoPtr == NULL)
3867 infoPtr->nMaxTextRows = (INT)wParam;
3873 /* << TOOLBAR_SetPadding >> */
3877 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3884 if (infoPtr == NULL)
3886 hwndOldNotify = infoPtr->hwndNotify;
3887 infoPtr->hwndNotify = (HWND)wParam;
3889 return hwndOldNotify;
3894 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3897 LPRECT lprc = (LPRECT)lParam;
3901 if (LOWORD(wParam) > 1) {
3902 FIXME("multiple rows not supported!\n");
3905 if(infoPtr->nRows != LOWORD(wParam))
3907 infoPtr->nRows = LOWORD(wParam);
3909 /* recalculate toolbar */
3910 TOOLBAR_CalcToolbar (hwnd);
3912 /* repaint toolbar */
3913 InvalidateRect(hwnd, NULL, FALSE);
3916 /* return bounding rectangle */
3918 lprc->left = infoPtr->rcBound.left;
3919 lprc->right = infoPtr->rcBound.right;
3920 lprc->top = infoPtr->rcBound.top;
3921 lprc->bottom = infoPtr->rcBound.bottom;
3929 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3931 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3932 TBUTTON_INFO *btnPtr;
3935 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3939 btnPtr = &infoPtr->buttons[nIndex];
3941 /* if hidden state has changed the invalidate entire window and recalc */
3942 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
3943 btnPtr->fsState = LOWORD(lParam);
3944 TOOLBAR_CalcToolbar (hwnd);
3945 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
3949 /* process state changing if current state doesn't match new state */
3950 if(btnPtr->fsState != LOWORD(lParam))
3952 btnPtr->fsState = LOWORD(lParam);
3953 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3962 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3964 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3965 TBUTTON_INFO *btnPtr;
3968 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3972 btnPtr = &infoPtr->buttons[nIndex];
3974 /* process style change if current style doesn't match new style */
3975 if(btnPtr->fsStyle != LOWORD(lParam))
3977 btnPtr->fsStyle = LOWORD(lParam);
3978 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3981 if (infoPtr->hwndToolTip) {
3982 FIXME("change tool tip!\n");
3990 inline static LRESULT
3991 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3993 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3995 if (infoPtr == NULL)
3997 infoPtr->hwndToolTip = (HWND)wParam;
4003 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4008 TRACE("%s hwnd=0x%04x stub!\n",
4009 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4011 bTemp = infoPtr->bUnicode;
4012 infoPtr->bUnicode = (BOOL)wParam;
4019 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4021 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4022 INT iOldVersion = infoPtr->iVersion;
4024 infoPtr->iVersion = iVersion;
4031 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4034 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4037 /* initialize info structure */
4038 infoPtr->nButtonHeight = 22;
4039 infoPtr->nButtonWidth = 24;
4040 infoPtr->nBitmapHeight = 15;
4041 infoPtr->nBitmapWidth = 16;
4043 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4045 infoPtr->nMaxTextRows = 1;
4046 infoPtr->cxMin = -1;
4047 infoPtr->cxMax = -1;
4048 infoPtr->nNumBitmaps = 0;
4049 infoPtr->nNumStrings = 0;
4051 infoPtr->bCaptured = FALSE;
4052 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4053 infoPtr->nButtonDown = -1;
4054 infoPtr->nOldHit = -1;
4055 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4056 infoPtr->hwndNotify = GetParent (hwnd);
4057 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4058 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4059 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4060 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4061 infoPtr->iVersion = 0;
4062 infoPtr->bNtfUnicode = FALSE;
4063 infoPtr->hwndSelf = hwnd;
4064 infoPtr->bDoRedraw = TRUE;
4066 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4067 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4069 if (dwStyle & TBSTYLE_TOOLTIPS) {
4070 /* Create tooltip control */
4071 infoPtr->hwndToolTip =
4072 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4073 CW_USEDEFAULT, CW_USEDEFAULT,
4074 CW_USEDEFAULT, CW_USEDEFAULT,
4077 /* Send NM_TOOLTIPSCREATED notification */
4078 if (infoPtr->hwndToolTip) {
4079 NMTOOLTIPSCREATED nmttc;
4081 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4083 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4084 NM_TOOLTIPSCREATED);
4088 TOOLBAR_CheckStyle (hwnd, dwStyle);
4090 TOOLBAR_CalcToolbar(hwnd);
4097 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4099 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4101 /* delete tooltip control */
4102 if (infoPtr->hwndToolTip)
4103 DestroyWindow (infoPtr->hwndToolTip);
4105 /* delete button data */
4106 if (infoPtr->buttons)
4107 COMCTL32_Free (infoPtr->buttons);
4109 /* delete strings */
4110 if (infoPtr->strings) {
4112 for (i = 0; i < infoPtr->nNumStrings; i++)
4113 if (infoPtr->strings[i])
4114 COMCTL32_Free (infoPtr->strings[i]);
4116 COMCTL32_Free (infoPtr->strings);
4119 /* destroy internal image list */
4120 if (infoPtr->himlInt)
4121 ImageList_Destroy (infoPtr->himlInt);
4123 /* delete default font */
4125 DeleteObject (infoPtr->hDefaultFont);
4127 /* free toolbar info data */
4128 COMCTL32_Free (infoPtr);
4129 SetWindowLongA (hwnd, 0, 0);
4136 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4139 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4140 NMTBCUSTOMDRAW tbcd;
4143 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4144 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4145 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4146 tbcd.nmcd.hdc = (HDC)wParam;
4147 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4148 /* FIXME: in general the return flags *can* be or'ed together */
4151 case CDRF_DODEFAULT:
4153 case CDRF_SKIPDEFAULT:
4156 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4161 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4162 * to my parent for processing.
4164 if (infoPtr->bTransparent) {
4166 HDC hdc = (HDC)wParam;
4171 parent = GetParent(hwnd);
4172 MapWindowPoints(hwnd, parent, &pt, 1);
4173 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4174 SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4175 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4178 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4180 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4181 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4182 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4183 tbcd.nmcd.hdc = (HDC)wParam;
4184 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4187 case CDRF_DODEFAULT:
4189 case CDRF_SKIPDEFAULT:
4192 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4201 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4205 return infoPtr->hFont;
4210 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4212 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4213 TBUTTON_INFO *btnPtr;
4217 pt.x = (INT)LOWORD(lParam);
4218 pt.y = (INT)HIWORD(lParam);
4219 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4222 btnPtr = &infoPtr->buttons[nHit];
4223 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4226 infoPtr->bCaptured = TRUE;
4227 infoPtr->nButtonDown = nHit;
4229 btnPtr->fsState |= TBSTATE_PRESSED;
4231 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4234 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4235 TOOLBAR_Customize (hwnd);
4242 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4244 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4245 TBUTTON_INFO *btnPtr;
4250 if (infoPtr->hwndToolTip)
4251 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4252 WM_LBUTTONDOWN, wParam, lParam);
4254 pt.x = (INT)LOWORD(lParam);
4255 pt.y = (INT)HIWORD(lParam);
4256 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4260 btnPtr = &infoPtr->buttons[nHit];
4261 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4264 infoPtr->nOldHit = nHit;
4266 CopyRect(&arrowRect, &btnPtr->rect);
4267 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4269 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4270 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4271 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4272 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4276 * this time we must force a Redraw, so the btn is
4277 * painted down before CaptureChanged repaints it up
4279 RedrawWindow(hwnd,&btnPtr->rect,0,
4280 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4282 nmtb.iItem = btnPtr->idCommand;
4283 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4286 memset(&nmtb.rcButton, 0, sizeof(RECT));
4287 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4289 if (res != TBDDRET_TREATPRESSED)
4290 /* ??? guess (GA) */
4292 /* otherwise drop through and process as pushed */
4294 /* SetCapture (hwnd); */
4295 infoPtr->bCaptured = TRUE;
4296 infoPtr->nButtonDown = nHit;
4298 btnPtr->fsState |= TBSTATE_PRESSED;
4299 btnPtr->bHot = FALSE;
4301 InvalidateRect(hwnd, &btnPtr->rect,
4302 TOOLBAR_HasText(infoPtr, btnPtr));
4306 /* native issues the TBN_BEGINDRAG here */
4307 nmtb.iItem = btnPtr->idCommand;
4308 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4309 nmtb.tbButton.idCommand = btnPtr->idCommand;
4310 nmtb.tbButton.fsState = btnPtr->fsState;
4311 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4312 nmtb.tbButton.dwData = btnPtr->dwData;
4313 nmtb.tbButton.iString = btnPtr->iString;
4314 nmtb.cchText = 0; /* !!! not correct */
4315 nmtb.pszText = 0; /* !!! not correct */
4316 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4324 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4326 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4327 TBUTTON_INFO *btnPtr;
4331 BOOL bSendMessage = TRUE;
4336 if (infoPtr->hwndToolTip)
4337 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4338 WM_LBUTTONUP, wParam, lParam);
4340 pt.x = (INT)LOWORD(lParam);
4341 pt.y = (INT)HIWORD(lParam);
4342 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4344 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4345 /* if the cursor is still inside of the toolbar */
4346 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4347 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4349 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
4350 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4351 btnPtr->fsState &= ~TBSTATE_PRESSED;
4353 if (nHit == infoPtr->nButtonDown) {
4354 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4355 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4356 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4357 infoPtr->nButtonDown);
4358 if (nOldIndex == infoPtr->nButtonDown)
4359 bSendMessage = FALSE;
4360 if ((nOldIndex != infoPtr->nButtonDown) &&
4362 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4363 btnPtr->fsState |= TBSTATE_CHECKED;
4366 if (btnPtr->fsState & TBSTATE_CHECKED)
4367 btnPtr->fsState &= ~TBSTATE_CHECKED;
4369 btnPtr->fsState |= TBSTATE_CHECKED;
4374 bSendMessage = FALSE;
4376 if (nOldIndex != -1)
4378 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4379 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4383 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4384 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4385 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4389 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4390 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4391 NM_RELEASEDCAPTURE);
4393 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4396 nmtb.iItem = btnPtr->idCommand;
4397 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4398 nmtb.tbButton.idCommand = btnPtr->idCommand;
4399 nmtb.tbButton.fsState = btnPtr->fsState;
4400 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4401 nmtb.tbButton.dwData = btnPtr->dwData;
4402 nmtb.tbButton.iString = btnPtr->iString;
4403 nmtb.cchText = 0; /* !!! not correct */
4404 nmtb.pszText = 0; /* !!! not correct */
4405 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4409 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4410 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
4412 /* !!! Undocumented - toolbar at 4.71 level and above sends
4413 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4414 * Only NM_RCLICK is documented.
4416 nmmouse.dwItemSpec = btnPtr->idCommand;
4417 nmmouse.dwItemData = btnPtr->dwData;
4418 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4426 TOOLBAR_CaptureChanged(HWND hwnd)
4428 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4429 TBUTTON_INFO *btnPtr;
4431 infoPtr->bCaptured = FALSE;
4433 if (infoPtr->nButtonDown >= 0)
4435 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4436 btnPtr->fsState &= ~TBSTATE_PRESSED;
4438 infoPtr->nButtonDown = -1;
4439 infoPtr->nOldHit = -1;
4441 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4448 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4451 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4454 if (infoPtr->nOldHit < 0)
4457 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4459 /* Redraw the button if the last button we were over is the hot button and it
4461 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4463 hotBtnPtr->bHot = FALSE;
4464 rc1 = hotBtnPtr->rect;
4465 InflateRect (&rc1, 1, 1);
4466 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4470 /* If the last button we were over is depressed then make it not */
4471 /* depressed and redraw it */
4472 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4474 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4476 btnPtr->fsState &= ~TBSTATE_PRESSED;
4478 rc1 = hotBtnPtr->rect;
4479 InflateRect (&rc1, 1, 1);
4480 InvalidateRect (hwnd, &rc1, TRUE);
4483 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4484 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4490 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4492 TBUTTON_INFO *btnPtr, *oldBtnPtr;
4493 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4496 TRACKMOUSEEVENT trackinfo;
4498 /* fill in the TRACKMOUSEEVENT struct */
4499 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4500 trackinfo.dwFlags = TME_QUERY;
4501 trackinfo.hwndTrack = hwnd;
4502 trackinfo.dwHoverTime = HOVER_DEFAULT;
4504 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4505 _TrackMouseEvent(&trackinfo);
4507 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4508 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4509 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4511 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4512 /* and can properly deactivate the hot toolbar button */
4513 _TrackMouseEvent(&trackinfo);
4516 if (infoPtr->hwndToolTip)
4517 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4518 WM_MOUSEMOVE, wParam, lParam);
4520 pt.x = (INT)LOWORD(lParam);
4521 pt.y = (INT)HIWORD(lParam);
4523 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4525 if (infoPtr->nOldHit != nHit)
4527 /* Remove the effect of an old hot button if the button was enabled and was
4528 drawn with the hot button effect */
4529 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
4530 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
4532 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4533 oldBtnPtr->bHot = FALSE;
4535 InvalidateRect (hwnd, &oldBtnPtr->rect,
4536 TOOLBAR_HasText(infoPtr, oldBtnPtr));
4539 /* It's not a separator or in nowhere. It's a hot button. */
4542 btnPtr = &infoPtr->buttons[nHit];
4544 infoPtr->nHotItem = nHit;
4546 /* only enabled buttons show hot effect */
4547 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
4549 btnPtr->bHot = TRUE;
4550 InvalidateRect(hwnd, &btnPtr->rect,
4551 TOOLBAR_HasText(infoPtr, btnPtr));
4556 if (infoPtr->bCaptured) {
4557 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4558 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
4559 btnPtr->fsState &= ~TBSTATE_PRESSED;
4560 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4562 else if (nHit == infoPtr->nButtonDown) {
4563 btnPtr->fsState |= TBSTATE_PRESSED;
4564 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4567 infoPtr->nOldHit = nHit;
4573 inline static LRESULT
4574 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4576 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
4577 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
4579 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
4583 inline static LRESULT
4584 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4586 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
4587 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
4589 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
4594 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4596 TOOLBAR_INFO *infoPtr;
4597 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
4600 /* allocate memory for info structure */
4601 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
4602 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4605 infoPtr->dwStructSize = sizeof(TBBUTTON);
4607 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
4608 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
4609 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
4610 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
4613 /* native control does:
4614 * Get a lot of colors and brushes
4616 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
4617 * CreateFontIndirectA(adr1)
4618 * CreateBitmap(0x27, 0x24, 1, 1, 0)
4619 * hdc = GetDC(toolbar)
4620 * GetSystemMetrics(0x48)
4621 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
4622 * 0, 0, 0, 0, "MARLETT")
4623 * oldfnt = SelectObject(hdc, fnt2)
4624 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
4625 * GetTextMetricsA(hdc, adr3)
4626 * SelectObject(hdc, oldfnt)
4627 * DeleteObject(fnt2)
4629 * InvalidateRect(toolbar, 0, 1)
4630 * SetWindowLongA(toolbar, 0, addr)
4631 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
4634 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
4635 * ie 2 0x4600094c 0x4600094c 0x4600894d
4636 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
4637 * rebar 0x50008844 0x40008844 0x50008845
4638 * pager 0x50000844 0x40000844 0x50008845
4639 * IC35mgr 0x5400084e **nochange**
4640 * on entry to _NCCREATE 0x5400084e
4641 * rowlist 0x5400004e **nochange**
4642 * on entry to _NCCREATE 0x5400004e
4646 /* I think the code below is a bug, but it is the way that the native
4647 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
4648 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
4649 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
4650 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
4651 * Some how, the only cases of this seem to be MFC programs.
4653 * Note also that the addition of _TRANSPARENT occurs *only* here. It
4654 * does not occur in the WM_STYLECHANGING routine.
4655 * (Guy Albertelli 9/2001)
4658 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
4659 styleadd |= TBSTYLE_TRANSPARENT;
4660 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
4661 styleadd |= CCS_TOP; /* default to top */
4662 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
4665 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
4670 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
4672 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4676 if (dwStyle & WS_MINIMIZE)
4677 return 0; /* Nothing to do */
4679 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
4681 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
4684 if (!(dwStyle & CCS_NODIVIDER))
4686 GetWindowRect (hwnd, &rcWindow);
4687 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4688 if( dwStyle & WS_BORDER )
4689 OffsetRect (&rcWindow, 1, 1);
4690 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
4693 ReleaseDC( hwnd, hdc );
4699 inline static LRESULT
4700 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
4702 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4703 LPNMHDR lpnmh = (LPNMHDR)lParam;
4705 if (lpnmh->code == PGN_CALCSIZE) {
4706 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
4708 if (lppgc->dwFlag == PGF_CALCWIDTH) {
4709 lppgc->iWidth = infoPtr->nWidth;
4710 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
4714 lppgc->iHeight = infoPtr->nHeight;
4715 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
4722 TRACE("passing WM_NOTIFY!\n");
4724 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
4725 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
4728 if (lpnmh->code == TTN_GETDISPINFOA) {
4729 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
4731 FIXME("retrieving ASCII string\n");
4734 else if (lpnmh->code == TTN_GETDISPINFOW) {
4735 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
4737 FIXME("retrieving UNICODE string\n");
4748 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
4750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4754 /* fill ps.rcPaint with a default rect */
4755 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
4757 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
4759 TRACE("psrect=(%d,%d)-(%d,%d)\n",
4760 ps.rcPaint.left, ps.rcPaint.top,
4761 ps.rcPaint.right, ps.rcPaint.bottom);
4763 TOOLBAR_Refresh (hwnd, hdc, &ps);
4764 if (!wParam) EndPaint (hwnd, &ps);
4771 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
4772 /*****************************************************
4775 * Handles the WM_SETREDRAW message.
4778 * According to testing V4.71 of COMCTL32 returns the
4779 * *previous* status of the redraw flag (either 0 or 1)
4780 * instead of the MSDN documented value of 0 if handled.
4781 * (For laughs see the "consistancy" with same function
4784 *****************************************************/
4786 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4787 BOOL oldredraw = infoPtr->bDoRedraw;
4789 TRACE("set to %s\n",
4790 (wParam) ? "TRUE" : "FALSE");
4791 infoPtr->bDoRedraw = (BOOL) wParam;
4793 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4795 return (oldredraw) ? 1 : 0;
4800 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
4802 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4803 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4812 /* Resize deadlock check */
4813 if (infoPtr->bAutoSize) {
4814 infoPtr->bAutoSize = FALSE;
4818 /* FIXME: optimize to only update size if the new size doesn't */
4819 /* match the current size */
4821 flags = (INT) wParam;
4823 /* FIXME for flags =
4824 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
4827 TRACE("sizing toolbar!\n");
4829 if (flags == SIZE_RESTORED) {
4830 /* width and height don't apply */
4831 parent = GetParent (hwnd);
4832 GetClientRect(parent, &parent_rect);
4833 x = parent_rect.left;
4834 y = parent_rect.top;
4836 if (dwStyle & CCS_NORESIZE) {
4837 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
4840 * this sets the working width of the toolbar, and
4841 * Calc Toolbar will not adjust it, only the height
4843 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4844 cy = infoPtr->nHeight;
4845 cx = infoPtr->nWidth;
4846 TOOLBAR_CalcToolbar (hwnd);
4847 infoPtr->nWidth = cx;
4848 infoPtr->nHeight = cy;
4851 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4852 TOOLBAR_CalcToolbar (hwnd);
4853 cy = infoPtr->nHeight;
4854 cx = infoPtr->nWidth;
4856 if (dwStyle & CCS_NOMOVEY) {
4857 GetWindowRect(hwnd, &window_rect);
4858 ScreenToClient(parent, (LPPOINT)&window_rect.left);
4859 y = window_rect.top;
4863 if (dwStyle & CCS_NOPARENTALIGN) {
4864 uPosFlags |= SWP_NOMOVE;
4865 cy = infoPtr->nHeight;
4866 cx = infoPtr->nWidth;
4869 if (!(dwStyle & CCS_NODIVIDER))
4870 cy += GetSystemMetrics(SM_CYEDGE);
4872 if (dwStyle & WS_BORDER)
4875 cy += GetSystemMetrics(SM_CYEDGE);
4876 cx += GetSystemMetrics(SM_CYEDGE);
4879 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
4880 cx, cy, uPosFlags | SWP_NOZORDER);
4887 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
4889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4891 if (nType == GWL_STYLE) {
4892 if (lpStyle->styleNew & TBSTYLE_LIST) {
4893 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
4896 infoPtr->dwDTFlags = DT_CENTER;
4898 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
4899 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
4900 (TBSTYLE_FLAT | TBSTYLE_LIST));
4901 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
4904 TOOLBAR_AutoSize (hwnd);
4906 InvalidateRect(hwnd, NULL, FALSE);
4913 static LRESULT WINAPI
4914 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4916 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4917 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4919 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
4920 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
4925 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
4927 case TB_ADDBUTTONSA:
4928 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
4930 case TB_ADDBUTTONSW:
4931 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
4934 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
4937 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
4940 return TOOLBAR_AutoSize (hwnd);
4942 case TB_BUTTONCOUNT:
4943 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
4945 case TB_BUTTONSTRUCTSIZE:
4946 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
4948 case TB_CHANGEBITMAP:
4949 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
4951 case TB_CHECKBUTTON:
4952 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
4954 case TB_COMMANDTOINDEX:
4955 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
4958 return TOOLBAR_Customize (hwnd);
4960 case TB_DELETEBUTTON:
4961 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
4963 case TB_ENABLEBUTTON:
4964 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
4966 case TB_GETANCHORHIGHLIGHT:
4967 return TOOLBAR_GetAnchorHighlight (hwnd);
4970 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
4972 case TB_GETBITMAPFLAGS:
4973 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
4976 return TOOLBAR_GetButton (hwnd, wParam, lParam);
4978 case TB_GETBUTTONINFOA:
4979 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
4981 case TB_GETBUTTONINFOW:
4982 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
4984 case TB_GETBUTTONSIZE:
4985 return TOOLBAR_GetButtonSize (hwnd);
4987 case TB_GETBUTTONTEXTA:
4988 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
4990 case TB_GETBUTTONTEXTW:
4991 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
4993 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
4995 case TB_GETDISABLEDIMAGELIST:
4996 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
4998 case TB_GETEXTENDEDSTYLE:
4999 return TOOLBAR_GetExtendedStyle (hwnd);
5001 case TB_GETHOTIMAGELIST:
5002 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5005 return TOOLBAR_GetHotItem (hwnd);
5007 case TB_GETIMAGELIST:
5008 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
5010 /* case TB_GETINSERTMARK: */ /* 4.71 */
5011 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5013 case TB_GETITEMRECT:
5014 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5017 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5019 /* case TB_GETOBJECT: */ /* 4.71 */
5020 /* case TB_GETPADDING: */ /* 4.71 */
5023 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5026 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5029 return TOOLBAR_GetState (hwnd, wParam, lParam);
5032 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5034 case TB_GETTEXTROWS:
5035 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5037 case TB_GETTOOLTIPS:
5038 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5040 case TB_GETUNICODEFORMAT:
5041 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5043 case CCM_GETVERSION:
5044 return TOOLBAR_GetVersion (hwnd);
5047 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5050 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5052 case TB_INDETERMINATE:
5053 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5055 case TB_INSERTBUTTONA:
5056 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5058 case TB_INSERTBUTTONW:
5059 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5061 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5063 case TB_ISBUTTONCHECKED:
5064 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5066 case TB_ISBUTTONENABLED:
5067 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5069 case TB_ISBUTTONHIDDEN:
5070 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5072 case TB_ISBUTTONHIGHLIGHTED:
5073 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5075 case TB_ISBUTTONINDETERMINATE:
5076 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5078 case TB_ISBUTTONPRESSED:
5079 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5081 case TB_LOADIMAGES: /* 4.70 */
5082 FIXME("missing standard imagelists\n");
5085 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5086 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5087 /* case TB_MARKBUTTON: */ /* 4.71 */
5088 /* case TB_MOVEBUTTON: */ /* 4.71 */
5090 case TB_PRESSBUTTON:
5091 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5093 /* case TB_REPLACEBITMAP: */
5095 case TB_SAVERESTOREA:
5096 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5098 case TB_SAVERESTOREW:
5099 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5101 case TB_SETANCHORHIGHLIGHT:
5102 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5104 case TB_SETBITMAPSIZE:
5105 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5107 case TB_SETBUTTONINFOA:
5108 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5110 case TB_SETBUTTONINFOW:
5111 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5113 case TB_SETBUTTONSIZE:
5114 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5116 case TB_SETBUTTONWIDTH:
5117 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5120 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5122 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
5124 case TB_SETDISABLEDIMAGELIST:
5125 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5127 case TB_SETDRAWTEXTFLAGS:
5128 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5130 case TB_SETEXTENDEDSTYLE:
5131 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5133 case TB_SETHOTIMAGELIST:
5134 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5137 return TOOLBAR_SetHotItem (hwnd, wParam);
5139 case TB_SETIMAGELIST:
5140 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5143 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5145 /* case TB_SETINSERTMARK: */ /* 4.71 */
5147 case TB_SETINSERTMARKCOLOR:
5148 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5150 case TB_SETMAXTEXTROWS:
5151 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5153 /* case TB_SETPADDING: */ /* 4.71 */
5156 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5159 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5162 return TOOLBAR_SetState (hwnd, wParam, lParam);
5165 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5167 case TB_SETTOOLTIPS:
5168 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5170 case TB_SETUNICODEFORMAT:
5171 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5173 case CCM_SETVERSION:
5174 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5180 return TOOLBAR_Create (hwnd, wParam, lParam);
5183 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5186 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5189 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5191 /* case WM_KEYDOWN: */
5192 /* case WM_KILLFOCUS: */
5194 case WM_LBUTTONDBLCLK:
5195 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5197 case WM_LBUTTONDOWN:
5198 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5201 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5204 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5207 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5209 case WM_CAPTURECHANGED:
5210 return TOOLBAR_CaptureChanged(hwnd);
5213 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5216 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5219 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5222 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5225 return TOOLBAR_Notify (hwnd, wParam, lParam);
5227 /* case WM_NOTIFYFORMAT: */
5230 return TOOLBAR_Paint (hwnd, wParam);
5233 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5236 return TOOLBAR_Size (hwnd, wParam, lParam);
5238 case WM_STYLECHANGED:
5239 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5241 /* case WM_SYSCOLORCHANGE: */
5243 /* case WM_WININICHANGE: */
5248 case WM_MEASUREITEM:
5251 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5253 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5255 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5259 if (uMsg >= WM_USER)
5260 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5261 uMsg, wParam, lParam);
5262 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5269 TOOLBAR_Register (void)
5273 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5274 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5275 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5276 wndClass.cbClsExtra = 0;
5277 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5278 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5279 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5280 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5282 RegisterClassA (&wndClass);
5287 TOOLBAR_Unregister (void)
5289 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);