Replaced direct access to the WND structure by corresponding calls to
[wine/multimedia.git] / dlls / comctl32 / toolbar.c
blobdef3673653b03bb77b49e63c17e0e6efa6341e1c
1 /*
2 * Toolbar control
4 * Copyright 1998 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 * - Internal COMMCTL32 bitmaps.
15 * - Fix TOOLBAR_SetButtonInfo32A.
16 * - Fix TOOLBAR_Customize. (Customize dialog.)
18 * Testing:
19 * - Run tests using Waite Group Windows95 API Bible Volume 2.
20 * The second cdrom contains executables addstr.exe, btncount.exe,
21 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
22 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
23 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
24 * setparnt.exe, setrows.exe, toolwnd.exe.
25 * - Microsofts controlspy examples.
28 #include <string.h>
30 #include "commctrl.h"
31 #include "sysmetrics.h"
32 #include "cache.h"
33 #include "toolbar.h"
34 #include "win.h"
35 #include "debug.h"
37 /* #define __NEW_WRAP_CODE__ */
39 #define SEPARATOR_WIDTH 8
40 #define SEPARATOR_HEIGHT 5
41 #define TOP_BORDER 2
42 #define BOTTOM_BORDER 2
46 #define TOOLBAR_GetInfoPtr(wndPtr) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
49 static void
50 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
52 INT x = (lpRect->left + lpRect->right) / 2 - 1;
53 INT yBottom = lpRect->bottom - 3;
54 INT yTop = lpRect->top + 1;
56 SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
57 MoveToEx (hdc, x, yBottom, NULL);
58 LineTo (hdc, x, yTop);
59 x++;
60 SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
61 MoveToEx (hdc, x, yBottom, NULL);
62 LineTo (hdc, x, yTop);
66 static void
67 TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
68 HDC hdc, INT nState)
70 RECT rcText = btnPtr->rect;
71 HFONT hOldFont;
72 INT nOldBkMode;
73 COLORREF clrOld;
75 /* draw text */
76 if ((btnPtr->iString > -1) && (btnPtr->iString < infoPtr->nNumStrings)) {
77 InflateRect (&rcText, -3, -3);
78 rcText.top += infoPtr->nBitmapHeight;
79 if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
80 OffsetRect (&rcText, 1, 1);
82 hOldFont = SelectObject (hdc, infoPtr->hFont);
83 nOldBkMode = SetBkMode (hdc, TRANSPARENT);
84 if (!(nState & TBSTATE_ENABLED)) {
85 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
86 OffsetRect (&rcText, 1, 1);
87 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
88 &rcText, infoPtr->dwDTFlags);
89 SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
90 OffsetRect (&rcText, -1, -1);
91 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
92 &rcText, infoPtr->dwDTFlags);
94 else if (nState & TBSTATE_INDETERMINATE) {
95 clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
96 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
97 &rcText, infoPtr->dwDTFlags);
99 else {
100 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
101 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
102 &rcText, infoPtr->dwDTFlags);
105 SetTextColor (hdc, clrOld);
106 SelectObject (hdc, hOldFont);
107 if (nOldBkMode != TRANSPARENT)
108 SetBkMode (hdc, nOldBkMode);
113 static void
114 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
116 HBRUSH hbr = SelectObject (hdc, CACHE_GetPattern55AABrush ());
117 INT cx = lpRect->right - lpRect->left;
118 INT cy = lpRect->bottom - lpRect->top;
119 PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
120 SelectObject (hdc, hbr);
124 static void
125 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
126 HDC hdc, INT x, INT y)
128 /* FIXME: this function is a hack since it uses image list
129 internals directly */
131 HDC hdcImageList = CreateCompatibleDC (0);
132 HDC hdcMask = CreateCompatibleDC (0);
133 HIMAGELIST himl = infoPtr->himlStd;
134 HBITMAP hbmMask;
136 /* create new bitmap */
137 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
138 SelectObject (hdcMask, hbmMask);
140 /* copy the mask bitmap */
141 SelectObject (hdcImageList, himl->hbmMask);
142 SetBkColor (hdcImageList, RGB(255, 255, 255));
143 SetTextColor (hdcImageList, RGB(0, 0, 0));
144 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
145 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
147 #if 0
148 /* add white mask from image */
149 SelectObject (hdcImageList, himl->hbmImage);
150 SetBkColor (hdcImageList, RGB(0, 0, 0));
151 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
152 hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
153 #endif
155 /* draw the new mask */
156 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
157 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
158 hdcMask, 0, 0, 0xB8074A);
160 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
161 BitBlt (hdc, x, y, himl->cx, himl->cy,
162 hdcMask, 0, 0, 0xB8074A);
164 DeleteObject (hbmMask);
165 DeleteDC (hdcMask);
166 DeleteDC (hdcImageList);
170 static void
171 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
173 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
174 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
175 RECT rc;
177 if (btnPtr->fsState & TBSTATE_HIDDEN)
178 return;
180 rc = btnPtr->rect;
181 if (btnPtr->fsStyle & TBSTYLE_SEP) {
182 if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->idCommand == 0))
183 TOOLBAR_DrawFlatSeparator (&btnPtr->rect, hdc);
184 return;
187 /* disabled */
188 if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
189 DrawEdge (hdc, &rc, EDGE_RAISED,
190 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
192 if (dwStyle & TBSTYLE_FLAT) {
193 /* if (infoPtr->himlDis) */
194 ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
195 rc.left+1, rc.top+1, ILD_NORMAL);
196 /* else */
197 /* TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1); */
199 else
200 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
202 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
203 return;
206 /* pressed TBSTYLE_BUTTON */
207 if (btnPtr->fsState & TBSTATE_PRESSED) {
208 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
209 ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
210 rc.left+2, rc.top+2, ILD_NORMAL);
211 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
212 return;
215 /* checked TBSTYLE_CHECK*/
216 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
217 (btnPtr->fsState & TBSTATE_CHECKED)) {
218 if (dwStyle & TBSTYLE_FLAT)
219 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
220 BF_RECT | BF_MIDDLE | BF_ADJUST);
221 else
222 DrawEdge (hdc, &rc, EDGE_SUNKEN,
223 BF_RECT | BF_MIDDLE | BF_ADJUST);
225 TOOLBAR_DrawPattern (hdc, &rc);
226 if (dwStyle & TBSTYLE_FLAT)
227 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
228 rc.left+2, rc.top+2, ILD_NORMAL);
229 else
230 ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
231 rc.left+2, rc.top+2, ILD_NORMAL);
232 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
233 return;
236 /* indeterminate */
237 if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
238 DrawEdge (hdc, &rc, EDGE_RAISED,
239 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
241 TOOLBAR_DrawPattern (hdc, &rc);
242 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
243 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
244 return;
247 /* normal state */
248 DrawEdge (hdc, &rc, EDGE_RAISED,
249 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
251 if (dwStyle & TBSTYLE_FLAT)
252 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
253 rc.left+1, rc.top+1, ILD_NORMAL);
254 else
255 ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
256 rc.left+1, rc.top+1, ILD_NORMAL);
258 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
262 static void
263 TOOLBAR_Refresh (HWND hwnd, HDC hdc)
265 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
266 TBUTTON_INFO *btnPtr;
267 INT i;
269 /* draw buttons */
270 btnPtr = infoPtr->buttons;
271 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
272 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
276 static void
277 TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
279 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
280 TBUTTON_INFO *btnPtr;
281 INT i;
282 HDC hdc;
283 HFONT hOldFont;
284 SIZE sz;
286 lpSize->cx = 0;
287 lpSize->cy = 0;
288 hdc = GetDC (0);
289 hOldFont = SelectObject (hdc, infoPtr->hFont);
291 btnPtr = infoPtr->buttons;
292 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
293 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
294 (btnPtr->iString > -1) &&
295 (btnPtr->iString < infoPtr->nNumStrings)) {
296 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
297 GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), &sz);
298 if (sz.cx > lpSize->cx)
299 lpSize->cx = sz.cx;
300 if (sz.cy > lpSize->cy)
301 lpSize->cy = sz.cy;
305 SelectObject (hdc, hOldFont);
306 ReleaseDC (0, hdc);
308 TRACE (toolbar, "string size %d x %d!\n", lpSize->cx, lpSize->cy);
312 static void
313 TOOLBAR_CalcToolbar (HWND hwnd)
315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
316 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
317 TBUTTON_INFO *btnPtr;
318 INT i, nRows;
319 INT x, y, cx, cy;
320 BOOL bWrap;
321 SIZE sizeString;
322 /* --- new --- */
323 #ifdef __NEW_WRAP_CODE__
324 INT nGrpCount = 0;
325 INT grpX,j;
326 TBUTTON_INFO *grpPtr;
327 #endif
328 /* --- end new --- */
330 TOOLBAR_CalcStrings (hwnd, &sizeString);
332 if (sizeString.cy > 0)
333 infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
334 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
335 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
337 if (sizeString.cx > infoPtr->nBitmapWidth)
338 infoPtr->nButtonWidth = sizeString.cx + 6;
339 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
340 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
342 x = infoPtr->nIndent;
343 y = TOP_BORDER;
344 cx = infoPtr->nButtonWidth;
345 cy = infoPtr->nButtonHeight;
346 nRows = 0;
348 /* calculate the size of each button according to it's style */
349 /* TOOLBAR_CalcButtons (hwnd); */
351 infoPtr->rcBound.top = y;
352 infoPtr->rcBound.left = x;
353 infoPtr->rcBound.bottom = y + cy;
354 infoPtr->rcBound.right = x;
356 btnPtr = infoPtr->buttons;
357 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
358 bWrap = FALSE;
360 if (btnPtr->fsState & TBSTATE_HIDDEN) {
361 SetRectEmpty (&btnPtr->rect);
362 continue;
365 #ifdef __NEW_WRAP_CODE__
366 /*#if 0 */
367 if (btnPtr->fsStyle & TBSTYLE_SEP) {
368 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
369 /* it is the actual width of the separator. This is used for */
370 /* custom controls in toolbars. */
371 if ((dwStyle & TBSTYLE_WRAPABLE) &&
372 (btnPtr->fsState & TBSTATE_WRAP)) {
373 x = 0;
374 y += cy;
375 cx = infoPtr->nWidth;
376 cy = ((btnPtr->iBitmap > 0) ?
377 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 / 3;
378 /* nRows++; */
379 /* bWrap = TRUE; */
381 else
382 cx = (btnPtr->iBitmap > 0) ?
383 btnPtr->iBitmap : SEPARATOR_WIDTH;
385 else {
386 /* this must be a button */
387 cx = infoPtr->nButtonWidth;
389 /*#endif */
391 /* --- begin test --- */
392 if ((i >= nGrpCount) && (btnPtr->fsStyle & TBSTYLE_GROUP)) {
393 for (j = i, grpX = x, nGrpCount = 0; j < infoPtr->nNumButtons; j++) {
394 grpPtr = &infoPtr->buttons[j];
395 if (grpPtr->fsState & TBSTATE_HIDDEN)
396 continue;
398 grpX += cx;
400 if ((grpPtr->fsStyle & TBSTYLE_SEP) ||
401 !(grpPtr->fsStyle & TBSTYLE_GROUP) ||
402 (grpX > infoPtr->nWidth)) {
403 nGrpCount = j;
404 break;
406 else if (grpX + x > infoPtr->nWidth) {
407 bWrap = TRUE;
408 nGrpCount = j;
409 break;
414 bWrap = ((bWrap || (x + cx > infoPtr->nWidth)) &&
415 (dwStyle & TBSTYLE_WRAPABLE));
416 if (bWrap) {
417 nRows++;
418 y += cy;
419 x = infoPtr->nIndent;
420 bWrap = FALSE;
423 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
425 btnPtr->nRow = nRows;
426 x += cx;
428 if (btnPtr->fsState & TBSTATE_WRAP) {
429 nRows++;
430 y += (cy + SEPARATOR_HEIGHT);
431 x = infoPtr->nIndent;
434 infoPtr->nRows = nRows + 1;
436 /* --- end test --- */
437 #else
438 if (btnPtr->fsStyle & TBSTYLE_SEP) {
439 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
440 /* it is the actual width of the separator. This is used for */
441 /* custom controls in toolbars. */
442 if ((dwStyle & TBSTYLE_WRAPABLE) &&
443 (btnPtr->fsState & TBSTATE_WRAP)) {
444 x = 0;
445 y += cy;
446 cx = infoPtr->nWidth;
447 cy = ((btnPtr->iBitmap > 0) ?
448 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 / 3;
449 nRows++;
450 bWrap = TRUE;
452 else
453 cx = (btnPtr->iBitmap > 0) ?
454 btnPtr->iBitmap : SEPARATOR_WIDTH;
456 else {
457 /* this must be a button */
458 cx = infoPtr->nButtonWidth;
461 btnPtr->rect.left = x;
462 btnPtr->rect.top = y;
463 btnPtr->rect.right = x + cx;
464 btnPtr->rect.bottom = y + cy;
466 if (infoPtr->rcBound.left > x)
467 infoPtr->rcBound.left = x;
468 if (infoPtr->rcBound.right < x + cx)
469 infoPtr->rcBound.right = x + cx;
470 if (infoPtr->rcBound.bottom < y + cy)
471 infoPtr->rcBound.bottom = y + cy;
473 if (infoPtr->hwndToolTip) {
474 TTTOOLINFOA ti;
476 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
477 ti.cbSize = sizeof(TTTOOLINFOA);
478 ti.hwnd = hwnd;
479 ti.uId = btnPtr->idCommand;
480 ti.rect = btnPtr->rect;
481 SendMessageA (infoPtr->hwndToolTip, TTM_NEWTOOLRECTA,
482 0, (LPARAM)&ti);
485 if (bWrap) {
486 x = 0;
487 y += cy;
488 if (i < infoPtr->nNumButtons)
489 nRows++;
491 else
492 x += cx;
493 #endif
496 infoPtr->nHeight = y + cy + BOTTOM_BORDER;
497 TRACE (toolbar, "toolbar height %d\n", infoPtr->nHeight);
501 static INT
502 TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
504 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
505 TBUTTON_INFO *btnPtr;
506 INT i;
508 btnPtr = infoPtr->buttons;
509 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
510 if (btnPtr->fsState & TBSTATE_HIDDEN)
511 continue;
513 if (btnPtr->fsStyle & TBSTYLE_SEP) {
514 if (PtInRect (&btnPtr->rect, *lpPt)) {
515 TRACE (toolbar, " ON SEPARATOR %d!\n", i);
516 return -i;
519 else {
520 if (PtInRect (&btnPtr->rect, *lpPt)) {
521 TRACE (toolbar, " ON BUTTON %d!\n", i);
522 return i;
527 TRACE (toolbar, " NOWHERE!\n");
528 return -1;
532 static INT
533 TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
535 TBUTTON_INFO *btnPtr;
536 INT i;
538 btnPtr = infoPtr->buttons;
539 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
540 if (btnPtr->idCommand == idCommand) {
541 TRACE (toolbar, "command=%d index=%d\n", idCommand, i);
542 return i;
545 TRACE (toolbar, "no index found for command=%d\n", idCommand);
546 return -1;
550 static INT
551 TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
553 TBUTTON_INFO *btnPtr;
554 INT nRunIndex;
556 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
557 return -1;
559 /* check index button */
560 btnPtr = &infoPtr->buttons[nIndex];
561 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
562 if (btnPtr->fsState & TBSTATE_CHECKED)
563 return nIndex;
566 /* check previous buttons */
567 nRunIndex = nIndex - 1;
568 while (nRunIndex >= 0) {
569 btnPtr = &infoPtr->buttons[nRunIndex];
570 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
571 if (btnPtr->fsState & TBSTATE_CHECKED)
572 return nRunIndex;
574 else
575 break;
576 nRunIndex--;
579 /* check next buttons */
580 nRunIndex = nIndex + 1;
581 while (nRunIndex < infoPtr->nNumButtons) {
582 btnPtr = &infoPtr->buttons[nRunIndex];
583 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
584 if (btnPtr->fsState & TBSTATE_CHECKED)
585 return nRunIndex;
587 else
588 break;
589 nRunIndex++;
592 return -1;
596 static VOID
597 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
598 WPARAM wParam, LPARAM lParam)
600 MSG msg;
602 msg.hwnd = hwndMsg;
603 msg.message = uMsg;
604 msg.wParam = wParam;
605 msg.lParam = lParam;
606 msg.time = GetMessageTime ();
607 msg.pt.x = LOWORD(GetMessagePos ());
608 msg.pt.y = HIWORD(GetMessagePos ());
610 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
614 static LRESULT
615 TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
617 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
618 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
619 INT nIndex = 0;
621 if ((!lpAddBmp) || ((INT)wParam <= 0))
622 return -1;
624 TRACE (toolbar, "adding %d bitmaps!\n", wParam);
626 if (!(infoPtr->himlDef)) {
627 /* create new default image list */
628 TRACE (toolbar, "creating default image list!\n");
629 infoPtr->himlStd =
630 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
631 ILC_COLOR | ILC_MASK, (INT)wParam, 2);
634 #if 0
635 if (!(infoPtr->himlDis)) {
636 /* create new disabled image list */
637 TRACE (toolbar, "creating disabled image list!\n");
638 infoPtr->himlDis =
639 ImageList_Create (infoPtr->nBitmapWidth,
640 infoPtr->nBitmapHeight, ILC_COLOR | ILC_MASK,
641 (INT)wParam, 2);
643 #endif
645 /* Add bitmaps to the default image list */
646 if (lpAddBmp->hInst == (HINSTANCE)0) {
647 nIndex =
648 ImageList_AddMasked (infoPtr->himlStd, (HBITMAP)lpAddBmp->nID,
649 CLR_DEFAULT);
651 else if (lpAddBmp->hInst == HINST_COMMCTRL) {
652 /* add internal bitmaps */
653 FIXME (toolbar, "internal bitmaps not supported!\n");
655 /* Hack to "add" some reserved images within the image list
656 to get the right image indices */
657 nIndex = ImageList_GetImageCount (infoPtr->himlStd);
658 ImageList_SetImageCount (infoPtr->himlStd, nIndex + (INT)wParam);
660 else {
661 HBITMAP hBmp =
662 LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
664 nIndex = ImageList_AddMasked (infoPtr->himlStd, hBmp, CLR_DEFAULT);
666 DeleteObject (hBmp);
670 infoPtr->nNumBitmaps += (INT)wParam;
672 return nIndex;
676 static LRESULT
677 TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
679 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
680 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
681 INT nOldButtons, nNewButtons, nAddButtons, nCount;
682 HDC hdc;
684 TRACE (toolbar, "adding %d buttons!\n", wParam);
686 nAddButtons = (UINT)wParam;
687 nOldButtons = infoPtr->nNumButtons;
688 nNewButtons = nOldButtons + nAddButtons;
690 if (infoPtr->nNumButtons == 0) {
691 infoPtr->buttons =
692 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
694 else {
695 TBUTTON_INFO *oldButtons = infoPtr->buttons;
696 infoPtr->buttons =
697 COMCTL32_Alloc (sizeof(TBUTTON_INFO) * nNewButtons);
698 memcpy (&infoPtr->buttons[0], &oldButtons[0],
699 nOldButtons * sizeof(TBUTTON_INFO));
700 COMCTL32_Free (oldButtons);
703 infoPtr->nNumButtons = nNewButtons;
705 /* insert new button data */
706 for (nCount = 0; nCount < nAddButtons; nCount++) {
707 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nOldButtons+nCount];
708 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
709 btnPtr->idCommand = lpTbb[nCount].idCommand;
710 btnPtr->fsState = lpTbb[nCount].fsState;
711 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
712 btnPtr->dwData = lpTbb[nCount].dwData;
713 btnPtr->iString = lpTbb[nCount].iString;
715 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP)) {
716 TTTOOLINFOA ti;
718 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
719 ti.cbSize = sizeof (TTTOOLINFOA);
720 ti.hwnd = hwnd;
721 ti.uId = btnPtr->idCommand;
722 ti.hinst = 0;
723 ti.lpszText = LPSTR_TEXTCALLBACKA;
725 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
726 0, (LPARAM)&ti);
730 TOOLBAR_CalcToolbar (hwnd);
732 hdc = GetDC (hwnd);
733 TOOLBAR_Refresh (hwnd, hdc);
734 ReleaseDC (hwnd, hdc);
736 return TRUE;
740 /* << TOOLBAR_AddButtons32W >> */
743 static LRESULT
744 TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
746 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
747 INT nIndex;
749 if ((wParam) && (HIWORD(lParam) == 0)) {
750 char szString[256];
751 INT len;
752 TRACE (toolbar, "adding string from resource!\n");
754 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
755 szString, 256);
757 TRACE (toolbar, "len=%d \"%s\"\n", len, szString);
758 nIndex = infoPtr->nNumStrings;
759 if (infoPtr->nNumStrings == 0) {
760 infoPtr->strings =
761 COMCTL32_Alloc (sizeof(LPWSTR));
763 else {
764 LPWSTR *oldStrings = infoPtr->strings;
765 infoPtr->strings =
766 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
767 memcpy (&infoPtr->strings[0], &oldStrings[0],
768 sizeof(LPWSTR) * infoPtr->nNumStrings);
769 COMCTL32_Free (oldStrings);
772 infoPtr->strings[infoPtr->nNumStrings] =
773 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
774 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
775 infoPtr->nNumStrings++;
777 else {
778 LPSTR p = (LPSTR)lParam;
779 INT len;
781 if (p == NULL)
782 return -1;
783 TRACE (toolbar, "adding string(s) from array!\n");
784 nIndex = infoPtr->nNumStrings;
785 while (*p) {
786 len = lstrlenA (p);
787 TRACE (toolbar, "len=%d \"%s\"\n", len, p);
789 if (infoPtr->nNumStrings == 0) {
790 infoPtr->strings =
791 COMCTL32_Alloc (sizeof(LPWSTR));
793 else {
794 LPWSTR *oldStrings = infoPtr->strings;
795 infoPtr->strings =
796 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
797 memcpy (&infoPtr->strings[0], &oldStrings[0],
798 sizeof(LPWSTR) * infoPtr->nNumStrings);
799 COMCTL32_Free (oldStrings);
802 infoPtr->strings[infoPtr->nNumStrings] =
803 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
804 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
805 infoPtr->nNumStrings++;
807 p += (len+1);
811 return nIndex;
815 static LRESULT
816 TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
818 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
819 INT nIndex;
821 if ((wParam) && (HIWORD(lParam) == 0)) {
822 WCHAR szString[256];
823 INT len;
824 TRACE (toolbar, "adding string from resource!\n");
826 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
827 szString, 256);
829 TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(szString));
830 nIndex = infoPtr->nNumStrings;
831 if (infoPtr->nNumStrings == 0) {
832 infoPtr->strings =
833 COMCTL32_Alloc (sizeof(LPWSTR));
835 else {
836 LPWSTR *oldStrings = infoPtr->strings;
837 infoPtr->strings =
838 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
839 memcpy (&infoPtr->strings[0], &oldStrings[0],
840 sizeof(LPWSTR) * infoPtr->nNumStrings);
841 COMCTL32_Free (oldStrings);
844 infoPtr->strings[infoPtr->nNumStrings] =
845 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
846 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
847 infoPtr->nNumStrings++;
849 else {
850 LPWSTR p = (LPWSTR)lParam;
851 INT len;
853 if (p == NULL)
854 return -1;
855 TRACE (toolbar, "adding string(s) from array!\n");
856 nIndex = infoPtr->nNumStrings;
857 while (*p) {
858 len = lstrlenW (p);
859 TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(p));
861 if (infoPtr->nNumStrings == 0) {
862 infoPtr->strings =
863 COMCTL32_Alloc (sizeof(LPWSTR));
865 else {
866 LPWSTR *oldStrings = infoPtr->strings;
867 infoPtr->strings =
868 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
869 memcpy (&infoPtr->strings[0], &oldStrings[0],
870 sizeof(LPWSTR) * infoPtr->nNumStrings);
871 COMCTL32_Free (oldStrings);
874 infoPtr->strings[infoPtr->nNumStrings] =
875 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
876 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
877 infoPtr->nNumStrings++;
879 p += (len+1);
883 return nIndex;
887 static LRESULT
888 TOOLBAR_AutoSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
890 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
891 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
892 RECT parent_rect;
893 HWND parent;
894 /* INT32 x, y; */
895 INT cx, cy;
896 UINT uPosFlags = 0;
898 TRACE (toolbar, "resize forced!\n");
900 parent = GetParent (hwnd);
901 GetClientRect(parent, &parent_rect);
903 if (dwStyle & CCS_NORESIZE) {
904 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
905 cx = 0;
906 cy = 0;
908 else {
909 infoPtr->nWidth = parent_rect.right - parent_rect.left;
910 TOOLBAR_CalcToolbar (hwnd);
911 cy = infoPtr->nHeight;
912 cx = infoPtr->nWidth;
915 if (dwStyle & CCS_NOPARENTALIGN)
916 uPosFlags |= SWP_NOMOVE;
918 if (!(dwStyle & CCS_NODIVIDER))
919 cy += sysMetrics[SM_CYEDGE];
921 infoPtr->bAutoSize = TRUE;
922 SetWindowPos (hwnd, HWND_TOP, parent_rect.left, parent_rect.top,
923 cx, cy, uPosFlags);
925 return 0;
929 static LRESULT
930 TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
932 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
934 return infoPtr->nNumButtons;
938 static LRESULT
939 TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
941 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
943 if (infoPtr == NULL) {
944 ERR (toolbar, "(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
945 ERR (toolbar, "infoPtr == NULL!\n");
946 return 0;
949 infoPtr->dwStructSize = (DWORD)wParam;
951 return 0;
955 static LRESULT
956 TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
958 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
959 TBUTTON_INFO *btnPtr;
960 HDC hdc;
961 INT nIndex;
963 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
964 if (nIndex == -1)
965 return FALSE;
967 btnPtr = &infoPtr->buttons[nIndex];
968 btnPtr->iBitmap = LOWORD(lParam);
970 hdc = GetDC (hwnd);
971 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
972 ReleaseDC (hwnd, hdc);
974 return TRUE;
978 static LRESULT
979 TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
982 TBUTTON_INFO *btnPtr;
983 HDC hdc;
984 INT nIndex;
985 INT nOldIndex = -1;
987 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
988 if (nIndex == -1)
989 return FALSE;
991 btnPtr = &infoPtr->buttons[nIndex];
993 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
994 return FALSE;
996 if (LOWORD(lParam) == FALSE)
997 btnPtr->fsState &= ~TBSTATE_CHECKED;
998 else {
999 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
1000 nOldIndex =
1001 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
1002 if (nOldIndex == nIndex)
1003 return 0;
1004 if (nOldIndex != -1)
1005 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
1007 btnPtr->fsState |= TBSTATE_CHECKED;
1010 hdc = GetDC (hwnd);
1011 if (nOldIndex != -1)
1012 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
1013 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1014 ReleaseDC (hwnd, hdc);
1016 /* FIXME: Send a WM_NOTIFY?? */
1018 return TRUE;
1022 static LRESULT
1023 TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
1025 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1027 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1031 static LRESULT
1032 TOOLBAR_Customize (HWND hwnd)
1034 FIXME (toolbar, "customization not implemented!\n");
1036 return 0;
1040 static LRESULT
1041 TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1043 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1044 INT nIndex = (INT)wParam;
1046 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1047 return FALSE;
1049 if ((infoPtr->hwndToolTip) &&
1050 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
1051 TTTOOLINFOA ti;
1053 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1054 ti.cbSize = sizeof (TTTOOLINFOA);
1055 ti.hwnd = hwnd;
1056 ti.uId = infoPtr->buttons[nIndex].idCommand;
1058 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
1061 if (infoPtr->nNumButtons == 1) {
1062 TRACE (toolbar, " simple delete!\n");
1063 COMCTL32_Free (infoPtr->buttons);
1064 infoPtr->buttons = NULL;
1065 infoPtr->nNumButtons = 0;
1067 else {
1068 TBUTTON_INFO *oldButtons = infoPtr->buttons;
1069 TRACE(toolbar, "complex delete! [nIndex=%d]\n", nIndex);
1071 infoPtr->nNumButtons--;
1072 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
1073 if (nIndex > 0) {
1074 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1075 nIndex * sizeof(TBUTTON_INFO));
1078 if (nIndex < infoPtr->nNumButtons) {
1079 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
1080 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
1083 COMCTL32_Free (oldButtons);
1086 TOOLBAR_CalcToolbar (hwnd);
1088 InvalidateRect (hwnd, NULL, TRUE);
1089 UpdateWindow (hwnd);
1091 return TRUE;
1095 static LRESULT
1096 TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1098 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1099 TBUTTON_INFO *btnPtr;
1100 HDC hdc;
1101 INT nIndex;
1103 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1104 if (nIndex == -1)
1105 return FALSE;
1107 btnPtr = &infoPtr->buttons[nIndex];
1108 if (LOWORD(lParam) == FALSE)
1109 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
1110 else
1111 btnPtr->fsState |= TBSTATE_ENABLED;
1113 hdc = GetDC (hwnd);
1114 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1115 ReleaseDC (hwnd, hdc);
1117 return TRUE;
1121 /* << TOOLBAR_GetAnchorHighlight >> */
1124 static LRESULT
1125 TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1127 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1128 INT nIndex;
1130 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1131 if (nIndex == -1)
1132 return -1;
1134 return infoPtr->buttons[nIndex].iBitmap;
1138 static __inline__ LRESULT
1139 TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
1141 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
1145 static LRESULT
1146 TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1148 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1149 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1150 INT nIndex = (INT)wParam;
1151 TBUTTON_INFO *btnPtr;
1153 if (infoPtr == NULL)
1154 return FALSE;
1156 if (lpTbb == NULL)
1157 return FALSE;
1159 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1160 return FALSE;
1162 btnPtr = &infoPtr->buttons[nIndex];
1163 lpTbb->iBitmap = btnPtr->iBitmap;
1164 lpTbb->idCommand = btnPtr->idCommand;
1165 lpTbb->fsState = btnPtr->fsState;
1166 lpTbb->fsStyle = btnPtr->fsStyle;
1167 lpTbb->dwData = btnPtr->dwData;
1168 lpTbb->iString = btnPtr->iString;
1170 return TRUE;
1174 static LRESULT
1175 TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1177 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1178 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
1179 TBUTTON_INFO *btnPtr;
1180 INT nIndex;
1182 if (infoPtr == NULL)
1183 return -1;
1184 if (lpTbInfo == NULL)
1185 return -1;
1186 if (lpTbInfo->cbSize < sizeof(LPTBBUTTONINFOA))
1187 return -1;
1189 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1190 if (nIndex == -1)
1191 return -1;
1193 btnPtr = &infoPtr->buttons[nIndex];
1195 if (lpTbInfo->dwMask & TBIF_COMMAND)
1196 lpTbInfo->idCommand = btnPtr->idCommand;
1197 if (lpTbInfo->dwMask & TBIF_IMAGE)
1198 lpTbInfo->iImage = btnPtr->iBitmap;
1199 if (lpTbInfo->dwMask & TBIF_LPARAM)
1200 lpTbInfo->lParam = btnPtr->dwData;
1201 if (lpTbInfo->dwMask & TBIF_SIZE)
1202 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
1203 if (lpTbInfo->dwMask & TBIF_STATE)
1204 lpTbInfo->fsState = btnPtr->fsState;
1205 if (lpTbInfo->dwMask & TBIF_STYLE)
1206 lpTbInfo->fsStyle = btnPtr->fsStyle;
1207 if (lpTbInfo->dwMask & TBIF_TEXT) {
1208 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
1209 lstrcpynA (lpTbInfo->pszText,
1210 (LPSTR)infoPtr->strings[btnPtr->iString],
1211 lpTbInfo->cchText);
1214 return nIndex;
1218 /* << TOOLBAR_GetButtonInfo32W >> */
1221 static LRESULT
1222 TOOLBAR_GetButtonSize (HWND hwnd)
1224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1226 return MAKELONG((WORD)infoPtr->nButtonWidth,
1227 (WORD)infoPtr->nButtonHeight);
1231 static LRESULT
1232 TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1234 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1235 INT nIndex, nStringIndex;
1237 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1238 if (nIndex == -1)
1239 return -1;
1241 nStringIndex = infoPtr->buttons[nIndex].iString;
1243 TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
1245 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
1246 return -1;
1248 if (lParam == 0) return -1;
1250 lstrcpyA ((LPSTR)lParam, (LPSTR)infoPtr->strings[nStringIndex]);
1252 return lstrlenA ((LPSTR)infoPtr->strings[nStringIndex]);
1256 /* << TOOLBAR_GetButtonText32W >> */
1257 /* << TOOLBAR_GetColorScheme >> */
1260 static LRESULT
1261 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1263 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1265 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
1266 return (LRESULT)infoPtr->himlDis;
1267 else
1268 return 0;
1272 __inline__ static LRESULT
1273 TOOLBAR_GetExtendedStyle (HWND hwnd)
1275 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1277 return infoPtr->dwExStyle;
1281 static LRESULT
1282 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1284 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1286 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
1287 return (LRESULT)infoPtr->himlHot;
1288 else
1289 return 0;
1293 /* << TOOLBAR_GetHotItem >> */
1296 static LRESULT
1297 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1299 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1301 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT)
1302 return (LRESULT)infoPtr->himlDef;
1303 else
1304 return 0;
1308 /* << TOOLBAR_GetInsertMark >> */
1309 /* << TOOLBAR_GetInsertMarkColor >> */
1312 static LRESULT
1313 TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1315 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1316 TBUTTON_INFO *btnPtr;
1317 LPRECT lpRect;
1318 INT nIndex;
1320 if (infoPtr == NULL)
1321 return FALSE;
1322 nIndex = (INT)wParam;
1323 btnPtr = &infoPtr->buttons[nIndex];
1324 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1325 return FALSE;
1326 lpRect = (LPRECT)lParam;
1327 if (lpRect == NULL)
1328 return FALSE;
1329 if (btnPtr->fsState & TBSTATE_HIDDEN)
1330 return FALSE;
1332 lpRect->left = btnPtr->rect.left;
1333 lpRect->right = btnPtr->rect.right;
1334 lpRect->bottom = btnPtr->rect.bottom;
1335 lpRect->top = btnPtr->rect.top;
1337 return TRUE;
1341 static LRESULT
1342 TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1344 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1345 LPSIZE lpSize = (LPSIZE)lParam;
1347 if (lpSize == NULL)
1348 return FALSE;
1350 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
1351 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
1353 TRACE (toolbar, "maximum size %d x %d\n",
1354 infoPtr->rcBound.right - infoPtr->rcBound.left,
1355 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
1357 return TRUE;
1361 /* << TOOLBAR_GetObject >> */
1362 /* << TOOLBAR_GetPadding >> */
1365 static LRESULT
1366 TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1368 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1369 TBUTTON_INFO *btnPtr;
1370 LPRECT lpRect;
1371 INT nIndex;
1373 if (infoPtr == NULL)
1374 return FALSE;
1375 nIndex = (INT)wParam;
1376 btnPtr = &infoPtr->buttons[nIndex];
1377 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1378 return FALSE;
1379 lpRect = (LPRECT)lParam;
1380 if (lpRect == NULL)
1381 return FALSE;
1383 lpRect->left = btnPtr->rect.left;
1384 lpRect->right = btnPtr->rect.right;
1385 lpRect->bottom = btnPtr->rect.bottom;
1386 lpRect->top = btnPtr->rect.top;
1388 return TRUE;
1392 static LRESULT
1393 TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
1395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1397 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
1398 return infoPtr->nRows;
1399 else
1400 return 1;
1404 static LRESULT
1405 TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
1407 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1408 INT nIndex;
1410 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1411 if (nIndex == -1)
1412 return -1;
1414 return infoPtr->buttons[nIndex].fsState;
1418 static LRESULT
1419 TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
1421 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1422 INT nIndex;
1424 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1425 if (nIndex == -1)
1426 return -1;
1428 return infoPtr->buttons[nIndex].fsStyle;
1432 static LRESULT
1433 TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
1435 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1437 if (infoPtr == NULL)
1438 return 0;
1440 return infoPtr->nMaxTextRows;
1444 static LRESULT
1445 TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
1447 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1449 if (infoPtr == NULL)
1450 return 0;
1451 return infoPtr->hwndToolTip;
1455 static LRESULT
1456 TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1458 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1460 TRACE (toolbar, "%s hwnd=0x%x stub!\n",
1461 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
1463 return infoPtr->bUnicode;
1467 static LRESULT
1468 TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1470 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1471 TBUTTON_INFO *btnPtr;
1472 INT nIndex;
1474 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1475 if (nIndex == -1)
1476 return FALSE;
1478 btnPtr = &infoPtr->buttons[nIndex];
1479 if (LOWORD(lParam) == FALSE)
1480 btnPtr->fsState &= ~TBSTATE_HIDDEN;
1481 else
1482 btnPtr->fsState |= TBSTATE_HIDDEN;
1484 TOOLBAR_CalcToolbar (hwnd);
1486 InvalidateRect (hwnd, NULL, TRUE);
1487 UpdateWindow (hwnd);
1489 return TRUE;
1493 __inline__ static LRESULT
1494 TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1496 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
1500 static LRESULT
1501 TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1504 TBUTTON_INFO *btnPtr;
1505 HDC hdc;
1506 INT nIndex;
1508 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1509 if (nIndex == -1)
1510 return FALSE;
1512 btnPtr = &infoPtr->buttons[nIndex];
1513 if (LOWORD(lParam) == FALSE)
1514 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
1515 else
1516 btnPtr->fsState |= TBSTATE_INDETERMINATE;
1518 hdc = GetDC (hwnd);
1519 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1520 ReleaseDC (hwnd, hdc);
1522 return TRUE;
1526 static LRESULT
1527 TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1529 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1530 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1531 INT nIndex = (INT)wParam;
1532 TBUTTON_INFO *oldButtons;
1533 HDC hdc;
1535 if (lpTbb == NULL)
1536 return FALSE;
1537 if (nIndex < 0)
1538 return FALSE;
1540 TRACE (toolbar, "inserting button index=%d\n", nIndex);
1541 if (nIndex > infoPtr->nNumButtons) {
1542 nIndex = infoPtr->nNumButtons;
1543 TRACE (toolbar, "adjust index=%d\n", nIndex);
1546 oldButtons = infoPtr->buttons;
1547 infoPtr->nNumButtons++;
1548 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
1549 /* pre insert copy */
1550 if (nIndex > 0) {
1551 memcpy (&infoPtr->buttons[0], &oldButtons[0],
1552 nIndex * sizeof(TBUTTON_INFO));
1555 /* insert new button */
1556 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
1557 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
1558 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
1559 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
1560 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
1561 infoPtr->buttons[nIndex].iString = lpTbb->iString;
1563 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
1564 TTTOOLINFOA ti;
1566 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1567 ti.cbSize = sizeof (TTTOOLINFOA);
1568 ti.hwnd = hwnd;
1569 ti.uId = lpTbb->idCommand;
1570 ti.hinst = 0;
1571 ti.lpszText = LPSTR_TEXTCALLBACKA;
1573 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
1574 0, (LPARAM)&ti);
1577 /* post insert copy */
1578 if (nIndex < infoPtr->nNumButtons - 1) {
1579 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
1580 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
1583 COMCTL32_Free (oldButtons);
1585 TOOLBAR_CalcToolbar (hwnd);
1587 hdc = GetDC (hwnd);
1588 TOOLBAR_Refresh (hwnd, hdc);
1589 ReleaseDC (hwnd, hdc);
1591 return TRUE;
1595 /* << TOOLBAR_InsertButton32W >> */
1596 /* << TOOLBAR_InsertMarkHitTest >> */
1599 static LRESULT
1600 TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
1602 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1603 INT nIndex;
1605 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1606 if (nIndex == -1)
1607 return FALSE;
1609 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
1613 static LRESULT
1614 TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
1616 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1617 INT nIndex;
1619 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1620 if (nIndex == -1)
1621 return FALSE;
1623 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
1627 static LRESULT
1628 TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
1630 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1631 INT nIndex;
1633 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1634 if (nIndex == -1)
1635 return FALSE;
1637 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
1641 static LRESULT
1642 TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
1644 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1645 INT nIndex;
1647 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1648 if (nIndex == -1)
1649 return FALSE;
1651 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
1655 static LRESULT
1656 TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1658 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1659 INT nIndex;
1661 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1662 if (nIndex == -1)
1663 return FALSE;
1665 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
1669 static LRESULT
1670 TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
1672 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1673 INT nIndex;
1675 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1676 if (nIndex == -1)
1677 return FALSE;
1679 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
1683 /* << TOOLBAR_LoadImages >> */
1684 /* << TOOLBAR_MapAccelerator >> */
1685 /* << TOOLBAR_MarkButton >> */
1686 /* << TOOLBAR_MoveButton >> */
1689 static LRESULT
1690 TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
1692 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1693 TBUTTON_INFO *btnPtr;
1694 HDC hdc;
1695 INT nIndex;
1697 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1698 if (nIndex == -1)
1699 return FALSE;
1701 btnPtr = &infoPtr->buttons[nIndex];
1702 if (LOWORD(lParam) == FALSE)
1703 btnPtr->fsState &= ~TBSTATE_PRESSED;
1704 else
1705 btnPtr->fsState |= TBSTATE_PRESSED;
1707 hdc = GetDC (hwnd);
1708 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
1709 ReleaseDC (hwnd, hdc);
1711 return TRUE;
1715 /* << TOOLBAR_ReplaceBitmap >> */
1718 static LRESULT
1719 TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1721 #if 0
1722 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1723 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
1725 if (lpSave == NULL) return 0;
1727 if ((BOOL)wParam) {
1728 /* save toolbar information */
1729 FIXME (toolbar, "save to \"%s\" \"%s\"\n",
1730 lpSave->pszSubKey, lpSave->pszValueName);
1734 else {
1735 /* restore toolbar information */
1737 FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
1738 lpSave->pszSubKey, lpSave->pszValueName);
1742 #endif
1744 return 0;
1748 /* << TOOLBAR_SaveRestore32W >> */
1749 /* << TOOLBAR_SetAnchorHighlight >> */
1752 static LRESULT
1753 TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1755 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1757 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
1758 return FALSE;
1760 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
1761 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
1763 return TRUE;
1767 static LRESULT
1768 TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1770 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1771 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
1772 TBUTTON_INFO *btnPtr;
1773 INT nIndex;
1775 if (lptbbi == NULL)
1776 return FALSE;
1777 if (lptbbi->cbSize < sizeof(LPTBBUTTONINFOA))
1778 return FALSE;
1780 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
1781 if (nIndex == -1)
1782 return FALSE;
1784 btnPtr = &infoPtr->buttons[nIndex];
1785 if (lptbbi->dwMask & TBIF_COMMAND)
1786 btnPtr->idCommand = lptbbi->idCommand;
1787 if (lptbbi->dwMask & TBIF_IMAGE)
1788 btnPtr->iBitmap = lptbbi->iImage;
1789 if (lptbbi->dwMask & TBIF_LPARAM)
1790 btnPtr->dwData = lptbbi->lParam;
1791 /* if (lptbbi->dwMask & TBIF_SIZE) */
1792 /* btnPtr->cx = lptbbi->cx; */
1793 if (lptbbi->dwMask & TBIF_STATE)
1794 btnPtr->fsState = lptbbi->fsState;
1795 if (lptbbi->dwMask & TBIF_STYLE)
1796 btnPtr->fsStyle = lptbbi->fsStyle;
1798 if (lptbbi->dwMask & TBIF_TEXT) {
1799 if ((btnPtr->iString >= 0) ||
1800 (btnPtr->iString < infoPtr->nNumStrings)) {
1801 #if 0
1802 CHAR **lpString = &infoPtr->strings[btnPtr->iString];
1803 INT len = lstrlenA (lptbbi->pszText);
1804 *lpString = COMCTL32_ReAlloc (lpString, sizeof(char)*(len+1));
1805 #endif
1807 /* this is the ultimate sollution */
1808 /* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
1812 return TRUE;
1816 /* << TOOLBAR_SetButtonInfo32W >> */
1819 static LRESULT
1820 TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1822 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1824 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
1825 return FALSE;
1827 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
1828 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
1830 return TRUE;
1834 static LRESULT
1835 TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
1837 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1839 if (infoPtr == NULL)
1840 return FALSE;
1842 infoPtr->cxMin = (INT)LOWORD(lParam);
1843 infoPtr->cxMax = (INT)HIWORD(lParam);
1845 return TRUE;
1849 static LRESULT
1850 TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
1852 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1853 INT nIndex = (INT)wParam;
1855 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
1856 return FALSE;
1858 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
1860 if (infoPtr->hwndToolTip) {
1862 FIXME (toolbar, "change tool tip!\n");
1866 return TRUE;
1870 /* << TOOLBAR_SetColorScheme >> */
1873 static LRESULT
1874 TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1877 HIMAGELIST himlTemp;
1879 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
1880 return 0;
1882 himlTemp = infoPtr->himlDis;
1883 infoPtr->himlDis = (HIMAGELIST)lParam;
1885 /* FIXME: redraw ? */
1887 return (LRESULT)himlTemp;
1891 static LRESULT
1892 TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
1894 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1895 DWORD dwTemp;
1897 dwTemp = infoPtr->dwDTFlags;
1898 infoPtr->dwDTFlags =
1899 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
1901 return (LRESULT)dwTemp;
1905 static LRESULT
1906 TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
1908 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1909 DWORD dwTemp;
1911 dwTemp = infoPtr->dwExStyle;
1912 infoPtr->dwExStyle = (DWORD)lParam;
1914 return (LRESULT)dwTemp;
1918 static LRESULT
1919 TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1921 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
1922 HIMAGELIST himlTemp;
1924 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
1925 return 0;
1927 himlTemp = infoPtr->himlHot;
1928 infoPtr->himlHot = (HIMAGELIST)lParam;
1930 /* FIXME: redraw ? */
1932 return (LRESULT)himlTemp;
1936 /* << TOOLBAR_SetHotItem >> */
1939 static LRESULT
1940 TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1942 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1943 HIMAGELIST himlTemp;
1945 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
1946 return 0;
1948 himlTemp = infoPtr->himlDef;
1949 infoPtr->himlDef = (HIMAGELIST)lParam;
1951 /* FIXME: redraw ? */
1953 return (LRESULT)himlTemp;
1957 static LRESULT
1958 TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
1960 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1961 HDC hdc;
1963 infoPtr->nIndent = (INT)wParam;
1965 TOOLBAR_CalcToolbar (hwnd);
1967 hdc = GetDC (hwnd);
1968 TOOLBAR_Refresh (hwnd, hdc);
1969 ReleaseDC (hwnd, hdc);
1971 return TRUE;
1975 /* << TOOLBAR_SetInsertMark >> */
1978 static LRESULT
1979 TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1981 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1983 infoPtr->clrInsertMark = (COLORREF)lParam;
1985 /* FIXME : redraw ??*/
1987 return 0;
1991 static LRESULT
1992 TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
1994 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1996 if (infoPtr == NULL)
1997 return FALSE;
1999 infoPtr->nMaxTextRows = (INT)wParam;
2001 return TRUE;
2005 /* << TOOLBAR_SetPadding >> */
2008 static LRESULT
2009 TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
2011 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2012 HWND hwndOldNotify;
2014 if (infoPtr == NULL)
2015 return 0;
2016 hwndOldNotify = infoPtr->hwndNotify;
2017 infoPtr->hwndNotify = (HWND)wParam;
2019 return hwndOldNotify;
2023 static LRESULT
2024 TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2026 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2027 LPRECT lprc = (LPRECT)lParam;
2028 HDC hdc;
2030 if (LOWORD(wParam) > 1) {
2032 FIXME (toolbar, "multiple rows not supported!\n");
2036 /* recalculate toolbar */
2037 TOOLBAR_CalcToolbar (hwnd);
2039 /* return bounding rectangle */
2040 if (lprc) {
2041 lprc->left = infoPtr->rcBound.left;
2042 lprc->right = infoPtr->rcBound.right;
2043 lprc->top = infoPtr->rcBound.top;
2044 lprc->bottom = infoPtr->rcBound.bottom;
2047 /* repaint toolbar */
2048 hdc = GetDC (hwnd);
2049 TOOLBAR_Refresh (hwnd, hdc);
2050 ReleaseDC (hwnd, hdc);
2052 return 0;
2056 static LRESULT
2057 TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2059 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2060 TBUTTON_INFO *btnPtr;
2061 HDC hdc;
2062 INT nIndex;
2064 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2065 if (nIndex == -1)
2066 return FALSE;
2068 btnPtr = &infoPtr->buttons[nIndex];
2069 btnPtr->fsState = LOWORD(lParam);
2071 hdc = GetDC (hwnd);
2072 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2073 ReleaseDC (hwnd, hdc);
2075 return TRUE;
2079 static LRESULT
2080 TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2082 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2083 TBUTTON_INFO *btnPtr;
2084 HDC hdc;
2085 INT nIndex;
2087 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2088 if (nIndex == -1)
2089 return FALSE;
2091 btnPtr = &infoPtr->buttons[nIndex];
2092 btnPtr->fsStyle = LOWORD(lParam);
2094 hdc = GetDC (hwnd);
2095 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2096 ReleaseDC (hwnd, hdc);
2098 if (infoPtr->hwndToolTip) {
2100 FIXME (toolbar, "change tool tip!\n");
2104 return TRUE;
2108 __inline__ static LRESULT
2109 TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
2111 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2113 if (infoPtr == NULL)
2114 return 0;
2115 infoPtr->hwndToolTip = (HWND)wParam;
2116 return 0;
2120 static LRESULT
2121 TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2123 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2124 BOOL bTemp;
2126 TRACE (toolbar, "%s hwnd=0x%04x stub!\n",
2127 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
2129 bTemp = infoPtr->bUnicode;
2130 infoPtr->bUnicode = (BOOL)wParam;
2132 return bTemp;
2136 static LRESULT
2137 TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
2139 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2140 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2141 LOGFONTA logFont;
2143 /* initialize info structure */
2144 infoPtr->nButtonHeight = 22;
2145 infoPtr->nButtonWidth = 23;
2146 infoPtr->nBitmapHeight = 15;
2147 infoPtr->nBitmapWidth = 16;
2149 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
2150 infoPtr->nRows = 1;
2151 infoPtr->nMaxTextRows = 1;
2152 infoPtr->cxMin = -1;
2153 infoPtr->cxMax = -1;
2155 infoPtr->bCaptured = FALSE;
2156 infoPtr->bUnicode = IsWindowUnicode (hwnd);
2157 infoPtr->nButtonDown = -1;
2158 infoPtr->nOldHit = -1;
2160 infoPtr->hwndNotify = GetParent (hwnd);
2161 infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
2162 infoPtr->nHotItem = -1;
2163 infoPtr->dwDTFlags = DT_CENTER;
2165 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
2166 infoPtr->hFont = CreateFontIndirectA (&logFont);
2168 if (dwStyle & TBSTYLE_TOOLTIPS) {
2169 /* Create tooltip control */
2170 infoPtr->hwndToolTip =
2171 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
2172 CW_USEDEFAULT, CW_USEDEFAULT,
2173 CW_USEDEFAULT, CW_USEDEFAULT,
2174 hwnd, 0, 0, 0);
2176 /* Send NM_TOOLTIPSCREATED notification */
2177 if (infoPtr->hwndToolTip) {
2178 NMTOOLTIPSCREATED nmttc;
2180 nmttc.hdr.hwndFrom = hwnd;
2181 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
2182 nmttc.hdr.code = NM_TOOLTIPSCREATED;
2183 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2185 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
2186 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
2190 return 0;
2194 static LRESULT
2195 TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
2197 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2199 /* delete tooltip control */
2200 if (infoPtr->hwndToolTip)
2201 DestroyWindow (infoPtr->hwndToolTip);
2203 /* delete button data */
2204 if (infoPtr->buttons)
2205 COMCTL32_Free (infoPtr->buttons);
2207 /* delete strings */
2208 if (infoPtr->strings) {
2209 INT i;
2210 for (i = 0; i < infoPtr->nNumStrings; i++)
2211 if (infoPtr->strings[i])
2212 COMCTL32_Free (infoPtr->strings[i]);
2214 COMCTL32_Free (infoPtr->strings);
2217 /* destroy default image list */
2218 if (infoPtr->himlDef)
2219 ImageList_Destroy (infoPtr->himlDef);
2221 /* destroy disabled image list */
2222 if (infoPtr->himlDis)
2223 ImageList_Destroy (infoPtr->himlDis);
2225 /* destroy hot image list */
2226 if (infoPtr->himlHot)
2227 ImageList_Destroy (infoPtr->himlHot);
2229 /* delete default font */
2230 if (infoPtr->hFont)
2231 DeleteObject (infoPtr->hFont);
2233 /* free toolbar info data */
2234 COMCTL32_Free (infoPtr);
2236 return 0;
2240 static LRESULT
2241 TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
2243 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2245 if (infoPtr->bTransparent)
2246 return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
2248 return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
2252 static LRESULT
2253 TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
2255 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2256 TBUTTON_INFO *btnPtr;
2257 POINT pt;
2258 INT nHit;
2259 HDC hdc;
2261 pt.x = (INT)LOWORD(lParam);
2262 pt.y = (INT)HIWORD(lParam);
2263 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2265 if (nHit >= 0) {
2266 btnPtr = &infoPtr->buttons[nHit];
2267 if (!(btnPtr->fsState & TBSTATE_ENABLED))
2268 return 0;
2269 SetCapture (hwnd);
2270 infoPtr->bCaptured = TRUE;
2271 infoPtr->nButtonDown = nHit;
2273 btnPtr->fsState |= TBSTATE_PRESSED;
2275 hdc = GetDC (hwnd);
2276 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2277 ReleaseDC (hwnd, hdc);
2279 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
2280 TOOLBAR_Customize (hwnd);
2282 return 0;
2286 static LRESULT
2287 TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
2289 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2290 TBUTTON_INFO *btnPtr;
2291 POINT pt;
2292 INT nHit;
2293 HDC hdc;
2295 if (infoPtr->hwndToolTip)
2296 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2297 WM_LBUTTONDOWN, wParam, lParam);
2299 pt.x = (INT)LOWORD(lParam);
2300 pt.y = (INT)HIWORD(lParam);
2301 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2303 if (nHit >= 0) {
2304 btnPtr = &infoPtr->buttons[nHit];
2305 if (!(btnPtr->fsState & TBSTATE_ENABLED))
2306 return 0;
2308 SetCapture (hwnd);
2309 infoPtr->bCaptured = TRUE;
2310 infoPtr->nButtonDown = nHit;
2311 infoPtr->nOldHit = nHit;
2313 btnPtr->fsState |= TBSTATE_PRESSED;
2315 hdc = GetDC (hwnd);
2316 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2317 ReleaseDC (hwnd, hdc);
2320 return 0;
2324 static LRESULT
2325 TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
2327 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2328 TBUTTON_INFO *btnPtr;
2329 POINT pt;
2330 INT nHit;
2331 INT nOldIndex = -1;
2332 HDC hdc;
2333 BOOL bSendMessage = TRUE;
2335 if (infoPtr->hwndToolTip)
2336 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2337 WM_LBUTTONUP, wParam, lParam);
2339 pt.x = (INT)LOWORD(lParam);
2340 pt.y = (INT)HIWORD(lParam);
2341 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2343 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
2344 infoPtr->bCaptured = FALSE;
2345 ReleaseCapture ();
2346 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
2347 btnPtr->fsState &= ~TBSTATE_PRESSED;
2349 if (nHit == infoPtr->nButtonDown) {
2350 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
2351 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2352 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
2353 infoPtr->nButtonDown);
2354 if (nOldIndex == infoPtr->nButtonDown)
2355 bSendMessage = FALSE;
2356 if ((nOldIndex != infoPtr->nButtonDown) &&
2357 (nOldIndex != -1))
2358 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2359 btnPtr->fsState |= TBSTATE_CHECKED;
2361 else {
2362 if (btnPtr->fsState & TBSTATE_CHECKED)
2363 btnPtr->fsState &= ~TBSTATE_CHECKED;
2364 else
2365 btnPtr->fsState |= TBSTATE_CHECKED;
2369 else
2370 bSendMessage = FALSE;
2372 hdc = GetDC (hwnd);
2373 if (nOldIndex != -1)
2374 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
2375 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2376 ReleaseDC (hwnd, hdc);
2378 if (bSendMessage)
2379 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
2380 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
2382 infoPtr->nButtonDown = -1;
2383 infoPtr->nOldHit = -1;
2386 return 0;
2390 static LRESULT
2391 TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
2393 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2394 TBUTTON_INFO *btnPtr;
2395 POINT pt;
2396 INT nHit;
2397 HDC hdc;
2399 if (infoPtr->hwndToolTip)
2400 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
2401 WM_MOUSEMOVE, wParam, lParam);
2403 pt.x = (INT)LOWORD(lParam);
2404 pt.y = (INT)HIWORD(lParam);
2405 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
2407 if (infoPtr->bCaptured) {
2408 if (infoPtr->nOldHit != nHit) {
2409 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
2410 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
2411 btnPtr->fsState &= ~TBSTATE_PRESSED;
2412 hdc = GetDC (hwnd);
2413 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2414 ReleaseDC (hwnd, hdc);
2416 else if (nHit == infoPtr->nButtonDown) {
2417 btnPtr->fsState |= TBSTATE_PRESSED;
2418 hdc = GetDC (hwnd);
2419 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2420 ReleaseDC (hwnd, hdc);
2423 infoPtr->nOldHit = nHit;
2426 return 0;
2430 __inline__ static LRESULT
2431 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2433 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
2434 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
2435 /* else */
2436 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
2440 __inline__ static LRESULT
2441 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2443 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
2444 ((LPRECT)lParam)->top += sysMetrics[SM_CYEDGE];
2446 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
2450 static LRESULT
2451 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2453 TOOLBAR_INFO *infoPtr;
2455 /* allocate memory for info structure */
2456 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
2457 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
2459 /* paranoid!! */
2460 infoPtr->dwStructSize = sizeof(TBBUTTON);
2462 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
2463 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
2464 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
2465 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
2468 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
2472 static LRESULT
2473 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
2475 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2476 RECT rcWindow;
2477 HDC hdc;
2479 if (dwStyle & WS_MINIMIZE)
2480 return 0; /* Nothing to do */
2482 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
2484 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
2485 return 0;
2487 if (!(dwStyle & CCS_NODIVIDER))
2489 GetWindowRect (hwnd, &rcWindow);
2490 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
2491 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
2494 ReleaseDC( hwnd, hdc );
2496 return 0;
2500 __inline__ static LRESULT
2501 TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
2503 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2504 LPNMHDR lpnmh = (LPNMHDR)lParam;
2506 TRACE (toolbar, "passing WM_NOTIFY!\n");
2508 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
2509 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
2511 #if 0
2512 if (lpnmh->code == TTN_GETDISPINFOA) {
2513 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
2515 FIXME (toolbar, "retrieving ASCII string\n");
2518 else if (lpnmh->code == TTN_GETDISPINFOW) {
2519 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
2521 FIXME (toolbar, "retrieving UNICODE string\n");
2524 #endif
2527 return 0;
2531 static LRESULT
2532 TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
2534 HDC hdc;
2535 PAINTSTRUCT ps;
2537 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
2538 TOOLBAR_Refresh (hwnd, hdc);
2539 if (!wParam)
2540 EndPaint (hwnd, &ps);
2541 return 0;
2545 static LRESULT
2546 TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
2548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2549 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
2550 RECT parent_rect;
2551 HWND parent;
2552 /* INT32 x, y; */
2553 INT cx, cy;
2554 INT flags;
2555 UINT uPosFlags = 0;
2557 /* Resize deadlock check */
2558 if (infoPtr->bAutoSize) {
2559 infoPtr->bAutoSize = FALSE;
2560 return 0;
2563 flags = (INT) wParam;
2565 /* FIXME for flags =
2566 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
2569 TRACE (toolbar, "sizing toolbar!\n");
2571 if (flags == SIZE_RESTORED) {
2572 /* width and height don't apply */
2573 parent = GetParent (hwnd);
2574 GetClientRect(parent, &parent_rect);
2576 if (dwStyle & CCS_NORESIZE) {
2577 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
2579 /* FIXME */
2580 /* infoPtr->nWidth = parent_rect.right - parent_rect.left; */
2581 cy = infoPtr->nHeight;
2582 cx = infoPtr->nWidth;
2583 TOOLBAR_CalcToolbar (hwnd);
2584 infoPtr->nWidth = cx;
2585 infoPtr->nHeight = cy;
2587 else {
2588 infoPtr->nWidth = parent_rect.right - parent_rect.left;
2589 TOOLBAR_CalcToolbar (hwnd);
2590 cy = infoPtr->nHeight;
2591 cx = infoPtr->nWidth;
2594 if (dwStyle & CCS_NOPARENTALIGN) {
2595 uPosFlags |= SWP_NOMOVE;
2596 cy = infoPtr->nHeight;
2597 cx = infoPtr->nWidth;
2600 if (!(dwStyle & CCS_NODIVIDER))
2601 cy += sysMetrics[SM_CYEDGE];
2603 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
2604 cx, cy, uPosFlags | SWP_NOZORDER);
2606 return 0;
2610 static LRESULT
2611 TOOLBAR_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
2613 HDC hdc;
2615 TOOLBAR_AutoSize (hwnd, wParam, lParam);
2617 hdc = GetDC (hwnd);
2618 TOOLBAR_Refresh (hwnd, hdc);
2619 ReleaseDC (hwnd, hdc);
2621 return 0;
2626 LRESULT WINAPI
2627 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2629 switch (uMsg)
2631 case TB_ADDBITMAP:
2632 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
2634 case TB_ADDBUTTONSA:
2635 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
2637 /* case TB_ADDBUTTONS32W: */
2639 case TB_ADDSTRINGA:
2640 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
2642 case TB_ADDSTRINGW:
2643 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
2645 case TB_AUTOSIZE:
2646 return TOOLBAR_AutoSize (hwnd, wParam, lParam);
2648 case TB_BUTTONCOUNT:
2649 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
2651 case TB_BUTTONSTRUCTSIZE:
2652 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
2654 case TB_CHANGEBITMAP:
2655 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
2657 case TB_CHECKBUTTON:
2658 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
2660 case TB_COMMANDTOINDEX:
2661 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
2663 case TB_CUSTOMIZE:
2664 return TOOLBAR_Customize (hwnd);
2666 case TB_DELETEBUTTON:
2667 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
2669 case TB_ENABLEBUTTON:
2670 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
2672 /* case TB_GETANCHORHIGHLIGHT: */ /* 4.71 */
2674 case TB_GETBITMAP:
2675 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
2677 case TB_GETBITMAPFLAGS:
2678 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
2680 case TB_GETBUTTON:
2681 return TOOLBAR_GetButton (hwnd, wParam, lParam);
2683 case TB_GETBUTTONINFOA:
2684 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
2686 /* case TB_GETBUTTONINFO32W: */ /* 4.71 */
2688 case TB_GETBUTTONSIZE:
2689 return TOOLBAR_GetButtonSize (hwnd);
2691 case TB_GETBUTTONTEXTA:
2692 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
2694 /* case TB_GETBUTTONTEXT32W: */
2695 /* case TB_GETCOLORSCHEME: */ /* 4.71 */
2697 case TB_GETDISABLEDIMAGELIST:
2698 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
2700 case TB_GETEXTENDEDSTYLE:
2701 return TOOLBAR_GetExtendedStyle (hwnd);
2703 case TB_GETHOTIMAGELIST:
2704 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
2706 /* case TB_GETHOTITEM: */ /* 4.71 */
2708 case TB_GETIMAGELIST:
2709 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
2711 /* case TB_GETINSERTMARK: */ /* 4.71 */
2712 /* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
2714 case TB_GETITEMRECT:
2715 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
2717 case TB_GETMAXSIZE:
2718 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
2720 /* case TB_GETOBJECT: */ /* 4.71 */
2721 /* case TB_GETPADDING: */ /* 4.71 */
2723 case TB_GETRECT:
2724 return TOOLBAR_GetRect (hwnd, wParam, lParam);
2726 case TB_GETROWS:
2727 return TOOLBAR_GetRows (hwnd, wParam, lParam);
2729 case TB_GETSTATE:
2730 return TOOLBAR_GetState (hwnd, wParam, lParam);
2732 case TB_GETSTYLE:
2733 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
2735 case TB_GETTEXTROWS:
2736 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
2738 case TB_GETTOOLTIPS:
2739 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
2741 case TB_GETUNICODEFORMAT:
2742 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
2744 case TB_HIDEBUTTON:
2745 return TOOLBAR_HideButton (hwnd, wParam, lParam);
2747 case TB_HITTEST:
2748 return TOOLBAR_HitTest (hwnd, wParam, lParam);
2750 case TB_INDETERMINATE:
2751 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
2753 case TB_INSERTBUTTONA:
2754 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
2756 /* case TB_INSERTBUTTON32W: */
2757 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
2759 case TB_ISBUTTONCHECKED:
2760 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
2762 case TB_ISBUTTONENABLED:
2763 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
2765 case TB_ISBUTTONHIDDEN:
2766 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
2768 case TB_ISBUTTONHIGHLIGHTED:
2769 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
2771 case TB_ISBUTTONINDETERMINATE:
2772 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
2774 case TB_ISBUTTONPRESSED:
2775 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
2777 /* case TB_LOADIMAGES: */ /* 4.70 */
2778 /* case TB_MAPACCELERATOR32A: */ /* 4.71 */
2779 /* case TB_MAPACCELERATOR32W: */ /* 4.71 */
2780 /* case TB_MARKBUTTON: */ /* 4.71 */
2781 /* case TB_MOVEBUTTON: */ /* 4.71 */
2783 case TB_PRESSBUTTON:
2784 return TOOLBAR_PressButton (hwnd, wParam, lParam);
2786 /* case TB_REPLACEBITMAP: */
2788 case TB_SAVERESTOREA:
2789 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
2791 /* case TB_SAVERESTORE32W: */
2792 /* case TB_SETANCHORHIGHLIGHT: */ /* 4.71 */
2794 case TB_SETBITMAPSIZE:
2795 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
2797 case TB_SETBUTTONINFOA:
2798 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
2800 /* case TB_SETBUTTONINFO32W: */ /* 4.71 */
2802 case TB_SETBUTTONSIZE:
2803 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
2805 case TB_SETBUTTONWIDTH:
2806 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
2808 case TB_SETCMDID:
2809 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
2811 /* case TB_SETCOLORSCHEME: */ /* 4.71 */
2813 case TB_SETDISABLEDIMAGELIST:
2814 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
2816 case TB_SETDRAWTEXTFLAGS:
2817 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
2819 case TB_SETEXTENDEDSTYLE:
2820 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
2822 case TB_SETHOTIMAGELIST:
2823 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
2825 /* case TB_SETHOTITEM: */ /* 4.71 */
2827 case TB_SETIMAGELIST:
2828 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
2830 case TB_SETINDENT:
2831 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
2833 /* case TB_SETINSERTMARK: */ /* 4.71 */
2835 case TB_SETINSERTMARKCOLOR:
2836 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
2838 case TB_SETMAXTEXTROWS:
2839 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
2841 /* case TB_SETPADDING: */ /* 4.71 */
2843 case TB_SETPARENT:
2844 return TOOLBAR_SetParent (hwnd, wParam, lParam);
2846 case TB_SETROWS:
2847 return TOOLBAR_SetRows (hwnd, wParam, lParam);
2849 case TB_SETSTATE:
2850 return TOOLBAR_SetState (hwnd, wParam, lParam);
2852 case TB_SETSTYLE:
2853 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
2855 case TB_SETTOOLTIPS:
2856 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
2858 case TB_SETUNICODEFORMAT:
2859 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
2862 /* case WM_CHAR: */
2864 case WM_CREATE:
2865 return TOOLBAR_Create (hwnd, wParam, lParam);
2867 case WM_DESTROY:
2868 return TOOLBAR_Destroy (hwnd, wParam, lParam);
2870 case WM_ERASEBKGND:
2871 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
2873 /* case WM_GETFONT: */
2874 /* case WM_KEYDOWN: */
2875 /* case WM_KILLFOCUS: */
2877 case WM_LBUTTONDBLCLK:
2878 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
2880 case WM_LBUTTONDOWN:
2881 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
2883 case WM_LBUTTONUP:
2884 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
2886 case WM_MOUSEMOVE:
2887 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
2889 case WM_NCACTIVATE:
2890 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
2892 case WM_NCCALCSIZE:
2893 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
2895 case WM_NCCREATE:
2896 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
2898 case WM_NCPAINT:
2899 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
2901 case WM_NOTIFY:
2902 return TOOLBAR_Notify (hwnd, wParam, lParam);
2904 /* case WM_NOTIFYFORMAT: */
2906 case WM_PAINT:
2907 return TOOLBAR_Paint (hwnd, wParam);
2909 case WM_SIZE:
2910 return TOOLBAR_Size (hwnd, wParam, lParam);
2912 case WM_STYLECHANGED:
2913 return TOOLBAR_StyleChanged (hwnd, wParam, lParam);
2915 /* case WM_SYSCOLORCHANGE: */
2917 /* case WM_WININICHANGE: */
2919 case WM_CHARTOITEM:
2920 case WM_COMMAND:
2921 case WM_DRAWITEM:
2922 case WM_MEASUREITEM:
2923 case WM_VKEYTOITEM:
2924 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2926 default:
2927 if (uMsg >= WM_USER)
2928 ERR (toolbar, "unknown msg %04x wp=%08x lp=%08lx\n",
2929 uMsg, wParam, lParam);
2930 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2932 return 0;
2936 VOID
2937 TOOLBAR_Register (VOID)
2939 WNDCLASSA wndClass;
2941 if (GlobalFindAtomA (TOOLBARCLASSNAMEA)) return;
2943 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2944 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
2945 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
2946 wndClass.cbClsExtra = 0;
2947 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
2948 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2949 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2950 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
2952 RegisterClassA (&wndClass);
2956 VOID
2957 TOOLBAR_Unregister (VOID)
2959 if (GlobalFindAtomA (TOOLBARCLASSNAMEA))
2960 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);