Added undocumented feature to InsertButtonA.
[wine.git] / dlls / comctl32 / toolbar.c
blob1bdd373aa9a3eb8820bb14f43649c6122571a592
1 /*
2 * Toolbar control
4 * Copyright 1998,1999 Eric Kohl
6 * TODO:
7 * - A little bug in TOOLBAR_DrawMasked()
8 * - Button wrapping (under construction).
9 * - Messages.
10 * - Notifications.
11 * - Fix TB_SETROWS.
12 * - Tooltip support (almost complete).
13 * - Unicode suppport.
14 * - Fix TOOLBAR_SetButtonInfo32A.
15 * - Customize dialog (under construction).
17 * Testing:
18 * - Run tests using Waite Group Windows95 API Bible Volume 2.
19 * The second cdrom contains executables addstr.exe, btncount.exe,
20 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
21 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
22 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
23 * setparnt.exe, setrows.exe, toolwnd.exe.
24 * - Microsofts controlspy examples.
27 #include <string.h>
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "wingdi.h"
32 #include "commctrl.h"
33 #include "cache.h"
34 #include "comctl32.h"
35 #include "toolbar.h"
36 #include "debugtools.h"
38 DEFAULT_DEBUG_CHANNEL(toolbar)
40 #define SEPARATOR_WIDTH 8
41 #define TOP_BORDER 2
42 #define BOTTOM_BORDER 2
44 #define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
47 static void
48 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
50 INT x = (lpRect->left + lpRect->right) / 2 - 1;
51 INT yBottom = lpRect->bottom - 3;
52 INT yTop = lpRect->top + 1;
54 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
55 MoveToEx (hdc, x, yBottom, NULL);
56 LineTo (hdc, x, yTop);
57 x++;
58 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
59 MoveToEx (hdc, x, yBottom, NULL);
60 LineTo (hdc, x, yTop);
64 static void
65 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
66 HDC hdc, INT nState)
68 RECT rcText = btnPtr->rect;
69 HFONT hOldFont;
70 INT nOldBkMode;
71 COLORREF clrOld;
73 /* draw text */
74 if ((btnPtr->iString > -1) && (btnPtr->iString < infoPtr->nNumStrings)) {
75 InflateRect (&rcText, -3, -3);
76 rcText.top += infoPtr->nBitmapHeight;
77 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
78 OffsetRect (&rcText, 1, 1);
80 hOldFont = SelectObject (hdc, infoPtr->hFont);
81 nOldBkMode = SetBkMode (hdc, TRANSPARENT);
82 if (!(nState & TBSTATE_ENABLED)) {
83 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
84 OffsetRect (&rcText, 1, 1);
85 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
86 &rcText, infoPtr->dwDTFlags);
87 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
88 OffsetRect (&rcText, -1, -1);
89 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
90 &rcText, infoPtr->dwDTFlags);
92 else if (nState & TBSTATE_INDETERMINATE) {
93 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
94 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
95 &rcText, infoPtr->dwDTFlags);
97 else {
98 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
99 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
100 &rcText, infoPtr->dwDTFlags);
103 SetTextColor (hdc, clrOld);
104 SelectObject (hdc, hOldFont);
105 if (nOldBkMode != TRANSPARENT)
106 SetBkMode (hdc, nOldBkMode);
111 static void
112 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
114 HBRUSH hbr = SelectObject (hdc, CACHE_GetPattern55AABrush ());
115 INT cx = lpRect->right - lpRect->left;
116 INT cy = lpRect->bottom - lpRect->top;
117 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
118 SelectObject (hdc, hbr);
122 static void
123 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
124 HDC hdc, INT x, INT y)
126 /* FIXME: this function is a hack since it uses image list
127 internals directly */
129 HIMAGELIST himl = infoPtr->himlDef;
130 HBITMAP hbmMask;
131 HDC hdcImageList;
132 HDC hdcMask;
134 if (!himl)
135 return;
137 /* create new dc's */
138 hdcImageList = CreateCompatibleDC (0);
139 hdcMask = CreateCompatibleDC (0);
141 /* create new bitmap */
142 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
143 SelectObject (hdcMask, hbmMask);
145 /* copy the mask bitmap */
146 SelectObject (hdcImageList, himl->hbmMask);
147 SetBkColor (hdcImageList, RGB(255, 255, 255));
148 SetTextColor (hdcImageList, RGB(0, 0, 0));
149 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
150 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
152 #if 0
153 /* add white mask from image */
154 SelectObject (hdcImageList, himl->hbmImage);
155 SetBkColor (hdcImageList, RGB(0, 0, 0));
156 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
157 hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
158 #endif
160 /* draw the new mask */
161 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
162 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
163 hdcMask, 0, 0, 0xB8074A);
165 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
166 BitBlt (hdc, x, y, himl->cx, himl->cy,
167 hdcMask, 0, 0, 0xB8074A);
169 DeleteObject (hbmMask);
170 DeleteDC (hdcMask);
171 DeleteDC (hdcImageList);
175 static void
176 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
178 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
179 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
180 RECT rc;
182 if (btnPtr->fsState & TBSTATE_HIDDEN)
183 return;
185 rc = btnPtr->rect;
187 /* separator */
188 if (btnPtr->fsStyle & TBSTYLE_SEP) {
189 if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->iBitmap == 0))
190 TOOLBAR_DrawFlatSeparator (&rc, hdc);
191 return;
194 /* disabled */
195 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
196 if (!(dwStyle & TBSTYLE_FLAT))
197 DrawEdge (hdc, &rc, EDGE_RAISED,
198 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
200 if (infoPtr->himlDis)
201 ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
202 rc.left+1, rc.top+1, ILD_NORMAL);
203 else
204 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
206 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
207 return;
210 /* pressed TBSTYLE_BUTTON */
211 if (btnPtr->fsState & TBSTATE_PRESSED) {
212 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
213 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
214 rc.left+2, rc.top+2, ILD_NORMAL);
215 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
216 return;
219 /* checked TBSTYLE_CHECK */
220 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
221 (btnPtr->fsState & TBSTATE_CHECKED)) {
222 if (dwStyle & TBSTYLE_FLAT)
223 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
224 BF_RECT | BF_MIDDLE | BF_ADJUST);
225 else
226 DrawEdge (hdc, &rc, EDGE_SUNKEN,
227 BF_RECT | BF_MIDDLE | BF_ADJUST);
229 TOOLBAR_DrawPattern (hdc, &rc);
231 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
232 rc.left+2, rc.top+2, ILD_NORMAL);
234 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
235 return;
238 /* indeterminate */
239 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
240 DrawEdge (hdc, &rc, EDGE_RAISED,
241 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
243 TOOLBAR_DrawPattern (hdc, &rc);
244 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
245 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
246 return;
249 /* normal state */
250 if (dwStyle & TBSTYLE_FLAT)
252 if (btnPtr->bHot)
253 DrawEdge (hdc, &rc, BDR_RAISEDINNER,
254 BF_RECT | BF_MIDDLE | BF_SOFT);
255 if (btnPtr->bHot && infoPtr->himlHot)
256 ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
257 rc.left +2, rc.top +2, ILD_NORMAL);
258 else
259 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
260 rc.left +2, rc.top +2, ILD_NORMAL);
262 else
264 DrawEdge (hdc, &rc, EDGE_RAISED,
265 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
267 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
268 rc.left+1, rc.top+1, ILD_NORMAL);
271 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
275 static void
276 TOOLBAR_Refresh (HWND hwnd, HDC hdc)
278 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
279 TBUTTON_INFO *btnPtr;
280 INT i;
282 /* draw buttons */
283 btnPtr = infoPtr->buttons;
284 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
285 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
289 static void
290 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
293 TBUTTON_INFO *btnPtr;
294 INT i;
295 HDC hdc;
296 HFONT hOldFont;
297 SIZE sz;
299 lpSize->cx = 0;
300 lpSize->cy = 0;
301 hdc = GetDC (0);
302 hOldFont = SelectObject (hdc, infoPtr->hFont);
304 btnPtr = infoPtr->buttons;
305 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
306 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
307 (btnPtr->iString > -1) &&
308 (btnPtr->iString < infoPtr->nNumStrings)) {
309 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
310 GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), &sz);
311 if (sz.cx > lpSize->cx)
312 lpSize->cx = sz.cx;
313 if (sz.cy > lpSize->cy)
314 lpSize->cy = sz.cy;
318 SelectObject (hdc, hOldFont);
319 ReleaseDC (0, hdc);
321 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
324 /***********************************************************************
325 * TOOLBAR_WrapToolbar
327 * This function walks through the buttons and seperators in the
328 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
329 * wrapping should occur based on the width of the toolbar window.
330 * It does *not* calculate button placement itself. That task
331 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
332 * the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE
333 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
336 static void
337 TOOLBAR_WrapToolbar( HWND hwnd )
339 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
340 TBUTTON_INFO *btnPtr;
341 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
342 INT x, cx, i, j;
343 RECT rc;
344 BOOL bWrap, bButtonWrap;
346 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
347 /* no layout is necessary. Applications may use this style */
348 /* to perform their own layout on the toolbar. */
349 if( !(dwStyle & TBSTYLE_WRAPABLE) )
350 return;
352 btnPtr = infoPtr->buttons;
353 x = infoPtr->nIndent;
355 GetClientRect( GetParent(hwnd), &rc );
356 infoPtr->nWidth = rc.right - rc.left;
357 bButtonWrap = FALSE;
359 for (i = 0; i < infoPtr->nNumButtons; i++ )
361 bWrap = FALSE;
362 btnPtr[i].fsState &= ~TBSTATE_WRAP;
364 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
365 continue;
367 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
368 /* it is the actual width of the separator. This is used for */
369 /* custom controls in toolbars. */
370 if (btnPtr[i].fsStyle & TBSTYLE_SEP)
371 cx = (btnPtr[i].iBitmap > 0) ?
372 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
373 else
374 cx = infoPtr->nButtonWidth;
376 /* Two or more adjacent separators form a separator group. */
377 /* The first separator in a group should be wrapped to the */
378 /* next row if the previous wrapping is on a button. */
379 if( bButtonWrap &&
380 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
381 (i + 1 < infoPtr->nNumButtons ) &&
382 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
384 btnPtr[i].fsState |= TBSTATE_WRAP;
385 x = infoPtr->nIndent;
386 i++;
387 bButtonWrap = FALSE;
388 continue;
391 /* The layout makes sure the bitmap is visible, but not the button. */
392 if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
393 > infoPtr->nWidth )
395 BOOL bFound = FALSE;
397 /* If the current button is a separator and not hidden, */
398 /* go to the next until it reaches a non separator. */
399 /* Wrap the last separator if it is before a button. */
400 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
401 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
402 i < infoPtr->nNumButtons )
404 i++;
405 bFound = TRUE;
408 if( bFound && i < infoPtr->nNumButtons )
410 i--;
411 btnPtr[i].fsState |= TBSTATE_WRAP;
412 x = infoPtr->nIndent;
413 bButtonWrap = FALSE;
414 continue;
416 else if ( i >= infoPtr->nNumButtons)
417 break;
419 /* If the current button is not a separator, find the last */
420 /* separator and wrap it. */
421 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
423 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
424 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
426 bFound = TRUE;
427 i = j;
428 x = infoPtr->nIndent;
429 btnPtr[j].fsState |= TBSTATE_WRAP;
430 bButtonWrap = FALSE;
431 break;
435 /* If no separator available for wrapping, wrap one of */
436 /* non-hidden previous button. */
437 if (!bFound)
439 for ( j = i - 1;
440 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
442 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
443 continue;
445 bFound = TRUE;
446 i = j;
447 x = infoPtr->nIndent;
448 btnPtr[j].fsState |= TBSTATE_WRAP;
449 bButtonWrap = TRUE;
450 break;
454 /* If all above failed, wrap the current button. */
455 if (!bFound)
457 btnPtr[i].fsState |= TBSTATE_WRAP;
458 bFound = TRUE;
459 x = infoPtr->nIndent;
460 if (btnPtr[i].fsState & TBSTYLE_SEP )
461 bButtonWrap = FALSE;
462 else
463 bButtonWrap = TRUE;
466 else
467 x += cx;
471 /***********************************************************************
472 * TOOLBAR_CalcToolbar
474 * This function calculates button and separator placement. It first
475 * calculates the button sizes, gets the toolbar window width and then
476 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
477 * on. It assigns a new location to each item and sends this location to
478 * the tooltip window if appropriate. Finally, it updates the rcBound
479 * rect and calculates the new required toolbar window height.
482 static void
483 TOOLBAR_CalcToolbar (HWND hwnd)
485 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
486 TBUTTON_INFO *btnPtr;
487 INT i, nRows, nSepRows;
488 INT x, y, cx, cy;
489 SIZE sizeString;
490 RECT rc;
491 BOOL bWrap;
493 TOOLBAR_CalcStrings (hwnd, &sizeString);
495 if (sizeString.cy > 0)
496 infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
497 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
498 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
500 if (sizeString.cx > infoPtr->nBitmapWidth)
501 infoPtr->nButtonWidth = sizeString.cx + 6;
502 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
503 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
505 TOOLBAR_WrapToolbar( hwnd );
507 x = infoPtr->nIndent;
508 y = TOP_BORDER;
509 cx = infoPtr->nButtonWidth;
510 cy = infoPtr->nButtonHeight;
511 nRows = nSepRows = 0;
513 infoPtr->rcBound.top = y;
514 infoPtr->rcBound.left = x;
515 infoPtr->rcBound.bottom = y + cy;
516 infoPtr->rcBound.right = x;
518 btnPtr = infoPtr->buttons;
519 GetClientRect( GetParent(hwnd), &rc );
520 infoPtr->nWidth = rc.right - rc.left;
522 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
524 bWrap = FALSE;
525 if (btnPtr->fsState & TBSTATE_HIDDEN)
527 SetRectEmpty (&btnPtr->rect);
528 continue;
531 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
532 /* it is the actual width of the separator. This is used for */
533 /* custom controls in toolbars. */
534 if (btnPtr->fsStyle & TBSTYLE_SEP)
535 cx = (btnPtr->iBitmap > 0) ?
536 btnPtr->iBitmap : SEPARATOR_WIDTH;
537 else
538 cx = infoPtr->nButtonWidth;
540 if (btnPtr->fsState & TBSTATE_WRAP )
541 bWrap = TRUE;
543 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
545 if (infoPtr->rcBound.left > x)
546 infoPtr->rcBound.left = x;
547 if (infoPtr->rcBound.right < x + cx)
548 infoPtr->rcBound.right = x + cx;
549 if (infoPtr->rcBound.bottom < y + cy)
550 infoPtr->rcBound.bottom = y + cy;
552 /* Set the toolTip only for non-hidden, non-separator button */
553 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP ))
555 TTTOOLINFOA ti;
557 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
558 ti.cbSize = sizeof(TTTOOLINFOA);
559 ti.hwnd = hwnd;
560 ti.uId = btnPtr->idCommand;
561 ti.rect = btnPtr->rect;
562 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
563 0, (LPARAM)&ti);
566 /* btnPtr->nRow is zero based. The space between the rows is */
567 /* also considered as a row. */
568 btnPtr->nRow = nRows + nSepRows;
569 if( bWrap )
571 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
572 y += cy;
573 else
575 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
576 /* it is the actual width of the separator. This is used for */
577 /* custom controls in toolbars. */
578 y += cy + ( (btnPtr->iBitmap > 0 ) ?
579 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
581 /* nSepRows is used to calculate the extra height follwoing */
582 /* the last row. */
583 nSepRows++;
585 x = infoPtr->nIndent;
586 nRows++;
588 else
589 x += cx;
592 /* infoPtr->nRows is the number of rows on the toolbar */
593 infoPtr->nRows = nRows + nSepRows + 1;
595 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
596 /* the last row. */
597 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
598 nSepRows * SEPARATOR_WIDTH * 2 / 3 +
599 nSepRows * (infoPtr->nBitmapHeight + 1) +
600 BOTTOM_BORDER;
601 TRACE("toolbar height %d\n", infoPtr->nHeight);
605 static INT
606 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
608 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
609 TBUTTON_INFO *btnPtr;
610 INT i;
612 btnPtr = infoPtr->buttons;
613 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
614 if (btnPtr->fsState & TBSTATE_HIDDEN)
615 continue;
617 if (btnPtr->fsStyle & TBSTYLE_SEP) {
618 if (PtInRect (&btnPtr->rect, *lpPt)) {
619 TRACE(" ON SEPARATOR %d!\n", i);
620 return -i;
623 else {
624 if (PtInRect (&btnPtr->rect, *lpPt)) {
625 TRACE(" ON BUTTON %d!\n", i);
626 return i;
631 TRACE(" NOWHERE!\n");
632 return -1;
636 static INT
637 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
639 TBUTTON_INFO *btnPtr;
640 INT i;
642 btnPtr = infoPtr->buttons;
643 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
644 if (btnPtr->idCommand == idCommand) {
645 TRACE("command=%d index=%d\n", idCommand, i);
646 return i;
649 TRACE("no index found for command=%d\n", idCommand);
650 return -1;
654 static INT
655 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
657 TBUTTON_INFO *btnPtr;
658 INT nRunIndex;
660 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
661 return -1;
663 /* check index button */
664 btnPtr = &infoPtr->buttons[nIndex];
665 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
666 if (btnPtr->fsState & TBSTATE_CHECKED)
667 return nIndex;
670 /* check previous buttons */
671 nRunIndex = nIndex - 1;
672 while (nRunIndex >= 0) {
673 btnPtr = &infoPtr->buttons[nRunIndex];
674 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
675 if (btnPtr->fsState & TBSTATE_CHECKED)
676 return nRunIndex;
678 else
679 break;
680 nRunIndex--;
683 /* check next buttons */
684 nRunIndex = nIndex + 1;
685 while (nRunIndex < infoPtr->nNumButtons) {
686 btnPtr = &infoPtr->buttons[nRunIndex];
687 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
688 if (btnPtr->fsState & TBSTATE_CHECKED)
689 return nRunIndex;
691 else
692 break;
693 nRunIndex++;
696 return -1;
700 static VOID
701 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
702 WPARAM wParam, LPARAM lParam)
704 MSG msg;
706 msg.hwnd = hwndMsg;
707 msg.message = uMsg;
708 msg.wParam = wParam;
709 msg.lParam = lParam;
710 msg.time = GetMessageTime ();
711 msg.pt.x = LOWORD(GetMessagePos ());
712 msg.pt.y = HIWORD(GetMessagePos ());
714 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
718 /***********************************************************************
719 * TOOLBAR_CustomizeDialogProc
720 * This function implements the toolbar customization dialog.
722 static BOOL WINAPI
723 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
725 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongA (hwnd, DWL_USER);
726 static HDSA hDsa = NULL;
728 switch (uMsg)
730 case WM_INITDIALOG:
731 infoPtr = (TOOLBAR_INFO *)lParam;
732 SetWindowLongA (hwnd, DWL_USER, (DWORD)infoPtr);
734 hDsa = DSA_Create (sizeof(TBUTTON_INFO), 5);
736 if (infoPtr)
738 TBUTTON_INFO *btnPtr;
739 INT i;
741 /* insert 'virtual' separator button into 'available buttons' list */
742 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
744 /* copy all buttons and append them to the right listbox */
745 btnPtr = infoPtr->buttons;
746 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
748 DSA_InsertItem (hDsa, i, btnPtr);
750 /* FIXME: hidden buttons appear in the 'toolbar buttons' list too */
751 if (btnPtr->fsState & TBSTATE_HIDDEN)
753 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
755 else
757 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)"");
761 /* append 'virtual' separator button to the 'toolbar buttons' list */
762 /* TODO */
764 return TRUE;
766 case WM_CLOSE:
767 EndDialog(hwnd, FALSE);
768 return TRUE;
770 case WM_COMMAND:
771 switch (LOWORD(wParam))
773 case IDCANCEL:
774 EndDialog(hwnd, FALSE);
775 break;
777 return TRUE;
779 case WM_DESTROY:
780 if (hDsa)
781 DSA_Destroy (hDsa);
782 return TRUE;
784 case WM_DRAWITEM:
785 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
787 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
788 RECT rcButton;
789 RECT rcText;
790 HPEN hOldPen;
791 HBRUSH hOldBrush;
792 COLORREF oldText = 0;
793 COLORREF oldBk = 0;
795 FIXME("action: %x itemState: %x\n",
796 lpdis->itemAction, lpdis->itemState);
798 if (lpdis->itemState & ODS_FOCUS)
800 oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
801 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
804 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
805 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
807 /* fill background rectangle */
808 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
809 lpdis->rcItem.right, lpdis->rcItem.bottom);
811 /* calculate button and text rectangles */
812 CopyRect (&rcButton, &lpdis->rcItem);
813 InflateRect (&rcButton, -1, -1);
814 CopyRect (&rcText, &rcButton);
815 rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
816 rcText.left = rcButton.right + 2;
818 /* draw focus rectangle */
819 if (lpdis->itemState & ODS_FOCUS)
820 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
822 /* draw button */
823 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
825 /* FIXME: draw bitmap */
827 ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
828 rcButton.left+1, rcButton.top+1, ILD_NORMAL);
830 /* draw text */
831 if (wParam == IDC_AVAILBTN_LBOX && lpdis->itemID == 0)
833 /* virtual separator in the 'available' list */
834 DrawTextA (lpdis->hDC, "Separator", -1, &rcText,
835 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
837 else
839 /* real button */
842 if (lpdis->itemState & ODS_FOCUS)
844 SetBkColor (lpdis->hDC, oldBk);
845 SetTextColor (lpdis->hDC, oldText);
848 SelectObject (lpdis->hDC, hOldBrush);
849 SelectObject (lpdis->hDC, hOldPen);
851 return TRUE;
853 return FALSE;
855 case WM_MEASUREITEM:
856 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
858 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
860 if (infoPtr)
861 lpmis->itemHeight = infoPtr->nBitmapHeight + 8;
862 else
863 lpmis->itemHeight = 16 + 8; /* default height */
865 return TRUE;
867 return FALSE;
869 default:
870 return FALSE;
875 /***********************************************************************
876 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
879 static LRESULT
880 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
882 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
883 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
884 INT nIndex = 0, nButtons;
885 HBITMAP hbmLoad;
887 if (!lpAddBmp)
888 return -1;
890 if (lpAddBmp->hInst == HINST_COMMCTRL)
892 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
893 nButtons = 15;
894 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
895 nButtons = 13;
896 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
897 nButtons = 5;
898 else
899 return -1;
901 TRACE ("adding %d internal bitmaps!\n", nButtons);
903 /* Windows resize all the buttons to the size of a newly added standard image */
904 if (lpAddBmp->nID & 1)
906 /* large icons */
907 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
908 MAKELPARAM((WORD)26, (WORD)26));
909 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
910 MAKELPARAM((WORD)33, (WORD)33));
912 else
914 /* small icons */
915 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
916 MAKELPARAM((WORD)16, (WORD)16));
917 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
918 MAKELPARAM((WORD)22, (WORD)22));
921 TOOLBAR_CalcToolbar (hwnd);
923 else
925 nButtons = (INT)wParam;
926 if (nButtons <= 0)
927 return -1;
929 TRACE ("adding %d bitmaps!\n", nButtons);
932 if (!(infoPtr->himlDef)) {
933 /* create new default image list */
934 TRACE ("creating default image list!\n");
936 infoPtr->himlDef =
937 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
938 ILC_COLOR | ILC_MASK, nButtons, 2);
939 infoPtr->himlInt = infoPtr->himlDef;
942 /* Add bitmaps to the default image list */
943 if (lpAddBmp->hInst == (HINSTANCE)0)
945 nIndex =
946 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
947 CLR_DEFAULT);
949 else if (lpAddBmp->hInst == HINST_COMMCTRL)
951 /* Add system bitmaps */
952 switch (lpAddBmp->nID)
954 case IDB_STD_SMALL_COLOR:
955 hbmLoad = LoadBitmapA (COMCTL32_hModule,
956 MAKEINTRESOURCEA(IDB_STD_SMALL));
957 nIndex = ImageList_AddMasked (infoPtr->himlDef,
958 hbmLoad, CLR_DEFAULT);
959 DeleteObject (hbmLoad);
960 break;
962 case IDB_STD_LARGE_COLOR:
963 hbmLoad = LoadBitmapA (COMCTL32_hModule,
964 MAKEINTRESOURCEA(IDB_STD_LARGE));
965 nIndex = ImageList_AddMasked (infoPtr->himlDef,
966 hbmLoad, CLR_DEFAULT);
967 DeleteObject (hbmLoad);
968 break;
970 case IDB_VIEW_SMALL_COLOR:
971 hbmLoad = LoadBitmapA (COMCTL32_hModule,
972 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
973 nIndex = ImageList_AddMasked (infoPtr->himlDef,
974 hbmLoad, CLR_DEFAULT);
975 DeleteObject (hbmLoad);
976 break;
978 case IDB_VIEW_LARGE_COLOR:
979 hbmLoad = LoadBitmapA (COMCTL32_hModule,
980 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
981 nIndex = ImageList_AddMasked (infoPtr->himlDef,
982 hbmLoad, CLR_DEFAULT);
983 DeleteObject (hbmLoad);
984 break;
986 case IDB_HIST_SMALL_COLOR:
987 hbmLoad = LoadBitmapA (COMCTL32_hModule,
988 MAKEINTRESOURCEA(IDB_HIST_SMALL));
989 nIndex = ImageList_AddMasked (infoPtr->himlDef,
990 hbmLoad, CLR_DEFAULT);
991 DeleteObject (hbmLoad);
992 break;
994 case IDB_HIST_LARGE_COLOR:
995 hbmLoad = LoadBitmapA (COMCTL32_hModule,
996 MAKEINTRESOURCEA(IDB_HIST_LARGE));
997 nIndex = ImageList_AddMasked (infoPtr->himlDef,
998 hbmLoad, CLR_DEFAULT);
999 DeleteObject (hbmLoad);
1000 break;
1002 default:
1003 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1004 ERR ("invalid imagelist!\n");
1005 break;
1008 else
1010 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1011 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1012 DeleteObject (hbmLoad);
1015 infoPtr->nNumBitmaps += nButtons;
1017 return nIndex;
1021 static LRESULT
1022 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1024 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1025 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1026 INT nOldButtons, nNewButtons, nAddButtons, nCount;
1028 TRACE("adding %d buttons!\n", wParam);
1030 nAddButtons = (UINT)wParam;
1031 nOldButtons = infoPtr->nNumButtons;
1032 nNewButtons = nOldButtons + nAddButtons;
1034 if (infoPtr->nNumButtons == 0) {
1035 infoPtr->buttons =
1036 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1038 else {
1039 TBUTTON_INFO *oldButtons = infoPtr->buttons;
1040 infoPtr->buttons =
1041 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
1042 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1043 nOldButtons * sizeof(TBUTTON_INFO));
1044 COMCTL32_Free (oldButtons);
1047 infoPtr->nNumButtons = nNewButtons;
1049 /* insert new button data */
1050 for (nCount = 0; nCount < nAddButtons; nCount++) {
1051 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
1052 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
1053 btnPtr->idCommand = lpTbb[nCount].idCommand;
1054 btnPtr->fsState = lpTbb[nCount].fsState;
1055 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
1056 btnPtr->dwData = lpTbb[nCount].dwData;
1057 btnPtr->iString = lpTbb[nCount].iString;
1058 btnPtr->bHot = FALSE;
1060 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
1061 TTTOOLINFOA ti;
1063 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1064 ti.cbSize = sizeof (TTTOOLINFOA);
1065 ti.hwnd = hwnd;
1066 ti.uId = btnPtr->idCommand;
1067 ti.hinst = 0;
1068 ti.lpszText = LPSTR_TEXTCALLBACKA;
1070 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
1071 0, (LPARAM)&ti);
1075 TOOLBAR_CalcToolbar (hwnd);
1077 InvalidateRect(hwnd, NULL, FALSE);
1079 return TRUE;
1083 /* << TOOLBAR_AddButtons32W >> */
1086 static LRESULT
1087 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1090 INT nIndex;
1092 if ((wParam) && (HIWORD(lParam) == 0)) {
1093 char szString[256];
1094 INT len;
1095 TRACE("adding string from resource!\n");
1097 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
1098 szString, 256);
1100 TRACE("len=%d \"%s\"\n", len, szString);
1101 nIndex = infoPtr->nNumStrings;
1102 if (infoPtr->nNumStrings == 0) {
1103 infoPtr->strings =
1104 COMCTL32_Alloc (sizeof(LPWSTR));
1106 else {
1107 LPWSTR *oldStrings = infoPtr->strings;
1108 infoPtr->strings =
1109 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1110 memcpy (&infoPtr->strings[0], &oldStrings[0],
1111 sizeof(LPWSTR) * infoPtr->nNumStrings);
1112 COMCTL32_Free (oldStrings);
1115 infoPtr->strings[infoPtr->nNumStrings] =
1116 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1117 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
1118 infoPtr->nNumStrings++;
1120 else {
1121 LPSTR p = (LPSTR)lParam;
1122 INT len;
1124 if (p == NULL)
1125 return -1;
1126 TRACE("adding string(s) from array!\n");
1127 nIndex = infoPtr->nNumStrings;
1128 while (*p) {
1129 len = lstrlenA (p);
1130 TRACE("len=%d \"%s\"\n", len, p);
1132 if (infoPtr->nNumStrings == 0) {
1133 infoPtr->strings =
1134 COMCTL32_Alloc (sizeof(LPWSTR));
1136 else {
1137 LPWSTR *oldStrings = infoPtr->strings;
1138 infoPtr->strings =
1139 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1140 memcpy (&infoPtr->strings[0], &oldStrings[0],
1141 sizeof(LPWSTR) * infoPtr->nNumStrings);
1142 COMCTL32_Free (oldStrings);
1145 infoPtr->strings[infoPtr->nNumStrings] =
1146 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1147 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
1148 infoPtr->nNumStrings++;
1150 p += (len+1);
1154 return nIndex;
1158 static LRESULT
1159 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1162 INT nIndex;
1164 if ((wParam) && (HIWORD(lParam) == 0)) {
1165 WCHAR szString[256];
1166 INT len;
1167 TRACE("adding string from resource!\n");
1169 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
1170 szString, 256);
1172 TRACE("len=%d \"%s\"\n", len, debugstr_w(szString));
1173 nIndex = infoPtr->nNumStrings;
1174 if (infoPtr->nNumStrings == 0) {
1175 infoPtr->strings =
1176 COMCTL32_Alloc (sizeof(LPWSTR));
1178 else {
1179 LPWSTR *oldStrings = infoPtr->strings;
1180 infoPtr->strings =
1181 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1182 memcpy (&infoPtr->strings[0], &oldStrings[0],
1183 sizeof(LPWSTR) * infoPtr->nNumStrings);
1184 COMCTL32_Free (oldStrings);
1187 infoPtr->strings[infoPtr->nNumStrings] =
1188 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1189 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
1190 infoPtr->nNumStrings++;
1192 else {
1193 LPWSTR p = (LPWSTR)lParam;
1194 INT len;
1196 if (p == NULL)
1197 return -1;
1198 TRACE("adding string(s) from array!\n");
1199 nIndex = infoPtr->nNumStrings;
1200 while (*p) {
1201 len = lstrlenW (p);
1202 TRACE("len=%d \"%s\"\n", len, debugstr_w(p));
1204 if (infoPtr->nNumStrings == 0) {
1205 infoPtr->strings =
1206 COMCTL32_Alloc (sizeof(LPWSTR));
1208 else {
1209 LPWSTR *oldStrings = infoPtr->strings;
1210 infoPtr->strings =
1211 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1212 memcpy (&infoPtr->strings[0], &oldStrings[0],
1213 sizeof(LPWSTR) * infoPtr->nNumStrings);
1214 COMCTL32_Free (oldStrings);
1217 infoPtr->strings[infoPtr->nNumStrings] =
1218 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1219 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
1220 infoPtr->nNumStrings++;
1222 p += (len+1);
1226 return nIndex;
1230 static LRESULT
1231 TOOLBAR_AutoSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1233 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1234 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1235 RECT parent_rect;
1236 HWND parent;
1237 /* INT32 x, y; */
1238 INT cx, cy;
1239 UINT uPosFlags = 0;
1241 TRACE("resize forced!\n");
1243 parent = GetParent (hwnd);
1244 GetClientRect(parent, &parent_rect);
1246 if (dwStyle & CCS_NORESIZE) {
1247 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
1248 cx = 0;
1249 cy = 0;
1251 else {
1252 infoPtr->nWidth = parent_rect.right - parent_rect.left;
1253 TOOLBAR_CalcToolbar (hwnd);
1254 InvalidateRect( hwnd, NULL, TRUE );
1255 cy = infoPtr->nHeight;
1256 cx = infoPtr->nWidth;
1259 if (dwStyle & CCS_NOPARENTALIGN)
1260 uPosFlags |= SWP_NOMOVE;
1262 if (!(dwStyle & CCS_NODIVIDER))
1263 cy += GetSystemMetrics(SM_CYEDGE);
1265 infoPtr->bAutoSize = TRUE;
1266 SetWindowPos (hwnd, HWND_TOP, parent_rect.left, parent_rect.top,
1267 cx, cy, uPosFlags);
1269 return 0;
1273 static LRESULT
1274 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1276 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1278 return infoPtr->nNumButtons;
1282 static LRESULT
1283 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1285 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1287 if (infoPtr == NULL) {
1288 ERR("(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
1289 ERR("infoPtr == NULL!\n");
1290 return 0;
1293 infoPtr->dwStructSize = (DWORD)wParam;
1295 return 0;
1299 static LRESULT
1300 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1302 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1303 TBUTTON_INFO *btnPtr;
1304 HDC hdc;
1305 INT nIndex;
1307 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1308 if (nIndex == -1)
1309 return FALSE;
1311 btnPtr = &infoPtr->buttons[nIndex];
1312 btnPtr->iBitmap = LOWORD(lParam);
1314 hdc = GetDC (hwnd);
1315 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1316 ReleaseDC (hwnd, hdc);
1318 return TRUE;
1322 static LRESULT
1323 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1325 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1326 TBUTTON_INFO *btnPtr;
1327 HDC hdc;
1328 INT nIndex;
1329 INT nOldIndex = -1;
1331 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1332 if (nIndex == -1)
1333 return FALSE;
1335 btnPtr = &infoPtr->buttons[nIndex];
1337 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
1338 return FALSE;
1340 if (LOWORD(lParam) == FALSE)
1341 btnPtr->fsState &= ~TBSTATE_CHECKED;
1342 else {
1343 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
1344 nOldIndex =
1345 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
1346 if (nOldIndex == nIndex)
1347 return 0;
1348 if (nOldIndex != -1)
1349 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
1351 btnPtr->fsState |= TBSTATE_CHECKED;
1354 hdc = GetDC (hwnd);
1355 if (nOldIndex != -1)
1356 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
1357 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1358 ReleaseDC (hwnd, hdc);
1360 /* FIXME: Send a WM_NOTIFY?? */
1362 return TRUE;
1366 static LRESULT
1367 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
1369 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1371 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1375 static LRESULT
1376 TOOLBAR_Customize (HWND hwnd)
1378 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1379 LRESULT ret;
1380 LPCVOID template;
1381 HRSRC hRes;
1382 NMHDR nmhdr;
1384 /* send TBN_BEGINADJUST notification */
1385 nmhdr.hwndFrom = hwnd;
1386 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1387 nmhdr.code = TBN_BEGINADJUST;
1389 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
1390 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1392 if (!(hRes = FindResourceA (COMCTL32_hModule,
1393 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
1394 RT_DIALOGA)))
1395 return FALSE;
1397 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
1398 return FALSE;
1400 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
1401 (LPDLGTEMPLATEA)template,
1402 hwnd,
1403 (DLGPROC)TOOLBAR_CustomizeDialogProc,
1404 (LPARAM)infoPtr);
1406 /* send TBN_ENDADJUST notification */
1407 nmhdr.code = TBN_ENDADJUST;
1409 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
1410 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
1412 return ret;
1416 static LRESULT
1417 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1419 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1420 INT nIndex = (INT)wParam;
1422 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1423 return FALSE;
1425 if ((infoPtr->hwndToolTip) &&
1426 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
1427 TTTOOLINFOA ti;
1429 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1430 ti.cbSize = sizeof (TTTOOLINFOA);
1431 ti.hwnd = hwnd;
1432 ti.uId = infoPtr->buttons[nIndex].idCommand;
1434 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
1437 if (infoPtr->nNumButtons == 1) {
1438 TRACE(" simple delete!\n");
1439 COMCTL32_Free (infoPtr->buttons);
1440 infoPtr->buttons = NULL;
1441 infoPtr->nNumButtons = 0;
1443 else {
1444 TBUTTON_INFO *oldButtons = infoPtr->buttons;
1445 TRACE("complex delete! [nIndex=%d]\n", nIndex);
1447 infoPtr->nNumButtons--;
1448 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
1449 if (nIndex > 0) {
1450 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1451 nIndex * sizeof(TBUTTON_INFO));
1454 if (nIndex < infoPtr->nNumButtons) {
1455 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
1456 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
1459 COMCTL32_Free (oldButtons);
1462 TOOLBAR_CalcToolbar (hwnd);
1464 InvalidateRect (hwnd, NULL, TRUE);
1466 return TRUE;
1470 static LRESULT
1471 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1473 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1474 TBUTTON_INFO *btnPtr;
1475 HDC hdc;
1476 INT nIndex;
1478 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1479 if (nIndex == -1)
1480 return FALSE;
1482 btnPtr = &infoPtr->buttons[nIndex];
1483 if (LOWORD(lParam) == FALSE)
1484 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
1485 else
1486 btnPtr->fsState |= TBSTATE_ENABLED;
1488 hdc = GetDC (hwnd);
1489 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1490 ReleaseDC (hwnd, hdc);
1492 return TRUE;
1496 /* << TOOLBAR_GetAnchorHighlight >> */
1499 static LRESULT
1500 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1502 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1503 INT nIndex;
1505 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1506 if (nIndex == -1)
1507 return -1;
1509 return infoPtr->buttons[nIndex].iBitmap;
1513 static inline LRESULT
1514 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
1516 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
1520 static LRESULT
1521 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1523 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1524 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1525 INT nIndex = (INT)wParam;
1526 TBUTTON_INFO *btnPtr;
1528 if (infoPtr == NULL)
1529 return FALSE;
1531 if (lpTbb == NULL)
1532 return FALSE;
1534 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1535 return FALSE;
1537 btnPtr = &infoPtr->buttons[nIndex];
1538 lpTbb->iBitmap = btnPtr->iBitmap;
1539 lpTbb->idCommand = btnPtr->idCommand;
1540 lpTbb->fsState = btnPtr->fsState;
1541 lpTbb->fsStyle = btnPtr->fsStyle;
1542 lpTbb->dwData = btnPtr->dwData;
1543 lpTbb->iString = btnPtr->iString;
1545 return TRUE;
1549 static LRESULT
1550 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1552 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1553 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
1554 TBUTTON_INFO *btnPtr;
1555 INT nIndex;
1557 if (infoPtr == NULL)
1558 return -1;
1559 if (lpTbInfo == NULL)
1560 return -1;
1561 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
1562 return -1;
1564 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1565 if (nIndex == -1)
1566 return -1;
1568 btnPtr = &infoPtr->buttons[nIndex];
1570 if (lpTbInfo->dwMask & TBIF_COMMAND)
1571 lpTbInfo->idCommand = btnPtr->idCommand;
1572 if (lpTbInfo->dwMask & TBIF_IMAGE)
1573 lpTbInfo->iImage = btnPtr->iBitmap;
1574 if (lpTbInfo->dwMask & TBIF_LPARAM)
1575 lpTbInfo->lParam = btnPtr->dwData;
1576 if (lpTbInfo->dwMask & TBIF_SIZE)
1577 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
1578 if (lpTbInfo->dwMask & TBIF_STATE)
1579 lpTbInfo->fsState = btnPtr->fsState;
1580 if (lpTbInfo->dwMask & TBIF_STYLE)
1581 lpTbInfo->fsStyle = btnPtr->fsStyle;
1582 if (lpTbInfo->dwMask & TBIF_TEXT) {
1583 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
1584 lstrcpynA (lpTbInfo->pszText,
1585 (LPSTR)infoPtr->strings[btnPtr->iString],
1586 lpTbInfo->cchText);
1589 return nIndex;
1593 /* << TOOLBAR_GetButtonInfo32W >> */
1596 static LRESULT
1597 TOOLBAR_GetButtonSize (HWND hwnd)
1599 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1601 return MAKELONG((WORD)infoPtr->nButtonWidth,
1602 (WORD)infoPtr->nButtonHeight);
1606 static LRESULT
1607 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1609 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1610 INT nIndex, nStringIndex;
1612 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1613 if (nIndex == -1)
1614 return -1;
1616 nStringIndex = infoPtr->buttons[nIndex].iString;
1618 TRACE("index=%d stringIndex=%d\n", nIndex, nStringIndex);
1620 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
1621 return -1;
1623 if (lParam == 0) return -1;
1625 lstrcpyA ((LPSTR)lParam, (LPSTR)infoPtr->strings[nStringIndex]);
1627 return lstrlenA ((LPSTR)infoPtr->strings[nStringIndex]);
1631 /* << TOOLBAR_GetButtonText32W >> */
1632 /* << TOOLBAR_GetColorScheme >> */
1635 static LRESULT
1636 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1638 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1640 return (LRESULT)infoPtr->himlDis;
1644 inline static LRESULT
1645 TOOLBAR_GetExtendedStyle (HWND hwnd)
1647 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1649 return infoPtr->dwExStyle;
1653 static LRESULT
1654 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1656 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1658 return (LRESULT)infoPtr->himlHot;
1662 /* << TOOLBAR_GetHotItem >> */
1665 static LRESULT
1666 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1668 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1670 return (LRESULT)infoPtr->himlDef;
1674 /* << TOOLBAR_GetInsertMark >> */
1675 /* << TOOLBAR_GetInsertMarkColor >> */
1678 static LRESULT
1679 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1681 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1682 TBUTTON_INFO *btnPtr;
1683 LPRECT lpRect;
1684 INT nIndex;
1686 if (infoPtr == NULL)
1687 return FALSE;
1688 nIndex = (INT)wParam;
1689 btnPtr = &infoPtr->buttons[nIndex];
1690 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1691 return FALSE;
1692 lpRect = (LPRECT)lParam;
1693 if (lpRect == NULL)
1694 return FALSE;
1695 if (btnPtr->fsState & TBSTATE_HIDDEN)
1696 return FALSE;
1698 TOOLBAR_CalcToolbar( hwnd );
1700 lpRect->left = btnPtr->rect.left;
1701 lpRect->right = btnPtr->rect.right;
1702 lpRect->bottom = btnPtr->rect.bottom;
1703 lpRect->top = btnPtr->rect.top;
1705 return TRUE;
1709 static LRESULT
1710 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1712 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1713 LPSIZE lpSize = (LPSIZE)lParam;
1715 if (lpSize == NULL)
1716 return FALSE;
1718 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
1719 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1721 TRACE("maximum size %d x %d\n",
1722 infoPtr->rcBound.right - infoPtr->rcBound.left,
1723 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
1725 return TRUE;
1729 /* << TOOLBAR_GetObject >> */
1730 /* << TOOLBAR_GetPadding >> */
1733 static LRESULT
1734 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1736 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1737 TBUTTON_INFO *btnPtr;
1738 LPRECT lpRect;
1739 INT nIndex;
1741 if (infoPtr == NULL)
1742 return FALSE;
1743 nIndex = (INT)wParam;
1744 btnPtr = &infoPtr->buttons[nIndex];
1745 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1746 return FALSE;
1747 lpRect = (LPRECT)lParam;
1748 if (lpRect == NULL)
1749 return FALSE;
1751 lpRect->left = btnPtr->rect.left;
1752 lpRect->right = btnPtr->rect.right;
1753 lpRect->bottom = btnPtr->rect.bottom;
1754 lpRect->top = btnPtr->rect.top;
1756 return TRUE;
1760 static LRESULT
1761 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
1763 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1765 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
1766 return infoPtr->nRows;
1767 else
1768 return 1;
1772 static LRESULT
1773 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
1775 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1776 INT nIndex;
1778 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1779 if (nIndex == -1)
1780 return -1;
1782 return infoPtr->buttons[nIndex].fsState;
1786 static LRESULT
1787 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
1789 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1790 INT nIndex;
1792 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1793 if (nIndex == -1)
1794 return -1;
1796 return infoPtr->buttons[nIndex].fsStyle;
1800 static LRESULT
1801 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
1803 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1805 if (infoPtr == NULL)
1806 return 0;
1808 return infoPtr->nMaxTextRows;
1812 static LRESULT
1813 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
1815 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1817 if (infoPtr == NULL)
1818 return 0;
1819 return infoPtr->hwndToolTip;
1823 static LRESULT
1824 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1828 TRACE("%s hwnd=0x%x stub!\n",
1829 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
1831 return infoPtr->bUnicode;
1835 static LRESULT
1836 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1838 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1839 TBUTTON_INFO *btnPtr;
1840 INT nIndex;
1842 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1843 if (nIndex == -1)
1844 return FALSE;
1846 btnPtr = &infoPtr->buttons[nIndex];
1847 if (LOWORD(lParam) == FALSE)
1848 btnPtr->fsState &= ~TBSTATE_HIDDEN;
1849 else
1850 btnPtr->fsState |= TBSTATE_HIDDEN;
1852 TOOLBAR_CalcToolbar (hwnd);
1854 InvalidateRect (hwnd, NULL, TRUE);
1856 return TRUE;
1860 inline static LRESULT
1861 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1863 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
1867 static LRESULT
1868 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1870 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1871 TBUTTON_INFO *btnPtr;
1872 HDC hdc;
1873 INT nIndex;
1875 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1876 if (nIndex == -1)
1877 return FALSE;
1879 btnPtr = &infoPtr->buttons[nIndex];
1880 if (LOWORD(lParam) == FALSE)
1881 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
1882 else
1883 btnPtr->fsState |= TBSTATE_INDETERMINATE;
1885 hdc = GetDC (hwnd);
1886 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1887 ReleaseDC (hwnd, hdc);
1889 return TRUE;
1893 static LRESULT
1894 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1896 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1897 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1898 INT nIndex = (INT)wParam;
1899 TBUTTON_INFO *oldButtons;
1901 if (lpTbb == NULL)
1902 return FALSE;
1904 if (nIndex == -1) {
1905 /* EPP: this seems to be an undocumented call (from my IE4)
1906 * I assume in that case that:
1907 * - lpTbb->iString is a string pointer (not a string index in strings[] table
1908 * - index of insertion is at the end of existing buttons
1909 * I only see this happen with nIndex == -1, but it could have a special
1910 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
1912 int len = lstrlenA((char*)lpTbb->iString) + 2;
1913 LPSTR ptr = COMCTL32_Alloc(len);
1915 nIndex = infoPtr->nNumButtons;
1916 strcpy(ptr, (char*)lpTbb->iString);
1917 ptr[len - 1] = 0; /* ended by two '\0' */
1918 lpTbb->iString = TOOLBAR_AddStringA(hwnd, 0, (LPARAM)ptr);
1919 COMCTL32_Free(ptr);
1921 } else if (nIndex < 0)
1922 return FALSE;
1924 TRACE("inserting button index=%d\n", nIndex);
1925 if (nIndex > infoPtr->nNumButtons) {
1926 nIndex = infoPtr->nNumButtons;
1927 TRACE("adjust index=%d\n", nIndex);
1930 oldButtons = infoPtr->buttons;
1931 infoPtr->nNumButtons++;
1932 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
1933 /* pre insert copy */
1934 if (nIndex > 0) {
1935 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1936 nIndex * sizeof(TBUTTON_INFO));
1939 /* insert new button */
1940 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
1941 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
1942 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
1943 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
1944 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
1945 infoPtr->buttons[nIndex].iString = lpTbb->iString;
1947 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
1948 TTTOOLINFOA ti;
1950 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1951 ti.cbSize = sizeof (TTTOOLINFOA);
1952 ti.hwnd = hwnd;
1953 ti.uId = lpTbb->idCommand;
1954 ti.hinst = 0;
1955 ti.lpszText = LPSTR_TEXTCALLBACKA;
1957 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
1958 0, (LPARAM)&ti);
1961 /* post insert copy */
1962 if (nIndex < infoPtr->nNumButtons - 1) {
1963 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
1964 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
1967 COMCTL32_Free (oldButtons);
1969 TOOLBAR_CalcToolbar (hwnd);
1971 InvalidateRect (hwnd, NULL, FALSE);
1973 return TRUE;
1977 /* << TOOLBAR_InsertButton32W >> */
1978 /* << TOOLBAR_InsertMarkHitTest >> */
1981 static LRESULT
1982 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
1984 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1985 INT nIndex;
1987 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1988 if (nIndex == -1)
1989 return FALSE;
1991 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
1995 static LRESULT
1996 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
1998 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1999 INT nIndex;
2001 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2002 if (nIndex == -1)
2003 return FALSE;
2005 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
2009 static LRESULT
2010 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
2012 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2013 INT nIndex;
2015 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2016 if (nIndex == -1)
2017 return FALSE;
2019 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
2023 static LRESULT
2024 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
2026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2027 INT nIndex;
2029 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2030 if (nIndex == -1)
2031 return FALSE;
2033 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
2037 static LRESULT
2038 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2040 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2041 INT nIndex;
2043 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2044 if (nIndex == -1)
2045 return FALSE;
2047 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
2051 static LRESULT
2052 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
2054 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2055 INT nIndex;
2057 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2058 if (nIndex == -1)
2059 return FALSE;
2061 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
2065 /* << TOOLBAR_LoadImages >> */
2066 /* << TOOLBAR_MapAccelerator >> */
2067 /* << TOOLBAR_MarkButton >> */
2068 /* << TOOLBAR_MoveButton >> */
2071 static LRESULT
2072 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2074 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2075 TBUTTON_INFO *btnPtr;
2076 HDC hdc;
2077 INT nIndex;
2079 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2080 if (nIndex == -1)
2081 return FALSE;
2083 btnPtr = &infoPtr->buttons[nIndex];
2084 if (LOWORD(lParam) == FALSE)
2085 btnPtr->fsState &= ~TBSTATE_PRESSED;
2086 else
2087 btnPtr->fsState |= TBSTATE_PRESSED;
2089 hdc = GetDC (hwnd);
2090 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2091 ReleaseDC (hwnd, hdc);
2093 return TRUE;
2097 /* << TOOLBAR_ReplaceBitmap >> */
2100 static LRESULT
2101 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2103 #if 0
2104 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2105 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
2107 if (lpSave == NULL) return 0;
2109 if ((BOOL)wParam) {
2110 /* save toolbar information */
2111 FIXME("save to \"%s\" \"%s\"\n",
2112 lpSave->pszSubKey, lpSave->pszValueName);
2116 else {
2117 /* restore toolbar information */
2119 FIXME("restore from \"%s\" \"%s\"\n",
2120 lpSave->pszSubKey, lpSave->pszValueName);
2124 #endif
2126 return 0;
2130 /* << TOOLBAR_SaveRestore32W >> */
2131 /* << TOOLBAR_SetAnchorHighlight >> */
2134 static LRESULT
2135 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2137 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2139 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
2140 return FALSE;
2142 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
2143 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
2145 return TRUE;
2149 static LRESULT
2150 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2152 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2153 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
2154 TBUTTON_INFO *btnPtr;
2155 INT nIndex;
2157 if (lptbbi == NULL)
2158 return FALSE;
2159 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
2160 return FALSE;
2162 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2163 if (nIndex == -1)
2164 return FALSE;
2166 btnPtr = &infoPtr->buttons[nIndex];
2167 if (lptbbi->dwMask & TBIF_COMMAND)
2168 btnPtr->idCommand = lptbbi->idCommand;
2169 if (lptbbi->dwMask & TBIF_IMAGE)
2170 btnPtr->iBitmap = lptbbi->iImage;
2171 if (lptbbi->dwMask & TBIF_LPARAM)
2172 btnPtr->dwData = lptbbi->lParam;
2173 /* if (lptbbi->dwMask & TBIF_SIZE) */
2174 /* btnPtr->cx = lptbbi->cx; */
2175 if (lptbbi->dwMask & TBIF_STATE)
2176 btnPtr->fsState = lptbbi->fsState;
2177 if (lptbbi->dwMask & TBIF_STYLE)
2178 btnPtr->fsStyle = lptbbi->fsStyle;
2180 if (lptbbi->dwMask & TBIF_TEXT) {
2181 if ((btnPtr->iString >= 0) ||
2182 (btnPtr->iString < infoPtr->nNumStrings)) {
2183 TRACE("Ooooooch\n");
2184 #if 0
2185 CHAR **lpString = &infoPtr->strings[btnPtr->iString];
2186 INT len = lstrlenA (lptbbi->pszText);
2187 *lpString = COMCTL32_ReAlloc (lpString, sizeof(char)*(len+1));
2188 #endif
2190 /* this is the ultimate sollution */
2191 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
2195 return TRUE;
2199 /* << TOOLBAR_SetButtonInfo32W >> */
2202 static LRESULT
2203 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2207 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
2208 return FALSE;
2210 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
2211 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
2213 return TRUE;
2217 static LRESULT
2218 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
2220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2222 if (infoPtr == NULL)
2223 return FALSE;
2225 infoPtr->cxMin = (INT)LOWORD(lParam);
2226 infoPtr->cxMax = (INT)HIWORD(lParam);
2228 return TRUE;
2232 static LRESULT
2233 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
2235 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2236 INT nIndex = (INT)wParam;
2238 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2239 return FALSE;
2241 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
2243 if (infoPtr->hwndToolTip) {
2245 FIXME("change tool tip!\n");
2249 return TRUE;
2253 /* << TOOLBAR_SetColorScheme >> */
2256 static LRESULT
2257 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2259 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2260 HIMAGELIST himlTemp;
2262 himlTemp = infoPtr->himlDis;
2263 infoPtr->himlDis = (HIMAGELIST)lParam;
2265 /* FIXME: redraw ? */
2267 return (LRESULT)himlTemp;
2271 static LRESULT
2272 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2275 DWORD dwTemp;
2277 dwTemp = infoPtr->dwDTFlags;
2278 infoPtr->dwDTFlags =
2279 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
2281 return (LRESULT)dwTemp;
2285 static LRESULT
2286 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2288 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2289 DWORD dwTemp;
2291 dwTemp = infoPtr->dwExStyle;
2292 infoPtr->dwExStyle = (DWORD)lParam;
2294 return (LRESULT)dwTemp;
2298 static LRESULT
2299 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2301 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
2302 HIMAGELIST himlTemp;
2304 himlTemp = infoPtr->himlHot;
2305 infoPtr->himlHot = (HIMAGELIST)lParam;
2307 /* FIXME: redraw ? */
2309 return (LRESULT)himlTemp;
2313 /* << TOOLBAR_SetHotItem >> */
2316 static LRESULT
2317 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2319 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2320 HIMAGELIST himlTemp;
2322 himlTemp = infoPtr->himlDef;
2323 infoPtr->himlDef = (HIMAGELIST)lParam;
2325 /* FIXME: redraw ? */
2327 return (LRESULT)himlTemp;
2331 static LRESULT
2332 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
2334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2336 infoPtr->nIndent = (INT)wParam;
2338 TOOLBAR_CalcToolbar (hwnd);
2340 InvalidateRect(hwnd, NULL, FALSE);
2342 return TRUE;
2346 /* << TOOLBAR_SetInsertMark >> */
2349 static LRESULT
2350 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
2352 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2354 infoPtr->clrInsertMark = (COLORREF)lParam;
2356 /* FIXME : redraw ??*/
2358 return 0;
2362 static LRESULT
2363 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2365 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2367 if (infoPtr == NULL)
2368 return FALSE;
2370 infoPtr->nMaxTextRows = (INT)wParam;
2372 return TRUE;
2376 /* << TOOLBAR_SetPadding >> */
2379 static LRESULT
2380 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
2382 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2383 HWND hwndOldNotify;
2385 if (infoPtr == NULL)
2386 return 0;
2387 hwndOldNotify = infoPtr->hwndNotify;
2388 infoPtr->hwndNotify = (HWND)wParam;
2390 return hwndOldNotify;
2394 static LRESULT
2395 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2397 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2398 LPRECT lprc = (LPRECT)lParam;
2400 if (LOWORD(wParam) > 1) {
2402 FIXME("multiple rows not supported!\n");
2406 /* recalculate toolbar */
2407 TOOLBAR_CalcToolbar (hwnd);
2409 /* return bounding rectangle */
2410 if (lprc) {
2411 lprc->left = infoPtr->rcBound.left;
2412 lprc->right = infoPtr->rcBound.right;
2413 lprc->top = infoPtr->rcBound.top;
2414 lprc->bottom = infoPtr->rcBound.bottom;
2417 /* repaint toolbar */
2418 InvalidateRect(hwnd, NULL, FALSE);
2420 return 0;
2424 static LRESULT
2425 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2427 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2428 TBUTTON_INFO *btnPtr;
2429 HDC hdc;
2430 INT nIndex;
2432 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2433 if (nIndex == -1)
2434 return FALSE;
2436 btnPtr = &infoPtr->buttons[nIndex];
2437 btnPtr->fsState = LOWORD(lParam);
2439 hdc = GetDC (hwnd);
2440 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2441 ReleaseDC (hwnd, hdc);
2443 return TRUE;
2447 static LRESULT
2448 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2450 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2451 TBUTTON_INFO *btnPtr;
2452 HDC hdc;
2453 INT nIndex;
2455 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2456 if (nIndex == -1)
2457 return FALSE;
2459 btnPtr = &infoPtr->buttons[nIndex];
2460 btnPtr->fsStyle = LOWORD(lParam);
2462 hdc = GetDC (hwnd);
2463 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2464 ReleaseDC (hwnd, hdc);
2466 if (infoPtr->hwndToolTip) {
2468 FIXME("change tool tip!\n");
2472 return TRUE;
2476 inline static LRESULT
2477 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
2479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2481 if (infoPtr == NULL)
2482 return 0;
2483 infoPtr->hwndToolTip = (HWND)wParam;
2484 return 0;
2488 static LRESULT
2489 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2491 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2492 BOOL bTemp;
2494 TRACE("%s hwnd=0x%04x stub!\n",
2495 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
2497 bTemp = infoPtr->bUnicode;
2498 infoPtr->bUnicode = (BOOL)wParam;
2500 return bTemp;
2504 static LRESULT
2505 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
2507 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2508 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2509 LOGFONTA logFont;
2511 /* initialize info structure */
2512 infoPtr->nButtonHeight = 22;
2513 infoPtr->nButtonWidth = 23;
2514 infoPtr->nBitmapHeight = 15;
2515 infoPtr->nBitmapWidth = 16;
2517 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
2518 infoPtr->nRows = 1;
2519 infoPtr->nMaxTextRows = 1;
2520 infoPtr->cxMin = -1;
2521 infoPtr->cxMax = -1;
2523 infoPtr->bCaptured = FALSE;
2524 infoPtr->bUnicode = IsWindowUnicode (hwnd);
2525 infoPtr->nButtonDown = -1;
2526 infoPtr->nOldHit = -1;
2527 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
2528 infoPtr->hwndNotify = GetParent (hwnd);
2529 infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
2530 infoPtr->dwDTFlags = DT_CENTER;
2532 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
2533 infoPtr->hFont = CreateFontIndirectA (&logFont);
2535 if (dwStyle & TBSTYLE_TOOLTIPS) {
2536 /* Create tooltip control */
2537 infoPtr->hwndToolTip =
2538 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
2539 CW_USEDEFAULT, CW_USEDEFAULT,
2540 CW_USEDEFAULT, CW_USEDEFAULT,
2541 hwnd, 0, 0, 0);
2543 /* Send NM_TOOLTIPSCREATED notification */
2544 if (infoPtr->hwndToolTip) {
2545 NMTOOLTIPSCREATED nmttc;
2547 nmttc.hdr.hwndFrom = hwnd;
2548 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
2549 nmttc.hdr.code = NM_TOOLTIPSCREATED;
2550 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2552 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
2553 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
2557 return 0;
2561 static LRESULT
2562 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2564 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2566 /* delete tooltip control */
2567 if (infoPtr->hwndToolTip)
2568 DestroyWindow (infoPtr->hwndToolTip);
2570 /* delete button data */
2571 if (infoPtr->buttons)
2572 COMCTL32_Free (infoPtr->buttons);
2574 /* delete strings */
2575 if (infoPtr->strings) {
2576 INT i;
2577 for (i = 0; i < infoPtr->nNumStrings; i++)
2578 if (infoPtr->strings[i])
2579 COMCTL32_Free (infoPtr->strings[i]);
2581 COMCTL32_Free (infoPtr->strings);
2584 /* destroy internal image list */
2585 if (infoPtr->himlInt)
2586 ImageList_Destroy (infoPtr->himlInt);
2588 /* delete default font */
2589 if (infoPtr->hFont)
2590 DeleteObject (infoPtr->hFont);
2592 /* free toolbar info data */
2593 COMCTL32_Free (infoPtr);
2595 return 0;
2599 static LRESULT
2600 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
2602 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2604 if (infoPtr->bTransparent)
2605 return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
2607 return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
2611 static LRESULT
2612 TOOLBAR_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
2614 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2616 return infoPtr->hFont;
2620 static LRESULT
2621 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
2623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2624 TBUTTON_INFO *btnPtr;
2625 POINT pt;
2626 INT nHit;
2627 HDC hdc;
2629 pt.x = (INT)LOWORD(lParam);
2630 pt.y = (INT)HIWORD(lParam);
2631 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2633 if (nHit >= 0) {
2634 btnPtr = &infoPtr->buttons[nHit];
2635 if (!(btnPtr->fsState & TBSTATE_ENABLED))
2636 return 0;
2637 SetCapture (hwnd);
2638 infoPtr->bCaptured = TRUE;
2639 infoPtr->nButtonDown = nHit;
2641 btnPtr->fsState |= TBSTATE_PRESSED;
2643 hdc = GetDC (hwnd);
2644 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2645 ReleaseDC (hwnd, hdc);
2647 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
2648 TOOLBAR_Customize (hwnd);
2650 return 0;
2654 static LRESULT
2655 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
2657 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2658 TBUTTON_INFO *btnPtr;
2659 POINT pt;
2660 INT nHit;
2661 HDC hdc;
2663 if (infoPtr->hwndToolTip)
2664 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2665 WM_LBUTTONDOWN, wParam, lParam);
2667 pt.x = (INT)LOWORD(lParam);
2668 pt.y = (INT)HIWORD(lParam);
2669 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2671 if (nHit >= 0) {
2672 btnPtr = &infoPtr->buttons[nHit];
2673 if (!(btnPtr->fsState & TBSTATE_ENABLED))
2674 return 0;
2676 SetCapture (hwnd);
2677 infoPtr->bCaptured = TRUE;
2678 infoPtr->nButtonDown = nHit;
2679 infoPtr->nOldHit = nHit;
2681 btnPtr->fsState |= TBSTATE_PRESSED;
2683 hdc = GetDC (hwnd);
2684 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2685 ReleaseDC (hwnd, hdc);
2688 return 0;
2691 static LRESULT
2692 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
2694 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2695 TBUTTON_INFO *btnPtr;
2696 POINT pt;
2697 INT nHit;
2698 INT nOldIndex = -1;
2699 HDC hdc;
2700 BOOL bSendMessage = TRUE;
2702 if (infoPtr->hwndToolTip)
2703 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2704 WM_LBUTTONUP, wParam, lParam);
2706 pt.x = (INT)LOWORD(lParam);
2707 pt.y = (INT)HIWORD(lParam);
2708 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2710 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
2711 infoPtr->bCaptured = FALSE;
2712 ReleaseCapture ();
2713 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
2714 btnPtr->fsState &= ~TBSTATE_PRESSED;
2716 if (nHit == infoPtr->nButtonDown) {
2717 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
2718 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2719 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
2720 infoPtr->nButtonDown);
2721 if (nOldIndex == infoPtr->nButtonDown)
2722 bSendMessage = FALSE;
2723 if ((nOldIndex != infoPtr->nButtonDown) &&
2724 (nOldIndex != -1))
2725 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2726 btnPtr->fsState |= TBSTATE_CHECKED;
2728 else {
2729 if (btnPtr->fsState & TBSTATE_CHECKED)
2730 btnPtr->fsState &= ~TBSTATE_CHECKED;
2731 else
2732 btnPtr->fsState |= TBSTATE_CHECKED;
2736 else
2737 bSendMessage = FALSE;
2739 hdc = GetDC (hwnd);
2740 if (nOldIndex != -1)
2741 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
2742 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2743 ReleaseDC (hwnd, hdc);
2745 if (bSendMessage) {
2746 SendMessageA (GetParent(hwnd), WM_COMMAND,
2747 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
2749 if ((GetWindowLongA(hwnd, GWL_STYLE) & TBSTYLE_DROPDOWN) ||
2750 (btnPtr->fsStyle & 0x08/* BTNS_DROPDOWN */)) {
2751 NMTOOLBARW nmtb;
2753 nmtb.hdr.hwndFrom = hwnd;
2754 nmtb.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
2755 nmtb.hdr.code = TBN_DROPDOWN;
2756 nmtb.iItem = nHit;
2757 /* nmtb.tbButton not used with TBN_DROPDOWN */
2758 if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings)) {
2759 nmtb.pszText = infoPtr->strings[btnPtr->iString];
2760 nmtb.cchText = lstrlenW(nmtb.pszText);
2761 } else {
2762 nmtb.pszText = NULL;
2763 nmtb.cchText = 0;
2765 nmtb.rcButton = btnPtr->rect;
2767 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
2768 (WPARAM)nmtb.hdr.idFrom, (LPARAM)&nmtb);
2771 infoPtr->nButtonDown = -1;
2772 infoPtr->nOldHit = -1;
2775 return 0;
2779 static LRESULT
2780 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
2782 TBUTTON_INFO *btnPtr, *oldBtnPtr;
2783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2784 POINT pt;
2785 INT nHit;
2786 HDC hdc;
2788 if (infoPtr->hwndToolTip)
2789 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2790 WM_MOUSEMOVE, wParam, lParam);
2792 pt.x = (INT)LOWORD(lParam);
2793 pt.y = (INT)HIWORD(lParam);
2795 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2797 if (infoPtr->nOldHit != nHit)
2799 /* Remove the effect of an old hot button */
2800 if(infoPtr->nOldHit == infoPtr->nHotItem)
2802 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
2803 oldBtnPtr->bHot = FALSE;
2805 InvalidateRect (hwnd, &oldBtnPtr->rect, TRUE);
2808 /* It's not a separator or in nowhere. It's a hot button. */
2809 if (nHit >= 0)
2811 btnPtr = &infoPtr->buttons[nHit];
2812 btnPtr->bHot = TRUE;
2814 hdc = GetDC (hwnd);
2815 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2816 ReleaseDC (hwnd, hdc);
2818 infoPtr->nHotItem = nHit;
2821 if (infoPtr->bCaptured) {
2822 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
2823 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
2824 btnPtr->fsState &= ~TBSTATE_PRESSED;
2825 hdc = GetDC (hwnd);
2826 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2827 ReleaseDC (hwnd, hdc);
2829 else if (nHit == infoPtr->nButtonDown) {
2830 btnPtr->fsState |= TBSTATE_PRESSED;
2831 hdc = GetDC (hwnd);
2832 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2833 ReleaseDC (hwnd, hdc);
2836 infoPtr->nOldHit = nHit;
2838 return 0;
2842 inline static LRESULT
2843 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2845 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
2846 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
2847 /* else */
2848 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
2852 inline static LRESULT
2853 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2855 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
2856 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
2858 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
2862 static LRESULT
2863 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2865 TOOLBAR_INFO *infoPtr;
2867 /* allocate memory for info structure */
2868 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
2869 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
2871 /* paranoid!! */
2872 infoPtr->dwStructSize = sizeof(TBBUTTON);
2874 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
2875 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
2876 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
2877 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
2880 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
2884 static LRESULT
2885 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2887 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2888 RECT rcWindow;
2889 HDC hdc;
2891 if (dwStyle & WS_MINIMIZE)
2892 return 0; /* Nothing to do */
2894 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
2896 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
2897 return 0;
2899 if (!(dwStyle & CCS_NODIVIDER))
2901 GetWindowRect (hwnd, &rcWindow);
2902 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
2903 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
2906 ReleaseDC( hwnd, hdc );
2908 return 0;
2912 inline static LRESULT
2913 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
2915 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2916 LPNMHDR lpnmh = (LPNMHDR)lParam;
2918 TRACE("passing WM_NOTIFY!\n");
2920 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
2921 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
2923 #if 0
2924 if (lpnmh->code == TTN_GETDISPINFOA) {
2925 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
2927 FIXME("retrieving ASCII string\n");
2930 else if (lpnmh->code == TTN_GETDISPINFOW) {
2931 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
2933 FIXME("retrieving UNICODE string\n");
2936 #endif
2939 return 0;
2943 static LRESULT
2944 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
2946 HDC hdc;
2947 PAINTSTRUCT ps;
2949 TOOLBAR_CalcToolbar( hwnd );
2950 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2951 TOOLBAR_Refresh (hwnd, hdc);
2952 if (!wParam)
2953 EndPaint (hwnd, &ps);
2954 return 0;
2958 static LRESULT
2959 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
2961 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2962 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2963 RECT parent_rect;
2964 HWND parent;
2965 /* INT32 x, y; */
2966 INT cx, cy;
2967 INT flags;
2968 UINT uPosFlags = 0;
2970 /* Resize deadlock check */
2971 if (infoPtr->bAutoSize) {
2972 infoPtr->bAutoSize = FALSE;
2973 return 0;
2976 flags = (INT) wParam;
2978 /* FIXME for flags =
2979 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
2982 TRACE("sizing toolbar!\n");
2984 if (flags == SIZE_RESTORED) {
2985 /* width and height don't apply */
2986 parent = GetParent (hwnd);
2987 GetClientRect(parent, &parent_rect);
2989 if (dwStyle & CCS_NORESIZE) {
2990 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2992 /* FIXME */
2993 /* infoPtr->nWidth = parent_rect.right - parent_rect.left; */
2994 cy = infoPtr->nHeight;
2995 cx = infoPtr->nWidth;
2996 TOOLBAR_CalcToolbar (hwnd);
2997 infoPtr->nWidth = cx;
2998 infoPtr->nHeight = cy;
3000 else {
3001 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3002 TOOLBAR_CalcToolbar (hwnd);
3003 cy = infoPtr->nHeight;
3004 cx = infoPtr->nWidth;
3007 if (dwStyle & CCS_NOPARENTALIGN) {
3008 uPosFlags |= SWP_NOMOVE;
3009 cy = infoPtr->nHeight;
3010 cx = infoPtr->nWidth;
3013 if (!(dwStyle & CCS_NODIVIDER))
3014 cy += GetSystemMetrics(SM_CYEDGE);
3016 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
3017 cx, cy, uPosFlags | SWP_NOZORDER);
3019 return 0;
3023 static LRESULT
3024 TOOLBAR_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
3026 TOOLBAR_AutoSize (hwnd, wParam, lParam);
3028 InvalidateRect(hwnd, NULL, FALSE);
3030 return 0;
3035 static LRESULT WINAPI
3036 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3038 switch (uMsg)
3040 case TB_ADDBITMAP:
3041 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
3043 case TB_ADDBUTTONSA:
3044 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
3046 /* case TB_ADDBUTTONSW: */
3048 case TB_ADDSTRINGA:
3049 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
3051 case TB_ADDSTRINGW:
3052 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
3054 case TB_AUTOSIZE:
3055 return TOOLBAR_AutoSize (hwnd, wParam, lParam);
3057 case TB_BUTTONCOUNT:
3058 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
3060 case TB_BUTTONSTRUCTSIZE:
3061 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
3063 case TB_CHANGEBITMAP:
3064 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
3066 case TB_CHECKBUTTON:
3067 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
3069 case TB_COMMANDTOINDEX:
3070 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
3072 case TB_CUSTOMIZE:
3073 return TOOLBAR_Customize (hwnd);
3075 case TB_DELETEBUTTON:
3076 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
3078 case TB_ENABLEBUTTON:
3079 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
3081 /* case TB_GETANCHORHIGHLIGHT: */ /* 4.71 */
3083 case TB_GETBITMAP:
3084 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
3086 case TB_GETBITMAPFLAGS:
3087 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
3089 case TB_GETBUTTON:
3090 return TOOLBAR_GetButton (hwnd, wParam, lParam);
3092 case TB_GETBUTTONINFOA:
3093 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
3095 /* case TB_GETBUTTONINFOW: */ /* 4.71 */
3097 case TB_GETBUTTONSIZE:
3098 return TOOLBAR_GetButtonSize (hwnd);
3100 case TB_GETBUTTONTEXTA:
3101 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
3103 /* case TB_GETBUTTONTEXTW: */
3104 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
3106 case TB_GETDISABLEDIMAGELIST:
3107 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
3109 case TB_GETEXTENDEDSTYLE:
3110 return TOOLBAR_GetExtendedStyle (hwnd);
3112 case TB_GETHOTIMAGELIST:
3113 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
3115 /* case TB_GETHOTITEM: */ /* 4.71 */
3117 case TB_GETIMAGELIST:
3118 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
3120 /* case TB_GETINSERTMARK: */ /* 4.71 */
3121 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
3123 case TB_GETITEMRECT:
3124 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
3126 case TB_GETMAXSIZE:
3127 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
3129 /* case TB_GETOBJECT: */ /* 4.71 */
3130 /* case TB_GETPADDING: */ /* 4.71 */
3132 case TB_GETRECT:
3133 return TOOLBAR_GetRect (hwnd, wParam, lParam);
3135 case TB_GETROWS:
3136 return TOOLBAR_GetRows (hwnd, wParam, lParam);
3138 case TB_GETSTATE:
3139 return TOOLBAR_GetState (hwnd, wParam, lParam);
3141 case TB_GETSTYLE:
3142 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
3144 case TB_GETTEXTROWS:
3145 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
3147 case TB_GETTOOLTIPS:
3148 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
3150 case TB_GETUNICODEFORMAT:
3151 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
3153 case TB_HIDEBUTTON:
3154 return TOOLBAR_HideButton (hwnd, wParam, lParam);
3156 case TB_HITTEST:
3157 return TOOLBAR_HitTest (hwnd, wParam, lParam);
3159 case TB_INDETERMINATE:
3160 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
3162 case TB_INSERTBUTTONA:
3163 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
3165 /* case TB_INSERTBUTTONW: */
3166 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
3168 case TB_ISBUTTONCHECKED:
3169 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
3171 case TB_ISBUTTONENABLED:
3172 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
3174 case TB_ISBUTTONHIDDEN:
3175 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
3177 case TB_ISBUTTONHIGHLIGHTED:
3178 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
3180 case TB_ISBUTTONINDETERMINATE:
3181 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
3183 case TB_ISBUTTONPRESSED:
3184 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
3186 case TB_LOADIMAGES: /* 4.70 */
3187 FIXME("missing standard imagelists\n");
3188 return 0;
3190 /* case TB_MAPACCELERATORA: */ /* 4.71 */
3191 /* case TB_MAPACCELERATORW: */ /* 4.71 */
3192 /* case TB_MARKBUTTON: */ /* 4.71 */
3193 /* case TB_MOVEBUTTON: */ /* 4.71 */
3195 case TB_PRESSBUTTON:
3196 return TOOLBAR_PressButton (hwnd, wParam, lParam);
3198 /* case TB_REPLACEBITMAP: */
3200 case TB_SAVERESTOREA:
3201 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
3203 /* case TB_SAVERESTOREW: */
3204 /* case TB_SETANCHORHIGHLIGHT: */ /* 4.71 */
3206 case TB_SETBITMAPSIZE:
3207 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
3209 case TB_SETBUTTONINFOA:
3210 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
3212 /* case TB_SETBUTTONINFOW: */ /* 4.71 */
3214 case TB_SETBUTTONSIZE:
3215 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
3217 case TB_SETBUTTONWIDTH:
3218 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
3220 case TB_SETCMDID:
3221 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
3223 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
3225 case TB_SETDISABLEDIMAGELIST:
3226 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
3228 case TB_SETDRAWTEXTFLAGS:
3229 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
3231 case TB_SETEXTENDEDSTYLE:
3232 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
3234 case TB_SETHOTIMAGELIST:
3235 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
3237 /* case TB_SETHOTITEM: */ /* 4.71 */
3239 case TB_SETIMAGELIST:
3240 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
3242 case TB_SETINDENT:
3243 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
3245 /* case TB_SETINSERTMARK: */ /* 4.71 */
3247 case TB_SETINSERTMARKCOLOR:
3248 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
3250 case TB_SETMAXTEXTROWS:
3251 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
3253 /* case TB_SETPADDING: */ /* 4.71 */
3255 case TB_SETPARENT:
3256 return TOOLBAR_SetParent (hwnd, wParam, lParam);
3258 case TB_SETROWS:
3259 return TOOLBAR_SetRows (hwnd, wParam, lParam);
3261 case TB_SETSTATE:
3262 return TOOLBAR_SetState (hwnd, wParam, lParam);
3264 case TB_SETSTYLE:
3265 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
3267 case TB_SETTOOLTIPS:
3268 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
3270 case TB_SETUNICODEFORMAT:
3271 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
3274 /* case WM_CHAR: */
3276 case WM_CREATE:
3277 return TOOLBAR_Create (hwnd, wParam, lParam);
3279 case WM_DESTROY:
3280 return TOOLBAR_Destroy (hwnd, wParam, lParam);
3282 case WM_ERASEBKGND:
3283 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
3285 case WM_GETFONT:
3286 return TOOLBAR_GetFont (hwnd, wParam, lParam);
3288 /* case WM_KEYDOWN: */
3289 /* case WM_KILLFOCUS: */
3291 case WM_LBUTTONDBLCLK:
3292 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
3294 case WM_LBUTTONDOWN:
3295 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
3297 case WM_LBUTTONUP:
3298 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
3300 case WM_MOUSEMOVE:
3301 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
3303 case WM_NCACTIVATE:
3304 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
3306 case WM_NCCALCSIZE:
3307 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
3309 case WM_NCCREATE:
3310 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
3312 case WM_NCPAINT:
3313 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
3315 case WM_NOTIFY:
3316 return TOOLBAR_Notify (hwnd, wParam, lParam);
3318 /* case WM_NOTIFYFORMAT: */
3320 case WM_PAINT:
3321 return TOOLBAR_Paint (hwnd, wParam);
3323 case WM_SIZE:
3324 return TOOLBAR_Size (hwnd, wParam, lParam);
3326 case WM_STYLECHANGED:
3327 return TOOLBAR_StyleChanged (hwnd, wParam, lParam);
3329 /* case WM_SYSCOLORCHANGE: */
3331 /* case WM_WININICHANGE: */
3333 case WM_CHARTOITEM:
3334 case WM_COMMAND:
3335 case WM_DRAWITEM:
3336 case WM_MEASUREITEM:
3337 case WM_VKEYTOITEM:
3338 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
3340 default:
3341 if (uMsg >= WM_USER)
3342 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
3343 uMsg, wParam, lParam);
3344 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
3346 return 0;
3350 VOID
3351 TOOLBAR_Register (void)
3353 WNDCLASSA wndClass;
3355 if (GlobalFindAtomA (TOOLBARCLASSNAMEA)) return;
3357 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
3358 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3359 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
3360 wndClass.cbClsExtra = 0;
3361 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
3362 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
3363 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3364 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
3366 RegisterClassA (&wndClass);
3370 VOID
3371 TOOLBAR_Unregister (void)
3373 if (GlobalFindAtomA (TOOLBARCLASSNAMEA))
3374 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);