4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * Differences between MSDN and actual native control operation:
8 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
9 * to the right of the bitmap. Otherwise, this style is
10 * identical to TBSTYLE_FLAT."
11 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
12 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
13 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
14 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
18 * - A little bug in TOOLBAR_DrawMasked()
19 * - Button wrapping (under construction).
21 * - Notifications (under construction).
23 * - Tooltip support (almost complete).
24 * - Unicode suppport (under construction).
25 * - Fix TOOLBAR_SetButtonInfo32A/W.
26 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
27 * - I_IMAGECALLBACK support.
28 * - iString of -1 is undocumented
29 * - Customization dialog:
31 * - Minor buglet in 'available buttons' list:
32 * Buttons are not listed in M$-like order. M$ seems to use a single
33 * internal list to store the button information of both listboxes.
34 * - Drag list support.
35 * - Help and Reset button support.
38 * - Run tests using Waite Group Windows95 API Bible Volume 2.
39 * The second cdrom contains executables addstr.exe, btncount.exe,
40 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
41 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
42 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
43 * setparnt.exe, setrows.exe, toolwnd.exe.
44 * - Microsofts controlspy examples.
45 * - Charles Petzold's 'Programming Windows': gadgets.exe
54 #include "wine/unicode.h"
56 #include "imagelist.h"
58 #include "debugtools.h"
60 DEFAULT_DEBUG_CHANNEL(toolbar);
78 DWORD dwStructSize; /* size of TBBUTTON struct */
79 INT nHeight; /* height of the toolbar */
80 INT nWidth; /* width of the toolbar */
86 INT nRows; /* number of button rows */
87 INT nMaxTextRows; /* maximum number of text rows */
88 INT cxMin; /* minimum button width */
89 INT cxMax; /* maximum button width */
90 INT nNumButtons; /* number of buttons */
91 INT nNumBitmaps; /* number of bitmaps */
92 INT nNumStrings; /* number of strings */
93 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
94 BOOL bCaptured; /* mouse captured? */
97 INT nHotItem; /* index of the "hot" item */
98 HFONT hFont; /* text font */
99 HIMAGELIST himlInt; /* image list created internally */
100 HIMAGELIST himlDef; /* default image list */
101 HIMAGELIST himlHot; /* hot image list */
102 HIMAGELIST himlDis; /* disabled image list */
103 HWND hwndToolTip; /* handle to tool tip control */
104 HWND hwndNotify; /* handle to the window that gets notifications */
105 HWND hwndSelf; /* my own handle */
106 BOOL bTransparent; /* background transparency flag */
107 BOOL bBtnTranspnt; /* button transparency flag */
108 BOOL bAutoSize; /* auto size deadlock indicator */
109 BOOL bAnchor; /* anchor highlight enabled */
110 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
111 DWORD dwExStyle; /* extended toolbar style */
112 DWORD dwDTFlags; /* DrawText flags */
114 COLORREF clrInsertMark; /* insert mark color */
115 RECT rcBound; /* bounding rectangle */
118 TBUTTON_INFO *buttons; /* pointer to button array */
119 LPWSTR *strings; /* pointer to string array */
120 } TOOLBAR_INFO, *PTOOLBAR_INFO;
123 /* used by customization dialog */
126 PTOOLBAR_INFO tbInfo;
128 } CUSTDLG_INFO, *PCUSTDLG_INFO;
136 } CUSTOMBUTTON, *PCUSTOMBUTTON;
139 #define SEPARATOR_WIDTH 8
141 #define BOTTOM_BORDER 2
142 #define DDARROW_WIDTH 11
144 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
145 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
146 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
150 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
152 if (TRACE_ON(toolbar)){
153 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, string=%d\n",
154 btn_num, bP->idCommand,
155 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
157 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
158 btn_num, bP->idCommand,
159 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
160 bP->rect.left, bP->rect.top,
161 bP->rect.right, bP->rect.bottom);
167 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
169 if (TRACE_ON(toolbar)) {
173 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
174 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
176 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
177 iP->nNumStrings, dwStyle);
178 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p\n",
180 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis);
181 for(i=0; i<iP->nNumButtons; i++) {
182 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
188 /***********************************************************************
191 * This function validates that the styles set are implemented and
192 * issues FIXME's warning of possible problems. In a perfect world this
193 * function should be null.
196 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
198 if (dwStyle & TBSTYLE_ALTDRAG)
199 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
200 if (dwStyle & TBSTYLE_REGISTERDROP)
201 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
206 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
208 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
209 nmhdr->hwndFrom = infoPtr->hwndSelf;
212 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
213 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
215 if (infoPtr->bNtfUnicode)
216 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
217 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
219 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
220 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
224 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
226 LPWSTR lpText = NULL;
228 /* FIXME: iString == -1 is undocumented */
229 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
230 lpText = (LPWSTR)btnPtr->iString;
231 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
232 lpText = infoPtr->strings[btnPtr->iString];
237 /***********************************************************************
238 * TOOLBAR_GetBitmapIndex
240 * This function returns the bitmap index associated with a button.
241 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
242 * is issued to retrieve the index.
245 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
247 INT ret = btnPtr->iBitmap;
249 if (ret == I_IMAGECALLBACK) {
250 /* issue TBN_GETDISPINFO */
253 nmgd.idCommand = btnPtr->idCommand;
254 nmgd.lParam = btnPtr->dwData;
255 nmgd.dwMask = TBNF_IMAGE;
256 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
257 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
259 if (nmgd.dwMask & TBNF_DI_SETITEM) {
260 btnPtr->iBitmap = nmgd.iImage;
263 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
264 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
271 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
273 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
274 (index == I_IMAGECALLBACK))
281 /***********************************************************************
282 * TOOLBAR_DrawImageList
284 * This function validates the bitmap index (including I_IMAGECALLBACK
285 * functionality). It then draws the image via the ImageList_Draw
286 * function. It returns TRUE if the image was drawn, FALSE otherwise.
289 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
290 HDC hdc, UINT left, UINT top, UINT draw_flags)
294 if (!himl) return FALSE;
296 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
297 ERR("index %d is not valid, max %d\n",
298 btnPtr->iBitmap, infoPtr->nNumBitmaps);
302 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
303 if (index == -1) return FALSE;
304 ERR("TBN_GETDISPINFO returned invalid index %d\n",
308 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
309 index, himl, left, top, draw_flags);
311 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
316 /***********************************************************************
317 * TOOLBAR_TestImageExist
319 * This function is similar to TOOLBAR_DrawImageList, except it does not
320 * draw the image. The I_IMAGECALLBACK functionality is implemented.
323 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
327 if (!himl) return FALSE;
329 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
330 ERR("index %d is not valid, max %d\n",
331 btnPtr->iBitmap, infoPtr->nNumBitmaps);
335 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
336 if (index == -1) return FALSE;
337 ERR("TBN_GETDISPINFO returned invalid index %d\n",
346 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
348 INT x = (lpRect->left + lpRect->right) / 2 - 1;
349 INT yBottom = lpRect->bottom - 3;
350 INT yTop = lpRect->top + 1;
352 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
353 MoveToEx (hdc, x, yBottom, NULL);
354 LineTo (hdc, x, yTop);
356 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
357 MoveToEx (hdc, x, yBottom, NULL);
358 LineTo (hdc, x, yTop);
362 /***********************************************************************
363 * TOOLBAR_DrawDDFlatSeparator
365 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
366 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
367 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
368 * are horizontal as opposed to the vertical separators for not dropdown
371 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
374 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr)
377 COLORREF oldcolor, newcolor;
379 myrect.left = lpRect->left;
380 myrect.right = lpRect->right;
381 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
382 myrect.bottom = myrect.top + 1;
384 InflateRect (&myrect, -2, 0);
386 TRACE("rect=(%d,%d)-(%d,%d)\n",
387 myrect.left, myrect.top, myrect.right, myrect.bottom);
389 newcolor = GetSysColor (COLOR_BTNSHADOW);
390 oldcolor = SetBkColor (hdc, newcolor);
391 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
393 myrect.top = myrect.bottom;
394 myrect.bottom = myrect.top + 1;
396 newcolor = GetSysColor (COLOR_BTNHIGHLIGHT);
397 SetBkColor (hdc, newcolor);
398 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
400 SetBkColor (hdc, oldcolor);
405 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
408 SelectObject ( hdc, GetSysColorPen (colorRef));
411 MoveToEx (hdc, x, y, NULL);
412 LineTo (hdc, x+5, y++); x++;
413 MoveToEx (hdc, x, y, NULL);
414 LineTo (hdc, x+3, y++); x++;
415 MoveToEx (hdc, x, y, NULL);
416 LineTo (hdc, x+1, y++);
420 * Draw the text string for this button.
421 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
422 * is non-zero, so we can simply check himlDef to see if we have
426 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
427 HDC hdc, INT nState, DWORD dwStyle)
429 RECT rcText = btnPtr->rect;
432 LPWSTR lpText = NULL;
433 HIMAGELIST himl = infoPtr->himlDef;
435 TRACE ("iString: %x\n", btnPtr->iString);
437 /* get a pointer to the text */
438 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
440 TRACE ("lpText: %s\n", debugstr_w(lpText));
445 InflateRect (&rcText, -3, -3);
447 if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
448 /* The following test looked like this before
449 * I changed it. IE4 "Links" toolbar would not
450 * draw correctly with the original code. - GA 8/01
451 * ((dwStyle & TBSTYLE_LIST) &&
452 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
453 * (btnPtr->iBitmap != I_IMAGENONE))
455 if (dwStyle & TBSTYLE_LIST) {
456 /* LIST style w/ ICON offset is by matching native. */
457 /* Matches IE4 "Links" bar. - GA 8/01 */
458 rcText.left += (infoPtr->nBitmapWidth + 2);
461 rcText.top += infoPtr->nBitmapHeight + 1;
465 if (dwStyle & TBSTYLE_LIST) {
466 /* LIST style w/o ICON offset is by matching native. */
467 /* Matches IE4 "menu" bar. - GA 8/01 */
472 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
473 OffsetRect (&rcText, 1, 1);
475 TRACE("string rect=(%d,%d)-(%d,%d)\n",
476 rcText.left, rcText.top, rcText.right, rcText.bottom);
478 hOldFont = SelectObject (hdc, infoPtr->hFont);
479 if (!(nState & TBSTATE_ENABLED)) {
480 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
481 OffsetRect (&rcText, 1, 1);
482 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
483 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
484 OffsetRect (&rcText, -1, -1);
485 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
487 else if (nState & TBSTATE_INDETERMINATE) {
488 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
489 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
492 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
493 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
496 SetTextColor (hdc, clrOld);
497 SelectObject (hdc, hOldFont);
503 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
505 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
506 INT cx = lpRect->right - lpRect->left;
507 INT cy = lpRect->bottom - lpRect->top;
508 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
509 SelectObject (hdc, hbr);
514 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
515 HDC hdc, INT x, INT y)
517 /* FIXME: this function is a hack since it uses image list
518 internals directly */
520 HIMAGELIST himl = infoPtr->himlDef;
528 /* create new dc's */
529 hdcImageList = CreateCompatibleDC (0);
530 hdcMask = CreateCompatibleDC (0);
532 /* create new bitmap */
533 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
534 SelectObject (hdcMask, hbmMask);
536 /* copy the mask bitmap */
537 SelectObject (hdcImageList, himl->hbmMask);
538 SetBkColor (hdcImageList, RGB(255, 255, 255));
539 SetTextColor (hdcImageList, RGB(0, 0, 0));
540 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
541 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
543 /* draw the new mask */
544 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
545 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
546 hdcMask, 0, 0, 0xB8074A);
548 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
549 BitBlt (hdc, x, y, himl->cx, himl->cy,
550 hdcMask, 0, 0, 0xB8074A);
552 DeleteObject (hbmMask);
554 DeleteDC (hdcImageList);
559 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
562 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
563 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
564 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
565 RECT rc, rcArrow, rcBitmap;
567 if (btnPtr->fsState & TBSTATE_HIDDEN)
571 CopyRect (&rcArrow, &rc);
572 CopyRect(&rcBitmap, &rc);
574 if (!infoPtr->bBtnTranspnt)
575 FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
577 if (hasDropDownArrow)
579 if (dwStyle & TBSTYLE_FLAT)
580 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
582 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
583 rcArrow.left = rc.right;
586 /* Center the bitmap horizontally and vertically */
587 if (dwStyle & TBSTYLE_LIST)
590 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
592 if(TOOLBAR_HasText(infoPtr, btnPtr))
593 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
595 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
597 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
598 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
599 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
602 if (btnPtr->fsStyle & TBSTYLE_SEP) {
603 /* with the FLAT style, iBitmap is the width and has already */
604 /* been taken into consideration in calculating the width */
605 /* so now we need to draw the vertical separator */
606 /* empirical tests show that iBitmap can/will be non-zero */
607 /* when drawing the vertical bar... */
608 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
609 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
610 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr);
612 TOOLBAR_DrawFlatSeparator (&rc, hdc);
618 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
619 if (!(dwStyle & TBSTYLE_FLAT))
621 DrawEdge (hdc, &rc, EDGE_RAISED,
622 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
623 if (hasDropDownArrow)
624 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
625 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
628 if (hasDropDownArrow)
630 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
631 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
634 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
635 hdc, rcBitmap.left, rcBitmap.top,
637 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
639 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
643 /* pressed TBSTYLE_BUTTON */
644 if (btnPtr->fsState & TBSTATE_PRESSED) {
645 if (dwStyle & TBSTYLE_FLAT)
647 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
648 if (hasDropDownArrow)
649 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
653 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
654 if (hasDropDownArrow)
655 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
658 if (hasDropDownArrow)
659 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
661 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
662 hdc, rcBitmap.left+1, rcBitmap.top+1,
665 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
669 /* checked TBSTYLE_CHECK */
670 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
671 (btnPtr->fsState & TBSTATE_CHECKED)) {
672 if (dwStyle & TBSTYLE_FLAT)
673 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
674 BF_RECT | BF_ADJUST);
676 DrawEdge (hdc, &rc, EDGE_SUNKEN,
677 BF_RECT | BF_MIDDLE | BF_ADJUST);
679 TOOLBAR_DrawPattern (hdc, &rc);
681 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
682 hdc, rcBitmap.left+1, rcBitmap.top+1,
685 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
690 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
691 DrawEdge (hdc, &rc, EDGE_RAISED,
692 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
694 TOOLBAR_DrawPattern (hdc, &rc);
695 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
696 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
701 if (dwStyle & TBSTYLE_FLAT)
705 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
706 if (hasDropDownArrow)
707 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
710 else /* The following code needs to be removed after
711 * "hot item" support has been implemented for the
712 * case where it is being de-selected.
715 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
716 if (hasDropDownArrow)
717 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
721 if (hasDropDownArrow)
722 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
725 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
726 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
729 rcBitmap.top, ILD_NORMAL))
730 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
731 hdc, rcBitmap.left, rcBitmap.top,
735 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
736 hdc, rcBitmap.left, rcBitmap.top,
741 DrawEdge (hdc, &rc, EDGE_RAISED,
742 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
744 if (hasDropDownArrow)
746 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
747 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
748 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
751 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
752 hdc, rcBitmap.left, rcBitmap.top,
756 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
761 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
764 TBUTTON_INFO *btnPtr;
765 INT i, oldBKmode = 0;
768 /* if imagelist belongs to the app, it can be changed
769 by the app after setting it */
770 if (infoPtr->himlDef != infoPtr->himlInt)
771 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
773 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
775 if (infoPtr->bBtnTranspnt)
776 oldBKmode = SetBkMode (hdc, TRANSPARENT);
778 /* redraw necessary buttons */
779 btnPtr = infoPtr->buttons;
780 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
782 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
783 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
786 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
787 SetBkMode (hdc, oldBKmode);
790 /***********************************************************************
791 * TOOLBAR_MeasureString
793 * This function gets the width and height of a string in pixels. This
794 * is done first by using GetTextExtentPoint to get the basic width
795 * and height. The DrawText is called with DT_CALCRECT to get the exact
796 * width. The reason is because the text may have more than one "&" (or
797 * prefix characters as M$ likes to call them). The prefix character
798 * indicates where the underline goes, except for the string "&&" which
799 * is reduced to a single "&". GetTextExtentPoint does not process these
800 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
803 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
804 HDC hdc, LPSIZE lpSize)
811 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
812 (btnPtr->iString > -1) &&
813 (btnPtr->iString < infoPtr->nNumStrings))
815 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
817 /* first get size of all the text */
818 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
820 /* feed above size into the rectangle for DrawText */
821 myrect.left = myrect.top = 0;
822 myrect.right = lpSize->cx;
823 myrect.bottom = lpSize->cy;
825 /* Use DrawText to get true size as drawn (less pesky "&") */
826 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
827 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
830 /* feed back to caller */
831 lpSize->cx = myrect.right;
832 lpSize->cy = myrect.bottom;
835 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
838 /***********************************************************************
839 * TOOLBAR_CalcStrings
841 * This function walks through each string and measures it and returns
842 * the largest height and width to caller.
845 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
848 TBUTTON_INFO *btnPtr;
858 hOldFont = SelectObject (hdc, infoPtr->hFont);
860 btnPtr = infoPtr->buttons;
861 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
862 if(TOOLBAR_HasText(infoPtr, btnPtr))
864 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
865 if (sz.cx > lpSize->cx)
867 if (sz.cy > lpSize->cy)
872 SelectObject (hdc, hOldFont);
873 ReleaseDC (hwnd, hdc);
875 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
878 /***********************************************************************
879 * TOOLBAR_WrapToolbar
881 * This function walks through the buttons and seperators in the
882 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
883 * wrapping should occur based on the width of the toolbar window.
884 * It does *not* calculate button placement itself. That task
885 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
886 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
887 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
891 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
894 TBUTTON_INFO *btnPtr;
897 BOOL bWrap, bButtonWrap;
899 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
900 /* no layout is necessary. Applications may use this style */
901 /* to perform their own layout on the toolbar. */
902 if( !(dwStyle & TBSTYLE_WRAPABLE) )
905 btnPtr = infoPtr->buttons;
906 x = infoPtr->nIndent;
908 /* this can get the parents width, to know how far we can extend
909 * this toolbar. We cannot use its height, as there may be multiple
910 * toolbars in a rebar control
912 GetClientRect( GetParent(hwnd), &rc );
913 infoPtr->nWidth = rc.right - rc.left;
916 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
917 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
920 for (i = 0; i < infoPtr->nNumButtons; i++ )
923 btnPtr[i].fsState &= ~TBSTATE_WRAP;
925 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
928 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
929 /* it is the actual width of the separator. This is used for */
930 /* custom controls in toolbars. */
932 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
933 /* width. - GA 8/01 */
934 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
935 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
936 cx = (btnPtr[i].iBitmap > 0) ?
937 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
939 cx = infoPtr->nButtonWidth;
941 /* Two or more adjacent separators form a separator group. */
942 /* The first separator in a group should be wrapped to the */
943 /* next row if the previous wrapping is on a button. */
945 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
946 (i + 1 < infoPtr->nNumButtons ) &&
947 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
949 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
950 btnPtr[i].fsState |= TBSTATE_WRAP;
951 x = infoPtr->nIndent;
957 /* The layout makes sure the bitmap is visible, but not the button. */
958 /* Test added to also wrap after a button that starts a row but */
959 /* is bigger than the area. - GA 8/01 */
960 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
961 > infoPtr->nWidth ) ||
962 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
966 /* If the current button is a separator and not hidden, */
967 /* go to the next until it reaches a non separator. */
968 /* Wrap the last separator if it is before a button. */
969 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
970 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
971 i < infoPtr->nNumButtons )
977 if( bFound && i < infoPtr->nNumButtons )
980 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
981 i, btnPtr[i].fsStyle, x, cx);
982 btnPtr[i].fsState |= TBSTATE_WRAP;
983 x = infoPtr->nIndent;
987 else if ( i >= infoPtr->nNumButtons)
990 /* If the current button is not a separator, find the last */
991 /* separator and wrap it. */
992 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
994 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
995 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
999 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1000 i, btnPtr[i].fsStyle, x, cx);
1001 x = infoPtr->nIndent;
1002 btnPtr[j].fsState |= TBSTATE_WRAP;
1003 bButtonWrap = FALSE;
1008 /* If no separator available for wrapping, wrap one of */
1009 /* non-hidden previous button. */
1013 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1015 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1020 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1021 i, btnPtr[i].fsStyle, x, cx);
1022 x = infoPtr->nIndent;
1023 btnPtr[j].fsState |= TBSTATE_WRAP;
1029 /* If all above failed, wrap the current button. */
1032 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1033 i, btnPtr[i].fsStyle, x, cx);
1034 btnPtr[i].fsState |= TBSTATE_WRAP;
1036 x = infoPtr->nIndent;
1037 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1038 bButtonWrap = FALSE;
1044 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1045 i, btnPtr[i].fsStyle, x, cx);
1052 /***********************************************************************
1053 * TOOLBAR_CalcToolbar
1055 * This function calculates button and separator placement. It first
1056 * calculates the button sizes, gets the toolbar window width and then
1057 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1058 * on. It assigns a new location to each item and sends this location to
1059 * the tooltip window if appropriate. Finally, it updates the rcBound
1060 * rect and calculates the new required toolbar window height.
1064 TOOLBAR_CalcToolbar (HWND hwnd)
1066 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1067 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1068 TBUTTON_INFO *btnPtr;
1069 INT i, nRows, nSepRows;
1073 BOOL usesBitmaps = FALSE;
1074 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1076 TOOLBAR_CalcStrings (hwnd, &sizeString);
1078 if (dwStyle & TBSTYLE_LIST)
1080 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1082 if (infoPtr->buttons[i].iBitmap >= 0)
1085 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1086 0, sizeString.cy) + 6;
1087 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1088 0) + sizeString.cx + 6;
1089 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1090 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1091 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1092 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1095 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1097 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1101 if (sizeString.cy > 0)
1104 infoPtr->nButtonHeight = sizeString.cy +
1105 2 + /* this is the space to separate text from bitmap */
1106 infoPtr->nBitmapHeight + 6;
1108 infoPtr->nButtonHeight = sizeString.cy + 6;
1110 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1111 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1113 if (sizeString.cx > infoPtr->nBitmapWidth)
1114 infoPtr->nButtonWidth = sizeString.cx + 6;
1115 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1116 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1119 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1120 infoPtr->nButtonWidth = infoPtr->cxMin;
1121 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1122 infoPtr->nButtonWidth = infoPtr->cxMax;
1124 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1126 x = infoPtr->nIndent;
1130 * We will set the height below, and we set the width on entry
1131 * so we do not reset them here..
1134 GetClientRect( hwnd, &rc );
1135 /* get initial values for toolbar */
1136 infoPtr->nWidth = rc.right - rc.left;
1137 infoPtr->nHeight = rc.bottom - rc.top;
1140 /* from above, minimum is a button, and possible text */
1141 cx = infoPtr->nButtonWidth;
1143 /* cannot use just ButtonHeight, we may have no buttons! */
1144 if (infoPtr->nNumButtons > 0)
1145 infoPtr->nHeight = infoPtr->nButtonHeight;
1147 cy = infoPtr->nHeight;
1149 nRows = nSepRows = 0;
1151 infoPtr->rcBound.top = y;
1152 infoPtr->rcBound.left = x;
1153 infoPtr->rcBound.bottom = y + cy;
1154 infoPtr->rcBound.right = x;
1156 btnPtr = infoPtr->buttons;
1158 /* do not base height/width on parent, if the parent is a */
1159 /* rebar control it could have multiple rows of toolbars */
1160 /* GetClientRect( GetParent(hwnd), &rc ); */
1161 /* cx = rc.right - rc.left; */
1162 /* cy = rc.bottom - rc.top; */
1164 TRACE("cy=%d\n", cy);
1166 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1169 if (btnPtr->fsState & TBSTATE_HIDDEN)
1171 SetRectEmpty (&btnPtr->rect);
1175 cy = infoPtr->nHeight;
1177 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1178 /* it is the actual width of the separator. This is used for */
1179 /* custom controls in toolbars. */
1180 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1181 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1182 cy = (btnPtr->iBitmap > 0) ?
1183 btnPtr->iBitmap : SEPARATOR_WIDTH;
1184 cx = infoPtr->nButtonWidth;
1187 cx = (btnPtr->iBitmap > 0) ?
1188 btnPtr->iBitmap : SEPARATOR_WIDTH;
1192 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1199 hOldFont = SelectObject (hdc, infoPtr->hFont);
1201 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1203 SelectObject (hdc, hOldFont);
1204 ReleaseDC (hwnd, hdc);
1206 /* Fudge amount measured against IE4 "menu" and "Links" */
1207 /* toolbars with native control (v4.71). - GA 8/01 */
1208 cx = sz.cx + 6 + 5 + 5;
1209 if ((dwStyle & TBSTYLE_LIST) &&
1210 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1211 cx += infoPtr->nBitmapWidth;
1214 cx = infoPtr->nButtonWidth;
1216 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1217 cx += DDARROW_WIDTH;
1219 if (btnPtr->fsState & TBSTATE_WRAP )
1222 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1224 if (infoPtr->rcBound.left > x)
1225 infoPtr->rcBound.left = x;
1226 if (infoPtr->rcBound.right < x + cx)
1227 infoPtr->rcBound.right = x + cx;
1228 if (infoPtr->rcBound.bottom < y + cy)
1229 infoPtr->rcBound.bottom = y + cy;
1231 /* Set the toolTip only for non-hidden, non-separator button */
1232 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1236 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1237 ti.cbSize = sizeof(TTTOOLINFOA);
1239 ti.uId = btnPtr->idCommand;
1240 ti.rect = btnPtr->rect;
1241 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1245 /* btnPtr->nRow is zero based. The space between the rows is */
1246 /* also considered as a row. */
1247 btnPtr->nRow = nRows + nSepRows;
1249 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d\n",
1250 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow);
1254 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1258 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1259 /* it is the actual width of the separator. This is used for */
1260 /* custom controls in toolbars. */
1261 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1262 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1263 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1267 /* nSepRows is used to calculate the extra height follwoing */
1271 x = infoPtr->nIndent;
1278 /* infoPtr->nRows is the number of rows on the toolbar */
1279 infoPtr->nRows = nRows + nSepRows + 1;
1281 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1283 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1284 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1285 nSepRows * (infoPtr->nBitmapHeight + 1) +
1287 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1292 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1295 TBUTTON_INFO *btnPtr;
1298 btnPtr = infoPtr->buttons;
1299 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1300 if (btnPtr->fsState & TBSTATE_HIDDEN)
1303 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1304 if (PtInRect (&btnPtr->rect, *lpPt)) {
1305 TRACE(" ON SEPARATOR %d!\n", i);
1310 if (PtInRect (&btnPtr->rect, *lpPt)) {
1311 TRACE(" ON BUTTON %d!\n", i);
1317 TRACE(" NOWHERE!\n");
1323 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
1325 TBUTTON_INFO *btnPtr;
1328 btnPtr = infoPtr->buttons;
1329 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1330 if (btnPtr->idCommand == idCommand) {
1331 TRACE("command=%d index=%d\n", idCommand, i);
1335 TRACE("no index found for command=%d\n", idCommand);
1341 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1343 TBUTTON_INFO *btnPtr;
1346 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1349 /* check index button */
1350 btnPtr = &infoPtr->buttons[nIndex];
1351 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1352 if (btnPtr->fsState & TBSTATE_CHECKED)
1356 /* check previous buttons */
1357 nRunIndex = nIndex - 1;
1358 while (nRunIndex >= 0) {
1359 btnPtr = &infoPtr->buttons[nRunIndex];
1360 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1361 if (btnPtr->fsState & TBSTATE_CHECKED)
1369 /* check next buttons */
1370 nRunIndex = nIndex + 1;
1371 while (nRunIndex < infoPtr->nNumButtons) {
1372 btnPtr = &infoPtr->buttons[nRunIndex];
1373 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1374 if (btnPtr->fsState & TBSTATE_CHECKED)
1387 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1388 WPARAM wParam, LPARAM lParam)
1394 msg.wParam = wParam;
1395 msg.lParam = lParam;
1396 msg.time = GetMessageTime ();
1397 msg.pt.x = LOWORD(GetMessagePos ());
1398 msg.pt.y = HIWORD(GetMessagePos ());
1400 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1404 /***********************************************************************
1405 * TOOLBAR_CustomizeDialogProc
1406 * This function implements the toolbar customization dialog.
1409 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1411 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1412 PCUSTOMBUTTON btnInfo;
1414 TOOLBAR_INFO *infoPtr = custInfo->tbInfo;
1419 custInfo = (PCUSTDLG_INFO)lParam;
1420 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1428 /* send TBN_QUERYINSERT notification */
1429 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1431 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1434 /* add items to 'toolbar buttons' list and check if removable */
1435 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1437 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1438 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1439 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1440 btnInfo->bVirtual = FALSE;
1441 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1443 /* send TBN_QUERYDELETE notification */
1445 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1449 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1450 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1453 /* insert separator button into 'available buttons' list */
1454 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1455 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1456 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1457 btnInfo->bVirtual = FALSE;
1458 btnInfo->bRemovable = TRUE;
1459 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1460 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1461 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1463 /* insert all buttons into dsa */
1466 /* send TBN_GETBUTTONINFO notification */
1468 nmtb.pszText = Buffer;
1471 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1474 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1476 /* insert button into the apropriate list */
1477 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand);
1480 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1481 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1482 btnInfo->bVirtual = FALSE;
1483 btnInfo->bRemovable = TRUE;
1484 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1485 strcpy (btnInfo->text, nmtb.pszText);
1487 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1488 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1492 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1493 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1494 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1495 strcpy (btnInfo->text, nmtb.pszText);
1497 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1501 /* select first item in the 'available' list */
1502 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1504 /* append 'virtual' separator button to the 'toolbar buttons' list */
1505 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1506 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1507 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1508 btnInfo->bVirtual = TRUE;
1509 btnInfo->bRemovable = FALSE;
1510 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1511 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1512 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1514 /* select last item in the 'toolbar' list */
1515 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1516 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1518 /* set focus and disable buttons */
1519 PostMessageA (hwnd, WM_USER, 0, 0);
1524 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1525 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1526 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1527 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1531 EndDialog(hwnd, FALSE);
1535 switch (LOWORD(wParam))
1537 case IDC_TOOLBARBTN_LBOX:
1538 if (HIWORD(wParam) == LBN_SELCHANGE)
1540 PCUSTOMBUTTON btnInfo;
1545 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1546 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1548 /* send TBN_QUERYINSERT notification */
1550 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1553 /* get list box item */
1554 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1556 if (index == (count - 1))
1558 /* last item (virtual separator) */
1559 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1560 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1562 else if (index == (count - 2))
1564 /* second last item (last non-virtual item) */
1565 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1566 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1568 else if (index == 0)
1571 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1572 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1576 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1577 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1580 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1584 case IDC_MOVEUP_BTN:
1586 PCUSTOMBUTTON btnInfo;
1590 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1591 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1592 TRACE("Move up: index %d\n", index);
1594 /* send TBN_QUERYINSERT notification */
1597 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1600 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1602 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1603 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1604 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1605 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1608 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1609 else if (index >= (count - 3))
1610 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1612 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1613 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1618 case IDC_MOVEDN_BTN: /* move down */
1620 PCUSTOMBUTTON btnInfo;
1624 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1625 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1626 TRACE("Move up: index %d\n", index);
1628 /* send TBN_QUERYINSERT notification */
1630 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1633 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1635 /* move button down */
1636 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1637 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1638 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1639 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1642 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1643 else if (index >= (count - 3))
1644 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1646 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1647 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1652 case IDC_REMOVE_BTN: /* remove button */
1654 PCUSTOMBUTTON btnInfo;
1657 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1658 TRACE("Remove: index %d\n", index);
1660 /* send TBN_QUERYDELETE notification */
1662 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1665 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1666 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1667 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1669 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1671 /* insert into 'available button' list */
1672 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1674 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1675 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1678 COMCTL32_Free (btnInfo);
1683 case IDOK: /* Add button */
1688 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1689 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1690 TRACE("Add: index %d\n", index);
1692 /* send TBN_QUERYINSERT notification */
1694 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1697 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1701 /* remove from 'available buttons' list */
1702 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1703 if (index == count-1)
1704 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1706 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1710 PCUSTOMBUTTON btnNew;
1712 /* duplicate 'separator' button */
1713 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1714 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1718 /* insert into 'toolbar button' list */
1719 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1720 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1721 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1723 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1729 EndDialog(hwnd, FALSE);
1739 /* delete items from 'toolbar buttons' listbox*/
1740 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1741 for (i = 0; i < count; i++)
1743 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1744 COMCTL32_Free(btnInfo);
1745 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1747 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1750 /* delete items from 'available buttons' listbox*/
1751 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1752 for (i = 0; i < count; i++)
1754 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1755 COMCTL32_Free(btnInfo);
1756 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1758 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1763 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1765 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1770 COLORREF oldText = 0;
1774 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1775 if (btnInfo == NULL)
1777 FIXME("btnInfo invalid!\n");
1781 /* set colors and select objects */
1782 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1783 if (btnInfo->bVirtual)
1784 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
1786 oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
1787 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1788 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1790 /* fill background rectangle */
1791 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
1792 lpdis->rcItem.right, lpdis->rcItem.bottom);
1794 /* calculate button and text rectangles */
1795 CopyRect (&rcButton, &lpdis->rcItem);
1796 InflateRect (&rcButton, -1, -1);
1797 CopyRect (&rcText, &rcButton);
1798 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
1799 rcText.left = rcButton.right + 2;
1801 /* draw focus rectangle */
1802 if (lpdis->itemState & ODS_FOCUS)
1803 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1806 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
1808 /* draw image and text */
1809 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
1810 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
1811 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
1812 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
1813 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1815 /* delete objects and reset colors */
1816 SelectObject (lpdis->hDC, hOldBrush);
1817 SelectObject (lpdis->hDC, hOldPen);
1818 SetBkColor (lpdis->hDC, oldBk);
1819 SetTextColor (lpdis->hDC, oldText);
1825 case WM_MEASUREITEM:
1826 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1828 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1830 if (custInfo && custInfo->tbInfo)
1831 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
1833 lpmis->itemHeight = 15 + 8; /* default height */
1845 /***********************************************************************
1846 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1850 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1853 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1854 INT nIndex = 0, nButtons, nCount;
1857 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1861 if (lpAddBmp->hInst == HINST_COMMCTRL)
1863 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1865 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1867 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1872 TRACE ("adding %d internal bitmaps!\n", nButtons);
1874 /* Windows resize all the buttons to the size of a newly added standard image */
1875 if (lpAddBmp->nID & 1)
1878 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
1879 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
1881 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1882 MAKELPARAM((WORD)24, (WORD)24));
1883 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1884 MAKELPARAM((WORD)31, (WORD)30));
1889 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1890 MAKELPARAM((WORD)16, (WORD)16));
1891 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1892 MAKELPARAM((WORD)22, (WORD)22));
1895 TOOLBAR_CalcToolbar (hwnd);
1899 nButtons = (INT)wParam;
1903 TRACE ("adding %d bitmaps!\n", nButtons);
1906 if (!(infoPtr->himlDef)) {
1907 /* create new default image list */
1908 TRACE ("creating default image list!\n");
1911 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1912 ILC_COLOR | ILC_MASK, nButtons, 2);
1913 infoPtr->himlInt = infoPtr->himlDef;
1916 nCount = ImageList_GetImageCount(infoPtr->himlDef);
1918 /* Add bitmaps to the default image list */
1919 if (lpAddBmp->hInst == (HINSTANCE)0)
1922 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1925 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1927 /* Add system bitmaps */
1928 switch (lpAddBmp->nID)
1930 case IDB_STD_SMALL_COLOR:
1931 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1932 MAKEINTRESOURCEA(IDB_STD_SMALL));
1933 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1934 hbmLoad, CLR_DEFAULT);
1935 DeleteObject (hbmLoad);
1938 case IDB_STD_LARGE_COLOR:
1939 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1940 MAKEINTRESOURCEA(IDB_STD_LARGE));
1941 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1942 hbmLoad, CLR_DEFAULT);
1943 DeleteObject (hbmLoad);
1946 case IDB_VIEW_SMALL_COLOR:
1947 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1948 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1949 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1950 hbmLoad, CLR_DEFAULT);
1951 DeleteObject (hbmLoad);
1954 case IDB_VIEW_LARGE_COLOR:
1955 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1956 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1957 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1958 hbmLoad, CLR_DEFAULT);
1959 DeleteObject (hbmLoad);
1962 case IDB_HIST_SMALL_COLOR:
1963 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1964 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1965 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1966 hbmLoad, CLR_DEFAULT);
1967 DeleteObject (hbmLoad);
1970 case IDB_HIST_LARGE_COLOR:
1971 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1972 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1973 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1974 hbmLoad, CLR_DEFAULT);
1975 DeleteObject (hbmLoad);
1979 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1980 ERR ("invalid imagelist!\n");
1986 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1987 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1988 DeleteObject (hbmLoad);
1993 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
1995 if (infoPtr->nNumBitmaps + nButtons != imagecount)
1997 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",
1998 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
1999 infoPtr->nNumBitmaps+nButtons,imagecount);
2001 infoPtr->nNumBitmaps = imagecount;
2004 infoPtr->nNumBitmaps += nButtons;
2007 InvalidateRect(hwnd, NULL, FALSE);
2014 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2016 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2017 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2018 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2020 TRACE("adding %d buttons!\n", wParam);
2022 nAddButtons = (UINT)wParam;
2023 nOldButtons = infoPtr->nNumButtons;
2024 nNewButtons = nOldButtons + nAddButtons;
2026 if (infoPtr->nNumButtons == 0) {
2028 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2031 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2033 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2034 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2035 nOldButtons * sizeof(TBUTTON_INFO));
2036 COMCTL32_Free (oldButtons);
2039 infoPtr->nNumButtons = nNewButtons;
2041 /* insert new button data */
2042 for (nCount = 0; nCount < nAddButtons; nCount++) {
2043 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2044 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2045 btnPtr->idCommand = lpTbb[nCount].idCommand;
2046 btnPtr->fsState = lpTbb[nCount].fsState;
2047 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2048 btnPtr->dwData = lpTbb[nCount].dwData;
2049 btnPtr->iString = lpTbb[nCount].iString;
2050 btnPtr->bHot = FALSE;
2052 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2055 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2056 ti.cbSize = sizeof (TTTOOLINFOA);
2058 ti.uId = btnPtr->idCommand;
2060 ti.lpszText = LPSTR_TEXTCALLBACKA;
2062 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2067 TOOLBAR_CalcToolbar (hwnd);
2069 InvalidateRect(hwnd, NULL, FALSE);
2076 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2079 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2080 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2082 TRACE("adding %d buttons!\n", wParam);
2084 nAddButtons = (UINT)wParam;
2085 nOldButtons = infoPtr->nNumButtons;
2086 nNewButtons = nOldButtons + nAddButtons;
2088 if (infoPtr->nNumButtons == 0) {
2090 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2093 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2095 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2096 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2097 nOldButtons * sizeof(TBUTTON_INFO));
2098 COMCTL32_Free (oldButtons);
2101 infoPtr->nNumButtons = nNewButtons;
2103 /* insert new button data */
2104 for (nCount = 0; nCount < nAddButtons; nCount++) {
2105 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2106 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2107 btnPtr->idCommand = lpTbb[nCount].idCommand;
2108 btnPtr->fsState = lpTbb[nCount].fsState;
2109 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2110 btnPtr->dwData = lpTbb[nCount].dwData;
2111 btnPtr->iString = lpTbb[nCount].iString;
2112 btnPtr->bHot = FALSE;
2114 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2117 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2118 ti.cbSize = sizeof (TTTOOLINFOW);
2120 ti.uId = btnPtr->idCommand;
2122 ti.lpszText = LPSTR_TEXTCALLBACKW;
2124 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2129 TOOLBAR_CalcToolbar (hwnd);
2131 InvalidateRect(hwnd, NULL, FALSE);
2138 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2143 if ((wParam) && (HIWORD(lParam) == 0)) {
2146 TRACE("adding string from resource!\n");
2148 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2151 TRACE("len=%d \"%s\"\n", len, szString);
2152 nIndex = infoPtr->nNumStrings;
2153 if (infoPtr->nNumStrings == 0) {
2155 COMCTL32_Alloc (sizeof(LPWSTR));
2158 LPWSTR *oldStrings = infoPtr->strings;
2160 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2161 memcpy (&infoPtr->strings[0], &oldStrings[0],
2162 sizeof(LPWSTR) * infoPtr->nNumStrings);
2163 COMCTL32_Free (oldStrings);
2166 lenW = MultiByteToWideChar( CP_ACP, 0, szString, -1, NULL, 0 );
2167 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2168 MultiByteToWideChar( CP_ACP, 0, szString, -1,
2169 infoPtr->strings[infoPtr->nNumStrings], lenW );
2170 infoPtr->nNumStrings++;
2173 LPSTR p = (LPSTR)lParam;
2178 TRACE("adding string(s) from array!\n");
2180 nIndex = infoPtr->nNumStrings;
2183 TRACE("len=%d \"%s\"\n", len, p);
2185 if (infoPtr->nNumStrings == 0) {
2187 COMCTL32_Alloc (sizeof(LPWSTR));
2190 LPWSTR *oldStrings = infoPtr->strings;
2192 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2193 memcpy (&infoPtr->strings[0], &oldStrings[0],
2194 sizeof(LPWSTR) * infoPtr->nNumStrings);
2195 COMCTL32_Free (oldStrings);
2198 lenW = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
2199 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
2200 MultiByteToWideChar( CP_ACP, 0, p, -1,
2201 infoPtr->strings[infoPtr->nNumStrings], lenW );
2202 infoPtr->nNumStrings++;
2213 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2215 #define MAX_RESOURCE_STRING_LENGTH 512
2216 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2219 if ((wParam) && (HIWORD(lParam) == 0)) {
2220 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2222 TRACE("adding string from resource!\n");
2224 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2225 szString, MAX_RESOURCE_STRING_LENGTH);
2227 TRACE("len=%d %s\n", len, debugstr_w(szString));
2228 TRACE("First char: 0x%x\n", *szString);
2229 if (szString[0] == L'|')
2231 PWSTR p = szString + 1;
2233 nIndex = infoPtr->nNumStrings;
2234 while (*p != L'|') {
2236 if (infoPtr->nNumStrings == 0) {
2238 COMCTL32_Alloc (sizeof(LPWSTR));
2241 LPWSTR *oldStrings = infoPtr->strings;
2243 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2244 memcpy (&infoPtr->strings[0], &oldStrings[0],
2245 sizeof(LPWSTR) * infoPtr->nNumStrings);
2246 COMCTL32_Free (oldStrings);
2249 len = COMCTL32_StrChrW (p, L'|') - p;
2250 TRACE("len=%d %s\n", len, debugstr_w(p));
2251 infoPtr->strings[infoPtr->nNumStrings] =
2252 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2253 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
2254 infoPtr->nNumStrings++;
2261 nIndex = infoPtr->nNumStrings;
2262 if (infoPtr->nNumStrings == 0) {
2264 COMCTL32_Alloc (sizeof(LPWSTR));
2267 LPWSTR *oldStrings = infoPtr->strings;
2269 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2270 memcpy (&infoPtr->strings[0], &oldStrings[0],
2271 sizeof(LPWSTR) * infoPtr->nNumStrings);
2272 COMCTL32_Free (oldStrings);
2275 infoPtr->strings[infoPtr->nNumStrings] =
2276 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2277 strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
2278 infoPtr->nNumStrings++;
2282 LPWSTR p = (LPWSTR)lParam;
2287 TRACE("adding string(s) from array!\n");
2288 nIndex = infoPtr->nNumStrings;
2292 TRACE("len=%d %s\n", len, debugstr_w(p));
2293 if (infoPtr->nNumStrings == 0) {
2295 COMCTL32_Alloc (sizeof(LPWSTR));
2298 LPWSTR *oldStrings = infoPtr->strings;
2300 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2301 memcpy (&infoPtr->strings[0], &oldStrings[0],
2302 sizeof(LPWSTR) * infoPtr->nNumStrings);
2303 COMCTL32_Free (oldStrings);
2306 infoPtr->strings[infoPtr->nNumStrings] =
2307 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2308 strcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
2309 infoPtr->nNumStrings++;
2320 TOOLBAR_AutoSize (HWND hwnd)
2322 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2323 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2329 UINT uPosFlags = SWP_NOZORDER;
2331 TRACE("resize forced, style=%lx!\n", dwStyle);
2333 parent = GetParent (hwnd);
2334 GetClientRect(parent, &parent_rect);
2336 x = parent_rect.left;
2337 y = parent_rect.top;
2339 /* FIXME: we should be able to early out if nothing */
2340 /* has changed with nWidth != parent_rect width */
2342 if (dwStyle & CCS_NORESIZE) {
2343 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2348 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2349 TOOLBAR_CalcToolbar (hwnd);
2350 InvalidateRect( hwnd, NULL, TRUE );
2351 cy = infoPtr->nHeight;
2352 cx = infoPtr->nWidth;
2354 if (dwStyle & CCS_NOMOVEY) {
2355 GetWindowRect(hwnd, &window_rect);
2356 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2357 y = window_rect.top;
2361 if (dwStyle & CCS_NOPARENTALIGN)
2362 uPosFlags |= SWP_NOMOVE;
2364 if (!(dwStyle & CCS_NODIVIDER))
2365 cy += GetSystemMetrics(SM_CYEDGE);
2367 if (dwStyle & WS_BORDER)
2370 cy += GetSystemMetrics(SM_CYEDGE);
2371 cx += GetSystemMetrics(SM_CYEDGE);
2374 infoPtr->bAutoSize = TRUE;
2375 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2377 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2378 * the setwindowpos calls */
2379 infoPtr->bAutoSize = FALSE;
2386 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2390 return infoPtr->nNumButtons;
2395 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2399 if (infoPtr == NULL) {
2400 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2401 ERR("infoPtr == NULL!\n");
2405 infoPtr->dwStructSize = (DWORD)wParam;
2412 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2415 TBUTTON_INFO *btnPtr;
2418 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2422 btnPtr = &infoPtr->buttons[nIndex];
2423 btnPtr->iBitmap = LOWORD(lParam);
2425 /* we HAVE to erase the background, the new bitmap could be */
2427 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2434 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2436 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2437 TBUTTON_INFO *btnPtr;
2440 BOOL bChecked = FALSE;
2442 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2446 btnPtr = &infoPtr->buttons[nIndex];
2448 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2451 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2453 if (LOWORD(lParam) == FALSE)
2454 btnPtr->fsState &= ~TBSTATE_CHECKED;
2456 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2458 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2459 if (nOldIndex == nIndex)
2461 if (nOldIndex != -1)
2462 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2464 btnPtr->fsState |= TBSTATE_CHECKED;
2467 if( bChecked != LOWORD(lParam) )
2469 if (nOldIndex != -1)
2471 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2472 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2474 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2477 /* FIXME: Send a WM_NOTIFY?? */
2484 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2486 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2488 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2493 TOOLBAR_Customize (HWND hwnd)
2495 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2496 CUSTDLG_INFO custInfo;
2502 custInfo.tbInfo = infoPtr;
2503 custInfo.tbHwnd = hwnd;
2505 /* send TBN_BEGINADJUST notification */
2506 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2509 if (!(hRes = FindResourceA (COMCTL32_hModule,
2510 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2514 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2517 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2518 (LPDLGTEMPLATEA)template,
2520 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2523 /* send TBN_ENDADJUST notification */
2524 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2532 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2534 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2535 INT nIndex = (INT)wParam;
2537 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2540 if ((infoPtr->hwndToolTip) &&
2541 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2544 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2545 ti.cbSize = sizeof (TTTOOLINFOA);
2547 ti.uId = infoPtr->buttons[nIndex].idCommand;
2549 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2552 if (infoPtr->nNumButtons == 1) {
2553 TRACE(" simple delete!\n");
2554 COMCTL32_Free (infoPtr->buttons);
2555 infoPtr->buttons = NULL;
2556 infoPtr->nNumButtons = 0;
2559 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2560 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2562 infoPtr->nNumButtons--;
2563 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2565 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2566 nIndex * sizeof(TBUTTON_INFO));
2569 if (nIndex < infoPtr->nNumButtons) {
2570 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2571 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2574 COMCTL32_Free (oldButtons);
2577 TOOLBAR_CalcToolbar (hwnd);
2579 InvalidateRect (hwnd, NULL, TRUE);
2586 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2589 TBUTTON_INFO *btnPtr;
2593 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2597 btnPtr = &infoPtr->buttons[nIndex];
2599 bState = btnPtr->fsState & TBSTATE_ENABLED;
2601 /* update the toolbar button state */
2602 if(LOWORD(lParam) == FALSE) {
2603 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2605 btnPtr->fsState |= TBSTATE_ENABLED;
2608 /* redraw the button only if the state of the button changed */
2609 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2611 InvalidateRect(hwnd, &btnPtr->rect,
2612 TOOLBAR_HasText(infoPtr, btnPtr));
2619 static inline LRESULT
2620 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2622 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2624 return infoPtr->bAnchor;
2629 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2631 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2634 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2638 return infoPtr->buttons[nIndex].iBitmap;
2642 static inline LRESULT
2643 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2645 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2650 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2652 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2653 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2654 INT nIndex = (INT)wParam;
2655 TBUTTON_INFO *btnPtr;
2657 if (infoPtr == NULL)
2663 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2666 btnPtr = &infoPtr->buttons[nIndex];
2667 lpTbb->iBitmap = btnPtr->iBitmap;
2668 lpTbb->idCommand = btnPtr->idCommand;
2669 lpTbb->fsState = btnPtr->fsState;
2670 lpTbb->fsStyle = btnPtr->fsStyle;
2671 lpTbb->dwData = btnPtr->dwData;
2672 lpTbb->iString = btnPtr->iString;
2679 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2682 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2683 TBUTTON_INFO *btnPtr;
2686 if (infoPtr == NULL)
2688 if (lpTbInfo == NULL)
2690 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2693 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2697 btnPtr = &infoPtr->buttons[nIndex];
2699 if (lpTbInfo->dwMask & TBIF_COMMAND)
2700 lpTbInfo->idCommand = btnPtr->idCommand;
2701 if (lpTbInfo->dwMask & TBIF_IMAGE)
2702 lpTbInfo->iImage = btnPtr->iBitmap;
2703 if (lpTbInfo->dwMask & TBIF_LPARAM)
2704 lpTbInfo->lParam = btnPtr->dwData;
2705 if (lpTbInfo->dwMask & TBIF_SIZE)
2706 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2707 if (lpTbInfo->dwMask & TBIF_STATE)
2708 lpTbInfo->fsState = btnPtr->fsState;
2709 if (lpTbInfo->dwMask & TBIF_STYLE)
2710 lpTbInfo->fsStyle = btnPtr->fsStyle;
2711 if (lpTbInfo->dwMask & TBIF_TEXT) {
2712 if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
2714 if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[btnPtr->iString], -1,
2715 lpTbInfo->pszText, lpTbInfo->cchText, NULL, NULL ))
2716 lpTbInfo->pszText[lpTbInfo->cchText-1] = 0;
2718 else lpTbInfo->pszText[0]=0;
2725 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2727 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2728 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2729 TBUTTON_INFO *btnPtr;
2732 if (infoPtr == NULL)
2734 if (lpTbInfo == NULL)
2736 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2739 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2743 btnPtr = &infoPtr->buttons[nIndex];
2745 if (lpTbInfo->dwMask & TBIF_COMMAND)
2746 lpTbInfo->idCommand = btnPtr->idCommand;
2747 if (lpTbInfo->dwMask & TBIF_IMAGE)
2748 lpTbInfo->iImage = btnPtr->iBitmap;
2749 if (lpTbInfo->dwMask & TBIF_LPARAM)
2750 lpTbInfo->lParam = btnPtr->dwData;
2751 if (lpTbInfo->dwMask & TBIF_SIZE)
2752 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2753 if (lpTbInfo->dwMask & TBIF_STATE)
2754 lpTbInfo->fsState = btnPtr->fsState;
2755 if (lpTbInfo->dwMask & TBIF_STYLE)
2756 lpTbInfo->fsStyle = btnPtr->fsStyle;
2757 if (lpTbInfo->dwMask & TBIF_TEXT) {
2758 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2759 lstrcpynW (lpTbInfo->pszText,
2760 (LPWSTR)infoPtr->strings[btnPtr->iString],
2769 TOOLBAR_GetButtonSize (HWND hwnd)
2771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2773 if (infoPtr->nNumButtons > 0)
2774 return MAKELONG((WORD)infoPtr->nButtonWidth,
2775 (WORD)infoPtr->nButtonHeight);
2777 return MAKELONG(8,7);
2782 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2784 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2785 INT nIndex, nStringIndex;
2787 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2791 nStringIndex = infoPtr->buttons[nIndex].iString;
2793 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2795 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2801 return WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[nStringIndex], -1,
2802 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
2807 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2810 INT nIndex, nStringIndex;
2812 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2816 nStringIndex = infoPtr->buttons[nIndex].iString;
2818 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2820 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2826 strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
2828 return strlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
2832 /* << TOOLBAR_GetColorScheme >> */
2836 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2840 return (LRESULT)infoPtr->himlDis;
2844 inline static LRESULT
2845 TOOLBAR_GetExtendedStyle (HWND hwnd)
2847 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2849 return infoPtr->dwExStyle;
2854 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2856 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2858 return (LRESULT)infoPtr->himlHot;
2863 TOOLBAR_GetHotItem (HWND hwnd)
2865 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2867 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
2870 if (infoPtr->nHotItem < 0)
2873 return (LRESULT)infoPtr->nHotItem;
2878 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2880 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2882 return (LRESULT)infoPtr->himlDef;
2886 /* << TOOLBAR_GetInsertMark >> */
2887 /* << TOOLBAR_GetInsertMarkColor >> */
2891 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2894 TBUTTON_INFO *btnPtr;
2898 if (infoPtr == NULL)
2900 nIndex = (INT)wParam;
2901 btnPtr = &infoPtr->buttons[nIndex];
2902 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2904 lpRect = (LPRECT)lParam;
2907 if (btnPtr->fsState & TBSTATE_HIDDEN)
2910 lpRect->left = btnPtr->rect.left;
2911 lpRect->right = btnPtr->rect.right;
2912 lpRect->bottom = btnPtr->rect.bottom;
2913 lpRect->top = btnPtr->rect.top;
2920 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2923 LPSIZE lpSize = (LPSIZE)lParam;
2928 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2929 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2931 TRACE("maximum size %d x %d\n",
2932 infoPtr->rcBound.right - infoPtr->rcBound.left,
2933 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2939 /* << TOOLBAR_GetObject >> */
2940 /* << TOOLBAR_GetPadding >> */
2944 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2947 TBUTTON_INFO *btnPtr;
2951 if (infoPtr == NULL)
2953 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2954 btnPtr = &infoPtr->buttons[nIndex];
2955 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2957 lpRect = (LPRECT)lParam;
2961 lpRect->left = btnPtr->rect.left;
2962 lpRect->right = btnPtr->rect.right;
2963 lpRect->bottom = btnPtr->rect.bottom;
2964 lpRect->top = btnPtr->rect.top;
2971 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2973 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2975 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2976 return infoPtr->nRows;
2983 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2985 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2988 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2992 return infoPtr->buttons[nIndex].fsState;
2997 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3002 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3006 return infoPtr->buttons[nIndex].fsStyle;
3011 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3013 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3015 if (infoPtr == NULL)
3018 return infoPtr->nMaxTextRows;
3023 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3027 if (infoPtr == NULL)
3029 return infoPtr->hwndToolTip;
3034 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3036 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3038 TRACE("%s hwnd=0x%x stub!\n",
3039 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3041 return infoPtr->bUnicode;
3045 inline static LRESULT
3046 TOOLBAR_GetVersion (HWND hwnd)
3048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3049 return infoPtr->iVersion;
3054 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3057 TBUTTON_INFO *btnPtr;
3062 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3066 btnPtr = &infoPtr->buttons[nIndex];
3067 if (LOWORD(lParam) == FALSE)
3068 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3070 btnPtr->fsState |= TBSTATE_HIDDEN;
3072 TOOLBAR_CalcToolbar (hwnd);
3074 InvalidateRect (hwnd, NULL, TRUE);
3080 inline static LRESULT
3081 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3083 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3088 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3091 TBUTTON_INFO *btnPtr;
3094 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3098 btnPtr = &infoPtr->buttons[nIndex];
3099 if (LOWORD(lParam) == FALSE)
3100 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3102 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3104 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3111 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3114 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3115 INT nIndex = (INT)wParam;
3116 TBUTTON_INFO *oldButtons;
3121 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3124 /* EPP: this seems to be an undocumented call (from my IE4)
3125 * I assume in that case that:
3126 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3127 * - index of insertion is at the end of existing buttons
3128 * I only see this happen with nIndex == -1, but it could have a special
3129 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3134 /* FIXME: iString == -1 is undocumented */
3135 if(lpTbb->iString && lpTbb->iString!=-1) {
3136 len = strlen((char*)lpTbb->iString) + 2;
3137 ptr = COMCTL32_Alloc(len);
3138 nIndex = infoPtr->nNumButtons;
3139 strcpy(ptr, (char*)lpTbb->iString);
3140 ptr[len - 1] = 0; /* ended by two '\0' */
3141 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3145 ERR("lpTbb->iString is NULL\n");
3149 } else if (nIndex < 0)
3152 TRACE("inserting button index=%d\n", nIndex);
3153 if (nIndex > infoPtr->nNumButtons) {
3154 nIndex = infoPtr->nNumButtons;
3155 TRACE("adjust index=%d\n", nIndex);
3158 oldButtons = infoPtr->buttons;
3159 infoPtr->nNumButtons++;
3160 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3161 /* pre insert copy */
3163 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3164 nIndex * sizeof(TBUTTON_INFO));
3167 /* insert new button */
3168 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3169 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3170 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3171 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3172 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3173 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3175 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3178 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3179 ti.cbSize = sizeof (TTTOOLINFOA);
3181 ti.uId = lpTbb->idCommand;
3183 ti.lpszText = LPSTR_TEXTCALLBACKA;
3185 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3189 /* post insert copy */
3190 if (nIndex < infoPtr->nNumButtons - 1) {
3191 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3192 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3195 COMCTL32_Free (oldButtons);
3197 TOOLBAR_CalcToolbar (hwnd);
3199 InvalidateRect (hwnd, NULL, FALSE);
3206 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3209 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3210 INT nIndex = (INT)wParam;
3211 TBUTTON_INFO *oldButtons;
3218 TRACE("inserting button index=%d\n", nIndex);
3219 if (nIndex > infoPtr->nNumButtons) {
3220 nIndex = infoPtr->nNumButtons;
3221 TRACE("adjust index=%d\n", nIndex);
3224 oldButtons = infoPtr->buttons;
3225 infoPtr->nNumButtons++;
3226 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3227 /* pre insert copy */
3229 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3230 nIndex * sizeof(TBUTTON_INFO));
3233 /* insert new button */
3234 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3235 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3236 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3237 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3238 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3239 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3241 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3244 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3245 ti.cbSize = sizeof (TTTOOLINFOW);
3247 ti.uId = lpTbb->idCommand;
3249 ti.lpszText = LPSTR_TEXTCALLBACKW;
3251 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3255 /* post insert copy */
3256 if (nIndex < infoPtr->nNumButtons - 1) {
3257 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3258 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3261 COMCTL32_Free (oldButtons);
3263 InvalidateRect (hwnd, NULL, FALSE);
3269 /* << TOOLBAR_InsertMarkHitTest >> */
3273 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3278 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3282 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3287 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3292 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3296 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3301 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3303 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3306 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3310 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3315 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3317 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3320 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3324 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3329 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3331 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3334 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3338 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3343 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3345 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3348 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3352 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3356 /* << TOOLBAR_LoadImages >> */
3357 /* << TOOLBAR_MapAccelerator >> */
3358 /* << TOOLBAR_MarkButton >> */
3359 /* << TOOLBAR_MoveButton >> */
3363 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3366 TBUTTON_INFO *btnPtr;
3369 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3373 btnPtr = &infoPtr->buttons[nIndex];
3374 if (LOWORD(lParam) == FALSE)
3375 btnPtr->fsState &= ~TBSTATE_PRESSED;
3377 btnPtr->fsState |= TBSTATE_PRESSED;
3379 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3385 /* << TOOLBAR_ReplaceBitmap >> */
3389 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3393 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3395 if (lpSave == NULL) return 0;
3398 /* save toolbar information */
3399 FIXME("save to \"%s\" \"%s\"\n",
3400 lpSave->pszSubKey, lpSave->pszValueName);
3405 /* restore toolbar information */
3407 FIXME("restore from \"%s\" \"%s\"\n",
3408 lpSave->pszSubKey, lpSave->pszValueName);
3419 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3423 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3429 /* save toolbar information */
3430 FIXME("save to \"%s\" \"%s\"\n",
3431 lpSave->pszSubKey, lpSave->pszValueName);
3436 /* restore toolbar information */
3438 FIXME("restore from \"%s\" \"%s\"\n",
3439 lpSave->pszSubKey, lpSave->pszValueName);
3450 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3452 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3453 BOOL bOldAnchor = infoPtr->bAnchor;
3455 infoPtr->bAnchor = (BOOL)wParam;
3457 return (LRESULT)bOldAnchor;
3462 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3466 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3469 if (infoPtr->nNumButtons > 0)
3470 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3471 infoPtr->nNumButtons,
3472 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3473 LOWORD(lParam), HIWORD(lParam));
3475 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3476 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3478 /* uses image list internals directly */
3479 if (infoPtr->himlDef) {
3480 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3481 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3489 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3491 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3492 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3493 TBUTTON_INFO *btnPtr;
3498 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3501 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3505 btnPtr = &infoPtr->buttons[nIndex];
3506 if (lptbbi->dwMask & TBIF_COMMAND)
3507 btnPtr->idCommand = lptbbi->idCommand;
3508 if (lptbbi->dwMask & TBIF_IMAGE)
3509 btnPtr->iBitmap = lptbbi->iImage;
3510 if (lptbbi->dwMask & TBIF_LPARAM)
3511 btnPtr->dwData = lptbbi->lParam;
3512 /* if (lptbbi->dwMask & TBIF_SIZE) */
3513 /* btnPtr->cx = lptbbi->cx; */
3514 if (lptbbi->dwMask & TBIF_STATE)
3515 btnPtr->fsState = lptbbi->fsState;
3516 if (lptbbi->dwMask & TBIF_STYLE)
3517 btnPtr->fsStyle = lptbbi->fsStyle;
3519 if (lptbbi->dwMask & TBIF_TEXT) {
3520 if ((btnPtr->iString >= 0) ||
3521 (btnPtr->iString < infoPtr->nNumStrings)) {
3522 TRACE("Ooooooch\n");
3524 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3525 INT len = lstrlenA (lptbbi->pszText);
3526 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3529 /* this is the ultimate sollution */
3530 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3539 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3541 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3542 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3543 TBUTTON_INFO *btnPtr;
3548 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3551 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3555 btnPtr = &infoPtr->buttons[nIndex];
3556 if (lptbbi->dwMask & TBIF_COMMAND)
3557 btnPtr->idCommand = lptbbi->idCommand;
3558 if (lptbbi->dwMask & TBIF_IMAGE)
3559 btnPtr->iBitmap = lptbbi->iImage;
3560 if (lptbbi->dwMask & TBIF_LPARAM)
3561 btnPtr->dwData = lptbbi->lParam;
3562 /* if (lptbbi->dwMask & TBIF_SIZE) */
3563 /* btnPtr->cx = lptbbi->cx; */
3564 if (lptbbi->dwMask & TBIF_STATE)
3565 btnPtr->fsState = lptbbi->fsState;
3566 if (lptbbi->dwMask & TBIF_STYLE)
3567 btnPtr->fsStyle = lptbbi->fsStyle;
3569 if (lptbbi->dwMask & TBIF_TEXT) {
3570 if ((btnPtr->iString >= 0) ||
3571 (btnPtr->iString < infoPtr->nNumStrings)) {
3573 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3574 INT len = lstrlenW (lptbbi->pszText);
3575 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3578 /* this is the ultimate solution */
3579 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3588 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3590 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3592 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3594 ERR("invalid parameter\n");
3598 /* The documentation claims you can only change the button size before
3599 * any button has been added. But this is wrong.
3600 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3601 * it to the toolbar, and it checks that the return value is nonzero - mjm
3602 * Further testing shows that we must actually perform the change too.
3604 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3605 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3611 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3615 if (infoPtr == NULL) {
3616 TRACE("Toolbar not initialized yet?????\n");
3620 /* if setting to current values, ignore */
3621 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3622 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3623 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3624 infoPtr->cxMin, infoPtr->cxMax);
3628 /* save new values */
3629 infoPtr->cxMin = (INT)LOWORD(lParam);
3630 infoPtr->cxMax = (INT)HIWORD(lParam);
3632 /* if both values are 0 then we are done */
3634 TRACE("setting both min and max to 0, norecalc\n");
3638 /* otherwise we need to recalc the toolbar and in some cases
3639 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3640 which doesn't actually draw - GA). */
3641 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3642 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3644 TOOLBAR_CalcToolbar (hwnd);
3646 InvalidateRect (hwnd, NULL, TRUE);
3653 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3655 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3656 INT nIndex = (INT)wParam;
3658 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3661 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3663 if (infoPtr->hwndToolTip) {
3665 FIXME("change tool tip!\n");
3673 /* << TOOLBAR_SetColorScheme >> */
3677 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3680 HIMAGELIST himlTemp;
3683 himlTemp = infoPtr->himlDis;
3684 infoPtr->himlDis = (HIMAGELIST)lParam;
3686 /* FIXME: redraw ? */
3688 return (LRESULT)himlTemp;
3693 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3695 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3698 dwTemp = infoPtr->dwDTFlags;
3699 infoPtr->dwDTFlags =
3700 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3702 return (LRESULT)dwTemp;
3707 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3709 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3712 dwTemp = infoPtr->dwExStyle;
3713 infoPtr->dwExStyle = (DWORD)lParam;
3715 return (LRESULT)dwTemp;
3720 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3723 HIMAGELIST himlTemp;
3725 himlTemp = infoPtr->himlHot;
3726 infoPtr->himlHot = (HIMAGELIST)lParam;
3728 /* FIXME: redraw ? */
3730 return (LRESULT)himlTemp;
3735 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
3737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3738 INT nOldHotItem = infoPtr->nHotItem;
3739 TBUTTON_INFO *btnPtr;
3741 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
3744 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
3747 infoPtr->nHotItem = (INT)wParam;
3748 if ((INT)wParam >=0)
3750 btnPtr = &infoPtr->buttons[(INT)wParam];
3751 btnPtr->bHot = TRUE;
3752 InvalidateRect (hwnd, &btnPtr->rect,
3753 TOOLBAR_HasText(infoPtr, btnPtr));
3757 btnPtr = &infoPtr->buttons[nOldHotItem];
3758 btnPtr->bHot = FALSE;
3759 InvalidateRect (hwnd, &btnPtr->rect,
3760 TOOLBAR_HasText(infoPtr, btnPtr));
3764 if (nOldHotItem < 0)
3767 return (LRESULT)nOldHotItem;
3772 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3774 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3775 HIMAGELIST himlTemp;
3777 himlTemp = infoPtr->himlDef;
3778 infoPtr->himlDef = (HIMAGELIST)lParam;
3780 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
3782 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
3783 &infoPtr->nBitmapHeight);
3784 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
3785 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
3786 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
3788 /* FIXME: redraw ? */
3790 return (LRESULT)himlTemp;
3795 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3799 infoPtr->nIndent = (INT)wParam;
3803 /* process only on indent changing */
3804 if(infoPtr->nIndent != (INT)wParam)
3806 infoPtr->nIndent = (INT)wParam;
3807 TOOLBAR_CalcToolbar (hwnd);
3808 InvalidateRect(hwnd, NULL, FALSE);
3815 /* << TOOLBAR_SetInsertMark >> */
3819 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3821 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3823 infoPtr->clrInsertMark = (COLORREF)lParam;
3825 /* FIXME : redraw ??*/
3832 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3834 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3836 if (infoPtr == NULL)
3839 infoPtr->nMaxTextRows = (INT)wParam;
3845 /* << TOOLBAR_SetPadding >> */
3849 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3851 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3856 if (infoPtr == NULL)
3858 hwndOldNotify = infoPtr->hwndNotify;
3859 infoPtr->hwndNotify = (HWND)wParam;
3861 return hwndOldNotify;
3866 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 LPRECT lprc = (LPRECT)lParam;
3873 if (LOWORD(wParam) > 1) {
3874 FIXME("multiple rows not supported!\n");
3877 if(infoPtr->nRows != LOWORD(wParam))
3879 infoPtr->nRows = LOWORD(wParam);
3881 /* recalculate toolbar */
3882 TOOLBAR_CalcToolbar (hwnd);
3884 /* repaint toolbar */
3885 InvalidateRect(hwnd, NULL, FALSE);
3888 /* return bounding rectangle */
3890 lprc->left = infoPtr->rcBound.left;
3891 lprc->right = infoPtr->rcBound.right;
3892 lprc->top = infoPtr->rcBound.top;
3893 lprc->bottom = infoPtr->rcBound.bottom;
3901 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3904 TBUTTON_INFO *btnPtr;
3907 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3911 btnPtr = &infoPtr->buttons[nIndex];
3913 /* if hidden state has changed the invalidate entire window and recalc */
3914 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
3915 btnPtr->fsState = LOWORD(lParam);
3916 TOOLBAR_CalcToolbar (hwnd);
3917 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
3921 /* process state changing if current state doesn't match new state */
3922 if(btnPtr->fsState != LOWORD(lParam))
3924 btnPtr->fsState = LOWORD(lParam);
3925 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3934 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3937 TBUTTON_INFO *btnPtr;
3940 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3944 btnPtr = &infoPtr->buttons[nIndex];
3946 /* process style change if current style doesn't match new style */
3947 if(btnPtr->fsStyle != LOWORD(lParam))
3949 btnPtr->fsStyle = LOWORD(lParam);
3950 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3953 if (infoPtr->hwndToolTip) {
3954 FIXME("change tool tip!\n");
3962 inline static LRESULT
3963 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3967 if (infoPtr == NULL)
3969 infoPtr->hwndToolTip = (HWND)wParam;
3975 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3977 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3980 TRACE("%s hwnd=0x%04x stub!\n",
3981 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3983 bTemp = infoPtr->bUnicode;
3984 infoPtr->bUnicode = (BOOL)wParam;
3991 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
3993 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3994 INT iOldVersion = infoPtr->iVersion;
3996 infoPtr->iVersion = iVersion;
4003 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4006 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4009 /* initialize info structure */
4010 infoPtr->nButtonHeight = 22;
4011 infoPtr->nButtonWidth = 24;
4012 infoPtr->nBitmapHeight = 15;
4013 infoPtr->nBitmapWidth = 16;
4015 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4017 infoPtr->nMaxTextRows = 1;
4018 infoPtr->cxMin = -1;
4019 infoPtr->cxMax = -1;
4020 infoPtr->nNumBitmaps = 0;
4021 infoPtr->nNumStrings = 0;
4023 infoPtr->bCaptured = FALSE;
4024 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4025 infoPtr->nButtonDown = -1;
4026 infoPtr->nOldHit = -1;
4027 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4028 infoPtr->hwndNotify = GetParent (hwnd);
4029 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4030 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4031 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4032 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4033 infoPtr->iVersion = 0;
4034 infoPtr->bNtfUnicode = FALSE;
4035 infoPtr->hwndSelf = hwnd;
4037 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4038 infoPtr->hFont = CreateFontIndirectA (&logFont);
4040 if (dwStyle & TBSTYLE_TOOLTIPS) {
4041 /* Create tooltip control */
4042 infoPtr->hwndToolTip =
4043 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4044 CW_USEDEFAULT, CW_USEDEFAULT,
4045 CW_USEDEFAULT, CW_USEDEFAULT,
4048 /* Send NM_TOOLTIPSCREATED notification */
4049 if (infoPtr->hwndToolTip) {
4050 NMTOOLTIPSCREATED nmttc;
4052 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4054 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4055 NM_TOOLTIPSCREATED);
4059 TOOLBAR_CheckStyle (hwnd, dwStyle);
4061 TOOLBAR_CalcToolbar(hwnd);
4068 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4070 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4072 /* delete tooltip control */
4073 if (infoPtr->hwndToolTip)
4074 DestroyWindow (infoPtr->hwndToolTip);
4076 /* delete button data */
4077 if (infoPtr->buttons)
4078 COMCTL32_Free (infoPtr->buttons);
4080 /* delete strings */
4081 if (infoPtr->strings) {
4083 for (i = 0; i < infoPtr->nNumStrings; i++)
4084 if (infoPtr->strings[i])
4085 COMCTL32_Free (infoPtr->strings[i]);
4087 COMCTL32_Free (infoPtr->strings);
4090 /* destroy internal image list */
4091 if (infoPtr->himlInt)
4092 ImageList_Destroy (infoPtr->himlInt);
4094 /* delete default font */
4096 DeleteObject (infoPtr->hFont);
4098 /* free toolbar info data */
4099 COMCTL32_Free (infoPtr);
4100 SetWindowLongA (hwnd, 0, 0);
4107 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4109 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4110 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4111 NMTBCUSTOMDRAW tbcd;
4114 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4115 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4116 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4117 tbcd.nmcd.hdc = (HDC)wParam;
4118 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4119 /* FIXME: in general the return flags *can* be or'ed together */
4122 case CDRF_DODEFAULT:
4124 case CDRF_SKIPDEFAULT:
4127 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4132 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4133 * to my parent for processing.
4135 if (infoPtr->bTransparent) {
4137 HDC hdc = (HDC)wParam;
4142 parent = GetParent(hwnd);
4143 MapWindowPoints(hwnd, parent, &pt, 1);
4144 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4145 SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4146 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4149 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4151 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4152 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4153 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4154 tbcd.nmcd.hdc = (HDC)wParam;
4155 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4158 case CDRF_DODEFAULT:
4160 case CDRF_SKIPDEFAULT:
4163 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4172 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4176 return infoPtr->hFont;
4181 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4183 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4184 TBUTTON_INFO *btnPtr;
4188 pt.x = (INT)LOWORD(lParam);
4189 pt.y = (INT)HIWORD(lParam);
4190 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4193 btnPtr = &infoPtr->buttons[nHit];
4194 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4197 infoPtr->bCaptured = TRUE;
4198 infoPtr->nButtonDown = nHit;
4200 btnPtr->fsState |= TBSTATE_PRESSED;
4202 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4205 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4206 TOOLBAR_Customize (hwnd);
4213 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4216 TBUTTON_INFO *btnPtr;
4221 if (infoPtr->hwndToolTip)
4222 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4223 WM_LBUTTONDOWN, wParam, lParam);
4225 pt.x = (INT)LOWORD(lParam);
4226 pt.y = (INT)HIWORD(lParam);
4227 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4231 btnPtr = &infoPtr->buttons[nHit];
4232 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4235 infoPtr->nOldHit = nHit;
4237 CopyRect(&arrowRect, &btnPtr->rect);
4238 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4240 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4241 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4242 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4243 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4247 * this time we must force a Redraw, so the btn is
4248 * painted down before CaptureChanged repaints it up
4250 RedrawWindow(hwnd,&btnPtr->rect,0,
4251 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4253 nmtb.iItem = btnPtr->idCommand;
4254 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4257 memset(&nmtb.rcButton, 0, sizeof(RECT));
4258 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4260 if (res != TBDDRET_TREATPRESSED)
4261 /* ??? guess (GA) */
4263 /* otherwise drop through and process as pushed */
4265 /* SetCapture (hwnd); */
4266 infoPtr->bCaptured = TRUE;
4267 infoPtr->nButtonDown = nHit;
4269 btnPtr->fsState |= TBSTATE_PRESSED;
4270 btnPtr->bHot = FALSE;
4272 InvalidateRect(hwnd, &btnPtr->rect,
4273 TOOLBAR_HasText(infoPtr, btnPtr));
4277 /* native issues the TBN_BEGINDRAG here */
4278 nmtb.iItem = btnPtr->idCommand;
4279 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4280 nmtb.tbButton.idCommand = btnPtr->idCommand;
4281 nmtb.tbButton.fsState = btnPtr->fsState;
4282 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4283 nmtb.tbButton.dwData = btnPtr->dwData;
4284 nmtb.tbButton.iString = btnPtr->iString;
4285 nmtb.cchText = 0; /* !!! not correct */
4286 nmtb.pszText = 0; /* !!! not correct */
4287 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4295 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4298 TBUTTON_INFO *btnPtr;
4302 BOOL bSendMessage = TRUE;
4307 if (infoPtr->hwndToolTip)
4308 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4309 WM_LBUTTONUP, wParam, lParam);
4311 pt.x = (INT)LOWORD(lParam);
4312 pt.y = (INT)HIWORD(lParam);
4313 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4315 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4316 /* if the cursor is still inside of the toolbar */
4317 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4318 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4320 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
4321 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4322 btnPtr->fsState &= ~TBSTATE_PRESSED;
4324 if (nHit == infoPtr->nButtonDown) {
4325 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4326 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4327 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4328 infoPtr->nButtonDown);
4329 if (nOldIndex == infoPtr->nButtonDown)
4330 bSendMessage = FALSE;
4331 if ((nOldIndex != infoPtr->nButtonDown) &&
4333 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4334 btnPtr->fsState |= TBSTATE_CHECKED;
4337 if (btnPtr->fsState & TBSTATE_CHECKED)
4338 btnPtr->fsState &= ~TBSTATE_CHECKED;
4340 btnPtr->fsState |= TBSTATE_CHECKED;
4345 bSendMessage = FALSE;
4347 if (nOldIndex != -1)
4349 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4350 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4354 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4355 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4356 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4360 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4361 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4362 NM_RELEASEDCAPTURE);
4364 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4367 nmtb.iItem = btnPtr->idCommand;
4368 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4369 nmtb.tbButton.idCommand = btnPtr->idCommand;
4370 nmtb.tbButton.fsState = btnPtr->fsState;
4371 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4372 nmtb.tbButton.dwData = btnPtr->dwData;
4373 nmtb.tbButton.iString = btnPtr->iString;
4374 nmtb.cchText = 0; /* !!! not correct */
4375 nmtb.pszText = 0; /* !!! not correct */
4376 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4380 SendMessageA (GetParent(hwnd), WM_COMMAND,
4381 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
4383 /* !!! Undocumented - toolbar at 4.71 level and above sends
4384 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4385 * Only NM_RCLICK is documented.
4387 nmmouse.dwItemSpec = btnPtr->idCommand;
4388 nmmouse.dwItemData = btnPtr->dwData;
4389 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4397 TOOLBAR_CaptureChanged(HWND hwnd)
4399 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4400 TBUTTON_INFO *btnPtr;
4402 infoPtr->bCaptured = FALSE;
4404 if (infoPtr->nButtonDown >= 0)
4406 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4407 btnPtr->fsState &= ~TBSTATE_PRESSED;
4409 infoPtr->nButtonDown = -1;
4410 infoPtr->nOldHit = -1;
4412 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4419 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4422 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4425 if (infoPtr->nOldHit < 0)
4428 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4430 /* Redraw the button if the last button we were over is the hot button and it
4432 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4434 hotBtnPtr->bHot = FALSE;
4435 rc1 = hotBtnPtr->rect;
4436 InflateRect (&rc1, 1, 1);
4437 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4441 /* If the last button we were over is depressed then make it not */
4442 /* depressed and redraw it */
4443 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4445 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4447 btnPtr->fsState &= ~TBSTATE_PRESSED;
4449 rc1 = hotBtnPtr->rect;
4450 InflateRect (&rc1, 1, 1);
4451 InvalidateRect (hwnd, &rc1, TRUE);
4454 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4455 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4461 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4463 TBUTTON_INFO *btnPtr, *oldBtnPtr;
4464 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4467 TRACKMOUSEEVENT trackinfo;
4469 /* fill in the TRACKMOUSEEVENT struct */
4470 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4471 trackinfo.dwFlags = TME_QUERY;
4472 trackinfo.hwndTrack = hwnd;
4473 trackinfo.dwHoverTime = HOVER_DEFAULT;
4475 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4476 _TrackMouseEvent(&trackinfo);
4478 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4479 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4480 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4482 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4483 /* and can properly deactivate the hot toolbar button */
4484 _TrackMouseEvent(&trackinfo);
4487 if (infoPtr->hwndToolTip)
4488 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4489 WM_MOUSEMOVE, wParam, lParam);
4491 pt.x = (INT)LOWORD(lParam);
4492 pt.y = (INT)HIWORD(lParam);
4494 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4496 if (infoPtr->nOldHit != nHit)
4498 /* Remove the effect of an old hot button if the button was enabled and was
4499 drawn with the hot button effect */
4500 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
4501 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
4503 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4504 oldBtnPtr->bHot = FALSE;
4506 InvalidateRect (hwnd, &oldBtnPtr->rect,
4507 TOOLBAR_HasText(infoPtr, oldBtnPtr));
4510 /* It's not a separator or in nowhere. It's a hot button. */
4513 btnPtr = &infoPtr->buttons[nHit];
4515 infoPtr->nHotItem = nHit;
4517 /* only enabled buttons show hot effect */
4518 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
4520 btnPtr->bHot = TRUE;
4521 InvalidateRect(hwnd, &btnPtr->rect,
4522 TOOLBAR_HasText(infoPtr, btnPtr));
4527 if (infoPtr->bCaptured) {
4528 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4529 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
4530 btnPtr->fsState &= ~TBSTATE_PRESSED;
4531 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4533 else if (nHit == infoPtr->nButtonDown) {
4534 btnPtr->fsState |= TBSTATE_PRESSED;
4535 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4538 infoPtr->nOldHit = nHit;
4544 inline static LRESULT
4545 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4547 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
4548 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
4550 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
4554 inline static LRESULT
4555 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4557 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
4558 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
4560 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
4565 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4567 TOOLBAR_INFO *infoPtr;
4568 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
4571 /* allocate memory for info structure */
4572 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
4573 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4576 infoPtr->dwStructSize = sizeof(TBBUTTON);
4578 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
4579 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
4580 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
4581 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
4584 /* native control does:
4585 * Get a lot of colors and brushes
4587 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
4588 * CreateFontIndirectA(adr1)
4589 * CreateBitmap(0x27, 0x24, 1, 1, 0)
4590 * hdc = GetDC(toolbar)
4591 * GetSystemMetrics(0x48)
4592 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
4593 * 0, 0, 0, 0, "MARLETT")
4594 * oldfnt = SelectObject(hdc, fnt2)
4595 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
4596 * GetTextMetricsA(hdc, adr3)
4597 * SelectObject(hdc, oldfnt)
4598 * DeleteObject(fnt2)
4600 * InvalidateRect(toolbar, 0, 1)
4601 * SetWindowLongA(toolbar, 0, addr)
4602 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
4605 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
4606 * ie 2 0x4600094c 0x4600094c 0x4600894d
4607 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
4608 * rebar 0x50008844 0x40008844 0x50008845
4609 * pager 0x50000844 0x40000844 0x50008845
4610 * IC35mgr 0x5400084e **nochange**
4611 * on entry to _NCCREATE 0x5400084e
4612 * rowlist 0x5400004e **nochange**
4613 * on entry to _NCCREATE 0x5400004e
4617 /* I think the code below is a bug, but it is the way that the native
4618 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
4619 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
4620 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
4621 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
4622 * Some how, the only cases of this seem to be MFC programs.
4624 * Note also that the addition of _TRANSPARENT occurs *only* here. It
4625 * does not occur in the WM_STYLECHANGING routine.
4626 * (Guy Albertelli 9/2001)
4629 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
4630 styleadd |= TBSTYLE_TRANSPARENT;
4631 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
4632 styleadd |= CCS_TOP; /* default to top */
4633 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
4636 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
4641 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
4643 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4647 if (dwStyle & WS_MINIMIZE)
4648 return 0; /* Nothing to do */
4650 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
4652 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
4655 if (!(dwStyle & CCS_NODIVIDER))
4657 GetWindowRect (hwnd, &rcWindow);
4658 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4659 if( dwStyle & WS_BORDER )
4660 OffsetRect (&rcWindow, 1, 1);
4661 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
4664 ReleaseDC( hwnd, hdc );
4670 inline static LRESULT
4671 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
4673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4674 LPNMHDR lpnmh = (LPNMHDR)lParam;
4676 if (lpnmh->code == PGN_CALCSIZE) {
4677 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
4679 if (lppgc->dwFlag == PGF_CALCWIDTH) {
4680 lppgc->iWidth = infoPtr->nWidth;
4681 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
4685 lppgc->iHeight = infoPtr->nHeight;
4686 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
4693 TRACE("passing WM_NOTIFY!\n");
4695 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
4696 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
4699 if (lpnmh->code == TTN_GETDISPINFOA) {
4700 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
4702 FIXME("retrieving ASCII string\n");
4705 else if (lpnmh->code == TTN_GETDISPINFOW) {
4706 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
4708 FIXME("retrieving UNICODE string\n");
4719 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
4721 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4725 /* fill ps.rcPaint with a default rect */
4726 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
4728 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
4730 TRACE("psrect=(%d,%d)-(%d,%d)\n",
4731 ps.rcPaint.left, ps.rcPaint.top,
4732 ps.rcPaint.right, ps.rcPaint.bottom);
4734 TOOLBAR_Refresh (hwnd, hdc, &ps);
4735 if (!wParam) EndPaint (hwnd, &ps);
4742 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
4744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4745 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4754 /* Resize deadlock check */
4755 if (infoPtr->bAutoSize) {
4756 infoPtr->bAutoSize = FALSE;
4760 /* FIXME: optimize to only update size if the new size doesn't */
4761 /* match the current size */
4763 flags = (INT) wParam;
4765 /* FIXME for flags =
4766 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
4769 TRACE("sizing toolbar!\n");
4771 if (flags == SIZE_RESTORED) {
4772 /* width and height don't apply */
4773 parent = GetParent (hwnd);
4774 GetClientRect(parent, &parent_rect);
4775 x = parent_rect.left;
4776 y = parent_rect.top;
4778 if (dwStyle & CCS_NORESIZE) {
4779 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
4782 * this sets the working width of the toolbar, and
4783 * Calc Toolbar will not adjust it, only the height
4785 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4786 cy = infoPtr->nHeight;
4787 cx = infoPtr->nWidth;
4788 TOOLBAR_CalcToolbar (hwnd);
4789 infoPtr->nWidth = cx;
4790 infoPtr->nHeight = cy;
4793 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4794 TOOLBAR_CalcToolbar (hwnd);
4795 cy = infoPtr->nHeight;
4796 cx = infoPtr->nWidth;
4798 if (dwStyle & CCS_NOMOVEY) {
4799 GetWindowRect(hwnd, &window_rect);
4800 ScreenToClient(parent, (LPPOINT)&window_rect.left);
4801 y = window_rect.top;
4805 if (dwStyle & CCS_NOPARENTALIGN) {
4806 uPosFlags |= SWP_NOMOVE;
4807 cy = infoPtr->nHeight;
4808 cx = infoPtr->nWidth;
4811 if (!(dwStyle & CCS_NODIVIDER))
4812 cy += GetSystemMetrics(SM_CYEDGE);
4814 if (dwStyle & WS_BORDER)
4817 cy += GetSystemMetrics(SM_CYEDGE);
4818 cx += GetSystemMetrics(SM_CYEDGE);
4821 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
4822 cx, cy, uPosFlags | SWP_NOZORDER);
4829 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
4831 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4833 if (nType == GWL_STYLE) {
4834 if (lpStyle->styleNew & TBSTYLE_LIST) {
4835 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
4838 infoPtr->dwDTFlags = DT_CENTER;
4840 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
4841 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
4842 (TBSTYLE_FLAT | TBSTYLE_LIST));
4843 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
4846 TOOLBAR_AutoSize (hwnd);
4848 InvalidateRect(hwnd, NULL, FALSE);
4855 static LRESULT WINAPI
4856 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4858 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
4859 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
4861 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
4862 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
4867 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
4869 case TB_ADDBUTTONSA:
4870 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
4872 case TB_ADDBUTTONSW:
4873 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
4876 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
4879 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
4882 return TOOLBAR_AutoSize (hwnd);
4884 case TB_BUTTONCOUNT:
4885 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
4887 case TB_BUTTONSTRUCTSIZE:
4888 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
4890 case TB_CHANGEBITMAP:
4891 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
4893 case TB_CHECKBUTTON:
4894 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
4896 case TB_COMMANDTOINDEX:
4897 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
4900 return TOOLBAR_Customize (hwnd);
4902 case TB_DELETEBUTTON:
4903 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
4905 case TB_ENABLEBUTTON:
4906 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
4908 case TB_GETANCHORHIGHLIGHT:
4909 return TOOLBAR_GetAnchorHighlight (hwnd);
4912 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
4914 case TB_GETBITMAPFLAGS:
4915 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
4918 return TOOLBAR_GetButton (hwnd, wParam, lParam);
4920 case TB_GETBUTTONINFOA:
4921 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
4923 case TB_GETBUTTONINFOW:
4924 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
4926 case TB_GETBUTTONSIZE:
4927 return TOOLBAR_GetButtonSize (hwnd);
4929 case TB_GETBUTTONTEXTA:
4930 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
4932 case TB_GETBUTTONTEXTW:
4933 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
4935 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
4937 case TB_GETDISABLEDIMAGELIST:
4938 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
4940 case TB_GETEXTENDEDSTYLE:
4941 return TOOLBAR_GetExtendedStyle (hwnd);
4943 case TB_GETHOTIMAGELIST:
4944 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
4947 return TOOLBAR_GetHotItem (hwnd);
4949 case TB_GETIMAGELIST:
4950 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
4952 /* case TB_GETINSERTMARK: */ /* 4.71 */
4953 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
4955 case TB_GETITEMRECT:
4956 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
4959 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
4961 /* case TB_GETOBJECT: */ /* 4.71 */
4962 /* case TB_GETPADDING: */ /* 4.71 */
4965 return TOOLBAR_GetRect (hwnd, wParam, lParam);
4968 return TOOLBAR_GetRows (hwnd, wParam, lParam);
4971 return TOOLBAR_GetState (hwnd, wParam, lParam);
4974 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
4976 case TB_GETTEXTROWS:
4977 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
4979 case TB_GETTOOLTIPS:
4980 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
4982 case TB_GETUNICODEFORMAT:
4983 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
4985 case CCM_GETVERSION:
4986 return TOOLBAR_GetVersion (hwnd);
4989 return TOOLBAR_HideButton (hwnd, wParam, lParam);
4992 return TOOLBAR_HitTest (hwnd, wParam, lParam);
4994 case TB_INDETERMINATE:
4995 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
4997 case TB_INSERTBUTTONA:
4998 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5000 case TB_INSERTBUTTONW:
5001 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5003 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5005 case TB_ISBUTTONCHECKED:
5006 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5008 case TB_ISBUTTONENABLED:
5009 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5011 case TB_ISBUTTONHIDDEN:
5012 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5014 case TB_ISBUTTONHIGHLIGHTED:
5015 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5017 case TB_ISBUTTONINDETERMINATE:
5018 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5020 case TB_ISBUTTONPRESSED:
5021 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5023 case TB_LOADIMAGES: /* 4.70 */
5024 FIXME("missing standard imagelists\n");
5027 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5028 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5029 /* case TB_MARKBUTTON: */ /* 4.71 */
5030 /* case TB_MOVEBUTTON: */ /* 4.71 */
5032 case TB_PRESSBUTTON:
5033 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5035 /* case TB_REPLACEBITMAP: */
5037 case TB_SAVERESTOREA:
5038 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5040 case TB_SAVERESTOREW:
5041 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5043 case TB_SETANCHORHIGHLIGHT:
5044 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5046 case TB_SETBITMAPSIZE:
5047 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5049 case TB_SETBUTTONINFOA:
5050 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5052 case TB_SETBUTTONINFOW:
5053 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5055 case TB_SETBUTTONSIZE:
5056 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5058 case TB_SETBUTTONWIDTH:
5059 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5062 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5064 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
5066 case TB_SETDISABLEDIMAGELIST:
5067 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5069 case TB_SETDRAWTEXTFLAGS:
5070 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5072 case TB_SETEXTENDEDSTYLE:
5073 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5075 case TB_SETHOTIMAGELIST:
5076 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5079 return TOOLBAR_SetHotItem (hwnd, wParam);
5081 case TB_SETIMAGELIST:
5082 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5085 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5087 /* case TB_SETINSERTMARK: */ /* 4.71 */
5089 case TB_SETINSERTMARKCOLOR:
5090 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5092 case TB_SETMAXTEXTROWS:
5093 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5095 /* case TB_SETPADDING: */ /* 4.71 */
5098 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5101 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5104 return TOOLBAR_SetState (hwnd, wParam, lParam);
5107 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5109 case TB_SETTOOLTIPS:
5110 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5112 case TB_SETUNICODEFORMAT:
5113 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5115 case CCM_SETVERSION:
5116 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5122 return TOOLBAR_Create (hwnd, wParam, lParam);
5125 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5128 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5131 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5133 /* case WM_KEYDOWN: */
5134 /* case WM_KILLFOCUS: */
5136 case WM_LBUTTONDBLCLK:
5137 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5139 case WM_LBUTTONDOWN:
5140 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5143 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5146 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5149 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5151 case WM_CAPTURECHANGED:
5152 return TOOLBAR_CaptureChanged(hwnd);
5155 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5158 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5161 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5164 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5167 return TOOLBAR_Notify (hwnd, wParam, lParam);
5169 /* case WM_NOTIFYFORMAT: */
5172 return TOOLBAR_Paint (hwnd, wParam);
5175 return TOOLBAR_Size (hwnd, wParam, lParam);
5177 case WM_STYLECHANGED:
5178 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5180 /* case WM_SYSCOLORCHANGE: */
5182 /* case WM_WININICHANGE: */
5187 case WM_MEASUREITEM:
5189 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5192 if (uMsg >= WM_USER)
5193 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5194 uMsg, wParam, lParam);
5195 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5202 TOOLBAR_Register (void)
5206 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5207 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5208 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5209 wndClass.cbClsExtra = 0;
5210 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5211 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5212 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5213 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5215 RegisterClassA (&wndClass);
5220 TOOLBAR_Unregister (void)
5222 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);