4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Differences between MSDN and actual native control operation:
22 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
23 * to the right of the bitmap. Otherwise, this style is
24 * identical to TBSTYLE_FLAT."
25 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
26 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
27 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
28 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
32 * - Button wrapping (under construction).
34 * - Notifications (under construction).
36 * - Tooltip support (almost complete).
37 * - Unicode suppport (under construction).
38 * - Fix TOOLBAR_SetButtonInfo32A/W.
39 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
40 * - I_IMAGECALLBACK support.
41 * - iString of -1 is undocumented
42 * - Customization dialog:
44 * - Minor buglet in 'available buttons' list:
45 * Buttons are not listed in M$-like order. M$ seems to use a single
46 * internal list to store the button information of both listboxes.
47 * - Drag list support.
48 * - Help and Reset button support.
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsofts controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
68 #include "wine/unicode.h"
71 #include "imagelist.h"
73 #include "wine/debug.h"
75 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
102 } IMLENTRY, *PIMLENTRY;
106 DWORD dwStructSize; /* size of TBBUTTON struct */
107 INT nHeight; /* height of the toolbar */
108 INT nWidth; /* width of the toolbar */
114 INT nRows; /* number of button rows */
115 INT nMaxTextRows; /* maximum number of text rows */
116 INT cxMin; /* minimum button width */
117 INT cxMax; /* maximum button width */
118 INT nNumButtons; /* number of buttons */
119 INT nNumBitmaps; /* number of bitmaps */
120 INT nNumStrings; /* number of strings */
122 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
123 BOOL bCaptured; /* mouse captured? */
126 INT nHotItem; /* index of the "hot" item */
127 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
128 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
129 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
130 SIZE szPadding; /* padding values around button */
132 HFONT hFont; /* text font */
133 HIMAGELIST himlInt; /* image list created internally */
134 PIMLENTRY *himlDef; /* default image list array */
135 INT cimlDef; /* default image list array count */
136 PIMLENTRY *himlHot; /* hot image list array */
137 INT cimlHot; /* hot image list array count */
138 PIMLENTRY *himlDis; /* disabled image list array */
139 INT cimlDis; /* disabled image list array count */
140 HWND hwndToolTip; /* handle to tool tip control */
141 HWND hwndNotify; /* handle to the window that gets notifications */
142 HWND hwndSelf; /* my own handle */
143 BOOL bTransparent; /* background transparency flag */
144 BOOL bBtnTranspnt; /* button transparency flag */
145 BOOL bAutoSize; /* auto size deadlock indicator */
146 BOOL bAnchor; /* anchor highlight enabled */
147 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
148 BOOL bDoRedraw; /* Redraw status */
149 DWORD dwExStyle; /* extended toolbar style */
150 DWORD dwDTFlags; /* DrawText flags */
152 COLORREF clrInsertMark; /* insert mark color */
153 COLORREF clrBtnHighlight; /* color for Flat Separator */
154 COLORREF clrBtnShadow; /* color for Flag Separator */
155 RECT rcBound; /* bounding rectangle */
158 TBUTTON_INFO *buttons; /* pointer to button array */
159 LPWSTR *strings; /* pointer to string array */
160 TBITMAP_INFO *bitmaps;
161 } TOOLBAR_INFO, *PTOOLBAR_INFO;
164 /* used by customization dialog */
167 PTOOLBAR_INFO tbInfo;
169 } CUSTDLG_INFO, *PCUSTDLG_INFO;
177 } CUSTOMBUTTON, *PCUSTOMBUTTON;
180 #define SEPARATOR_WIDTH 8
182 #define BOTTOM_BORDER 2
183 #define DDARROW_WIDTH 11
184 #define ARROW_HEIGHT 3
186 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
187 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
188 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
190 /* Used to find undocumented extended styles */
191 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
192 TBSTYLE_EX_UNDOC1 | \
193 TBSTYLE_EX_MIXEDBUTTONS | \
194 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
196 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
197 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
198 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
199 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
200 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
202 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
203 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
204 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
205 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
206 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
207 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
210 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
214 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
216 LPWSTR lpText = NULL;
218 /* FIXME: iString == -1 is undocumented */
219 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
220 lpText = (LPWSTR)btnPtr->iString;
221 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
222 lpText = infoPtr->strings[btnPtr->iString];
228 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
230 if (TRACE_ON(toolbar)){
231 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
232 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
233 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
234 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
236 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n",
237 btn_num, bP->idCommand,
238 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
239 bP->rect.left, bP->rect.top,
240 bP->rect.right, bP->rect.bottom);
246 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
248 if (TRACE_ON(toolbar)) {
252 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
253 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
255 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
256 iP->nNumStrings, dwStyle);
257 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
259 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
260 (iP->bDoRedraw) ? "TRUE" : "FALSE");
261 for(i=0; i<iP->nNumButtons; i++) {
262 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
268 /***********************************************************************
271 * This function validates that the styles set are implemented and
272 * issues FIXME's warning of possible problems. In a perfect world this
273 * function should be null.
276 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
278 if (dwStyle & TBSTYLE_ALTDRAG)
279 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
280 if (dwStyle & TBSTYLE_REGISTERDROP)
281 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
286 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
288 if(!IsWindow(infoPtr->hwndSelf))
289 return 0; /* we have just been destroyed */
291 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
292 nmhdr->hwndFrom = infoPtr->hwndSelf;
295 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
296 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
298 if (infoPtr->bNtfUnicode)
299 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
300 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
302 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
303 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
306 /***********************************************************************
307 * TOOLBAR_GetBitmapIndex
309 * This function returns the bitmap index associated with a button.
310 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
311 * is issued to retrieve the index.
314 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
316 INT ret = btnPtr->iBitmap;
318 if (ret == I_IMAGECALLBACK) {
319 /* issue TBN_GETDISPINFO */
322 nmgd.idCommand = btnPtr->idCommand;
323 nmgd.lParam = btnPtr->dwData;
324 nmgd.dwMask = TBNF_IMAGE;
325 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
326 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
328 if (nmgd.dwMask & TBNF_DI_SETITEM) {
329 btnPtr->iBitmap = nmgd.iImage;
332 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
333 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
336 if (ret != I_IMAGENONE)
337 ret = GETIBITMAP(infoPtr, ret);
344 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
347 INT id = GETHIMLID(infoPtr, index);
348 INT iBitmap = GETIBITMAP(infoPtr, index);
350 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
351 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
352 (index == I_IMAGECALLBACK))
359 /***********************************************************************
360 * TOOLBAR_DrawImageList
362 * This function validates the bitmap index (including I_IMAGECALLBACK
363 * functionality). It then draws the image via the ImageList_Draw
364 * function. It returns TRUE if the image was drawn, FALSE otherwise.
367 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
368 HDC hdc, UINT left, UINT top, UINT draw_flags)
372 if (!himl) return FALSE;
374 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
375 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
376 ERR("index %d is not valid, max %d\n",
377 btnPtr->iBitmap, infoPtr->nNumBitmaps);
381 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
382 if ((index == I_IMAGECALLBACK) ||
383 (index == I_IMAGENONE)) return FALSE;
384 ERR("TBN_GETDISPINFO returned invalid index %d\n",
388 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
389 index, himl, left, top, draw_flags);
391 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
396 /***********************************************************************
397 * TOOLBAR_TestImageExist
399 * This function is similar to TOOLBAR_DrawImageList, except it does not
400 * draw the image. The I_IMAGECALLBACK functionality is implemented.
403 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
407 if (!himl) return FALSE;
409 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
410 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
411 ERR("index %d is not valid, max %d\n",
412 btnPtr->iBitmap, infoPtr->nNumBitmaps);
416 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
417 if ((index == I_IMAGECALLBACK) ||
418 (index == I_IMAGENONE)) return FALSE;
419 ERR("TBN_GETDISPINFO returned invalid index %d\n",
428 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
431 COLORREF oldcolor, newcolor;
433 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
434 myrect.right = myrect.left + 1;
435 myrect.top = lpRect->top + 2;
436 myrect.bottom = lpRect->bottom - 2;
438 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
439 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
440 oldcolor = SetBkColor (hdc, newcolor);
441 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
443 myrect.left = myrect.right;
444 myrect.right = myrect.left + 1;
446 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
447 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
448 SetBkColor (hdc, newcolor);
449 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
451 SetBkColor (hdc, oldcolor);
455 /***********************************************************************
456 * TOOLBAR_DrawDDFlatSeparator
458 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
459 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
460 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
461 * are horizontal as opposed to the vertical separators for not dropdown
464 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
467 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
470 COLORREF oldcolor, newcolor;
472 myrect.left = lpRect->left;
473 myrect.right = lpRect->right;
474 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
475 myrect.bottom = myrect.top + 1;
477 InflateRect (&myrect, -2, 0);
479 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n",
480 myrect.left, myrect.top, myrect.right, myrect.bottom);
482 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
483 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
484 oldcolor = SetBkColor (hdc, newcolor);
485 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
487 myrect.top = myrect.bottom;
488 myrect.bottom = myrect.top + 1;
490 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
491 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
492 SetBkColor (hdc, newcolor);
493 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
495 SetBkColor (hdc, oldcolor);
500 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
505 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
506 hOldPen = SelectObject ( hdc, hPen );
509 MoveToEx (hdc, x, y, NULL);
510 LineTo (hdc, x+5, y++); x++;
511 MoveToEx (hdc, x, y, NULL);
512 LineTo (hdc, x+3, y++); x++;
513 MoveToEx (hdc, x, y, NULL);
514 LineTo (hdc, x+1, y++);
515 SelectObject( hdc, hOldPen );
516 DeleteObject( hPen );
520 * Draw the text string for this button.
521 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
522 * is non-zero, so we can simply check himlDef to see if we have
526 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
527 HDC hdc, INT nState, DWORD dwStyle,
528 RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
535 TRACE("string rect=(%ld,%ld)-(%ld,%ld)\n",
536 rcText->left, rcText->top, rcText->right, rcText->bottom);
538 hOldFont = SelectObject (hdc, infoPtr->hFont);
539 if (!(nState & TBSTATE_ENABLED)) {
540 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
541 OffsetRect (rcText, 1, 1);
542 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
543 SetTextColor (hdc, comctl32_color.clr3dShadow);
544 OffsetRect (rcText, -1, -1);
546 else if (nState & TBSTATE_INDETERMINATE) {
547 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
549 else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
550 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
553 clrOld = SetTextColor (hdc, tbcd->clrText);
556 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
557 SetTextColor (hdc, clrOld);
558 SelectObject (hdc, hOldFont);
564 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
566 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
567 INT cx = lpRect->right - lpRect->left;
568 INT cy = lpRect->bottom - lpRect->top;
569 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
570 SelectObject (hdc, hbr);
575 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
576 HDC hdc, INT x, INT y)
578 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0);
586 ImageList_GetIconSize(himl, &cx, &cy);
588 /* create new dc's */
589 hdcMask = CreateCompatibleDC (0);
591 /* create new bitmap */
592 hbmMask = CreateBitmap (cx, cy, 1, 1, NULL);
593 SelectObject (hdcMask, hbmMask);
595 /* copy the mask bitmap */
596 ImageList_DrawEx(himl, btnPtr->iBitmap, hdcMask, 0, 0, 0, 0, RGB(255, 255, 255), RGB(0, 0, 0), ILD_MASK);
598 /* draw the new mask */
599 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
600 BitBlt (hdc, x+1, y+1, cx, cy, hdcMask, 0, 0, 0xB8074A);
602 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
603 BitBlt (hdc, x, y, cx, cy, hdcMask, 0, 0, 0xB8074A);
605 DeleteObject (hbmMask);
611 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
615 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
616 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
617 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
618 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
619 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
620 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
621 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
622 /* don't test TBSTATE_HIDDEN */
628 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
631 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
632 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
633 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
634 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
635 LPWSTR lpText = NULL;
641 if (btnPtr->fsState & TBSTATE_HIDDEN)
645 CopyRect (&rcFill, &rc);
646 CopyRect (&rcArrow, &rc);
647 CopyRect(&rcBitmap, &rc);
649 /* get a pointer to the text */
650 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
652 if (hasDropDownArrow)
654 if (dwStyle & TBSTYLE_FLAT)
655 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
657 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
658 rcArrow.left = rc.right;
661 /* copy text rect after adjusting for drop-down arrow
662 * so that text is centred in the rectangle not containing
664 CopyRect(&rcText, &rc);
666 /* Center the bitmap horizontally and vertically */
667 if (dwStyle & TBSTYLE_LIST)
670 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
673 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
675 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
677 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n",
678 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
679 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
680 TRACE ("iString: %x\n", btnPtr->iString);
681 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
686 InflateRect (&rcText, -3, -3);
688 if (GETDEFIMAGELIST(infoPtr, 0) &&
689 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
690 /* The following test looked like this before
691 * I changed it. IE4 "Links" toolbar would not
692 * draw correctly with the original code. - GA 8/01
693 * ((dwStyle & TBSTYLE_LIST) &&
694 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
695 * (btnPtr->iBitmap != I_IMAGENONE))
697 if (dwStyle & TBSTYLE_LIST) {
698 /* LIST style w/ ICON offset is by matching native. */
699 /* Matches IE4 "Links" bar. - GA 8/01 */
700 rcText.left += (infoPtr->nBitmapWidth + 2);
703 rcText.top += infoPtr->nBitmapHeight + 1;
707 if (dwStyle & TBSTYLE_LIST) {
708 /* LIST style w/o ICON offset is by matching native. */
709 /* Matches IE4 "menu" bar. - GA 8/01 */
714 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
715 OffsetRect (&rcText, 1, 1);
718 /* Initialize fields in all cases, because we use these later */
719 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
720 tbcd.clrText = comctl32_color.clrBtnText;
721 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
722 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
723 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
724 tbcd.clrMark = comctl32_color.clrHighlight;
725 tbcd.clrHighlightHotTrack = 0;
726 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
727 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
728 /* MSDN says that this is the text rectangle. */
729 /* But (why always a but) tracing of v5.7 of native shows */
730 /* that this is really a *relative* rectangle based on the */
731 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
732 /* any bitmap that might be present. */
733 tbcd.rcText.left = 0;
735 tbcd.rcText.right = rcText.right - rc.left;
736 tbcd.rcText.bottom = rcText.bottom - rc.top;
738 /* FIXME: what should these be set to ????? */
739 tbcd.hbrMonoDither = 0;
743 /* Issue Item Prepaint notify */
744 infoPtr->dwItemCustDraw = 0;
745 infoPtr->dwItemCDFlag = 0;
746 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
748 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
751 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
752 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
753 tbcd.nmcd.lItemlParam = btnPtr->dwData;
754 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
755 infoPtr->dwItemCustDraw = ntfret & 0xffff;
756 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
757 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
759 /* save the only part of the rect that the user can change */
760 rcText.right = tbcd.rcText.right + rc.left;
761 rcText.bottom = tbcd.rcText.bottom + rc.top;
764 if (!infoPtr->bBtnTranspnt)
765 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
768 if (btnPtr->fsStyle & TBSTYLE_SEP) {
769 /* with the FLAT style, iBitmap is the width and has already */
770 /* been taken into consideration in calculating the width */
771 /* so now we need to draw the vertical separator */
772 /* empirical tests show that iBitmap can/will be non-zero */
773 /* when drawing the vertical bar... */
774 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
775 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
776 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
778 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
780 else if (btnPtr->fsStyle != TBSTYLE_SEP) {
781 FIXME("Draw some kind of separator: fsStyle=%x\n",
787 /* Determine index of image list */
788 himlDef = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
791 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
792 HIMAGELIST himlDis = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
793 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
795 DrawEdge (hdc, &rc, EDGE_RAISED,
796 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
797 if (hasDropDownArrow)
798 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
799 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
802 if (hasDropDownArrow)
804 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_3DHIGHLIGHT);
805 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_3DSHADOW);
808 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDis,
809 hdc, rcBitmap.left, rcBitmap.top,
811 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
813 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
817 /* pressed TBSTYLE_BUTTON */
818 if (btnPtr->fsState & TBSTATE_PRESSED) {
819 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
820 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
822 if (dwStyle & TBSTYLE_FLAT)
824 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
825 if (hasDropDownArrow)
826 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
830 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
831 if (hasDropDownArrow)
832 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
836 if (hasDropDownArrow)
837 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_WINDOWFRAME);
839 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
840 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
843 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
847 /* checked TBSTYLE_CHECK */
848 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
849 (btnPtr->fsState & TBSTATE_CHECKED)) {
850 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
852 if (dwStyle & TBSTYLE_FLAT)
853 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
854 BF_RECT | BF_ADJUST);
856 DrawEdge (hdc, &rc, EDGE_SUNKEN,
857 BF_RECT | BF_MIDDLE | BF_ADJUST);
860 TOOLBAR_DrawPattern (hdc, &rc);
862 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
863 hdc, rcBitmap.left+1, rcBitmap.top+1,
866 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
871 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
872 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
873 DrawEdge (hdc, &rc, EDGE_RAISED,
874 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
876 TOOLBAR_DrawPattern (hdc, &rc);
877 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
878 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
883 if (dwStyle & TBSTYLE_FLAT)
887 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
891 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
892 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
893 if (hasDropDownArrow)
894 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
895 SetBkColor(hdc, oldclr);
899 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
901 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
902 if (hasDropDownArrow)
903 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
908 else /* The following code needs to be removed after
909 * "hot item" support has been implemented for the
910 * case where it is being de-selected.
913 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
914 if (hasDropDownArrow)
915 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
919 if (hasDropDownArrow)
920 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
923 HIMAGELIST himlHot = GETHOTIMAGELIST(infoPtr,
924 GETHIMLID(infoPtr, btnPtr->iBitmap));
925 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
926 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
929 rcBitmap.top, ILD_NORMAL))
930 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
931 hdc, rcBitmap.left, rcBitmap.top,
935 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
936 hdc, rcBitmap.left, rcBitmap.top,
941 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
942 DrawEdge (hdc, &rc, EDGE_RAISED,
943 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
945 if (hasDropDownArrow)
947 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
948 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
949 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
950 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, COLOR_WINDOWFRAME);
953 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
954 hdc, rcBitmap.left, rcBitmap.top,
958 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
961 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
963 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
966 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
967 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
968 tbcd.nmcd.lItemlParam = btnPtr->dwData;
969 tbcd.rcText = rcText;
970 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
971 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
972 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
979 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
982 TBUTTON_INFO *btnPtr;
983 INT i, oldBKmode = 0;
988 /* if imagelist belongs to the app, it can be changed
989 by the app after setting it */
990 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
992 infoPtr->nNumBitmaps = 0;
993 for (i = 0; i < infoPtr->cimlDef; i++)
994 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
997 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
999 /* Send initial notify */
1000 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1001 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1002 tbcd.nmcd.hdc = hdc;
1003 tbcd.nmcd.rc = ps->rcPaint;
1004 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1005 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1007 if (infoPtr->bBtnTranspnt)
1008 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1010 /* redraw necessary buttons */
1011 btnPtr = infoPtr->buttons;
1012 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1014 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
1015 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1018 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1019 SetBkMode (hdc, oldBKmode);
1021 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1023 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1024 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1025 tbcd.nmcd.hdc = hdc;
1026 tbcd.nmcd.rc = ps->rcPaint;
1027 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1031 /***********************************************************************
1032 * TOOLBAR_MeasureString
1034 * This function gets the width and height of a string in pixels. This
1035 * is done first by using GetTextExtentPoint to get the basic width
1036 * and height. The DrawText is called with DT_CALCRECT to get the exact
1037 * width. The reason is because the text may have more than one "&" (or
1038 * prefix characters as M$ likes to call them). The prefix character
1039 * indicates where the underline goes, except for the string "&&" which
1040 * is reduced to a single "&". GetTextExtentPoint does not process these
1041 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
1044 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1045 HDC hdc, LPSIZE lpSize)
1052 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
1054 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1056 if(lpText != NULL) {
1057 /* first get size of all the text */
1058 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1060 /* feed above size into the rectangle for DrawText */
1061 myrect.left = myrect.top = 0;
1062 myrect.right = lpSize->cx;
1063 myrect.bottom = lpSize->cy;
1065 /* Use DrawText to get true size as drawn (less pesky "&") */
1066 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1067 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
1070 /* feed back to caller */
1071 lpSize->cx = myrect.right;
1072 lpSize->cy = myrect.bottom;
1076 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1079 /***********************************************************************
1080 * TOOLBAR_CalcStrings
1082 * This function walks through each string and measures it and returns
1083 * the largest height and width to caller.
1086 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1088 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1089 TBUTTON_INFO *btnPtr;
1099 hOldFont = SelectObject (hdc, infoPtr->hFont);
1101 btnPtr = infoPtr->buttons;
1102 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1103 if(TOOLBAR_HasText(infoPtr, btnPtr))
1105 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1106 if (sz.cx > lpSize->cx)
1108 if (sz.cy > lpSize->cy)
1113 SelectObject (hdc, hOldFont);
1114 ReleaseDC (hwnd, hdc);
1116 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1119 /***********************************************************************
1120 * TOOLBAR_WrapToolbar
1122 * This function walks through the buttons and separators in the
1123 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1124 * wrapping should occur based on the width of the toolbar window.
1125 * It does *not* calculate button placement itself. That task
1126 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1127 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1128 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1130 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1131 * vertical toolbar lists.
1135 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1138 TBUTTON_INFO *btnPtr;
1141 BOOL bWrap, bButtonWrap;
1143 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1144 /* no layout is necessary. Applications may use this style */
1145 /* to perform their own layout on the toolbar. */
1146 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1147 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1149 btnPtr = infoPtr->buttons;
1150 x = infoPtr->nIndent;
1152 /* this can get the parents width, to know how far we can extend
1153 * this toolbar. We cannot use its height, as there may be multiple
1154 * toolbars in a rebar control
1156 GetClientRect( GetParent(hwnd), &rc );
1157 infoPtr->nWidth = rc.right - rc.left;
1158 bButtonWrap = FALSE;
1160 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1161 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1164 for (i = 0; i < infoPtr->nNumButtons; i++ )
1167 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1169 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1172 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1173 /* it is the actual width of the separator. This is used for */
1174 /* custom controls in toolbars. */
1176 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
1177 /* width. - GA 8/01 */
1178 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1179 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
1180 cx = (btnPtr[i].iBitmap > 0) ?
1181 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1183 cx = infoPtr->nButtonWidth;
1185 /* Two or more adjacent separators form a separator group. */
1186 /* The first separator in a group should be wrapped to the */
1187 /* next row if the previous wrapping is on a button. */
1189 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1190 (i + 1 < infoPtr->nNumButtons ) &&
1191 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
1193 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1194 btnPtr[i].fsState |= TBSTATE_WRAP;
1195 x = infoPtr->nIndent;
1197 bButtonWrap = FALSE;
1201 /* The layout makes sure the bitmap is visible, but not the button. */
1202 /* Test added to also wrap after a button that starts a row but */
1203 /* is bigger than the area. - GA 8/01 */
1204 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1205 > infoPtr->nWidth ) ||
1206 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1208 BOOL bFound = FALSE;
1210 /* If the current button is a separator and not hidden, */
1211 /* go to the next until it reaches a non separator. */
1212 /* Wrap the last separator if it is before a button. */
1213 while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1214 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
1215 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1216 i < infoPtr->nNumButtons )
1222 if( bFound && i < infoPtr->nNumButtons )
1225 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1226 i, btnPtr[i].fsStyle, x, cx);
1227 btnPtr[i].fsState |= TBSTATE_WRAP;
1228 x = infoPtr->nIndent;
1229 bButtonWrap = FALSE;
1232 else if ( i >= infoPtr->nNumButtons)
1235 /* If the current button is not a separator, find the last */
1236 /* separator and wrap it. */
1237 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1239 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1240 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1244 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1245 i, btnPtr[i].fsStyle, x, cx);
1246 x = infoPtr->nIndent;
1247 btnPtr[j].fsState |= TBSTATE_WRAP;
1248 bButtonWrap = FALSE;
1253 /* If no separator available for wrapping, wrap one of */
1254 /* non-hidden previous button. */
1258 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1260 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1265 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1266 i, btnPtr[i].fsStyle, x, cx);
1267 x = infoPtr->nIndent;
1268 btnPtr[j].fsState |= TBSTATE_WRAP;
1274 /* If all above failed, wrap the current button. */
1277 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1278 i, btnPtr[i].fsStyle, x, cx);
1279 btnPtr[i].fsState |= TBSTATE_WRAP;
1281 x = infoPtr->nIndent;
1282 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1283 bButtonWrap = FALSE;
1289 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1290 i, btnPtr[i].fsStyle, x, cx);
1297 /***********************************************************************
1298 * TOOLBAR_CalcToolbar
1300 * This function calculates button and separator placement. It first
1301 * calculates the button sizes, gets the toolbar window width and then
1302 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1303 * on. It assigns a new location to each item and sends this location to
1304 * the tooltip window if appropriate. Finally, it updates the rcBound
1305 * rect and calculates the new required toolbar window height.
1309 TOOLBAR_CalcToolbar (HWND hwnd)
1311 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1312 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1313 TBUTTON_INFO *btnPtr;
1314 INT i, nRows, nSepRows;
1318 BOOL usesBitmaps = FALSE;
1319 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1321 TOOLBAR_CalcStrings (hwnd, &sizeString);
1323 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1325 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1328 if (dwStyle & TBSTYLE_LIST)
1330 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1331 0, sizeString.cy) + infoPtr->szPadding.cy;
1332 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1333 0) + sizeString.cx + 6;
1334 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1335 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1336 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1337 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1340 if (sizeString.cy > 0)
1343 infoPtr->nButtonHeight = sizeString.cy +
1344 2 + /* this is the space to separate text from bitmap */
1345 infoPtr->nBitmapHeight + 6;
1347 infoPtr->nButtonHeight = sizeString.cy + 6;
1349 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1350 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1352 if (sizeString.cx > infoPtr->nBitmapWidth)
1353 infoPtr->nButtonWidth = sizeString.cx + 6;
1354 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1355 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1358 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1359 infoPtr->nButtonWidth = infoPtr->cxMin;
1360 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1361 infoPtr->nButtonWidth = infoPtr->cxMax;
1363 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1365 x = infoPtr->nIndent;
1369 * We will set the height below, and we set the width on entry
1370 * so we do not reset them here..
1373 GetClientRect( hwnd, &rc );
1374 /* get initial values for toolbar */
1375 infoPtr->nWidth = rc.right - rc.left;
1376 infoPtr->nHeight = rc.bottom - rc.top;
1379 /* from above, minimum is a button, and possible text */
1380 cx = infoPtr->nButtonWidth;
1382 /* cannot use just ButtonHeight, we may have no buttons! */
1383 if (infoPtr->nNumButtons > 0)
1384 infoPtr->nHeight = infoPtr->nButtonHeight;
1386 cy = infoPtr->nHeight;
1388 nRows = nSepRows = 0;
1390 infoPtr->rcBound.top = y;
1391 infoPtr->rcBound.left = x;
1392 infoPtr->rcBound.bottom = y + cy;
1393 infoPtr->rcBound.right = x;
1395 btnPtr = infoPtr->buttons;
1397 /* do not base height/width on parent, if the parent is a */
1398 /* rebar control it could have multiple rows of toolbars */
1399 /* GetClientRect( GetParent(hwnd), &rc ); */
1400 /* cx = rc.right - rc.left; */
1401 /* cy = rc.bottom - rc.top; */
1403 TRACE("cy=%d\n", cy);
1405 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1408 if (btnPtr->fsState & TBSTATE_HIDDEN)
1410 SetRectEmpty (&btnPtr->rect);
1414 cy = infoPtr->nHeight;
1416 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1417 /* it is the actual width of the separator. This is used for */
1418 /* custom controls in toolbars. */
1419 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1420 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1421 cy = (btnPtr->iBitmap > 0) ?
1422 btnPtr->iBitmap : SEPARATOR_WIDTH;
1423 cx = infoPtr->nButtonWidth;
1426 cx = (btnPtr->iBitmap > 0) ?
1427 btnPtr->iBitmap : SEPARATOR_WIDTH;
1431 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1438 hOldFont = SelectObject (hdc, infoPtr->hFont);
1440 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1442 SelectObject (hdc, hOldFont);
1443 ReleaseDC (hwnd, hdc);
1445 /* Fudge amount measured against IE4 "menu" and "Links" */
1446 /* toolbars with native control (v4.71). - GA 8/01 */
1447 cx = sz.cx + 6 + 5 + 5;
1448 if (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))
1450 if (dwStyle & TBSTYLE_LIST)
1451 cx += infoPtr->nBitmapWidth;
1452 else if (cx < (infoPtr->nBitmapWidth+7))
1453 cx = infoPtr->nBitmapWidth+7;
1457 cx = infoPtr->nButtonWidth;
1459 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1460 cx += DDARROW_WIDTH;
1462 if (btnPtr->fsState & TBSTATE_WRAP )
1465 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1467 if (infoPtr->rcBound.left > x)
1468 infoPtr->rcBound.left = x;
1469 if (infoPtr->rcBound.right < x + cx)
1470 infoPtr->rcBound.right = x + cx;
1471 if (infoPtr->rcBound.bottom < y + cy)
1472 infoPtr->rcBound.bottom = y + cy;
1474 /* Set the toolTip only for non-hidden, non-separator button */
1475 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1479 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1480 ti.cbSize = sizeof(TTTOOLINFOA);
1482 ti.uId = btnPtr->idCommand;
1483 ti.rect = btnPtr->rect;
1484 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1488 /* btnPtr->nRow is zero based. The space between the rows is */
1489 /* also considered as a row. */
1490 btnPtr->nRow = nRows + nSepRows;
1492 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1493 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1498 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1502 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1503 /* it is the actual width of the separator. This is used for */
1504 /* custom controls in toolbars. */
1505 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1506 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1507 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1511 /* nSepRows is used to calculate the extra height follwoing */
1515 x = infoPtr->nIndent;
1517 /* Increment row number unless this is the last button */
1518 /* and it has Wrap set. */
1519 if (i != infoPtr->nNumButtons-1)
1526 /* infoPtr->nRows is the number of rows on the toolbar */
1527 infoPtr->nRows = nRows + nSepRows + 1;
1530 /********************************************************************
1531 * The following while interesting, does not match the values *
1532 * created above for the button rectangles, nor the rcBound rect. *
1533 * We will comment it out and remove it later. *
1535 * The problem showed up as heights in the pager control that was *
1537 ********************************************************************/
1539 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1541 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1542 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1543 nSepRows * (infoPtr->nBitmapHeight + 1) +
1547 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1549 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1554 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1556 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1557 TBUTTON_INFO *btnPtr;
1560 btnPtr = infoPtr->buttons;
1561 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1562 if (btnPtr->fsState & TBSTATE_HIDDEN)
1565 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1566 if (PtInRect (&btnPtr->rect, *lpPt)) {
1567 TRACE(" ON SEPARATOR %d!\n", i);
1572 if (PtInRect (&btnPtr->rect, *lpPt)) {
1573 TRACE(" ON BUTTON %d!\n", i);
1579 TRACE(" NOWHERE!\n");
1585 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1587 TBUTTON_INFO *btnPtr;
1590 if (CommandIsIndex) {
1591 TRACE("command is really index command=%d\n", idCommand);
1592 if (idCommand >= infoPtr->nNumButtons) return -1;
1595 btnPtr = infoPtr->buttons;
1596 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1597 if (btnPtr->idCommand == idCommand) {
1598 TRACE("command=%d index=%d\n", idCommand, i);
1602 TRACE("no index found for command=%d\n", idCommand);
1608 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1610 TBUTTON_INFO *btnPtr;
1613 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1616 /* check index button */
1617 btnPtr = &infoPtr->buttons[nIndex];
1618 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1619 if (btnPtr->fsState & TBSTATE_CHECKED)
1623 /* check previous buttons */
1624 nRunIndex = nIndex - 1;
1625 while (nRunIndex >= 0) {
1626 btnPtr = &infoPtr->buttons[nRunIndex];
1627 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1628 if (btnPtr->fsState & TBSTATE_CHECKED)
1636 /* check next buttons */
1637 nRunIndex = nIndex + 1;
1638 while (nRunIndex < infoPtr->nNumButtons) {
1639 btnPtr = &infoPtr->buttons[nRunIndex];
1640 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1641 if (btnPtr->fsState & TBSTATE_CHECKED)
1654 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1655 WPARAM wParam, LPARAM lParam)
1661 msg.wParam = wParam;
1662 msg.lParam = lParam;
1663 msg.time = GetMessageTime ();
1664 msg.pt.x = LOWORD(GetMessagePos ());
1665 msg.pt.y = HIWORD(GetMessagePos ());
1667 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1671 /***********************************************************************
1672 * TOOLBAR_CustomizeDialogProc
1673 * This function implements the toolbar customization dialog.
1675 static INT_PTR CALLBACK
1676 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1678 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1679 PCUSTOMBUTTON btnInfo;
1681 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1686 custInfo = (PCUSTDLG_INFO)lParam;
1687 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1695 infoPtr = custInfo->tbInfo;
1697 /* send TBN_QUERYINSERT notification */
1698 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1700 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1703 /* Send TBN_INITCUSTOMIZE notification */
1704 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1707 FIXME("TBNRF_HIDEHELP not supported\n");
1710 /* add items to 'toolbar buttons' list and check if removable */
1711 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1713 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1714 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1715 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1716 btnInfo->bVirtual = FALSE;
1717 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1719 /* send TBN_QUERYDELETE notification */
1720 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1722 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1723 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1726 /* insert separator button into 'available buttons' list */
1727 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1728 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1729 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1730 btnInfo->bVirtual = FALSE;
1731 btnInfo->bRemovable = TRUE;
1732 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1733 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1734 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1736 /* insert all buttons into dsa */
1739 /* send TBN_GETBUTTONINFO notification */
1742 nmtb.pszText = Buffer;
1745 /* Clear previous button's text */
1746 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1748 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1751 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1752 nmtb.tbButton.fsStyle, i,
1753 nmtb.tbButton.idCommand,
1754 nmtb.tbButton.iString,
1755 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1758 /* insert button into the apropriate list */
1759 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1762 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1763 btnInfo->bVirtual = FALSE;
1764 btnInfo->bRemovable = TRUE;
1766 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1767 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1768 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1772 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1773 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1776 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1777 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1779 if (lstrlenW(nmtb.pszText))
1780 lstrcpyW(btnInfo->text, nmtb.pszText);
1781 else if (nmtb.tbButton.iString >= 0 &&
1782 nmtb.tbButton.iString < infoPtr->nNumStrings)
1784 lstrcpyW(btnInfo->text,
1785 infoPtr->strings[nmtb.tbButton.iString]);
1790 /* select first item in the 'available' list */
1791 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1793 /* append 'virtual' separator button to the 'toolbar buttons' list */
1794 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1795 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1796 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1797 btnInfo->bVirtual = TRUE;
1798 btnInfo->bRemovable = FALSE;
1799 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1800 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1801 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1803 /* select last item in the 'toolbar' list */
1804 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1805 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1807 /* set focus and disable buttons */
1808 PostMessageA (hwnd, WM_USER, 0, 0);
1813 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1814 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1815 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1816 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1820 EndDialog(hwnd, FALSE);
1824 switch (LOWORD(wParam))
1826 case IDC_TOOLBARBTN_LBOX:
1827 if (HIWORD(wParam) == LBN_SELCHANGE)
1829 PCUSTOMBUTTON btnInfo;
1834 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1835 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1837 /* send TBN_QUERYINSERT notification */
1839 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1842 /* get list box item */
1843 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1845 if (index == (count - 1))
1847 /* last item (virtual separator) */
1848 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1849 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1851 else if (index == (count - 2))
1853 /* second last item (last non-virtual item) */
1854 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1855 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1857 else if (index == 0)
1860 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1861 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1865 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1866 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1869 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1873 case IDC_MOVEUP_BTN:
1875 PCUSTOMBUTTON btnInfo;
1879 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1880 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1881 TRACE("Move up: index %d\n", index);
1883 /* send TBN_QUERYINSERT notification */
1886 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1889 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1891 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1894 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1897 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1898 else if (index >= (count - 3))
1899 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1901 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1902 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1907 case IDC_MOVEDN_BTN: /* move down */
1909 PCUSTOMBUTTON btnInfo;
1913 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1914 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1915 TRACE("Move up: index %d\n", index);
1917 /* send TBN_QUERYINSERT notification */
1919 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1922 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1924 /* move button down */
1925 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1926 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1927 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1928 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1931 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1932 else if (index >= (count - 3))
1933 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1935 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1936 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1941 case IDC_REMOVE_BTN: /* remove button */
1943 PCUSTOMBUTTON btnInfo;
1946 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1948 if (LB_ERR == index)
1951 TRACE("Remove: index %d\n", index);
1953 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
1954 LB_GETITEMDATA, index, 0);
1956 /* send TBN_QUERYDELETE notification */
1957 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
1959 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1960 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1961 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1963 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1965 /* insert into 'available button' list */
1966 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1968 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1969 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1972 COMCTL32_Free (btnInfo);
1977 case IDOK: /* Add button */
1982 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1983 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1984 TRACE("Add: index %d\n", index);
1986 /* send TBN_QUERYINSERT notification */
1988 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1991 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1995 /* remove from 'available buttons' list */
1996 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1997 if (index == count-1)
1998 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
2000 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2004 PCUSTOMBUTTON btnNew;
2006 /* duplicate 'separator' button */
2007 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
2008 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2012 /* insert into 'toolbar button' list */
2013 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2014 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2015 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2017 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2023 EndDialog(hwnd, FALSE);
2033 /* delete items from 'toolbar buttons' listbox*/
2034 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2035 for (i = 0; i < count; i++)
2037 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2038 COMCTL32_Free(btnInfo);
2039 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2041 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2044 /* delete items from 'available buttons' listbox*/
2045 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2046 for (i = 0; i < count; i++)
2048 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2049 COMCTL32_Free(btnInfo);
2050 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2052 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2057 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2059 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2060 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2065 COLORREF oldText = 0;
2069 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2070 if (btnInfo == NULL)
2072 FIXME("btnInfo invalid!\n");
2076 /* set colors and select objects */
2077 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2078 if (btnInfo->bVirtual)
2079 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2081 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2082 hPen = CreatePen( PS_SOLID, 1,
2083 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2084 hOldPen = SelectObject (lpdis->hDC, hPen );
2085 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2087 /* fill background rectangle */
2088 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2089 lpdis->rcItem.right, lpdis->rcItem.bottom);
2091 /* calculate button and text rectangles */
2092 CopyRect (&rcButton, &lpdis->rcItem);
2093 InflateRect (&rcButton, -1, -1);
2094 CopyRect (&rcText, &rcButton);
2095 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2096 rcText.left = rcButton.right + 2;
2098 /* draw focus rectangle */
2099 if (lpdis->itemState & ODS_FOCUS)
2100 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2103 if (!(dwStyle & TBSTYLE_FLAT))
2104 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2106 /* draw image and text */
2107 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0) {
2108 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2109 btnInfo->btn.iBitmap));
2110 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2111 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2113 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2114 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2116 /* delete objects and reset colors */
2117 SelectObject (lpdis->hDC, hOldBrush);
2118 SelectObject (lpdis->hDC, hOldPen);
2119 SetBkColor (lpdis->hDC, oldBk);
2120 SetTextColor (lpdis->hDC, oldText);
2121 DeleteObject( hPen );
2126 case WM_MEASUREITEM:
2127 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2129 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2131 if (custInfo && custInfo->tbInfo)
2132 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2134 lpmis->itemHeight = 15 + 8; /* default height */
2146 /***********************************************************************
2147 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2151 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2153 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2154 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2155 INT nIndex = 0, nButtons, nCount;
2159 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2163 if (lpAddBmp->hInst == HINST_COMMCTRL)
2165 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2167 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2169 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2174 TRACE ("adding %d internal bitmaps!\n", nButtons);
2176 /* Windows resize all the buttons to the size of a newly added standard image */
2177 if (lpAddBmp->nID & 1)
2180 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2181 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2183 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2184 MAKELPARAM((WORD)24, (WORD)24));
2185 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2186 MAKELPARAM((WORD)31, (WORD)30));
2191 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2192 MAKELPARAM((WORD)16, (WORD)16));
2193 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2194 MAKELPARAM((WORD)22, (WORD)22));
2197 TOOLBAR_CalcToolbar (hwnd);
2201 nButtons = (INT)wParam;
2205 TRACE ("adding %d bitmaps!\n", nButtons);
2208 if (!infoPtr->cimlDef) {
2209 /* create new default image list */
2210 TRACE ("creating default image list!\n");
2212 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2213 ILC_COLOR | ILC_MASK, nButtons, 2);
2214 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2215 infoPtr->himlInt = himlDef;
2218 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2222 WARN("No default image list available\n");
2226 nCount = ImageList_GetImageCount(himlDef);
2228 /* Add bitmaps to the default image list */
2229 if (lpAddBmp->hInst == NULL)
2232 HBITMAP hOldBitmapBitmap, hOldBitmapLoad;
2233 HDC hdcImage, hdcBitmap;
2235 /* copy the bitmap before adding it so that the user's bitmap
2236 * doesn't get modified.
2238 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp);
2240 hdcImage = CreateCompatibleDC(0);
2241 hdcBitmap = CreateCompatibleDC(0);
2243 /* create new bitmap */
2244 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
2245 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID);
2246 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
2248 /* Copy the user's image */
2249 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
2250 hdcBitmap, 0, 0, SRCCOPY);
2252 SelectObject (hdcImage, hOldBitmapLoad);
2253 SelectObject (hdcBitmap, hOldBitmapBitmap);
2254 DeleteDC (hdcImage);
2255 DeleteDC (hdcBitmap);
2257 nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
2258 DeleteObject (hbmLoad);
2260 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2262 /* Add system bitmaps */
2263 switch (lpAddBmp->nID)
2265 case IDB_STD_SMALL_COLOR:
2266 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2267 MAKEINTRESOURCEA(IDB_STD_SMALL));
2268 nIndex = ImageList_AddMasked (himlDef,
2269 hbmLoad, CLR_DEFAULT);
2270 DeleteObject (hbmLoad);
2273 case IDB_STD_LARGE_COLOR:
2274 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2275 MAKEINTRESOURCEA(IDB_STD_LARGE));
2276 nIndex = ImageList_AddMasked (himlDef,
2277 hbmLoad, CLR_DEFAULT);
2278 DeleteObject (hbmLoad);
2281 case IDB_VIEW_SMALL_COLOR:
2282 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2283 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2284 nIndex = ImageList_AddMasked (himlDef,
2285 hbmLoad, CLR_DEFAULT);
2286 DeleteObject (hbmLoad);
2289 case IDB_VIEW_LARGE_COLOR:
2290 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2291 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2292 nIndex = ImageList_AddMasked (himlDef,
2293 hbmLoad, CLR_DEFAULT);
2294 DeleteObject (hbmLoad);
2297 case IDB_HIST_SMALL_COLOR:
2298 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2299 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2300 nIndex = ImageList_AddMasked (himlDef,
2301 hbmLoad, CLR_DEFAULT);
2302 DeleteObject (hbmLoad);
2305 case IDB_HIST_LARGE_COLOR:
2306 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2307 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2308 nIndex = ImageList_AddMasked (himlDef,
2309 hbmLoad, CLR_DEFAULT);
2310 DeleteObject (hbmLoad);
2314 nIndex = ImageList_GetImageCount (himlDef);
2315 ERR ("invalid imagelist!\n");
2321 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2322 nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
2323 DeleteObject (hbmLoad);
2326 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2328 if (infoPtr->nNumBitmapInfos == 0)
2330 infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
2334 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2335 infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2336 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2339 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2340 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2341 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2343 infoPtr->nNumBitmapInfos++;
2344 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2348 INT imagecount = ImageList_GetImageCount(himlDef);
2350 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2352 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",
2353 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2354 infoPtr->nNumBitmaps+nButtons,imagecount);
2356 infoPtr->nNumBitmaps = imagecount;
2359 infoPtr->nNumBitmaps += nButtons;
2362 InvalidateRect(hwnd, NULL, FALSE);
2369 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2371 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2372 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2373 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2375 TRACE("adding %d buttons!\n", wParam);
2377 nAddButtons = (UINT)wParam;
2378 nOldButtons = infoPtr->nNumButtons;
2379 nNewButtons = nOldButtons + nAddButtons;
2381 if (infoPtr->nNumButtons == 0) {
2383 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2386 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2388 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2389 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2390 nOldButtons * sizeof(TBUTTON_INFO));
2391 COMCTL32_Free (oldButtons);
2394 infoPtr->nNumButtons = nNewButtons;
2396 /* insert new button data */
2397 for (nCount = 0; nCount < nAddButtons; nCount++) {
2398 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2399 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2400 btnPtr->idCommand = lpTbb[nCount].idCommand;
2401 btnPtr->fsState = lpTbb[nCount].fsState;
2402 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2403 btnPtr->dwData = lpTbb[nCount].dwData;
2404 btnPtr->iString = lpTbb[nCount].iString;
2405 btnPtr->bHot = FALSE;
2407 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2410 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2411 ti.cbSize = sizeof (TTTOOLINFOA);
2413 ti.uId = btnPtr->idCommand;
2415 ti.lpszText = LPSTR_TEXTCALLBACKA;
2417 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2422 TOOLBAR_CalcToolbar (hwnd);
2424 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2426 InvalidateRect(hwnd, NULL, FALSE);
2433 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2435 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2436 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2437 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2439 TRACE("adding %d buttons!\n", wParam);
2441 nAddButtons = (UINT)wParam;
2442 nOldButtons = infoPtr->nNumButtons;
2443 nNewButtons = nOldButtons + nAddButtons;
2445 if (infoPtr->nNumButtons == 0) {
2447 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2450 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2452 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2453 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2454 nOldButtons * sizeof(TBUTTON_INFO));
2455 COMCTL32_Free (oldButtons);
2458 infoPtr->nNumButtons = nNewButtons;
2460 /* insert new button data */
2461 for (nCount = 0; nCount < nAddButtons; nCount++) {
2462 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2463 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2464 btnPtr->idCommand = lpTbb[nCount].idCommand;
2465 btnPtr->fsState = lpTbb[nCount].fsState;
2466 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2467 btnPtr->dwData = lpTbb[nCount].dwData;
2468 btnPtr->iString = lpTbb[nCount].iString;
2469 btnPtr->bHot = FALSE;
2471 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2474 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2475 ti.cbSize = sizeof (TTTOOLINFOW);
2477 ti.uId = btnPtr->idCommand;
2479 ti.lpszText = LPSTR_TEXTCALLBACKW;
2482 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2487 TOOLBAR_CalcToolbar (hwnd);
2489 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2491 InvalidateRect(hwnd, NULL, FALSE);
2498 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2500 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2503 if ((wParam) && (HIWORD(lParam) == 0)) {
2506 TRACE("adding string from resource!\n");
2508 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2511 TRACE("len=%d \"%s\"\n", len, szString);
2512 nIndex = infoPtr->nNumStrings;
2513 if (infoPtr->nNumStrings == 0) {
2515 COMCTL32_Alloc (sizeof(LPWSTR));
2518 LPWSTR *oldStrings = infoPtr->strings;
2520 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2521 memcpy (&infoPtr->strings[0], &oldStrings[0],
2522 sizeof(LPWSTR) * infoPtr->nNumStrings);
2523 COMCTL32_Free (oldStrings);
2526 /*COMCTL32_Alloc zeros out the allocated memory*/
2527 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2528 infoPtr->nNumStrings++;
2531 LPSTR p = (LPSTR)lParam;
2536 TRACE("adding string(s) from array!\n");
2538 nIndex = infoPtr->nNumStrings;
2541 TRACE("len=%d \"%s\"\n", len, p);
2543 if (infoPtr->nNumStrings == 0) {
2545 COMCTL32_Alloc (sizeof(LPWSTR));
2548 LPWSTR *oldStrings = infoPtr->strings;
2550 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2551 memcpy (&infoPtr->strings[0], &oldStrings[0],
2552 sizeof(LPWSTR) * infoPtr->nNumStrings);
2553 COMCTL32_Free (oldStrings);
2556 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2557 infoPtr->nNumStrings++;
2568 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2570 #define MAX_RESOURCE_STRING_LENGTH 512
2571 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2574 if ((wParam) && (HIWORD(lParam) == 0)) {
2575 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2577 TRACE("adding string from resource!\n");
2579 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2580 szString, MAX_RESOURCE_STRING_LENGTH);
2582 TRACE("len=%d %s\n", len, debugstr_w(szString));
2583 TRACE("First char: 0x%x\n", *szString);
2584 if (szString[0] == L'|')
2586 PWSTR p = szString + 1;
2588 nIndex = infoPtr->nNumStrings;
2589 while (*p != L'|' && *p != L'\0') {
2592 if (infoPtr->nNumStrings == 0) {
2593 infoPtr->strings = COMCTL32_Alloc (sizeof(LPWSTR));
2597 LPWSTR *oldStrings = infoPtr->strings;
2598 infoPtr->strings = COMCTL32_Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2599 memcpy(&infoPtr->strings[0], &oldStrings[0],
2600 sizeof(LPWSTR) * infoPtr->nNumStrings);
2601 COMCTL32_Free(oldStrings);
2604 np=COMCTL32_StrChrW (p, L'|');
2612 TRACE("len=%d %s\n", len, debugstr_w(p));
2613 infoPtr->strings[infoPtr->nNumStrings] =
2614 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2615 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2616 infoPtr->nNumStrings++;
2623 nIndex = infoPtr->nNumStrings;
2624 if (infoPtr->nNumStrings == 0) {
2626 COMCTL32_Alloc (sizeof(LPWSTR));
2629 LPWSTR *oldStrings = infoPtr->strings;
2631 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2632 memcpy (&infoPtr->strings[0], &oldStrings[0],
2633 sizeof(LPWSTR) * infoPtr->nNumStrings);
2634 COMCTL32_Free (oldStrings);
2637 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2638 infoPtr->nNumStrings++;
2642 LPWSTR p = (LPWSTR)lParam;
2647 TRACE("adding string(s) from array!\n");
2648 nIndex = infoPtr->nNumStrings;
2652 TRACE("len=%d %s\n", len, debugstr_w(p));
2653 if (infoPtr->nNumStrings == 0) {
2655 COMCTL32_Alloc (sizeof(LPWSTR));
2658 LPWSTR *oldStrings = infoPtr->strings;
2660 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2661 memcpy (&infoPtr->strings[0], &oldStrings[0],
2662 sizeof(LPWSTR) * infoPtr->nNumStrings);
2663 COMCTL32_Free (oldStrings);
2666 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2667 infoPtr->nNumStrings++;
2678 TOOLBAR_AutoSize (HWND hwnd)
2680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2681 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2687 UINT uPosFlags = SWP_NOZORDER;
2689 TRACE("resize forced, style=%lx!\n", dwStyle);
2691 parent = GetParent (hwnd);
2692 GetClientRect(parent, &parent_rect);
2694 x = parent_rect.left;
2695 y = parent_rect.top;
2697 /* FIXME: we should be able to early out if nothing */
2698 /* has changed with nWidth != parent_rect width */
2700 if (dwStyle & CCS_NORESIZE) {
2701 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2704 TOOLBAR_CalcToolbar (hwnd);
2707 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2708 TOOLBAR_CalcToolbar (hwnd);
2709 InvalidateRect( hwnd, NULL, TRUE );
2710 cy = infoPtr->nHeight;
2711 cx = infoPtr->nWidth;
2713 if (dwStyle & CCS_NOMOVEY) {
2714 GetWindowRect(hwnd, &window_rect);
2715 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2716 y = window_rect.top;
2720 if (dwStyle & CCS_NOPARENTALIGN)
2721 uPosFlags |= SWP_NOMOVE;
2723 if (!(dwStyle & CCS_NODIVIDER))
2724 cy += GetSystemMetrics(SM_CYEDGE);
2726 if (dwStyle & WS_BORDER)
2729 cy += GetSystemMetrics(SM_CYEDGE);
2730 cx += GetSystemMetrics(SM_CYEDGE);
2733 infoPtr->bAutoSize = TRUE;
2734 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2736 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2737 * the setwindowpos calls */
2738 infoPtr->bAutoSize = FALSE;
2745 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2749 return infoPtr->nNumButtons;
2754 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2758 if (infoPtr == NULL) {
2759 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2760 ERR("infoPtr == NULL!\n");
2764 infoPtr->dwStructSize = (DWORD)wParam;
2771 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2774 TBUTTON_INFO *btnPtr;
2777 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2781 btnPtr = &infoPtr->buttons[nIndex];
2782 btnPtr->iBitmap = LOWORD(lParam);
2784 /* we HAVE to erase the background, the new bitmap could be */
2786 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2793 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2795 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2796 TBUTTON_INFO *btnPtr;
2799 BOOL bChecked = FALSE;
2801 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2805 btnPtr = &infoPtr->buttons[nIndex];
2807 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2810 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2812 if (LOWORD(lParam) == FALSE)
2813 btnPtr->fsState &= ~TBSTATE_CHECKED;
2815 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2817 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2818 if (nOldIndex == nIndex)
2820 if (nOldIndex != -1)
2821 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2823 btnPtr->fsState |= TBSTATE_CHECKED;
2826 if( bChecked != LOWORD(lParam) )
2828 if (nOldIndex != -1)
2830 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2831 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2833 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2836 /* FIXME: Send a WM_NOTIFY?? */
2843 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2845 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2847 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2852 TOOLBAR_Customize (HWND hwnd)
2854 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2855 CUSTDLG_INFO custInfo;
2861 custInfo.tbInfo = infoPtr;
2862 custInfo.tbHwnd = hwnd;
2864 /* send TBN_BEGINADJUST notification */
2865 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2868 if (!(hRes = FindResourceA (COMCTL32_hModule,
2869 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2873 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2876 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2877 (LPDLGTEMPLATEA)template,
2879 TOOLBAR_CustomizeDialogProc,
2882 /* send TBN_ENDADJUST notification */
2883 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2891 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2893 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2894 INT nIndex = (INT)wParam;
2896 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2899 if ((infoPtr->hwndToolTip) &&
2900 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2903 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2904 ti.cbSize = sizeof (TTTOOLINFOA);
2906 ti.uId = infoPtr->buttons[nIndex].idCommand;
2908 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2911 if (infoPtr->nNumButtons == 1) {
2912 TRACE(" simple delete!\n");
2913 COMCTL32_Free (infoPtr->buttons);
2914 infoPtr->buttons = NULL;
2915 infoPtr->nNumButtons = 0;
2918 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2919 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2921 infoPtr->nNumButtons--;
2922 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2924 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2925 nIndex * sizeof(TBUTTON_INFO));
2928 if (nIndex < infoPtr->nNumButtons) {
2929 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2930 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2933 COMCTL32_Free (oldButtons);
2936 TOOLBAR_CalcToolbar (hwnd);
2938 InvalidateRect (hwnd, NULL, TRUE);
2945 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2948 TBUTTON_INFO *btnPtr;
2952 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2956 btnPtr = &infoPtr->buttons[nIndex];
2958 bState = btnPtr->fsState & TBSTATE_ENABLED;
2960 /* update the toolbar button state */
2961 if(LOWORD(lParam) == FALSE) {
2962 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2964 btnPtr->fsState |= TBSTATE_ENABLED;
2967 /* redraw the button only if the state of the button changed */
2968 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2970 InvalidateRect(hwnd, &btnPtr->rect,
2971 TOOLBAR_HasText(infoPtr, btnPtr));
2978 static inline LRESULT
2979 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2983 return infoPtr->bAnchor;
2988 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2990 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2993 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2997 return infoPtr->buttons[nIndex].iBitmap;
3001 static inline LRESULT
3002 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3004 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3009 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3012 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3013 INT nIndex = (INT)wParam;
3014 TBUTTON_INFO *btnPtr;
3016 if (infoPtr == NULL)
3022 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3025 btnPtr = &infoPtr->buttons[nIndex];
3026 lpTbb->iBitmap = btnPtr->iBitmap;
3027 lpTbb->idCommand = btnPtr->idCommand;
3028 lpTbb->fsState = btnPtr->fsState;
3029 lpTbb->fsStyle = btnPtr->fsStyle;
3030 lpTbb->bReserved[0] = 0;
3031 lpTbb->bReserved[1] = 0;
3032 lpTbb->dwData = btnPtr->dwData;
3033 lpTbb->iString = btnPtr->iString;
3040 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3042 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3043 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3044 TBUTTON_INFO *btnPtr;
3047 if (infoPtr == NULL)
3049 if (lpTbInfo == NULL)
3051 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3054 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3055 lpTbInfo->dwMask & 0x80000000);
3059 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3061 if (lpTbInfo->dwMask & TBIF_COMMAND)
3062 lpTbInfo->idCommand = btnPtr->idCommand;
3063 if (lpTbInfo->dwMask & TBIF_IMAGE)
3064 lpTbInfo->iImage = btnPtr->iBitmap;
3065 if (lpTbInfo->dwMask & TBIF_LPARAM)
3066 lpTbInfo->lParam = btnPtr->dwData;
3067 if (lpTbInfo->dwMask & TBIF_SIZE)
3068 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3069 if (lpTbInfo->dwMask & TBIF_STATE)
3070 lpTbInfo->fsState = btnPtr->fsState;
3071 if (lpTbInfo->dwMask & TBIF_STYLE)
3072 lpTbInfo->fsStyle = btnPtr->fsStyle;
3073 if (lpTbInfo->dwMask & TBIF_TEXT) {
3074 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3075 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3082 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3084 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3085 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3086 TBUTTON_INFO *btnPtr;
3089 if (infoPtr == NULL)
3091 if (lpTbInfo == NULL)
3093 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3096 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3097 lpTbInfo->dwMask & 0x80000000);
3101 btnPtr = &infoPtr->buttons[nIndex];
3106 if (lpTbInfo->dwMask & TBIF_COMMAND)
3107 lpTbInfo->idCommand = btnPtr->idCommand;
3108 if (lpTbInfo->dwMask & TBIF_IMAGE)
3109 lpTbInfo->iImage = btnPtr->iBitmap;
3110 if (lpTbInfo->dwMask & TBIF_LPARAM)
3111 lpTbInfo->lParam = btnPtr->dwData;
3112 if (lpTbInfo->dwMask & TBIF_SIZE)
3113 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3114 if (lpTbInfo->dwMask & TBIF_STATE)
3115 lpTbInfo->fsState = btnPtr->fsState;
3116 if (lpTbInfo->dwMask & TBIF_STYLE)
3117 lpTbInfo->fsStyle = btnPtr->fsStyle;
3118 if (lpTbInfo->dwMask & TBIF_TEXT) {
3119 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3120 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3128 TOOLBAR_GetButtonSize (HWND hwnd)
3130 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3132 if (infoPtr->nNumButtons > 0)
3133 return MAKELONG((WORD)infoPtr->nButtonWidth,
3134 (WORD)infoPtr->nButtonHeight);
3136 return MAKELONG(8,7);
3141 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3150 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3154 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3156 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3157 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3162 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3164 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3171 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3175 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3177 strcpyW ((LPWSTR)lParam, lpText);
3179 return strlenW (lpText);
3184 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3186 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0);
3190 inline static LRESULT
3191 TOOLBAR_GetExtendedStyle (HWND hwnd)
3193 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3195 return infoPtr->dwExStyle;
3200 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3202 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0);
3207 TOOLBAR_GetHotItem (HWND hwnd)
3209 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3211 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3214 if (infoPtr->nHotItem < 0)
3217 return (LRESULT)infoPtr->nHotItem;
3222 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3224 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), 0);
3228 /* << TOOLBAR_GetInsertMark >> */
3229 /* << TOOLBAR_GetInsertMarkColor >> */
3233 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3235 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3236 TBUTTON_INFO *btnPtr;
3240 if (infoPtr == NULL)
3242 nIndex = (INT)wParam;
3243 btnPtr = &infoPtr->buttons[nIndex];
3244 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3246 lpRect = (LPRECT)lParam;
3249 if (btnPtr->fsState & TBSTATE_HIDDEN)
3252 lpRect->left = btnPtr->rect.left;
3253 lpRect->right = btnPtr->rect.right;
3254 lpRect->bottom = btnPtr->rect.bottom;
3255 lpRect->top = btnPtr->rect.top;
3262 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3265 LPSIZE lpSize = (LPSIZE)lParam;
3270 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3271 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3273 TRACE("maximum size %ld x %ld\n",
3274 infoPtr->rcBound.right - infoPtr->rcBound.left,
3275 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3281 /* << TOOLBAR_GetObject >> */
3285 TOOLBAR_GetPadding (HWND hwnd)
3287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3290 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3291 return (LRESULT) oldPad;
3296 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3298 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3299 TBUTTON_INFO *btnPtr;
3303 if (infoPtr == NULL)
3305 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3306 btnPtr = &infoPtr->buttons[nIndex];
3307 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3309 lpRect = (LPRECT)lParam;
3313 lpRect->left = btnPtr->rect.left;
3314 lpRect->right = btnPtr->rect.right;
3315 lpRect->bottom = btnPtr->rect.bottom;
3316 lpRect->top = btnPtr->rect.top;
3323 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3327 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3328 return infoPtr->nRows;
3335 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3340 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3344 return infoPtr->buttons[nIndex].fsState;
3349 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3351 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3354 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3358 return infoPtr->buttons[nIndex].fsStyle;
3363 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3367 if (infoPtr == NULL)
3370 return infoPtr->nMaxTextRows;
3375 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3377 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3379 if (infoPtr == NULL)
3381 return (LRESULT)infoPtr->hwndToolTip;
3386 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3390 TRACE("%s hwnd=%p stub!\n",
3391 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3393 return infoPtr->bUnicode;
3397 inline static LRESULT
3398 TOOLBAR_GetVersion (HWND hwnd)
3400 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3401 return infoPtr->iVersion;
3406 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3409 TBUTTON_INFO *btnPtr;
3414 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3418 btnPtr = &infoPtr->buttons[nIndex];
3419 if (LOWORD(lParam) == FALSE)
3420 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3422 btnPtr->fsState |= TBSTATE_HIDDEN;
3424 TOOLBAR_CalcToolbar (hwnd);
3426 InvalidateRect (hwnd, NULL, TRUE);
3432 inline static LRESULT
3433 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3435 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3440 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3442 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3443 TBUTTON_INFO *btnPtr;
3446 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3450 btnPtr = &infoPtr->buttons[nIndex];
3451 if (LOWORD(lParam) == FALSE)
3452 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3454 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3456 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3463 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3465 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3466 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3467 INT nIndex = (INT)wParam;
3468 TBUTTON_INFO *oldButtons;
3473 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3476 /* EPP: this seems to be an undocumented call (from my IE4)
3477 * I assume in that case that:
3478 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3479 * - index of insertion is at the end of existing buttons
3480 * I only see this happen with nIndex == -1, but it could have a special
3481 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3483 nIndex = infoPtr->nNumButtons;
3485 } else if (nIndex < 0)
3488 /* If the string passed is not an index, assume address of string
3489 and do our own AddString */
3490 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3494 TRACE("string %s passed instead of index, adding string\n",
3495 debugstr_a((LPSTR)lpTbb->iString));
3496 len = strlen((LPSTR)lpTbb->iString) + 2;
3497 ptr = COMCTL32_Alloc(len);
3498 strcpy(ptr, (LPSTR)lpTbb->iString);
3499 ptr[len - 1] = 0; /* ended by two '\0' */
3500 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3504 TRACE("inserting button index=%d\n", nIndex);
3505 if (nIndex > infoPtr->nNumButtons) {
3506 nIndex = infoPtr->nNumButtons;
3507 TRACE("adjust index=%d\n", nIndex);
3510 oldButtons = infoPtr->buttons;
3511 infoPtr->nNumButtons++;
3512 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3513 /* pre insert copy */
3515 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3516 nIndex * sizeof(TBUTTON_INFO));
3519 /* insert new button */
3520 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3521 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3522 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3523 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3524 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3525 /* if passed string and not index, then add string */
3526 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3527 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3530 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3532 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3535 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3536 ti.cbSize = sizeof (TTTOOLINFOA);
3538 ti.uId = lpTbb->idCommand;
3540 ti.lpszText = LPSTR_TEXTCALLBACKA;
3542 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3546 /* post insert copy */
3547 if (nIndex < infoPtr->nNumButtons - 1) {
3548 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3549 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3552 COMCTL32_Free (oldButtons);
3554 TOOLBAR_CalcToolbar (hwnd);
3556 InvalidateRect (hwnd, NULL, TRUE);
3563 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3565 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3566 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3567 INT nIndex = (INT)wParam;
3568 TBUTTON_INFO *oldButtons;
3573 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3576 /* EPP: this seems to be an undocumented call (from my IE4)
3577 * I assume in that case that:
3578 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3579 * - index of insertion is at the end of existing buttons
3580 * I only see this happen with nIndex == -1, but it could have a special
3581 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3583 nIndex = infoPtr->nNumButtons;
3585 } else if (nIndex < 0)
3588 /* If the string passed is not an index, assume address of string
3589 and do our own AddString */
3590 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3594 TRACE("string %s passed instead of index, adding string\n",
3595 debugstr_w((LPWSTR)lpTbb->iString));
3596 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3597 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3598 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3599 ptr[len - 1] = 0; /* ended by two '\0' */
3600 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3604 TRACE("inserting button index=%d\n", nIndex);
3605 if (nIndex > infoPtr->nNumButtons) {
3606 nIndex = infoPtr->nNumButtons;
3607 TRACE("adjust index=%d\n", nIndex);
3610 oldButtons = infoPtr->buttons;
3611 infoPtr->nNumButtons++;
3612 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3613 /* pre insert copy */
3615 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3616 nIndex * sizeof(TBUTTON_INFO));
3619 /* insert new button */
3620 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3621 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3622 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3623 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3624 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3625 /* if passed string and not index, then add string */
3626 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3627 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3630 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3632 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3635 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3636 ti.cbSize = sizeof (TTTOOLINFOW);
3638 ti.uId = lpTbb->idCommand;
3640 ti.lpszText = LPSTR_TEXTCALLBACKW;
3642 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3646 /* post insert copy */
3647 if (nIndex < infoPtr->nNumButtons - 1) {
3648 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3649 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3652 COMCTL32_Free (oldButtons);
3654 TOOLBAR_CalcToolbar (hwnd);
3656 InvalidateRect (hwnd, NULL, TRUE);
3662 /* << TOOLBAR_InsertMarkHitTest >> */
3666 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3671 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3675 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3680 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3682 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3685 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3689 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3694 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3696 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3699 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3703 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3708 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3710 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3713 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3717 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3722 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3724 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3727 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3731 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3736 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3738 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3741 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3745 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3749 /* << TOOLBAR_LoadImages >> */
3750 /* << TOOLBAR_MapAccelerator >> */
3751 /* << TOOLBAR_MarkButton >> */
3752 /* << TOOLBAR_MoveButton >> */
3756 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3758 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3759 TBUTTON_INFO *btnPtr;
3762 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3766 btnPtr = &infoPtr->buttons[nIndex];
3767 if (LOWORD(lParam) == FALSE)
3768 btnPtr->fsState &= ~TBSTATE_PRESSED;
3770 btnPtr->fsState |= TBSTATE_PRESSED;
3772 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3779 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3781 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3782 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3784 int i = 0, nOldButtons = 0, pos = 0;
3785 HIMAGELIST himlDef = 0;
3787 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3788 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3789 lpReplace->nButtons);
3791 if (lpReplace->hInstOld == HINST_COMMCTRL)
3793 FIXME("changing standard bitmaps not implemented\n");
3796 else if (lpReplace->hInstOld != 0)
3798 FIXME("resources not in the current module not implemented\n");
3803 hBitmap = (HBITMAP) lpReplace->nIDNew;
3806 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3807 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3808 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3809 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3810 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3812 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3813 nOldButtons = tbi->nButtons;
3814 tbi->nButtons = lpReplace->nButtons;
3815 tbi->hInst = lpReplace->hInstNew;
3816 tbi->nID = lpReplace->nIDNew;
3817 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3820 pos += tbi->nButtons;
3823 if (nOldButtons == 0)
3825 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3829 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
3831 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
3834 himlDef = GETDEFIMAGELIST(infoPtr, 0);
3835 for (i = pos + nOldButtons - 1; i >= pos; i--) {
3836 ImageList_Remove(himlDef, i);
3841 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad;
3842 HDC hdcImage, hdcBitmap;
3844 /* copy the bitmap before adding it so that the user's bitmap
3845 * doesn't get modified.
3847 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp);
3849 hdcImage = CreateCompatibleDC(0);
3850 hdcBitmap = CreateCompatibleDC(0);
3852 /* create new bitmap */
3853 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
3854 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap);
3855 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad);
3857 /* Copy the user's image */
3858 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight,
3859 hdcBitmap, 0, 0, SRCCOPY);
3861 SelectObject (hdcImage, hOldBitmapLoad);
3862 SelectObject (hdcBitmap, hOldBitmapBitmap);
3863 DeleteDC (hdcImage);
3864 DeleteDC (hdcBitmap);
3866 ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
3867 DeleteObject (hbmLoad);
3870 InvalidateRect(hwnd, NULL, FALSE);
3876 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3879 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3880 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3882 if (lpSave == NULL) return 0;
3885 /* save toolbar information */
3886 FIXME("save to \"%s\" \"%s\"\n",
3887 lpSave->pszSubKey, lpSave->pszValueName);
3892 /* restore toolbar information */
3894 FIXME("restore from \"%s\" \"%s\"\n",
3895 lpSave->pszSubKey, lpSave->pszValueName);
3906 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3909 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3910 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3916 /* save toolbar information */
3917 FIXME("save to \"%s\" \"%s\"\n",
3918 lpSave->pszSubKey, lpSave->pszValueName);
3923 /* restore toolbar information */
3925 FIXME("restore from \"%s\" \"%s\"\n",
3926 lpSave->pszSubKey, lpSave->pszValueName);
3937 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3939 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3940 BOOL bOldAnchor = infoPtr->bAnchor;
3942 infoPtr->bAnchor = (BOOL)wParam;
3944 return (LRESULT)bOldAnchor;
3949 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3951 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3952 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
3954 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3957 if (infoPtr->nNumButtons > 0)
3958 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3959 infoPtr->nNumButtons,
3960 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3961 LOWORD(lParam), HIWORD(lParam));
3963 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3964 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3967 /* uses image list internals directly */
3969 himlDef->cx = infoPtr->nBitmapWidth;
3970 himlDef->cy = infoPtr->nBitmapHeight;
3978 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3980 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3981 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3982 TBUTTON_INFO *btnPtr;
3987 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3990 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3991 lptbbi->dwMask & 0x80000000);
3995 btnPtr = &infoPtr->buttons[nIndex];
3996 if (lptbbi->dwMask & TBIF_COMMAND)
3997 btnPtr->idCommand = lptbbi->idCommand;
3998 if (lptbbi->dwMask & TBIF_IMAGE)
3999 btnPtr->iBitmap = lptbbi->iImage;
4000 if (lptbbi->dwMask & TBIF_LPARAM)
4001 btnPtr->dwData = lptbbi->lParam;
4002 /* if (lptbbi->dwMask & TBIF_SIZE) */
4003 /* btnPtr->cx = lptbbi->cx; */
4004 if (lptbbi->dwMask & TBIF_STATE)
4005 btnPtr->fsState = lptbbi->fsState;
4006 if (lptbbi->dwMask & TBIF_STYLE)
4007 btnPtr->fsStyle = lptbbi->fsStyle;
4009 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4010 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4011 /* iString is index, zero it to make Str_SetPtr succeed */
4014 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4021 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
4023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4024 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
4025 TBUTTON_INFO *btnPtr;
4030 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4033 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
4034 lptbbi->dwMask & 0x80000000);
4038 btnPtr = &infoPtr->buttons[nIndex];
4039 if (lptbbi->dwMask & TBIF_COMMAND)
4040 btnPtr->idCommand = lptbbi->idCommand;
4041 if (lptbbi->dwMask & TBIF_IMAGE)
4042 btnPtr->iBitmap = lptbbi->iImage;
4043 if (lptbbi->dwMask & TBIF_LPARAM)
4044 btnPtr->dwData = lptbbi->lParam;
4045 /* if (lptbbi->dwMask & TBIF_SIZE) */
4046 /* btnPtr->cx = lptbbi->cx; */
4047 if (lptbbi->dwMask & TBIF_STATE)
4048 btnPtr->fsState = lptbbi->fsState;
4049 if (lptbbi->dwMask & TBIF_STYLE)
4050 btnPtr->fsStyle = lptbbi->fsStyle;
4052 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
4053 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
4054 /* iString is index, zero it to make Str_SetPtr succeed */
4056 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4063 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4065 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4066 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4068 if ((cx < 0) || (cy < 0))
4070 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4074 /* The documentation claims you can only change the button size before
4075 * any button has been added. But this is wrong.
4076 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4077 * it to the toolbar, and it checks that the return value is nonzero - mjm
4078 * Further testing shows that we must actually perform the change too.
4081 * The documentation also does not mention that if 0 is supplied for
4082 * either size, the system changes it to the default of 24 wide and
4083 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4085 infoPtr->nButtonWidth = (cx) ? cx : 24;
4086 infoPtr->nButtonHeight = (cy) ? cy : 22;
4092 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4096 if (infoPtr == NULL) {
4097 TRACE("Toolbar not initialized yet?????\n");
4101 /* if setting to current values, ignore */
4102 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4103 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4104 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4105 infoPtr->cxMin, infoPtr->cxMax);
4109 /* save new values */
4110 infoPtr->cxMin = (INT)LOWORD(lParam);
4111 infoPtr->cxMax = (INT)HIWORD(lParam);
4113 /* if both values are 0 then we are done */
4115 TRACE("setting both min and max to 0, norecalc\n");
4119 /* otherwise we need to recalc the toolbar and in some cases
4120 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4121 which doesn't actually draw - GA). */
4122 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4123 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4125 TOOLBAR_CalcToolbar (hwnd);
4127 InvalidateRect (hwnd, NULL, TRUE);
4134 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4137 INT nIndex = (INT)wParam;
4139 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4142 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4144 if (infoPtr->hwndToolTip) {
4146 FIXME("change tool tip!\n");
4155 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4157 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4158 HIMAGELIST himl = (HIMAGELIST)lParam;
4159 HIMAGELIST himlTemp;
4162 if (infoPtr->iVersion >= 5)
4165 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4166 &infoPtr->cimlDis, himl, id);
4168 /* FIXME: redraw ? */
4170 return (LRESULT)himlTemp;
4175 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4180 dwTemp = infoPtr->dwDTFlags;
4181 infoPtr->dwDTFlags =
4182 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4184 return (LRESULT)dwTemp;
4188 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4193 dwTemp = infoPtr->dwExStyle;
4194 infoPtr->dwExStyle = (DWORD)lParam;
4196 if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
4197 TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
4198 FIXME("Extended style not implemented %s %s\n",
4199 (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
4200 "TBSTYLE_EX_MIXEDBUTTONS" : "",
4201 (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
4202 "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
4205 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4206 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4207 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4209 return (LRESULT)dwTemp;
4214 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4216 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4217 HIMAGELIST himlTemp;
4218 HIMAGELIST himl = (HIMAGELIST)lParam;
4221 if (infoPtr->iVersion >= 5)
4224 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4225 &infoPtr->cimlHot, himl, id);
4227 /* FIXME: redraw ? */
4229 return (LRESULT)himlTemp;
4234 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4237 INT nOldHotItem = infoPtr->nHotItem;
4238 TBUTTON_INFO *btnPtr;
4240 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4243 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4246 infoPtr->nHotItem = (INT)wParam;
4247 if ((INT)wParam >=0)
4249 btnPtr = &infoPtr->buttons[(INT)wParam];
4250 btnPtr->bHot = TRUE;
4251 InvalidateRect (hwnd, &btnPtr->rect,
4252 TOOLBAR_HasText(infoPtr, btnPtr));
4256 btnPtr = &infoPtr->buttons[nOldHotItem];
4257 btnPtr->bHot = FALSE;
4258 InvalidateRect (hwnd, &btnPtr->rect,
4259 TOOLBAR_HasText(infoPtr, btnPtr));
4263 if (nOldHotItem < 0)
4266 return (LRESULT)nOldHotItem;
4271 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4274 HIMAGELIST himlTemp;
4275 HIMAGELIST himl = (HIMAGELIST)lParam;
4278 if (infoPtr->iVersion >= 5)
4281 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4282 &infoPtr->cimlDef, himl, id);
4284 infoPtr->nNumBitmaps = 0;
4285 for (i = 0; i < infoPtr->cimlDef; i++)
4286 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4288 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4289 &infoPtr->nBitmapHeight);
4290 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4291 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4292 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4294 /* FIXME: redraw ? */
4295 InvalidateRect(hwnd, NULL, TRUE);
4297 return (LRESULT)himlTemp;
4302 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4306 infoPtr->nIndent = (INT)wParam;
4310 /* process only on indent changing */
4311 if(infoPtr->nIndent != (INT)wParam)
4313 infoPtr->nIndent = (INT)wParam;
4314 TOOLBAR_CalcToolbar (hwnd);
4315 InvalidateRect(hwnd, NULL, FALSE);
4322 /* << TOOLBAR_SetInsertMark >> */
4326 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4330 infoPtr->clrInsertMark = (COLORREF)lParam;
4332 /* FIXME : redraw ??*/
4339 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4341 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4343 if (infoPtr == NULL)
4346 infoPtr->nMaxTextRows = (INT)wParam;
4353 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4358 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4359 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4360 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4361 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4362 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4363 return (LRESULT) oldPad;
4368 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4370 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4375 if (infoPtr == NULL)
4377 hwndOldNotify = infoPtr->hwndNotify;
4378 infoPtr->hwndNotify = (HWND)wParam;
4380 return (LRESULT)hwndOldNotify;
4385 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4387 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4388 LPRECT lprc = (LPRECT)lParam;
4392 if (LOWORD(wParam) > 1) {
4393 FIXME("multiple rows not supported!\n");
4396 if(infoPtr->nRows != LOWORD(wParam))
4398 infoPtr->nRows = LOWORD(wParam);
4400 /* recalculate toolbar */
4401 TOOLBAR_CalcToolbar (hwnd);
4403 /* repaint toolbar */
4404 InvalidateRect(hwnd, NULL, FALSE);
4407 /* return bounding rectangle */
4409 lprc->left = infoPtr->rcBound.left;
4410 lprc->right = infoPtr->rcBound.right;
4411 lprc->top = infoPtr->rcBound.top;
4412 lprc->bottom = infoPtr->rcBound.bottom;
4420 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4422 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4423 TBUTTON_INFO *btnPtr;
4426 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4430 btnPtr = &infoPtr->buttons[nIndex];
4432 /* if hidden state has changed the invalidate entire window and recalc */
4433 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4434 btnPtr->fsState = LOWORD(lParam);
4435 TOOLBAR_CalcToolbar (hwnd);
4436 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4440 /* process state changing if current state doesn't match new state */
4441 if(btnPtr->fsState != LOWORD(lParam))
4443 btnPtr->fsState = LOWORD(lParam);
4444 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4453 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4455 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4456 TBUTTON_INFO *btnPtr;
4459 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4463 btnPtr = &infoPtr->buttons[nIndex];
4465 /* process style change if current style doesn't match new style */
4466 if(btnPtr->fsStyle != LOWORD(lParam))
4468 btnPtr->fsStyle = LOWORD(lParam);
4469 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4472 if (infoPtr->hwndToolTip) {
4473 FIXME("change tool tip!\n");
4481 inline static LRESULT
4482 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4486 if (infoPtr == NULL)
4488 infoPtr->hwndToolTip = (HWND)wParam;
4494 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4496 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4499 TRACE("%s hwnd=%p stub!\n",
4500 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4502 bTemp = infoPtr->bUnicode;
4503 infoPtr->bUnicode = (BOOL)wParam;
4510 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4512 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4514 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4515 comctl32_color.clrBtnHighlight :
4516 infoPtr->clrBtnHighlight;
4517 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4518 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4524 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4526 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4528 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4529 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4530 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4532 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4533 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4534 InvalidateRect(hwnd, 0, 0);
4540 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4542 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4543 INT iOldVersion = infoPtr->iVersion;
4545 infoPtr->iVersion = iVersion;
4547 if (infoPtr->iVersion >= 5)
4548 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4554 /*********************************************************************/
4556 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4557 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4558 /* based on relay traces of the native control and IE 5.5 */
4560 /*********************************************************************/
4562 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4565 INT nOldHotItem = infoPtr->nHotItem;
4566 TBUTTON_INFO *btnPtr;
4568 NMTBHOTITEM nmhotitem;
4570 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4573 infoPtr->nHotItem = (INT)wParam;
4574 if (nOldHotItem != infoPtr->nHotItem) {
4575 nmhotitem.dwFlags = (DWORD)lParam;
4576 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4577 nmhotitem.idOld = (nOldHotItem >= 0) ?
4578 infoPtr->buttons[nOldHotItem].idCommand : 0;
4579 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4580 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4581 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4582 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4584 if ((INT)wParam >=0) {
4585 btnPtr = &infoPtr->buttons[(INT)wParam];
4586 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4587 InvalidateRect (hwnd, &btnPtr->rect,
4588 TOOLBAR_HasText(infoPtr, btnPtr));
4590 if (nOldHotItem>=0) {
4591 btnPtr = &infoPtr->buttons[nOldHotItem];
4592 btnPtr->bHot = FALSE;
4593 InvalidateRect (hwnd, &btnPtr->rect,
4594 TOOLBAR_HasText(infoPtr, btnPtr));
4597 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4598 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4600 if (nOldHotItem < 0)
4603 return (LRESULT)nOldHotItem;
4608 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4611 LPSIZE lpsize = (LPSIZE)lParam;
4617 * Testing shows the following:
4618 * wParam = 0 adjust cx value
4619 * = 1 set cy value to max size.
4620 * lParam pointer to SIZE structure
4623 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4624 wParam, lParam, lpsize->cx, lpsize->cy);
4628 if (lpsize->cx == -1) {
4629 /* **** this is wrong, native measures each button and sets it */
4630 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4632 else if(HIWORD(lpsize->cx)) {
4634 HWND hwndParent = GetParent(hwnd);
4636 InvalidateRect(hwnd, 0, 1);
4637 GetWindowRect(hwnd, &rc);
4638 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4639 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n",
4640 rc.left, rc.top, rc.right, rc.bottom);
4641 lpsize->cx = max(rc.right-rc.left,
4642 infoPtr->rcBound.right - infoPtr->rcBound.left);
4645 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4649 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4650 /* lpsize->cy = infoPtr->nHeight; */
4653 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4657 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4658 lpsize->cx, lpsize->cy);
4664 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4666 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4667 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4670 /* initialize info structure */
4671 infoPtr->nButtonHeight = 22;
4672 infoPtr->nButtonWidth = 24;
4673 infoPtr->nBitmapHeight = 15;
4674 infoPtr->nBitmapWidth = 16;
4676 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4678 infoPtr->nMaxTextRows = 1;
4679 infoPtr->cxMin = -1;
4680 infoPtr->cxMax = -1;
4681 infoPtr->nNumBitmaps = 0;
4682 infoPtr->nNumStrings = 0;
4684 infoPtr->bCaptured = FALSE;
4685 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4686 infoPtr->nButtonDown = -1;
4687 infoPtr->nOldHit = -1;
4688 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4689 infoPtr->hwndNotify = GetParent (hwnd);
4690 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4691 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4692 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4693 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4694 infoPtr->iVersion = 0;
4695 infoPtr->hwndSelf = hwnd;
4696 infoPtr->bDoRedraw = TRUE;
4697 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4698 infoPtr->clrBtnShadow = CLR_DEFAULT;
4699 infoPtr->szPadding.cx = 7;
4700 infoPtr->szPadding.cy = 6;
4701 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4703 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4704 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4706 if (dwStyle & TBSTYLE_TOOLTIPS) {
4707 /* Create tooltip control */
4708 infoPtr->hwndToolTip =
4709 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4710 CW_USEDEFAULT, CW_USEDEFAULT,
4711 CW_USEDEFAULT, CW_USEDEFAULT,
4714 /* Send NM_TOOLTIPSCREATED notification */
4715 if (infoPtr->hwndToolTip) {
4716 NMTOOLTIPSCREATED nmttc;
4718 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4720 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4721 NM_TOOLTIPSCREATED);
4725 TOOLBAR_CheckStyle (hwnd, dwStyle);
4727 TOOLBAR_CalcToolbar(hwnd);
4734 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4738 /* delete tooltip control */
4739 if (infoPtr->hwndToolTip)
4740 DestroyWindow (infoPtr->hwndToolTip);
4742 /* delete button data */
4743 if (infoPtr->buttons)
4744 COMCTL32_Free (infoPtr->buttons);
4746 /* delete strings */
4747 if (infoPtr->strings) {
4749 for (i = 0; i < infoPtr->nNumStrings; i++)
4750 if (infoPtr->strings[i])
4751 COMCTL32_Free (infoPtr->strings[i]);
4753 COMCTL32_Free (infoPtr->strings);
4756 /* destroy internal image list */
4757 if (infoPtr->himlInt)
4758 ImageList_Destroy (infoPtr->himlInt);
4760 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
4761 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
4762 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
4764 /* delete default font */
4766 DeleteObject (infoPtr->hDefaultFont);
4768 /* free toolbar info data */
4769 COMCTL32_Free (infoPtr);
4770 SetWindowLongA (hwnd, 0, 0);
4777 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4779 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4780 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4781 NMTBCUSTOMDRAW tbcd;
4785 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4786 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4787 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4788 tbcd.nmcd.hdc = (HDC)wParam;
4789 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4790 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4792 /* FIXME: in general the return flags *can* be or'ed together */
4793 switch (infoPtr->dwBaseCustDraw)
4795 case CDRF_DODEFAULT:
4797 case CDRF_SKIPDEFAULT:
4800 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4805 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4806 * to my parent for processing.
4808 if (infoPtr->bTransparent) {
4810 HDC hdc = (HDC)wParam;
4815 parent = GetParent(hwnd);
4816 MapWindowPoints(hwnd, parent, &pt, 1);
4817 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4818 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4819 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4822 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4824 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
4825 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
4826 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4827 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4828 tbcd.nmcd.hdc = (HDC)wParam;
4829 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4830 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4831 switch (infoPtr->dwBaseCustDraw)
4833 case CDRF_DODEFAULT:
4835 case CDRF_SKIPDEFAULT:
4838 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4847 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4849 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4851 return (LRESULT)infoPtr->hFont;
4856 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4858 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4859 TBUTTON_INFO *btnPtr;
4863 pt.x = (INT)LOWORD(lParam);
4864 pt.y = (INT)HIWORD(lParam);
4865 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4868 btnPtr = &infoPtr->buttons[nHit];
4869 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4872 infoPtr->bCaptured = TRUE;
4873 infoPtr->nButtonDown = nHit;
4875 btnPtr->fsState |= TBSTATE_PRESSED;
4877 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4880 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4881 TOOLBAR_Customize (hwnd);
4888 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4891 TBUTTON_INFO *btnPtr;
4896 if (infoPtr->hwndToolTip)
4897 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4898 WM_LBUTTONDOWN, wParam, lParam);
4900 pt.x = (INT)LOWORD(lParam);
4901 pt.y = (INT)HIWORD(lParam);
4902 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4906 btnPtr = &infoPtr->buttons[nHit];
4907 infoPtr->nOldHit = nHit;
4909 CopyRect(&arrowRect, &btnPtr->rect);
4910 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4912 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4913 if ((btnPtr->fsState & TBSTATE_ENABLED) && (btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4914 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4915 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4919 * this time we must force a Redraw, so the btn is
4920 * painted down before CaptureChanged repaints it up
4922 RedrawWindow(hwnd,&btnPtr->rect,0,
4923 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4925 nmtb.iItem = btnPtr->idCommand;
4926 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4929 memset(&nmtb.rcButton, 0, sizeof(RECT));
4930 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4932 if (res != TBDDRET_TREATPRESSED)
4933 /* ??? guess (GA) */
4935 /* otherwise drop through and process as pushed */
4937 /* SetCapture (hwnd); */
4938 infoPtr->bCaptured = TRUE;
4939 infoPtr->nButtonDown = nHit;
4941 btnPtr->fsState |= TBSTATE_PRESSED;
4942 btnPtr->bHot = FALSE;
4944 if (btnPtr->fsState & TBSTATE_ENABLED)
4945 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
4949 /* native issues the TBN_BEGINDRAG here */
4950 nmtb.iItem = btnPtr->idCommand;
4951 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4952 nmtb.tbButton.idCommand = btnPtr->idCommand;
4953 nmtb.tbButton.fsState = btnPtr->fsState;
4954 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4955 nmtb.tbButton.dwData = btnPtr->dwData;
4956 nmtb.tbButton.iString = btnPtr->iString;
4957 nmtb.cchText = 0; /* !!! not correct */
4958 nmtb.pszText = 0; /* !!! not correct */
4959 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4967 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4969 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4970 TBUTTON_INFO *btnPtr;
4974 BOOL bSendMessage = TRUE;
4979 if (infoPtr->hwndToolTip)
4980 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4981 WM_LBUTTONUP, wParam, lParam);
4983 pt.x = (INT)LOWORD(lParam);
4984 pt.y = (INT)HIWORD(lParam);
4985 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4987 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4988 /* if the cursor is still inside of the toolbar */
4989 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4990 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4992 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4993 btnPtr->fsState &= ~TBSTATE_PRESSED;
4995 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4996 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4997 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4999 if (nOldIndex == nHit)
5000 bSendMessage = FALSE;
5001 if ((nOldIndex != nHit) &&
5003 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5004 btnPtr->fsState |= TBSTATE_CHECKED;
5007 if (btnPtr->fsState & TBSTATE_CHECKED)
5008 btnPtr->fsState &= ~TBSTATE_CHECKED;
5010 btnPtr->fsState |= TBSTATE_CHECKED;
5014 if (nOldIndex != -1)
5016 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
5017 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
5021 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5022 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5023 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5025 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5027 infoPtr->nButtonDown = -1;
5029 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5030 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
5031 NM_RELEASEDCAPTURE);
5033 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
5036 nmtb.iItem = btnPtr->idCommand;
5037 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
5038 nmtb.tbButton.idCommand = btnPtr->idCommand;
5039 nmtb.tbButton.fsState = btnPtr->fsState;
5040 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
5041 nmtb.tbButton.dwData = btnPtr->dwData;
5042 nmtb.tbButton.iString = btnPtr->iString;
5043 nmtb.cchText = 0; /* !!! not correct */
5044 nmtb.pszText = 0; /* !!! not correct */
5045 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5048 if (btnPtr->fsState & TBSTATE_ENABLED)
5050 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
5051 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
5053 /* !!! Undocumented - toolbar at 4.71 level and above sends
5054 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
5055 * Only NM_RCLICK is documented.
5057 nmmouse.dwItemSpec = btnPtr->idCommand;
5058 nmmouse.dwItemData = btnPtr->dwData;
5059 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5065 TOOLBAR_CaptureChanged(HWND hwnd)
5067 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5068 TBUTTON_INFO *btnPtr;
5070 infoPtr->bCaptured = FALSE;
5072 if (infoPtr->nButtonDown >= 0)
5074 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5075 btnPtr->fsState &= ~TBSTATE_PRESSED;
5077 infoPtr->nOldHit = -1;
5079 if (btnPtr->fsState & TBSTATE_ENABLED)
5080 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5087 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5090 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5093 if (infoPtr->nOldHit < 0)
5096 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5098 /* Redraw the button if the last button we were over is the hot button and it
5100 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
5102 hotBtnPtr->bHot = FALSE;
5103 rc1 = hotBtnPtr->rect;
5104 InflateRect (&rc1, 1, 1);
5105 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
5109 /* If the last button we were over is depressed then make it not */
5110 /* depressed and redraw it */
5111 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5113 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5115 btnPtr->fsState &= ~TBSTATE_PRESSED;
5117 rc1 = hotBtnPtr->rect;
5118 InflateRect (&rc1, 1, 1);
5119 InvalidateRect (hwnd, &rc1, TRUE);
5122 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5123 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
5129 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5131 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5135 TRACKMOUSEEVENT trackinfo;
5136 NMTBHOTITEM nmhotitem;
5138 /* fill in the TRACKMOUSEEVENT struct */
5139 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5140 trackinfo.dwFlags = TME_QUERY;
5141 trackinfo.hwndTrack = hwnd;
5142 trackinfo.dwHoverTime = HOVER_DEFAULT;
5144 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5145 _TrackMouseEvent(&trackinfo);
5147 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5148 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5149 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5151 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5152 /* and can properly deactivate the hot toolbar button */
5153 _TrackMouseEvent(&trackinfo);
5156 if (infoPtr->hwndToolTip)
5157 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5158 WM_MOUSEMOVE, wParam, lParam);
5160 pt.x = (INT)LOWORD(lParam);
5161 pt.y = (INT)HIWORD(lParam);
5163 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5165 if (infoPtr->nOldHit != nHit)
5167 /* Remove the effect of an old hot button if the button was enabled and was
5168 drawn with the hot button effect */
5169 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
5170 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
5172 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5173 oldBtnPtr->bHot = FALSE;
5176 /* It's not a separator or in nowhere. It's a hot button. */
5179 btnPtr = &infoPtr->buttons[nHit];
5181 infoPtr->nHotItem = nHit;
5183 /* only enabled buttons show hot effect */
5184 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
5186 btnPtr->bHot = TRUE;
5190 nmhotitem.dwFlags = HICF_MOUSE;
5192 nmhotitem.idOld = oldBtnPtr->idCommand;
5194 nmhotitem.dwFlags |= HICF_ENTERING;
5196 nmhotitem.idNew = btnPtr->idCommand;
5198 nmhotitem.dwFlags |= HICF_LEAVING;
5199 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5201 /* now invalidate the old and new buttons so they will be painted */
5203 InvalidateRect (hwnd, &oldBtnPtr->rect,
5204 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5205 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
5206 InvalidateRect(hwnd, &btnPtr->rect,
5207 TOOLBAR_HasText(infoPtr, btnPtr));
5209 if (infoPtr->bCaptured) {
5210 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5211 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5212 btnPtr->fsState &= ~TBSTATE_PRESSED;
5213 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5215 else if (nHit == infoPtr->nButtonDown) {
5216 btnPtr->fsState |= TBSTATE_PRESSED;
5217 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5220 infoPtr->nOldHit = nHit;
5226 inline static LRESULT
5227 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5229 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5230 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5232 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5236 inline static LRESULT
5237 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5239 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5240 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5242 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5247 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5249 TOOLBAR_INFO *infoPtr;
5250 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5253 /* allocate memory for info structure */
5254 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
5255 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5258 infoPtr->dwStructSize = sizeof(TBBUTTON);
5260 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5261 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5262 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5263 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5266 /* native control does:
5267 * Get a lot of colors and brushes
5269 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5270 * CreateFontIndirectA(adr1)
5271 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5272 * hdc = GetDC(toolbar)
5273 * GetSystemMetrics(0x48)
5274 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5275 * 0, 0, 0, 0, "MARLETT")
5276 * oldfnt = SelectObject(hdc, fnt2)
5277 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5278 * GetTextMetricsA(hdc, adr3)
5279 * SelectObject(hdc, oldfnt)
5280 * DeleteObject(fnt2)
5282 * InvalidateRect(toolbar, 0, 1)
5283 * SetWindowLongA(toolbar, 0, addr)
5284 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5287 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5288 * ie 2 0x4600094c 0x4600094c 0x4600894d
5289 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5290 * rebar 0x50008844 0x40008844 0x50008845
5291 * pager 0x50000844 0x40000844 0x50008845
5292 * IC35mgr 0x5400084e **nochange**
5293 * on entry to _NCCREATE 0x5400084e
5294 * rowlist 0x5400004e **nochange**
5295 * on entry to _NCCREATE 0x5400004e
5299 /* I think the code below is a bug, but it is the way that the native
5300 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5301 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5302 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5303 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5304 * Some how, the only cases of this seem to be MFC programs.
5306 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5307 * does not occur in the WM_STYLECHANGING routine.
5308 * (Guy Albertelli 9/2001)
5311 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5312 styleadd |= TBSTYLE_TRANSPARENT;
5313 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5314 styleadd |= CCS_TOP; /* default to top */
5315 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5318 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5323 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5325 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5329 if (dwStyle & WS_MINIMIZE)
5330 return 0; /* Nothing to do */
5332 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5334 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5337 if (!(dwStyle & CCS_NODIVIDER))
5339 GetWindowRect (hwnd, &rcWindow);
5340 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5341 if( dwStyle & WS_BORDER )
5342 OffsetRect (&rcWindow, 1, 1);
5343 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5346 ReleaseDC( hwnd, hdc );
5352 inline static LRESULT
5353 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5355 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5356 LPNMHDR lpnmh = (LPNMHDR)lParam;
5358 if (lpnmh->code == PGN_CALCSIZE) {
5359 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5361 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5362 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5363 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5367 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5368 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5374 if (lpnmh->code == PGN_SCROLL) {
5375 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5377 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5378 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5379 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5380 lppgs->iScroll, lppgs->iDir);
5385 TRACE("passing WM_NOTIFY!\n");
5387 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5388 if (infoPtr->bNtfUnicode)
5389 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5392 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5396 if (lpnmh->code == TTN_GETDISPINFOA) {
5397 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5399 FIXME("retrieving ASCII string\n");
5402 else if (lpnmh->code == TTN_GETDISPINFOW) {
5403 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5405 FIXME("retrieving UNICODE string\n");
5416 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5418 /* remove this routine when Toolbar is improved to pass infoPtr
5419 * around instead of hwnd.
5421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5422 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5427 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5431 if (lParam == NF_REQUERY) {
5432 i = SendMessageA(GetParent(infoPtr->hwndSelf),
5433 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5434 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5435 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5439 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5442 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5447 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5449 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5453 /* fill ps.rcPaint with a default rect */
5454 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5456 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5458 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n",
5459 ps.rcPaint.left, ps.rcPaint.top,
5460 ps.rcPaint.right, ps.rcPaint.bottom);
5462 TOOLBAR_Refresh (hwnd, hdc, &ps);
5463 if (!wParam) EndPaint (hwnd, &ps);
5470 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5471 /*****************************************************
5474 * Handles the WM_SETREDRAW message.
5477 * According to testing V4.71 of COMCTL32 returns the
5478 * *previous* status of the redraw flag (either 0 or 1)
5479 * instead of the MSDN documented value of 0 if handled.
5480 * (For laughs see the "consistancy" with same function
5483 *****************************************************/
5485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5486 BOOL oldredraw = infoPtr->bDoRedraw;
5488 TRACE("set to %s\n",
5489 (wParam) ? "TRUE" : "FALSE");
5490 infoPtr->bDoRedraw = (BOOL) wParam;
5492 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5494 return (oldredraw) ? 1 : 0;
5499 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5501 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5502 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5511 /* Resize deadlock check */
5512 if (infoPtr->bAutoSize) {
5513 infoPtr->bAutoSize = FALSE;
5517 /* FIXME: optimize to only update size if the new size doesn't */
5518 /* match the current size */
5520 flags = (INT) wParam;
5522 /* FIXME for flags =
5523 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5526 TRACE("sizing toolbar!\n");
5528 if (flags == SIZE_RESTORED) {
5529 /* width and height don't apply */
5530 parent = GetParent (hwnd);
5531 GetClientRect(parent, &parent_rect);
5532 x = parent_rect.left;
5533 y = parent_rect.top;
5535 if (dwStyle & CCS_NORESIZE) {
5536 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5539 * this sets the working width of the toolbar, and
5540 * Calc Toolbar will not adjust it, only the height
5542 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5543 cy = infoPtr->nHeight;
5544 cx = infoPtr->nWidth;
5545 TOOLBAR_CalcToolbar (hwnd);
5546 infoPtr->nWidth = cx;
5547 infoPtr->nHeight = cy;
5550 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5551 TOOLBAR_CalcToolbar (hwnd);
5552 cy = infoPtr->nHeight;
5553 cx = infoPtr->nWidth;
5555 if (dwStyle & CCS_NOMOVEY) {
5556 GetWindowRect(hwnd, &window_rect);
5557 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5558 y = window_rect.top;
5562 if (dwStyle & CCS_NOPARENTALIGN) {
5563 uPosFlags |= SWP_NOMOVE;
5564 cy = infoPtr->nHeight;
5565 cx = infoPtr->nWidth;
5568 if (!(dwStyle & CCS_NODIVIDER))
5569 cy += GetSystemMetrics(SM_CYEDGE);
5571 if (dwStyle & WS_BORDER)
5574 cy += GetSystemMetrics(SM_CYEDGE);
5575 cx += GetSystemMetrics(SM_CYEDGE);
5578 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
5579 cx, cy, uPosFlags | SWP_NOZORDER);
5586 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5590 if (nType == GWL_STYLE) {
5591 if (lpStyle->styleNew & TBSTYLE_LIST) {
5592 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5595 infoPtr->dwDTFlags = DT_CENTER;
5597 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5598 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5599 (TBSTYLE_FLAT | TBSTYLE_LIST));
5600 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5603 TOOLBAR_AutoSize (hwnd);
5605 InvalidateRect(hwnd, NULL, FALSE);
5612 TOOLBAR_SysColorChange (HWND hwnd)
5614 COMCTL32_RefreshSysColors();
5621 static LRESULT WINAPI
5622 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5624 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
5625 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5627 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5628 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5633 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5635 case TB_ADDBUTTONSA:
5636 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5638 case TB_ADDBUTTONSW:
5639 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5642 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5645 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5648 return TOOLBAR_AutoSize (hwnd);
5650 case TB_BUTTONCOUNT:
5651 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5653 case TB_BUTTONSTRUCTSIZE:
5654 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5656 case TB_CHANGEBITMAP:
5657 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5659 case TB_CHECKBUTTON:
5660 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5662 case TB_COMMANDTOINDEX:
5663 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5666 return TOOLBAR_Customize (hwnd);
5668 case TB_DELETEBUTTON:
5669 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5671 case TB_ENABLEBUTTON:
5672 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5674 case TB_GETANCHORHIGHLIGHT:
5675 return TOOLBAR_GetAnchorHighlight (hwnd);
5678 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5680 case TB_GETBITMAPFLAGS:
5681 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5684 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5686 case TB_GETBUTTONINFOA:
5687 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5689 case TB_GETBUTTONINFOW:
5690 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5692 case TB_GETBUTTONSIZE:
5693 return TOOLBAR_GetButtonSize (hwnd);
5695 case TB_GETBUTTONTEXTA:
5696 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5698 case TB_GETBUTTONTEXTW:
5699 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5701 case TB_GETDISABLEDIMAGELIST:
5702 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5704 case TB_GETEXTENDEDSTYLE:
5705 return TOOLBAR_GetExtendedStyle (hwnd);
5707 case TB_GETHOTIMAGELIST:
5708 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5711 return TOOLBAR_GetHotItem (hwnd);
5713 case TB_GETIMAGELIST:
5714 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
5716 /* case TB_GETINSERTMARK: */ /* 4.71 */
5717 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5719 case TB_GETITEMRECT:
5720 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5723 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5725 /* case TB_GETOBJECT: */ /* 4.71 */
5728 return TOOLBAR_GetPadding (hwnd);
5731 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5734 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5737 return TOOLBAR_GetState (hwnd, wParam, lParam);
5740 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5742 case TB_GETTEXTROWS:
5743 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5745 case TB_GETTOOLTIPS:
5746 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5748 case TB_GETUNICODEFORMAT:
5749 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5752 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5755 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5757 case TB_INDETERMINATE:
5758 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5760 case TB_INSERTBUTTONA:
5761 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5763 case TB_INSERTBUTTONW:
5764 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5766 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5768 case TB_ISBUTTONCHECKED:
5769 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5771 case TB_ISBUTTONENABLED:
5772 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5774 case TB_ISBUTTONHIDDEN:
5775 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5777 case TB_ISBUTTONHIGHLIGHTED:
5778 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5780 case TB_ISBUTTONINDETERMINATE:
5781 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5783 case TB_ISBUTTONPRESSED:
5784 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5786 case TB_LOADIMAGES: /* 4.70 */
5787 FIXME("missing standard imagelists\n");
5790 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5791 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5792 /* case TB_MARKBUTTON: */ /* 4.71 */
5793 /* case TB_MOVEBUTTON: */ /* 4.71 */
5795 case TB_PRESSBUTTON:
5796 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5798 case TB_REPLACEBITMAP:
5799 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
5801 case TB_SAVERESTOREA:
5802 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5804 case TB_SAVERESTOREW:
5805 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5807 case TB_SETANCHORHIGHLIGHT:
5808 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5810 case TB_SETBITMAPSIZE:
5811 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5813 case TB_SETBUTTONINFOA:
5814 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5816 case TB_SETBUTTONINFOW:
5817 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5819 case TB_SETBUTTONSIZE:
5820 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5822 case TB_SETBUTTONWIDTH:
5823 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5826 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5828 case TB_SETDISABLEDIMAGELIST:
5829 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5831 case TB_SETDRAWTEXTFLAGS:
5832 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5834 case TB_SETEXTENDEDSTYLE:
5835 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5837 case TB_SETHOTIMAGELIST:
5838 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5841 return TOOLBAR_SetHotItem (hwnd, wParam);
5843 case TB_SETIMAGELIST:
5844 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5847 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5849 /* case TB_SETINSERTMARK: */ /* 4.71 */
5851 case TB_SETINSERTMARKCOLOR:
5852 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5854 case TB_SETMAXTEXTROWS:
5855 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5858 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
5861 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5864 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5867 return TOOLBAR_SetState (hwnd, wParam, lParam);
5870 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5872 case TB_SETTOOLTIPS:
5873 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5875 case TB_SETUNICODEFORMAT:
5876 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5879 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
5882 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
5885 /* Common Control Messages */
5887 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
5888 case CCM_GETCOLORSCHEME:
5889 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5891 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
5892 case CCM_SETCOLORSCHEME:
5893 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5895 case CCM_GETVERSION:
5896 return TOOLBAR_GetVersion (hwnd);
5898 case CCM_SETVERSION:
5899 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5905 return TOOLBAR_Create (hwnd, wParam, lParam);
5908 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5911 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5914 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5916 /* case WM_KEYDOWN: */
5917 /* case WM_KILLFOCUS: */
5919 case WM_LBUTTONDBLCLK:
5920 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5922 case WM_LBUTTONDOWN:
5923 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5926 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5929 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5932 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5934 case WM_CAPTURECHANGED:
5935 return TOOLBAR_CaptureChanged(hwnd);
5938 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5941 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5944 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5947 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5950 return TOOLBAR_Notify (hwnd, wParam, lParam);
5952 case WM_NOTIFYFORMAT:
5953 TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
5956 return TOOLBAR_Paint (hwnd, wParam);
5959 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5962 return TOOLBAR_Size (hwnd, wParam, lParam);
5964 case WM_STYLECHANGED:
5965 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5967 case WM_SYSCOLORCHANGE:
5968 return TOOLBAR_SysColorChange (hwnd);
5970 /* case WM_WININICHANGE: */
5975 case WM_MEASUREITEM:
5978 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5980 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5982 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5985 /* We see this in Outlook Express 5.x and just does DefWindowProc */
5986 case PGM_FORWARDMOUSE:
5987 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5990 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
5991 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5992 uMsg, wParam, lParam);
5993 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
6000 TOOLBAR_Register (void)
6004 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
6005 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6006 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
6007 wndClass.cbClsExtra = 0;
6008 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6009 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
6010 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
6011 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
6013 RegisterClassA (&wndClass);
6018 TOOLBAR_Unregister (void)
6020 UnregisterClassA (TOOLBARCLASSNAMEA, NULL);
6023 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6028 /* Check if the entry already exists */
6029 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6031 /* If this is a new entry we must create it and insert into the array */
6036 c = (PIMLENTRY) COMCTL32_Alloc(sizeof(IMLENTRY));
6039 pnies = COMCTL32_Alloc((*cies + 1) * sizeof(PIMLENTRY));
6040 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6044 COMCTL32_Free(*pies);
6055 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6059 for (i = 0; i < *cies; i++)
6060 COMCTL32_Free((*pies)[i]);
6062 COMCTL32_Free(*pies);
6069 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6077 for (i = 0; i < cies; i++)
6079 if (pies[i]->id == id)
6091 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6093 HIMAGELIST himlDef = 0;
6094 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6097 himlDef = pie->himl;
6103 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6105 if (infoPtr->bUnicode)
6106 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6113 nmtba.iItem = nmtb->iItem;
6114 nmtba.pszText = Buffer;
6115 nmtba.cchText = 256;
6116 ZeroMemory(nmtba.pszText, nmtba.cchText);
6118 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6120 int ccht = strlen(nmtba.pszText);
6122 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6123 nmtb->pszText, nmtb->cchText);
6125 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6134 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6135 int iItem, PCUSTOMBUTTON btnInfo)
6140 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6142 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);