4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
8 * - A little bug in TOOLBAR_DrawMasked()
9 * - Button wrapping (under construction).
11 * - Notifications (under construction).
13 * - Tooltip support (almost complete).
14 * - Unicode suppport (under construction).
15 * - Fix TOOLBAR_SetButtonInfo32A/W.
16 * - TBSTYLE_AUTOSIZE for toolbar and buttons.
17 * - I_IMAGECALLBACK support.
18 * - iString of -1 is undocumented
19 * - Customization dialog:
21 * - Minor buglet in 'available buttons' list:
22 * Buttons are not listed in M$-like order. M$ seems to use a single
23 * internal list to store the button information of both listboxes.
24 * - Drag list support.
25 * - Help and Reset button support.
28 * - Run tests using Waite Group Windows95 API Bible Volume 2.
29 * The second cdrom contains executables addstr.exe, btncount.exe,
30 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
31 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
32 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
33 * setparnt.exe, setrows.exe, toolwnd.exe.
34 * - Microsofts controlspy examples.
35 * - Charles Petzold's 'Programming Windows': gadgets.exe
44 #include "wine/unicode.h"
46 #include "imagelist.h"
48 #include "debugtools.h"
50 DEFAULT_DEBUG_CHANNEL(toolbar);
68 DWORD dwStructSize; /* size of TBBUTTON struct */
69 INT nHeight; /* height of the toolbar */
70 INT nWidth; /* width of the toolbar */
76 INT nRows; /* number of button rows */
77 INT nMaxTextRows; /* maximum number of text rows */
78 INT cxMin; /* minimum button width */
79 INT cxMax; /* maximum button width */
80 INT nNumButtons; /* number of buttons */
81 INT nNumBitmaps; /* number of bitmaps */
82 INT nNumStrings; /* number of strings */
83 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
84 BOOL bCaptured; /* mouse captured? */
87 INT nHotItem; /* index of the "hot" item */
88 HFONT hFont; /* text font */
89 HIMAGELIST himlInt; /* image list created internally */
90 HIMAGELIST himlDef; /* default image list */
91 HIMAGELIST himlHot; /* hot image list */
92 HIMAGELIST himlDis; /* disabled image list */
93 HWND hwndToolTip; /* handle to tool tip control */
94 HWND hwndNotify; /* handle to the window that gets notifications */
95 BOOL bTransparent; /* background transparency flag */
96 BOOL bAutoSize; /* auto size deadlock indicator */
97 BOOL bAnchor; /* anchor highlight enabled */
98 DWORD dwExStyle; /* extended toolbar style */
99 DWORD dwDTFlags; /* DrawText flags */
101 COLORREF clrInsertMark; /* insert mark color */
102 RECT rcBound; /* bounding rectangle */
105 TBUTTON_INFO *buttons; /* pointer to button array */
106 LPWSTR *strings; /* pointer to string array */
107 } TOOLBAR_INFO, *PTOOLBAR_INFO;
110 /* used by customization dialog */
113 PTOOLBAR_INFO tbInfo;
115 } CUSTDLG_INFO, *PCUSTDLG_INFO;
123 } CUSTOMBUTTON, *PCUSTOMBUTTON;
126 #define SEPARATOR_WIDTH 8
128 #define BOTTOM_BORDER 2
129 #define DDARROW_WIDTH 11
131 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
132 #define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
133 #define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
136 TOOLBAR_GetText(TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
138 LPWSTR lpText = NULL;
140 /* FIXME: iString == -1 is undocumented */
141 if ((HIWORD(btnPtr->iString) != 0) && (btnPtr->iString != -1))
142 lpText = (LPWSTR)btnPtr->iString;
143 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
144 lpText = infoPtr->strings[btnPtr->iString];
150 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index)
152 if ((index>=0) && (index < infoPtr->nNumBitmaps))
160 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
162 INT x = (lpRect->left + lpRect->right) / 2 - 1;
163 INT yBottom = lpRect->bottom - 3;
164 INT yTop = lpRect->top + 1;
166 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
167 MoveToEx (hdc, x, yBottom, NULL);
168 LineTo (hdc, x, yTop);
170 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
171 MoveToEx (hdc, x, yBottom, NULL);
172 LineTo (hdc, x, yTop);
176 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, INT colorRef)
179 SelectObject ( hdc, GetSysColorPen (colorRef));
182 MoveToEx (hdc, x, y, NULL);
183 LineTo (hdc, x+5, y++); x++;
184 MoveToEx (hdc, x, y, NULL);
185 LineTo (hdc, x+3, y++); x++;
186 MoveToEx (hdc, x, y, NULL);
187 LineTo (hdc, x+1, y++);
191 * Draw the text string for this button.
192 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
193 * is non-zero, so we can simply check himlDef to see if we have
197 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
198 HDC hdc, INT nState, DWORD dwStyle)
200 RECT rcText = btnPtr->rect;
204 LPWSTR lpText = NULL;
205 HIMAGELIST himl = infoPtr->himlDef;
207 TRACE ("iString: %x\n", btnPtr->iString);
209 /* get a pointer to the text */
210 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
212 TRACE ("lpText: %s\n", debugstr_w(lpText));
217 InflateRect (&rcText, -3, -3);
219 if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
220 if ((dwStyle & TBSTYLE_LIST) &&
221 ((btnPtr->fsStyle & TBSTYLE_AUTOSIZE) == 0) &&
222 (btnPtr->iBitmap != I_IMAGENONE)) {
223 rcText.left += infoPtr->nBitmapWidth;
226 rcText.top += infoPtr->nBitmapHeight;
230 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
231 OffsetRect (&rcText, 1, 1);
233 hOldFont = SelectObject (hdc, infoPtr->hFont);
234 nOldBkMode = SetBkMode (hdc, TRANSPARENT);
235 if (!(nState & TBSTATE_ENABLED)) {
236 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
237 OffsetRect (&rcText, 1, 1);
238 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
239 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
240 OffsetRect (&rcText, -1, -1);
241 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
243 else if (nState & TBSTATE_INDETERMINATE) {
244 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
245 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
248 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
249 DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
252 SetTextColor (hdc, clrOld);
253 SelectObject (hdc, hOldFont);
254 if (nOldBkMode != TRANSPARENT)
255 SetBkMode (hdc, nOldBkMode);
261 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
263 HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
264 INT cx = lpRect->right - lpRect->left;
265 INT cy = lpRect->bottom - lpRect->top;
266 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
267 SelectObject (hdc, hbr);
272 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
273 HDC hdc, INT x, INT y)
275 /* FIXME: this function is a hack since it uses image list
276 internals directly */
278 HIMAGELIST himl = infoPtr->himlDef;
286 /* create new dc's */
287 hdcImageList = CreateCompatibleDC (0);
288 hdcMask = CreateCompatibleDC (0);
290 /* create new bitmap */
291 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
292 SelectObject (hdcMask, hbmMask);
294 /* copy the mask bitmap */
295 SelectObject (hdcImageList, himl->hbmMask);
296 SetBkColor (hdcImageList, RGB(255, 255, 255));
297 SetTextColor (hdcImageList, RGB(0, 0, 0));
298 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
299 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
301 /* draw the new mask */
302 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
303 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
304 hdcMask, 0, 0, 0xB8074A);
306 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
307 BitBlt (hdc, x, y, himl->cx, himl->cy,
308 hdcMask, 0, 0, 0xB8074A);
310 DeleteObject (hbmMask);
312 DeleteDC (hdcImageList);
317 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
319 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
320 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
321 BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
322 (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
323 RECT rc, rcArrow, rcBitmap;
325 if (btnPtr->fsState & TBSTATE_HIDDEN)
329 CopyRect (&rcArrow, &rc);
330 CopyRect(&rcBitmap, &rc);
332 FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
334 if (hasDropDownArrow)
336 if (dwStyle & TBSTYLE_FLAT)
337 rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
339 rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
340 rcArrow.left = rc.right;
343 /* Center the bitmap horizontally and vertically */
344 rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
346 if(TOOLBAR_HasText(infoPtr, btnPtr))
347 rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
349 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
351 TRACE("iBitmap: %d\n", btnPtr->iBitmap);
354 if (btnPtr->fsStyle & TBSTYLE_SEP) {
355 /* with the FLAT style, iBitmap is the width and has already */
356 /* been taken into consideration in calculating the width */
357 /* so now we need to draw the vertical separator */
358 /* empirical tests show that iBitmap can/will be non-zero */
359 /* when drawing the vertical bar... */
360 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */)
361 TOOLBAR_DrawFlatSeparator (&rc, hdc);
366 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
367 if (!(dwStyle & TBSTYLE_FLAT))
369 DrawEdge (hdc, &rc, EDGE_RAISED,
370 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
371 if (hasDropDownArrow)
372 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
373 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
376 if (hasDropDownArrow)
378 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1, COLOR_3DHIGHLIGHT);
379 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_3DSHADOW);
382 if (infoPtr->himlDis &&
383 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
384 ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
385 rcBitmap.left, rcBitmap.top, ILD_NORMAL);
387 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
389 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
393 /* pressed TBSTYLE_BUTTON */
394 if (btnPtr->fsState & TBSTATE_PRESSED) {
395 if (dwStyle & TBSTYLE_FLAT)
397 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
398 if (hasDropDownArrow)
399 DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE | BF_ADJUST);
403 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
404 if (hasDropDownArrow)
405 DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
408 if (hasDropDownArrow)
409 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
411 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
412 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
413 rcBitmap.left + 1, rcBitmap.top + 1, ILD_NORMAL);
415 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
419 /* checked TBSTYLE_CHECK */
420 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
421 (btnPtr->fsState & TBSTATE_CHECKED)) {
422 if (dwStyle & TBSTYLE_FLAT)
423 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
424 BF_RECT | BF_MIDDLE | BF_ADJUST);
426 DrawEdge (hdc, &rc, EDGE_SUNKEN,
427 BF_RECT | BF_MIDDLE | BF_ADJUST);
429 TOOLBAR_DrawPattern (hdc, &rc);
431 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
432 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
433 rcBitmap.left + 1, rcBitmap.top + 1, ILD_NORMAL);
434 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
439 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
440 DrawEdge (hdc, &rc, EDGE_RAISED,
441 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
443 TOOLBAR_DrawPattern (hdc, &rc);
444 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
445 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
450 if (dwStyle & TBSTYLE_FLAT)
454 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
455 if (hasDropDownArrow)
456 DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
460 FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
461 if (hasDropDownArrow)
462 FrameRect(hdc, &rcArrow, GetSysColorBrush(COLOR_BTNFACE));
465 if (hasDropDownArrow)
466 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top, COLOR_WINDOWFRAME);
468 if (btnPtr->bHot && infoPtr->himlHot &&
469 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
470 ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
471 rcBitmap.left, rcBitmap.top, ILD_NORMAL);
472 else if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
473 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
474 rcBitmap.left, rcBitmap.top, ILD_NORMAL);
478 DrawEdge (hdc, &rc, EDGE_RAISED,
479 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
481 if (hasDropDownArrow)
483 DrawEdge (hdc, &rcArrow, EDGE_RAISED,
484 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
485 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
488 if (TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap))
489 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
490 rcBitmap.left, rcBitmap.top, ILD_NORMAL);
493 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
498 TOOLBAR_Refresh (HWND hwnd, HDC hdc, PAINTSTRUCT* ps)
500 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
501 TBUTTON_INFO *btnPtr;
505 /* if imagelist belongs to the app, it can be changed
506 by the app after setting it */
507 if (infoPtr->himlDef != infoPtr->himlInt)
508 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
509 /* redraw necessary buttons */
510 btnPtr = infoPtr->buttons;
511 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
513 if(IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect)))
514 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
519 TOOLBAR_MeasureString(HWND hwnd, INT index, LPSIZE lpSize)
521 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
522 TBUTTON_INFO *btnPtr;
529 hOldFont = SelectObject (hdc, infoPtr->hFont);
531 btnPtr = &infoPtr->buttons[index];
533 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
534 (btnPtr->iString > -1) &&
535 (btnPtr->iString < infoPtr->nNumStrings))
537 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
538 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
541 SelectObject (hdc, hOldFont);
544 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
548 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
550 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
551 TBUTTON_INFO *btnPtr;
559 btnPtr = infoPtr->buttons;
560 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
561 if(TOOLBAR_HasText(infoPtr, btnPtr))
563 TOOLBAR_MeasureString(hwnd,i,&sz);
564 if (sz.cx > lpSize->cx)
566 if (sz.cy > lpSize->cy)
571 TRACE("string size %ld x %ld!\n", lpSize->cx, lpSize->cy);
574 /***********************************************************************
575 * TOOLBAR_WrapToolbar
577 * This function walks through the buttons and seperators in the
578 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
579 * wrapping should occur based on the width of the toolbar window.
580 * It does *not* calculate button placement itself. That task
581 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
582 * the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE
583 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
587 TOOLBAR_WrapToolbar( HWND hwnd, DWORD dwStyle )
589 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
590 TBUTTON_INFO *btnPtr;
593 BOOL bWrap, bButtonWrap;
595 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
596 /* no layout is necessary. Applications may use this style */
597 /* to perform their own layout on the toolbar. */
598 if( !(dwStyle & TBSTYLE_WRAPABLE) )
601 btnPtr = infoPtr->buttons;
602 x = infoPtr->nIndent;
604 /* this can get the parents width, to know how far we can extend
605 * this toolbar. We cannot use its height, as there may be multiple
606 * toolbars in a rebar control
608 GetClientRect( GetParent(hwnd), &rc );
609 infoPtr->nWidth = rc.right - rc.left;
612 for (i = 0; i < infoPtr->nNumButtons; i++ )
615 btnPtr[i].fsState &= ~TBSTATE_WRAP;
617 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
620 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
621 /* it is the actual width of the separator. This is used for */
622 /* custom controls in toolbars. */
623 if (btnPtr[i].fsStyle & TBSTYLE_SEP)
624 cx = (btnPtr[i].iBitmap > 0) ?
625 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
627 cx = infoPtr->nButtonWidth;
629 /* Two or more adjacent separators form a separator group. */
630 /* The first separator in a group should be wrapped to the */
631 /* next row if the previous wrapping is on a button. */
633 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
634 (i + 1 < infoPtr->nNumButtons ) &&
635 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
637 btnPtr[i].fsState |= TBSTATE_WRAP;
638 x = infoPtr->nIndent;
644 /* The layout makes sure the bitmap is visible, but not the button. */
645 if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
650 /* If the current button is a separator and not hidden, */
651 /* go to the next until it reaches a non separator. */
652 /* Wrap the last separator if it is before a button. */
653 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
654 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
655 i < infoPtr->nNumButtons )
661 if( bFound && i < infoPtr->nNumButtons )
664 btnPtr[i].fsState |= TBSTATE_WRAP;
665 x = infoPtr->nIndent;
669 else if ( i >= infoPtr->nNumButtons)
672 /* If the current button is not a separator, find the last */
673 /* separator and wrap it. */
674 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
676 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
677 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
681 x = infoPtr->nIndent;
682 btnPtr[j].fsState |= TBSTATE_WRAP;
688 /* If no separator available for wrapping, wrap one of */
689 /* non-hidden previous button. */
693 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
695 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
700 x = infoPtr->nIndent;
701 btnPtr[j].fsState |= TBSTATE_WRAP;
707 /* If all above failed, wrap the current button. */
710 btnPtr[i].fsState |= TBSTATE_WRAP;
712 x = infoPtr->nIndent;
713 if (btnPtr[i].fsState & TBSTYLE_SEP )
725 /***********************************************************************
726 * TOOLBAR_CalcToolbar
728 * This function calculates button and separator placement. It first
729 * calculates the button sizes, gets the toolbar window width and then
730 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
731 * on. It assigns a new location to each item and sends this location to
732 * the tooltip window if appropriate. Finally, it updates the rcBound
733 * rect and calculates the new required toolbar window height.
737 TOOLBAR_CalcToolbar (HWND hwnd)
739 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
740 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
741 TBUTTON_INFO *btnPtr;
742 INT i, nRows, nSepRows;
746 BOOL usesBitmaps = FALSE;
747 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
749 TOOLBAR_CalcStrings (hwnd, &sizeString);
751 if (dwStyle & TBSTYLE_LIST)
753 infoPtr->nButtonHeight = max(infoPtr->nBitmapHeight, sizeString.cy) + 6;
754 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + sizeString.cx + 6;
757 for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
759 if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
763 if (sizeString.cy > 0)
766 infoPtr->nButtonHeight = sizeString.cy +
767 infoPtr->nBitmapHeight + 6;
769 infoPtr->nButtonHeight = sizeString.cy + 6;
771 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
772 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
774 if (sizeString.cx > infoPtr->nBitmapWidth)
775 infoPtr->nButtonWidth = sizeString.cx + 6;
776 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
777 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
780 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
781 infoPtr->nButtonWidth = infoPtr->cxMin;
782 if ( infoPtr->cxMax >= 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
783 infoPtr->nButtonWidth = infoPtr->cxMax;
785 TOOLBAR_WrapToolbar( hwnd, dwStyle );
787 x = infoPtr->nIndent;
788 y = (dwStyle & TBSTYLE_FLAT) ? 0 : TOP_BORDER;
791 * We will set the height below, and we set the width on entry
792 * so we do not reset them here..
795 GetClientRect( hwnd, &rc );
796 /* get initial values for toolbar */
797 infoPtr->nWidth = rc.right - rc.left;
798 infoPtr->nHeight = rc.bottom - rc.top;
801 /* from above, minimum is a button, and possible text */
802 cx = infoPtr->nButtonWidth;
804 /* cannot use just ButtonHeight, we may have no buttons! */
805 if (infoPtr->nNumButtons > 0)
806 infoPtr->nHeight = infoPtr->nButtonHeight;
808 cy = infoPtr->nHeight;
810 nRows = nSepRows = 0;
812 infoPtr->rcBound.top = y;
813 infoPtr->rcBound.left = x;
814 infoPtr->rcBound.bottom = y + cy;
815 infoPtr->rcBound.right = x;
817 btnPtr = infoPtr->buttons;
819 /* do not base height/width on parent, if the parent is a */
820 /* rebar control it could have multiple rows of toolbars */
821 /* GetClientRect( GetParent(hwnd), &rc ); */
822 /* cx = rc.right - rc.left; */
823 /* cy = rc.bottom - rc.top; */
825 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
828 if (btnPtr->fsState & TBSTATE_HIDDEN)
830 SetRectEmpty (&btnPtr->rect);
834 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
835 /* it is the actual width of the separator. This is used for */
836 /* custom controls in toolbars. */
837 if (btnPtr->fsStyle & TBSTYLE_SEP)
838 cx = (btnPtr->iBitmap > 0) ?
839 btnPtr->iBitmap : SEPARATOR_WIDTH;
842 if (btnPtr->fsStyle & TBSTYLE_AUTOSIZE)
845 TOOLBAR_MeasureString(hwnd,i,&sz);
849 cx = infoPtr->nButtonWidth;
851 if (hasDropDownArrows && (btnPtr->fsStyle & TBSTYLE_DROPDOWN))
854 cy = infoPtr->nHeight;
856 if (btnPtr->fsState & TBSTATE_WRAP )
859 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
861 if (infoPtr->rcBound.left > x)
862 infoPtr->rcBound.left = x;
863 if (infoPtr->rcBound.right < x + cx)
864 infoPtr->rcBound.right = x + cx;
865 if (infoPtr->rcBound.bottom < y + cy)
866 infoPtr->rcBound.bottom = y + cy;
868 /* Set the toolTip only for non-hidden, non-separator button */
869 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
873 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
874 ti.cbSize = sizeof(TTTOOLINFOA);
876 ti.uId = btnPtr->idCommand;
877 ti.rect = btnPtr->rect;
878 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
882 /* btnPtr->nRow is zero based. The space between the rows is */
883 /* also considered as a row. */
884 btnPtr->nRow = nRows + nSepRows;
887 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
891 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
892 /* it is the actual width of the separator. This is used for */
893 /* custom controls in toolbars. */
894 y += cy + ( (btnPtr->iBitmap > 0 ) ?
895 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
897 /* nSepRows is used to calculate the extra height follwoing */
901 x = infoPtr->nIndent;
908 /* infoPtr->nRows is the number of rows on the toolbar */
909 infoPtr->nRows = nRows + nSepRows + 1;
911 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
913 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
914 nSepRows * (SEPARATOR_WIDTH * 2 / 3) +
915 nSepRows * (infoPtr->nBitmapHeight + 1) +
917 TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
922 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
924 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
925 TBUTTON_INFO *btnPtr;
928 btnPtr = infoPtr->buttons;
929 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
930 if (btnPtr->fsState & TBSTATE_HIDDEN)
933 if (btnPtr->fsStyle & TBSTYLE_SEP) {
934 if (PtInRect (&btnPtr->rect, *lpPt)) {
935 TRACE(" ON SEPARATOR %d!\n", i);
940 if (PtInRect (&btnPtr->rect, *lpPt)) {
941 TRACE(" ON BUTTON %d!\n", i);
947 TRACE(" NOWHERE!\n");
953 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
955 TBUTTON_INFO *btnPtr;
958 btnPtr = infoPtr->buttons;
959 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
960 if (btnPtr->idCommand == idCommand) {
961 TRACE("command=%d index=%d\n", idCommand, i);
965 TRACE("no index found for command=%d\n", idCommand);
971 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
973 TBUTTON_INFO *btnPtr;
976 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
979 /* check index button */
980 btnPtr = &infoPtr->buttons[nIndex];
981 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
982 if (btnPtr->fsState & TBSTATE_CHECKED)
986 /* check previous buttons */
987 nRunIndex = nIndex - 1;
988 while (nRunIndex >= 0) {
989 btnPtr = &infoPtr->buttons[nRunIndex];
990 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
991 if (btnPtr->fsState & TBSTATE_CHECKED)
999 /* check next buttons */
1000 nRunIndex = nIndex + 1;
1001 while (nRunIndex < infoPtr->nNumButtons) {
1002 btnPtr = &infoPtr->buttons[nRunIndex];
1003 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
1004 if (btnPtr->fsState & TBSTATE_CHECKED)
1017 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1018 WPARAM wParam, LPARAM lParam)
1024 msg.wParam = wParam;
1025 msg.lParam = lParam;
1026 msg.time = GetMessageTime ();
1027 msg.pt.x = LOWORD(GetMessagePos ());
1028 msg.pt.y = HIWORD(GetMessagePos ());
1030 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1034 /***********************************************************************
1035 * TOOLBAR_CustomizeDialogProc
1036 * This function implements the toolbar customization dialog.
1039 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1041 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongA (hwnd, DWL_USER);
1042 PCUSTOMBUTTON btnInfo;
1048 custInfo = (PCUSTDLG_INFO)lParam;
1049 SetWindowLongA (hwnd, DWL_USER, (DWORD)custInfo);
1057 /* send TBN_QUERYINSERT notification */
1058 nmtb.hdr.hwndFrom = hwnd;
1059 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1060 nmtb.hdr.code = TBN_QUERYINSERT;
1061 nmtb.iItem = custInfo->tbInfo->nNumButtons;
1063 if (!SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1064 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1067 /* add items to 'toolbar buttons' list and check if removable */
1068 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
1070 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1071 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1072 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1073 btnInfo->bVirtual = FALSE;
1074 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1076 /* send TBN_QUERYDELETE notification */
1077 nmtb.hdr.hwndFrom = hwnd;
1078 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1079 nmtb.hdr.code = TBN_QUERYDELETE;
1082 btnInfo->bRemovable = SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1083 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
1085 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
1086 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1089 /* insert separator button into 'available buttons' list */
1090 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1091 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1092 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1093 btnInfo->bVirtual = FALSE;
1094 btnInfo->bRemovable = TRUE;
1095 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1096 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1097 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1099 /* insert all buttons into dsa */
1102 /* send TBN_GETBUTTONINFO notification */
1103 nmtb.hdr.hwndFrom = hwnd;
1104 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1105 nmtb.hdr.code = TBN_GETBUTTONINFOA;
1107 nmtb.pszText = Buffer;
1110 if (!SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1111 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1114 TRACE("style: %x\n", nmtb.tbButton.fsStyle);
1116 /* insert button into the apropriate list */
1117 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand);
1120 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1121 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1122 btnInfo->bVirtual = FALSE;
1123 btnInfo->bRemovable = TRUE;
1124 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1125 strcpy (btnInfo->text, nmtb.pszText);
1127 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1128 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1132 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1133 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));
1134 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))
1135 strcpy (btnInfo->text, nmtb.pszText);
1137 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1141 /* select first item in the 'available' list */
1142 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
1144 /* append 'virtual' separator button to the 'toolbar buttons' list */
1145 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON));
1146 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
1147 btnInfo->btn.fsStyle = TBSTYLE_SEP;
1148 btnInfo->bVirtual = TRUE;
1149 btnInfo->bRemovable = FALSE;
1150 LoadStringA (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
1151 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
1152 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1154 /* select last item in the 'toolbar' list */
1155 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
1156 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
1158 /* set focus and disable buttons */
1159 PostMessageA (hwnd, WM_USER, 0, 0);
1164 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1165 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1166 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
1167 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
1171 EndDialog(hwnd, FALSE);
1175 switch (LOWORD(wParam))
1177 case IDC_TOOLBARBTN_LBOX:
1178 if (HIWORD(wParam) == LBN_SELCHANGE)
1180 PCUSTOMBUTTON btnInfo;
1185 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1186 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1188 /* send TBN_QUERYINSERT notification */
1189 nmtb.hdr.hwndFrom = hwnd;
1190 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1191 nmtb.hdr.code = TBN_QUERYINSERT;
1194 SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1195 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
1197 /* get list box item */
1198 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1200 if (index == (count - 1))
1202 /* last item (virtual separator) */
1203 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1204 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1206 else if (index == (count - 2))
1208 /* second last item (last non-virtual item) */
1209 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1210 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1212 else if (index == 0)
1215 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1216 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1220 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1221 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1224 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
1228 case IDC_MOVEUP_BTN:
1230 PCUSTOMBUTTON btnInfo;
1234 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1235 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1236 TRACE("Move up: index %d\n", index);
1238 /* send TBN_QUERYINSERT notification */
1239 nmtb.hdr.hwndFrom = hwnd;
1240 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1241 nmtb.hdr.code = TBN_QUERYINSERT;
1244 if (SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1245 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1247 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1249 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1250 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index-1, 0);
1251 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index-1, (LPARAM)btnInfo);
1252 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1255 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
1256 else if (index >= (count - 3))
1257 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
1259 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1260 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index-1, (LPARAM)&(btnInfo->btn));
1265 case IDC_MOVEDN_BTN: /* move down */
1267 PCUSTOMBUTTON btnInfo;
1271 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1272 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1273 TRACE("Move up: index %d\n", index);
1275 /* send TBN_QUERYINSERT notification */
1276 nmtb.hdr.hwndFrom = hwnd;
1277 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1278 nmtb.hdr.code = TBN_QUERYINSERT;
1281 if (SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1282 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1284 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1286 /* move button down */
1287 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1288 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index+1, 0);
1289 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index+1, (LPARAM)btnInfo);
1290 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index+1 , 0);
1293 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
1294 else if (index >= (count - 3))
1295 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
1297 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1298 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index+1, (LPARAM)&(btnInfo->btn));
1303 case IDC_REMOVE_BTN: /* remove button */
1305 PCUSTOMBUTTON btnInfo;
1308 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1309 TRACE("Remove: index %d\n", index);
1311 /* send TBN_QUERYDELETE notification */
1312 nmtb.hdr.hwndFrom = hwnd;
1313 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1314 nmtb.hdr.code = TBN_QUERYDELETE;
1317 if (SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1318 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1320 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
1321 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_DELETESTRING, index, 0);
1322 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index , 0);
1324 SendMessageA (custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
1326 /* insert into 'available button' list */
1327 if (!(btnInfo->btn.fsStyle & TBSTYLE_SEP))
1329 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0);
1330 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1333 COMCTL32_Free (btnInfo);
1338 case IDOK: /* Add button */
1343 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1344 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
1345 TRACE("Add: index %d\n", index);
1347 /* send TBN_QUERYINSERT notification */
1348 nmtb.hdr.hwndFrom = hwnd;
1349 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1350 nmtb.hdr.code = TBN_QUERYINSERT;
1353 if (SendMessageA (custInfo->tbInfo->hwndNotify, WM_NOTIFY,
1354 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb))
1356 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, index, 0);
1360 /* remove from 'available buttons' list */
1361 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_DELETESTRING, index, 0);
1362 if (index == count-1)
1363 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index-1 , 0);
1365 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, index , 0);
1369 PCUSTOMBUTTON btnNew;
1371 /* duplicate 'separator' button */
1372 btnNew = (PCUSTOMBUTTON)COMCTL32_Alloc (sizeof(CUSTOMBUTTON));
1373 memcpy (btnNew, btnInfo, sizeof(CUSTOMBUTTON));
1377 /* insert into 'toolbar button' list */
1378 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
1379 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_INSERTSTRING, index, 0);
1380 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
1382 SendMessageA (custInfo->tbHwnd, TB_INSERTBUTTONA, index, (LPARAM)&(btnInfo->btn));
1388 EndDialog(hwnd, FALSE);
1398 /* delete items from 'toolbar buttons' listbox*/
1399 count = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
1400 for (i = 0; i < count; i++)
1402 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
1403 COMCTL32_Free(btnInfo);
1404 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
1406 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
1409 /* delete items from 'available buttons' listbox*/
1410 count = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
1411 for (i = 0; i < count; i++)
1413 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
1414 COMCTL32_Free(btnInfo);
1415 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
1417 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
1422 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1424 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1429 COLORREF oldText = 0;
1433 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, wParam, LB_GETITEMDATA, (WPARAM)lpdis->itemID, 0);
1434 if (btnInfo == NULL)
1436 FIXME("btnInfo invalid!\n");
1440 /* set colors and select objects */
1441 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1442 if (btnInfo->bVirtual)
1443 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
1445 oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
1446 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1447 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1449 /* fill background rectangle */
1450 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
1451 lpdis->rcItem.right, lpdis->rcItem.bottom);
1453 /* calculate button and text rectangles */
1454 CopyRect (&rcButton, &lpdis->rcItem);
1455 InflateRect (&rcButton, -1, -1);
1456 CopyRect (&rcText, &rcButton);
1457 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
1458 rcText.left = rcButton.right + 2;
1460 /* draw focus rectangle */
1461 if (lpdis->itemState & ODS_FOCUS)
1462 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1465 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
1467 /* draw image and text */
1468 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0)
1469 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC,
1470 rcButton.left+3, rcButton.top+3, ILD_NORMAL);
1471 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText,
1472 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1474 /* delete objects and reset colors */
1475 SelectObject (lpdis->hDC, hOldBrush);
1476 SelectObject (lpdis->hDC, hOldPen);
1477 SetBkColor (lpdis->hDC, oldBk);
1478 SetTextColor (lpdis->hDC, oldText);
1484 case WM_MEASUREITEM:
1485 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1487 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1489 if (custInfo && custInfo->tbInfo)
1490 lpmis->itemHeight = custInfo->tbInfo->nBitmapHeight + 8;
1492 lpmis->itemHeight = 15 + 8; /* default height */
1504 /***********************************************************************
1505 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1509 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1511 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1512 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1513 INT nIndex = 0, nButtons, nCount;
1516 TRACE("hwnd=%x wParam=%x lParam=%lx\n", hwnd, wParam, lParam);
1520 if (lpAddBmp->hInst == HINST_COMMCTRL)
1522 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1524 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1526 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1531 TRACE ("adding %d internal bitmaps!\n", nButtons);
1533 /* Windows resize all the buttons to the size of a newly added standard image */
1534 if (lpAddBmp->nID & 1)
1537 /* FIXME: on windows the size of the images is 25x24 but the size of the bitmap
1538 * in rsrc is only 24x24. Fix the bitmap (how?) and then fix this
1540 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1541 MAKELPARAM((WORD)24, (WORD)24));
1542 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1543 MAKELPARAM((WORD)31, (WORD)30));
1548 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1549 MAKELPARAM((WORD)16, (WORD)16));
1550 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1551 MAKELPARAM((WORD)22, (WORD)22));
1554 TOOLBAR_CalcToolbar (hwnd);
1558 nButtons = (INT)wParam;
1562 TRACE ("adding %d bitmaps!\n", nButtons);
1565 if (!(infoPtr->himlDef)) {
1566 /* create new default image list */
1567 TRACE ("creating default image list!\n");
1570 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1571 ILC_COLOR | ILC_MASK, nButtons, 2);
1572 infoPtr->himlInt = infoPtr->himlDef;
1575 nCount = ImageList_GetImageCount(infoPtr->himlDef);
1577 /* Add bitmaps to the default image list */
1578 if (lpAddBmp->hInst == (HINSTANCE)0)
1581 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1584 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1586 /* Add system bitmaps */
1587 switch (lpAddBmp->nID)
1589 case IDB_STD_SMALL_COLOR:
1590 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1591 MAKEINTRESOURCEA(IDB_STD_SMALL));
1592 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1593 hbmLoad, CLR_DEFAULT);
1594 DeleteObject (hbmLoad);
1597 case IDB_STD_LARGE_COLOR:
1598 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1599 MAKEINTRESOURCEA(IDB_STD_LARGE));
1600 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1601 hbmLoad, CLR_DEFAULT);
1602 DeleteObject (hbmLoad);
1605 case IDB_VIEW_SMALL_COLOR:
1606 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1607 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1608 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1609 hbmLoad, CLR_DEFAULT);
1610 DeleteObject (hbmLoad);
1613 case IDB_VIEW_LARGE_COLOR:
1614 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1615 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1616 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1617 hbmLoad, CLR_DEFAULT);
1618 DeleteObject (hbmLoad);
1621 case IDB_HIST_SMALL_COLOR:
1622 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1623 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1624 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1625 hbmLoad, CLR_DEFAULT);
1626 DeleteObject (hbmLoad);
1629 case IDB_HIST_LARGE_COLOR:
1630 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1631 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1632 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1633 hbmLoad, CLR_DEFAULT);
1634 DeleteObject (hbmLoad);
1638 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1639 ERR ("invalid imagelist!\n");
1645 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1646 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1647 DeleteObject (hbmLoad);
1652 INT imagecount = ImageList_GetImageCount(infoPtr->himlDef);
1654 if (infoPtr->nNumBitmaps + nButtons != imagecount)
1656 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",
1657 infoPtr->nNumBitmaps, nCount, imagecount - nCount,
1658 infoPtr->nNumBitmaps+nButtons,imagecount);
1660 infoPtr->nNumBitmaps = imagecount;
1663 infoPtr->nNumBitmaps += nButtons;
1666 InvalidateRect(hwnd, NULL, FALSE);
1673 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1675 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1676 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1677 INT nOldButtons, nNewButtons, nAddButtons, nCount;
1679 TRACE("adding %d buttons!\n", wParam);
1681 nAddButtons = (UINT)wParam;
1682 nOldButtons = infoPtr->nNumButtons;
1683 nNewButtons = nOldButtons + nAddButtons;
1685 if (infoPtr->nNumButtons == 0) {
1687 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1690 TBUTTON_INFO *oldButtons = infoPtr->buttons;
1692 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1693 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1694 nOldButtons * sizeof(TBUTTON_INFO));
1695 COMCTL32_Free (oldButtons);
1698 infoPtr->nNumButtons = nNewButtons;
1700 /* insert new button data */
1701 for (nCount = 0; nCount < nAddButtons; nCount++) {
1702 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
1703 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
1704 btnPtr->idCommand = lpTbb[nCount].idCommand;
1705 btnPtr->fsState = lpTbb[nCount].fsState;
1706 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
1707 btnPtr->dwData = lpTbb[nCount].dwData;
1708 btnPtr->iString = lpTbb[nCount].iString;
1709 btnPtr->bHot = FALSE;
1711 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
1714 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1715 ti.cbSize = sizeof (TTTOOLINFOA);
1717 ti.uId = btnPtr->idCommand;
1719 ti.lpszText = LPSTR_TEXTCALLBACKA;
1721 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
1726 TOOLBAR_CalcToolbar (hwnd);
1728 InvalidateRect(hwnd, NULL, FALSE);
1735 TOOLBAR_AddButtonsW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1737 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1738 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1739 INT nOldButtons, nNewButtons, nAddButtons, nCount;
1741 TRACE("adding %d buttons!\n", wParam);
1743 nAddButtons = (UINT)wParam;
1744 nOldButtons = infoPtr->nNumButtons;
1745 nNewButtons = nOldButtons + nAddButtons;
1747 if (infoPtr->nNumButtons == 0) {
1749 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1752 TBUTTON_INFO *oldButtons = infoPtr->buttons;
1754 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1755 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1756 nOldButtons * sizeof(TBUTTON_INFO));
1757 COMCTL32_Free (oldButtons);
1760 infoPtr->nNumButtons = nNewButtons;
1762 /* insert new button data */
1763 for (nCount = 0; nCount < nAddButtons; nCount++) {
1764 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
1765 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
1766 btnPtr->idCommand = lpTbb[nCount].idCommand;
1767 btnPtr->fsState = lpTbb[nCount].fsState;
1768 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
1769 btnPtr->dwData = lpTbb[nCount].dwData;
1770 btnPtr->iString = lpTbb[nCount].iString;
1771 btnPtr->bHot = FALSE;
1773 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
1776 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
1777 ti.cbSize = sizeof (TTTOOLINFOW);
1779 ti.uId = btnPtr->idCommand;
1781 ti.lpszText = LPSTR_TEXTCALLBACKW;
1783 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
1788 TOOLBAR_CalcToolbar (hwnd);
1790 InvalidateRect(hwnd, NULL, FALSE);
1797 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1799 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1802 if ((wParam) && (HIWORD(lParam) == 0)) {
1805 TRACE("adding string from resource!\n");
1807 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
1810 TRACE("len=%d \"%s\"\n", len, szString);
1811 nIndex = infoPtr->nNumStrings;
1812 if (infoPtr->nNumStrings == 0) {
1814 COMCTL32_Alloc (sizeof(LPWSTR));
1817 LPWSTR *oldStrings = infoPtr->strings;
1819 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1820 memcpy (&infoPtr->strings[0], &oldStrings[0],
1821 sizeof(LPWSTR) * infoPtr->nNumStrings);
1822 COMCTL32_Free (oldStrings);
1825 lenW = MultiByteToWideChar( CP_ACP, 0, szString, -1, NULL, 0 );
1826 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
1827 MultiByteToWideChar( CP_ACP, 0, szString, -1,
1828 infoPtr->strings[infoPtr->nNumStrings], lenW );
1829 infoPtr->nNumStrings++;
1832 LPSTR p = (LPSTR)lParam;
1837 TRACE("adding string(s) from array!\n");
1839 nIndex = infoPtr->nNumStrings;
1842 TRACE("len=%d \"%s\"\n", len, p);
1844 if (infoPtr->nNumStrings == 0) {
1846 COMCTL32_Alloc (sizeof(LPWSTR));
1849 LPWSTR *oldStrings = infoPtr->strings;
1851 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1852 memcpy (&infoPtr->strings[0], &oldStrings[0],
1853 sizeof(LPWSTR) * infoPtr->nNumStrings);
1854 COMCTL32_Free (oldStrings);
1857 lenW = MultiByteToWideChar( CP_ACP, 0, p, -1, NULL, 0 );
1858 infoPtr->strings[infoPtr->nNumStrings] = COMCTL32_Alloc (sizeof(WCHAR)*lenW);
1859 MultiByteToWideChar( CP_ACP, 0, p, -1,
1860 infoPtr->strings[infoPtr->nNumStrings], lenW );
1861 infoPtr->nNumStrings++;
1872 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1874 #define MAX_RESOURCE_STRING_LENGTH 512
1875 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1878 if ((wParam) && (HIWORD(lParam) == 0)) {
1879 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
1881 TRACE("adding string from resource!\n");
1883 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
1884 szString, MAX_RESOURCE_STRING_LENGTH);
1886 TRACE("len=%d %s\n", len, debugstr_w(szString));
1887 TRACE("First char: 0x%x\n", *szString);
1888 if (szString[0] == L'|')
1890 PWSTR p = szString + 1;
1892 nIndex = infoPtr->nNumStrings;
1893 while (*p != L'|') {
1895 if (infoPtr->nNumStrings == 0) {
1897 COMCTL32_Alloc (sizeof(LPWSTR));
1900 LPWSTR *oldStrings = infoPtr->strings;
1902 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1903 memcpy (&infoPtr->strings[0], &oldStrings[0],
1904 sizeof(LPWSTR) * infoPtr->nNumStrings);
1905 COMCTL32_Free (oldStrings);
1908 len = COMCTL32_StrChrW (p, L'|') - p;
1909 TRACE("len=%d %s\n", len, debugstr_w(p));
1910 infoPtr->strings[infoPtr->nNumStrings] =
1911 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1912 lstrcpynW (infoPtr->strings[infoPtr->nNumStrings], p, len);
1913 infoPtr->nNumStrings++;
1920 nIndex = infoPtr->nNumStrings;
1921 if (infoPtr->nNumStrings == 0) {
1923 COMCTL32_Alloc (sizeof(LPWSTR));
1926 LPWSTR *oldStrings = infoPtr->strings;
1928 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1929 memcpy (&infoPtr->strings[0], &oldStrings[0],
1930 sizeof(LPWSTR) * infoPtr->nNumStrings);
1931 COMCTL32_Free (oldStrings);
1934 infoPtr->strings[infoPtr->nNumStrings] =
1935 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1936 strcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
1937 infoPtr->nNumStrings++;
1941 LPWSTR p = (LPWSTR)lParam;
1946 TRACE("adding string(s) from array!\n");
1947 nIndex = infoPtr->nNumStrings;
1951 TRACE("len=%d %s\n", len, debugstr_w(p));
1952 if (infoPtr->nNumStrings == 0) {
1954 COMCTL32_Alloc (sizeof(LPWSTR));
1957 LPWSTR *oldStrings = infoPtr->strings;
1959 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1960 memcpy (&infoPtr->strings[0], &oldStrings[0],
1961 sizeof(LPWSTR) * infoPtr->nNumStrings);
1962 COMCTL32_Free (oldStrings);
1965 infoPtr->strings[infoPtr->nNumStrings] =
1966 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1967 strcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
1968 infoPtr->nNumStrings++;
1979 TOOLBAR_AutoSize (HWND hwnd)
1981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1982 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1988 UINT uPosFlags = SWP_NOZORDER;
1990 TRACE("resize forced, style=%lx!\n", dwStyle);
1992 parent = GetParent (hwnd);
1993 GetClientRect(parent, &parent_rect);
1995 x = parent_rect.left;
1996 y = parent_rect.top;
1998 /* FIXME: we should be able to early out if nothing */
1999 /* has changed with nWidth != parent_rect width */
2001 if (dwStyle & CCS_NORESIZE) {
2002 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2007 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2008 TOOLBAR_CalcToolbar (hwnd);
2009 InvalidateRect( hwnd, NULL, TRUE );
2010 cy = infoPtr->nHeight;
2011 cx = infoPtr->nWidth;
2013 if (dwStyle & CCS_NOMOVEY) {
2014 GetWindowRect(hwnd, &window_rect);
2015 ScreenToClient(parent, (LPPOINT)&window_rect.left);
2016 y = window_rect.top;
2020 if (dwStyle & CCS_NOPARENTALIGN)
2021 uPosFlags |= SWP_NOMOVE;
2023 if (!(dwStyle & CCS_NODIVIDER))
2024 cy += GetSystemMetrics(SM_CYEDGE);
2026 if (dwStyle & WS_BORDER)
2029 cy += GetSystemMetrics(SM_CYEDGE);
2030 cx += GetSystemMetrics(SM_CYEDGE);
2033 infoPtr->bAutoSize = TRUE;
2034 SetWindowPos (hwnd, HWND_TOP, parent_rect.left - x, parent_rect.top - y,
2036 /* The following line makes sure that the infoPtr->bAutoSize is turned off after
2037 * the setwindowpos calls */
2038 infoPtr->bAutoSize = FALSE;
2045 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
2047 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2049 return infoPtr->nNumButtons;
2054 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2056 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2058 if (infoPtr == NULL) {
2059 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2060 ERR("infoPtr == NULL!\n");
2064 infoPtr->dwStructSize = (DWORD)wParam;
2071 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2073 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2074 TBUTTON_INFO *btnPtr;
2077 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2081 btnPtr = &infoPtr->buttons[nIndex];
2082 btnPtr->iBitmap = LOWORD(lParam);
2084 /* we HAVE to erase the background, the new bitmap could be */
2086 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2093 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2096 TBUTTON_INFO *btnPtr;
2099 BOOL bChecked = FALSE;
2101 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2105 btnPtr = &infoPtr->buttons[nIndex];
2107 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2110 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
2112 if (LOWORD(lParam) == FALSE)
2113 btnPtr->fsState &= ~TBSTATE_CHECKED;
2115 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2117 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2118 if (nOldIndex == nIndex)
2120 if (nOldIndex != -1)
2121 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2123 btnPtr->fsState |= TBSTATE_CHECKED;
2126 if( bChecked != LOWORD(lParam) )
2128 if (nOldIndex != -1)
2130 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
2131 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
2133 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
2136 /* FIXME: Send a WM_NOTIFY?? */
2143 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2145 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2147 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2152 TOOLBAR_Customize (HWND hwnd)
2154 CUSTDLG_INFO custInfo;
2160 custInfo.tbInfo = TOOLBAR_GetInfoPtr (hwnd);
2161 custInfo.tbHwnd = hwnd;
2163 /* send TBN_BEGINADJUST notification */
2164 nmhdr.hwndFrom = hwnd;
2165 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
2166 nmhdr.code = TBN_BEGINADJUST;
2168 SendMessageA (custInfo.tbInfo->hwndNotify, WM_NOTIFY,
2169 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
2171 if (!(hRes = FindResourceA (COMCTL32_hModule,
2172 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2176 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2179 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2180 (LPDLGTEMPLATEA)template,
2182 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2185 /* send TBN_ENDADJUST notification */
2186 nmhdr.code = TBN_ENDADJUST;
2187 SendMessageA (custInfo.tbInfo->hwndNotify, WM_NOTIFY,
2188 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
2195 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2198 INT nIndex = (INT)wParam;
2200 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2203 if ((infoPtr->hwndToolTip) &&
2204 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2207 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2208 ti.cbSize = sizeof (TTTOOLINFOA);
2210 ti.uId = infoPtr->buttons[nIndex].idCommand;
2212 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2215 if (infoPtr->nNumButtons == 1) {
2216 TRACE(" simple delete!\n");
2217 COMCTL32_Free (infoPtr->buttons);
2218 infoPtr->buttons = NULL;
2219 infoPtr->nNumButtons = 0;
2222 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2223 TRACE("complex delete! [nIndex=%d]\n", nIndex);
2225 infoPtr->nNumButtons--;
2226 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2228 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2229 nIndex * sizeof(TBUTTON_INFO));
2232 if (nIndex < infoPtr->nNumButtons) {
2233 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2234 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2237 COMCTL32_Free (oldButtons);
2240 TOOLBAR_CalcToolbar (hwnd);
2242 InvalidateRect (hwnd, NULL, TRUE);
2249 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2251 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2252 TBUTTON_INFO *btnPtr;
2256 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2260 btnPtr = &infoPtr->buttons[nIndex];
2262 bState = btnPtr->fsState & TBSTATE_ENABLED;
2264 /* update the toolbar button state */
2265 if(LOWORD(lParam) == FALSE) {
2266 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2268 btnPtr->fsState |= TBSTATE_ENABLED;
2271 /* redraw the button only if the state of the button changed */
2272 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
2274 InvalidateRect(hwnd, &btnPtr->rect,
2275 TOOLBAR_HasText(infoPtr, btnPtr));
2282 static inline LRESULT
2283 TOOLBAR_GetAnchorHighlight (HWND hwnd)
2285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2287 return infoPtr->bAnchor;
2292 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2294 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2297 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2301 return infoPtr->buttons[nIndex].iBitmap;
2305 static inline LRESULT
2306 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2308 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2313 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2316 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2317 INT nIndex = (INT)wParam;
2318 TBUTTON_INFO *btnPtr;
2320 if (infoPtr == NULL)
2326 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2329 btnPtr = &infoPtr->buttons[nIndex];
2330 lpTbb->iBitmap = btnPtr->iBitmap;
2331 lpTbb->idCommand = btnPtr->idCommand;
2332 lpTbb->fsState = btnPtr->fsState;
2333 lpTbb->fsStyle = btnPtr->fsStyle;
2334 lpTbb->dwData = btnPtr->dwData;
2335 lpTbb->iString = btnPtr->iString;
2342 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2344 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2345 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2346 TBUTTON_INFO *btnPtr;
2349 if (infoPtr == NULL)
2351 if (lpTbInfo == NULL)
2353 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2356 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2360 btnPtr = &infoPtr->buttons[nIndex];
2362 if (lpTbInfo->dwMask & TBIF_COMMAND)
2363 lpTbInfo->idCommand = btnPtr->idCommand;
2364 if (lpTbInfo->dwMask & TBIF_IMAGE)
2365 lpTbInfo->iImage = btnPtr->iBitmap;
2366 if (lpTbInfo->dwMask & TBIF_LPARAM)
2367 lpTbInfo->lParam = btnPtr->dwData;
2368 if (lpTbInfo->dwMask & TBIF_SIZE)
2369 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2370 if (lpTbInfo->dwMask & TBIF_STATE)
2371 lpTbInfo->fsState = btnPtr->fsState;
2372 if (lpTbInfo->dwMask & TBIF_STYLE)
2373 lpTbInfo->fsStyle = btnPtr->fsStyle;
2374 if (lpTbInfo->dwMask & TBIF_TEXT) {
2375 if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
2377 if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[btnPtr->iString], -1,
2378 lpTbInfo->pszText, lpTbInfo->cchText, NULL, NULL ))
2379 lpTbInfo->pszText[lpTbInfo->cchText-1] = 0;
2381 else lpTbInfo->pszText[0]=0;
2388 TOOLBAR_GetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2390 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2391 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2392 TBUTTON_INFO *btnPtr;
2395 if (infoPtr == NULL)
2397 if (lpTbInfo == NULL)
2399 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2402 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2406 btnPtr = &infoPtr->buttons[nIndex];
2408 if (lpTbInfo->dwMask & TBIF_COMMAND)
2409 lpTbInfo->idCommand = btnPtr->idCommand;
2410 if (lpTbInfo->dwMask & TBIF_IMAGE)
2411 lpTbInfo->iImage = btnPtr->iBitmap;
2412 if (lpTbInfo->dwMask & TBIF_LPARAM)
2413 lpTbInfo->lParam = btnPtr->dwData;
2414 if (lpTbInfo->dwMask & TBIF_SIZE)
2415 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2416 if (lpTbInfo->dwMask & TBIF_STATE)
2417 lpTbInfo->fsState = btnPtr->fsState;
2418 if (lpTbInfo->dwMask & TBIF_STYLE)
2419 lpTbInfo->fsStyle = btnPtr->fsStyle;
2420 if (lpTbInfo->dwMask & TBIF_TEXT) {
2421 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2422 lstrcpynW (lpTbInfo->pszText,
2423 (LPWSTR)infoPtr->strings[btnPtr->iString],
2432 TOOLBAR_GetButtonSize (HWND hwnd)
2434 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2436 return MAKELONG((WORD)infoPtr->nButtonWidth,
2437 (WORD)infoPtr->nButtonHeight);
2442 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2444 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2445 INT nIndex, nStringIndex;
2447 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2451 nStringIndex = infoPtr->buttons[nIndex].iString;
2453 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2455 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2461 return WideCharToMultiByte( CP_ACP, 0, (LPWSTR)infoPtr->strings[nStringIndex], -1,
2462 (LPSTR)lParam, 0x7fffffff, NULL, NULL ) - 1;
2467 TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2469 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2470 INT nIndex, nStringIndex;
2472 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2476 nStringIndex = infoPtr->buttons[nIndex].iString;
2478 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
2480 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2486 strcpyW ((LPWSTR)lParam, (LPWSTR)infoPtr->strings[nStringIndex]);
2488 return strlenW ((LPWSTR)infoPtr->strings[nStringIndex]);
2492 /* << TOOLBAR_GetColorScheme >> */
2496 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2498 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2500 return (LRESULT)infoPtr->himlDis;
2504 inline static LRESULT
2505 TOOLBAR_GetExtendedStyle (HWND hwnd)
2507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2509 return infoPtr->dwExStyle;
2514 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2516 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2518 return (LRESULT)infoPtr->himlHot;
2523 TOOLBAR_GetHotItem (HWND hwnd)
2525 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2527 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
2530 if (infoPtr->nHotItem < 0)
2533 return (LRESULT)infoPtr->nHotItem;
2538 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2540 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2542 return (LRESULT)infoPtr->himlDef;
2546 /* << TOOLBAR_GetInsertMark >> */
2547 /* << TOOLBAR_GetInsertMarkColor >> */
2551 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2553 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2554 TBUTTON_INFO *btnPtr;
2558 if (infoPtr == NULL)
2560 nIndex = (INT)wParam;
2561 btnPtr = &infoPtr->buttons[nIndex];
2562 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2564 lpRect = (LPRECT)lParam;
2567 if (btnPtr->fsState & TBSTATE_HIDDEN)
2570 lpRect->left = btnPtr->rect.left;
2571 lpRect->right = btnPtr->rect.right;
2572 lpRect->bottom = btnPtr->rect.bottom;
2573 lpRect->top = btnPtr->rect.top;
2580 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2582 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2583 LPSIZE lpSize = (LPSIZE)lParam;
2588 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2589 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2591 TRACE("maximum size %d x %d\n",
2592 infoPtr->rcBound.right - infoPtr->rcBound.left,
2593 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2599 /* << TOOLBAR_GetObject >> */
2600 /* << TOOLBAR_GetPadding >> */
2604 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2607 TBUTTON_INFO *btnPtr;
2611 if (infoPtr == NULL)
2613 nIndex = (INT)wParam;
2614 btnPtr = &infoPtr->buttons[nIndex];
2615 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2617 lpRect = (LPRECT)lParam;
2621 lpRect->left = btnPtr->rect.left;
2622 lpRect->right = btnPtr->rect.right;
2623 lpRect->bottom = btnPtr->rect.bottom;
2624 lpRect->top = btnPtr->rect.top;
2631 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2633 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2635 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2636 return infoPtr->nRows;
2643 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2645 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2648 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2652 return infoPtr->buttons[nIndex].fsState;
2657 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2659 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2662 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2666 return infoPtr->buttons[nIndex].fsStyle;
2671 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2673 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2675 if (infoPtr == NULL)
2678 return infoPtr->nMaxTextRows;
2683 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
2685 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2687 if (infoPtr == NULL)
2689 return infoPtr->hwndToolTip;
2694 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2696 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2698 TRACE("%s hwnd=0x%x stub!\n",
2699 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
2701 return infoPtr->bUnicode;
2705 inline static LRESULT
2706 TOOLBAR_GetVersion (HWND hwnd)
2708 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2709 return infoPtr->iVersion;
2714 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2716 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2717 TBUTTON_INFO *btnPtr;
2722 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2726 btnPtr = &infoPtr->buttons[nIndex];
2727 if (LOWORD(lParam) == FALSE)
2728 btnPtr->fsState &= ~TBSTATE_HIDDEN;
2730 btnPtr->fsState |= TBSTATE_HIDDEN;
2732 TOOLBAR_CalcToolbar (hwnd);
2734 InvalidateRect (hwnd, NULL, TRUE);
2740 inline static LRESULT
2741 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2743 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
2748 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2751 TBUTTON_INFO *btnPtr;
2754 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2758 btnPtr = &infoPtr->buttons[nIndex];
2759 if (LOWORD(lParam) == FALSE)
2760 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
2762 btnPtr->fsState |= TBSTATE_INDETERMINATE;
2764 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
2771 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2773 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2774 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2775 INT nIndex = (INT)wParam;
2776 TBUTTON_INFO *oldButtons;
2782 /* EPP: this seems to be an undocumented call (from my IE4)
2783 * I assume in that case that:
2784 * - lpTbb->iString is a string pointer (not a string index in strings[] table
2785 * - index of insertion is at the end of existing buttons
2786 * I only see this happen with nIndex == -1, but it could have a special
2787 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
2792 /* FIXME: iString == -1 is undocumented */
2793 if(lpTbb->iString && lpTbb->iString!=-1) {
2794 len = strlen((char*)lpTbb->iString) + 2;
2795 ptr = COMCTL32_Alloc(len);
2796 nIndex = infoPtr->nNumButtons;
2797 strcpy(ptr, (char*)lpTbb->iString);
2798 ptr[len - 1] = 0; /* ended by two '\0' */
2799 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
2803 ERR("lpTbb->iString is NULL\n");
2807 } else if (nIndex < 0)
2810 TRACE("inserting button index=%d\n", nIndex);
2811 if (nIndex > infoPtr->nNumButtons) {
2812 nIndex = infoPtr->nNumButtons;
2813 TRACE("adjust index=%d\n", nIndex);
2816 oldButtons = infoPtr->buttons;
2817 infoPtr->nNumButtons++;
2818 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2819 /* pre insert copy */
2821 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2822 nIndex * sizeof(TBUTTON_INFO));
2825 /* insert new button */
2826 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
2827 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
2828 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
2829 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
2830 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
2831 infoPtr->buttons[nIndex].iString = lpTbb->iString;
2833 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
2836 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2837 ti.cbSize = sizeof (TTTOOLINFOA);
2839 ti.uId = lpTbb->idCommand;
2841 ti.lpszText = LPSTR_TEXTCALLBACKA;
2843 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2847 /* post insert copy */
2848 if (nIndex < infoPtr->nNumButtons - 1) {
2849 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
2850 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
2853 COMCTL32_Free (oldButtons);
2855 TOOLBAR_CalcToolbar (hwnd);
2857 InvalidateRect (hwnd, NULL, FALSE);
2864 TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2866 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2867 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2868 INT nIndex = (INT)wParam;
2869 TBUTTON_INFO *oldButtons;
2876 TRACE("inserting button index=%d\n", nIndex);
2877 if (nIndex > infoPtr->nNumButtons) {
2878 nIndex = infoPtr->nNumButtons;
2879 TRACE("adjust index=%d\n", nIndex);
2882 oldButtons = infoPtr->buttons;
2883 infoPtr->nNumButtons++;
2884 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2885 /* pre insert copy */
2887 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2888 nIndex * sizeof(TBUTTON_INFO));
2891 /* insert new button */
2892 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
2893 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
2894 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
2895 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
2896 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
2897 infoPtr->buttons[nIndex].iString = lpTbb->iString;
2899 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
2902 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
2903 ti.cbSize = sizeof (TTTOOLINFOW);
2905 ti.uId = lpTbb->idCommand;
2907 ti.lpszText = LPSTR_TEXTCALLBACKW;
2909 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
2913 /* post insert copy */
2914 if (nIndex < infoPtr->nNumButtons - 1) {
2915 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
2916 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
2919 COMCTL32_Free (oldButtons);
2921 InvalidateRect (hwnd, NULL, FALSE);
2927 /* << TOOLBAR_InsertMarkHitTest >> */
2931 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
2933 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2936 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2940 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
2945 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
2947 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2950 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2954 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
2959 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2964 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2968 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
2973 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
2975 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2978 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2982 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
2987 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2989 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2992 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2996 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3001 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
3003 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3006 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3010 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3014 /* << TOOLBAR_LoadImages >> */
3015 /* << TOOLBAR_MapAccelerator >> */
3016 /* << TOOLBAR_MarkButton >> */
3017 /* << TOOLBAR_MoveButton >> */
3021 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
3023 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3024 TBUTTON_INFO *btnPtr;
3027 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3031 btnPtr = &infoPtr->buttons[nIndex];
3032 if (LOWORD(lParam) == FALSE)
3033 btnPtr->fsState &= ~TBSTATE_PRESSED;
3035 btnPtr->fsState |= TBSTATE_PRESSED;
3037 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr, btnPtr));
3043 /* << TOOLBAR_ReplaceBitmap >> */
3047 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3050 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3051 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
3053 if (lpSave == NULL) return 0;
3056 /* save toolbar information */
3057 FIXME("save to \"%s\" \"%s\"\n",
3058 lpSave->pszSubKey, lpSave->pszValueName);
3063 /* restore toolbar information */
3065 FIXME("restore from \"%s\" \"%s\"\n",
3066 lpSave->pszSubKey, lpSave->pszValueName);
3077 TOOLBAR_SaveRestoreW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3080 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3081 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
3087 /* save toolbar information */
3088 FIXME("save to \"%s\" \"%s\"\n",
3089 lpSave->pszSubKey, lpSave->pszValueName);
3094 /* restore toolbar information */
3096 FIXME("restore from \"%s\" \"%s\"\n",
3097 lpSave->pszSubKey, lpSave->pszValueName);
3108 TOOLBAR_SetAnchorHighlight (HWND hwnd, WPARAM wParam)
3110 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3111 BOOL bOldAnchor = infoPtr->bAnchor;
3113 infoPtr->bAnchor = (BOOL)wParam;
3115 return (LRESULT)bOldAnchor;
3120 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3122 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3124 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3127 if (infoPtr->nNumButtons > 0)
3128 WARN("%d buttons, undoc increase to bitmap size : %d-%d -> %d-%d\n",
3129 infoPtr->nNumButtons,
3130 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3131 LOWORD(lParam), HIWORD(lParam));
3133 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
3134 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
3136 /* uses image list internals directly */
3137 if (infoPtr->himlDef) {
3138 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;
3139 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;
3147 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
3149 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3150 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
3151 TBUTTON_INFO *btnPtr;
3156 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
3159 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3163 btnPtr = &infoPtr->buttons[nIndex];
3164 if (lptbbi->dwMask & TBIF_COMMAND)
3165 btnPtr->idCommand = lptbbi->idCommand;
3166 if (lptbbi->dwMask & TBIF_IMAGE)
3167 btnPtr->iBitmap = lptbbi->iImage;
3168 if (lptbbi->dwMask & TBIF_LPARAM)
3169 btnPtr->dwData = lptbbi->lParam;
3170 /* if (lptbbi->dwMask & TBIF_SIZE) */
3171 /* btnPtr->cx = lptbbi->cx; */
3172 if (lptbbi->dwMask & TBIF_STATE)
3173 btnPtr->fsState = lptbbi->fsState;
3174 if (lptbbi->dwMask & TBIF_STYLE)
3175 btnPtr->fsStyle = lptbbi->fsStyle;
3177 if (lptbbi->dwMask & TBIF_TEXT) {
3178 if ((btnPtr->iString >= 0) ||
3179 (btnPtr->iString < infoPtr->nNumStrings)) {
3180 TRACE("Ooooooch\n");
3182 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3183 INT len = lstrlenA (lptbbi->pszText);
3184 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3187 /* this is the ultimate sollution */
3188 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3197 TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3199 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3200 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3201 TBUTTON_INFO *btnPtr;
3206 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3209 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3213 btnPtr = &infoPtr->buttons[nIndex];
3214 if (lptbbi->dwMask & TBIF_COMMAND)
3215 btnPtr->idCommand = lptbbi->idCommand;
3216 if (lptbbi->dwMask & TBIF_IMAGE)
3217 btnPtr->iBitmap = lptbbi->iImage;
3218 if (lptbbi->dwMask & TBIF_LPARAM)
3219 btnPtr->dwData = lptbbi->lParam;
3220 /* if (lptbbi->dwMask & TBIF_SIZE) */
3221 /* btnPtr->cx = lptbbi->cx; */
3222 if (lptbbi->dwMask & TBIF_STATE)
3223 btnPtr->fsState = lptbbi->fsState;
3224 if (lptbbi->dwMask & TBIF_STYLE)
3225 btnPtr->fsStyle = lptbbi->fsStyle;
3227 if (lptbbi->dwMask & TBIF_TEXT) {
3228 if ((btnPtr->iString >= 0) ||
3229 (btnPtr->iString < infoPtr->nNumStrings)) {
3231 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3232 INT len = lstrlenW (lptbbi->pszText);
3233 *lpString = COMCTL32_ReAlloc (lpString, sizeof(WCHAR)*(len+1));
3236 /* this is the ultimate solution */
3237 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3246 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3248 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3250 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
3252 ERR("invalid parameter\n");
3256 /* The documentation claims you can only change the button size before
3257 * any button has been added. But this is wrong.
3258 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
3259 * it to the toolbar, and it checks that the return value is nonzero - mjm
3260 * Further testing shows that we must actually perform the change too.
3262 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3263 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3269 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3271 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3273 if (infoPtr == NULL) {
3274 TRACE("Toolbar not initialized yet?????\n");
3278 /* if setting to current values, ignore */
3279 if ((infoPtr->cxMin == (INT)LOWORD(lParam)) &&
3280 (infoPtr->cxMax == (INT)HIWORD(lParam))) {
3281 TRACE("matches current width, min=%d, max=%d, no recalc\n",
3282 infoPtr->cxMin, infoPtr->cxMax);
3286 /* save new values */
3287 infoPtr->cxMin = (INT)LOWORD(lParam);
3288 infoPtr->cxMax = (INT)HIWORD(lParam);
3290 /* if both values are 0 then we are done */
3292 TRACE("setting both min and max to 0, norecalc\n");
3296 /* otherwise we need to recalc the toolbar and in some cases
3297 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
3298 which doesn't actually draw - GA). */
3299 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
3300 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
3302 TOOLBAR_CalcToolbar (hwnd);
3304 InvalidateRect (hwnd, NULL, TRUE);
3311 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3313 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3314 INT nIndex = (INT)wParam;
3316 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3319 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3321 if (infoPtr->hwndToolTip) {
3323 FIXME("change tool tip!\n");
3331 /* << TOOLBAR_SetColorScheme >> */
3335 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3337 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3338 HIMAGELIST himlTemp;
3341 himlTemp = infoPtr->himlDis;
3342 infoPtr->himlDis = (HIMAGELIST)lParam;
3344 /* FIXME: redraw ? */
3346 return (LRESULT)himlTemp;
3351 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3353 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3356 dwTemp = infoPtr->dwDTFlags;
3357 infoPtr->dwDTFlags =
3358 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3360 return (LRESULT)dwTemp;
3365 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3367 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3370 dwTemp = infoPtr->dwExStyle;
3371 infoPtr->dwExStyle = (DWORD)lParam;
3373 return (LRESULT)dwTemp;
3378 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3380 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3381 HIMAGELIST himlTemp;
3383 himlTemp = infoPtr->himlHot;
3384 infoPtr->himlHot = (HIMAGELIST)lParam;
3386 /* FIXME: redraw ? */
3388 return (LRESULT)himlTemp;
3393 TOOLBAR_SetHotItem (HWND hwnd, WPARAM wParam)
3395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3396 INT nOldHotItem = infoPtr->nHotItem;
3397 TBUTTON_INFO *btnPtr;
3399 if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
3402 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
3405 infoPtr->nHotItem = (INT)wParam;
3406 if ((INT)wParam >=0)
3408 btnPtr = &infoPtr->buttons[(INT)wParam];
3409 btnPtr->bHot = TRUE;
3410 InvalidateRect (hwnd, &btnPtr->rect,
3411 TOOLBAR_HasText(infoPtr, btnPtr));
3415 btnPtr = &infoPtr->buttons[nOldHotItem];
3416 btnPtr->bHot = FALSE;
3417 InvalidateRect (hwnd, &btnPtr->rect,
3418 TOOLBAR_HasText(infoPtr, btnPtr));
3422 if (nOldHotItem < 0)
3425 return (LRESULT)nOldHotItem;
3430 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3432 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3433 HIMAGELIST himlTemp;
3435 himlTemp = infoPtr->himlDef;
3436 infoPtr->himlDef = (HIMAGELIST)lParam;
3438 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef);
3439 /* FIXME: redraw ? */
3441 return (LRESULT)himlTemp;
3446 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3448 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3450 infoPtr->nIndent = (INT)wParam;
3454 /* process only on indent changing */
3455 if(infoPtr->nIndent != (INT)wParam)
3457 infoPtr->nIndent = (INT)wParam;
3458 TOOLBAR_CalcToolbar (hwnd);
3459 InvalidateRect(hwnd, NULL, FALSE);
3466 /* << TOOLBAR_SetInsertMark >> */
3470 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3472 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3474 infoPtr->clrInsertMark = (COLORREF)lParam;
3476 /* FIXME : redraw ??*/
3483 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3487 if (infoPtr == NULL)
3490 infoPtr->nMaxTextRows = (INT)wParam;
3496 /* << TOOLBAR_SetPadding >> */
3500 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3507 if (infoPtr == NULL)
3509 hwndOldNotify = infoPtr->hwndNotify;
3510 infoPtr->hwndNotify = (HWND)wParam;
3512 return hwndOldNotify;
3517 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3519 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3520 LPRECT lprc = (LPRECT)lParam;
3524 if (LOWORD(wParam) > 1) {
3525 FIXME("multiple rows not supported!\n");
3528 if(infoPtr->nRows != LOWORD(wParam))
3530 infoPtr->nRows = LOWORD(wParam);
3532 /* recalculate toolbar */
3533 TOOLBAR_CalcToolbar (hwnd);
3535 /* repaint toolbar */
3536 InvalidateRect(hwnd, NULL, FALSE);
3539 /* return bounding rectangle */
3541 lprc->left = infoPtr->rcBound.left;
3542 lprc->right = infoPtr->rcBound.right;
3543 lprc->top = infoPtr->rcBound.top;
3544 lprc->bottom = infoPtr->rcBound.bottom;
3552 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3554 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3555 TBUTTON_INFO *btnPtr;
3558 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3562 btnPtr = &infoPtr->buttons[nIndex];
3564 /* process state changing if current state doesn't match new state */
3565 if(btnPtr->fsState != LOWORD(lParam))
3567 btnPtr->fsState = LOWORD(lParam);
3568 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3577 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3579 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3580 TBUTTON_INFO *btnPtr;
3583 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3587 btnPtr = &infoPtr->buttons[nIndex];
3589 /* process style change if current style doesn't match new style */
3590 if(btnPtr->fsStyle != LOWORD(lParam))
3592 btnPtr->fsStyle = LOWORD(lParam);
3593 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3596 if (infoPtr->hwndToolTip) {
3597 FIXME("change tool tip!\n");
3605 inline static LRESULT
3606 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3610 if (infoPtr == NULL)
3612 infoPtr->hwndToolTip = (HWND)wParam;
3618 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3620 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3623 TRACE("%s hwnd=0x%04x stub!\n",
3624 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3626 bTemp = infoPtr->bUnicode;
3627 infoPtr->bUnicode = (BOOL)wParam;
3634 TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
3636 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3637 INT iOldVersion = infoPtr->iVersion;
3639 infoPtr->iVersion = iVersion;
3646 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
3648 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3649 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3652 /* initialize info structure */
3653 infoPtr->nButtonHeight = 22;
3654 infoPtr->nButtonWidth = 24;
3655 infoPtr->nBitmapHeight = 15;
3656 infoPtr->nBitmapWidth = 16;
3658 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
3660 infoPtr->nMaxTextRows = 1;
3661 infoPtr->cxMin = -1;
3662 infoPtr->cxMax = -1;
3663 infoPtr->nNumBitmaps = 0;
3664 infoPtr->nNumStrings = 0;
3666 infoPtr->bCaptured = FALSE;
3667 infoPtr->bUnicode = IsWindowUnicode (hwnd);
3668 infoPtr->nButtonDown = -1;
3669 infoPtr->nOldHit = -1;
3670 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
3671 infoPtr->hwndNotify = GetParent (hwnd);
3672 infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
3673 infoPtr->dwDTFlags = (dwStyle & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE : DT_CENTER;
3674 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
3675 infoPtr->iVersion = 0;
3677 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3678 infoPtr->hFont = CreateFontIndirectA (&logFont);
3680 if (dwStyle & TBSTYLE_TOOLTIPS) {
3681 /* Create tooltip control */
3682 infoPtr->hwndToolTip =
3683 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
3684 CW_USEDEFAULT, CW_USEDEFAULT,
3685 CW_USEDEFAULT, CW_USEDEFAULT,
3688 /* Send NM_TOOLTIPSCREATED notification */
3689 if (infoPtr->hwndToolTip) {
3690 NMTOOLTIPSCREATED nmttc;
3692 nmttc.hdr.hwndFrom = hwnd;
3693 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
3694 nmttc.hdr.code = NM_TOOLTIPSCREATED;
3695 nmttc.hwndToolTips = infoPtr->hwndToolTip;
3697 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
3698 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
3702 TOOLBAR_CalcToolbar(hwnd);
3709 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
3711 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3713 /* delete tooltip control */
3714 if (infoPtr->hwndToolTip)
3715 DestroyWindow (infoPtr->hwndToolTip);
3717 /* delete button data */
3718 if (infoPtr->buttons)
3719 COMCTL32_Free (infoPtr->buttons);
3721 /* delete strings */
3722 if (infoPtr->strings) {
3724 for (i = 0; i < infoPtr->nNumStrings; i++)
3725 if (infoPtr->strings[i])
3726 COMCTL32_Free (infoPtr->strings[i]);
3728 COMCTL32_Free (infoPtr->strings);
3731 /* destroy internal image list */
3732 if (infoPtr->himlInt)
3733 ImageList_Destroy (infoPtr->himlInt);
3735 /* delete default font */
3737 DeleteObject (infoPtr->hFont);
3739 /* free toolbar info data */
3740 COMCTL32_Free (infoPtr);
3741 SetWindowLongA (hwnd, 0, 0);
3748 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
3750 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3752 if (infoPtr->bTransparent)
3753 return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
3755 return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
3760 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
3762 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3764 return infoPtr->hFont;
3769 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
3771 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3772 TBUTTON_INFO *btnPtr;
3776 pt.x = (INT)LOWORD(lParam);
3777 pt.y = (INT)HIWORD(lParam);
3778 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3781 btnPtr = &infoPtr->buttons[nHit];
3782 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3785 infoPtr->bCaptured = TRUE;
3786 infoPtr->nButtonDown = nHit;
3788 btnPtr->fsState |= TBSTATE_PRESSED;
3790 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3793 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
3794 TOOLBAR_Customize (hwnd);
3801 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
3803 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3804 TBUTTON_INFO *btnPtr;
3808 if (infoPtr->hwndToolTip)
3809 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3810 WM_LBUTTONDOWN, wParam, lParam);
3812 pt.x = (INT)LOWORD(lParam);
3813 pt.y = (INT)HIWORD(lParam);
3814 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3818 btnPtr = &infoPtr->buttons[nHit];
3819 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3822 infoPtr->nOldHit = nHit;
3824 CopyRect(&arrowRect, &btnPtr->rect);
3825 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
3827 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
3828 if ((btnPtr->fsStyle & TBSTYLE_DROPDOWN) &&
3829 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
3830 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))
3834 * this time we must force a Redraw, so the btn is
3835 * painted down before CaptureChanged repaints it up
3837 RedrawWindow(hwnd,&btnPtr->rect,0,
3838 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3840 nmtb.hdr.hwndFrom = hwnd;
3841 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
3842 nmtb.hdr.code = TBN_DROPDOWN;
3843 nmtb.iItem = btnPtr->idCommand;
3845 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
3846 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
3851 infoPtr->bCaptured = TRUE;
3852 infoPtr->nButtonDown = nHit;
3854 btnPtr->fsState |= TBSTATE_PRESSED;
3855 btnPtr->bHot = FALSE;
3857 InvalidateRect(hwnd, &btnPtr->rect,
3858 TOOLBAR_HasText(infoPtr, btnPtr));
3866 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
3868 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3869 TBUTTON_INFO *btnPtr;
3873 BOOL bSendMessage = TRUE;
3875 if (infoPtr->hwndToolTip)
3876 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3877 WM_LBUTTONUP, wParam, lParam);
3879 pt.x = (INT)LOWORD(lParam);
3880 pt.y = (INT)HIWORD(lParam);
3881 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3883 /* restore hot effect to hot button disabled by TOOLBAR_LButtonDown() */
3884 /* if the cursor is still inside of the toolbar */
3885 if((infoPtr->nHotItem >= 0) && (nHit != -1))
3886 infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
3888 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
3889 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3890 btnPtr->fsState &= ~TBSTATE_PRESSED;
3892 if (nHit == infoPtr->nButtonDown) {
3893 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
3894 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
3895 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
3896 infoPtr->nButtonDown);
3897 if (nOldIndex == infoPtr->nButtonDown)
3898 bSendMessage = FALSE;
3899 if ((nOldIndex != infoPtr->nButtonDown) &&
3901 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3902 btnPtr->fsState |= TBSTATE_CHECKED;
3905 if (btnPtr->fsState & TBSTATE_CHECKED)
3906 btnPtr->fsState &= ~TBSTATE_CHECKED;
3908 btnPtr->fsState |= TBSTATE_CHECKED;
3913 bSendMessage = FALSE;
3915 if (nOldIndex != -1)
3917 InvalidateRect(hwnd, &infoPtr->buttons[nOldIndex].rect,
3918 TOOLBAR_HasText(infoPtr, &infoPtr->buttons[nOldIndex]));
3922 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
3923 * that resets bCaptured and btn TBSTATE_PRESSED flags,
3924 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
3929 SendMessageA (GetParent(hwnd), WM_COMMAND,
3930 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
3937 TOOLBAR_CaptureChanged(HWND hwnd)
3939 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3940 TBUTTON_INFO *btnPtr;
3942 infoPtr->bCaptured = FALSE;
3944 if (infoPtr->nButtonDown >= 0)
3946 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3947 btnPtr->fsState &= ~TBSTATE_PRESSED;
3949 infoPtr->nButtonDown = -1;
3950 infoPtr->nOldHit = -1;
3952 InvalidateRect(hwnd, &btnPtr->rect, TOOLBAR_HasText(infoPtr,
3959 TOOLBAR_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
3961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3962 TBUTTON_INFO *hotBtnPtr, *btnPtr;
3964 if (infoPtr->nOldHit < 0)
3967 hotBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
3969 /* Redraw the button if the last button we were over is the hot button and it
3971 if((infoPtr->nOldHit == infoPtr->nHotItem) && (hotBtnPtr->fsState & TBSTATE_ENABLED))
3973 hotBtnPtr->bHot = FALSE;
3975 InvalidateRect (hwnd, &hotBtnPtr->rect, TOOLBAR_HasText(infoPtr,
3979 /* If the last button we were over is depressed then make it not */
3980 /* depressed and redraw it */
3981 if(infoPtr->nOldHit == infoPtr->nButtonDown)
3983 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3985 btnPtr->fsState &= ~TBSTATE_PRESSED;
3987 InvalidateRect (hwnd, &(btnPtr->rect), TRUE);
3990 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
3991 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
3997 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
3999 TBUTTON_INFO *btnPtr, *oldBtnPtr;
4000 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4003 TRACKMOUSEEVENT trackinfo;
4005 /* fill in the TRACKMOUSEEVENT struct */
4006 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4007 trackinfo.dwFlags = TME_QUERY;
4008 trackinfo.hwndTrack = hwnd;
4009 trackinfo.dwHoverTime = HOVER_DEFAULT;
4011 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4012 _TrackMouseEvent(&trackinfo);
4014 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4015 if(!(trackinfo.dwFlags & TME_LEAVE)) {
4016 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4018 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4019 /* and can properly deactivate the hot toolbar button */
4020 _TrackMouseEvent(&trackinfo);
4023 if (infoPtr->hwndToolTip)
4024 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
4025 WM_MOUSEMOVE, wParam, lParam);
4027 pt.x = (INT)LOWORD(lParam);
4028 pt.y = (INT)HIWORD(lParam);
4030 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
4032 if (infoPtr->nOldHit != nHit)
4034 /* Remove the effect of an old hot button if the button was enabled and was
4035 drawn with the hot button effect */
4036 if(infoPtr->nOldHit >= 0 && infoPtr->nOldHit == infoPtr->nHotItem &&
4037 (infoPtr->buttons[infoPtr->nOldHit].fsState & TBSTATE_ENABLED))
4039 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
4040 oldBtnPtr->bHot = FALSE;
4042 InvalidateRect (hwnd, &oldBtnPtr->rect,
4043 TOOLBAR_HasText(infoPtr, oldBtnPtr));
4046 /* It's not a separator or in nowhere. It's a hot button. */
4049 btnPtr = &infoPtr->buttons[nHit];
4050 btnPtr->bHot = TRUE;
4052 infoPtr->nHotItem = nHit;
4054 /* only enabled buttons show hot effect */
4055 if(infoPtr->buttons[nHit].fsState & TBSTATE_ENABLED)
4057 InvalidateRect(hwnd, &btnPtr->rect,
4058 TOOLBAR_HasText(infoPtr, btnPtr));
4063 if (infoPtr->bCaptured) {
4064 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
4065 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
4066 btnPtr->fsState &= ~TBSTATE_PRESSED;
4067 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4069 else if (nHit == infoPtr->nButtonDown) {
4070 btnPtr->fsState |= TBSTATE_PRESSED;
4071 InvalidateRect(hwnd, &btnPtr->rect, TRUE);
4074 infoPtr->nOldHit = nHit;
4080 inline static LRESULT
4081 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4083 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
4084 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
4086 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
4090 inline static LRESULT
4091 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
4093 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
4094 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
4096 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
4101 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4103 TOOLBAR_INFO *infoPtr;
4105 /* allocate memory for info structure */
4106 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
4107 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4110 infoPtr->dwStructSize = sizeof(TBBUTTON);
4112 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
4113 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
4114 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
4115 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
4118 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
4123 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
4125 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4129 if (dwStyle & WS_MINIMIZE)
4130 return 0; /* Nothing to do */
4132 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
4134 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
4137 if (!(dwStyle & CCS_NODIVIDER))
4139 GetWindowRect (hwnd, &rcWindow);
4140 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4141 if( dwStyle & WS_BORDER )
4142 OffsetRect (&rcWindow, 1, 1);
4143 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
4146 ReleaseDC( hwnd, hdc );
4152 inline static LRESULT
4153 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
4155 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4156 LPNMHDR lpnmh = (LPNMHDR)lParam;
4158 TRACE("passing WM_NOTIFY!\n");
4160 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
4161 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
4164 if (lpnmh->code == TTN_GETDISPINFOA) {
4165 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
4167 FIXME("retrieving ASCII string\n");
4170 else if (lpnmh->code == TTN_GETDISPINFOW) {
4171 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
4173 FIXME("retrieving UNICODE string\n");
4184 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
4186 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
4190 /* fill ps.rcPaint with a default rect */
4191 memcpy(&(ps.rcPaint), &(infoPtr->rcBound), sizeof(infoPtr->rcBound));
4193 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam;
4195 TRACE("psrect=(%d,%d)-(%d,%d)\n",
4196 ps.rcPaint.left, ps.rcPaint.top,
4197 ps.rcPaint.right, ps.rcPaint.bottom);
4199 TOOLBAR_Refresh (hwnd, hdc, &ps);
4200 if (!wParam) EndPaint (hwnd, &ps);
4207 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
4209 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4210 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
4219 /* Resize deadlock check */
4220 if (infoPtr->bAutoSize) {
4221 infoPtr->bAutoSize = FALSE;
4225 /* FIXME: optimize to only update size if the new size doesn't */
4226 /* match the current size */
4228 flags = (INT) wParam;
4230 /* FIXME for flags =
4231 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
4234 TRACE("sizing toolbar!\n");
4236 if (flags == SIZE_RESTORED) {
4237 /* width and height don't apply */
4238 parent = GetParent (hwnd);
4239 GetClientRect(parent, &parent_rect);
4240 x = parent_rect.left;
4241 y = parent_rect.top;
4243 if (dwStyle & CCS_NORESIZE) {
4244 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
4247 * this sets the working width of the toolbar, and
4248 * Calc Toolbar will not adjust it, only the height
4250 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4251 cy = infoPtr->nHeight;
4252 cx = infoPtr->nWidth;
4253 TOOLBAR_CalcToolbar (hwnd);
4254 infoPtr->nWidth = cx;
4255 infoPtr->nHeight = cy;
4258 infoPtr->nWidth = parent_rect.right - parent_rect.left;
4259 TOOLBAR_CalcToolbar (hwnd);
4260 cy = infoPtr->nHeight;
4261 cx = infoPtr->nWidth;
4263 if (dwStyle & CCS_NOMOVEY) {
4264 GetWindowRect(hwnd, &window_rect);
4265 ScreenToClient(parent, (LPPOINT)&window_rect.left);
4266 y = window_rect.top;
4270 if (dwStyle & CCS_NOPARENTALIGN) {
4271 uPosFlags |= SWP_NOMOVE;
4272 cy = infoPtr->nHeight;
4273 cx = infoPtr->nWidth;
4276 if (!(dwStyle & CCS_NODIVIDER))
4277 cy += GetSystemMetrics(SM_CYEDGE);
4279 if (dwStyle & WS_BORDER)
4282 cy += GetSystemMetrics(SM_CYEDGE);
4283 cx += GetSystemMetrics(SM_CYEDGE);
4286 SetWindowPos (hwnd, 0, parent_rect.left - x, parent_rect.top - y,
4287 cx, cy, uPosFlags | SWP_NOZORDER);
4294 TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
4296 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
4298 if (nType == GWL_STYLE) {
4299 if (lpStyle->styleNew & TBSTYLE_LIST) {
4300 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
4303 infoPtr->dwDTFlags = DT_CENTER;
4307 TOOLBAR_AutoSize (hwnd);
4309 InvalidateRect(hwnd, NULL, FALSE);
4316 static LRESULT WINAPI
4317 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4319 if (!TOOLBAR_GetInfoPtr(hwnd) && (uMsg != WM_NCCREATE))
4320 return DefWindowProcA( hwnd, uMsg, wParam, lParam );
4325 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
4327 case TB_ADDBUTTONSA:
4328 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
4330 case TB_ADDBUTTONSW:
4331 return TOOLBAR_AddButtonsW (hwnd, wParam, lParam);
4334 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
4337 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
4340 return TOOLBAR_AutoSize (hwnd);
4342 case TB_BUTTONCOUNT:
4343 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
4345 case TB_BUTTONSTRUCTSIZE:
4346 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
4348 case TB_CHANGEBITMAP:
4349 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
4351 case TB_CHECKBUTTON:
4352 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
4354 case TB_COMMANDTOINDEX:
4355 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
4358 return TOOLBAR_Customize (hwnd);
4360 case TB_DELETEBUTTON:
4361 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
4363 case TB_ENABLEBUTTON:
4364 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
4366 case TB_GETANCHORHIGHLIGHT:
4367 return TOOLBAR_GetAnchorHighlight (hwnd);
4370 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
4372 case TB_GETBITMAPFLAGS:
4373 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
4376 return TOOLBAR_GetButton (hwnd, wParam, lParam);
4378 case TB_GETBUTTONINFOA:
4379 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
4381 case TB_GETBUTTONINFOW:
4382 return TOOLBAR_GetButtonInfoW (hwnd, wParam, lParam);
4384 case TB_GETBUTTONSIZE:
4385 return TOOLBAR_GetButtonSize (hwnd);
4387 case TB_GETBUTTONTEXTA:
4388 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
4390 case TB_GETBUTTONTEXTW:
4391 return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
4393 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
4395 case TB_GETDISABLEDIMAGELIST:
4396 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
4398 case TB_GETEXTENDEDSTYLE:
4399 return TOOLBAR_GetExtendedStyle (hwnd);
4401 case TB_GETHOTIMAGELIST:
4402 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
4405 return TOOLBAR_GetHotItem (hwnd);
4407 case TB_GETIMAGELIST:
4408 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
4410 /* case TB_GETINSERTMARK: */ /* 4.71 */
4411 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
4413 case TB_GETITEMRECT:
4414 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
4417 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
4419 /* case TB_GETOBJECT: */ /* 4.71 */
4420 /* case TB_GETPADDING: */ /* 4.71 */
4423 return TOOLBAR_GetRect (hwnd, wParam, lParam);
4426 return TOOLBAR_GetRows (hwnd, wParam, lParam);
4429 return TOOLBAR_GetState (hwnd, wParam, lParam);
4432 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
4434 case TB_GETTEXTROWS:
4435 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
4437 case TB_GETTOOLTIPS:
4438 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
4440 case TB_GETUNICODEFORMAT:
4441 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
4443 case CCM_GETVERSION:
4444 return TOOLBAR_GetVersion (hwnd);
4447 return TOOLBAR_HideButton (hwnd, wParam, lParam);
4450 return TOOLBAR_HitTest (hwnd, wParam, lParam);
4452 case TB_INDETERMINATE:
4453 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
4455 case TB_INSERTBUTTONA:
4456 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
4458 case TB_INSERTBUTTONW:
4459 return TOOLBAR_InsertButtonW (hwnd, wParam, lParam);
4461 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
4463 case TB_ISBUTTONCHECKED:
4464 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
4466 case TB_ISBUTTONENABLED:
4467 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
4469 case TB_ISBUTTONHIDDEN:
4470 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
4472 case TB_ISBUTTONHIGHLIGHTED:
4473 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
4475 case TB_ISBUTTONINDETERMINATE:
4476 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
4478 case TB_ISBUTTONPRESSED:
4479 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
4481 case TB_LOADIMAGES: /* 4.70 */
4482 FIXME("missing standard imagelists\n");
4485 /* case TB_MAPACCELERATORA: */ /* 4.71 */
4486 /* case TB_MAPACCELERATORW: */ /* 4.71 */
4487 /* case TB_MARKBUTTON: */ /* 4.71 */
4488 /* case TB_MOVEBUTTON: */ /* 4.71 */
4490 case TB_PRESSBUTTON:
4491 return TOOLBAR_PressButton (hwnd, wParam, lParam);
4493 /* case TB_REPLACEBITMAP: */
4495 case TB_SAVERESTOREA:
4496 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
4498 case TB_SAVERESTOREW:
4499 return TOOLBAR_SaveRestoreW (hwnd, wParam, lParam);
4501 case TB_SETANCHORHIGHLIGHT:
4502 return TOOLBAR_SetAnchorHighlight (hwnd, wParam);
4504 case TB_SETBITMAPSIZE:
4505 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
4507 case TB_SETBUTTONINFOA:
4508 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
4510 case TB_SETBUTTONINFOW:
4511 return TOOLBAR_SetButtonInfoW (hwnd, wParam, lParam);
4513 case TB_SETBUTTONSIZE:
4514 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
4516 case TB_SETBUTTONWIDTH:
4517 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
4520 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
4522 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
4524 case TB_SETDISABLEDIMAGELIST:
4525 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
4527 case TB_SETDRAWTEXTFLAGS:
4528 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
4530 case TB_SETEXTENDEDSTYLE:
4531 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
4533 case TB_SETHOTIMAGELIST:
4534 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
4537 return TOOLBAR_SetHotItem (hwnd, wParam);
4539 case TB_SETIMAGELIST:
4540 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
4543 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
4545 /* case TB_SETINSERTMARK: */ /* 4.71 */
4547 case TB_SETINSERTMARKCOLOR:
4548 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
4550 case TB_SETMAXTEXTROWS:
4551 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
4553 /* case TB_SETPADDING: */ /* 4.71 */
4556 return TOOLBAR_SetParent (hwnd, wParam, lParam);
4559 return TOOLBAR_SetRows (hwnd, wParam, lParam);
4562 return TOOLBAR_SetState (hwnd, wParam, lParam);
4565 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
4567 case TB_SETTOOLTIPS:
4568 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
4570 case TB_SETUNICODEFORMAT:
4571 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
4573 case CCM_SETVERSION:
4574 return TOOLBAR_SetVersion (hwnd, (INT)wParam);
4580 return TOOLBAR_Create (hwnd, wParam, lParam);
4583 return TOOLBAR_Destroy (hwnd, wParam, lParam);
4586 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
4589 return TOOLBAR_GetFont (hwnd, wParam, lParam);
4591 /* case WM_KEYDOWN: */
4592 /* case WM_KILLFOCUS: */
4594 case WM_LBUTTONDBLCLK:
4595 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
4597 case WM_LBUTTONDOWN:
4598 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
4601 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
4604 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
4607 return TOOLBAR_MouseLeave (hwnd, wParam, lParam);
4609 case WM_CAPTURECHANGED:
4610 return TOOLBAR_CaptureChanged(hwnd);
4613 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
4616 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
4619 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
4622 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
4625 return TOOLBAR_Notify (hwnd, wParam, lParam);
4627 /* case WM_NOTIFYFORMAT: */
4630 return TOOLBAR_Paint (hwnd, wParam);
4633 return TOOLBAR_Size (hwnd, wParam, lParam);
4635 case WM_STYLECHANGED:
4636 return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
4638 /* case WM_SYSCOLORCHANGE: */
4640 /* case WM_WININICHANGE: */
4645 case WM_MEASUREITEM:
4647 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
4650 if (uMsg >= WM_USER)
4651 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4652 uMsg, wParam, lParam);
4653 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4660 TOOLBAR_Register (void)
4664 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4665 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4666 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
4667 wndClass.cbClsExtra = 0;
4668 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
4669 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
4670 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
4671 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
4673 RegisterClassA (&wndClass);
4678 TOOLBAR_Unregister (void)
4680 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);