Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / dlls / comctl32 / toolbar.c
blob5f1d8b7ae4f5e46a71cd2657b70ee01f786d58d4
1 /*
2 * Toolbar control
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)
31 * TODO:
32 * - A little bug in TOOLBAR_DrawMasked()
33 * - Button wrapping (under construction).
34 * - Messages.
35 * - Notifications (under construction).
36 * - Fix TB_SETROWS.
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:
44 * - Add flat look.
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.
51 * Testing:
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
62 #include <string.h>
64 #include "winbase.h"
65 #include "windef.h"
66 #include "wingdi.h"
67 #include "winuser.h"
68 #include "wine/unicode.h"
69 #include "commctrl.h"
70 #include "imagelist.h"
71 #include "comctl32.h"
72 #include "wine/debug.h"
74 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
76 typedef struct
78 INT iBitmap;
79 INT idCommand;
80 BYTE fsState;
81 BYTE fsStyle;
82 DWORD dwData;
83 INT iString;
85 BOOL bHot;
86 INT nRow;
87 RECT rect;
88 } TBUTTON_INFO;
90 typedef struct
92 UINT nButtons;
93 HINSTANCE hInst;
94 UINT nID;
95 } TBITMAP_INFO;
97 typedef struct
99 DWORD dwStructSize; /* size of TBBUTTON struct */
100 INT nHeight; /* height of the toolbar */
101 INT nWidth; /* width of the toolbar */
102 INT nButtonHeight;
103 INT nButtonWidth;
104 INT nBitmapHeight;
105 INT nBitmapWidth;
106 INT nIndent;
107 INT nRows; /* number of button rows */
108 INT nMaxTextRows; /* maximum number of text rows */
109 INT cxMin; /* minimum button width */
110 INT cxMax; /* maximum button width */
111 INT nNumButtons; /* number of buttons */
112 INT nNumBitmaps; /* number of bitmaps */
113 INT nNumStrings; /* number of strings */
114 INT nNumBitmapInfos;
115 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
116 BOOL bCaptured; /* mouse captured? */
117 INT nButtonDown;
118 INT nOldHit;
119 INT nHotItem; /* index of the "hot" item */
120 DWORD dwBaseCustDraw; /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
121 DWORD dwItemCustDraw; /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
122 DWORD dwItemCDFlag; /* TBCDRF_ flags from last ITEMPREPAINT */
123 SIZE szPadding; /* padding values around button */
124 HFONT hDefaultFont;
125 HFONT hFont; /* text font */
126 HIMAGELIST himlInt; /* image list created internally */
127 HIMAGELIST himlDef; /* default image list */
128 HIMAGELIST himlHot; /* hot image list */
129 HIMAGELIST himlDis; /* disabled image list */
130 HWND hwndToolTip; /* handle to tool tip control */
131 HWND hwndNotify; /* handle to the window that gets notifications */
132 HWND hwndSelf; /* my own handle */
133 BOOL bTransparent; /* background transparency flag */
134 BOOL bBtnTranspnt; /* button transparency flag */
135 BOOL bAutoSize; /* auto size deadlock indicator */
136 BOOL bAnchor; /* anchor highlight enabled */
137 BOOL bNtfUnicode; /* TRUE if NOTIFYs use {W} */
138 BOOL bDoRedraw; /* Redraw status */
139 DWORD dwExStyle; /* extended toolbar style */
140 DWORD dwDTFlags; /* DrawText flags */
142 COLORREF clrInsertMark; /* insert mark color */
143 COLORREF clrBtnHighlight; /* color for Flat Separator */
144 COLORREF clrBtnShadow; /* color for Flag Separator */
145 RECT rcBound; /* bounding rectangle */
146 INT iVersion;
148 TBUTTON_INFO *buttons; /* pointer to button array */
149 LPWSTR *strings; /* pointer to string array */
150 TBITMAP_INFO *bitmaps;
151 } TOOLBAR_INFO, *PTOOLBAR_INFO;
154 /* used by customization dialog */
155 typedef struct
157 PTOOLBAR_INFO tbInfo;
158 HWND tbHwnd;
159 } CUSTDLG_INFO, *PCUSTDLG_INFO;
161 typedef struct
163 TBBUTTON btn;
164 BOOL bVirtual;
165 BOOL bRemovable;
166 CHAR text[64];
167 } CUSTOMBUTTON, *PCUSTOMBUTTON;
170 #define SEPARATOR_WIDTH 8
171 #define TOP_BORDER 2
172 #define BOTTOM_BORDER 2
173 #define DDARROW_WIDTH 11
175 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
176 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
177 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
179 /* Used to find undocumented extended styles */
180 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
181 TBSTYLE_EX_UNDOC1 | \
182 TBSTYLE_EX_MIXEDBUTTONS | \
183 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
185 static LRESULT
186 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
189 static LPWSTR
190 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
192 LPWSTR lpText = NULL;
194 /* FIXME: iString == -1 is undocumented */
195 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
196 lpText = (LPWSTR)btnPtr->iString;
197 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
198 lpText = infoPtr->strings[btnPtr->iString];
200 return lpText;
203 static void
204 TOOLBAR_DumpButton(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *bP, INT btn_num, BOOL internal)
206 if (TRACE_ON(toolbar)){
207 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n",
208 btn_num, bP->idCommand,
209 bP->iBitmap, bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
210 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
211 if (internal)
212 TRACE("button %d id %d, hot=%s, row=%d, rect=(%d,%d)-(%d,%d)\n",
213 btn_num, bP->idCommand,
214 (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
215 bP->rect.left, bP->rect.top,
216 bP->rect.right, bP->rect.bottom);
221 static void
222 TOOLBAR_DumpToolbar(TOOLBAR_INFO *iP, INT line)
224 if (TRACE_ON(toolbar)) {
225 INT i;
226 DWORD dwStyle;
228 dwStyle = GetWindowLongA (iP->hwndSelf, GWL_STYLE);
229 TRACE("toolbar %08x at line %d, exStyle=%08lx, buttons=%d, bitmaps=%d, strings=%d, style=%08lx\n",
230 iP->hwndSelf, line,
231 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
232 iP->nNumStrings, dwStyle);
233 TRACE("toolbar %08x at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
234 iP->hwndSelf, line,
235 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
236 (iP->bDoRedraw) ? "TRUE" : "FALSE");
237 for(i=0; i<iP->nNumButtons; i++) {
238 TOOLBAR_DumpButton(iP, &iP->buttons[i], i, TRUE);
244 /***********************************************************************
245 * TOOLBAR_CheckStyle
247 * This function validates that the styles set are implemented and
248 * issues FIXME's warning of possible problems. In a perfect world this
249 * function should be null.
251 static void
252 TOOLBAR_CheckStyle (HWND hwnd, DWORD dwStyle)
254 if (dwStyle & TBSTYLE_ALTDRAG)
255 FIXME("[%04x] TBSTYLE_ALTDRAG not implemented\n", hwnd);
256 if (dwStyle & TBSTYLE_REGISTERDROP)
257 FIXME("[%04x] TBSTYLE_REGISTERDROP not implemented\n", hwnd);
261 static INT
262 TOOLBAR_SendNotify (NMHDR *nmhdr, TOOLBAR_INFO *infoPtr, UINT code)
264 if(!IsWindow(infoPtr->hwndSelf))
265 return 0; /* we have just been destroyed */
267 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
268 nmhdr->hwndFrom = infoPtr->hwndSelf;
269 nmhdr->code = code;
271 TRACE("to window %04x, code=%08x, %s\n", infoPtr->hwndNotify, code,
272 (infoPtr->bNtfUnicode) ? "via Unicode" : "via ANSI");
274 if (infoPtr->bNtfUnicode)
275 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
276 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
277 else
278 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
279 (WPARAM) nmhdr->idFrom, (LPARAM)nmhdr);
282 /***********************************************************************
283 * TOOLBAR_GetBitmapIndex
285 * This function returns the bitmap index associated with a button.
286 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
287 * is issued to retrieve the index.
289 static INT
290 TOOLBAR_GetBitmapIndex(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
292 INT ret = btnPtr->iBitmap;
294 if (ret == I_IMAGECALLBACK) {
295 /* issue TBN_GETDISPINFO */
296 NMTBDISPINFOA nmgd;
298 nmgd.idCommand = btnPtr->idCommand;
299 nmgd.lParam = btnPtr->dwData;
300 nmgd.dwMask = TBNF_IMAGE;
301 TOOLBAR_SendNotify ((NMHDR *) &nmgd, infoPtr,
302 (infoPtr->bNtfUnicode) ? TBN_GETDISPINFOW :
303 TBN_GETDISPINFOA);
304 if (nmgd.dwMask & TBNF_DI_SETITEM) {
305 btnPtr->iBitmap = nmgd.iImage;
307 ret = nmgd.iImage;
308 TRACE("TBN_GETDISPINFOA returned bitmap id %d, mask=%08lx, nNumBitmaps=%d\n",
309 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
311 return ret;
315 static BOOL
316 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
318 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) ||
319 (index == I_IMAGECALLBACK))
320 return TRUE;
321 else
322 return FALSE;
326 /***********************************************************************
327 * TOOLBAR_DrawImageList
329 * This function validates the bitmap index (including I_IMAGECALLBACK
330 * functionality). It then draws the image via the ImageList_Draw
331 * function. It returns TRUE if the image was drawn, FALSE otherwise.
333 static BOOL
334 TOOLBAR_DrawImageList (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl,
335 HDC hdc, UINT left, UINT top, UINT draw_flags)
337 INT index;
339 if (!himl) return FALSE;
341 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
342 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
343 ERR("index %d is not valid, max %d\n",
344 btnPtr->iBitmap, infoPtr->nNumBitmaps);
345 return FALSE;
348 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
349 if ((index == I_IMAGECALLBACK) ||
350 (index == I_IMAGENONE)) return FALSE;
351 ERR("TBN_GETDISPINFO returned invalid index %d\n",
352 index);
353 return FALSE;
355 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, flags=%08x\n",
356 index, himl, left, top, draw_flags);
358 ImageList_Draw (himl, index, hdc, left, top, draw_flags);
359 return TRUE;
363 /***********************************************************************
364 * TOOLBAR_TestImageExist
366 * This function is similar to TOOLBAR_DrawImageList, except it does not
367 * draw the image. The I_IMAGECALLBACK functionality is implemented.
369 static BOOL
370 TOOLBAR_TestImageExist (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HIMAGELIST himl)
372 INT index;
374 if (!himl) return FALSE;
376 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
377 if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
378 ERR("index %d is not valid, max %d\n",
379 btnPtr->iBitmap, infoPtr->nNumBitmaps);
380 return FALSE;
383 if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
384 if ((index == I_IMAGECALLBACK) ||
385 (index == I_IMAGENONE)) return FALSE;
386 ERR("TBN_GETDISPINFO returned invalid index %d\n",
387 index);
388 return FALSE;
390 return TRUE;
394 static void
395 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
397 RECT myrect;
398 COLORREF oldcolor, newcolor;
400 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
401 myrect.right = myrect.left + 1;
402 myrect.top = lpRect->top + 2;
403 myrect.bottom = lpRect->bottom - 2;
405 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
406 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
407 oldcolor = SetBkColor (hdc, newcolor);
408 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
410 myrect.left = myrect.right;
411 myrect.right = myrect.left + 1;
413 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
414 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
415 SetBkColor (hdc, newcolor);
416 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
418 SetBkColor (hdc, oldcolor);
422 /***********************************************************************
423 * TOOLBAR_DrawDDFlatSeparator
425 * This function draws the separator that was flaged as TBSTYLE_DROPDOWN.
426 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
427 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
428 * are horizontal as opposed to the vertical separators for not dropdown
429 * type.
431 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
433 static void
434 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
436 RECT myrect;
437 COLORREF oldcolor, newcolor;
439 myrect.left = lpRect->left;
440 myrect.right = lpRect->right;
441 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
442 myrect.bottom = myrect.top + 1;
444 InflateRect (&myrect, -2, 0);
446 TRACE("rect=(%d,%d)-(%d,%d)\n",
447 myrect.left, myrect.top, myrect.right, myrect.bottom);
449 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
450 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
451 oldcolor = SetBkColor (hdc, newcolor);
452 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
454 myrect.top = myrect.bottom;
455 myrect.bottom = myrect.top + 1;
457 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
458 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
459 SetBkColor (hdc, newcolor);
460 ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
462 SetBkColor (hdc, oldcolor);
466 static void
467 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
469 INT x, y;
470 HPEN hPen, hOldPen;
472 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
473 hOldPen = SelectObject ( hdc, hPen );
474 x = left + 2;
475 y = top + 8;
476 MoveToEx (hdc, x, y, NULL);
477 LineTo (hdc, x+5, y++); x++;
478 MoveToEx (hdc, x, y, NULL);
479 LineTo (hdc, x+3, y++); x++;
480 MoveToEx (hdc, x, y, NULL);
481 LineTo (hdc, x+1, y++);
482 SelectObject( hdc, hOldPen );
483 DeleteObject( hPen );
487 * Draw the text string for this button.
488 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
489 * is non-zero, so we can simply check himlDef to see if we have
490 * an image list
492 static void
493 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
494 HDC hdc, INT nState, DWORD dwStyle,
495 RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
497 HFONT hOldFont = 0;
498 COLORREF clrOld = 0;
500 /* draw text */
501 if (lpText) {
502 TRACE("string rect=(%d,%d)-(%d,%d)\n",
503 rcText->left, rcText->top, rcText->right, rcText->bottom);
505 hOldFont = SelectObject (hdc, infoPtr->hFont);
506 if (!(nState & TBSTATE_ENABLED)) {
507 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
508 OffsetRect (rcText, 1, 1);
509 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
510 SetTextColor (hdc, comctl32_color.clr3dShadow);
511 OffsetRect (rcText, -1, -1);
513 else if (nState & TBSTATE_INDETERMINATE) {
514 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
516 else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
517 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
519 else {
520 clrOld = SetTextColor (hdc, tbcd->clrText);
523 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
524 SetTextColor (hdc, clrOld);
525 SelectObject (hdc, hOldFont);
530 static void
531 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
533 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
534 INT cx = lpRect->right - lpRect->left;
535 INT cy = lpRect->bottom - lpRect->top;
536 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
537 SelectObject (hdc, hbr);
541 static void
542 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
543 HDC hdc, INT x, INT y)
545 /* FIXME: this function is a hack since it uses image list
546 internals directly */
548 HIMAGELIST himl = infoPtr->himlDef;
549 HBITMAP hbmMask;
550 HDC hdcImageList;
551 HDC hdcMask;
553 if (!himl)
554 return;
556 /* create new dc's */
557 hdcImageList = CreateCompatibleDC (0);
558 hdcMask = CreateCompatibleDC (0);
560 /* create new bitmap */
561 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
562 SelectObject (hdcMask, hbmMask);
564 /* copy the mask bitmap */
565 SelectObject (hdcImageList, himl->hbmMask);
566 SetBkColor (hdcImageList, RGB(255, 255, 255));
567 SetTextColor (hdcImageList, RGB(0, 0, 0));
568 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
569 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
571 /* draw the new mask */
572 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
573 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
574 hdcMask, 0, 0, 0xB8074A);
576 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
577 BitBlt (hdc, x, y, himl->cx, himl->cy,
578 hdcMask, 0, 0, 0xB8074A);
580 DeleteObject (hbmMask);
581 DeleteDC (hdcMask);
582 DeleteDC (hdcImageList);
586 static UINT
587 TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
589 UINT retstate = 0;
591 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
592 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
593 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
594 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
595 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
596 retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
597 /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
598 /* don't test TBSTATE_HIDDEN */
599 return retstate;
603 static void
604 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
607 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
608 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
609 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
610 RECT rc, rcArrow, rcBitmap, rcText, rcFill;
611 LPWSTR lpText = NULL;
612 NMTBCUSTOMDRAW tbcd;
613 DWORD ntfret;
614 INT offset;
616 if (btnPtr->fsState & TBSTATE_HIDDEN)
617 return;
619 rc = btnPtr->rect;
620 CopyRect (&rcFill, &rc);
621 CopyRect (&rcArrow, &rc);
622 CopyRect(&rcBitmap, &rc);
623 CopyRect(&rcText, &rc);
625 /* get a pointer to the text */
626 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
628 if (hasDropDownArrow)
630 if (dwStyle & TBSTYLE_FLAT)
631 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
632 else
633 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
634 rcArrow.left = rc.right;
637 /* Center the bitmap horizontally and vertically */
638 if (dwStyle & TBSTYLE_LIST)
639 rcBitmap.left += 3;
640 else
641 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
643 if(lpText)
644 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
645 else
646 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
648 TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
649 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
650 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
651 TRACE ("iString: %x\n", btnPtr->iString);
652 TRACE ("Stringtext: %s\n", debugstr_w(lpText));
654 /* draw text */
655 if (lpText) {
657 InflateRect (&rcText, -3, -3);
659 if (infoPtr->himlDef &&
660 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
661 /* The following test looked like this before
662 * I changed it. IE4 "Links" toolbar would not
663 * draw correctly with the original code. - GA 8/01
664 * ((dwStyle & TBSTYLE_LIST) &&
665 * ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
666 * (btnPtr->iBitmap != I_IMAGENONE))
668 if (dwStyle & TBSTYLE_LIST) {
669 /* LIST style w/ ICON offset is by matching native. */
670 /* Matches IE4 "Links" bar. - GA 8/01 */
671 rcText.left += (infoPtr->nBitmapWidth + 2);
673 else {
674 rcText.top += infoPtr->nBitmapHeight + 1;
677 else {
678 if (dwStyle & TBSTYLE_LIST) {
679 /* LIST style w/o ICON offset is by matching native. */
680 /* Matches IE4 "menu" bar. - GA 8/01 */
681 rcText.left += 4;
685 if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
686 OffsetRect (&rcText, 1, 1);
689 /* Initialize fields in all cases, because we use these later */
690 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
691 tbcd.clrText = comctl32_color.clrBtnText;
692 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
693 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
694 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
695 tbcd.clrMark = comctl32_color.clrHighlight;
696 tbcd.clrHighlightHotTrack = 0;
697 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
698 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
699 /* MSDN says that this is the text rectangle. */
700 /* But (why always a but) tracing of v5.7 of native shows */
701 /* that this is really a *relative* rectangle based on the */
702 /* the nmcd.rc. Also the left and top are always 0 ignoring*/
703 /* any bitmap that might be present. */
704 tbcd.rcText.left = 0;
705 tbcd.rcText.top = 0;
706 tbcd.rcText.right = rcText.right - rc.left;
707 tbcd.rcText.bottom = rcText.bottom - rc.top;
709 /* FIXME: what should these be set to ????? */
710 tbcd.hbrMonoDither = 0;
711 tbcd.hbrLines = 0;
712 tbcd.hpenLines = 0;
714 /* Issue Item Prepaint notify */
715 infoPtr->dwItemCustDraw = 0;
716 infoPtr->dwItemCDFlag = 0;
717 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
719 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
720 tbcd.nmcd.hdc = hdc;
721 tbcd.nmcd.rc = rc;
722 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
723 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
724 tbcd.nmcd.lItemlParam = btnPtr->dwData;
725 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
726 infoPtr->dwItemCustDraw = ntfret & 0xffff;
727 infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
728 if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
729 return;
730 /* save the only part of the rect that the user can change */
731 rcText.right = tbcd.rcText.right + rc.left;
732 rcText.bottom = tbcd.rcText.bottom + rc.top;
735 if (!infoPtr->bBtnTranspnt)
736 FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
738 /* separator */
739 if (btnPtr->fsStyle & TBSTYLE_SEP) {
740 /* with the FLAT style, iBitmap is the width and has already */
741 /* been taken into consideration in calculating the width */
742 /* so now we need to draw the vertical separator */
743 /* empirical tests show that iBitmap can/will be non-zero */
744 /* when drawing the vertical bar... */
745 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
746 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
747 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
748 else
749 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
751 else if (btnPtr->fsStyle != TBSTYLE_SEP) {
752 FIXME("Draw some kind of separator: fsStyle=%x\n",
753 btnPtr->fsStyle);
755 goto FINALNOTIFY;
758 /* disabled */
759 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
760 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
762 DrawEdge (hdc, &rc, EDGE_RAISED,
763 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
764 if (hasDropDownArrow)
765 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
766 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
769 if (hasDropDownArrow)
771 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
772 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
775 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,
776 hdc, rcBitmap.left, rcBitmap.top,
777 ILD_NORMAL))
778 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
780 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
781 goto FINALNOTIFY;
784 /* pressed TBSTYLE_BUTTON */
785 if (btnPtr->fsState & TBSTATE_PRESSED) {
786 offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
787 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
789 if (dwStyle & TBSTYLE_FLAT)
791 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
792 if (hasDropDownArrow)
793 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
795 else
797 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
798 if (hasDropDownArrow)
799 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
803 if (hasDropDownArrow)
804 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
806 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
807 hdc, rcBitmap.left+offset, rcBitmap.top+offset,
808 ILD_NORMAL);
810 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
811 goto FINALNOTIFY;
814 /* checked TBSTYLE_CHECK */
815 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
816 (btnPtr->fsState & TBSTATE_CHECKED)) {
817 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
819 if (dwStyle & TBSTYLE_FLAT)
820 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
821 BF_RECT | BF_ADJUST);
822 else
823 DrawEdge (hdc, &rc, EDGE_SUNKEN,
824 BF_RECT | BF_MIDDLE | BF_ADJUST);
827 TOOLBAR_DrawPattern (hdc, &rc);
829 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
830 hdc, rcBitmap.left+1, rcBitmap.top+1,
831 ILD_NORMAL);
833 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
834 goto FINALNOTIFY;
837 /* indeterminate */
838 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
839 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
840 DrawEdge (hdc, &rc, EDGE_RAISED,
841 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
843 TOOLBAR_DrawPattern (hdc, &rc);
844 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
845 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
846 goto FINALNOTIFY;
849 /* normal state */
850 if (dwStyle & TBSTYLE_FLAT)
852 if (btnPtr->bHot)
854 if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
856 COLORREF oldclr;
858 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
859 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
860 if (hasDropDownArrow)
861 ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
862 SetBkColor(hdc, oldclr);
864 else
866 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
868 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
869 if (hasDropDownArrow)
870 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
874 #if 1
875 else /* The following code needs to be removed after
876 * "hot item" support has been implemented for the
877 * case where it is being de-selected.
880 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
881 if (hasDropDownArrow)
882 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
884 #endif
886 if (hasDropDownArrow)
887 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
889 if (btnPtr->bHot) {
890 /* if hot, attempt to draw with himlHot, if fails, use himlDef */
891 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr,
892 infoPtr->himlHot,
893 hdc, rcBitmap.left,
894 rcBitmap.top, ILD_NORMAL))
895 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
896 hdc, rcBitmap.left, rcBitmap.top,
897 ILD_NORMAL);
899 else
900 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
901 hdc, rcBitmap.left, rcBitmap.top,
902 ILD_NORMAL);
904 else
906 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
907 DrawEdge (hdc, &rc, EDGE_RAISED,
908 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
910 if (hasDropDownArrow)
912 if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
913 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
914 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
915 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
918 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
919 hdc, rcBitmap.left, rcBitmap.top,
920 ILD_NORMAL);}
923 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
925 FINALNOTIFY:
926 if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
928 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
929 tbcd.nmcd.hdc = hdc;
930 tbcd.nmcd.rc = rc;
931 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
932 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
933 tbcd.nmcd.lItemlParam = btnPtr->dwData;
934 tbcd.rcText = rcText;
935 tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
936 tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
937 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
943 static void
944 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
946 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
947 TBUTTON_INFO *btnPtr;
948 INT i, oldBKmode = 0;
949 RECT rcTemp;
950 NMTBCUSTOMDRAW tbcd;
951 DWORD ntfret;
953 /* if imagelist belongs to the app, it can be changed
954 by the app after setting it */
955 if (infoPtr->himlDef != infoPtr->himlInt)
956 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
958 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
960 /* Send initial notify */
961 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
962 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
963 tbcd.nmcd.hdc = hdc;
964 tbcd.nmcd.rc = ps->rcPaint;
965 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
966 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
968 if (infoPtr->bBtnTranspnt)
969 oldBKmode = SetBkMode (hdc, TRANSPARENT);
971 /* redraw necessary buttons */
972 btnPtr = infoPtr->buttons;
973 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
975 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
976 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
979 if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
980 SetBkMode (hdc, oldBKmode);
982 if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
984 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
985 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
986 tbcd.nmcd.hdc = hdc;
987 tbcd.nmcd.rc = ps->rcPaint;
988 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
992 /***********************************************************************
993 * TOOLBAR_MeasureString
995 * This function gets the width and height of a string in pixels. This
996 * is done first by using GetTextExtentPoint to get the basic width
997 * and height. The DrawText is called with DT_CALCRECT to get the exact
998 * width. The reason is because the text may have more than one "&" (or
999 * prefix characters as M$ likes to call them). The prefix character
1000 * indicates where the underline goes, except for the string "&&" which
1001 * is reduced to a single "&". GetTextExtentPoint does not process these
1002 * only DrawText does. Note that the TBSTYLE_NOPREFIX is handled here.
1004 static void
1005 TOOLBAR_MeasureString(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
1006 HDC hdc, LPSIZE lpSize)
1008 RECT myrect;
1010 lpSize->cx = 0;
1011 lpSize->cy = 0;
1013 if (!(btnPtr->fsState & TBSTATE_HIDDEN) )
1015 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1017 if(lpText != NULL) {
1018 /* first get size of all the text */
1019 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1021 /* feed above size into the rectangle for DrawText */
1022 myrect.left = myrect.top = 0;
1023 myrect.right = lpSize->cx;
1024 myrect.bottom = lpSize->cy;
1026 /* Use DrawText to get true size as drawn (less pesky "&") */
1027 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1028 DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
1029 DT_NOPREFIX : 0));
1031 /* feed back to caller */
1032 lpSize->cx = myrect.right;
1033 lpSize->cy = myrect.bottom;
1037 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1040 /***********************************************************************
1041 * TOOLBAR_CalcStrings
1043 * This function walks through each string and measures it and returns
1044 * the largest height and width to caller.
1046 static void
1047 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
1049 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1050 TBUTTON_INFO *btnPtr;
1051 INT i;
1052 SIZE sz;
1053 HDC hdc;
1054 HFONT hOldFont;
1056 lpSize->cx = 0;
1057 lpSize->cy = 0;
1059 hdc = GetDC (hwnd);
1060 hOldFont = SelectObject (hdc, infoPtr->hFont);
1062 btnPtr = infoPtr->buttons;
1063 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1064 if(TOOLBAR_HasText(infoPtr, btnPtr))
1066 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1067 if (sz.cx > lpSize->cx)
1068 lpSize->cx = sz.cx;
1069 if (sz.cy > lpSize->cy)
1070 lpSize->cy = sz.cy;
1074 SelectObject (hdc, hOldFont);
1075 ReleaseDC (hwnd, hdc);
1077 TRACE("max string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
1080 /***********************************************************************
1081 * TOOLBAR_WrapToolbar
1083 * This function walks through the buttons and seperators in the
1084 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1085 * wrapping should occur based on the width of the toolbar window.
1086 * It does *not* calculate button placement itself. That task
1087 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1088 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1089 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1091 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
1092 * vertical toolbar lists.
1095 static void
1096 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
1098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1099 TBUTTON_INFO *btnPtr;
1100 INT x, cx, i, j;
1101 RECT rc;
1102 BOOL bWrap, bButtonWrap;
1104 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1105 /* no layout is necessary. Applications may use this style */
1106 /* to perform their own layout on the toolbar. */
1107 if( !(dwStyle & TBSTYLE_WRAPABLE) &&
1108 !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
1110 btnPtr = infoPtr->buttons;
1111 x = infoPtr->nIndent;
1113 /* this can get the parents width, to know how far we can extend
1114 * this toolbar. We cannot use its height, as there may be multiple
1115 * toolbars in a rebar control
1117 GetClientRect( GetParent(hwnd), &rc );
1118 infoPtr->nWidth = rc.right - rc.left;
1119 bButtonWrap = FALSE;
1121 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1122 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1123 infoPtr->nIndent);
1125 for (i = 0; i < infoPtr->nNumButtons; i++ )
1127 bWrap = FALSE;
1128 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1130 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1131 continue;
1133 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1134 /* it is the actual width of the separator. This is used for */
1135 /* custom controls in toolbars. */
1136 /* */
1137 /* TBSTYLE_DROPDOWN separators are treated as buttons for */
1138 /* width. - GA 8/01 */
1139 if ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1140 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN))
1141 cx = (btnPtr[i].iBitmap > 0) ?
1142 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1143 else
1144 cx = infoPtr->nButtonWidth;
1146 /* Two or more adjacent separators form a separator group. */
1147 /* The first separator in a group should be wrapped to the */
1148 /* next row if the previous wrapping is on a button. */
1149 if( bButtonWrap &&
1150 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1151 (i + 1 < infoPtr->nNumButtons ) &&
1152 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
1154 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1155 btnPtr[i].fsState |= TBSTATE_WRAP;
1156 x = infoPtr->nIndent;
1157 i++;
1158 bButtonWrap = FALSE;
1159 continue;
1162 /* The layout makes sure the bitmap is visible, but not the button. */
1163 /* Test added to also wrap after a button that starts a row but */
1164 /* is bigger than the area. - GA 8/01 */
1165 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1166 > infoPtr->nWidth ) ||
1167 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1169 BOOL bFound = FALSE;
1171 /* If the current button is a separator and not hidden, */
1172 /* go to the next until it reaches a non separator. */
1173 /* Wrap the last separator if it is before a button. */
1174 while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
1175 !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
1176 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1177 i < infoPtr->nNumButtons )
1179 i++;
1180 bFound = TRUE;
1183 if( bFound && i < infoPtr->nNumButtons )
1185 i--;
1186 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1187 i, btnPtr[i].fsStyle, x, cx);
1188 btnPtr[i].fsState |= TBSTATE_WRAP;
1189 x = infoPtr->nIndent;
1190 bButtonWrap = FALSE;
1191 continue;
1193 else if ( i >= infoPtr->nNumButtons)
1194 break;
1196 /* If the current button is not a separator, find the last */
1197 /* separator and wrap it. */
1198 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1200 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
1201 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1203 bFound = TRUE;
1204 i = j;
1205 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1206 i, btnPtr[i].fsStyle, x, cx);
1207 x = infoPtr->nIndent;
1208 btnPtr[j].fsState |= TBSTATE_WRAP;
1209 bButtonWrap = FALSE;
1210 break;
1214 /* If no separator available for wrapping, wrap one of */
1215 /* non-hidden previous button. */
1216 if (!bFound)
1218 for ( j = i - 1;
1219 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1221 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1222 continue;
1224 bFound = TRUE;
1225 i = j;
1226 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1227 i, btnPtr[i].fsStyle, x, cx);
1228 x = infoPtr->nIndent;
1229 btnPtr[j].fsState |= TBSTATE_WRAP;
1230 bButtonWrap = TRUE;
1231 break;
1235 /* If all above failed, wrap the current button. */
1236 if (!bFound)
1238 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1239 i, btnPtr[i].fsStyle, x, cx);
1240 btnPtr[i].fsState |= TBSTATE_WRAP;
1241 bFound = TRUE;
1242 x = infoPtr->nIndent;
1243 if (btnPtr[i].fsStyle & TBSTYLE_SEP )
1244 bButtonWrap = FALSE;
1245 else
1246 bButtonWrap = TRUE;
1249 else {
1250 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1251 i, btnPtr[i].fsStyle, x, cx);
1252 x += cx;
1258 /***********************************************************************
1259 * TOOLBAR_CalcToolbar
1261 * This function calculates button and separator placement. It first
1262 * calculates the button sizes, gets the toolbar window width and then
1263 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1264 * on. It assigns a new location to each item and sends this location to
1265 * the tooltip window if appropriate. Finally, it updates the rcBound
1266 * rect and calculates the new required toolbar window height.
1269 static void
1270 TOOLBAR_CalcToolbar (HWND hwnd)
1272 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1273 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1274 TBUTTON_INFO *btnPtr;
1275 INT i, nRows, nSepRows;
1276 INT x, y, cx, cy;
1277 SIZE sizeString;
1278 BOOL bWrap;
1279 BOOL usesBitmaps = FALSE;
1280 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1282 TOOLBAR_CalcStrings (hwnd, &sizeString);
1284 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
1286 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
1287 usesBitmaps = TRUE;
1289 if (dwStyle & TBSTYLE_LIST)
1291 infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
1292 0, sizeString.cy) + infoPtr->szPadding.cy;
1293 infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
1294 0) + sizeString.cx + 6;
1295 TRACE("LIST style, But w=%d h=%d, useBitmaps=%d, Bit w=%d h=%d\n",
1296 infoPtr->nButtonWidth, infoPtr->nButtonHeight, usesBitmaps,
1297 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1298 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1300 else {
1301 if (sizeString.cy > 0)
1303 if (usesBitmaps)
1304 infoPtr->nButtonHeight = sizeString.cy +
1305 2 + /* this is the space to separate text from bitmap */
1306 infoPtr->nBitmapHeight + 6;
1307 else
1308 infoPtr->nButtonHeight = sizeString.cy + 6;
1310 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
1311 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
1313 if (sizeString.cx > infoPtr->nBitmapWidth)
1314 infoPtr->nButtonWidth = sizeString.cx + 6;
1315 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
1316 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
1319 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1320 infoPtr->nButtonWidth = infoPtr->cxMin;
1321 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1322 infoPtr->nButtonWidth = infoPtr->cxMax;
1324 TOOLBAR_WrapToolbar( hwnd, dwStyle );
1326 x = infoPtr->nIndent;
1327 y = 0;
1330 * We will set the height below, and we set the width on entry
1331 * so we do not reset them here..
1333 #if 0
1334 GetClientRect( hwnd, &rc );
1335 /* get initial values for toolbar */
1336 infoPtr->nWidth = rc.right - rc.left;
1337 infoPtr->nHeight = rc.bottom - rc.top;
1338 #endif
1340 /* from above, minimum is a button, and possible text */
1341 cx = infoPtr->nButtonWidth;
1343 /* cannot use just ButtonHeight, we may have no buttons! */
1344 if (infoPtr->nNumButtons > 0)
1345 infoPtr->nHeight = infoPtr->nButtonHeight;
1347 cy = infoPtr->nHeight;
1349 nRows = nSepRows = 0;
1351 infoPtr->rcBound.top = y;
1352 infoPtr->rcBound.left = x;
1353 infoPtr->rcBound.bottom = y + cy;
1354 infoPtr->rcBound.right = x;
1356 btnPtr = infoPtr->buttons;
1358 /* do not base height/width on parent, if the parent is a */
1359 /* rebar control it could have multiple rows of toolbars */
1360 /* GetClientRect( GetParent(hwnd), &rc ); */
1361 /* cx = rc.right - rc.left; */
1362 /* cy = rc.bottom - rc.top; */
1364 TRACE("cy=%d\n", cy);
1366 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1368 bWrap = FALSE;
1369 if (btnPtr->fsState & TBSTATE_HIDDEN)
1371 SetRectEmpty (&btnPtr->rect);
1372 continue;
1375 cy = infoPtr->nHeight;
1377 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1378 /* it is the actual width of the separator. This is used for */
1379 /* custom controls in toolbars. */
1380 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1381 if (btnPtr->fsStyle & TBSTYLE_DROPDOWN) {
1382 cy = (btnPtr->iBitmap > 0) ?
1383 btnPtr->iBitmap : SEPARATOR_WIDTH;
1384 cx = infoPtr->nButtonWidth;
1386 else
1387 cx = (btnPtr->iBitmap > 0) ?
1388 btnPtr->iBitmap : SEPARATOR_WIDTH;
1390 else
1392 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
1394 SIZE sz;
1395 HDC hdc;
1396 HFONT hOldFont;
1398 hdc = GetDC (hwnd);
1399 hOldFont = SelectObject (hdc, infoPtr->hFont);
1401 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1403 SelectObject (hdc, hOldFont);
1404 ReleaseDC (hwnd, hdc);
1406 /* Fudge amount measured against IE4 "menu" and "Links" */
1407 /* toolbars with native control (v4.71). - GA 8/01 */
1408 cx = sz.cx + 6 + 5 + 5;
1409 if ((dwStyle & TBSTYLE_LIST) &&
1410 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))
1411 cx += infoPtr->nBitmapWidth;
1413 else
1414 cx = infoPtr->nButtonWidth;
1416 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1417 cx += DDARROW_WIDTH;
1419 if (btnPtr->fsState & TBSTATE_WRAP )
1420 bWrap = TRUE;
1422 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1424 if (infoPtr->rcBound.left > x)
1425 infoPtr->rcBound.left = x;
1426 if (infoPtr->rcBound.right < x + cx)
1427 infoPtr->rcBound.right = x + cx;
1428 if (infoPtr->rcBound.bottom < y + cy)
1429 infoPtr->rcBound.bottom = y + cy;
1431 /* Set the toolTip only for non-hidden, non-separator button */
1432 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
1434 TTTOOLINFOA ti;
1436 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1437 ti.cbSize = sizeof(TTTOOLINFOA);
1438 ti.hwnd = hwnd;
1439 ti.uId = btnPtr->idCommand;
1440 ti.rect = btnPtr->rect;
1441 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
1442 0, (LPARAM)&ti);
1445 /* btnPtr->nRow is zero based. The space between the rows is */
1446 /* also considered as a row. */
1447 btnPtr->nRow = nRows + nSepRows;
1449 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1450 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1451 x, y, x+cx, y+cy);
1453 if( bWrap )
1455 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
1456 y += cy;
1457 else
1459 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
1460 /* it is the actual width of the separator. This is used for */
1461 /* custom controls in toolbars. */
1462 if ( !(btnPtr->fsStyle & TBSTYLE_DROPDOWN))
1463 y += cy + ( (btnPtr->iBitmap > 0 ) ?
1464 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
1465 else
1466 y += cy;
1468 /* nSepRows is used to calculate the extra height follwoing */
1469 /* the last row. */
1470 nSepRows++;
1472 x = infoPtr->nIndent;
1474 /* Increment row number unless this is the last button */
1475 /* and it has Wrap set. */
1476 if (i != infoPtr->nNumButtons-1)
1477 nRows++;
1479 else
1480 x += cx;
1483 /* infoPtr->nRows is the number of rows on the toolbar */
1484 infoPtr->nRows = nRows + nSepRows + 1;
1486 #if 0
1487 /********************************************************************
1488 * The following while interesting, does not match the values *
1489 * created above for the button rectangles, nor the rcBound rect. *
1490 * We will comment it out and remove it later. *
1492 * The problem showed up as heights in the pager control that was *
1493 * wrong. *
1494 ********************************************************************/
1496 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
1497 /* the last row. */
1498 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
1499 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
1500 nSepRows * (infoPtr->nBitmapHeight + 1) +
1501 BOTTOM_BORDER;
1502 #endif
1504 infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1506 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
1510 static INT
1511 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
1513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1514 TBUTTON_INFO *btnPtr;
1515 INT i;
1517 btnPtr = infoPtr->buttons;
1518 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1519 if (btnPtr->fsState & TBSTATE_HIDDEN)
1520 continue;
1522 if (btnPtr->fsStyle & TBSTYLE_SEP) {
1523 if (PtInRect (&btnPtr->rect, *lpPt)) {
1524 TRACE(" ON SEPARATOR %d!\n", i);
1525 return -i;
1528 else {
1529 if (PtInRect (&btnPtr->rect, *lpPt)) {
1530 TRACE(" ON BUTTON %d!\n", i);
1531 return i;
1536 TRACE(" NOWHERE!\n");
1537 return -1;
1541 static INT
1542 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1544 TBUTTON_INFO *btnPtr;
1545 INT i;
1547 if (CommandIsIndex) {
1548 TRACE("command is really index command=%d\n", idCommand);
1549 if (idCommand >= infoPtr->nNumButtons) return -1;
1550 return idCommand;
1552 btnPtr = infoPtr->buttons;
1553 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1554 if (btnPtr->idCommand == idCommand) {
1555 TRACE("command=%d index=%d\n", idCommand, i);
1556 return i;
1559 TRACE("no index found for command=%d\n", idCommand);
1560 return -1;
1564 static INT
1565 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
1567 TBUTTON_INFO *btnPtr;
1568 INT nRunIndex;
1570 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1571 return -1;
1573 /* check index button */
1574 btnPtr = &infoPtr->buttons[nIndex];
1575 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1576 if (btnPtr->fsState & TBSTATE_CHECKED)
1577 return nIndex;
1580 /* check previous buttons */
1581 nRunIndex = nIndex - 1;
1582 while (nRunIndex >= 0) {
1583 btnPtr = &infoPtr->buttons[nRunIndex];
1584 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1585 if (btnPtr->fsState & TBSTATE_CHECKED)
1586 return nRunIndex;
1588 else
1589 break;
1590 nRunIndex--;
1593 /* check next buttons */
1594 nRunIndex = nIndex + 1;
1595 while (nRunIndex < infoPtr->nNumButtons) {
1596 btnPtr = &infoPtr->buttons[nRunIndex];
1597 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1598 if (btnPtr->fsState & TBSTATE_CHECKED)
1599 return nRunIndex;
1601 else
1602 break;
1603 nRunIndex++;
1606 return -1;
1610 static VOID
1611 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1612 WPARAM wParam, LPARAM lParam)
1614 MSG msg;
1616 msg.hwnd = hwndMsg;
1617 msg.message = uMsg;
1618 msg.wParam = wParam;
1619 msg.lParam = lParam;
1620 msg.time = GetMessageTime ();
1621 msg.pt.x = LOWORD(GetMessagePos ());
1622 msg.pt.y = HIWORD(GetMessagePos ());
1624 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1628 /***********************************************************************
1629 * TOOLBAR_CustomizeDialogProc
1630 * This function implements the toolbar customization dialog.
1632 static BOOL WINAPI
1633 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1635 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1636 PCUSTOMBUTTON btnInfo;
1637 NMTOOLBARA nmtb;
1638 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
1640 switch (uMsg)
1642 case WM_INITDIALOG:
1643 custInfo = (PCUSTDLG_INFO)lParam;
1644 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1646 if (custInfo)
1648 char Buffer[256];
1649 int i = 0;
1650 int index;
1652 infoPtr = custInfo->tbInfo;
1654 /* send TBN_QUERYINSERT notification */
1655 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1657 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYINSERT))
1658 return FALSE;
1660 /* add items to 'toolbar buttons' list and check if removable */
1661 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1663 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1664 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1665 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1666 btnInfo->bVirtual = FALSE;
1667 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1669 /* send TBN_QUERYDELETE notification */
1670 nmtb.iItem = i;
1671 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb,
1672 infoPtr,
1673 TBN_QUERYDELETE);
1675 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1676 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1679 /* insert separator button into 'available buttons' list */
1680 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1681 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1682 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1683 btnInfo->bVirtual = FALSE;
1684 btnInfo->bRemovable = TRUE;
1685 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1686 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1687 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1689 /* insert all buttons into dsa */
1690 for (i = 0;; i++)
1692 /* send TBN_GETBUTTONINFO notification */
1693 nmtb.iItem = i;
1694 nmtb.pszText = Buffer;
1695 nmtb.cchText = 256;
1697 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA))
1698 break;
1700 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1702 /* insert button into the apropriate list */
1703 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
1704 if (index == -1)
1706 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1707 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1708 btnInfo->bVirtual = FALSE;
1709 btnInfo->bRemovable = TRUE;
1710 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1711 strcpy (btnInfo->text, nmtb.pszText);
1713 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1714 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1716 else
1718 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1719 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1720 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1721 strcpy (btnInfo->text, nmtb.pszText);
1723 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1727 /* select first item in the 'available' list */
1728 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1730 /* append 'virtual' separator button to the 'toolbar buttons' list */
1731 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1732 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1733 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1734 btnInfo->bVirtual = TRUE;
1735 btnInfo->bRemovable = FALSE;
1736 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1737 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1738 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1740 /* select last item in the 'toolbar' list */
1741 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1742 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1744 /* set focus and disable buttons */
1745 PostMessageA (hwnd, WM_USER, 0, 0);
1747 return TRUE;
1749 case WM_USER:
1750 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1751 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1752 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1753 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1754 return TRUE;
1756 case WM_CLOSE:
1757 EndDialog(hwnd, FALSE);
1758 return TRUE;
1760 case WM_COMMAND:
1761 switch (LOWORD(wParam))
1763 case IDC_TOOLBARBTN_LBOX:
1764 if (HIWORD(wParam) == LBN_SELCHANGE)
1766 PCUSTOMBUTTON btnInfo;
1767 NMTOOLBARA nmtb;
1768 int count;
1769 int index;
1771 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1772 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1774 /* send TBN_QUERYINSERT notification */
1775 nmtb.iItem = index;
1776 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1777 TBN_QUERYINSERT);
1779 /* get list box item */
1780 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1782 if (index == (count - 1))
1784 /* last item (virtual separator) */
1785 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1786 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1788 else if (index == (count - 2))
1790 /* second last item (last non-virtual item) */
1791 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1792 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1794 else if (index == 0)
1796 /* first item */
1797 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1798 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1800 else
1802 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1803 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1806 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1808 break;
1810 case IDC_MOVEUP_BTN:
1812 PCUSTOMBUTTON btnInfo;
1813 int index;
1814 int count;
1816 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1817 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1818 TRACE("Move up: index %d\n", index);
1820 /* send TBN_QUERYINSERT notification */
1821 nmtb.iItem = index;
1823 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1824 TBN_QUERYINSERT))
1826 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1828 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1829 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1830 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1831 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1833 if (index <= 1)
1834 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1835 else if (index >= (count - 3))
1836 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1838 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1839 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1842 break;
1844 case IDC_MOVEDN_BTN: /* move down */
1846 PCUSTOMBUTTON btnInfo;
1847 int index;
1848 int count;
1850 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1851 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1852 TRACE("Move up: index %d\n", index);
1854 /* send TBN_QUERYINSERT notification */
1855 nmtb.iItem = index;
1856 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1857 TBN_QUERYINSERT))
1859 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1861 /* move button down */
1862 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1863 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1864 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1865 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1867 if (index == 0)
1868 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1869 else if (index >= (count - 3))
1870 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1872 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1873 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1876 break;
1878 case IDC_REMOVE_BTN: /* remove button */
1880 PCUSTOMBUTTON btnInfo;
1881 int index;
1883 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1884 TRACE("Remove: index %d\n", index);
1886 /* send TBN_QUERYDELETE notification */
1887 nmtb.iItem = index;
1888 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1889 TBN_QUERYDELETE))
1891 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1892 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1893 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1895 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1897 /* insert into 'available button' list */
1898 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1900 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1901 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1903 else
1904 COMCTL32_Free (btnInfo);
1907 break;
1909 case IDOK: /* Add button */
1911 int index;
1912 int count;
1914 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1915 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1916 TRACE("Add: index %d\n", index);
1918 /* send TBN_QUERYINSERT notification */
1919 nmtb.iItem = index;
1920 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
1921 TBN_QUERYINSERT))
1923 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1925 if (index != 0)
1927 /* remove from 'available buttons' list */
1928 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1929 if (index == count-1)
1930 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1931 else
1932 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1934 else
1936 PCUSTOMBUTTON btnNew;
1938 /* duplicate 'separator' button */
1939 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1940 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1941 btnInfo = btnNew;
1944 /* insert into 'toolbar button' list */
1945 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1946 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1947 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1949 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1952 break;
1954 case IDCANCEL:
1955 EndDialog(hwnd, FALSE);
1956 break;
1958 return TRUE;
1960 case WM_DESTROY:
1962 int count;
1963 int i;
1965 /* delete items from 'toolbar buttons' listbox*/
1966 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1967 for (i = 0; i < count; i++)
1969 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1970 COMCTL32_Free(btnInfo);
1971 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1973 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1976 /* delete items from 'available buttons' listbox*/
1977 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1978 for (i = 0; i < count; i++)
1980 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1981 COMCTL32_Free(btnInfo);
1982 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1984 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1986 return TRUE;
1988 case WM_DRAWITEM:
1989 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1991 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1992 RECT rcButton;
1993 RECT rcText;
1994 HPEN hPen, hOldPen;
1995 HBRUSH hOldBrush;
1996 COLORREF oldText = 0;
1997 COLORREF oldBk = 0;
1999 /* get item data */
2000 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
2001 if (btnInfo == NULL)
2003 FIXME("btnInfo invalid!\n");
2004 return TRUE;
2007 /* set colors and select objects */
2008 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2009 if (btnInfo->bVirtual)
2010 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2011 else
2012 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2013 hPen = CreatePen( PS_SOLID, 1,
2014 GetSysColor( (lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2015 hOldPen = SelectObject (lpdis->hDC, hPen );
2016 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2018 /* fill background rectangle */
2019 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2020 lpdis->rcItem.right, lpdis->rcItem.bottom);
2022 /* calculate button and text rectangles */
2023 CopyRect (&rcButton, &lpdis->rcItem);
2024 InflateRect (&rcButton, -1, -1);
2025 CopyRect (&rcText, &rcButton);
2026 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2027 rcText.left = rcButton.right + 2;
2029 /* draw focus rectangle */
2030 if (lpdis->itemState & ODS_FOCUS)
2031 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2033 /* draw button */
2034 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2036 /* draw image and text */
2037 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
2038 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
2039 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2040 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
2041 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2043 /* delete objects and reset colors */
2044 SelectObject (lpdis->hDC, hOldBrush);
2045 SelectObject (lpdis->hDC, hOldPen);
2046 SetBkColor (lpdis->hDC, oldBk);
2047 SetTextColor (lpdis->hDC, oldText);
2048 DeleteObject( hPen );
2049 return TRUE;
2051 return FALSE;
2053 case WM_MEASUREITEM:
2054 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2056 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2058 if (custInfo && custInfo->tbInfo)
2059 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
2060 else
2061 lpmis->itemHeight = 15 + 8; /* default height */
2063 return TRUE;
2065 return FALSE;
2067 default:
2068 return FALSE;
2073 /***********************************************************************
2074 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2077 static LRESULT
2078 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2081 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
2082 INT nIndex = 0, nButtons, nCount;
2083 HBITMAP hbmLoad;
2085 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
2086 if (!lpAddBmp)
2087 return -1;
2089 if (lpAddBmp->hInst == HINST_COMMCTRL)
2091 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
2092 nButtons = 15;
2093 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
2094 nButtons = 13;
2095 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
2096 nButtons = 5;
2097 else
2098 return -1;
2100 TRACE ("adding %d internal bitmaps!\n", nButtons);
2102 /* Windows resize all the buttons to the size of a newly added standard image */
2103 if (lpAddBmp->nID & 1)
2105 /* large icons */
2106 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
2107 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
2109 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2110 MAKELPARAM((WORD)24, (WORD)24));
2111 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2112 MAKELPARAM((WORD)31, (WORD)30));
2114 else
2116 /* small icons */
2117 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
2118 MAKELPARAM((WORD)16, (WORD)16));
2119 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
2120 MAKELPARAM((WORD)22, (WORD)22));
2123 TOOLBAR_CalcToolbar (hwnd);
2125 else
2127 nButtons = (INT)wParam;
2128 if (nButtons <= 0)
2129 return -1;
2131 TRACE ("adding %d bitmaps!\n", nButtons);
2134 if (!(infoPtr->himlDef)) {
2135 /* create new default image list */
2136 TRACE ("creating default image list!\n");
2138 infoPtr->himlDef =
2139 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2140 ILC_COLOR | ILC_MASK, nButtons, 2);
2141 infoPtr->himlInt = infoPtr->himlDef;
2144 nCount = ImageList_GetImageCount(infoPtr->himlDef);
2146 /* Add bitmaps to the default image list */
2147 if (lpAddBmp->hInst == (HINSTANCE)0)
2149 nIndex =
2150 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
2151 CLR_DEFAULT);
2153 else if (lpAddBmp->hInst == HINST_COMMCTRL)
2155 /* Add system bitmaps */
2156 switch (lpAddBmp->nID)
2158 case IDB_STD_SMALL_COLOR:
2159 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2160 MAKEINTRESOURCEA(IDB_STD_SMALL));
2161 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2162 hbmLoad, CLR_DEFAULT);
2163 DeleteObject (hbmLoad);
2164 break;
2166 case IDB_STD_LARGE_COLOR:
2167 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2168 MAKEINTRESOURCEA(IDB_STD_LARGE));
2169 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2170 hbmLoad, CLR_DEFAULT);
2171 DeleteObject (hbmLoad);
2172 break;
2174 case IDB_VIEW_SMALL_COLOR:
2175 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2176 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
2177 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2178 hbmLoad, CLR_DEFAULT);
2179 DeleteObject (hbmLoad);
2180 break;
2182 case IDB_VIEW_LARGE_COLOR:
2183 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2184 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
2185 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2186 hbmLoad, CLR_DEFAULT);
2187 DeleteObject (hbmLoad);
2188 break;
2190 case IDB_HIST_SMALL_COLOR:
2191 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2192 MAKEINTRESOURCEA(IDB_HIST_SMALL));
2193 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2194 hbmLoad, CLR_DEFAULT);
2195 DeleteObject (hbmLoad);
2196 break;
2198 case IDB_HIST_LARGE_COLOR:
2199 hbmLoad = LoadBitmapA (COMCTL32_hModule,
2200 MAKEINTRESOURCEA(IDB_HIST_LARGE));
2201 nIndex = ImageList_AddMasked (infoPtr->himlDef,
2202 hbmLoad, CLR_DEFAULT);
2203 DeleteObject (hbmLoad);
2204 break;
2206 default:
2207 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
2208 ERR ("invalid imagelist!\n");
2209 break;
2212 else
2214 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
2215 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
2216 DeleteObject (hbmLoad);
2219 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2221 if (infoPtr->nNumBitmapInfos == 0)
2223 infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
2225 else
2227 TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
2228 infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2229 memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
2232 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
2233 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
2234 infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
2236 infoPtr->nNumBitmapInfos++;
2237 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2239 if (nIndex != -1)
2241 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
2243 if (infoPtr->nNumBitmaps + nButtons != imagecount)
2245 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",
2246 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
2247 infoPtr->nNumBitmaps+nButtons,imagecount);
2249 infoPtr->nNumBitmaps = imagecount;
2251 else
2252 infoPtr->nNumBitmaps += nButtons;
2255 InvalidateRect(hwnd, NULL, FALSE);
2257 return nIndex;
2261 static LRESULT
2262 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2264 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2265 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2266 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2268 TRACE("adding %d buttons!\n", wParam);
2270 nAddButtons = (UINT)wParam;
2271 nOldButtons = infoPtr->nNumButtons;
2272 nNewButtons = nOldButtons + nAddButtons;
2274 if (infoPtr->nNumButtons == 0) {
2275 infoPtr->buttons =
2276 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2278 else {
2279 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2280 infoPtr->buttons =
2281 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2282 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2283 nOldButtons * sizeof(TBUTTON_INFO));
2284 COMCTL32_Free (oldButtons);
2287 infoPtr->nNumButtons = nNewButtons;
2289 /* insert new button data */
2290 for (nCount = 0; nCount < nAddButtons; nCount++) {
2291 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2292 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2293 btnPtr->idCommand = lpTbb[nCount].idCommand;
2294 btnPtr->fsState = lpTbb[nCount].fsState;
2295 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2296 btnPtr->dwData = lpTbb[nCount].dwData;
2297 btnPtr->iString = lpTbb[nCount].iString;
2298 btnPtr->bHot = FALSE;
2300 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2301 TTTOOLINFOA ti;
2303 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2304 ti.cbSize = sizeof (TTTOOLINFOA);
2305 ti.hwnd = hwnd;
2306 ti.uId = btnPtr->idCommand;
2307 ti.hinst = 0;
2308 ti.lpszText = LPSTR_TEXTCALLBACKA;
2310 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2311 0, (LPARAM)&ti);
2315 TOOLBAR_CalcToolbar (hwnd);
2317 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2319 InvalidateRect(hwnd, NULL, FALSE);
2321 return TRUE;
2325 static LRESULT
2326 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2328 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2329 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2330 INT nOldButtons, nNewButtons, nAddButtons, nCount;
2332 TRACE("adding %d buttons!\n", wParam);
2334 nAddButtons = (UINT)wParam;
2335 nOldButtons = infoPtr->nNumButtons;
2336 nNewButtons = nOldButtons + nAddButtons;
2338 if (infoPtr->nNumButtons == 0) {
2339 infoPtr->buttons =
2340 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2342 else {
2343 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2344 infoPtr->buttons =
2345 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
2346 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2347 nOldButtons * sizeof(TBUTTON_INFO));
2348 COMCTL32_Free (oldButtons);
2351 infoPtr->nNumButtons = nNewButtons;
2353 /* insert new button data */
2354 for (nCount = 0; nCount < nAddButtons; nCount++) {
2355 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
2356 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
2357 btnPtr->idCommand = lpTbb[nCount].idCommand;
2358 btnPtr->fsState = lpTbb[nCount].fsState;
2359 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
2360 btnPtr->dwData = lpTbb[nCount].dwData;
2361 btnPtr->iString = lpTbb[nCount].iString;
2362 btnPtr->bHot = FALSE;
2364 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
2365 TTTOOLINFOW ti;
2367 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2368 ti.cbSize = sizeof (TTTOOLINFOW);
2369 ti.hwnd = hwnd;
2370 ti.uId = btnPtr->idCommand;
2371 ti.hinst = 0;
2372 ti.lpszText = LPSTR_TEXTCALLBACKW;
2374 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2375 0, (LPARAM)&ti);
2379 TOOLBAR_CalcToolbar (hwnd);
2381 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
2383 InvalidateRect(hwnd, NULL, FALSE);
2385 return TRUE;
2389 static LRESULT
2390 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2392 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2393 INT nIndex;
2395 if ((wParam) && (HIWORD(lParam) == 0)) {
2396 char szString[256];
2397 INT len;
2398 TRACE("adding string from resource!\n");
2400 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
2401 szString, 256);
2403 TRACE("len=%d \"%s\"\n", len, szString);
2404 nIndex = infoPtr->nNumStrings;
2405 if (infoPtr->nNumStrings == 0) {
2406 infoPtr->strings =
2407 COMCTL32_Alloc (sizeof(LPWSTR));
2409 else {
2410 LPWSTR *oldStrings = infoPtr->strings;
2411 infoPtr->strings =
2412 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2413 memcpy (&infoPtr->strings[0], &oldStrings[0],
2414 sizeof(LPWSTR) * infoPtr->nNumStrings);
2415 COMCTL32_Free (oldStrings);
2418 /*COMCTL32_Alloc zeros out the allocated memory*/
2419 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], szString );
2420 infoPtr->nNumStrings++;
2422 else {
2423 LPSTR p = (LPSTR)lParam;
2424 INT len;
2426 if (p == NULL)
2427 return -1;
2428 TRACE("adding string(s) from array!\n");
2430 nIndex = infoPtr->nNumStrings;
2431 while (*p) {
2432 len = strlen (p);
2433 TRACE("len=%d \"%s\"\n", len, p);
2435 if (infoPtr->nNumStrings == 0) {
2436 infoPtr->strings =
2437 COMCTL32_Alloc (sizeof(LPWSTR));
2439 else {
2440 LPWSTR *oldStrings = infoPtr->strings;
2441 infoPtr->strings =
2442 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2443 memcpy (&infoPtr->strings[0], &oldStrings[0],
2444 sizeof(LPWSTR) * infoPtr->nNumStrings);
2445 COMCTL32_Free (oldStrings);
2448 Str_SetPtrAtoW (&infoPtr->strings[infoPtr->nNumStrings], p );
2449 infoPtr->nNumStrings++;
2451 p += (len+1);
2455 return nIndex;
2459 static LRESULT
2460 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2462 #define MAX_RESOURCE_STRING_LENGTH 512
2463 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2464 INT nIndex;
2466 if ((wParam) && (HIWORD(lParam) == 0)) {
2467 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2468 INT len;
2469 TRACE("adding string from resource!\n");
2471 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
2472 szString, MAX_RESOURCE_STRING_LENGTH);
2474 TRACE("len=%d %s\n", len, debugstr_w(szString));
2475 TRACE("First char: 0x%x\n", *szString);
2476 if (szString[0] == L'|')
2478 PWSTR p = szString + 1;
2480 nIndex = infoPtr->nNumStrings;
2481 while (*p != L'|' && *p != L'\0') {
2482 PWSTR np;
2484 if (infoPtr->nNumStrings == 0) {
2485 infoPtr->strings = COMCTL32_Alloc (sizeof(LPWSTR));
2487 else
2489 LPWSTR *oldStrings = infoPtr->strings;
2490 infoPtr->strings = COMCTL32_Alloc(sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2491 memcpy(&infoPtr->strings[0], &oldStrings[0],
2492 sizeof(LPWSTR) * infoPtr->nNumStrings);
2493 COMCTL32_Free(oldStrings);
2496 np=COMCTL32_StrChrW (p, L'|');
2497 if (np!=NULL) {
2498 len = np - p;
2499 np++;
2500 } else {
2501 len = strlenW(p);
2502 np = p + len;
2504 TRACE("len=%d %s\n", len, debugstr_w(p));
2505 infoPtr->strings[infoPtr->nNumStrings] =
2506 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
2507 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len+1);
2508 infoPtr->nNumStrings++;
2510 p = np;
2513 else
2515 nIndex = infoPtr->nNumStrings;
2516 if (infoPtr->nNumStrings == 0) {
2517 infoPtr->strings =
2518 COMCTL32_Alloc (sizeof(LPWSTR));
2520 else {
2521 LPWSTR *oldStrings = infoPtr->strings;
2522 infoPtr->strings =
2523 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2524 memcpy (&infoPtr->strings[0], &oldStrings[0],
2525 sizeof(LPWSTR) * infoPtr->nNumStrings);
2526 COMCTL32_Free (oldStrings);
2529 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], szString);
2530 infoPtr->nNumStrings++;
2533 else {
2534 LPWSTR p = (LPWSTR)lParam;
2535 INT len;
2537 if (p == NULL)
2538 return -1;
2539 TRACE("adding string(s) from array!\n");
2540 nIndex = infoPtr->nNumStrings;
2541 while (*p) {
2542 len = strlenW (p);
2544 TRACE("len=%d %s\n", len, debugstr_w(p));
2545 if (infoPtr->nNumStrings == 0) {
2546 infoPtr->strings =
2547 COMCTL32_Alloc (sizeof(LPWSTR));
2549 else {
2550 LPWSTR *oldStrings = infoPtr->strings;
2551 infoPtr->strings =
2552 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
2553 memcpy (&infoPtr->strings[0], &oldStrings[0],
2554 sizeof(LPWSTR) * infoPtr->nNumStrings);
2555 COMCTL32_Free (oldStrings);
2558 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2559 infoPtr->nNumStrings++;
2561 p += (len+1);
2565 return nIndex;
2569 static LRESULT
2570 TOOLBAR_AutoSize (HWND hwnd)
2572 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2573 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2574 RECT parent_rect;
2575 RECT window_rect;
2576 HWND parent;
2577 INT x, y;
2578 INT cx, cy;
2579 UINT uPosFlags = SWP_NOZORDER;
2581 TRACE("resize forced, style=%lx!\n", dwStyle);
2583 parent = GetParent (hwnd);
2584 GetClientRect(parent, &parent_rect);
2586 x = parent_rect.left;
2587 y = parent_rect.top;
2589 /* FIXME: we should be able to early out if nothing */
2590 /* has changed with nWidth != parent_rect width */
2592 if (dwStyle & CCS_NORESIZE) {
2593 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2594 cx = 0;
2595 cy = 0;
2596 TOOLBAR_CalcToolbar (hwnd);
2598 else {
2599 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2600 TOOLBAR_CalcToolbar (hwnd);
2601 InvalidateRect( hwnd, NULL, TRUE );
2602 cy = infoPtr->nHeight;
2603 cx = infoPtr->nWidth;
2605 if (dwStyle & CCS_NOMOVEY) {
2606 GetWindowRect(hwnd, &window_rect);
2607 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2608 y = window_rect.top;
2612 if (dwStyle & CCS_NOPARENTALIGN)
2613 uPosFlags |= SWP_NOMOVE;
2615 if (!(dwStyle & CCS_NODIVIDER))
2616 cy += GetSystemMetrics(SM_CYEDGE);
2618 if (dwStyle & WS_BORDER)
2620 x = y = 1;
2621 cy += GetSystemMetrics(SM_CYEDGE);
2622 cx += GetSystemMetrics(SM_CYEDGE);
2625 infoPtr->bAutoSize = TRUE;
2626 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2627 cx, cy, uPosFlags);
2628 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2629 * the setwindowpos calls */
2630 infoPtr->bAutoSize = FALSE;
2632 return 0;
2636 static LRESULT
2637 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2639 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2641 return infoPtr->nNumButtons;
2645 static LRESULT
2646 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2650 if (infoPtr == NULL) {
2651 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2652 ERR("infoPtr == NULL!\n");
2653 return 0;
2656 infoPtr->dwStructSize = (DWORD)wParam;
2658 return 0;
2662 static LRESULT
2663 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2665 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2666 TBUTTON_INFO *btnPtr;
2667 INT nIndex;
2669 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2670 if (nIndex == -1)
2671 return FALSE;
2673 btnPtr = &infoPtr->buttons[nIndex];
2674 btnPtr->iBitmap = LOWORD(lParam);
2676 /* we HAVE to erase the background, the new bitmap could be */
2677 /* transparent */
2678 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2680 return TRUE;
2684 static LRESULT
2685 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2687 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2688 TBUTTON_INFO *btnPtr;
2689 INT nIndex;
2690 INT nOldIndex = -1;
2691 BOOL bChecked = FALSE;
2693 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2694 if (nIndex == -1)
2695 return FALSE;
2697 btnPtr = &infoPtr->buttons[nIndex];
2699 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2700 return FALSE;
2702 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2704 if (LOWORD(lParam) == FALSE)
2705 btnPtr->fsState &= ~TBSTATE_CHECKED;
2706 else {
2707 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2708 nOldIndex =
2709 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2710 if (nOldIndex == nIndex)
2711 return 0;
2712 if (nOldIndex != -1)
2713 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2715 btnPtr->fsState |= TBSTATE_CHECKED;
2718 if( bChecked != LOWORD(lParam) )
2720 if (nOldIndex != -1)
2722 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2723 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2725 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2728 /* FIXME: Send a WM_NOTIFY?? */
2730 return TRUE;
2734 static LRESULT
2735 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2739 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2743 static LRESULT
2744 TOOLBAR_Customize (HWND hwnd)
2746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2747 CUSTDLG_INFO custInfo;
2748 LRESULT ret;
2749 LPCVOID template;
2750 HRSRC hRes;
2751 NMHDR nmhdr;
2753 custInfo.tbInfo = infoPtr;
2754 custInfo.tbHwnd = hwnd;
2756 /* send TBN_BEGINADJUST notification */
2757 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2758 TBN_BEGINADJUST);
2760 if (!(hRes = FindResourceA (COMCTL32_hModule,
2761 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2762 RT_DIALOGA)))
2763 return FALSE;
2765 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2766 return FALSE;
2768 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2769 (LPDLGTEMPLATEA)template,
2770 hwnd,
2771 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2772 (LPARAM)&custInfo);
2774 /* send TBN_ENDADJUST notification */
2775 TOOLBAR_SendNotify ((NMHDR *) &nmhdr, infoPtr,
2776 TBN_ENDADJUST);
2778 return ret;
2782 static LRESULT
2783 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2785 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2786 INT nIndex = (INT)wParam;
2788 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2789 return FALSE;
2791 if ((infoPtr->hwndToolTip) &&
2792 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2793 TTTOOLINFOA ti;
2795 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2796 ti.cbSize = sizeof (TTTOOLINFOA);
2797 ti.hwnd = hwnd;
2798 ti.uId = infoPtr->buttons[nIndex].idCommand;
2800 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2803 if (infoPtr->nNumButtons == 1) {
2804 TRACE(" simple delete!\n");
2805 COMCTL32_Free (infoPtr->buttons);
2806 infoPtr->buttons = NULL;
2807 infoPtr->nNumButtons = 0;
2809 else {
2810 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2811 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2813 infoPtr->nNumButtons--;
2814 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2815 if (nIndex > 0) {
2816 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2817 nIndex * sizeof(TBUTTON_INFO));
2820 if (nIndex < infoPtr->nNumButtons) {
2821 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2822 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2825 COMCTL32_Free (oldButtons);
2828 TOOLBAR_CalcToolbar (hwnd);
2830 InvalidateRect (hwnd, NULL, TRUE);
2832 return TRUE;
2836 static LRESULT
2837 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2840 TBUTTON_INFO *btnPtr;
2841 INT nIndex;
2842 DWORD bState;
2844 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2845 if (nIndex == -1)
2846 return FALSE;
2848 btnPtr = &infoPtr->buttons[nIndex];
2850 bState = btnPtr->fsState & TBSTATE_ENABLED;
2852 /* update the toolbar button state */
2853 if(LOWORD(lParam) == FALSE) {
2854 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2855 } else {
2856 btnPtr->fsState |= TBSTATE_ENABLED;
2859 /* redraw the button only if the state of the button changed */
2860 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2862 InvalidateRect(hwnd, &btnPtr->rect,
2863 TOOLBAR_HasText(infoPtr, btnPtr));
2866 return TRUE;
2870 static inline LRESULT
2871 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2873 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2875 return infoPtr->bAnchor;
2879 static LRESULT
2880 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2883 INT nIndex;
2885 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
2886 if (nIndex == -1)
2887 return -1;
2889 return infoPtr->buttons[nIndex].iBitmap;
2893 static inline LRESULT
2894 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2896 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2900 static LRESULT
2901 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2903 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2904 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2905 INT nIndex = (INT)wParam;
2906 TBUTTON_INFO *btnPtr;
2908 if (infoPtr == NULL)
2909 return FALSE;
2911 if (lpTbb == NULL)
2912 return FALSE;
2914 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2915 return FALSE;
2917 btnPtr = &infoPtr->buttons[nIndex];
2918 lpTbb->iBitmap = btnPtr->iBitmap;
2919 lpTbb->idCommand = btnPtr->idCommand;
2920 lpTbb->fsState = btnPtr->fsState;
2921 lpTbb->fsStyle = btnPtr->fsStyle;
2922 lpTbb->dwData = btnPtr->dwData;
2923 lpTbb->iString = btnPtr->iString;
2925 return TRUE;
2929 static LRESULT
2930 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2933 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2934 TBUTTON_INFO *btnPtr;
2935 INT nIndex;
2937 if (infoPtr == NULL)
2938 return -1;
2939 if (lpTbInfo == NULL)
2940 return -1;
2941 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2942 return -1;
2944 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2945 lpTbInfo->dwMask & 0x80000000);
2946 if (nIndex == -1)
2947 return -1;
2949 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
2951 if (lpTbInfo->dwMask & TBIF_COMMAND)
2952 lpTbInfo->idCommand = btnPtr->idCommand;
2953 if (lpTbInfo->dwMask & TBIF_IMAGE)
2954 lpTbInfo->iImage = btnPtr->iBitmap;
2955 if (lpTbInfo->dwMask & TBIF_LPARAM)
2956 lpTbInfo->lParam = btnPtr->dwData;
2957 if (lpTbInfo->dwMask & TBIF_SIZE)
2958 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2959 if (lpTbInfo->dwMask & TBIF_STATE)
2960 lpTbInfo->fsState = btnPtr->fsState;
2961 if (lpTbInfo->dwMask & TBIF_STYLE)
2962 lpTbInfo->fsStyle = btnPtr->fsStyle;
2963 if (lpTbInfo->dwMask & TBIF_TEXT) {
2964 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
2965 Str_GetPtrWtoA (lpText, lpTbInfo->pszText,lpTbInfo->cchText);
2967 return nIndex;
2971 static LRESULT
2972 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2974 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2975 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2976 TBUTTON_INFO *btnPtr;
2977 INT nIndex;
2979 if (infoPtr == NULL)
2980 return -1;
2981 if (lpTbInfo == NULL)
2982 return -1;
2983 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2984 return -1;
2986 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
2987 lpTbInfo->dwMask & 0x80000000);
2988 if (nIndex == -1)
2989 return -1;
2991 btnPtr = &infoPtr->buttons[nIndex];
2993 if(!btnPtr)
2994 return -1;
2996 if (lpTbInfo->dwMask & TBIF_COMMAND)
2997 lpTbInfo->idCommand = btnPtr->idCommand;
2998 if (lpTbInfo->dwMask & TBIF_IMAGE)
2999 lpTbInfo->iImage = btnPtr->iBitmap;
3000 if (lpTbInfo->dwMask & TBIF_LPARAM)
3001 lpTbInfo->lParam = btnPtr->dwData;
3002 if (lpTbInfo->dwMask & TBIF_SIZE)
3003 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3004 if (lpTbInfo->dwMask & TBIF_STATE)
3005 lpTbInfo->fsState = btnPtr->fsState;
3006 if (lpTbInfo->dwMask & TBIF_STYLE)
3007 lpTbInfo->fsStyle = btnPtr->fsStyle;
3008 if (lpTbInfo->dwMask & TBIF_TEXT) {
3009 LPWSTR lpText = TOOLBAR_GetText(infoPtr,btnPtr);
3010 Str_GetPtrW (lpText,lpTbInfo->pszText,lpTbInfo->cchText);
3013 return nIndex;
3017 static LRESULT
3018 TOOLBAR_GetButtonSize (HWND hwnd)
3020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3022 if (infoPtr->nNumButtons > 0)
3023 return MAKELONG((WORD)infoPtr->nButtonWidth,
3024 (WORD)infoPtr->nButtonHeight);
3025 else
3026 return MAKELONG(8,7);
3030 static LRESULT
3031 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3033 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3034 INT nIndex;
3035 LPWSTR lpText;
3037 if (lParam == 0)
3038 return -1;
3040 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3041 if (nIndex == -1)
3042 return -1;
3044 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3046 return WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3047 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
3051 static LRESULT
3052 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3055 INT nIndex;
3056 LPWSTR lpText;
3058 if (lParam == 0)
3059 return -1;
3061 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3062 if (nIndex == -1)
3063 return -1;
3065 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3067 strcpyW ((LPWSTR)lParam, lpText);
3069 return strlenW (lpText);
3073 static LRESULT
3074 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3076 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3078 return (LRESULT)infoPtr->himlDis;
3082 inline static LRESULT
3083 TOOLBAR_GetExtendedStyle (HWND hwnd)
3085 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3087 return infoPtr->dwExStyle;
3091 static LRESULT
3092 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3094 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3096 return (LRESULT)infoPtr->himlHot;
3100 static LRESULT
3101 TOOLBAR_GetHotItem (HWND hwnd)
3103 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3105 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
3106 return -1;
3108 if (infoPtr->nHotItem < 0)
3109 return -1;
3111 return (LRESULT)infoPtr->nHotItem;
3115 static LRESULT
3116 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3118 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3120 return (LRESULT)infoPtr->himlDef;
3124 /* << TOOLBAR_GetInsertMark >> */
3125 /* << TOOLBAR_GetInsertMarkColor >> */
3128 static LRESULT
3129 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3131 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3132 TBUTTON_INFO *btnPtr;
3133 LPRECT lpRect;
3134 INT nIndex;
3136 if (infoPtr == NULL)
3137 return FALSE;
3138 nIndex = (INT)wParam;
3139 btnPtr = &infoPtr->buttons[nIndex];
3140 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3141 return FALSE;
3142 lpRect = (LPRECT)lParam;
3143 if (lpRect == NULL)
3144 return FALSE;
3145 if (btnPtr->fsState & TBSTATE_HIDDEN)
3146 return FALSE;
3148 lpRect->left = btnPtr->rect.left;
3149 lpRect->right = btnPtr->rect.right;
3150 lpRect->bottom = btnPtr->rect.bottom;
3151 lpRect->top = btnPtr->rect.top;
3153 return TRUE;
3157 static LRESULT
3158 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3160 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3161 LPSIZE lpSize = (LPSIZE)lParam;
3163 if (lpSize == NULL)
3164 return FALSE;
3166 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3167 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3169 TRACE("maximum size %d x %d\n",
3170 infoPtr->rcBound.right - infoPtr->rcBound.left,
3171 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3173 return TRUE;
3177 /* << TOOLBAR_GetObject >> */
3180 static LRESULT
3181 TOOLBAR_GetPadding (HWND hwnd)
3183 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3184 DWORD oldPad;
3186 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3187 return (LRESULT) oldPad;
3191 static LRESULT
3192 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
3194 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3195 TBUTTON_INFO *btnPtr;
3196 LPRECT lpRect;
3197 INT nIndex;
3199 if (infoPtr == NULL)
3200 return FALSE;
3201 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3202 btnPtr = &infoPtr->buttons[nIndex];
3203 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3204 return FALSE;
3205 lpRect = (LPRECT)lParam;
3206 if (lpRect == NULL)
3207 return FALSE;
3209 lpRect->left = btnPtr->rect.left;
3210 lpRect->right = btnPtr->rect.right;
3211 lpRect->bottom = btnPtr->rect.bottom;
3212 lpRect->top = btnPtr->rect.top;
3214 return TRUE;
3218 static LRESULT
3219 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3221 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3223 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
3224 return infoPtr->nRows;
3225 else
3226 return 1;
3230 static LRESULT
3231 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3234 INT nIndex;
3236 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3237 if (nIndex == -1)
3238 return -1;
3240 return infoPtr->buttons[nIndex].fsState;
3244 static LRESULT
3245 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3247 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3248 INT nIndex;
3250 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3251 if (nIndex == -1)
3252 return -1;
3254 return infoPtr->buttons[nIndex].fsStyle;
3258 static LRESULT
3259 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3261 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3263 if (infoPtr == NULL)
3264 return 0;
3266 return infoPtr->nMaxTextRows;
3270 static LRESULT
3271 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3273 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3275 if (infoPtr == NULL)
3276 return 0;
3277 return (LRESULT)infoPtr->hwndToolTip;
3281 static LRESULT
3282 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3286 TRACE("%s hwnd=0x%x stub!\n",
3287 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
3289 return infoPtr->bUnicode;
3293 inline static LRESULT
3294 TOOLBAR_GetVersion (HWND hwnd)
3296 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3297 return infoPtr->iVersion;
3301 static LRESULT
3302 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3305 TBUTTON_INFO *btnPtr;
3306 INT nIndex;
3308 TRACE("\n");
3310 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3311 if (nIndex == -1)
3312 return FALSE;
3314 btnPtr = &infoPtr->buttons[nIndex];
3315 if (LOWORD(lParam) == FALSE)
3316 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3317 else
3318 btnPtr->fsState |= TBSTATE_HIDDEN;
3320 TOOLBAR_CalcToolbar (hwnd);
3322 InvalidateRect (hwnd, NULL, TRUE);
3324 return TRUE;
3328 inline static LRESULT
3329 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
3331 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
3335 static LRESULT
3336 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3338 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3339 TBUTTON_INFO *btnPtr;
3340 INT nIndex;
3342 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3343 if (nIndex == -1)
3344 return FALSE;
3346 btnPtr = &infoPtr->buttons[nIndex];
3347 if (LOWORD(lParam) == FALSE)
3348 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3349 else
3350 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3352 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3354 return TRUE;
3358 static LRESULT
3359 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3361 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3362 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3363 INT nIndex = (INT)wParam;
3364 TBUTTON_INFO *oldButtons;
3366 if (lpTbb == NULL)
3367 return FALSE;
3369 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3371 if (nIndex == -1) {
3372 /* EPP: this seems to be an undocumented call (from my IE4)
3373 * I assume in that case that:
3374 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3375 * - index of insertion is at the end of existing buttons
3376 * I only see this happen with nIndex == -1, but it could have a special
3377 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3379 nIndex = infoPtr->nNumButtons;
3381 } else if (nIndex < 0)
3382 return FALSE;
3384 /* If the string passed is not an index, assume address of string
3385 and do our own AddString */
3386 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3387 LPSTR ptr;
3388 INT len;
3390 TRACE("string %s passed instead of index, adding string\n",
3391 debugstr_a((LPSTR)lpTbb->iString));
3392 len = strlen((LPSTR)lpTbb->iString) + 2;
3393 ptr = COMCTL32_Alloc(len);
3394 strcpy(ptr, (LPSTR)lpTbb->iString);
3395 ptr[len - 1] = 0; /* ended by two '\0' */
3396 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
3397 COMCTL32_Free(ptr);
3400 TRACE("inserting button index=%d\n", nIndex);
3401 if (nIndex > infoPtr->nNumButtons) {
3402 nIndex = infoPtr->nNumButtons;
3403 TRACE("adjust index=%d\n", nIndex);
3406 oldButtons = infoPtr->buttons;
3407 infoPtr->nNumButtons++;
3408 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3409 /* pre insert copy */
3410 if (nIndex > 0) {
3411 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3412 nIndex * sizeof(TBUTTON_INFO));
3415 /* insert new button */
3416 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3417 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3418 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3419 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3420 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3421 /* if passed string and not index, then add string */
3422 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3423 Str_SetPtrAtoW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPCSTR )lpTbb->iString);
3425 else
3426 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3428 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3429 TTTOOLINFOA ti;
3431 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
3432 ti.cbSize = sizeof (TTTOOLINFOA);
3433 ti.hwnd = hwnd;
3434 ti.uId = lpTbb->idCommand;
3435 ti.hinst = 0;
3436 ti.lpszText = LPSTR_TEXTCALLBACKA;
3438 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
3439 0, (LPARAM)&ti);
3442 /* post insert copy */
3443 if (nIndex < infoPtr->nNumButtons - 1) {
3444 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3445 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3448 COMCTL32_Free (oldButtons);
3450 TOOLBAR_CalcToolbar (hwnd);
3452 InvalidateRect (hwnd, NULL, TRUE);
3454 return TRUE;
3458 static LRESULT
3459 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3461 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3462 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
3463 INT nIndex = (INT)wParam;
3464 TBUTTON_INFO *oldButtons;
3466 if (lpTbb == NULL)
3467 return FALSE;
3469 TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
3471 if (nIndex == -1) {
3472 /* EPP: this seems to be an undocumented call (from my IE4)
3473 * I assume in that case that:
3474 * - lpTbb->iString is a string pointer (not a string index in strings[] table
3475 * - index of insertion is at the end of existing buttons
3476 * I only see this happen with nIndex == -1, but it could have a special
3477 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3479 nIndex = infoPtr->nNumButtons;
3481 } else if (nIndex < 0)
3482 return FALSE;
3484 /* If the string passed is not an index, assume address of string
3485 and do our own AddString */
3486 if ((HIWORD(lpTbb->iString) != 0) && (lpTbb->iString != -1)) {
3487 LPWSTR ptr;
3488 INT len;
3490 TRACE("string %s passed instead of index, adding string\n",
3491 debugstr_w((LPWSTR)lpTbb->iString));
3492 len = strlenW((LPWSTR)lpTbb->iString) + 2;
3493 ptr = COMCTL32_Alloc(len*sizeof(WCHAR));
3494 strcpyW(ptr, (LPWSTR)lpTbb->iString);
3495 ptr[len - 1] = 0; /* ended by two '\0' */
3496 lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
3497 COMCTL32_Free(ptr);
3500 TRACE("inserting button index=%d\n", nIndex);
3501 if (nIndex > infoPtr->nNumButtons) {
3502 nIndex = infoPtr->nNumButtons;
3503 TRACE("adjust index=%d\n", nIndex);
3506 oldButtons = infoPtr->buttons;
3507 infoPtr->nNumButtons++;
3508 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3509 /* pre insert copy */
3510 if (nIndex > 0) {
3511 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3512 nIndex * sizeof(TBUTTON_INFO));
3515 /* insert new button */
3516 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
3517 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
3518 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
3519 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
3520 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
3521 /* if passed string and not index, then add string */
3522 if(HIWORD(lpTbb->iString) && lpTbb->iString!=-1) {
3523 Str_SetPtrW ((LPWSTR *)&infoPtr->buttons[nIndex].iString, (LPWSTR)lpTbb->iString);
3525 else
3526 infoPtr->buttons[nIndex].iString = lpTbb->iString;
3528 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
3529 TTTOOLINFOW ti;
3531 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
3532 ti.cbSize = sizeof (TTTOOLINFOW);
3533 ti.hwnd = hwnd;
3534 ti.uId = lpTbb->idCommand;
3535 ti.hinst = 0;
3536 ti.lpszText = LPSTR_TEXTCALLBACKW;
3538 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
3539 0, (LPARAM)&ti);
3542 /* post insert copy */
3543 if (nIndex < infoPtr->nNumButtons - 1) {
3544 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
3545 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
3548 COMCTL32_Free (oldButtons);
3550 TOOLBAR_CalcToolbar (hwnd);
3552 InvalidateRect (hwnd, NULL, TRUE);
3554 return TRUE;
3558 /* << TOOLBAR_InsertMarkHitTest >> */
3561 static LRESULT
3562 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
3564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3565 INT nIndex;
3567 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3568 if (nIndex == -1)
3569 return FALSE;
3571 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3575 static LRESULT
3576 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
3578 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3579 INT nIndex;
3581 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3582 if (nIndex == -1)
3583 return FALSE;
3585 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3589 static LRESULT
3590 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
3592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3593 INT nIndex;
3595 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3596 if (nIndex == -1)
3597 return TRUE;
3599 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3603 static LRESULT
3604 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
3606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3607 INT nIndex;
3609 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3610 if (nIndex == -1)
3611 return FALSE;
3613 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3617 static LRESULT
3618 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3621 INT nIndex;
3623 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3624 if (nIndex == -1)
3625 return FALSE;
3627 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3631 static LRESULT
3632 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3635 INT nIndex;
3637 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3638 if (nIndex == -1)
3639 return FALSE;
3641 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3645 /* << TOOLBAR_LoadImages >> */
3646 /* << TOOLBAR_MapAccelerator >> */
3647 /* << TOOLBAR_MarkButton >> */
3648 /* << TOOLBAR_MoveButton >> */
3651 static LRESULT
3652 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3655 TBUTTON_INFO *btnPtr;
3656 INT nIndex;
3658 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
3659 if (nIndex == -1)
3660 return FALSE;
3662 btnPtr = &infoPtr->buttons[nIndex];
3663 if (LOWORD(lParam) == FALSE)
3664 btnPtr->fsState &= ~TBSTATE_PRESSED;
3665 else
3666 btnPtr->fsState |= TBSTATE_PRESSED;
3668 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3670 return TRUE;
3674 static LRESULT
3675 TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
3677 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3678 LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
3679 HBITMAP hBitmap;
3680 int i = 0, nOldButtons = 0, pos = 0;
3682 TRACE("hInstOld %x nIDOld %x hInstNew %x nIDNew %x nButtons %x\n",
3683 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3684 lpReplace->nButtons);
3686 if (lpReplace->hInstOld == -1)
3688 FIXME("changing standard bitmaps not implemented\n");
3689 return FALSE;
3691 else if (lpReplace->hInstOld != 0)
3693 FIXME("resources not in the current module not implemented\n");
3694 return FALSE;
3696 else
3698 hBitmap = (HBITMAP) lpReplace->nIDNew;
3701 TRACE("To be replaced hInstOld %x nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3702 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3703 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3704 TRACE("tbimapinfo %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3705 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
3707 TRACE("Found: nButtons %d hInst %x nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
3708 nOldButtons = tbi->nButtons;
3709 tbi->nButtons = lpReplace->nButtons;
3710 tbi->hInst = lpReplace->hInstNew;
3711 tbi->nID = lpReplace->nIDNew;
3712 TRACE("tbimapinfo changed %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
3713 break;
3715 pos += tbi->nButtons;
3718 if (nOldButtons == 0)
3720 WARN("No hinst/bitmap found! hInst %x nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
3721 return FALSE;
3724 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
3726 /* ImageList_Replace(infoPtr->himlDef, pos, hBitmap, NULL); */
3729 for (i = pos + nOldButtons - 1; i >= pos; i--) {
3730 ImageList_Remove(infoPtr->himlDef, i);
3733 ImageList_AddMasked(infoPtr->himlDef, hBitmap, CLR_DEFAULT);
3735 InvalidateRect(hwnd, NULL, FALSE);
3737 return TRUE;
3740 static LRESULT
3741 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3743 #if 0
3744 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3745 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3747 if (lpSave == NULL) return 0;
3749 if ((BOOL)wParam) {
3750 /* save toolbar information */
3751 FIXME("save to \"%s\" \"%s\"\n",
3752 lpSave->pszSubKey, lpSave->pszValueName);
3756 else {
3757 /* restore toolbar information */
3759 FIXME("restore from \"%s\" \"%s\"\n",
3760 lpSave->pszSubKey, lpSave->pszValueName);
3764 #endif
3766 return 0;
3770 static LRESULT
3771 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3773 #if 0
3774 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3775 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3777 if (lpSave == NULL)
3778 return 0;
3780 if ((BOOL)wParam) {
3781 /* save toolbar information */
3782 FIXME("save to \"%s\" \"%s\"\n",
3783 lpSave->pszSubKey, lpSave->pszValueName);
3787 else {
3788 /* restore toolbar information */
3790 FIXME("restore from \"%s\" \"%s\"\n",
3791 lpSave->pszSubKey, lpSave->pszValueName);
3795 #endif
3797 return 0;
3801 static LRESULT
3802 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3804 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3805 BOOL bOldAnchor = infoPtr->bAnchor;
3807 infoPtr->bAnchor = (BOOL)wParam;
3809 return (LRESULT)bOldAnchor;
3813 static LRESULT
3814 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3816 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3818 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3819 return FALSE;
3821 if (infoPtr->nNumButtons > 0)
3822 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3823 infoPtr->nNumButtons,
3824 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3825 LOWORD(lParam), HIWORD(lParam));
3827 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3828 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3830 /* uses image list internals directly */
3831 if (infoPtr->himlDef) {
3832 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3833 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3836 return TRUE;
3840 static LRESULT
3841 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3843 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3844 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3845 TBUTTON_INFO *btnPtr;
3846 INT nIndex;
3848 if (lptbbi == NULL)
3849 return FALSE;
3850 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3851 return FALSE;
3853 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3854 lptbbi->dwMask & 0x80000000);
3855 if (nIndex == -1)
3856 return FALSE;
3858 btnPtr = &infoPtr->buttons[nIndex];
3859 if (lptbbi->dwMask & TBIF_COMMAND)
3860 btnPtr->idCommand = lptbbi->idCommand;
3861 if (lptbbi->dwMask & TBIF_IMAGE)
3862 btnPtr->iBitmap = lptbbi->iImage;
3863 if (lptbbi->dwMask & TBIF_LPARAM)
3864 btnPtr->dwData = lptbbi->lParam;
3865 /* if (lptbbi->dwMask & TBIF_SIZE) */
3866 /* btnPtr->cx = lptbbi->cx; */
3867 if (lptbbi->dwMask & TBIF_STATE)
3868 btnPtr->fsState = lptbbi->fsState;
3869 if (lptbbi->dwMask & TBIF_STYLE)
3870 btnPtr->fsStyle = lptbbi->fsStyle;
3872 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3873 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3874 /* iString is index, zero it to make Str_SetPtr succeed */
3875 btnPtr->iString=0;
3877 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3879 return TRUE;
3883 static LRESULT
3884 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3886 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3887 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3888 TBUTTON_INFO *btnPtr;
3889 INT nIndex;
3891 if (lptbbi == NULL)
3892 return FALSE;
3893 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3894 return FALSE;
3896 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam,
3897 lptbbi->dwMask & 0x80000000);
3898 if (nIndex == -1)
3899 return FALSE;
3901 btnPtr = &infoPtr->buttons[nIndex];
3902 if (lptbbi->dwMask & TBIF_COMMAND)
3903 btnPtr->idCommand = lptbbi->idCommand;
3904 if (lptbbi->dwMask & TBIF_IMAGE)
3905 btnPtr->iBitmap = lptbbi->iImage;
3906 if (lptbbi->dwMask & TBIF_LPARAM)
3907 btnPtr->dwData = lptbbi->lParam;
3908 /* if (lptbbi->dwMask & TBIF_SIZE) */
3909 /* btnPtr->cx = lptbbi->cx; */
3910 if (lptbbi->dwMask & TBIF_STATE)
3911 btnPtr->fsState = lptbbi->fsState;
3912 if (lptbbi->dwMask & TBIF_STYLE)
3913 btnPtr->fsStyle = lptbbi->fsStyle;
3915 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT)lptbbi->pszText != -1)) {
3916 if ((HIWORD(btnPtr->iString) == 0) || (btnPtr->iString == -1))
3917 /* iString is index, zero it to make Str_SetPtr succeed */
3918 btnPtr->iString=0;
3919 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
3921 return TRUE;
3925 static LRESULT
3926 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3928 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3929 INT cx = LOWORD(lParam), cy = HIWORD(lParam);
3931 if ((cx < 0) || (cy < 0))
3933 ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
3934 return FALSE;
3937 /* The documentation claims you can only change the button size before
3938 * any button has been added. But this is wrong.
3939 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3940 * it to the toolbar, and it checks that the return value is nonzero - mjm
3941 * Further testing shows that we must actually perform the change too.
3944 * The documentation also does not mention that if 0 is supplied for
3945 * either size, the system changes it to the default of 24 wide and
3946 * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
3948 infoPtr->nButtonWidth = (cx) ? cx : 24;
3949 infoPtr->nButtonHeight = (cy) ? cy : 22;
3950 return TRUE;
3954 static LRESULT
3955 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3957 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3959 if (infoPtr == NULL) {
3960 TRACE("Toolbar not initialized yet?????\n");
3961 return FALSE;
3964 /* if setting to current values, ignore */
3965 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3966 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3967 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3968 infoPtr->cxMin, infoPtr->cxMax);
3969 return TRUE;
3972 /* save new values */
3973 infoPtr->cxMin = (INT)LOWORD(lParam);
3974 infoPtr->cxMax = (INT)HIWORD(lParam);
3976 /* if both values are 0 then we are done */
3977 if (lParam == 0) {
3978 TRACE("setting both min and max to 0, norecalc\n");
3979 return TRUE;
3982 /* otherwise we need to recalc the toolbar and in some cases
3983 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3984 which doesn't actually draw - GA). */
3985 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3986 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3988 TOOLBAR_CalcToolbar (hwnd);
3990 InvalidateRect (hwnd, NULL, TRUE);
3992 return TRUE;
3996 static LRESULT
3997 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3999 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4000 INT nIndex = (INT)wParam;
4002 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4003 return FALSE;
4005 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
4007 if (infoPtr->hwndToolTip) {
4009 FIXME("change tool tip!\n");
4013 return TRUE;
4017 static LRESULT
4018 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4020 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4021 HIMAGELIST himlTemp;
4024 if (wParam != 0) {
4025 FIXME("no support for multiple image lists\n");
4026 return 0;
4029 himlTemp = infoPtr->himlDis;
4030 infoPtr->himlDis = (HIMAGELIST)lParam;
4032 /* FIXME: redraw ? */
4034 return (LRESULT)himlTemp;
4038 static LRESULT
4039 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
4041 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4042 DWORD dwTemp;
4044 dwTemp = infoPtr->dwDTFlags;
4045 infoPtr->dwDTFlags =
4046 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4048 return (LRESULT)dwTemp;
4051 static LRESULT
4052 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4055 DWORD dwTemp;
4057 dwTemp = infoPtr->dwExStyle;
4058 infoPtr->dwExStyle = (DWORD)lParam;
4060 if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
4061 TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
4062 FIXME("Extended style not implemented %s %s\n",
4063 (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
4064 "TBSTYLE_EX_MIXEDBUTTONS" : "",
4065 (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
4066 "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
4069 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4070 FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
4071 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4073 return (LRESULT)dwTemp;
4077 static LRESULT
4078 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4081 HIMAGELIST himlTemp;
4083 if (wParam != 0) {
4084 FIXME("no support for multiple image lists\n");
4085 return 0;
4088 himlTemp = infoPtr->himlHot;
4089 infoPtr->himlHot = (HIMAGELIST)lParam;
4091 /* FIXME: redraw ? */
4093 return (LRESULT)himlTemp;
4097 static LRESULT
4098 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
4100 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4101 INT nOldHotItem = infoPtr->nHotItem;
4102 TBUTTON_INFO *btnPtr;
4104 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4105 wParam = -2;
4107 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
4110 infoPtr->nHotItem = (INT)wParam;
4111 if ((INT)wParam >=0)
4113 btnPtr = &infoPtr->buttons[(INT)wParam];
4114 btnPtr->bHot = TRUE;
4115 InvalidateRect (hwnd, &btnPtr->rect,
4116 TOOLBAR_HasText(infoPtr, btnPtr));
4118 if (nOldHotItem>=0)
4120 btnPtr = &infoPtr->buttons[nOldHotItem];
4121 btnPtr->bHot = FALSE;
4122 InvalidateRect (hwnd, &btnPtr->rect,
4123 TOOLBAR_HasText(infoPtr, btnPtr));
4127 if (nOldHotItem < 0)
4128 return -1;
4130 return (LRESULT)nOldHotItem;
4134 static LRESULT
4135 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
4137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4138 HIMAGELIST himlTemp;
4140 if (wParam != 0) {
4141 FIXME("no support for multiple image lists\n");
4142 return 0;
4145 himlTemp = infoPtr->himlDef;
4146 infoPtr->himlDef = (HIMAGELIST)lParam;
4148 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
4150 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth,
4151 &infoPtr->nBitmapHeight);
4152 TRACE("hwnd %08x, new himl=%08x, count=%d, bitmap w=%d, h=%d\n",
4153 hwnd, (INT)infoPtr->himlDef, infoPtr->nNumBitmaps,
4154 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4156 /* FIXME: redraw ? */
4157 InvalidateRect(hwnd, NULL, TRUE);
4159 return (LRESULT)himlTemp;
4163 static LRESULT
4164 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4166 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4168 infoPtr->nIndent = (INT)wParam;
4170 TRACE("\n");
4172 /* process only on indent changing */
4173 if(infoPtr->nIndent != (INT)wParam)
4175 infoPtr->nIndent = (INT)wParam;
4176 TOOLBAR_CalcToolbar (hwnd);
4177 InvalidateRect(hwnd, NULL, FALSE);
4180 return TRUE;
4184 /* << TOOLBAR_SetInsertMark >> */
4187 static LRESULT
4188 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
4190 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4192 infoPtr->clrInsertMark = (COLORREF)lParam;
4194 /* FIXME : redraw ??*/
4196 return 0;
4200 static LRESULT
4201 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4203 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4205 if (infoPtr == NULL)
4206 return FALSE;
4208 infoPtr->nMaxTextRows = (INT)wParam;
4210 return TRUE;
4214 static LRESULT
4215 TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
4217 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4218 DWORD oldPad;
4220 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4221 infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
4222 infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
4223 FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
4224 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4225 return (LRESULT) oldPad;
4229 static LRESULT
4230 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
4232 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4233 HWND hwndOldNotify;
4235 TRACE("\n");
4237 if (infoPtr == NULL)
4238 return 0;
4239 hwndOldNotify = infoPtr->hwndNotify;
4240 infoPtr->hwndNotify = (HWND)wParam;
4242 return (LRESULT)hwndOldNotify;
4246 static LRESULT
4247 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
4249 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4250 LPRECT lprc = (LPRECT)lParam;
4252 TRACE("\n");
4254 if (LOWORD(wParam) > 1) {
4255 FIXME("multiple rows not supported!\n");
4258 if(infoPtr->nRows != LOWORD(wParam))
4260 infoPtr->nRows = LOWORD(wParam);
4262 /* recalculate toolbar */
4263 TOOLBAR_CalcToolbar (hwnd);
4265 /* repaint toolbar */
4266 InvalidateRect(hwnd, NULL, FALSE);
4269 /* return bounding rectangle */
4270 if (lprc) {
4271 lprc->left = infoPtr->rcBound.left;
4272 lprc->right = infoPtr->rcBound.right;
4273 lprc->top = infoPtr->rcBound.top;
4274 lprc->bottom = infoPtr->rcBound.bottom;
4277 return 0;
4281 static LRESULT
4282 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
4284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4285 TBUTTON_INFO *btnPtr;
4286 INT nIndex;
4288 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4289 if (nIndex == -1)
4290 return FALSE;
4292 btnPtr = &infoPtr->buttons[nIndex];
4294 /* if hidden state has changed the invalidate entire window and recalc */
4295 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4296 btnPtr->fsState = LOWORD(lParam);
4297 TOOLBAR_CalcToolbar (hwnd);
4298 InvalidateRect(hwnd, 0, TOOLBAR_HasText(infoPtr, btnPtr));
4299 return TRUE;
4302 /* process state changing if current state doesn't match new state */
4303 if(btnPtr->fsState != LOWORD(lParam))
4305 btnPtr->fsState = LOWORD(lParam);
4306 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4307 btnPtr));
4310 return TRUE;
4314 static LRESULT
4315 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
4317 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4318 TBUTTON_INFO *btnPtr;
4319 INT nIndex;
4321 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam, FALSE);
4322 if (nIndex == -1)
4323 return FALSE;
4325 btnPtr = &infoPtr->buttons[nIndex];
4327 /* process style change if current style doesn't match new style */
4328 if(btnPtr->fsStyle != LOWORD(lParam))
4330 btnPtr->fsStyle = LOWORD(lParam);
4331 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4332 btnPtr));
4334 if (infoPtr->hwndToolTip) {
4335 FIXME("change tool tip!\n");
4339 return TRUE;
4343 inline static LRESULT
4344 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
4346 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4348 if (infoPtr == NULL)
4349 return 0;
4350 infoPtr->hwndToolTip = (HWND)wParam;
4351 return 0;
4355 static LRESULT
4356 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
4358 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4359 BOOL bTemp;
4361 TRACE("%s hwnd=0x%04x stub!\n",
4362 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
4364 bTemp = infoPtr->bUnicode;
4365 infoPtr->bUnicode = (BOOL)wParam;
4367 return bTemp;
4371 static LRESULT
4372 TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4374 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4376 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4377 comctl32_color.clrBtnHighlight :
4378 infoPtr->clrBtnHighlight;
4379 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4380 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4381 return 1;
4385 static LRESULT
4386 TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
4388 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4390 TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
4391 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4392 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4394 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4395 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4396 InvalidateRect(hwnd, 0, 0);
4397 return 0;
4401 static LRESULT
4402 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
4404 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4405 INT iOldVersion = infoPtr->iVersion;
4407 infoPtr->iVersion = iVersion;
4409 return iOldVersion;
4413 /*********************************************************************/
4414 /* */
4415 /* This is undocumented and appears to be a "Super" TB_SETHOTITEM */
4416 /* without the restriction of TBSTYLE_FLAT. This implementation is */
4417 /* based on relay traces of the native control and IE 5.5 */
4418 /* */
4419 /*********************************************************************/
4420 static LRESULT
4421 TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
4423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4424 INT nOldHotItem = infoPtr->nHotItem;
4425 TBUTTON_INFO *btnPtr;
4426 INT no_hi = 0;
4427 NMTBHOTITEM nmhotitem;
4429 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
4430 wParam = -2;
4432 infoPtr->nHotItem = (INT)wParam;
4433 if (nOldHotItem != infoPtr->nHotItem) {
4434 nmhotitem.dwFlags = (DWORD)lParam;
4435 if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
4436 nmhotitem.idOld = (nOldHotItem >= 0) ?
4437 infoPtr->buttons[nOldHotItem].idCommand : 0;
4438 if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
4439 nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
4440 infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
4441 no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
4443 if ((INT)wParam >=0) {
4444 btnPtr = &infoPtr->buttons[(INT)wParam];
4445 btnPtr->bHot = (no_hi) ? FALSE : TRUE;
4446 InvalidateRect (hwnd, &btnPtr->rect,
4447 TOOLBAR_HasText(infoPtr, btnPtr));
4449 if (nOldHotItem>=0) {
4450 btnPtr = &infoPtr->buttons[nOldHotItem];
4451 btnPtr->bHot = FALSE;
4452 InvalidateRect (hwnd, &btnPtr->rect,
4453 TOOLBAR_HasText(infoPtr, btnPtr));
4455 GetFocus();
4456 TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
4457 nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
4459 if (nOldHotItem < 0)
4460 return -1;
4462 return (LRESULT)nOldHotItem;
4466 static LRESULT
4467 TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
4469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4470 LPSIZE lpsize = (LPSIZE)lParam;
4472 if (lpsize == NULL)
4473 return FALSE;
4476 * Testing shows the following:
4477 * wParam = 0 adjust cx value
4478 * = 1 set cy value to max size.
4479 * lParam pointer to SIZE structure
4482 TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
4483 wParam, lParam, lpsize->cx, lpsize->cy);
4485 switch(wParam) {
4486 case 0:
4487 if (lpsize->cx == -1) {
4488 /* **** this is wrong, native measures each button and sets it */
4489 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4491 else if(HIWORD(lpsize->cx)) {
4492 RECT rc;
4493 HWND hwndParent = GetParent(hwnd);
4495 InvalidateRect(hwnd, 0, 1);
4496 GetWindowRect(hwnd, &rc);
4497 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
4498 TRACE("mapped to (%d,%d)-(%d,%d)\n",
4499 rc.left, rc.top, rc.right, rc.bottom);
4500 lpsize->cx = max(rc.right-rc.left,
4501 infoPtr->rcBound.right - infoPtr->rcBound.left);
4503 else {
4504 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
4506 break;
4507 case 1:
4508 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
4509 /* lpsize->cy = infoPtr->nHeight; */
4510 break;
4511 default:
4512 ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
4513 wParam);
4514 return 0;
4516 TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
4517 lpsize->cx, lpsize->cy);
4518 return 1;
4522 static LRESULT
4523 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
4525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4526 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4527 LOGFONTA logFont;
4529 /* initialize info structure */
4530 infoPtr->nButtonHeight = 22;
4531 infoPtr->nButtonWidth = 24;
4532 infoPtr->nBitmapHeight = 15;
4533 infoPtr->nBitmapWidth = 16;
4535 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
4536 infoPtr->nRows = 1;
4537 infoPtr->nMaxTextRows = 1;
4538 infoPtr->cxMin = -1;
4539 infoPtr->cxMax = -1;
4540 infoPtr->nNumBitmaps = 0;
4541 infoPtr->nNumStrings = 0;
4543 infoPtr->bCaptured = FALSE;
4544 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4545 infoPtr->nButtonDown = -1;
4546 infoPtr->nOldHit = -1;
4547 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4548 infoPtr->hwndNotify = GetParent (hwnd);
4549 infoPtr->bTransparent = (dwStyle & TBSTYLE_TRANSPARENT);
4550 infoPtr->bBtnTranspnt = (dwStyle & (TBSTYLE_FLAT | TBSTYLE_LIST));
4551 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
4552 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
4553 infoPtr->iVersion = 0;
4554 infoPtr->hwndSelf = hwnd;
4555 infoPtr->bDoRedraw = TRUE;
4556 infoPtr->clrBtnHighlight = CLR_DEFAULT;
4557 infoPtr->clrBtnShadow = CLR_DEFAULT;
4558 infoPtr->szPadding.cx = 7;
4559 infoPtr->szPadding.cy = 6;
4560 TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
4562 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
4563 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectA (&logFont);
4565 if (dwStyle & TBSTYLE_TOOLTIPS) {
4566 /* Create tooltip control */
4567 infoPtr->hwndToolTip =
4568 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
4569 CW_USEDEFAULT, CW_USEDEFAULT,
4570 CW_USEDEFAULT, CW_USEDEFAULT,
4571 hwnd, 0, 0, 0);
4573 /* Send NM_TOOLTIPSCREATED notification */
4574 if (infoPtr->hwndToolTip) {
4575 NMTOOLTIPSCREATED nmttc;
4577 nmttc.hwndToolTips = infoPtr->hwndToolTip;
4579 TOOLBAR_SendNotify ((NMHDR *) &nmttc, infoPtr,
4580 NM_TOOLTIPSCREATED);
4584 TOOLBAR_CheckStyle (hwnd, dwStyle);
4586 TOOLBAR_CalcToolbar(hwnd);
4588 return 0;
4592 static LRESULT
4593 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
4595 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4597 /* delete tooltip control */
4598 if (infoPtr->hwndToolTip)
4599 DestroyWindow (infoPtr->hwndToolTip);
4601 /* delete button data */
4602 if (infoPtr->buttons)
4603 COMCTL32_Free (infoPtr->buttons);
4605 /* delete strings */
4606 if (infoPtr->strings) {
4607 INT i;
4608 for (i = 0; i < infoPtr->nNumStrings; i++)
4609 if (infoPtr->strings[i])
4610 COMCTL32_Free (infoPtr->strings[i]);
4612 COMCTL32_Free (infoPtr->strings);
4615 /* destroy internal image list */
4616 if (infoPtr->himlInt)
4617 ImageList_Destroy (infoPtr->himlInt);
4619 /* delete default font */
4620 if (infoPtr->hFont)
4621 DeleteObject (infoPtr->hDefaultFont);
4623 /* free toolbar info data */
4624 COMCTL32_Free (infoPtr);
4625 SetWindowLongA (hwnd, 0, 0);
4627 return 0;
4631 static LRESULT
4632 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
4634 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4635 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4636 NMTBCUSTOMDRAW tbcd;
4637 INT ret = FALSE;
4638 DWORD ntfret;
4640 if (dwStyle & TBSTYLE_CUSTOMERASE) {
4641 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4642 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
4643 tbcd.nmcd.hdc = (HDC)wParam;
4644 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4645 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4647 /* FIXME: in general the return flags *can* be or'ed together */
4648 switch (infoPtr->dwBaseCustDraw)
4650 case CDRF_DODEFAULT:
4651 break;
4652 case CDRF_SKIPDEFAULT:
4653 return TRUE;
4654 default:
4655 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4656 hwnd, ntfret);
4660 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
4661 * to my parent for processing.
4663 if (infoPtr->bTransparent) {
4664 POINT pt, ptorig;
4665 HDC hdc = (HDC)wParam;
4666 HWND parent;
4668 pt.x = 0;
4669 pt.y = 0;
4670 parent = GetParent(hwnd);
4671 MapWindowPoints(hwnd, parent, &pt, 1);
4672 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
4673 ret = SendMessageA (parent, WM_ERASEBKGND, wParam, lParam);
4674 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
4676 if (!ret)
4677 ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
4679 if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
4680 (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
4681 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
4682 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
4683 tbcd.nmcd.hdc = (HDC)wParam;
4684 ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
4685 infoPtr->dwBaseCustDraw = ntfret & 0xffff;
4686 switch (infoPtr->dwBaseCustDraw)
4688 case CDRF_DODEFAULT:
4689 break;
4690 case CDRF_SKIPDEFAULT:
4691 return TRUE;
4692 default:
4693 FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
4694 hwnd, ntfret);
4697 return ret;
4701 static LRESULT
4702 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
4704 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4706 return infoPtr->hFont;
4710 static LRESULT
4711 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
4713 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4714 TBUTTON_INFO *btnPtr;
4715 POINT pt;
4716 INT nHit;
4718 pt.x = (INT)LOWORD(lParam);
4719 pt.y = (INT)HIWORD(lParam);
4720 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4722 if (nHit >= 0) {
4723 btnPtr = &infoPtr->buttons[nHit];
4724 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4725 return 0;
4726 SetCapture (hwnd);
4727 infoPtr->bCaptured = TRUE;
4728 infoPtr->nButtonDown = nHit;
4730 btnPtr->fsState |= TBSTATE_PRESSED;
4732 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4733 btnPtr));
4735 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
4736 TOOLBAR_Customize (hwnd);
4738 return 0;
4742 static LRESULT
4743 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
4745 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4746 TBUTTON_INFO *btnPtr;
4747 POINT pt;
4748 INT nHit;
4749 NMTOOLBARA nmtb;
4751 if (infoPtr->hwndToolTip)
4752 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4753 WM_LBUTTONDOWN, wParam, lParam);
4755 pt.x = (INT)LOWORD(lParam);
4756 pt.y = (INT)HIWORD(lParam);
4757 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4759 if (nHit >= 0) {
4760 RECT arrowRect;
4761 btnPtr = &infoPtr->buttons[nHit];
4762 if (!(btnPtr->fsState & TBSTATE_ENABLED))
4763 return 0;
4765 infoPtr->nOldHit = nHit;
4767 CopyRect(&arrowRect, &btnPtr->rect);
4768 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
4770 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
4771 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
4772 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
4773 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
4775 LRESULT res;
4777 * this time we must force a Redraw, so the btn is
4778 * painted down before CaptureChanged repaints it up
4780 RedrawWindow(hwnd,&btnPtr->rect,0,
4781 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
4783 nmtb.iItem = btnPtr->idCommand;
4784 memset(&nmtb.tbButton, 0, sizeof(TBBUTTON));
4785 nmtb.cchText = 0;
4786 nmtb.pszText = 0;
4787 memset(&nmtb.rcButton, 0, sizeof(RECT));
4788 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4789 TBN_DROPDOWN);
4790 if (res != TBDDRET_TREATPRESSED)
4791 /* ??? guess (GA) */
4792 return 0;
4793 /* otherwise drop through and process as pushed */
4795 /* SetCapture (hwnd); */
4796 infoPtr->bCaptured = TRUE;
4797 infoPtr->nButtonDown = nHit;
4799 btnPtr->fsState |= TBSTATE_PRESSED;
4800 btnPtr->bHot = FALSE;
4802 InvalidateRect(hwnd, &btnPtr->rect,
4803 TOOLBAR_HasText(infoPtr, btnPtr));
4804 UpdateWindow(hwnd);
4805 SetCapture (hwnd);
4807 /* native issues the TBN_BEGINDRAG here */
4808 nmtb.iItem = btnPtr->idCommand;
4809 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4810 nmtb.tbButton.idCommand = btnPtr->idCommand;
4811 nmtb.tbButton.fsState = btnPtr->fsState;
4812 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4813 nmtb.tbButton.dwData = btnPtr->dwData;
4814 nmtb.tbButton.iString = btnPtr->iString;
4815 nmtb.cchText = 0; /* !!! not correct */
4816 nmtb.pszText = 0; /* !!! not correct */
4817 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4818 TBN_BEGINDRAG);
4821 return 0;
4824 static LRESULT
4825 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
4827 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4828 TBUTTON_INFO *btnPtr;
4829 POINT pt;
4830 INT nHit;
4831 INT nOldIndex = -1;
4832 BOOL bSendMessage = TRUE;
4833 NMHDR hdr;
4834 NMMOUSE nmmouse;
4835 NMTOOLBARA nmtb;
4837 if (infoPtr->hwndToolTip)
4838 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4839 WM_LBUTTONUP, wParam, lParam);
4841 pt.x = (INT)LOWORD(lParam);
4842 pt.y = (INT)HIWORD(lParam);
4843 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4845 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
4846 /* if the cursor is still inside of the toolbar */
4847 if((infoPtr->nHotItem >= 0) && (nHit != -1))
4848 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
4850 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4851 btnPtr->fsState &= ~TBSTATE_PRESSED;
4853 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
4854 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
4855 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
4856 nHit);
4857 if (nOldIndex == nHit)
4858 bSendMessage = FALSE;
4859 if ((nOldIndex != nHit) &&
4860 (nOldIndex != -1))
4861 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
4862 btnPtr->fsState |= TBSTATE_CHECKED;
4864 else {
4865 if (btnPtr->fsState & TBSTATE_CHECKED)
4866 btnPtr->fsState &= ~TBSTATE_CHECKED;
4867 else
4868 btnPtr->fsState |= TBSTATE_CHECKED;
4872 if (nOldIndex != -1)
4874 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
4875 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
4879 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
4880 * that resets bCaptured and btn TBSTATE_PRESSED flags,
4881 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
4883 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
4884 ReleaseCapture ();
4886 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
4887 TOOLBAR_SendNotify ((NMHDR *) &hdr, infoPtr,
4888 NM_RELEASEDCAPTURE);
4890 /* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
4891 * TBN_BEGINDRAG
4893 nmtb.iItem = btnPtr->idCommand;
4894 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
4895 nmtb.tbButton.idCommand = btnPtr->idCommand;
4896 nmtb.tbButton.fsState = btnPtr->fsState;
4897 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
4898 nmtb.tbButton.dwData = btnPtr->dwData;
4899 nmtb.tbButton.iString = btnPtr->iString;
4900 nmtb.cchText = 0; /* !!! not correct */
4901 nmtb.pszText = 0; /* !!! not correct */
4902 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
4903 TBN_ENDDRAG);
4905 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
4906 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
4908 /* !!! Undocumented - toolbar at 4.71 level and above sends
4909 * either NMRCLICK or NM_CLICK with the NMMOUSE structure.
4910 * Only NM_RCLICK is documented.
4912 nmmouse.dwItemSpec = btnPtr->idCommand;
4913 nmmouse.dwItemData = btnPtr->dwData;
4914 TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
4915 NM_CLICK);
4916 return 0;
4919 static LRESULT
4920 TOOLBAR_CaptureChanged(HWND hwnd)
4922 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4923 TBUTTON_INFO *btnPtr;
4925 infoPtr->bCaptured = FALSE;
4927 if (infoPtr->nButtonDown >= 0)
4929 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4930 btnPtr->fsState &= ~TBSTATE_PRESSED;
4932 infoPtr->nButtonDown = -1;
4933 infoPtr->nOldHit = -1;
4935 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
4936 btnPtr));
4938 return 0;
4941 static LRESULT
4942 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
4944 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4945 TBUTTON_INFO *hotBtnPtr, *btnPtr;
4946 RECT rc1;
4948 if (infoPtr->nOldHit < 0)
4949 return TRUE;
4951 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4953 /* Redraw the button if the last button we were over is the hot button and it
4954 is enabled */
4955 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
4957 hotBtnPtr->bHot = FALSE;
4958 rc1 = hotBtnPtr->rect;
4959 InflateRect (&rc1, 1, 1);
4960 InvalidateRect (hwnd, &rc1, TOOLBAR_HasText(infoPtr,
4961 hotBtnPtr));
4964 /* If the last button we were over is depressed then make it not */
4965 /* depressed and redraw it */
4966 if(infoPtr->nOldHit == infoPtr->nButtonDown)
4968 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4970 btnPtr->fsState &= ~TBSTATE_PRESSED;
4972 rc1 = hotBtnPtr->rect;
4973 InflateRect (&rc1, 1, 1);
4974 InvalidateRect (hwnd, &rc1, TRUE);
4977 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
4978 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
4980 return TRUE;
4983 static LRESULT
4984 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
4986 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4987 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4988 POINT pt;
4989 INT nHit;
4990 TRACKMOUSEEVENT trackinfo;
4991 NMTBHOTITEM nmhotitem;
4993 /* fill in the TRACKMOUSEEVENT struct */
4994 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4995 trackinfo.dwFlags = TME_QUERY;
4996 trackinfo.hwndTrack = hwnd;
4997 trackinfo.dwHoverTime = HOVER_DEFAULT;
4999 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5000 _TrackMouseEvent(&trackinfo);
5002 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5003 if(!(trackinfo.dwFlags & TME_LEAVE)) {
5004 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5006 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5007 /* and can properly deactivate the hot toolbar button */
5008 _TrackMouseEvent(&trackinfo);
5011 if (infoPtr->hwndToolTip)
5012 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
5013 WM_MOUSEMOVE, wParam, lParam);
5015 pt.x = (INT)LOWORD(lParam);
5016 pt.y = (INT)HIWORD(lParam);
5018 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
5020 if (infoPtr->nOldHit != nHit)
5022 /* Remove the effect of an old hot button if the button was enabled and was
5023 drawn with the hot button effect */
5024 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
5025 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
5027 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
5028 oldBtnPtr->bHot = FALSE;
5031 /* It's not a separator or in nowhere. It's a hot button. */
5032 if (nHit >= 0)
5034 btnPtr = &infoPtr->buttons[nHit];
5036 infoPtr->nHotItem = nHit;
5038 /* only enabled buttons show hot effect */
5039 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
5041 btnPtr->bHot = TRUE;
5045 nmhotitem.dwFlags = HICF_MOUSE;
5046 if (oldBtnPtr)
5047 nmhotitem.idOld = oldBtnPtr->idCommand;
5048 else
5049 nmhotitem.dwFlags |= HICF_ENTERING;
5050 if (btnPtr)
5051 nmhotitem.idNew = btnPtr->idCommand;
5052 else
5053 nmhotitem.dwFlags |= HICF_LEAVING;
5054 TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
5056 /* now invalidate the old and new buttons so they will be painted */
5057 if (oldBtnPtr)
5058 InvalidateRect (hwnd, &oldBtnPtr->rect,
5059 TOOLBAR_HasText(infoPtr, oldBtnPtr));
5060 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
5061 InvalidateRect(hwnd, &btnPtr->rect,
5062 TOOLBAR_HasText(infoPtr, btnPtr));
5064 if (infoPtr->bCaptured) {
5065 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5066 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5067 btnPtr->fsState &= ~TBSTATE_PRESSED;
5068 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5070 else if (nHit == infoPtr->nButtonDown) {
5071 btnPtr->fsState |= TBSTATE_PRESSED;
5072 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
5075 infoPtr->nOldHit = nHit;
5077 return 0;
5081 inline static LRESULT
5082 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5084 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5085 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
5086 /* else */
5087 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5091 inline static LRESULT
5092 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5094 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
5095 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5097 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
5101 static LRESULT
5102 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5104 TOOLBAR_INFO *infoPtr;
5105 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
5106 DWORD styleadd = 0;
5108 /* allocate memory for info structure */
5109 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
5110 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
5112 /* paranoid!! */
5113 infoPtr->dwStructSize = sizeof(TBBUTTON);
5115 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5116 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
5117 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
5118 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
5121 /* native control does:
5122 * Get a lot of colors and brushes
5123 * WM_NOTIFYFORMAT
5124 * SystemParametersInfoA(0x1f, 0x3c, adr1, 0)
5125 * CreateFontIndirectA(adr1)
5126 * CreateBitmap(0x27, 0x24, 1, 1, 0)
5127 * hdc = GetDC(toolbar)
5128 * GetSystemMetrics(0x48)
5129 * fnt2=CreateFontA(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
5130 * 0, 0, 0, 0, "MARLETT")
5131 * oldfnt = SelectObject(hdc, fnt2)
5132 * GetCharWidthA(hdc, 0x36, 0x36, adr2)
5133 * GetTextMetricsA(hdc, adr3)
5134 * SelectObject(hdc, oldfnt)
5135 * DeleteObject(fnt2)
5136 * ReleaseDC(hdc)
5137 * InvalidateRect(toolbar, 0, 1)
5138 * SetWindowLongA(toolbar, 0, addr)
5139 * SetWindowLongA(toolbar, -16, xxx) **sometimes**
5140 * WM_STYLECHANGING
5141 * CallWinEx old new
5142 * ie 1 0x56000a4c 0x46000a4c 0x56008a4d
5143 * ie 2 0x4600094c 0x4600094c 0x4600894d
5144 * ie 3 0x56000b4c 0x46000b4c 0x56008b4d
5145 * rebar 0x50008844 0x40008844 0x50008845
5146 * pager 0x50000844 0x40000844 0x50008845
5147 * IC35mgr 0x5400084e **nochange**
5148 * on entry to _NCCREATE 0x5400084e
5149 * rowlist 0x5400004e **nochange**
5150 * on entry to _NCCREATE 0x5400004e
5154 /* I think the code below is a bug, but it is the way that the native
5155 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5156 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5157 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5158 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5159 * Some how, the only cases of this seem to be MFC programs.
5161 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5162 * does not occur in the WM_STYLECHANGING routine.
5163 * (Guy Albertelli 9/2001)
5166 if ((cs->style & TBSTYLE_FLAT) && !(cs->style & TBSTYLE_TRANSPARENT))
5167 styleadd |= TBSTYLE_TRANSPARENT;
5168 if (!(cs->style & (CCS_TOP | CCS_NOMOVEY))) {
5169 styleadd |= CCS_TOP; /* default to top */
5170 SetWindowLongA (hwnd, GWL_STYLE, cs->style | styleadd);
5173 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
5177 static LRESULT
5178 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5180 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5181 RECT rcWindow;
5182 HDC hdc;
5184 if (dwStyle & WS_MINIMIZE)
5185 return 0; /* Nothing to do */
5187 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
5189 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5190 return 0;
5192 if (!(dwStyle & CCS_NODIVIDER))
5194 GetWindowRect (hwnd, &rcWindow);
5195 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5196 if( dwStyle & WS_BORDER )
5197 OffsetRect (&rcWindow, 1, 1);
5198 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5201 ReleaseDC( hwnd, hdc );
5203 return 0;
5207 inline static LRESULT
5208 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
5210 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5211 LPNMHDR lpnmh = (LPNMHDR)lParam;
5213 if (lpnmh->code == PGN_CALCSIZE) {
5214 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5216 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5217 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
5218 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
5219 lppgc->iWidth);
5221 else {
5222 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5223 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
5224 lppgc->iHeight);
5226 return 0;
5229 if (lpnmh->code == PGN_SCROLL) {
5230 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lParam;
5232 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
5233 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
5234 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
5235 lppgs->iScroll, lppgs->iDir);
5236 return 0;
5240 TRACE("passing WM_NOTIFY!\n");
5242 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
5243 if (infoPtr->bNtfUnicode)
5244 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
5245 wParam, lParam);
5246 else
5247 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
5248 wParam, lParam);
5250 #if 0
5251 if (lpnmh->code == TTN_GETDISPINFOA) {
5252 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
5254 FIXME("retrieving ASCII string\n");
5257 else if (lpnmh->code == TTN_GETDISPINFOW) {
5258 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
5260 FIXME("retrieving UNICODE string\n");
5263 #endif
5266 return 0;
5270 static LRESULT
5271 TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
5273 /* remove this routine when Toolbar is improved to pass infoPtr
5274 * around instead of hwnd.
5276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5277 return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
5281 static LRESULT
5282 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5284 INT i;
5286 if (lParam == NF_REQUERY) {
5287 i = SendMessageA(GetParent(infoPtr->hwndSelf),
5288 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
5289 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
5290 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
5292 i = NFR_ANSI;
5294 infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
5295 return (LRESULT)i;
5297 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
5301 static LRESULT
5302 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
5304 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
5305 HDC hdc;
5306 PAINTSTRUCT ps;
5308 /* fill ps.rcPaint with a default rect */
5309 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
5311 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
5313 TRACE("psrect=(%d,%d)-(%d,%d)\n",
5314 ps.rcPaint.left, ps.rcPaint.top,
5315 ps.rcPaint.right, ps.rcPaint.bottom);
5317 TOOLBAR_Refresh (hwnd, hdc, &ps);
5318 if (!wParam) EndPaint (hwnd, &ps);
5320 return 0;
5324 static LRESULT
5325 TOOLBAR_SetRedraw (HWND hwnd, WPARAM wParam, LPARAM lParam)
5326 /*****************************************************
5328 * Function;
5329 * Handles the WM_SETREDRAW message.
5331 * Documentation:
5332 * According to testing V4.71 of COMCTL32 returns the
5333 * *previous* status of the redraw flag (either 0 or 1)
5334 * instead of the MSDN documented value of 0 if handled.
5335 * (For laughs see the "consistancy" with same function
5336 * in rebar.)
5338 *****************************************************/
5340 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5341 BOOL oldredraw = infoPtr->bDoRedraw;
5343 TRACE("set to %s\n",
5344 (wParam) ? "TRUE" : "FALSE");
5345 infoPtr->bDoRedraw = (BOOL) wParam;
5346 if (wParam) {
5347 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
5349 return (oldredraw) ? 1 : 0;
5353 static LRESULT
5354 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
5356 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5357 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
5358 RECT parent_rect;
5359 RECT window_rect;
5360 HWND parent;
5361 INT x, y;
5362 INT cx, cy;
5363 INT flags;
5364 UINT uPosFlags = 0;
5366 /* Resize deadlock check */
5367 if (infoPtr->bAutoSize) {
5368 infoPtr->bAutoSize = FALSE;
5369 return 0;
5372 /* FIXME: optimize to only update size if the new size doesn't */
5373 /* match the current size */
5375 flags = (INT) wParam;
5377 /* FIXME for flags =
5378 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
5381 TRACE("sizing toolbar!\n");
5383 if (flags == SIZE_RESTORED) {
5384 /* width and height don't apply */
5385 parent = GetParent (hwnd);
5386 GetClientRect(parent, &parent_rect);
5387 x = parent_rect.left;
5388 y = parent_rect.top;
5390 if (dwStyle & CCS_NORESIZE) {
5391 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
5394 * this sets the working width of the toolbar, and
5395 * Calc Toolbar will not adjust it, only the height
5397 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5398 cy = infoPtr->nHeight;
5399 cx = infoPtr->nWidth;
5400 TOOLBAR_CalcToolbar (hwnd);
5401 infoPtr->nWidth = cx;
5402 infoPtr->nHeight = cy;
5404 else {
5405 infoPtr->nWidth = parent_rect.right - parent_rect.left;
5406 TOOLBAR_CalcToolbar (hwnd);
5407 cy = infoPtr->nHeight;
5408 cx = infoPtr->nWidth;
5410 if (dwStyle & CCS_NOMOVEY) {
5411 GetWindowRect(hwnd, &window_rect);
5412 ScreenToClient(parent, (LPPOINT)&window_rect.left);
5413 y = window_rect.top;
5417 if (dwStyle & CCS_NOPARENTALIGN) {
5418 uPosFlags |= SWP_NOMOVE;
5419 cy = infoPtr->nHeight;
5420 cx = infoPtr->nWidth;
5423 if (!(dwStyle & CCS_NODIVIDER))
5424 cy += GetSystemMetrics(SM_CYEDGE);
5426 if (dwStyle & WS_BORDER)
5428 x = y = 1;
5429 cy += GetSystemMetrics(SM_CYEDGE);
5430 cx += GetSystemMetrics(SM_CYEDGE);
5433 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
5434 cx, cy, uPosFlags | SWP_NOZORDER);
5436 return 0;
5440 static LRESULT
5441 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
5443 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5445 if (nType == GWL_STYLE) {
5446 if (lpStyle->styleNew & TBSTYLE_LIST) {
5447 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
5449 else {
5450 infoPtr->dwDTFlags = DT_CENTER;
5452 infoPtr->bTransparent = (lpStyle->styleNew & TBSTYLE_TRANSPARENT);
5453 infoPtr->bBtnTranspnt = (lpStyle->styleNew &
5454 (TBSTYLE_FLAT | TBSTYLE_LIST));
5455 TOOLBAR_CheckStyle (hwnd, lpStyle->styleNew);
5458 TOOLBAR_AutoSize (hwnd);
5460 InvalidateRect(hwnd, NULL, FALSE);
5462 return 0;
5466 static LRESULT
5467 TOOLBAR_SysColorChange (HWND hwnd)
5469 COMCTL32_RefreshSysColors();
5471 return 0;
5476 static LRESULT WINAPI
5477 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5479 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
5480 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
5482 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
5483 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
5485 switch (uMsg)
5487 case TB_ADDBITMAP:
5488 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
5490 case TB_ADDBUTTONSA:
5491 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
5493 case TB_ADDBUTTONSW:
5494 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
5496 case TB_ADDSTRINGA:
5497 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
5499 case TB_ADDSTRINGW:
5500 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
5502 case TB_AUTOSIZE:
5503 return TOOLBAR_AutoSize (hwnd);
5505 case TB_BUTTONCOUNT:
5506 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
5508 case TB_BUTTONSTRUCTSIZE:
5509 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
5511 case TB_CHANGEBITMAP:
5512 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
5514 case TB_CHECKBUTTON:
5515 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
5517 case TB_COMMANDTOINDEX:
5518 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
5520 case TB_CUSTOMIZE:
5521 return TOOLBAR_Customize (hwnd);
5523 case TB_DELETEBUTTON:
5524 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
5526 case TB_ENABLEBUTTON:
5527 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
5529 case TB_GETANCHORHIGHLIGHT:
5530 return TOOLBAR_GetAnchorHighlight (hwnd);
5532 case TB_GETBITMAP:
5533 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
5535 case TB_GETBITMAPFLAGS:
5536 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
5538 case TB_GETBUTTON:
5539 return TOOLBAR_GetButton (hwnd, wParam, lParam);
5541 case TB_GETBUTTONINFOA:
5542 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
5544 case TB_GETBUTTONINFOW:
5545 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
5547 case TB_GETBUTTONSIZE:
5548 return TOOLBAR_GetButtonSize (hwnd);
5550 case TB_GETBUTTONTEXTA:
5551 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
5553 case TB_GETBUTTONTEXTW:
5554 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
5556 case TB_GETDISABLEDIMAGELIST:
5557 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
5559 case TB_GETEXTENDEDSTYLE:
5560 return TOOLBAR_GetExtendedStyle (hwnd);
5562 case TB_GETHOTIMAGELIST:
5563 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
5565 case TB_GETHOTITEM:
5566 return TOOLBAR_GetHotItem (hwnd);
5568 case TB_GETIMAGELIST:
5569 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
5571 /* case TB_GETINSERTMARK: */ /* 4.71 */
5572 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
5574 case TB_GETITEMRECT:
5575 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
5577 case TB_GETMAXSIZE:
5578 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
5580 /* case TB_GETOBJECT: */ /* 4.71 */
5582 case TB_GETPADDING:
5583 return TOOLBAR_GetPadding (hwnd);
5585 case TB_GETRECT:
5586 return TOOLBAR_GetRect (hwnd, wParam, lParam);
5588 case TB_GETROWS:
5589 return TOOLBAR_GetRows (hwnd, wParam, lParam);
5591 case TB_GETSTATE:
5592 return TOOLBAR_GetState (hwnd, wParam, lParam);
5594 case TB_GETSTYLE:
5595 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
5597 case TB_GETTEXTROWS:
5598 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
5600 case TB_GETTOOLTIPS:
5601 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
5603 case TB_GETUNICODEFORMAT:
5604 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
5606 case TB_HIDEBUTTON:
5607 return TOOLBAR_HideButton (hwnd, wParam, lParam);
5609 case TB_HITTEST:
5610 return TOOLBAR_HitTest (hwnd, wParam, lParam);
5612 case TB_INDETERMINATE:
5613 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
5615 case TB_INSERTBUTTONA:
5616 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
5618 case TB_INSERTBUTTONW:
5619 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
5621 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
5623 case TB_ISBUTTONCHECKED:
5624 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
5626 case TB_ISBUTTONENABLED:
5627 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
5629 case TB_ISBUTTONHIDDEN:
5630 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
5632 case TB_ISBUTTONHIGHLIGHTED:
5633 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
5635 case TB_ISBUTTONINDETERMINATE:
5636 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
5638 case TB_ISBUTTONPRESSED:
5639 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
5641 case TB_LOADIMAGES: /* 4.70 */
5642 FIXME("missing standard imagelists\n");
5643 return 0;
5645 /* case TB_MAPACCELERATORA: */ /* 4.71 */
5646 /* case TB_MAPACCELERATORW: */ /* 4.71 */
5647 /* case TB_MARKBUTTON: */ /* 4.71 */
5648 /* case TB_MOVEBUTTON: */ /* 4.71 */
5650 case TB_PRESSBUTTON:
5651 return TOOLBAR_PressButton (hwnd, wParam, lParam);
5653 case TB_REPLACEBITMAP:
5654 return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
5656 case TB_SAVERESTOREA:
5657 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
5659 case TB_SAVERESTOREW:
5660 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
5662 case TB_SETANCHORHIGHLIGHT:
5663 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
5665 case TB_SETBITMAPSIZE:
5666 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
5668 case TB_SETBUTTONINFOA:
5669 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
5671 case TB_SETBUTTONINFOW:
5672 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
5674 case TB_SETBUTTONSIZE:
5675 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
5677 case TB_SETBUTTONWIDTH:
5678 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
5680 case TB_SETCMDID:
5681 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
5683 case TB_SETDISABLEDIMAGELIST:
5684 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
5686 case TB_SETDRAWTEXTFLAGS:
5687 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
5689 case TB_SETEXTENDEDSTYLE:
5690 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
5692 case TB_SETHOTIMAGELIST:
5693 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
5695 case TB_SETHOTITEM:
5696 return TOOLBAR_SetHotItem (hwnd, wParam);
5698 case TB_SETIMAGELIST:
5699 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
5701 case TB_SETINDENT:
5702 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
5704 /* case TB_SETINSERTMARK: */ /* 4.71 */
5706 case TB_SETINSERTMARKCOLOR:
5707 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
5709 case TB_SETMAXTEXTROWS:
5710 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
5712 case TB_SETPADDING:
5713 return TOOLBAR_SetPadding (hwnd, wParam, lParam);
5715 case TB_SETPARENT:
5716 return TOOLBAR_SetParent (hwnd, wParam, lParam);
5718 case TB_SETROWS:
5719 return TOOLBAR_SetRows (hwnd, wParam, lParam);
5721 case TB_SETSTATE:
5722 return TOOLBAR_SetState (hwnd, wParam, lParam);
5724 case TB_SETSTYLE:
5725 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
5727 case TB_SETTOOLTIPS:
5728 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
5730 case TB_SETUNICODEFORMAT:
5731 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
5733 case TB_UNKWN45E:
5734 return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
5736 case TB_UNKWN463:
5737 return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
5740 /* Common Control Messages */
5742 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
5743 case CCM_GETCOLORSCHEME:
5744 return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5746 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
5747 case CCM_SETCOLORSCHEME:
5748 return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
5750 case CCM_GETVERSION:
5751 return TOOLBAR_GetVersion (hwnd);
5753 case CCM_SETVERSION:
5754 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
5757 /* case WM_CHAR: */
5759 case WM_CREATE:
5760 return TOOLBAR_Create (hwnd, wParam, lParam);
5762 case WM_DESTROY:
5763 return TOOLBAR_Destroy (hwnd, wParam, lParam);
5765 case WM_ERASEBKGND:
5766 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
5768 case WM_GETFONT:
5769 return TOOLBAR_GetFont (hwnd, wParam, lParam);
5771 /* case WM_KEYDOWN: */
5772 /* case WM_KILLFOCUS: */
5774 case WM_LBUTTONDBLCLK:
5775 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
5777 case WM_LBUTTONDOWN:
5778 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
5780 case WM_LBUTTONUP:
5781 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
5783 case WM_MOUSEMOVE:
5784 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
5786 case WM_MOUSELEAVE:
5787 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
5789 case WM_CAPTURECHANGED:
5790 return TOOLBAR_CaptureChanged(hwnd);
5792 case WM_NCACTIVATE:
5793 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
5795 case WM_NCCALCSIZE:
5796 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
5798 case WM_NCCREATE:
5799 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
5801 case WM_NCPAINT:
5802 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
5804 case WM_NOTIFY:
5805 return TOOLBAR_Notify (hwnd, wParam, lParam);
5807 case WM_NOTIFYFORMAT:
5808 TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
5810 case WM_PAINT:
5811 return TOOLBAR_Paint (hwnd, wParam);
5813 case WM_SETREDRAW:
5814 return TOOLBAR_SetRedraw (hwnd, wParam, lParam);
5816 case WM_SIZE:
5817 return TOOLBAR_Size (hwnd, wParam, lParam);
5819 case WM_STYLECHANGED:
5820 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
5822 case WM_SYSCOLORCHANGE:
5823 return TOOLBAR_SysColorChange (hwnd);
5825 /* case WM_WININICHANGE: */
5827 case WM_CHARTOITEM:
5828 case WM_COMMAND:
5829 case WM_DRAWITEM:
5830 case WM_MEASUREITEM:
5831 case WM_VKEYTOITEM:
5833 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
5834 if(infoPtr != NULL)
5835 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
5836 else
5837 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
5840 /* We see this in Outlook Express 5.x and just does DefWindowProc */
5841 case PGM_FORWARDMOUSE:
5842 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5844 default:
5845 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
5846 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
5847 uMsg, wParam, lParam);
5848 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
5850 return 0;
5854 VOID
5855 TOOLBAR_Register (void)
5857 WNDCLASSA wndClass;
5859 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
5860 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5861 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
5862 wndClass.cbClsExtra = 0;
5863 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
5864 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
5865 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
5866 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
5868 RegisterClassA (&wndClass);
5872 VOID
5873 TOOLBAR_Unregister (void)
5875 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);