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 * - A little bug in TOOLBAR_DrawMasked()
33 * - Button wrapping (under construction).
35 * - Notifications (under construction).
37 * - Tooltip support (almost complete).
38 * - Unicode suppport (under construction).
39 * - Fix TOOLBAR_SetButtonInfo32A/W.
40 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
41 * - I_IMAGECALLBACK support.
42 * - iString of -1 is undocumented
43 * - Customization dialog:
45 * - Minor buglet in 'available buttons' list:
46 * Buttons are not listed in M$-like order. M$ seems to use a single
47 * internal list to store the button information of both listboxes.
48 * - Drag list support.
49 * - Help and Reset button support.
52 * - Run tests using Waite Group Windows95 API Bible Volume 2.
53 * The second cdrom contains executables addstr.exe, btncount.exe,
54 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
55 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
56 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
57 * setparnt.exe, setrows.exe, toolwnd.exe.
58 * - Microsofts controlspy examples.
59 * - Charles Petzold's 'Programming Windows': gadgets.exe
68 #include "wine/unicode.h"
70 #include "imagelist.h"
72 #include "wine/debug.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
101 } IMLENTRY, *PIMLENTRY;
105 DWORD dwStructSize; /* size of TBBUTTON struct */
106 INT nHeight; /* height of the toolbar */
107 INT nWidth; /* width of the toolbar */
113 INT nRows; /* number of button rows */
114 INT nMaxTextRows; /* maximum number of text rows */
115 INT cxMin; /* minimum button width */
116 INT cxMax; /* maximum button width */
117 INT nNumButtons; /* number of buttons */
118 INT nNumBitmaps; /* number of bitmaps */
119 INT nNumStrings; /* number of strings */
121 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
122 BOOL bCaptured; /* mouse captured? */
125 INT nHotItem; /* index of the "hot" item */
126 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
127 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
128 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
129 SIZE szPadding; /* padding values around button */
131 HFONT hFont; /* text font */
132 HIMAGELIST himlInt; /* image list created internally */
133 PIMLENTRY *himlDef; /* default image list array */
134 INT cimlDef; /* default image list array count */
135 PIMLENTRY *himlHot; /* hot image list array */
136 INT cimlHot; /* hot image list array count */
137 PIMLENTRY *himlDis; /* disabled image list array */
138 INT cimlDis; /* disabled image list array count */
139 HWND hwndToolTip; /* handle to tool tip control */
140 HWND hwndNotify; /* handle to the window that gets notifications */
141 HWND hwndSelf; /* my own handle */
142 BOOL bTransparent; /* background transparency flag */
143 BOOL bBtnTranspnt; /* button transparency flag */
144 BOOL bAutoSize; /* auto size deadlock indicator */
145 BOOL bAnchor; /* anchor highlight enabled */
146 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
147 BOOL bDoRedraw; /* Redraw status */
148 DWORD dwExStyle; /* extended toolbar style */
149 DWORD dwDTFlags; /* DrawText flags */
151 COLORREF clrInsertMark; /* insert mark color */
152 COLORREF clrBtnHighlight; /* color for Flat Separator */
153 COLORREF clrBtnShadow; /* color for Flag Separator */
154 RECT rcBound; /* bounding rectangle */
157 TBUTTON_INFO *buttons; /* pointer to button array */
158 LPWSTR *strings; /* pointer to string array */
159 TBITMAP_INFO *bitmaps;
160 } TOOLBAR_INFO, *PTOOLBAR_INFO;
163 /* used by customization dialog */
166 PTOOLBAR_INFO tbInfo;
168 } CUSTDLG_INFO, *PCUSTDLG_INFO;
176 } CUSTOMBUTTON, *PCUSTOMBUTTON;
179 #define SEPARATOR_WIDTH 8
181 #define BOTTOM_BORDER 2
182 #define DDARROW_WIDTH 11
184 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
185 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
186 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
188 /* Used to find undocumented extended styles */
189 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
190 TBSTYLE_EX_UNDOC1 | \
191 TBSTYLE_EX_MIXEDBUTTONS | \
192 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
194 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
195 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
196 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
197 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
198 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
200 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
201 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo);
202 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id);
203 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id);
204 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
205 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
208 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
212 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
214 LPWSTR lpText = NULL;
216 /* FIXME: iString == -1 is undocumented */
217 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
218 lpText = (LPWSTR)btnPtr->iString;
219 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
220 lpText = infoPtr->strings[btnPtr->iString];
226 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
228 if (TRACE_ON(toolbar)){
229 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
230 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
231 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
232 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
234 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
235 btn_num, bP->idCommand,
236 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
237 bP->rect.left, bP->rect.top,
238 bP->rect.right, bP->rect.bottom);
244 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
246 if (TRACE_ON(toolbar)) {
250 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
251 TRACE("toolbar %p at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
253 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
254 iP->nNumStrings, dwStyle);
255 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
257 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
258 (iP->bDoRedraw) ? "TRUE" : "FALSE");
259 for(i=0; i<iP->nNumButtons; i++) {
260 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
266 /***********************************************************************
269 * This function validates that the styles set are implemented and
270 * issues FIXME's warning of possible problems. In a perfect world this
271 * function should be null.
274 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
276 if (dwStyle & TBSTYLE_ALTDRAG)
277 FIXME("[%p] TBSTYLE_ALTDRAG not implemented\n", hwnd);
278 if (dwStyle & TBSTYLE_REGISTERDROP)
279 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
284 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
286 if(!IsWindow(infoPtr->hwndSelf))
287 return 0; /* we have just been destroyed */
289 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
290 nmhdr->hwndFrom = infoPtr->hwndSelf;
293 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
294 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
296 if (infoPtr->bNtfUnicode)
297 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
298 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
300 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
301 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
304 /***********************************************************************
305 * TOOLBAR_GetBitmapIndex
307 * This function returns the bitmap index associated with a button.
308 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
309 * is issued to retrieve the index.
312 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
314 INT ret = btnPtr->iBitmap;
316 if (ret == I_IMAGECALLBACK) {
317 /* issue TBN_GETDISPINFO */
320 nmgd.idCommand = btnPtr->idCommand;
321 nmgd.lParam = btnPtr->dwData;
322 nmgd.dwMask = TBNF_IMAGE;
323 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
324 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
326 if (nmgd.dwMask & TBNF_DI_SETITEM) {
327 btnPtr->iBitmap = nmgd.iImage;
330 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
331 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
334 if (ret != I_IMAGENONE)
335 ret = GETIBITMAP(infoPtr, ret);
342 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
345 INT id = GETHIMLID(infoPtr, index);
346 INT iBitmap = GETIBITMAP(infoPtr, index);
348 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
349 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
350 (index == I_IMAGECALLBACK))
357 /***********************************************************************
358 * TOOLBAR_DrawImageList
360 * This function validates the bitmap index (including I_IMAGECALLBACK
361 * functionality). It then draws the image via the ImageList_Draw
362 * function. It returns TRUE if the image was drawn, FALSE otherwise.
365 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
366 HDC hdc, UINT left, UINT top, UINT draw_flags)
370 if (!himl) return FALSE;
372 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
373 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
374 ERR("index %d is not valid, max %d\n",
375 btnPtr->iBitmap, infoPtr->nNumBitmaps);
379 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
380 if ((index == I_IMAGECALLBACK) ||
381 (index == I_IMAGENONE)) return FALSE;
382 ERR("TBN_GETDISPINFO returned invalid index %d\n",
386 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
387 index, himl, left, top, draw_flags);
389 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
394 /***********************************************************************
395 * TOOLBAR_TestImageExist
397 * This function is similar to TOOLBAR_DrawImageList, except it does not
398 * draw the image. The I_IMAGECALLBACK functionality is implemented.
401 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
405 if (!himl) return FALSE;
407 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
408 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
409 ERR("index %d is not valid, max %d\n",
410 btnPtr->iBitmap, infoPtr->nNumBitmaps);
414 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
415 if ((index == I_IMAGECALLBACK) ||
416 (index == I_IMAGENONE)) return FALSE;
417 ERR("TBN_GETDISPINFO returned invalid index %d\n",
426 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
429 COLORREF oldcolor, newcolor;
431 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
432 myrect.right = myrect.left + 1;
433 myrect.top = lpRect->top + 2;
434 myrect.bottom = lpRect->bottom - 2;
436 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
437 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
438 oldcolor = SetBkColor (hdc, newcolor);
439 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
441 myrect.left = myrect.right;
442 myrect.right = myrect.left + 1;
444 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
445 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
446 SetBkColor (hdc, newcolor);
447 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
449 SetBkColor (hdc, oldcolor);
453 /***********************************************************************
454 * TOOLBAR_DrawDDFlatSeparator
456 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
457 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
458 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
459 * are horizontal as opposed to the vertical separators for not dropdown
462 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
465 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
468 COLORREF oldcolor, newcolor;
470 myrect.left = lpRect->left;
471 myrect.right = lpRect->right;
472 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
473 myrect.bottom = myrect.top + 1;
475 InflateRect (&myrect, -2, 0);
477 TRACE("rect=(%d,%d)-(%d,%d)\n",
478 myrect.left, myrect.top, myrect.right, myrect.bottom);
480 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
481 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
482 oldcolor = SetBkColor (hdc, newcolor);
483 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
485 myrect.top = myrect.bottom;
486 myrect.bottom = myrect.top + 1;
488 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
489 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
490 SetBkColor (hdc, newcolor);
491 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
493 SetBkColor (hdc, oldcolor);
498 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
503 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
504 hOldPen = SelectObject ( hdc, hPen );
507 MoveToEx (hdc, x, y, NULL);
508 LineTo (hdc, x+5, y++); x++;
509 MoveToEx (hdc, x, y, NULL);
510 LineTo (hdc, x+3, y++); x++;
511 MoveToEx (hdc, x, y, NULL);
512 LineTo (hdc, x+1, y++);
513 SelectObject( hdc, hOldPen );
514 DeleteObject( hPen );
518 * Draw the text string for this button.
519 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
520 * is non-zero, so we can simply check himlDef to see if we have
524 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
525 HDC hdc, INT nState, DWORD dwStyle,
526 RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
533 TRACE("string rect=(%d,%d)-(%d,%d)\n",
534 rcText->left, rcText->top, rcText->right, rcText->bottom);
536 hOldFont = SelectObject (hdc, infoPtr->hFont);
537 if (!(nState & TBSTATE_ENABLED)) {
538 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
539 OffsetRect (rcText, 1, 1);
540 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
541 SetTextColor (hdc, comctl32_color.clr3dShadow);
542 OffsetRect (rcText, -1, -1);
544 else if (nState & TBSTATE_INDETERMINATE) {
545 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
547 else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
548 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
551 clrOld = SetTextColor (hdc, tbcd->clrText);
554 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
555 SetTextColor (hdc, clrOld);
556 SelectObject (hdc, hOldFont);
562 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
564 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
565 INT cx = lpRect->right - lpRect->left;
566 INT cy = lpRect->bottom - lpRect->top;
567 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
568 SelectObject (hdc, hbr);
573 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
574 HDC hdc, INT x, INT y)
576 /* FIXME: this function is a hack since it uses image list
577 internals directly */
579 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0);
587 /* create new dc's */
588 hdcImageList = CreateCompatibleDC (0);
589 hdcMask = CreateCompatibleDC (0);
591 /* create new bitmap */
592 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
593 SelectObject (hdcMask, hbmMask);
595 /* copy the mask bitmap */
596 SelectObject (hdcImageList, himl->hbmMask);
597 SetBkColor (hdcImageList, RGB(255, 255, 255));
598 SetTextColor (hdcImageList, RGB(0, 0, 0));
599 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
600 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
602 /* draw the new mask */
603 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
604 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
605 hdcMask, 0, 0, 0xB8074A);
607 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
608 BitBlt (hdc, x, y, himl->cx, himl->cy,
609 hdcMask, 0, 0, 0xB8074A);
611 DeleteObject (hbmMask);
613 DeleteDC (hdcImageList);
618 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
622 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
623 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
624 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
625 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
626 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
627 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
628 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
629 /* don't test TBSTATE_HIDDEN */
635 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
637 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
638 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
639 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
640 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
641 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
642 LPWSTR lpText = NULL;
648 if (btnPtr->fsState & TBSTATE_HIDDEN)
652 CopyRect (&rcFill, &rc);
653 CopyRect (&rcArrow, &rc);
654 CopyRect(&rcBitmap, &rc);
655 CopyRect(&rcText, &rc);
657 /* get a pointer to the text */
658 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
660 if (hasDropDownArrow)
662 if (dwStyle & TBSTYLE_FLAT)
663 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
665 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
666 rcArrow.left = rc.right;
669 /* Center the bitmap horizontally and vertically */
670 if (dwStyle & TBSTYLE_LIST)
673 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
676 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
678 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
680 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
681 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
682 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
683 TRACE ("iString: %x\n", btnPtr->iString);
684 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
689 InflateRect (&rcText, -3, -3);
691 if (GETDEFIMAGELIST(infoPtr, 0) &&
692 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
693 /* The following test looked like this before
694 * I changed it. IE4 "Links" toolbar would not
695 * draw correctly with the original code. - GA 8/01
696 * ((dwStyle & TBSTYLE_LIST) &&
697 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
698 * (btnPtr->iBitmap != I_IMAGENONE))
700 if (dwStyle & TBSTYLE_LIST) {
701 /* LIST style w/ ICON offset is by matching native. */
702 /* Matches IE4 "Links" bar. - GA 8/01 */
703 rcText.left += (infoPtr->nBitmapWidth + 2);
706 rcText.top += infoPtr->nBitmapHeight + 1;
710 if (dwStyle & TBSTYLE_LIST) {
711 /* LIST style w/o ICON offset is by matching native. */
712 /* Matches IE4 "menu" bar. - GA 8/01 */
717 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
718 OffsetRect (&rcText, 1, 1);
721 /* Initialize fields in all cases, because we use these later */
722 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
723 tbcd.clrText = comctl32_color.clrBtnText;
724 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
725 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
726 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
727 tbcd.clrMark = comctl32_color.clrHighlight;
728 tbcd.clrHighlightHotTrack = 0;
729 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
730 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
731 /* MSDN says that this is the text rectangle. */
732 /* But (why always a but) tracing of v5.7 of native shows */
733 /* that this is really a *relative* rectangle based on the */
734 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
735 /* any bitmap that might be present. */
736 tbcd.rcText.left = 0;
738 tbcd.rcText.right = rcText.right - rc.left;
739 tbcd.rcText.bottom = rcText.bottom - rc.top;
741 /* FIXME: what should these be set to ????? */
742 tbcd.hbrMonoDither = 0;
746 /* Issue Item Prepaint notify */
747 infoPtr->dwItemCustDraw = 0;
748 infoPtr->dwItemCDFlag = 0;
749 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
751 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
754 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
755 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
756 tbcd.nmcd.lItemlParam = btnPtr->dwData;
757 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
758 infoPtr->dwItemCustDraw = ntfret & 0xffff;
759 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
760 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
762 /* save the only part of the rect that the user can change */
763 rcText.right = tbcd.rcText.right + rc.left;
764 rcText.bottom = tbcd.rcText.bottom + rc.top;
767 if (!infoPtr->bBtnTranspnt)
768 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
771 if (btnPtr->fsStyle & TBSTYLE_SEP) {
772 /* with the FLAT style, iBitmap is the width and has already */
773 /* been taken into consideration in calculating the width */
774 /* so now we need to draw the vertical separator */
775 /* empirical tests show that iBitmap can/will be non-zero */
776 /* when drawing the vertical bar... */
777 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
778 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
779 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
781 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
783 else if (btnPtr->fsStyle != TBSTYLE_SEP) {
784 FIXME("Draw some kind of separator: fsStyle=%x\n",
790 /* Determine index of image list */
791 himlDef = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
794 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
795 HIMAGELIST himlDis = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
796 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
798 DrawEdge (hdc, &rc, EDGE_RAISED,
799 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
800 if (hasDropDownArrow)
801 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
802 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
805 if (hasDropDownArrow)
807 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
808 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
811 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDis,
812 hdc, rcBitmap.left, rcBitmap.top,
814 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
816 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
820 /* pressed TBSTYLE_BUTTON */
821 if (btnPtr->fsState & TBSTATE_PRESSED) {
822 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
823 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
825 if (dwStyle & TBSTYLE_FLAT)
827 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
828 if (hasDropDownArrow)
829 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
833 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
834 if (hasDropDownArrow)
835 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
839 if (hasDropDownArrow)
840 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
842 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
843 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
846 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
850 /* checked TBSTYLE_CHECK */
851 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
852 (btnPtr->fsState & TBSTATE_CHECKED)) {
853 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
855 if (dwStyle & TBSTYLE_FLAT)
856 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
857 BF_RECT | BF_ADJUST);
859 DrawEdge (hdc, &rc, EDGE_SUNKEN,
860 BF_RECT | BF_MIDDLE | BF_ADJUST);
863 TOOLBAR_DrawPattern (hdc, &rc);
865 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
866 hdc, rcBitmap.left+1, rcBitmap.top+1,
869 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
874 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
875 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
876 DrawEdge (hdc, &rc, EDGE_RAISED,
877 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
879 TOOLBAR_DrawPattern (hdc, &rc);
880 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
881 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
886 if (dwStyle & TBSTYLE_FLAT)
890 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
894 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
895 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
896 if (hasDropDownArrow)
897 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
898 SetBkColor(hdc, oldclr);
902 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
904 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
905 if (hasDropDownArrow)
906 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
911 else /* The following code needs to be removed after
912 * "hot item" support has been implemented for the
913 * case where it is being de-selected.
916 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
917 if (hasDropDownArrow)
918 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
922 if (hasDropDownArrow)
923 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
926 HIMAGELIST himlHot = GETHOTIMAGELIST(infoPtr,
927 GETHIMLID(infoPtr, btnPtr->iBitmap));
928 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
929 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
932 rcBitmap.top, ILD_NORMAL))
933 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
934 hdc, rcBitmap.left, rcBitmap.top,
938 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
939 hdc, rcBitmap.left, rcBitmap.top,
944 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
945 DrawEdge (hdc, &rc, EDGE_RAISED,
946 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
948 if (hasDropDownArrow)
950 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
951 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
952 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
953 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
956 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef,
957 hdc, rcBitmap.left, rcBitmap.top,
961 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
964 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
966 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
969 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
970 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
971 tbcd.nmcd.lItemlParam = btnPtr->dwData;
972 tbcd.rcText = rcText;
973 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
974 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
975 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
982 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
985 TBUTTON_INFO *btnPtr;
986 INT i, oldBKmode = 0;
991 /* if imagelist belongs to the app, it can be changed
992 by the app after setting it */
993 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
995 infoPtr->nNumBitmaps = 0;
996 for (i = 0; i < infoPtr->cimlDef; i++)
997 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1000 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1002 /* Send initial notify */
1003 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1004 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1005 tbcd.nmcd.hdc = hdc;
1006 tbcd.nmcd.rc = ps->rcPaint;
1007 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1008 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
1010 if (infoPtr->bBtnTranspnt)
1011 oldBKmode = SetBkMode (hdc, TRANSPARENT);
1013 /* redraw necessary buttons */
1014 btnPtr = infoPtr->buttons;
1015 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1017 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
1018 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1021 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
1022 SetBkMode (hdc, oldBKmode);
1024 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1026 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1027 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1028 tbcd.nmcd.hdc = hdc;
1029 tbcd.nmcd.rc = ps->rcPaint;
1030 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
1034 /***********************************************************************
1035 * TOOLBAR_MeasureString
1037 * This function gets the width and height of a string in pixels. This
1038 * is done first by using GetTextExtentPoint to get the basic width
1039 * and height. The DrawText is called with DT_CALCRECT to get the exact
1040 * width. The reason is because the text may have more than one "&" (or
1041 * prefix characters as M$ likes to call them). The prefix character
1042 * indicates where the underline goes, except for the string "&&" which
1043 * is reduced to a single "&". GetTextExtentPoint does not process these
1044 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
1047 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1048 HDC hdc, LPSIZE lpSize)
1055 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
1057 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1059 if(lpText != NULL) {
1060 /* first get size of all the text */
1061 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1063 /* feed above size into the rectangle for DrawText */
1064 myrect.left = myrect.top = 0;
1065 myrect.right = lpSize->cx;
1066 myrect.bottom = lpSize->cy;
1068 /* Use DrawText to get true size as drawn (less pesky "&") */
1069 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1070 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
1073 /* feed back to caller */
1074 lpSize->cx = myrect.right;
1075 lpSize->cy = myrect.bottom;
1079 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1082 /***********************************************************************
1083 * TOOLBAR_CalcStrings
1085 * This function walks through each string and measures it and returns
1086 * the largest height and width to caller.
1089 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1091 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1092 TBUTTON_INFO *btnPtr;
1102 hOldFont = SelectObject (hdc, infoPtr->hFont);
1104 btnPtr = infoPtr->buttons;
1105 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1106 if(TOOLBAR_HasText(infoPtr, btnPtr))
1108 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1109 if (sz.cx > lpSize->cx)
1111 if (sz.cy > lpSize->cy)
1116 SelectObject (hdc, hOldFont);
1117 ReleaseDC (hwnd, hdc);
1119 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1122 /***********************************************************************
1123 * TOOLBAR_WrapToolbar
1125 * This function walks through the buttons and seperators in the
1126 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1127 * wrapping should occur based on the width of the toolbar window.
1128 * It does *not* calculate button placement itself. That task
1129 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1130 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1131 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1133 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1134 * vertical toolbar lists.
1138 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1140 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1141 TBUTTON_INFO *btnPtr;
1144 BOOL bWrap, bButtonWrap;
1146 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1147 /* no layout is necessary. Applications may use this style */
1148 /* to perform their own layout on the toolbar. */
1149 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1150 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1152 btnPtr = infoPtr->buttons;
1153 x = infoPtr->nIndent;
1155 /* this can get the parents width, to know how far we can extend
1156 * this toolbar. We cannot use its height, as there may be multiple
1157 * toolbars in a rebar control
1159 GetClientRect( GetParent(hwnd), &rc );
1160 infoPtr->nWidth = rc.right - rc.left;
1161 bButtonWrap = FALSE;
1163 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1164 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1167 for (i = 0; i < infoPtr->nNumButtons; i++ )
1170 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1172 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1175 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1176 /* it is the actual width of the separator. This is used for */
1177 /* custom controls in toolbars. */
1179 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
1180 /* width. - GA 8/01 */
1181 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1182 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
1183 cx = (btnPtr[i].iBitmap > 0) ?
1184 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1186 cx = infoPtr->nButtonWidth;
1188 /* Two or more adjacent separators form a separator group. */
1189 /* The first separator in a group should be wrapped to the */
1190 /* next row if the previous wrapping is on a button. */
1192 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1193 (i + 1 < infoPtr->nNumButtons ) &&
1194 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
1196 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1197 btnPtr[i].fsState |= TBSTATE_WRAP;
1198 x = infoPtr->nIndent;
1200 bButtonWrap = FALSE;
1204 /* The layout makes sure the bitmap is visible, but not the button. */
1205 /* Test added to also wrap after a button that starts a row but */
1206 /* is bigger than the area. - GA 8/01 */
1207 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1208 > infoPtr->nWidth ) ||
1209 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1211 BOOL bFound = FALSE;
1213 /* If the current button is a separator and not hidden, */
1214 /* go to the next until it reaches a non separator. */
1215 /* Wrap the last separator if it is before a button. */
1216 while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1217 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
1218 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1219 i < infoPtr->nNumButtons )
1225 if( bFound && i < infoPtr->nNumButtons )
1228 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1229 i, btnPtr[i].fsStyle, x, cx);
1230 btnPtr[i].fsState |= TBSTATE_WRAP;
1231 x = infoPtr->nIndent;
1232 bButtonWrap = FALSE;
1235 else if ( i >= infoPtr->nNumButtons)
1238 /* If the current button is not a separator, find the last */
1239 /* separator and wrap it. */
1240 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1242 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1243 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1247 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1248 i, btnPtr[i].fsStyle, x, cx);
1249 x = infoPtr->nIndent;
1250 btnPtr[j].fsState |= TBSTATE_WRAP;
1251 bButtonWrap = FALSE;
1256 /* If no separator available for wrapping, wrap one of */
1257 /* non-hidden previous button. */
1261 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1263 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1268 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1269 i, btnPtr[i].fsStyle, x, cx);
1270 x = infoPtr->nIndent;
1271 btnPtr[j].fsState |= TBSTATE_WRAP;
1277 /* If all above failed, wrap the current button. */
1280 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1281 i, btnPtr[i].fsStyle, x, cx);
1282 btnPtr[i].fsState |= TBSTATE_WRAP;
1284 x = infoPtr->nIndent;
1285 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1286 bButtonWrap = FALSE;
1292 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1293 i, btnPtr[i].fsStyle, x, cx);
1300 /***********************************************************************
1301 * TOOLBAR_CalcToolbar
1303 * This function calculates button and separator placement. It first
1304 * calculates the button sizes, gets the toolbar window width and then
1305 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1306 * on. It assigns a new location to each item and sends this location to
1307 * the tooltip window if appropriate. Finally, it updates the rcBound
1308 * rect and calculates the new required toolbar window height.
1312 TOOLBAR_CalcToolbar (HWND hwnd)
1314 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1315 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1316 TBUTTON_INFO *btnPtr;
1317 INT i, nRows, nSepRows;
1321 BOOL usesBitmaps = FALSE;
1322 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1324 TOOLBAR_CalcStrings (hwnd, &sizeString);
1326 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1328 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1331 if (dwStyle & TBSTYLE_LIST)
1333 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1334 0, sizeString.cy) + infoPtr->szPadding.cy;
1335 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1336 0) + sizeString.cx + 6;
1337 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1338 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1339 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1340 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1343 if (sizeString.cy > 0)
1346 infoPtr->nButtonHeight = sizeString.cy +
1347 2 + /* this is the space to separate text from bitmap */
1348 infoPtr->nBitmapHeight + 6;
1350 infoPtr->nButtonHeight = sizeString.cy + 6;
1352 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1353 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1355 if (sizeString.cx > infoPtr->nBitmapWidth)
1356 infoPtr->nButtonWidth = sizeString.cx + 6;
1357 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1358 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1361 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1362 infoPtr->nButtonWidth = infoPtr->cxMin;
1363 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1364 infoPtr->nButtonWidth = infoPtr->cxMax;
1366 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1368 x = infoPtr->nIndent;
1372 * We will set the height below, and we set the width on entry
1373 * so we do not reset them here..
1376 GetClientRect( hwnd, &rc );
1377 /* get initial values for toolbar */
1378 infoPtr->nWidth = rc.right - rc.left;
1379 infoPtr->nHeight = rc.bottom - rc.top;
1382 /* from above, minimum is a button, and possible text */
1383 cx = infoPtr->nButtonWidth;
1385 /* cannot use just ButtonHeight, we may have no buttons! */
1386 if (infoPtr->nNumButtons > 0)
1387 infoPtr->nHeight = infoPtr->nButtonHeight;
1389 cy = infoPtr->nHeight;
1391 nRows = nSepRows = 0;
1393 infoPtr->rcBound.top = y;
1394 infoPtr->rcBound.left = x;
1395 infoPtr->rcBound.bottom = y + cy;
1396 infoPtr->rcBound.right = x;
1398 btnPtr = infoPtr->buttons;
1400 /* do not base height/width on parent, if the parent is a */
1401 /* rebar control it could have multiple rows of toolbars */
1402 /* GetClientRect( GetParent(hwnd), &rc ); */
1403 /* cx = rc.right - rc.left; */
1404 /* cy = rc.bottom - rc.top; */
1406 TRACE("cy=%d\n", cy);
1408 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1411 if (btnPtr->fsState & TBSTATE_HIDDEN)
1413 SetRectEmpty (&btnPtr->rect);
1417 cy = infoPtr->nHeight;
1419 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1420 /* it is the actual width of the separator. This is used for */
1421 /* custom controls in toolbars. */
1422 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1423 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1424 cy = (btnPtr->iBitmap > 0) ?
1425 btnPtr->iBitmap : SEPARATOR_WIDTH;
1426 cx = infoPtr->nButtonWidth;
1429 cx = (btnPtr->iBitmap > 0) ?
1430 btnPtr->iBitmap : SEPARATOR_WIDTH;
1434 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1441 hOldFont = SelectObject (hdc, infoPtr->hFont);
1443 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1445 SelectObject (hdc, hOldFont);
1446 ReleaseDC (hwnd, hdc);
1448 /* Fudge amount measured against IE4 "menu" and "Links" */
1449 /* toolbars with native control (v4.71). - GA 8/01 */
1450 cx = sz.cx + 6 + 5 + 5;
1451 if ((dwStyle & TBSTYLE_LIST) &&
1452 (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0))))
1453 cx += infoPtr->nBitmapWidth;
1456 cx = infoPtr->nButtonWidth;
1458 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1459 cx += DDARROW_WIDTH;
1461 if (btnPtr->fsState & TBSTATE_WRAP )
1464 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1466 if (infoPtr->rcBound.left > x)
1467 infoPtr->rcBound.left = x;
1468 if (infoPtr->rcBound.right < x + cx)
1469 infoPtr->rcBound.right = x + cx;
1470 if (infoPtr->rcBound.bottom < y + cy)
1471 infoPtr->rcBound.bottom = y + cy;
1473 /* Set the toolTip only for non-hidden, non-separator button */
1474 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1478 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1479 ti.cbSize = sizeof(TTTOOLINFOA);
1481 ti.uId = btnPtr->idCommand;
1482 ti.rect = btnPtr->rect;
1483 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1487 /* btnPtr->nRow is zero based. The space between the rows is */
1488 /* also considered as a row. */
1489 btnPtr->nRow = nRows + nSepRows;
1491 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1492 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1497 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1501 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1502 /* it is the actual width of the separator. This is used for */
1503 /* custom controls in toolbars. */
1504 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1505 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1506 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1510 /* nSepRows is used to calculate the extra height follwoing */
1514 x = infoPtr->nIndent;
1516 /* Increment row number unless this is the last button */
1517 /* and it has Wrap set. */
1518 if (i != infoPtr->nNumButtons-1)
1525 /* infoPtr->nRows is the number of rows on the toolbar */
1526 infoPtr->nRows = nRows + nSepRows + 1;
1529 /********************************************************************
1530 * The following while interesting, does not match the values *
1531 * created above for the button rectangles, nor the rcBound rect. *
1532 * We will comment it out and remove it later. *
1534 * The problem showed up as heights in the pager control that was *
1536 ********************************************************************/
1538 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1540 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1541 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1542 nSepRows * (infoPtr->nBitmapHeight + 1) +
1546 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1548 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1553 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1555 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1556 TBUTTON_INFO *btnPtr;
1559 btnPtr = infoPtr->buttons;
1560 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1561 if (btnPtr->fsState & TBSTATE_HIDDEN)
1564 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1565 if (PtInRect (&btnPtr->rect, *lpPt)) {
1566 TRACE(" ON SEPARATOR %d!\n", i);
1571 if (PtInRect (&btnPtr->rect, *lpPt)) {
1572 TRACE(" ON BUTTON %d!\n", i);
1578 TRACE(" NOWHERE!\n");
1584 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1586 TBUTTON_INFO *btnPtr;
1589 if (CommandIsIndex) {
1590 TRACE("command is really index command=%d\n", idCommand);
1591 if (idCommand >= infoPtr->nNumButtons) return -1;
1594 btnPtr = infoPtr->buttons;
1595 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1596 if (btnPtr->idCommand == idCommand) {
1597 TRACE("command=%d index=%d\n", idCommand, i);
1601 TRACE("no index found for command=%d\n", idCommand);
1607 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1609 TBUTTON_INFO *btnPtr;
1612 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1615 /* check index button */
1616 btnPtr = &infoPtr->buttons[nIndex];
1617 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1618 if (btnPtr->fsState & TBSTATE_CHECKED)
1622 /* check previous buttons */
1623 nRunIndex = nIndex - 1;
1624 while (nRunIndex >= 0) {
1625 btnPtr = &infoPtr->buttons[nRunIndex];
1626 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1627 if (btnPtr->fsState & TBSTATE_CHECKED)
1635 /* check next buttons */
1636 nRunIndex = nIndex + 1;
1637 while (nRunIndex < infoPtr->nNumButtons) {
1638 btnPtr = &infoPtr->buttons[nRunIndex];
1639 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1640 if (btnPtr->fsState & TBSTATE_CHECKED)
1653 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1654 WPARAM wParam, LPARAM lParam)
1660 msg.wParam = wParam;
1661 msg.lParam = lParam;
1662 msg.time = GetMessageTime ();
1663 msg.pt.x = LOWORD(GetMessagePos ());
1664 msg.pt.y = HIWORD(GetMessagePos ());
1666 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1670 /***********************************************************************
1671 * TOOLBAR_CustomizeDialogProc
1672 * This function implements the toolbar customization dialog.
1674 static INT_PTR CALLBACK
1675 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1677 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1678 PCUSTOMBUTTON btnInfo;
1680 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1685 custInfo = (PCUSTDLG_INFO)lParam;
1686 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1694 infoPtr = custInfo->tbInfo;
1696 /* send TBN_QUERYINSERT notification */
1697 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1699 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1702 /* Send TBN_INITCUSTOMIZE notification */
1703 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) ==
1706 FIXME("TBNRF_HIDEHELP not supported\n");
1709 /* add items to 'toolbar buttons' list and check if removable */
1710 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1712 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1713 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1714 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1715 btnInfo->bVirtual = FALSE;
1716 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1718 /* send TBN_QUERYDELETE notification */
1719 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
1721 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1722 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1725 /* insert separator button into 'available buttons' list */
1726 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1727 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1728 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1729 btnInfo->bVirtual = FALSE;
1730 btnInfo->bRemovable = TRUE;
1731 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1732 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1733 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1735 /* insert all buttons into dsa */
1738 /* send TBN_GETBUTTONINFO notification */
1741 nmtb.pszText = Buffer;
1744 /* Clear previous button's text */
1745 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
1747 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
1750 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n",
1751 nmtb.tbButton.fsStyle, i,
1752 nmtb.tbButton.idCommand,
1753 nmtb.tbButton.iString,
1754 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
1757 /* insert button into the apropriate list */
1758 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1761 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1762 btnInfo->bVirtual = FALSE;
1763 btnInfo->bRemovable = TRUE;
1765 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1766 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX,
1767 LB_SETITEMDATA, index, (LPARAM)btnInfo);
1771 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd,
1772 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1775 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1776 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1778 if (lstrlenW(nmtb.pszText))
1779 lstrcpyW(btnInfo->text, nmtb.pszText);
1780 else if (nmtb.tbButton.iString >= 0 &&
1781 nmtb.tbButton.iString < infoPtr->nNumStrings)
1783 lstrcpyW(btnInfo->text,
1784 infoPtr->strings[nmtb.tbButton.iString]);
1789 /* select first item in the 'available' list */
1790 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1792 /* append 'virtual' separator button to the 'toolbar buttons' list */
1793 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1794 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1795 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1796 btnInfo->bVirtual = TRUE;
1797 btnInfo->bRemovable = FALSE;
1798 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1799 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1800 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1802 /* select last item in the 'toolbar' list */
1803 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1804 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1806 /* set focus and disable buttons */
1807 PostMessageA (hwnd, WM_USER, 0, 0);
1812 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1813 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1814 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1815 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1819 EndDialog(hwnd, FALSE);
1823 switch (LOWORD(wParam))
1825 case IDC_TOOLBARBTN_LBOX:
1826 if (HIWORD(wParam) == LBN_SELCHANGE)
1828 PCUSTOMBUTTON btnInfo;
1833 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1834 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1836 /* send TBN_QUERYINSERT notification */
1838 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1841 /* get list box item */
1842 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1844 if (index == (count - 1))
1846 /* last item (virtual separator) */
1847 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1848 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1850 else if (index == (count - 2))
1852 /* second last item (last non-virtual item) */
1853 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1854 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1856 else if (index == 0)
1859 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1860 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1864 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1865 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1868 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1872 case IDC_MOVEUP_BTN:
1874 PCUSTOMBUTTON btnInfo;
1878 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1879 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1880 TRACE("Move up: index %d\n", index);
1882 /* send TBN_QUERYINSERT notification */
1885 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1888 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1890 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1891 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1896 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1897 else if (index >= (count - 3))
1898 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1900 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1901 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1906 case IDC_MOVEDN_BTN: /* move down */
1908 PCUSTOMBUTTON btnInfo;
1912 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1913 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1914 TRACE("Move up: index %d\n", index);
1916 /* send TBN_QUERYINSERT notification */
1918 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1921 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1923 /* move button down */
1924 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1925 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1926 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1927 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1930 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1931 else if (index >= (count - 3))
1932 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1934 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1935 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1940 case IDC_REMOVE_BTN: /* remove button */
1942 PCUSTOMBUTTON btnInfo;
1945 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1947 if (LB_ERR == index)
1950 TRACE("Remove: index %d\n", index);
1952 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX,
1953 LB_GETITEMDATA, index, 0);
1955 /* send TBN_QUERYDELETE notification */
1956 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo))
1958 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1959 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1960 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1962 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1964 /* insert into 'available button' list */
1965 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1967 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1968 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1971 COMCTL32_Free (btnInfo);
1976 case IDOK: /* Add button */
1981 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1982 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1983 TRACE("Add: index %d\n", index);
1985 /* send TBN_QUERYINSERT notification */
1987 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1990 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1994 /* remove from 'available buttons' list */
1995 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1996 if (index == count-1)
1997 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1999 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
2003 PCUSTOMBUTTON btnNew;
2005 /* duplicate 'separator' button */
2006 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
2007 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
2011 /* insert into 'toolbar button' list */
2012 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2013 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
2014 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2016 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
2022 EndDialog(hwnd, FALSE);
2032 /* delete items from 'toolbar buttons' listbox*/
2033 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2034 for (i = 0; i < count; i++)
2036 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2037 COMCTL32_Free(btnInfo);
2038 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2040 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2043 /* delete items from 'available buttons' listbox*/
2044 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2045 for (i = 0; i < count; i++)
2047 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2048 COMCTL32_Free(btnInfo);
2049 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2051 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2056 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2058 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2059 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE);
2064 COLORREF oldText = 0;
2068 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2069 if (btnInfo == NULL)
2071 FIXME("btnInfo invalid!\n");
2075 /* set colors and select objects */
2076 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2077 if (btnInfo->bVirtual)
2078 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2080 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2081 hPen = CreatePen( PS_SOLID, 1,
2082 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2083 hOldPen = SelectObject (lpdis->hDC, hPen );
2084 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2086 /* fill background rectangle */
2087 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2088 lpdis->rcItem.right, lpdis->rcItem.bottom);
2090 /* calculate button and text rectangles */
2091 CopyRect (&rcButton, &lpdis->rcItem);
2092 InflateRect (&rcButton, -1, -1);
2093 CopyRect (&rcText, &rcButton);
2094 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2095 rcText.left = rcButton.right + 2;
2097 /* draw focus rectangle */
2098 if (lpdis->itemState & ODS_FOCUS)
2099 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2102 if (!(dwStyle & TBSTYLE_FLAT))
2103 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2105 /* draw image and text */
2106 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0) {
2107 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2108 btnInfo->btn.iBitmap));
2109 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2110 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2112 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2113 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2115 /* delete objects and reset colors */
2116 SelectObject (lpdis->hDC, hOldBrush);
2117 SelectObject (lpdis->hDC, hOldPen);
2118 SetBkColor (lpdis->hDC, oldBk);
2119 SetTextColor (lpdis->hDC, oldText);
2120 DeleteObject( hPen );
2125 case WM_MEASUREITEM:
2126 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2128 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2130 if (custInfo && custInfo->tbInfo)
2131 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2133 lpmis->itemHeight = 15 + 8; /* default height */
2145 /***********************************************************************
2146 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2150 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2153 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2154 INT nIndex = 0, nButtons, nCount;
2158 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2162 if (lpAddBmp->hInst == HINST_COMMCTRL)
2164 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2166 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2168 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2173 TRACE ("adding %d internal bitmaps!\n", nButtons);
2175 /* Windows resize all the buttons to the size of a newly added standard image */
2176 if (lpAddBmp->nID & 1)
2179 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2180 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2182 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2183 MAKELPARAM((WORD)24, (WORD)24));
2184 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2185 MAKELPARAM((WORD)31, (WORD)30));
2190 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2191 MAKELPARAM((WORD)16, (WORD)16));
2192 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2193 MAKELPARAM((WORD)22, (WORD)22));
2196 TOOLBAR_CalcToolbar (hwnd);
2200 nButtons = (INT)wParam;
2204 TRACE ("adding %d bitmaps!\n", nButtons);
2207 if (!infoPtr->cimlDef) {
2208 /* create new default image list */
2209 TRACE ("creating default image list!\n");
2211 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2212 ILC_COLOR | ILC_MASK, nButtons, 2);
2213 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2214 infoPtr->himlInt = himlDef;
2217 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2221 WARN("No default image list available\n");
2225 nCount = ImageList_GetImageCount(himlDef);
2227 /* Add bitmaps to the default image list */
2228 if (lpAddBmp->hInst == (HINSTANCE)0)
2231 ImageList_AddMasked (himlDef, (HBITMAP)lpAddBmp->nID,
2234 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2236 /* Add system bitmaps */
2237 switch (lpAddBmp->nID)
2239 case IDB_STD_SMALL_COLOR:
2240 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2241 MAKEINTRESOURCEA(IDB_STD_SMALL));
2242 nIndex = ImageList_AddMasked (himlDef,
2243 hbmLoad, CLR_DEFAULT);
2244 DeleteObject (hbmLoad);
2247 case IDB_STD_LARGE_COLOR:
2248 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2249 MAKEINTRESOURCEA(IDB_STD_LARGE));
2250 nIndex = ImageList_AddMasked (himlDef,
2251 hbmLoad, CLR_DEFAULT);
2252 DeleteObject (hbmLoad);
2255 case IDB_VIEW_SMALL_COLOR:
2256 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2257 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2258 nIndex = ImageList_AddMasked (himlDef,
2259 hbmLoad, CLR_DEFAULT);
2260 DeleteObject (hbmLoad);
2263 case IDB_VIEW_LARGE_COLOR:
2264 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2265 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2266 nIndex = ImageList_AddMasked (himlDef,
2267 hbmLoad, CLR_DEFAULT);
2268 DeleteObject (hbmLoad);
2271 case IDB_HIST_SMALL_COLOR:
2272 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2273 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2274 nIndex = ImageList_AddMasked (himlDef,
2275 hbmLoad, CLR_DEFAULT);
2276 DeleteObject (hbmLoad);
2279 case IDB_HIST_LARGE_COLOR:
2280 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2281 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2282 nIndex = ImageList_AddMasked (himlDef,
2283 hbmLoad, CLR_DEFAULT);
2284 DeleteObject (hbmLoad);
2288 nIndex = ImageList_GetImageCount (himlDef);
2289 ERR ("invalid imagelist!\n");
2295 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2296 nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT);
2297 DeleteObject (hbmLoad);
2300 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2302 if (infoPtr->nNumBitmapInfos == 0)
2304 infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
2308 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2309 infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2310 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2313 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2314 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2315 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2317 infoPtr->nNumBitmapInfos++;
2318 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2322 INT imagecount = ImageList_GetImageCount(himlDef);
2324 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2326 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",
2327 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2328 infoPtr->nNumBitmaps+nButtons,imagecount);
2330 infoPtr->nNumBitmaps = imagecount;
2333 infoPtr->nNumBitmaps += nButtons;
2336 InvalidateRect(hwnd, NULL, FALSE);
2343 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2345 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2346 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2347 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2349 TRACE("adding %d buttons!\n", wParam);
2351 nAddButtons = (UINT)wParam;
2352 nOldButtons = infoPtr->nNumButtons;
2353 nNewButtons = nOldButtons + nAddButtons;
2355 if (infoPtr->nNumButtons == 0) {
2357 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2360 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2362 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2363 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2364 nOldButtons * sizeof(TBUTTON_INFO));
2365 COMCTL32_Free (oldButtons);
2368 infoPtr->nNumButtons = nNewButtons;
2370 /* insert new button data */
2371 for (nCount = 0; nCount < nAddButtons; nCount++) {
2372 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2373 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2374 btnPtr->idCommand = lpTbb[nCount].idCommand;
2375 btnPtr->fsState = lpTbb[nCount].fsState;
2376 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2377 btnPtr->dwData = lpTbb[nCount].dwData;
2378 btnPtr->iString = lpTbb[nCount].iString;
2379 btnPtr->bHot = FALSE;
2381 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2384 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2385 ti.cbSize = sizeof (TTTOOLINFOA);
2387 ti.uId = btnPtr->idCommand;
2389 ti.lpszText = LPSTR_TEXTCALLBACKA;
2391 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2396 TOOLBAR_CalcToolbar (hwnd);
2398 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2400 InvalidateRect(hwnd, NULL, FALSE);
2407 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2409 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2410 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2411 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2413 TRACE("adding %d buttons!\n", wParam);
2415 nAddButtons = (UINT)wParam;
2416 nOldButtons = infoPtr->nNumButtons;
2417 nNewButtons = nOldButtons + nAddButtons;
2419 if (infoPtr->nNumButtons == 0) {
2421 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2424 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2426 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2427 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2428 nOldButtons * sizeof(TBUTTON_INFO));
2429 COMCTL32_Free (oldButtons);
2432 infoPtr->nNumButtons = nNewButtons;
2434 /* insert new button data */
2435 for (nCount = 0; nCount < nAddButtons; nCount++) {
2436 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2437 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2438 btnPtr->idCommand = lpTbb[nCount].idCommand;
2439 btnPtr->fsState = lpTbb[nCount].fsState;
2440 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2441 btnPtr->dwData = lpTbb[nCount].dwData;
2442 btnPtr->iString = lpTbb[nCount].iString;
2443 btnPtr->bHot = FALSE;
2445 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2448 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2449 ti.cbSize = sizeof (TTTOOLINFOW);
2451 ti.uId = btnPtr->idCommand;
2453 ti.lpszText = LPSTR_TEXTCALLBACKW;
2456 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2461 TOOLBAR_CalcToolbar (hwnd);
2463 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2465 InvalidateRect(hwnd, NULL, FALSE);
2472 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2474 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2477 if ((wParam) && (HIWORD(lParam) == 0)) {
2480 TRACE("adding string from resource!\n");
2482 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2485 TRACE("len=%d \"%s\"\n", len, szString);
2486 nIndex = infoPtr->nNumStrings;
2487 if (infoPtr->nNumStrings == 0) {
2489 COMCTL32_Alloc (sizeof(LPWSTR));
2492 LPWSTR *oldStrings = infoPtr->strings;
2494 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2495 memcpy (&infoPtr->strings[0], &oldStrings[0],
2496 sizeof(LPWSTR) * infoPtr->nNumStrings);
2497 COMCTL32_Free (oldStrings);
2500 /*COMCTL32_Alloc zeros out the allocated memory*/
2501 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2502 infoPtr->nNumStrings++;
2505 LPSTR p = (LPSTR)lParam;
2510 TRACE("adding string(s) from array!\n");
2512 nIndex = infoPtr->nNumStrings;
2515 TRACE("len=%d \"%s\"\n", len, p);
2517 if (infoPtr->nNumStrings == 0) {
2519 COMCTL32_Alloc (sizeof(LPWSTR));
2522 LPWSTR *oldStrings = infoPtr->strings;
2524 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2525 memcpy (&infoPtr->strings[0], &oldStrings[0],
2526 sizeof(LPWSTR) * infoPtr->nNumStrings);
2527 COMCTL32_Free (oldStrings);
2530 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2531 infoPtr->nNumStrings++;
2542 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2544 #define MAX_RESOURCE_STRING_LENGTH 512
2545 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2548 if ((wParam) && (HIWORD(lParam) == 0)) {
2549 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2551 TRACE("adding string from resource!\n");
2553 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2554 szString, MAX_RESOURCE_STRING_LENGTH);
2556 TRACE("len=%d %s\n", len, debugstr_w(szString));
2557 TRACE("First char: 0x%x\n", *szString);
2558 if (szString[0] == L'|')
2560 PWSTR p = szString + 1;
2562 nIndex = infoPtr->nNumStrings;
2563 while (*p != L'|' && *p != L'\0') {
2566 if (infoPtr->nNumStrings == 0) {
2567 infoPtr->strings = COMCTL32_Alloc (sizeof(LPWSTR));
2571 LPWSTR *oldStrings = infoPtr->strings;
2572 infoPtr->strings = COMCTL32_Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2573 memcpy(&infoPtr->strings[0], &oldStrings[0],
2574 sizeof(LPWSTR) * infoPtr->nNumStrings);
2575 COMCTL32_Free(oldStrings);
2578 np=COMCTL32_StrChrW (p, L'|');
2586 TRACE("len=%d %s\n", len, debugstr_w(p));
2587 infoPtr->strings[infoPtr->nNumStrings] =
2588 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2589 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2590 infoPtr->nNumStrings++;
2597 nIndex = infoPtr->nNumStrings;
2598 if (infoPtr->nNumStrings == 0) {
2600 COMCTL32_Alloc (sizeof(LPWSTR));
2603 LPWSTR *oldStrings = infoPtr->strings;
2605 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2606 memcpy (&infoPtr->strings[0], &oldStrings[0],
2607 sizeof(LPWSTR) * infoPtr->nNumStrings);
2608 COMCTL32_Free (oldStrings);
2611 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2612 infoPtr->nNumStrings++;
2616 LPWSTR p = (LPWSTR)lParam;
2621 TRACE("adding string(s) from array!\n");
2622 nIndex = infoPtr->nNumStrings;
2626 TRACE("len=%d %s\n", len, debugstr_w(p));
2627 if (infoPtr->nNumStrings == 0) {
2629 COMCTL32_Alloc (sizeof(LPWSTR));
2632 LPWSTR *oldStrings = infoPtr->strings;
2634 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2635 memcpy (&infoPtr->strings[0], &oldStrings[0],
2636 sizeof(LPWSTR) * infoPtr->nNumStrings);
2637 COMCTL32_Free (oldStrings);
2640 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2641 infoPtr->nNumStrings++;
2652 TOOLBAR_AutoSize (HWND hwnd)
2654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2655 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2661 UINT uPosFlags = SWP_NOZORDER;
2663 TRACE("resize forced, style=%lx!\n", dwStyle);
2665 parent = GetParent (hwnd);
2666 GetClientRect(parent, &parent_rect);
2668 x = parent_rect.left;
2669 y = parent_rect.top;
2671 /* FIXME: we should be able to early out if nothing */
2672 /* has changed with nWidth != parent_rect width */
2674 if (dwStyle & CCS_NORESIZE) {
2675 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2678 TOOLBAR_CalcToolbar (hwnd);
2681 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2682 TOOLBAR_CalcToolbar (hwnd);
2683 InvalidateRect( hwnd, NULL, TRUE );
2684 cy = infoPtr->nHeight;
2685 cx = infoPtr->nWidth;
2687 if (dwStyle & CCS_NOMOVEY) {
2688 GetWindowRect(hwnd, &window_rect);
2689 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2690 y = window_rect.top;
2694 if (dwStyle & CCS_NOPARENTALIGN)
2695 uPosFlags |= SWP_NOMOVE;
2697 if (!(dwStyle & CCS_NODIVIDER))
2698 cy += GetSystemMetrics(SM_CYEDGE);
2700 if (dwStyle & WS_BORDER)
2703 cy += GetSystemMetrics(SM_CYEDGE);
2704 cx += GetSystemMetrics(SM_CYEDGE);
2707 infoPtr->bAutoSize = TRUE;
2708 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2710 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2711 * the setwindowpos calls */
2712 infoPtr->bAutoSize = FALSE;
2719 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2721 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2723 return infoPtr->nNumButtons;
2728 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2732 if (infoPtr == NULL) {
2733 ERR("(%p, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2734 ERR("infoPtr == NULL!\n");
2738 infoPtr->dwStructSize = (DWORD)wParam;
2745 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2747 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2748 TBUTTON_INFO *btnPtr;
2751 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2755 btnPtr = &infoPtr->buttons[nIndex];
2756 btnPtr->iBitmap = LOWORD(lParam);
2758 /* we HAVE to erase the background, the new bitmap could be */
2760 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2767 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2770 TBUTTON_INFO *btnPtr;
2773 BOOL bChecked = FALSE;
2775 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2779 btnPtr = &infoPtr->buttons[nIndex];
2781 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2784 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2786 if (LOWORD(lParam) == FALSE)
2787 btnPtr->fsState &= ~TBSTATE_CHECKED;
2789 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2791 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2792 if (nOldIndex == nIndex)
2794 if (nOldIndex != -1)
2795 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2797 btnPtr->fsState |= TBSTATE_CHECKED;
2800 if( bChecked != LOWORD(lParam) )
2802 if (nOldIndex != -1)
2804 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2805 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2807 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2810 /* FIXME: Send a WM_NOTIFY?? */
2817 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2819 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2821 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2826 TOOLBAR_Customize (HWND hwnd)
2828 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2829 CUSTDLG_INFO custInfo;
2835 custInfo.tbInfo = infoPtr;
2836 custInfo.tbHwnd = hwnd;
2838 /* send TBN_BEGINADJUST notification */
2839 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2842 if (!(hRes = FindResourceA (COMCTL32_hModule,
2843 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2847 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2850 ret = DialogBoxIndirectParamA ((HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE),
2851 (LPDLGTEMPLATEA)template,
2853 TOOLBAR_CustomizeDialogProc,
2856 /* send TBN_ENDADJUST notification */
2857 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2865 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2867 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2868 INT nIndex = (INT)wParam;
2870 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2873 if ((infoPtr->hwndToolTip) &&
2874 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2877 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2878 ti.cbSize = sizeof (TTTOOLINFOA);
2880 ti.uId = infoPtr->buttons[nIndex].idCommand;
2882 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2885 if (infoPtr->nNumButtons == 1) {
2886 TRACE(" simple delete!\n");
2887 COMCTL32_Free (infoPtr->buttons);
2888 infoPtr->buttons = NULL;
2889 infoPtr->nNumButtons = 0;
2892 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2893 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2895 infoPtr->nNumButtons--;
2896 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2898 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2899 nIndex * sizeof(TBUTTON_INFO));
2902 if (nIndex < infoPtr->nNumButtons) {
2903 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2904 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2907 COMCTL32_Free (oldButtons);
2910 TOOLBAR_CalcToolbar (hwnd);
2912 InvalidateRect (hwnd, NULL, TRUE);
2919 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2922 TBUTTON_INFO *btnPtr;
2926 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2930 btnPtr = &infoPtr->buttons[nIndex];
2932 bState = btnPtr->fsState & TBSTATE_ENABLED;
2934 /* update the toolbar button state */
2935 if(LOWORD(lParam) == FALSE) {
2936 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2938 btnPtr->fsState |= TBSTATE_ENABLED;
2941 /* redraw the button only if the state of the button changed */
2942 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2944 InvalidateRect(hwnd, &btnPtr->rect,
2945 TOOLBAR_HasText(infoPtr, btnPtr));
2952 static inline LRESULT
2953 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2955 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2957 return infoPtr->bAnchor;
2962 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2964 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2967 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2971 return infoPtr->buttons[nIndex].iBitmap;
2975 static inline LRESULT
2976 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2978 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2983 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2985 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2986 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2987 INT nIndex = (INT)wParam;
2988 TBUTTON_INFO *btnPtr;
2990 if (infoPtr == NULL)
2996 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2999 btnPtr = &infoPtr->buttons[nIndex];
3000 lpTbb->iBitmap = btnPtr->iBitmap;
3001 lpTbb->idCommand = btnPtr->idCommand;
3002 lpTbb->fsState = btnPtr->fsState;
3003 lpTbb->fsStyle = btnPtr->fsStyle;
3004 lpTbb->dwData = btnPtr->dwData;
3005 lpTbb->iString = btnPtr->iString;
3012 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3014 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3015 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
3016 TBUTTON_INFO *btnPtr;
3019 if (infoPtr == NULL)
3021 if (lpTbInfo == NULL)
3023 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
3026 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3027 lpTbInfo->dwMask & 0x80000000);
3031 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3033 if (lpTbInfo->dwMask & TBIF_COMMAND)
3034 lpTbInfo->idCommand = btnPtr->idCommand;
3035 if (lpTbInfo->dwMask & TBIF_IMAGE)
3036 lpTbInfo->iImage = btnPtr->iBitmap;
3037 if (lpTbInfo->dwMask & TBIF_LPARAM)
3038 lpTbInfo->lParam = btnPtr->dwData;
3039 if (lpTbInfo->dwMask & TBIF_SIZE)
3040 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3041 if (lpTbInfo->dwMask & TBIF_STATE)
3042 lpTbInfo->fsState = btnPtr->fsState;
3043 if (lpTbInfo->dwMask & TBIF_STYLE)
3044 lpTbInfo->fsStyle = btnPtr->fsStyle;
3045 if (lpTbInfo->dwMask & TBIF_TEXT) {
3046 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3047 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
3054 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3057 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
3058 TBUTTON_INFO *btnPtr;
3061 if (infoPtr == NULL)
3063 if (lpTbInfo == NULL)
3065 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
3068 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3069 lpTbInfo->dwMask & 0x80000000);
3073 btnPtr = &infoPtr->buttons[nIndex];
3078 if (lpTbInfo->dwMask & TBIF_COMMAND)
3079 lpTbInfo->idCommand = btnPtr->idCommand;
3080 if (lpTbInfo->dwMask & TBIF_IMAGE)
3081 lpTbInfo->iImage = btnPtr->iBitmap;
3082 if (lpTbInfo->dwMask & TBIF_LPARAM)
3083 lpTbInfo->lParam = btnPtr->dwData;
3084 if (lpTbInfo->dwMask & TBIF_SIZE)
3085 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3086 if (lpTbInfo->dwMask & TBIF_STATE)
3087 lpTbInfo->fsState = btnPtr->fsState;
3088 if (lpTbInfo->dwMask & TBIF_STYLE)
3089 lpTbInfo->fsStyle = btnPtr->fsStyle;
3090 if (lpTbInfo->dwMask & TBIF_TEXT) {
3091 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3092 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3100 TOOLBAR_GetButtonSize (HWND hwnd)
3102 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3104 if (infoPtr->nNumButtons > 0)
3105 return MAKELONG((WORD)infoPtr->nButtonWidth,
3106 (WORD)infoPtr->nButtonHeight);
3108 return MAKELONG(8,7);
3113 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3115 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3122 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3126 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3128 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3129 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3134 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3136 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3143 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3147 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3149 strcpyW ((LPWSTR)lParam, lpText);
3151 return strlenW (lpText);
3156 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3158 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0);
3162 inline static LRESULT
3163 TOOLBAR_GetExtendedStyle (HWND hwnd)
3165 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3167 return infoPtr->dwExStyle;
3172 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3174 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0);
3179 TOOLBAR_GetHotItem (HWND hwnd)
3181 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3183 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3186 if (infoPtr->nHotItem < 0)
3189 return (LRESULT)infoPtr->nHotItem;
3194 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3196 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), 0);
3200 /* << TOOLBAR_GetInsertMark >> */
3201 /* << TOOLBAR_GetInsertMarkColor >> */
3205 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3208 TBUTTON_INFO *btnPtr;
3212 if (infoPtr == NULL)
3214 nIndex = (INT)wParam;
3215 btnPtr = &infoPtr->buttons[nIndex];
3216 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3218 lpRect = (LPRECT)lParam;
3221 if (btnPtr->fsState & TBSTATE_HIDDEN)
3224 lpRect->left = btnPtr->rect.left;
3225 lpRect->right = btnPtr->rect.right;
3226 lpRect->bottom = btnPtr->rect.bottom;
3227 lpRect->top = btnPtr->rect.top;
3234 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3236 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3237 LPSIZE lpSize = (LPSIZE)lParam;
3242 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3243 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3245 TRACE("maximum size %d x %d\n",
3246 infoPtr->rcBound.right - infoPtr->rcBound.left,
3247 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3253 /* << TOOLBAR_GetObject >> */
3257 TOOLBAR_GetPadding (HWND hwnd)
3259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3262 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3263 return (LRESULT) oldPad;
3268 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3271 TBUTTON_INFO *btnPtr;
3275 if (infoPtr == NULL)
3277 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3278 btnPtr = &infoPtr->buttons[nIndex];
3279 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3281 lpRect = (LPRECT)lParam;
3285 lpRect->left = btnPtr->rect.left;
3286 lpRect->right = btnPtr->rect.right;
3287 lpRect->bottom = btnPtr->rect.bottom;
3288 lpRect->top = btnPtr->rect.top;
3295 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3299 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3300 return infoPtr->nRows;
3307 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3309 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3312 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3316 return infoPtr->buttons[nIndex].fsState;
3321 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3323 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3326 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3330 return infoPtr->buttons[nIndex].fsStyle;
3335 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3339 if (infoPtr == NULL)
3342 return infoPtr->nMaxTextRows;
3347 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3349 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3351 if (infoPtr == NULL)
3353 return (LRESULT)infoPtr->hwndToolTip;
3358 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3360 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 TRACE("%s hwnd=%p stub!\n",
3363 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3365 return infoPtr->bUnicode;
3369 inline static LRESULT
3370 TOOLBAR_GetVersion (HWND hwnd)
3372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3373 return infoPtr->iVersion;
3378 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3381 TBUTTON_INFO *btnPtr;
3386 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3390 btnPtr = &infoPtr->buttons[nIndex];
3391 if (LOWORD(lParam) == FALSE)
3392 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3394 btnPtr->fsState |= TBSTATE_HIDDEN;
3396 TOOLBAR_CalcToolbar (hwnd);
3398 InvalidateRect (hwnd, NULL, TRUE);
3404 inline static LRESULT
3405 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3407 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3412 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3414 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3415 TBUTTON_INFO *btnPtr;
3418 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3422 btnPtr = &infoPtr->buttons[nIndex];
3423 if (LOWORD(lParam) == FALSE)
3424 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3426 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3428 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3435 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3437 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3438 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3439 INT nIndex = (INT)wParam;
3440 TBUTTON_INFO *oldButtons;
3445 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3448 /* EPP: this seems to be an undocumented call (from my IE4)
3449 * I assume in that case that:
3450 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3451 * - index of insertion is at the end of existing buttons
3452 * I only see this happen with nIndex == -1, but it could have a special
3453 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3455 nIndex = infoPtr->nNumButtons;
3457 } else if (nIndex < 0)
3460 /* If the string passed is not an index, assume address of string
3461 and do our own AddString */
3462 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3466 TRACE("string %s passed instead of index, adding string\n",
3467 debugstr_a((LPSTR)lpTbb->iString));
3468 len = strlen((LPSTR)lpTbb->iString) + 2;
3469 ptr = COMCTL32_Alloc(len);
3470 strcpy(ptr, (LPSTR)lpTbb->iString);
3471 ptr[len - 1] = 0; /* ended by two '\0' */
3472 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3476 TRACE("inserting button index=%d\n", nIndex);
3477 if (nIndex > infoPtr->nNumButtons) {
3478 nIndex = infoPtr->nNumButtons;
3479 TRACE("adjust index=%d\n", nIndex);
3482 oldButtons = infoPtr->buttons;
3483 infoPtr->nNumButtons++;
3484 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3485 /* pre insert copy */
3487 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3488 nIndex * sizeof(TBUTTON_INFO));
3491 /* insert new button */
3492 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3493 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3494 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3495 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3496 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3497 /* if passed string and not index, then add string */
3498 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3499 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3502 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3504 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3507 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3508 ti.cbSize = sizeof (TTTOOLINFOA);
3510 ti.uId = lpTbb->idCommand;
3512 ti.lpszText = LPSTR_TEXTCALLBACKA;
3514 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3518 /* post insert copy */
3519 if (nIndex < infoPtr->nNumButtons - 1) {
3520 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3521 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3524 COMCTL32_Free (oldButtons);
3526 TOOLBAR_CalcToolbar (hwnd);
3528 InvalidateRect (hwnd, NULL, TRUE);
3535 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3537 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3538 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3539 INT nIndex = (INT)wParam;
3540 TBUTTON_INFO *oldButtons;
3545 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3548 /* EPP: this seems to be an undocumented call (from my IE4)
3549 * I assume in that case that:
3550 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3551 * - index of insertion is at the end of existing buttons
3552 * I only see this happen with nIndex == -1, but it could have a special
3553 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3555 nIndex = infoPtr->nNumButtons;
3557 } else if (nIndex < 0)
3560 /* If the string passed is not an index, assume address of string
3561 and do our own AddString */
3562 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3566 TRACE("string %s passed instead of index, adding string\n",
3567 debugstr_w((LPWSTR)lpTbb->iString));
3568 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3569 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3570 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3571 ptr[len - 1] = 0; /* ended by two '\0' */
3572 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3576 TRACE("inserting button index=%d\n", nIndex);
3577 if (nIndex > infoPtr->nNumButtons) {
3578 nIndex = infoPtr->nNumButtons;
3579 TRACE("adjust index=%d\n", nIndex);
3582 oldButtons = infoPtr->buttons;
3583 infoPtr->nNumButtons++;
3584 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3585 /* pre insert copy */
3587 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3588 nIndex * sizeof(TBUTTON_INFO));
3591 /* insert new button */
3592 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3593 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3594 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3595 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3596 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3597 /* if passed string and not index, then add string */
3598 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3599 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3602 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3604 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3607 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3608 ti.cbSize = sizeof (TTTOOLINFOW);
3610 ti.uId = lpTbb->idCommand;
3612 ti.lpszText = LPSTR_TEXTCALLBACKW;
3614 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3618 /* post insert copy */
3619 if (nIndex < infoPtr->nNumButtons - 1) {
3620 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3621 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3624 COMCTL32_Free (oldButtons);
3626 TOOLBAR_CalcToolbar (hwnd);
3628 InvalidateRect (hwnd, NULL, TRUE);
3634 /* << TOOLBAR_InsertMarkHitTest >> */
3638 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3640 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3643 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3647 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3652 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3657 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3661 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3666 TOOLBAR_IsButtonHidden (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_HIDDEN);
3680 TOOLBAR_IsButtonHighlighted (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_MARKED);
3694 TOOLBAR_IsButtonIndeterminate (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_INDETERMINATE);
3708 TOOLBAR_IsButtonPressed (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_PRESSED);
3721 /* << TOOLBAR_LoadImages >> */
3722 /* << TOOLBAR_MapAccelerator >> */
3723 /* << TOOLBAR_MarkButton >> */
3724 /* << TOOLBAR_MoveButton >> */
3728 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3730 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3731 TBUTTON_INFO *btnPtr;
3734 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3738 btnPtr = &infoPtr->buttons[nIndex];
3739 if (LOWORD(lParam) == FALSE)
3740 btnPtr->fsState &= ~TBSTATE_PRESSED;
3742 btnPtr->fsState |= TBSTATE_PRESSED;
3744 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3751 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3753 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3754 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3756 int i = 0, nOldButtons = 0, pos = 0;
3757 HIMAGELIST himlDef = 0;
3759 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n",
3760 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3761 lpReplace->nButtons);
3763 if (lpReplace->hInstOld == HINST_COMMCTRL)
3765 FIXME("changing standard bitmaps not implemented\n");
3768 else if (lpReplace->hInstOld != 0)
3770 FIXME("resources not in the current module not implemented\n");
3775 hBitmap = (HBITMAP) lpReplace->nIDNew;
3778 TRACE("To be replaced hInstOld %p nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3779 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3780 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3781 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3782 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3784 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3785 nOldButtons = tbi->nButtons;
3786 tbi->nButtons = lpReplace->nButtons;
3787 tbi->hInst = lpReplace->hInstNew;
3788 tbi->nID = lpReplace->nIDNew;
3789 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3792 pos += tbi->nButtons;
3795 if (nOldButtons == 0)
3797 WARN("No hinst/bitmap found! hInst %p nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3801 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
3803 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
3806 himlDef = GETDEFIMAGELIST(infoPtr, 0);
3807 for (i = pos + nOldButtons - 1; i >= pos; i--) {
3808 ImageList_Remove(himlDef, i);
3811 ImageList_AddMasked(himlDef, hBitmap, CLR_DEFAULT);
3813 InvalidateRect(hwnd, NULL, FALSE);
3819 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3823 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3825 if (lpSave == NULL) return 0;
3828 /* save toolbar information */
3829 FIXME("save to \"%s\" \"%s\"\n",
3830 lpSave->pszSubKey, lpSave->pszValueName);
3835 /* restore toolbar information */
3837 FIXME("restore from \"%s\" \"%s\"\n",
3838 lpSave->pszSubKey, lpSave->pszValueName);
3849 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3853 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3859 /* save toolbar information */
3860 FIXME("save to \"%s\" \"%s\"\n",
3861 lpSave->pszSubKey, lpSave->pszValueName);
3866 /* restore toolbar information */
3868 FIXME("restore from \"%s\" \"%s\"\n",
3869 lpSave->pszSubKey, lpSave->pszValueName);
3880 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3883 BOOL bOldAnchor = infoPtr->bAnchor;
3885 infoPtr->bAnchor = (BOOL)wParam;
3887 return (LRESULT)bOldAnchor;
3892 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3895 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
3897 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3900 if (infoPtr->nNumButtons > 0)
3901 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3902 infoPtr->nNumButtons,
3903 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3904 LOWORD(lParam), HIWORD(lParam));
3906 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3907 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3909 /* uses image list internals directly */
3911 himlDef->cx = infoPtr->nBitmapWidth;
3912 himlDef->cy = infoPtr->nBitmapHeight;
3920 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3923 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3924 TBUTTON_INFO *btnPtr;
3929 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3932 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3933 lptbbi->dwMask & 0x80000000);
3937 btnPtr = &infoPtr->buttons[nIndex];
3938 if (lptbbi->dwMask & TBIF_COMMAND)
3939 btnPtr->idCommand = lptbbi->idCommand;
3940 if (lptbbi->dwMask & TBIF_IMAGE)
3941 btnPtr->iBitmap = lptbbi->iImage;
3942 if (lptbbi->dwMask & TBIF_LPARAM)
3943 btnPtr->dwData = lptbbi->lParam;
3944 /* if (lptbbi->dwMask & TBIF_SIZE) */
3945 /* btnPtr->cx = lptbbi->cx; */
3946 if (lptbbi->dwMask & TBIF_STATE)
3947 btnPtr->fsState = lptbbi->fsState;
3948 if (lptbbi->dwMask & TBIF_STYLE)
3949 btnPtr->fsStyle = lptbbi->fsStyle;
3951 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3952 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3953 /* iString is index, zero it to make Str_SetPtr succeed */
3956 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3963 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3965 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3966 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3967 TBUTTON_INFO *btnPtr;
3972 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3975 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3976 lptbbi->dwMask & 0x80000000);
3980 btnPtr = &infoPtr->buttons[nIndex];
3981 if (lptbbi->dwMask & TBIF_COMMAND)
3982 btnPtr->idCommand = lptbbi->idCommand;
3983 if (lptbbi->dwMask & TBIF_IMAGE)
3984 btnPtr->iBitmap = lptbbi->iImage;
3985 if (lptbbi->dwMask & TBIF_LPARAM)
3986 btnPtr->dwData = lptbbi->lParam;
3987 /* if (lptbbi->dwMask & TBIF_SIZE) */
3988 /* btnPtr->cx = lptbbi->cx; */
3989 if (lptbbi->dwMask & TBIF_STATE)
3990 btnPtr->fsState = lptbbi->fsState;
3991 if (lptbbi->dwMask & TBIF_STYLE)
3992 btnPtr->fsStyle = lptbbi->fsStyle;
3994 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3995 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3996 /* iString is index, zero it to make Str_SetPtr succeed */
3998 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4005 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4007 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4008 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
4010 if ((cx < 0) || (cy < 0))
4012 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
4016 /* The documentation claims you can only change the button size before
4017 * any button has been added. But this is wrong.
4018 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4019 * it to the toolbar, and it checks that the return value is nonzero - mjm
4020 * Further testing shows that we must actually perform the change too.
4023 * The documentation also does not mention that if 0 is supplied for
4024 * either size, the system changes it to the default of 24 wide and
4025 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
4027 infoPtr->nButtonWidth = (cx) ? cx : 24;
4028 infoPtr->nButtonHeight = (cy) ? cy : 22;
4034 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
4036 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4038 if (infoPtr == NULL) {
4039 TRACE("Toolbar not initialized yet?????\n");
4043 /* if setting to current values, ignore */
4044 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
4045 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
4046 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4047 infoPtr->cxMin, infoPtr->cxMax);
4051 /* save new values */
4052 infoPtr->cxMin = (INT)LOWORD(lParam);
4053 infoPtr->cxMax = (INT)HIWORD(lParam);
4055 /* if both values are 0 then we are done */
4057 TRACE("setting both min and max to 0, norecalc\n");
4061 /* otherwise we need to recalc the toolbar and in some cases
4062 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4063 which doesn't actually draw - GA). */
4064 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4065 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4067 TOOLBAR_CalcToolbar (hwnd);
4069 InvalidateRect (hwnd, NULL, TRUE);
4076 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
4078 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4079 INT nIndex = (INT)wParam;
4081 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4084 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4086 if (infoPtr->hwndToolTip) {
4088 FIXME("change tool tip!\n");
4097 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4099 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4100 HIMAGELIST himl = (HIMAGELIST)lParam;
4101 HIMAGELIST himlTemp;
4104 if (infoPtr->iVersion >= 5)
4107 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4108 &infoPtr->cimlDis, himl, id);
4110 /* FIXME: redraw ? */
4112 return (LRESULT)himlTemp;
4117 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4122 dwTemp = infoPtr->dwDTFlags;
4123 infoPtr->dwDTFlags =
4124 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4126 return (LRESULT)dwTemp;
4130 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4132 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4135 dwTemp = infoPtr->dwExStyle;
4136 infoPtr->dwExStyle = (DWORD)lParam;
4138 if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
4139 TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
4140 FIXME("Extended style not implemented %s %s\n",
4141 (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
4142 "TBSTYLE_EX_MIXEDBUTTONS" : "",
4143 (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
4144 "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
4147 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4148 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4149 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4151 return (LRESULT)dwTemp;
4156 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4158 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4159 HIMAGELIST himlTemp;
4160 HIMAGELIST himl = (HIMAGELIST)lParam;
4163 if (infoPtr->iVersion >= 5)
4166 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4167 &infoPtr->cimlHot, himl, id);
4169 /* FIXME: redraw ? */
4171 return (LRESULT)himlTemp;
4176 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4179 INT nOldHotItem = infoPtr->nHotItem;
4180 TBUTTON_INFO *btnPtr;
4182 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4185 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4188 infoPtr->nHotItem = (INT)wParam;
4189 if ((INT)wParam >=0)
4191 btnPtr = &infoPtr->buttons[(INT)wParam];
4192 btnPtr->bHot = TRUE;
4193 InvalidateRect (hwnd, &btnPtr->rect,
4194 TOOLBAR_HasText(infoPtr, btnPtr));
4198 btnPtr = &infoPtr->buttons[nOldHotItem];
4199 btnPtr->bHot = FALSE;
4200 InvalidateRect (hwnd, &btnPtr->rect,
4201 TOOLBAR_HasText(infoPtr, btnPtr));
4205 if (nOldHotItem < 0)
4208 return (LRESULT)nOldHotItem;
4213 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4215 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4216 HIMAGELIST himlTemp;
4217 HIMAGELIST himl = (HIMAGELIST)lParam;
4220 if (infoPtr->iVersion >= 5)
4223 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4224 &infoPtr->cimlDef, himl, id);
4226 infoPtr->nNumBitmaps = 0;
4227 for (i = 0; i < infoPtr->cimlDef; i++)
4228 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4230 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4231 &infoPtr->nBitmapHeight);
4232 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4233 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4234 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4236 /* FIXME: redraw ? */
4237 InvalidateRect(hwnd, NULL, TRUE);
4239 return (LRESULT)himlTemp;
4244 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4246 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4248 infoPtr->nIndent = (INT)wParam;
4252 /* process only on indent changing */
4253 if(infoPtr->nIndent != (INT)wParam)
4255 infoPtr->nIndent = (INT)wParam;
4256 TOOLBAR_CalcToolbar (hwnd);
4257 InvalidateRect(hwnd, NULL, FALSE);
4264 /* << TOOLBAR_SetInsertMark >> */
4268 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4270 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4272 infoPtr->clrInsertMark = (COLORREF)lParam;
4274 /* FIXME : redraw ??*/
4281 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4283 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4285 if (infoPtr == NULL)
4288 infoPtr->nMaxTextRows = (INT)wParam;
4295 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4300 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4301 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4302 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4303 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4304 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4305 return (LRESULT) oldPad;
4310 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4312 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4317 if (infoPtr == NULL)
4319 hwndOldNotify = infoPtr->hwndNotify;
4320 infoPtr->hwndNotify = (HWND)wParam;
4322 return (LRESULT)hwndOldNotify;
4327 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4330 LPRECT lprc = (LPRECT)lParam;
4334 if (LOWORD(wParam) > 1) {
4335 FIXME("multiple rows not supported!\n");
4338 if(infoPtr->nRows != LOWORD(wParam))
4340 infoPtr->nRows = LOWORD(wParam);
4342 /* recalculate toolbar */
4343 TOOLBAR_CalcToolbar (hwnd);
4345 /* repaint toolbar */
4346 InvalidateRect(hwnd, NULL, FALSE);
4349 /* return bounding rectangle */
4351 lprc->left = infoPtr->rcBound.left;
4352 lprc->right = infoPtr->rcBound.right;
4353 lprc->top = infoPtr->rcBound.top;
4354 lprc->bottom = infoPtr->rcBound.bottom;
4362 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4364 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4365 TBUTTON_INFO *btnPtr;
4368 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4372 btnPtr = &infoPtr->buttons[nIndex];
4374 /* if hidden state has changed the invalidate entire window and recalc */
4375 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4376 btnPtr->fsState = LOWORD(lParam);
4377 TOOLBAR_CalcToolbar (hwnd);
4378 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4382 /* process state changing if current state doesn't match new state */
4383 if(btnPtr->fsState != LOWORD(lParam))
4385 btnPtr->fsState = LOWORD(lParam);
4386 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4395 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4398 TBUTTON_INFO *btnPtr;
4401 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4405 btnPtr = &infoPtr->buttons[nIndex];
4407 /* process style change if current style doesn't match new style */
4408 if(btnPtr->fsStyle != LOWORD(lParam))
4410 btnPtr->fsStyle = LOWORD(lParam);
4411 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4414 if (infoPtr->hwndToolTip) {
4415 FIXME("change tool tip!\n");
4423 inline static LRESULT
4424 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4426 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4428 if (infoPtr == NULL)
4430 infoPtr->hwndToolTip = (HWND)wParam;
4436 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4438 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4441 TRACE("%s hwnd=%p stub!\n",
4442 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4444 bTemp = infoPtr->bUnicode;
4445 infoPtr->bUnicode = (BOOL)wParam;
4452 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4456 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4457 comctl32_color.clrBtnHighlight :
4458 infoPtr->clrBtnHighlight;
4459 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4460 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4466 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4468 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4470 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4471 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4472 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4474 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4475 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4476 InvalidateRect(hwnd, 0, 0);
4482 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4484 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4485 INT iOldVersion = infoPtr->iVersion;
4487 infoPtr->iVersion = iVersion;
4489 if (infoPtr->iVersion >= 5)
4490 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0);
4496 /*********************************************************************/
4498 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4499 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4500 /* based on relay traces of the native control and IE 5.5 */
4502 /*********************************************************************/
4504 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4506 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4507 INT nOldHotItem = infoPtr->nHotItem;
4508 TBUTTON_INFO *btnPtr;
4510 NMTBHOTITEM nmhotitem;
4512 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4515 infoPtr->nHotItem = (INT)wParam;
4516 if (nOldHotItem != infoPtr->nHotItem) {
4517 nmhotitem.dwFlags = (DWORD)lParam;
4518 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4519 nmhotitem.idOld = (nOldHotItem >= 0) ?
4520 infoPtr->buttons[nOldHotItem].idCommand : 0;
4521 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4522 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4523 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4524 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4526 if ((INT)wParam >=0) {
4527 btnPtr = &infoPtr->buttons[(INT)wParam];
4528 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4529 InvalidateRect (hwnd, &btnPtr->rect,
4530 TOOLBAR_HasText(infoPtr, btnPtr));
4532 if (nOldHotItem>=0) {
4533 btnPtr = &infoPtr->buttons[nOldHotItem];
4534 btnPtr->bHot = FALSE;
4535 InvalidateRect (hwnd, &btnPtr->rect,
4536 TOOLBAR_HasText(infoPtr, btnPtr));
4539 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4540 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4542 if (nOldHotItem < 0)
4545 return (LRESULT)nOldHotItem;
4550 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4552 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4553 LPSIZE lpsize = (LPSIZE)lParam;
4559 * Testing shows the following:
4560 * wParam = 0 adjust cx value
4561 * = 1 set cy value to max size.
4562 * lParam pointer to SIZE structure
4565 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4566 wParam, lParam, lpsize->cx, lpsize->cy);
4570 if (lpsize->cx == -1) {
4571 /* **** this is wrong, native measures each button and sets it */
4572 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4574 else if(HIWORD(lpsize->cx)) {
4576 HWND hwndParent = GetParent(hwnd);
4578 InvalidateRect(hwnd, 0, 1);
4579 GetWindowRect(hwnd, &rc);
4580 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4581 TRACE("mapped to (%d,%d)-(%d,%d)\n",
4582 rc.left, rc.top, rc.right, rc.bottom);
4583 lpsize->cx = max(rc.right-rc.left,
4584 infoPtr->rcBound.right - infoPtr->rcBound.left);
4587 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4591 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4592 /* lpsize->cy = infoPtr->nHeight; */
4595 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4599 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4600 lpsize->cx, lpsize->cy);
4606 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4609 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4612 /* initialize info structure */
4613 infoPtr->nButtonHeight = 22;
4614 infoPtr->nButtonWidth = 24;
4615 infoPtr->nBitmapHeight = 15;
4616 infoPtr->nBitmapWidth = 16;
4618 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4620 infoPtr->nMaxTextRows = 1;
4621 infoPtr->cxMin = -1;
4622 infoPtr->cxMax = -1;
4623 infoPtr->nNumBitmaps = 0;
4624 infoPtr->nNumStrings = 0;
4626 infoPtr->bCaptured = FALSE;
4627 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4628 infoPtr->nButtonDown = -1;
4629 infoPtr->nOldHit = -1;
4630 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4631 infoPtr->hwndNotify = GetParent (hwnd);
4632 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4633 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4634 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4635 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4636 infoPtr->iVersion = 0;
4637 infoPtr->hwndSelf = hwnd;
4638 infoPtr->bDoRedraw = TRUE;
4639 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4640 infoPtr->clrBtnShadow = CLR_DEFAULT;
4641 infoPtr->szPadding.cx = 7;
4642 infoPtr->szPadding.cy = 6;
4643 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4645 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4646 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4648 if (dwStyle & TBSTYLE_TOOLTIPS) {
4649 /* Create tooltip control */
4650 infoPtr->hwndToolTip =
4651 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4652 CW_USEDEFAULT, CW_USEDEFAULT,
4653 CW_USEDEFAULT, CW_USEDEFAULT,
4656 /* Send NM_TOOLTIPSCREATED notification */
4657 if (infoPtr->hwndToolTip) {
4658 NMTOOLTIPSCREATED nmttc;
4660 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4662 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4663 NM_TOOLTIPSCREATED);
4667 TOOLBAR_CheckStyle (hwnd, dwStyle);
4669 TOOLBAR_CalcToolbar(hwnd);
4676 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4678 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4680 /* delete tooltip control */
4681 if (infoPtr->hwndToolTip)
4682 DestroyWindow (infoPtr->hwndToolTip);
4684 /* delete button data */
4685 if (infoPtr->buttons)
4686 COMCTL32_Free (infoPtr->buttons);
4688 /* delete strings */
4689 if (infoPtr->strings) {
4691 for (i = 0; i < infoPtr->nNumStrings; i++)
4692 if (infoPtr->strings[i])
4693 COMCTL32_Free (infoPtr->strings[i]);
4695 COMCTL32_Free (infoPtr->strings);
4698 /* destroy internal image list */
4699 if (infoPtr->himlInt)
4700 ImageList_Destroy (infoPtr->himlInt);
4702 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
4703 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
4704 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
4706 /* delete default font */
4708 DeleteObject (infoPtr->hDefaultFont);
4710 /* free toolbar info data */
4711 COMCTL32_Free (infoPtr);
4712 SetWindowLongA (hwnd, 0, 0);
4719 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4721 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4722 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4723 NMTBCUSTOMDRAW tbcd;
4727 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4728 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4729 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4730 tbcd.nmcd.hdc = (HDC)wParam;
4731 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4732 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4734 /* FIXME: in general the return flags *can* be or'ed together */
4735 switch (infoPtr->dwBaseCustDraw)
4737 case CDRF_DODEFAULT:
4739 case CDRF_SKIPDEFAULT:
4742 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4747 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4748 * to my parent for processing.
4750 if (infoPtr->bTransparent) {
4752 HDC hdc = (HDC)wParam;
4757 parent = GetParent(hwnd);
4758 MapWindowPoints(hwnd, parent, &pt, 1);
4759 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4760 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4761 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4764 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4766 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
4767 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
4768 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4769 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4770 tbcd.nmcd.hdc = (HDC)wParam;
4771 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4772 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4773 switch (infoPtr->dwBaseCustDraw)
4775 case CDRF_DODEFAULT:
4777 case CDRF_SKIPDEFAULT:
4780 FIXME("[%p] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4789 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4791 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4793 return (LRESULT)infoPtr->hFont;
4798 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4800 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4801 TBUTTON_INFO *btnPtr;
4805 pt.x = (INT)LOWORD(lParam);
4806 pt.y = (INT)HIWORD(lParam);
4807 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4810 btnPtr = &infoPtr->buttons[nHit];
4811 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4814 infoPtr->bCaptured = TRUE;
4815 infoPtr->nButtonDown = nHit;
4817 btnPtr->fsState |= TBSTATE_PRESSED;
4819 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4822 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4823 TOOLBAR_Customize (hwnd);
4830 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4832 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4833 TBUTTON_INFO *btnPtr;
4838 if (infoPtr->hwndToolTip)
4839 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4840 WM_LBUTTONDOWN, wParam, lParam);
4842 pt.x = (INT)LOWORD(lParam);
4843 pt.y = (INT)HIWORD(lParam);
4844 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4848 btnPtr = &infoPtr->buttons[nHit];
4849 infoPtr->nOldHit = nHit;
4851 CopyRect(&arrowRect, &btnPtr->rect);
4852 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4854 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4855 if ((btnPtr->fsState & TBSTATE_ENABLED) && (btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4856 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4857 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4861 * this time we must force a Redraw, so the btn is
4862 * painted down before CaptureChanged repaints it up
4864 RedrawWindow(hwnd,&btnPtr->rect,0,
4865 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4867 nmtb.iItem = btnPtr->idCommand;
4868 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4871 memset(&nmtb.rcButton, 0, sizeof(RECT));
4872 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4874 if (res != TBDDRET_TREATPRESSED)
4875 /* ??? guess (GA) */
4877 /* otherwise drop through and process as pushed */
4879 /* SetCapture (hwnd); */
4880 infoPtr->bCaptured = TRUE;
4881 infoPtr->nButtonDown = nHit;
4883 btnPtr->fsState |= TBSTATE_PRESSED;
4884 btnPtr->bHot = FALSE;
4886 if (btnPtr->fsState & TBSTATE_ENABLED)
4887 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
4891 /* native issues the TBN_BEGINDRAG here */
4892 nmtb.iItem = btnPtr->idCommand;
4893 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4894 nmtb.tbButton.idCommand = btnPtr->idCommand;
4895 nmtb.tbButton.fsState = btnPtr->fsState;
4896 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4897 nmtb.tbButton.dwData = btnPtr->dwData;
4898 nmtb.tbButton.iString = btnPtr->iString;
4899 nmtb.cchText = 0; /* !!! not correct */
4900 nmtb.pszText = 0; /* !!! not correct */
4901 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4909 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4911 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4912 TBUTTON_INFO *btnPtr;
4916 BOOL bSendMessage = TRUE;
4921 if (infoPtr->hwndToolTip)
4922 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4923 WM_LBUTTONUP, wParam, lParam);
4925 pt.x = (INT)LOWORD(lParam);
4926 pt.y = (INT)HIWORD(lParam);
4927 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4929 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4930 /* if the cursor is still inside of the toolbar */
4931 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4932 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4934 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4935 btnPtr->fsState &= ~TBSTATE_PRESSED;
4937 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4938 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4939 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4941 if (nOldIndex == nHit)
4942 bSendMessage = FALSE;
4943 if ((nOldIndex != nHit) &&
4945 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4946 btnPtr->fsState |= TBSTATE_CHECKED;
4949 if (btnPtr->fsState & TBSTATE_CHECKED)
4950 btnPtr->fsState &= ~TBSTATE_CHECKED;
4952 btnPtr->fsState |= TBSTATE_CHECKED;
4956 if (nOldIndex != -1)
4958 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4959 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4963 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4964 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4965 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4967 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
4969 infoPtr->nButtonDown = -1;
4971 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4972 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4973 NM_RELEASEDCAPTURE);
4975 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4978 nmtb.iItem = btnPtr->idCommand;
4979 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4980 nmtb.tbButton.idCommand = btnPtr->idCommand;
4981 nmtb.tbButton.fsState = btnPtr->fsState;
4982 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4983 nmtb.tbButton.dwData = btnPtr->dwData;
4984 nmtb.tbButton.iString = btnPtr->iString;
4985 nmtb.cchText = 0; /* !!! not correct */
4986 nmtb.pszText = 0; /* !!! not correct */
4987 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4990 if (btnPtr->fsState & TBSTATE_ENABLED)
4992 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4993 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
4995 /* !!! Undocumented - toolbar at 4.71 level and above sends
4996 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4997 * Only NM_RCLICK is documented.
4999 nmmouse.dwItemSpec = btnPtr->idCommand;
5000 nmmouse.dwItemData = btnPtr->dwData;
5001 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr, NM_CLICK);
5007 TOOLBAR_CaptureChanged(HWND hwnd)
5009 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5010 TBUTTON_INFO *btnPtr;
5012 infoPtr->bCaptured = FALSE;
5014 if (infoPtr->nButtonDown >= 0)
5016 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5017 btnPtr->fsState &= ~TBSTATE_PRESSED;
5019 infoPtr->nOldHit = -1;
5021 if (btnPtr->fsState & TBSTATE_ENABLED)
5022 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
5029 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
5031 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5032 TBUTTON_INFO *hotBtnPtr, *btnPtr;
5035 if (infoPtr->nOldHit < 0)
5038 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5040 /* Redraw the button if the last button we were over is the hot button and it
5042 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
5044 hotBtnPtr->bHot = FALSE;
5045 rc1 = hotBtnPtr->rect;
5046 InflateRect (&rc1, 1, 1);
5047 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
5051 /* If the last button we were over is depressed then make it not */
5052 /* depressed and redraw it */
5053 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5055 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5057 btnPtr->fsState &= ~TBSTATE_PRESSED;
5059 rc1 = hotBtnPtr->rect;
5060 InflateRect (&rc1, 1, 1);
5061 InvalidateRect (hwnd, &rc1, TRUE);
5064 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5065 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
5071 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
5073 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
5074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5077 TRACKMOUSEEVENT trackinfo;
5078 NMTBHOTITEM nmhotitem;
5080 /* fill in the TRACKMOUSEEVENT struct */
5081 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5082 trackinfo.dwFlags = TME_QUERY;
5083 trackinfo.hwndTrack = hwnd;
5084 trackinfo.dwHoverTime = HOVER_DEFAULT;
5086 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5087 _TrackMouseEvent(&trackinfo);
5089 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5090 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5091 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5093 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5094 /* and can properly deactivate the hot toolbar button */
5095 _TrackMouseEvent(&trackinfo);
5098 if (infoPtr->hwndToolTip)
5099 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5100 WM_MOUSEMOVE, wParam, lParam);
5102 pt.x = (INT)LOWORD(lParam);
5103 pt.y = (INT)HIWORD(lParam);
5105 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5107 if (infoPtr->nOldHit != nHit)
5109 /* Remove the effect of an old hot button if the button was enabled and was
5110 drawn with the hot button effect */
5111 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
5112 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
5114 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5115 oldBtnPtr->bHot = FALSE;
5118 /* It's not a separator or in nowhere. It's a hot button. */
5121 btnPtr = &infoPtr->buttons[nHit];
5123 infoPtr->nHotItem = nHit;
5125 /* only enabled buttons show hot effect */
5126 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
5128 btnPtr->bHot = TRUE;
5132 nmhotitem.dwFlags = HICF_MOUSE;
5134 nmhotitem.idOld = oldBtnPtr->idCommand;
5136 nmhotitem.dwFlags |= HICF_ENTERING;
5138 nmhotitem.idNew = btnPtr->idCommand;
5140 nmhotitem.dwFlags |= HICF_LEAVING;
5141 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5143 /* now invalidate the old and new buttons so they will be painted */
5145 InvalidateRect (hwnd, &oldBtnPtr->rect,
5146 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5147 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
5148 InvalidateRect(hwnd, &btnPtr->rect,
5149 TOOLBAR_HasText(infoPtr, btnPtr));
5151 if (infoPtr->bCaptured) {
5152 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5153 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5154 btnPtr->fsState &= ~TBSTATE_PRESSED;
5155 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5157 else if (nHit == infoPtr->nButtonDown) {
5158 btnPtr->fsState |= TBSTATE_PRESSED;
5159 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5162 infoPtr->nOldHit = nHit;
5168 inline static LRESULT
5169 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5171 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5172 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5174 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5178 inline static LRESULT
5179 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5181 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5182 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5184 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5189 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5191 TOOLBAR_INFO *infoPtr;
5192 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5195 /* allocate memory for info structure */
5196 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
5197 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5200 infoPtr->dwStructSize = sizeof(TBBUTTON);
5202 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5203 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5204 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5205 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5208 /* native control does:
5209 * Get a lot of colors and brushes
5211 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5212 * CreateFontIndirectA(adr1)
5213 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5214 * hdc = GetDC(toolbar)
5215 * GetSystemMetrics(0x48)
5216 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5217 * 0, 0, 0, 0, "MARLETT")
5218 * oldfnt = SelectObject(hdc, fnt2)
5219 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5220 * GetTextMetricsA(hdc, adr3)
5221 * SelectObject(hdc, oldfnt)
5222 * DeleteObject(fnt2)
5224 * InvalidateRect(toolbar, 0, 1)
5225 * SetWindowLongA(toolbar, 0, addr)
5226 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5229 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5230 * ie 2 0x4600094c 0x4600094c 0x4600894d
5231 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5232 * rebar 0x50008844 0x40008844 0x50008845
5233 * pager 0x50000844 0x40000844 0x50008845
5234 * IC35mgr 0x5400084e **nochange**
5235 * on entry to _NCCREATE 0x5400084e
5236 * rowlist 0x5400004e **nochange**
5237 * on entry to _NCCREATE 0x5400004e
5241 /* I think the code below is a bug, but it is the way that the native
5242 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5243 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5244 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5245 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5246 * Some how, the only cases of this seem to be MFC programs.
5248 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5249 * does not occur in the WM_STYLECHANGING routine.
5250 * (Guy Albertelli 9/2001)
5253 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5254 styleadd |= TBSTYLE_TRANSPARENT;
5255 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5256 styleadd |= CCS_TOP; /* default to top */
5257 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5260 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5265 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5267 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5271 if (dwStyle & WS_MINIMIZE)
5272 return 0; /* Nothing to do */
5274 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5276 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5279 if (!(dwStyle & CCS_NODIVIDER))
5281 GetWindowRect (hwnd, &rcWindow);
5282 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5283 if( dwStyle & WS_BORDER )
5284 OffsetRect (&rcWindow, 1, 1);
5285 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5288 ReleaseDC( hwnd, hdc );
5294 inline static LRESULT
5295 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5298 LPNMHDR lpnmh = (LPNMHDR)lParam;
5300 if (lpnmh->code == PGN_CALCSIZE) {
5301 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5303 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5304 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5305 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5309 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5310 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5316 if (lpnmh->code == PGN_SCROLL) {
5317 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5319 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5320 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5321 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5322 lppgs->iScroll, lppgs->iDir);
5327 TRACE("passing WM_NOTIFY!\n");
5329 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5330 if (infoPtr->bNtfUnicode)
5331 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5334 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5338 if (lpnmh->code == TTN_GETDISPINFOA) {
5339 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5341 FIXME("retrieving ASCII string\n");
5344 else if (lpnmh->code == TTN_GETDISPINFOW) {
5345 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5347 FIXME("retrieving UNICODE string\n");
5358 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5360 /* remove this routine when Toolbar is improved to pass infoPtr
5361 * around instead of hwnd.
5363 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5364 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5369 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5373 if (lParam == NF_REQUERY) {
5374 i = SendMessageA(GetParent(infoPtr->hwndSelf),
5375 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5376 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5377 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5381 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5384 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5389 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5391 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5395 /* fill ps.rcPaint with a default rect */
5396 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5398 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5400 TRACE("psrect=(%d,%d)-(%d,%d)\n",
5401 ps.rcPaint.left, ps.rcPaint.top,
5402 ps.rcPaint.right, ps.rcPaint.bottom);
5404 TOOLBAR_Refresh (hwnd, hdc, &ps);
5405 if (!wParam) EndPaint (hwnd, &ps);
5412 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5413 /*****************************************************
5416 * Handles the WM_SETREDRAW message.
5419 * According to testing V4.71 of COMCTL32 returns the
5420 * *previous* status of the redraw flag (either 0 or 1)
5421 * instead of the MSDN documented value of 0 if handled.
5422 * (For laughs see the "consistancy" with same function
5425 *****************************************************/
5427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5428 BOOL oldredraw = infoPtr->bDoRedraw;
5430 TRACE("set to %s\n",
5431 (wParam) ? "TRUE" : "FALSE");
5432 infoPtr->bDoRedraw = (BOOL) wParam;
5434 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5436 return (oldredraw) ? 1 : 0;
5441 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5444 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5453 /* Resize deadlock check */
5454 if (infoPtr->bAutoSize) {
5455 infoPtr->bAutoSize = FALSE;
5459 /* FIXME: optimize to only update size if the new size doesn't */
5460 /* match the current size */
5462 flags = (INT) wParam;
5464 /* FIXME for flags =
5465 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5468 TRACE("sizing toolbar!\n");
5470 if (flags == SIZE_RESTORED) {
5471 /* width and height don't apply */
5472 parent = GetParent (hwnd);
5473 GetClientRect(parent, &parent_rect);
5474 x = parent_rect.left;
5475 y = parent_rect.top;
5477 if (dwStyle & CCS_NORESIZE) {
5478 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5481 * this sets the working width of the toolbar, and
5482 * Calc Toolbar will not adjust it, only the height
5484 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5485 cy = infoPtr->nHeight;
5486 cx = infoPtr->nWidth;
5487 TOOLBAR_CalcToolbar (hwnd);
5488 infoPtr->nWidth = cx;
5489 infoPtr->nHeight = cy;
5492 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5493 TOOLBAR_CalcToolbar (hwnd);
5494 cy = infoPtr->nHeight;
5495 cx = infoPtr->nWidth;
5497 if (dwStyle & CCS_NOMOVEY) {
5498 GetWindowRect(hwnd, &window_rect);
5499 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5500 y = window_rect.top;
5504 if (dwStyle & CCS_NOPARENTALIGN) {
5505 uPosFlags |= SWP_NOMOVE;
5506 cy = infoPtr->nHeight;
5507 cx = infoPtr->nWidth;
5510 if (!(dwStyle & CCS_NODIVIDER))
5511 cy += GetSystemMetrics(SM_CYEDGE);
5513 if (dwStyle & WS_BORDER)
5516 cy += GetSystemMetrics(SM_CYEDGE);
5517 cx += GetSystemMetrics(SM_CYEDGE);
5520 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
5521 cx, cy, uPosFlags | SWP_NOZORDER);
5528 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5530 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5532 if (nType == GWL_STYLE) {
5533 if (lpStyle->styleNew & TBSTYLE_LIST) {
5534 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5537 infoPtr->dwDTFlags = DT_CENTER;
5539 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5540 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5541 (TBSTYLE_FLAT | TBSTYLE_LIST));
5542 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5545 TOOLBAR_AutoSize (hwnd);
5547 InvalidateRect(hwnd, NULL, FALSE);
5554 TOOLBAR_SysColorChange (HWND hwnd)
5556 COMCTL32_RefreshSysColors();
5563 static LRESULT WINAPI
5564 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5566 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
5567 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5569 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5570 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5575 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5577 case TB_ADDBUTTONSA:
5578 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5580 case TB_ADDBUTTONSW:
5581 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5584 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5587 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5590 return TOOLBAR_AutoSize (hwnd);
5592 case TB_BUTTONCOUNT:
5593 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5595 case TB_BUTTONSTRUCTSIZE:
5596 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5598 case TB_CHANGEBITMAP:
5599 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5601 case TB_CHECKBUTTON:
5602 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5604 case TB_COMMANDTOINDEX:
5605 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5608 return TOOLBAR_Customize (hwnd);
5610 case TB_DELETEBUTTON:
5611 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5613 case TB_ENABLEBUTTON:
5614 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5616 case TB_GETANCHORHIGHLIGHT:
5617 return TOOLBAR_GetAnchorHighlight (hwnd);
5620 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5622 case TB_GETBITMAPFLAGS:
5623 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5626 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5628 case TB_GETBUTTONINFOA:
5629 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5631 case TB_GETBUTTONINFOW:
5632 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5634 case TB_GETBUTTONSIZE:
5635 return TOOLBAR_GetButtonSize (hwnd);
5637 case TB_GETBUTTONTEXTA:
5638 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5640 case TB_GETBUTTONTEXTW:
5641 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5643 case TB_GETDISABLEDIMAGELIST:
5644 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5646 case TB_GETEXTENDEDSTYLE:
5647 return TOOLBAR_GetExtendedStyle (hwnd);
5649 case TB_GETHOTIMAGELIST:
5650 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5653 return TOOLBAR_GetHotItem (hwnd);
5655 case TB_GETIMAGELIST:
5656 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam);
5658 /* case TB_GETINSERTMARK: */ /* 4.71 */
5659 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5661 case TB_GETITEMRECT:
5662 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5665 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5667 /* case TB_GETOBJECT: */ /* 4.71 */
5670 return TOOLBAR_GetPadding (hwnd);
5673 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5676 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5679 return TOOLBAR_GetState (hwnd, wParam, lParam);
5682 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5684 case TB_GETTEXTROWS:
5685 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5687 case TB_GETTOOLTIPS:
5688 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5690 case TB_GETUNICODEFORMAT:
5691 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5694 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5697 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5699 case TB_INDETERMINATE:
5700 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5702 case TB_INSERTBUTTONA:
5703 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5705 case TB_INSERTBUTTONW:
5706 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5708 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5710 case TB_ISBUTTONCHECKED:
5711 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5713 case TB_ISBUTTONENABLED:
5714 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5716 case TB_ISBUTTONHIDDEN:
5717 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5719 case TB_ISBUTTONHIGHLIGHTED:
5720 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5722 case TB_ISBUTTONINDETERMINATE:
5723 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5725 case TB_ISBUTTONPRESSED:
5726 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5728 case TB_LOADIMAGES: /* 4.70 */
5729 FIXME("missing standard imagelists\n");
5732 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5733 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5734 /* case TB_MARKBUTTON: */ /* 4.71 */
5735 /* case TB_MOVEBUTTON: */ /* 4.71 */
5737 case TB_PRESSBUTTON:
5738 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5740 case TB_REPLACEBITMAP:
5741 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
5743 case TB_SAVERESTOREA:
5744 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5746 case TB_SAVERESTOREW:
5747 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5749 case TB_SETANCHORHIGHLIGHT:
5750 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5752 case TB_SETBITMAPSIZE:
5753 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5755 case TB_SETBUTTONINFOA:
5756 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5758 case TB_SETBUTTONINFOW:
5759 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5761 case TB_SETBUTTONSIZE:
5762 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5764 case TB_SETBUTTONWIDTH:
5765 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5768 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5770 case TB_SETDISABLEDIMAGELIST:
5771 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5773 case TB_SETDRAWTEXTFLAGS:
5774 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5776 case TB_SETEXTENDEDSTYLE:
5777 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5779 case TB_SETHOTIMAGELIST:
5780 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5783 return TOOLBAR_SetHotItem (hwnd, wParam);
5785 case TB_SETIMAGELIST:
5786 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5789 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5791 /* case TB_SETINSERTMARK: */ /* 4.71 */
5793 case TB_SETINSERTMARKCOLOR:
5794 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5796 case TB_SETMAXTEXTROWS:
5797 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5800 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
5803 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5806 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5809 return TOOLBAR_SetState (hwnd, wParam, lParam);
5812 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5814 case TB_SETTOOLTIPS:
5815 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5817 case TB_SETUNICODEFORMAT:
5818 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5821 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
5824 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
5827 /* Common Control Messages */
5829 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
5830 case CCM_GETCOLORSCHEME:
5831 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5833 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
5834 case CCM_SETCOLORSCHEME:
5835 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5837 case CCM_GETVERSION:
5838 return TOOLBAR_GetVersion (hwnd);
5840 case CCM_SETVERSION:
5841 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5847 return TOOLBAR_Create (hwnd, wParam, lParam);
5850 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5853 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5856 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5858 /* case WM_KEYDOWN: */
5859 /* case WM_KILLFOCUS: */
5861 case WM_LBUTTONDBLCLK:
5862 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5864 case WM_LBUTTONDOWN:
5865 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5868 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5871 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5874 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5876 case WM_CAPTURECHANGED:
5877 return TOOLBAR_CaptureChanged(hwnd);
5880 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5883 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5886 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5889 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5892 return TOOLBAR_Notify (hwnd, wParam, lParam);
5894 case WM_NOTIFYFORMAT:
5895 TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
5898 return TOOLBAR_Paint (hwnd, wParam);
5901 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5904 return TOOLBAR_Size (hwnd, wParam, lParam);
5906 case WM_STYLECHANGED:
5907 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5909 case WM_SYSCOLORCHANGE:
5910 return TOOLBAR_SysColorChange (hwnd);
5912 /* case WM_WININICHANGE: */
5917 case WM_MEASUREITEM:
5920 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5922 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5924 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5927 /* We see this in Outlook Express 5.x and just does DefWindowProc */
5928 case PGM_FORWARDMOUSE:
5929 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5932 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
5933 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5934 uMsg, wParam, lParam);
5935 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5942 TOOLBAR_Register (void)
5946 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5947 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5948 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5949 wndClass.cbClsExtra = 0;
5950 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5951 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5952 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5953 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5955 RegisterClassA (&wndClass);
5960 TOOLBAR_Unregister (void)
5962 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
5965 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
5970 /* Check if the entry already exists */
5971 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
5973 /* If this is a new entry we must create it and insert into the array */
5978 c = (PIMLENTRY) COMCTL32_Alloc(sizeof(IMLENTRY));
5981 pnies = COMCTL32_Alloc((*cies + 1) * sizeof(PIMLENTRY));
5982 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
5986 COMCTL32_Free(*pies);
5997 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6001 for (i = 0; i < *cies; i++)
6002 COMCTL32_Free((*pies)[i]);
6004 COMCTL32_Free(*pies);
6011 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id)
6019 for (i = 0; i < cies; i++)
6021 if (pies[i]->id == id)
6033 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id)
6035 HIMAGELIST himlDef = 0;
6036 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6039 himlDef = pie->himl;
6045 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6047 if (infoPtr->bUnicode)
6048 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW);
6055 nmtba.iItem = nmtb->iItem;
6056 nmtba.pszText = Buffer;
6057 nmtba.cchText = 256;
6058 ZeroMemory(nmtba.pszText, nmtba.cchText);
6060 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA))
6062 int ccht = strlen(nmtba.pszText);
6064 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1,
6065 nmtb->pszText, nmtb->cchText);
6067 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON));
6076 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr,
6077 int iItem, PCUSTOMBUTTON btnInfo)
6082 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6084 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE);