source: trunk/src/comctl32/toolbar.c@ 1431

Last change on this file since 1431 was 1431, checked in by sandervl, 26 years ago

RegisterClass even if atom exists

File size: 116.8 KB
Line 
1/* $Id: toolbar.c,v 1.16 1999-10-24 22:49:47 sandervl Exp $ */
2/*
3 * Toolbar control
4 *
5 * Copyright 1998,1999 Eric Kohl
6 * Copyright 1999 Achim Hasenmueller
7 * Copyright 1999 Christoph Bratschi
8 *
9 * TODO:
10 * - A little bug in TOOLBAR_DrawMasked()
11 * - Button wrapping (under construction).
12 * - Messages.
13 * - Notifications.
14 * - Fix TB_SETROWS.
15 * - Tooltip support (almost complete).
16 * - Fix TOOLBAR_SetButtonInfo32A.
17 * - Drag & drop of buttons
18 *
19 * Testing:
20 * - Run tests using Waite Group Windows95 API Bible Volume 2.
21 * The second cdrom contains executables addstr.exe, btncount.exe,
22 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
23 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
24 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
25 * setparnt.exe, setrows.exe, toolwnd.exe.
26 * - Microsofts controlspy examples.
27 */
28
29/* CB: Odin32/WINE bugs
30 - IMAGELIST_Draw draws a line too at the bottom of the bitmap (toolbar.exe)
31 imagelist uses default size values instead of real bitmap values
32*/
33
34#include <string.h>
35
36#include "winbase.h"
37#include "commctrl.h"
38#include "cache.h"
39#include "comctl32.h"
40#include "toolbar.h"
41
42#define SEPARATOR_WIDTH 8
43#define TOP_BORDER 2
44#define BOTTOM_BORDER 2
45
46#define TOOLBAR_GetInfoPtr(hwnd) ((TOOLBAR_INFO *)GetWindowLongA(hwnd,0))
47
48
49static void
50TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
51{
52 INT x = (lpRect->left + lpRect->right) / 2 - 1;
53 INT yBottom = lpRect->bottom - 3;
54 INT yTop = lpRect->top + 1;
55
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);
63}
64
65
66static void
67TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
68 HDC hdc, INT nState)
69{
70 RECT rcText = btnPtr->rect;
71 HFONT hOldFont;
72 INT nOldBkMode;
73 COLORREF clrOld;
74
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);
81
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);
93 }
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);
98 }
99 else {
100 clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
101 DrawTextW (hdc, infoPtr->strings[btnPtr->iString], -1,
102 &rcText, infoPtr->dwDTFlags);
103 }
104
105 SetTextColor (hdc, clrOld);
106 SelectObject (hdc, hOldFont);
107 if (nOldBkMode != TRANSPARENT)
108 SetBkMode (hdc, nOldBkMode);
109 }
110}
111
112
113static void
114TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
115{
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);
121}
122
123
124static void
125TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
126 HDC hdc, INT x, INT y)
127{
128 /* FIXME: this function is a hack since it uses image list
129 internals directly */
130
131 HIMAGELIST himl = infoPtr->himlDef;
132 HBITMAP hbmMask;
133 HDC hdcImageList;
134 HDC hdcMask;
135
136 if (!himl)
137 return;
138
139 /* create new dc's */
140 hdcImageList = CreateCompatibleDC (0);
141 hdcMask = CreateCompatibleDC (0);
142
143 /* create new bitmap */
144 hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
145 SelectObject (hdcMask, hbmMask);
146
147 /* copy the mask bitmap */
148 SelectObject (hdcImageList, himl->hbmMask);
149 SetBkColor (hdcImageList, RGB(255, 255, 255));
150 SetTextColor (hdcImageList, RGB(0, 0, 0));
151 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
152 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
153
154#if 0
155 /* add white mask from image */
156 SelectObject (hdcImageList, himl->hbmImage);
157 SetBkColor (hdcImageList, RGB(0, 0, 0));
158 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
159 hdcImageList, himl->cx * btnPtr->iBitmap, 0, MERGEPAINT);
160#endif
161
162 /* draw the new mask */
163 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
164 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
165 hdcMask, 0, 0, 0xB8074A);
166
167 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
168 BitBlt (hdc, x, y, himl->cx, himl->cy,
169 hdcMask, 0, 0, 0xB8074A);
170
171 DeleteObject (hbmMask);
172 DeleteDC (hdcMask);
173 DeleteDC (hdcImageList);
174}
175
176
177static void
178TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
179{
180 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
181 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
182 RECT rc;
183
184 if (btnPtr->fsState & TBSTATE_HIDDEN) return;
185
186 rc = btnPtr->rect;
187
188 /* separator */
189 if (btnPtr->fsStyle & TBSTYLE_SEP)
190 {
191 if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->iBitmap == 0))
192 TOOLBAR_DrawFlatSeparator (&rc, hdc);
193 return;
194 }
195
196 /* disabled */
197 if (!(btnPtr->fsState & TBSTATE_ENABLED))
198 {
199 if (!(dwStyle & TBSTYLE_FLAT))
200 DrawEdge (hdc, &rc, EDGE_RAISED,
201 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
202
203 if (infoPtr->himlDis)
204 ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
205 rc.left+1, rc.top+1, ILD_NORMAL);
206 else
207 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
208
209 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
210 return;
211 }
212
213 /* pressed TBSTYLE_BUTTON */
214 if (btnPtr->fsState & TBSTATE_PRESSED)
215 {
216 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
217 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
218 rc.left+2, rc.top+2, ILD_NORMAL);
219 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
220 return;
221 }
222
223 /* checked TBSTYLE_CHECK*/
224 if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
225 (btnPtr->fsState & TBSTATE_CHECKED)) {
226 if (dwStyle & TBSTYLE_FLAT)
227 DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
228 BF_RECT | BF_MIDDLE | BF_ADJUST);
229 else
230 DrawEdge (hdc, &rc, EDGE_SUNKEN,
231 BF_RECT | BF_MIDDLE | BF_ADJUST);
232
233 TOOLBAR_DrawPattern (hdc, &rc);
234
235 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
236 rc.left+2, rc.top+2, ILD_NORMAL);
237
238 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
239 return;
240 }
241
242 /* indeterminate */
243 if (btnPtr->fsState & TBSTATE_INDETERMINATE)
244 {
245 DrawEdge (hdc, &rc, EDGE_RAISED,
246 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
247
248 TOOLBAR_DrawPattern (hdc, &rc);
249 TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
250 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
251 return;
252 }
253
254 /* normal state */
255 if (dwStyle & TBSTYLE_FLAT)
256 {
257 if(btnPtr->bHot)
258 DrawEdge (hdc, &rc, BDR_RAISEDINNER,
259 BF_RECT | BF_MIDDLE | BF_SOFT);
260
261 if(btnPtr->bHot && infoPtr->himlHot)
262 ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
263 rc.left +2, rc.top +2, ILD_NORMAL);
264 else
265 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
266 rc.left +2, rc.top +2, ILD_NORMAL);
267 } else
268 {
269 DrawEdge (hdc, &rc, EDGE_RAISED,
270 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
271
272 ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
273 rc.left+1, rc.top+1, ILD_NORMAL);
274 }
275
276 TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
277}
278
279
280static void
281TOOLBAR_Refresh (HWND hwnd, HDC hdc)
282{
283 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
284 TBUTTON_INFO *btnPtr;
285 INT i;
286
287 /* draw buttons */
288 btnPtr = infoPtr->buttons;
289 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
290 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
291}
292
293
294static void
295TOOLBAR_CalcStrings (HWND hwnd, LPSIZE lpSize)
296{
297 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
298 TBUTTON_INFO *btnPtr;
299 INT i;
300 HDC hdc;
301 HFONT hOldFont;
302 SIZE sz;
303
304 lpSize->cx = 0;
305 lpSize->cy = 0;
306 hdc = GetDC (0);
307 hOldFont = SelectObject (hdc, infoPtr->hFont);
308
309 btnPtr = infoPtr->buttons;
310 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
311 if (!(btnPtr->fsState & TBSTATE_HIDDEN) &&
312 (btnPtr->iString > -1) &&
313 (btnPtr->iString < infoPtr->nNumStrings)) {
314 LPWSTR lpText = infoPtr->strings[btnPtr->iString];
315 GetTextExtentPoint32W (hdc, lpText, lstrlenW (lpText), &sz);
316 if (sz.cx > lpSize->cx)
317 lpSize->cx = sz.cx;
318 if (sz.cy > lpSize->cy)
319 lpSize->cy = sz.cy;
320 }
321 }
322
323 SelectObject (hdc, hOldFont);
324 ReleaseDC (0, hdc);
325
326// TRACE (toolbar, "string size %d x %d!\n", lpSize->cx, lpSize->cy);
327}
328
329/***********************************************************************
330* TOOLBAR_WrapToolbar
331*
332* This function walks through the buttons and seperators in the
333* toolbar, and sets the TBSTATE_WRAP flag only on those items where
334* wrapping should occur based on the width of the toolbar window.
335* It does *not* calculate button placement itself. That task
336* takes place in TOOLBAR_CalcToolbar. If the program wants to manage
337* the toolbar wrapping on it's own, it can use the TBSTYLE_WRAPPABLE
338* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
339*/
340
341static void
342TOOLBAR_WrapToolbar( HWND hwnd )
343{
344 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
345 TBUTTON_INFO *btnPtr;
346 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
347 INT x, cx, i, j;
348 RECT rc;
349 BOOL bWrap, bButtonWrap;
350
351 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
352 /* no layout is necessary. Applications may use this style */
353 /* to perform their own layout on the toolbar. */
354 if( !(dwStyle & TBSTYLE_WRAPABLE) )
355 return;
356
357 btnPtr = infoPtr->buttons;
358 x = infoPtr->nIndent;
359
360 GetClientRect( GetParent(hwnd), &rc );
361 infoPtr->nWidth = rc.right - rc.left;
362 bButtonWrap = FALSE;
363
364 for (i = 0; i < infoPtr->nNumButtons; i++ )
365 {
366 bWrap = FALSE;
367 btnPtr[i].fsState &= ~TBSTATE_WRAP;
368
369 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
370 continue;
371
372 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
373 /* it is the actual width of the separator. This is used for */
374 /* custom controls in toolbars. */
375 if (btnPtr[i].fsStyle & TBSTYLE_SEP)
376 cx = (btnPtr[i].iBitmap > 0) ?
377 btnPtr[i].iBitmap : SEPARATOR_WIDTH;
378 else
379 cx = infoPtr->nButtonWidth;
380
381 /* Two or more adjacent separators form a separator group. */
382 /* The first separator in a group should be wrapped to the */
383 /* next row if the previous wrapping is on a button. */
384 if( bButtonWrap &&
385 (btnPtr[i].fsStyle & TBSTYLE_SEP) &&
386 (i + 1 < infoPtr->nNumButtons ) &&
387 (btnPtr[i + 1].fsStyle & TBSTYLE_SEP) )
388 {
389 btnPtr[i].fsState |= TBSTATE_WRAP;
390 x = infoPtr->nIndent;
391 i++;
392 bButtonWrap = FALSE;
393 continue;
394 }
395
396 /* The layout makes sure the bitmap is visible, but not the button. */
397 if ( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
398 > infoPtr->nWidth )
399 {
400 BOOL bFound = FALSE;
401
402 /* If the current button is a separator and not hidden, */
403 /* go to the next until it reaches a non separator. */
404 /* Wrap the last separator if it is before a button. */
405 while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
406 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
407 i < infoPtr->nNumButtons )
408 {
409 i++;
410 bFound = TRUE;
411 }
412
413 if( bFound && i < infoPtr->nNumButtons )
414 {
415 i--;
416 btnPtr[i].fsState |= TBSTATE_WRAP;
417 x = infoPtr->nIndent;
418 bButtonWrap = FALSE;
419 continue;
420 }
421 else if ( i >= infoPtr->nNumButtons)
422 break;
423
424 /* If the current button is not a separator, find the last */
425 /* separator and wrap it. */
426 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
427 {
428 if ((btnPtr[j].fsStyle & TBSTYLE_SEP) &&
429 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
430 {
431 bFound = TRUE;
432 i = j;
433 x = infoPtr->nIndent;
434 btnPtr[j].fsState |= TBSTATE_WRAP;
435 bButtonWrap = FALSE;
436 break;
437 }
438 }
439
440 /* If no separator available for wrapping, wrap one of */
441 /* non-hidden previous button. */
442 if (!bFound)
443 {
444 for ( j = i - 1;
445 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
446 {
447 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
448 continue;
449
450 bFound = TRUE;
451 i = j;
452 x = infoPtr->nIndent;
453 btnPtr[j].fsState |= TBSTATE_WRAP;
454 bButtonWrap = TRUE;
455 break;
456 }
457 }
458
459 /* If all above failed, wrap the current button. */
460 if (!bFound)
461 {
462 btnPtr[i].fsState |= TBSTATE_WRAP;
463 bFound = TRUE;
464 x = infoPtr->nIndent;
465 if (btnPtr[i].fsState & TBSTYLE_SEP )
466 bButtonWrap = FALSE;
467 else
468 bButtonWrap = TRUE;
469 }
470 }
471 else
472 x += cx;
473 }
474}
475
476/***********************************************************************
477* TOOLBAR_CalcToolbar
478*
479* This function calculates button and separator placement. It first
480* calculates the button sizes, gets the toolbar window width and then
481* calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
482* on. It assigns a new location to each item and sends this location to
483* the tooltip window if appropriate. Finally, it updates the rcBound
484* rect and calculates the new required toolbar window height.
485*/
486
487static void
488TOOLBAR_CalcToolbar (HWND hwnd)
489{
490 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
491 TBUTTON_INFO *btnPtr;
492 INT i, nRows, nSepRows;
493 INT x, y, cx, cy;
494 SIZE sizeString;
495 RECT rc;
496 BOOL bWrap;
497
498 TOOLBAR_CalcStrings (hwnd, &sizeString);
499
500 if (sizeString.cy > 0)
501 infoPtr->nButtonHeight = sizeString.cy + infoPtr->nBitmapHeight + 6;
502 else if (infoPtr->nButtonHeight < infoPtr->nBitmapHeight + 6)
503 infoPtr->nButtonHeight = infoPtr->nBitmapHeight + 6;
504
505 if (sizeString.cx > infoPtr->nBitmapWidth)
506 infoPtr->nButtonWidth = sizeString.cx + 6;
507 else if (infoPtr->nButtonWidth < infoPtr->nBitmapWidth + 6)
508 infoPtr->nButtonWidth = infoPtr->nBitmapWidth + 6;
509
510 TOOLBAR_WrapToolbar( hwnd );
511
512 x = infoPtr->nIndent;
513 y = TOP_BORDER;
514 cx = infoPtr->nButtonWidth;
515 cy = infoPtr->nButtonHeight;
516 nRows = nSepRows = 0;
517
518 infoPtr->rcBound.top = y;
519 infoPtr->rcBound.left = x;
520 infoPtr->rcBound.bottom = y + cy;
521 infoPtr->rcBound.right = x;
522
523 btnPtr = infoPtr->buttons;
524 GetClientRect( GetParent(hwnd), &rc );
525 infoPtr->nWidth = rc.right - rc.left;
526
527 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
528 {
529 bWrap = FALSE;
530 if (btnPtr->fsState & TBSTATE_HIDDEN)
531 {
532 SetRectEmpty (&btnPtr->rect);
533 continue;
534 }
535
536 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
537 /* it is the actual width of the separator. This is used for */
538 /* custom controls in toolbars. */
539 if (btnPtr->fsStyle & TBSTYLE_SEP)
540 cx = (btnPtr->iBitmap > 0) ?
541 btnPtr->iBitmap : SEPARATOR_WIDTH;
542 else
543 cx = infoPtr->nButtonWidth;
544
545 if (btnPtr->fsState & TBSTATE_WRAP )
546 bWrap = TRUE;
547
548 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
549
550 if (infoPtr->rcBound.left > x)
551 infoPtr->rcBound.left = x;
552 if (infoPtr->rcBound.right < x + cx)
553 infoPtr->rcBound.right = x + cx;
554 if (infoPtr->rcBound.bottom < y + cy)
555 infoPtr->rcBound.bottom = y + cy;
556
557 /* Set the toolTip only for non-hidden, non-separator button */
558 if (infoPtr->hwndToolTip && !(btnPtr->fsStyle & TBSTYLE_SEP))
559 {
560 TTTOOLINFOA ti;
561
562 ZeroMemory (&ti,sizeof(TTTOOLINFOA));
563 ti.cbSize = sizeof(TTTOOLINFOA);
564 ti.hwnd = hwnd;
565 ti.uId = btnPtr->idCommand;
566 ti.rect = btnPtr->rect;
567 SendMessageA(infoPtr->hwndToolTip,TTM_NEWTOOLRECTA,0,(LPARAM)&ti);
568 }
569
570 /* btnPtr->nRow is zero based. The space between the rows is */
571 /* also considered as a row. */
572 btnPtr->nRow = nRows + nSepRows;
573 if( bWrap )
574 {
575 if ( !(btnPtr->fsStyle & TBSTYLE_SEP) )
576 y += cy;
577 else
578 {
579 /* UNDOCUMENTED: If a separator has a non zero bitmap index, */
580 /* it is the actual width of the separator. This is used for */
581 /* custom controls in toolbars. */
582 y += cy + ( (btnPtr->iBitmap > 0 ) ?
583 btnPtr->iBitmap : SEPARATOR_WIDTH) * 2 /3;
584
585 /* nSepRows is used to calculate the extra height follwoing */
586 /* the last row. */
587 nSepRows++;
588 }
589 x = infoPtr->nIndent;
590 nRows++;
591 }
592 else
593 x += cx;
594 }
595
596 /* infoPtr->nRows is the number of rows on the toolbar */
597 infoPtr->nRows = nRows + nSepRows + 1;
598
599 /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following */
600 /* the last row. */
601 infoPtr->nHeight = TOP_BORDER + (nRows + 1) * infoPtr->nButtonHeight +
602 nSepRows * SEPARATOR_WIDTH * 2 / 3 +
603 nSepRows * (infoPtr->nBitmapHeight + 1) +
604 BOTTOM_BORDER;
605// TRACE (toolbar, "toolbar height %d\n", infoPtr->nHeight);
606}
607
608
609static INT
610TOOLBAR_InternalHitTest (HWND hwnd, LPPOINT lpPt)
611{
612 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
613 TBUTTON_INFO *btnPtr;
614 INT i;
615
616 btnPtr = infoPtr->buttons;
617 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
618 if (btnPtr->fsState & TBSTATE_HIDDEN)
619 continue;
620
621 if (btnPtr->fsStyle & TBSTYLE_SEP) {
622 if (PtInRect (&btnPtr->rect, *lpPt)) {
623// TRACE (toolbar, " ON SEPARATOR %d!\n", i);
624 return -i;
625 }
626 }
627 else {
628 if (PtInRect (&btnPtr->rect, *lpPt)) {
629// TRACE (toolbar, " ON BUTTON %d!\n", i);
630 return i;
631 }
632 }
633 }
634
635// TRACE (toolbar, " NOWHERE!\n");
636 return -1;
637}
638
639
640static INT
641TOOLBAR_GetButtonIndex (TOOLBAR_INFO *infoPtr, INT idCommand)
642{
643 TBUTTON_INFO *btnPtr;
644 INT i;
645
646 btnPtr = infoPtr->buttons;
647 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
648 if (btnPtr->idCommand == idCommand) {
649// TRACE (toolbar, "command=%d index=%d\n", idCommand, i);
650 return i;
651 }
652 }
653// TRACE (toolbar, "no index found for command=%d\n", idCommand);
654 return -1;
655}
656
657
658static INT
659TOOLBAR_GetCheckedGroupButtonIndex (TOOLBAR_INFO *infoPtr, INT nIndex)
660{
661 TBUTTON_INFO *btnPtr;
662 INT nRunIndex;
663
664 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
665 return -1;
666
667 /* check index button */
668 btnPtr = &infoPtr->buttons[nIndex];
669 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
670 if (btnPtr->fsState & TBSTATE_CHECKED)
671 return nIndex;
672 }
673
674 /* check previous buttons */
675 nRunIndex = nIndex - 1;
676 while (nRunIndex >= 0) {
677 btnPtr = &infoPtr->buttons[nRunIndex];
678 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
679 if (btnPtr->fsState & TBSTATE_CHECKED)
680 return nRunIndex;
681 }
682 else
683 break;
684 nRunIndex--;
685 }
686
687 /* check next buttons */
688 nRunIndex = nIndex + 1;
689 while (nRunIndex < infoPtr->nNumButtons) {
690 btnPtr = &infoPtr->buttons[nRunIndex];
691 if ((btnPtr->fsStyle & TBSTYLE_CHECKGROUP) == TBSTYLE_CHECKGROUP) {
692 if (btnPtr->fsState & TBSTATE_CHECKED)
693 return nRunIndex;
694 }
695 else
696 break;
697 nRunIndex++;
698 }
699
700 return -1;
701}
702
703
704static VOID
705TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
706 WPARAM wParam, LPARAM lParam)
707{
708 MSG msg;
709
710 msg.hwnd = hwndMsg;
711 msg.message = uMsg;
712 msg.wParam = wParam;
713 msg.lParam = lParam;
714 msg.time = GetMessageTime();
715 msg.pt.x = LOWORD(GetMessagePos());
716 msg.pt.y = HIWORD(GetMessagePos());
717
718 SendMessageA(hwndTip,TTM_RELAYEVENT,0,(LPARAM)&msg);
719}
720
721static void TBCUSTOMIZE_GetToolNameA(TOOLBAR_INFO* infoPtr,TBUTTON_INFO* btnPtr,INT pos)
722{
723 if (btnPtr->iString > -1 && btnPtr->iString < infoPtr->nNumStrings)
724 {
725 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
726 lstrcpynW(btnPtr->pszName,infoPtr->strings[btnPtr->iString],MAXTOOLNAME*sizeof(WCHAR));
727
728 return;
729 }
730
731 if (btnPtr->fsStyle & TBSTYLE_SEP)
732 {
733 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
734 lstrcpyAtoW(btnPtr->pszName,"Separator");
735 } else
736 {
737 TBNOTIFYA tbNotify;
738
739 tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
740 tbNotify.hdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
741 tbNotify.hdr.code = TBN_GETBUTTONINFOA;
742 tbNotify.iItem = pos;
743 tbNotify.tbButton = (TBBUTTON*)btnPtr;
744 tbNotify.cchText = MAXTOOLNAME;
745 tbNotify.pszText = COMCTL32_Alloc(MAXTOOLNAME);
746 tbNotify.pszText[0] = 0;
747
748 if (!SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify))
749 { //CB: failed, try other methods
750 if (infoPtr->hwndToolTip)
751 { //try to get tool tip text
752 TTTOOLINFOA ti;
753
754 ZeroMemory (&ti,sizeof(ti));
755 ti.cbSize = sizeof(ti);
756 ti.hwnd = infoPtr->hwndToolbar;
757 ti.uId = btnPtr->idCommand;
758 ti.hinst = 0;
759 ti.lpszText = COMCTL32_Alloc(INFOTIPSIZE);
760 ti.lpszText[0] = 0;
761
762 SendMessageA(infoPtr->hwndToolTip,TTM_GETTEXTA,0,(LPARAM)&ti);
763 if (ti.lpszText[0] != 0) lstrcpynA(tbNotify.pszText,ti.lpszText,MAXTOOLNAME);
764 else strcpy(tbNotify.pszText,"Button");
765
766 COMCTL32_Free(ti.lpszText);
767
768 } else strcpy(tbNotify.pszText,"Button");
769 }
770
771 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
772 lstrcpyAtoW(btnPtr->pszName,tbNotify.pszText);
773 COMCTL32_Free(tbNotify.pszText);
774 }
775}
776
777static void TBCUSTOMIZE_GetToolNameW(TOOLBAR_INFO* infoPtr,TBUTTON_INFO* btnPtr,INT pos)
778{
779 if (btnPtr->iString > -1 && btnPtr->iString < infoPtr->nNumStrings)
780 {
781 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
782 lstrcpynW(btnPtr->pszName,infoPtr->strings[btnPtr->iString],MAXTOOLNAME*sizeof(WCHAR));
783
784 return;
785 }
786
787 if (btnPtr->fsStyle & TBSTYLE_SEP)
788 {
789 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
790 lstrcpyAtoW(btnPtr->pszName,"Separator");
791 } else
792 {
793 TBNOTIFYW tbNotify;
794
795 if (!btnPtr->pszName) btnPtr->pszName = COMCTL32_Alloc(MAXTOOLNAME*sizeof(WCHAR));
796 btnPtr->pszName[0] = 0;
797
798 tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
799 tbNotify.hdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
800 tbNotify.hdr.code = TBN_GETBUTTONINFOW;
801 tbNotify.iItem = pos;
802 tbNotify.tbButton = (TBBUTTON*)btnPtr;
803 tbNotify.cchText = MAXTOOLNAME;
804 tbNotify.pszText = btnPtr->pszName;
805
806 if (!SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify))
807 { //CB: failed, try other methods
808 if (infoPtr->hwndToolTip)
809 { //try to get tool tip text
810 TTTOOLINFOW ti;
811
812 ZeroMemory (&ti,sizeof(ti));
813 ti.cbSize = sizeof(ti);
814 ti.hwnd = infoPtr->hwndToolbar;
815 ti.uId = btnPtr->idCommand;
816 ti.hinst = 0;
817 ti.lpszText = COMCTL32_Alloc(INFOTIPSIZE*sizeof(WCHAR));
818 ti.lpszText[0] = 0;
819
820 SendMessageA(infoPtr->hwndToolTip,TTM_GETTEXTW,0,(LPARAM)&ti);
821 if (ti.lpszText[0] != 0) lstrcpynW(btnPtr->pszName,ti.lpszText,MAXTOOLNAME);
822 else lstrcpyAtoW(btnPtr->pszName,"Button");
823
824 COMCTL32_Free(ti.lpszText);
825
826 } else lstrcpyAtoW(btnPtr->pszName,"Button");
827 }
828 }
829}
830
831static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd);
832static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd);
833
834static BOOL TBCUSTOMIZE_FillData(HWND hwnd,TOOLBAR_INFO* infoPtr)
835{
836 TBUTTON_INFO* btnPtr;
837 INT i;
838 INT leftCount = 0;
839 INT rightCount = 0;
840 INT nItem;
841
842 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_RESETCONTENT,0,0);
843 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_RESETCONTENT,0,0);
844
845 /* insert 'virtual' separator button into 'available buttons' list */
846 nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"Separator");
847 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,0);
848
849 /* copy all buttons and append them to the listboxes */
850 btnPtr = infoPtr->buttons;
851 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
852 {
853 if (IsWindowUnicode(infoPtr->hwndNotify))
854 {
855 TBNOTIFYW tbNotify;
856
857 tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
858 tbNotify.hdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
859 tbNotify.iItem = i;
860 tbNotify.tbButton = (TBBUTTON*)btnPtr;
861 tbNotify.cchText = 0;
862 tbNotify.pszText = NULL;
863
864 // send TBN_QUERYINSERT notification
865
866 tbNotify.hdr.code = TBN_QUERYINSERT;
867
868 if (!SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
869
870 // send TBN_QUERYDELETE notification
871
872 tbNotify.hdr.code = TBN_QUERYDELETE;
873
874 btnPtr->bDelete = (BOOL)SendMessageW(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
875
876 //get tool name
877
878 TBCUSTOMIZE_GetToolNameW(infoPtr,btnPtr,i);
879
880 } else
881 {
882 TBNOTIFYA tbNotify;
883
884 tbNotify.hdr.hwndFrom = infoPtr->hwndToolbar;
885 tbNotify.hdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
886 tbNotify.iItem = i;
887 tbNotify.tbButton = (TBBUTTON*)btnPtr;
888 tbNotify.cchText = 0;
889 tbNotify.pszText = NULL;
890
891 // send TBN_QUERYINSERT notification
892
893 tbNotify.hdr.code = TBN_QUERYINSERT;
894
895 if (!SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify)) continue;
896
897 // send TBN_QUERYDELETE notification
898
899 tbNotify.hdr.code = TBN_QUERYDELETE;
900
901 btnPtr->bDelete = (BOOL)SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)tbNotify.hdr.idFrom,(LPARAM)&tbNotify);
902
903 //get tool name
904
905 TBCUSTOMIZE_GetToolNameA(infoPtr,btnPtr,i);
906 }
907
908 if (btnPtr->fsState & TBSTATE_HIDDEN)
909 {
910 nItem = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
911 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
912 leftCount++;
913 } else
914 {
915 nItem = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
916 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,nItem,btnPtr->nCustomID);
917 rightCount++;
918 }
919 }
920
921 if (leftCount == 0 && rightCount == 0) return FALSE;
922
923 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,0,0);
924 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,(rightCount > 0) ? 0:(WPARAM)-1,0);
925
926 TBCUSTOMIZE_AvailSelChange(hwnd);
927 TBCUSTOMIZE_VisSelChange(hwnd);
928
929 return TRUE;
930}
931
932static BOOL TBCUSTOMIZE_InitDialog(HWND hwnd,WPARAM wParam,LPARAM lParam)
933{
934 TOOLBAR_INFO* infoPtr;
935
936 infoPtr = (TOOLBAR_INFO*)lParam;
937 SetWindowLongA(hwnd,DWL_USER,(DWORD)infoPtr);
938
939 if (infoPtr)
940 {
941 INT x;
942
943 //custom ID: 1-nNumButtons, 0 == new separator
944 for (x = 0;x < infoPtr->nNumButtons;x++)
945 {
946 infoPtr->buttons[x].nCustomID = x+1;
947 infoPtr->buttons[x].pszName = NULL;
948 }
949 infoPtr->nMaxCustomID = infoPtr->nNumButtons;
950
951 //save tools
952 infoPtr->nNumOldButtons = infoPtr->nNumButtons;
953 infoPtr->oldButtons = COMCTL32_Alloc(infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
954 memcpy(&infoPtr->oldButtons[0],&infoPtr->buttons[0],infoPtr->nNumOldButtons*sizeof(TBUTTON_INFO));
955
956 if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
957 }
958
959 return TRUE;
960}
961
962static BOOL TBCUSTOMIZE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam)
963{
964 EndDialog(hwnd,FALSE);
965
966 return TRUE;
967}
968
969static VOID TBCUSTOMIZE_Reset(HWND hwnd)
970{
971 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
972 NMHDR nmhdr;
973 INT x;
974
975 //Send TBN_RESET
976 nmhdr.hwndFrom = infoPtr->hwndToolbar;
977 nmhdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
978 nmhdr.code = TBN_RESET;
979
980 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
981
982 for (x = 0;x < infoPtr->nNumOldButtons;x++) COMCTL32_Free(infoPtr->oldButtons[x].pszName);
983
984 //restore data
985 if (infoPtr->nNumButtons != infoPtr->nNumOldButtons)
986 {
987 COMCTL32_Free(infoPtr->buttons);
988 infoPtr->nNumButtons = infoPtr->nNumOldButtons;
989 infoPtr->buttons = COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
990 }
991 memcpy(&infoPtr->buttons[0],&infoPtr->oldButtons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
992
993 if (!TBCUSTOMIZE_FillData(hwnd,infoPtr)) EndDialog(hwnd,FALSE);
994
995 TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
996 InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
997}
998
999static TBUTTON_INFO* TBCUSTOMIZE_GetBtnPtr(TOOLBAR_INFO* infoPtr,INT customID)
1000{
1001 INT x;
1002 TBUTTON_INFO* btnPtr = infoPtr->buttons;
1003
1004 if (customID == 0) return NULL;
1005
1006 for (x = 0;x < infoPtr->nNumButtons;btnPtr++)
1007 if (btnPtr->nCustomID == customID) return btnPtr;
1008
1009 return NULL;
1010}
1011
1012static VOID TBCUSTOMIZE_AddTool(HWND hwnd)
1013{
1014 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1015 LRESULT pos,count;
1016 INT customID;
1017 TBUTTON_INFO* btnPtr;
1018 LRESULT rightSel,rightCount,rightPos;
1019
1020 pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
1021 if (pos == (LRESULT)-1) return;
1022
1023 count = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
1024
1025 customID = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,pos,0);
1026 if (customID == 0) btnPtr = NULL; else
1027 {
1028 btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1029 if (btnPtr == NULL) return;
1030
1031 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_DELETESTRING,pos,0);
1032 }
1033
1034 rightSel = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
1035 rightCount = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
1036
1037 if (rightSel != (LRESULT)-1)
1038 rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_INSERTSTRING,rightSel,(LPARAM)"");
1039 else
1040 rightPos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
1041 if (!btnPtr)
1042 { //new separator
1043 TBUTTON_INFO* newButtons;
1044
1045 newButtons = COMCTL32_Alloc((infoPtr->nNumButtons+1)*sizeof(TBUTTON_INFO));
1046 memcpy(&newButtons[0],&infoPtr->buttons[0],infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
1047 COMCTL32_Free(infoPtr->buttons);
1048
1049 infoPtr->buttons = newButtons;
1050 infoPtr->nNumButtons++;
1051
1052 btnPtr = &infoPtr->buttons[infoPtr->nNumButtons-1];
1053 ZeroMemory(btnPtr,sizeof(TBUTTON_INFO));
1054 btnPtr->fsStyle = TBSTYLE_SEP;
1055 btnPtr->bDelete = TRUE;
1056
1057 customID = ++infoPtr->nMaxCustomID;
1058 btnPtr->nCustomID = customID;
1059 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
1060 } else
1061 {
1062 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,rightPos,customID);
1063 btnPtr->fsState &= ~TBSTATE_HIDDEN;
1064 }
1065 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,rightPos,0);
1066 TBCUSTOMIZE_VisSelChange(hwnd);
1067
1068 if (rightCount > 0)
1069 { //change order
1070 TBUTTON_INFO* btnPtr2;
1071 INT customID2,pos1,pos2;
1072
1073 pos1 = 0;
1074 while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
1075 if (rightPos < rightCount)
1076 { //insert before
1077 customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos+1,0);
1078 pos2 = 0;
1079 while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
1080 } else
1081 { //insert behind
1082 INT x;
1083
1084 customID2 = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,rightPos-1,0);
1085 pos2 = 0;
1086 while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
1087 //exchange to use first alogrithm
1088 x = pos1;
1089 pos1 = pos2;
1090 pos2 = x;
1091 }
1092
1093 if (pos1+1 != pos2)
1094 {
1095 TBUTTON_INFO temp;
1096 INT x;
1097
1098 memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
1099 if (pos1 < pos2)
1100 {
1101 for (x = pos1;x < pos2;x++)
1102 memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
1103 memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
1104 } else
1105 {
1106 for (x = pos1-1;x >= pos2;x--)
1107 memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
1108 memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
1109 }
1110 }
1111 }
1112
1113 if (pos == count-1 && pos > 0) pos--;
1114 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,pos,0);
1115 TBCUSTOMIZE_AvailSelChange(hwnd);
1116
1117 TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
1118 InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
1119}
1120
1121static VOID TBCUSTOMIZE_RemoveTool(HWND hwnd)
1122{
1123 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1124 LRESULT pos,count;
1125 INT customID;
1126 TBUTTON_INFO* btnPtr;
1127
1128 pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
1129 if (pos == (LRESULT)-1) return;
1130
1131 count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
1132
1133 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
1134 if (customID == 0) return; //no allowed
1135
1136 btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1137 if (btnPtr == NULL || !btnPtr->bDelete) return;
1138
1139 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_DELETESTRING,pos,0);
1140
1141 if (btnPtr->fsStyle & TBSTYLE_SEP)
1142 { //remove separator
1143 TBUTTON_INFO* newButtons;
1144 INT nIndex,x;
1145
1146 //find pos
1147 for (x = 0;x < infoPtr->nNumButtons;x++) if (&infoPtr->buttons[x] == btnPtr)
1148 {
1149 nIndex = x;
1150 break;
1151 }
1152
1153 infoPtr->nNumButtons--;
1154 newButtons = COMCTL32_Alloc(infoPtr->nNumButtons*sizeof(TBUTTON_INFO));
1155
1156 if (nIndex > 0)
1157 memcpy(&newButtons[0],&infoPtr->buttons[0],nIndex*sizeof(TBUTTON_INFO));
1158
1159 if (nIndex < infoPtr->nNumButtons)
1160 memcpy (&newButtons[nIndex],&infoPtr->buttons[nIndex+1],(infoPtr->nNumButtons-nIndex)*sizeof(TBUTTON_INFO));
1161
1162 COMCTL32_Free(infoPtr->buttons);
1163 infoPtr->buttons = newButtons;
1164 } else
1165 {
1166 LRESULT leftSel,leftCount,leftPos;
1167
1168 leftSel = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
1169 leftCount = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCOUNT,0,0);
1170
1171 if (leftSel == 0)
1172 if (leftCount > 1) leftSel++; else leftSel = -1;
1173
1174 if (leftSel != (LRESULT)-1)
1175 leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_INSERTSTRING,leftSel,(LPARAM)"");
1176 else
1177 leftPos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_ADDSTRING,0,(LPARAM)"");
1178 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETITEMDATA,leftPos,customID);
1179
1180 SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_SETCURSEL,leftPos,0);
1181 TBCUSTOMIZE_AvailSelChange(hwnd);
1182
1183 btnPtr->fsState |= TBSTATE_HIDDEN;
1184
1185 if (leftCount > 1)
1186 { //change order
1187 TBUTTON_INFO* btnPtr2;
1188 INT customID2,pos1,pos2;
1189
1190 pos1 = 0;
1191 while (infoPtr->buttons[pos1].nCustomID != customID) pos1++;
1192 if (leftPos < leftCount)
1193 { //insert before
1194 customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos+1,0);
1195 pos2 = 0;
1196 while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
1197 } else
1198 { //insert behind
1199 INT x;
1200
1201 customID2 = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETITEMDATA,leftPos-1,0);
1202 pos2 = 0;
1203 while (infoPtr->buttons[pos2].nCustomID != customID2) pos2++;
1204 //exchange to use first alogrithm
1205 x = pos1;
1206 pos1 = pos2;
1207 pos2 = x;
1208 }
1209
1210 if (pos1+1 != pos2)
1211 {
1212 TBUTTON_INFO temp;
1213 INT x;
1214
1215 memcpy(&temp,&infoPtr->buttons[pos1],sizeof(TBUTTON_INFO));
1216 if (pos1 < pos2)
1217 {
1218 for (x = pos1;x < pos2;x++)
1219 memcpy(&infoPtr->buttons[x],&infoPtr->buttons[x+1],sizeof(TBUTTON_INFO));
1220 memcpy(&infoPtr->buttons[pos2-1],&temp,sizeof(TBUTTON_INFO));
1221 } else
1222 {
1223 for (x = pos1-1;x >= pos2;x--)
1224 memcpy(&infoPtr->buttons[x+1],&infoPtr->buttons[x],sizeof(TBUTTON_INFO));
1225 memcpy(&infoPtr->buttons[pos2],&temp,sizeof(TBUTTON_INFO));
1226 }
1227 }
1228 }
1229 }
1230
1231 if (pos == count-1) pos--;
1232 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos,0);
1233 TBCUSTOMIZE_VisSelChange(hwnd);
1234
1235 TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
1236 InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
1237}
1238
1239static VOID TBCUSTOMIZE_Help(HWND hwnd)
1240{
1241 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1242 NMHDR nmhdr;
1243
1244 //Send TBN_CUSTHELP
1245 nmhdr.hwndFrom = infoPtr->hwndToolbar;
1246 nmhdr.idFrom = GetWindowLongA(infoPtr->hwndToolbar,GWL_ID);
1247 nmhdr.code = TBN_CUSTHELP;
1248
1249 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
1250}
1251
1252static VOID TBCUSTOMIZE_MoveToolUp(HWND hwnd)
1253{
1254 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1255 LRESULT pos;
1256 TBUTTON_INFO button;
1257 INT customID;
1258 TBUTTON_INFO* btnPtr1,* btnPtr2;
1259
1260 pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
1261 if (pos == (LRESULT)-1 || pos == 0) return;
1262
1263 //update listbox
1264
1265 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
1266 btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1267 if (btnPtr1 == NULL) return;
1268
1269 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos-1,0);
1270 btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1271 if (btnPtr2 == NULL) return;
1272
1273 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
1274 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos-1,btnPtr1->nCustomID);
1275
1276 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos-1,0);
1277 TBCUSTOMIZE_VisSelChange(hwnd);
1278
1279 //update buttons
1280 memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
1281 memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
1282 memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
1283
1284 TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
1285 InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
1286}
1287
1288static VOID TBCUSTOMIZE_MoveToolDown(HWND hwnd)
1289{
1290 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1291 LRESULT pos,count;
1292 TBUTTON_INFO button;
1293 INT customID;
1294 TBUTTON_INFO* btnPtr1,* btnPtr2;
1295
1296 pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
1297 if (pos == (LRESULT)-1) return;
1298
1299 count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
1300 if (pos == count-1) return;
1301
1302 //update listbox
1303
1304 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
1305 btnPtr1 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1306 if (btnPtr1 == NULL) return;
1307
1308 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos+1,0);
1309 btnPtr2 = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1310 if (btnPtr2 == NULL) return;
1311
1312 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos,btnPtr2->nCustomID);
1313 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETITEMDATA,pos+1,btnPtr1->nCustomID);
1314
1315 SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_SETCURSEL,pos+1,0);
1316 TBCUSTOMIZE_VisSelChange(hwnd);
1317
1318 //update buttons
1319 memcpy(&button,btnPtr1,sizeof(TBUTTON_INFO));
1320 memcpy(btnPtr1,btnPtr2,sizeof(TBUTTON_INFO));
1321 memcpy(btnPtr2,&button,sizeof(TBUTTON_INFO));
1322
1323 TOOLBAR_CalcToolbar(infoPtr->hwndToolbar);
1324 InvalidateRect(infoPtr->hwndToolbar,NULL,TRUE);
1325}
1326
1327static VOID TBCUSTOMIZE_AvailSelChange(HWND hwnd)
1328{
1329 LRESULT pos;
1330 HWND hwndBtn;
1331
1332 pos = SendDlgItemMessageA(hwnd,IDC_AVAILBTN_LBOX,LB_GETCURSEL,0,0);
1333
1334 hwndBtn = GetDlgItem(hwnd,IDOK);
1335 EnableWindow(hwndBtn,(pos == (LRESULT)-1) ? FALSE:TRUE);
1336}
1337
1338static VOID TBCUSTOMIZE_VisSelChange(HWND hwnd)
1339{
1340 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1341 LRESULT pos;
1342
1343 pos = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCURSEL,0,0);
1344
1345 if (pos == (LRESULT)-1)
1346 {
1347 EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),FALSE);
1348 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),FALSE);
1349 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),FALSE);
1350 } else
1351 {
1352 INT customID;
1353 TBUTTON_INFO* btnPtr;
1354 LRESULT count;
1355
1356 customID = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETITEMDATA,pos,0);
1357 btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1358 count = SendDlgItemMessageA(hwnd,IDC_TOOLBARBTN_LBOX,LB_GETCOUNT,0,0);
1359
1360 if (btnPtr)
1361 EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),btnPtr->bDelete);
1362 else
1363 EnableWindow(GetDlgItem(hwnd,IDC_REMOVE_BTN),TRUE);
1364 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN),!(pos == 0));
1365 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN),!(pos == count-1));
1366 }
1367}
1368
1369static BOOL TBCUSTOMIZE_Command(HWND hwnd,WPARAM wParam,LPARAM lParam)
1370{
1371 switch(LOWORD(wParam))
1372 {
1373 case IDCANCEL:
1374 EndDialog(hwnd,FALSE);
1375 break;
1376 case IDC_RESET_BTN:
1377 TBCUSTOMIZE_Reset(hwnd);
1378 break;
1379 case IDOK: //== add tool
1380 TBCUSTOMIZE_AddTool(hwnd);
1381 break;
1382 case IDC_REMOVE_BTN:
1383 TBCUSTOMIZE_RemoveTool(hwnd);
1384 break;
1385 case IDC_HELP_BTN:
1386 TBCUSTOMIZE_Help(hwnd);
1387 break;
1388 case IDC_MOVEUP_BTN:
1389 TBCUSTOMIZE_MoveToolUp(hwnd);
1390 break;
1391 case IDC_MOVEDN_BTN:
1392 TBCUSTOMIZE_MoveToolDown(hwnd);
1393 break;
1394 case IDC_AVAILBTN_LBOX:
1395 switch(HIWORD(wParam))
1396 {
1397 case LBN_SELCHANGE:
1398 TBCUSTOMIZE_AvailSelChange(hwnd);
1399 break;
1400 case LBN_DBLCLK:
1401 TBCUSTOMIZE_AddTool(hwnd);
1402 break;
1403 }
1404 break;
1405 case IDC_TOOLBARBTN_LBOX:
1406 switch(HIWORD(wParam))
1407 {
1408 case LBN_SELCHANGE:
1409 TBCUSTOMIZE_VisSelChange(hwnd);
1410 break;
1411 case LBN_DBLCLK:
1412 TBCUSTOMIZE_RemoveTool(hwnd);
1413 break;
1414 }
1415 break;
1416 }
1417
1418 return TRUE;
1419}
1420
1421static BOOL TBCUSTOMIZE_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
1422{
1423 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1424 INT x;
1425
1426 for (x = 0;x < infoPtr->nNumOldButtons;x++)
1427 COMCTL32_Free(infoPtr->oldButtons[x].pszName);
1428 COMCTL32_Free(infoPtr->oldButtons);
1429 infoPtr->oldButtons = NULL;
1430 infoPtr->nNumOldButtons = 0;
1431
1432 return TRUE;
1433}
1434
1435static BOOL TBCUSTOMIZE_DrawItem(HWND hwnd,WPARAM wParam,LPARAM lParam)
1436{
1437 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1438 {
1439 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1440 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
1441 RECT rcButton;
1442 RECT rcText;
1443 HPEN hOldPen;
1444 HBRUSH hOldBrush;
1445 COLORREF oldText = 0;
1446 COLORREF oldBk = 0;
1447 INT customID;
1448 TBUTTON_INFO* btnPtr;
1449 DWORD dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
1450
1451 customID = SendDlgItemMessageA(hwnd,wParam,LB_GETITEMDATA,lpdis->itemID,0);
1452 btnPtr = TBCUSTOMIZE_GetBtnPtr(infoPtr,customID);
1453
1454 if (btnPtr != NULL && !btnPtr->bDelete)
1455 {
1456 if (lpdis->itemState & ODS_FOCUS) oldBk = SetBkColor(lpdis->hDC,GetSysColor(COLOR_HIGHLIGHT));
1457 oldText = SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT));
1458 } else if (lpdis->itemState & ODS_FOCUS)
1459 {
1460 oldBk = SetBkColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
1461 oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
1462 }
1463
1464
1465 hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1466 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
1467
1468 /* fill background rectangle */
1469 Rectangle (lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,lpdis->rcItem.right,lpdis->rcItem.bottom);
1470
1471 /* calculate button and text rectangles */
1472 CopyRect (&rcButton, &lpdis->rcItem);
1473 InflateRect (&rcButton, -1, -1);
1474 CopyRect (&rcText, &rcButton);
1475 rcButton.right = rcButton.left + infoPtr->nBitmapWidth + 6;
1476 rcText.left = rcButton.right + 2;
1477
1478 /* draw focus rectangle */
1479 if (lpdis->itemState & ODS_FOCUS) DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
1480
1481 //draw tool
1482 if (btnPtr && !(btnPtr->fsStyle & TBSTYLE_SEP))
1483 {
1484 //draw button
1485 if (dwStyle & TBSTYLE_FLAT)
1486 {
1487 ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+2,rcButton.top+2,ILD_NORMAL);
1488 } else
1489 {
1490 DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
1491
1492 ImageList_Draw(infoPtr->himlDef,btnPtr->iBitmap,lpdis->hDC,rcButton.left+1,rcButton.top+1,ILD_NORMAL);
1493 }
1494
1495 } else
1496 { //draw separator
1497 if (!(dwStyle & TBSTYLE_FLAT))
1498 DrawEdge (lpdis->hDC,&rcButton,EDGE_RAISED,BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
1499
1500 TOOLBAR_DrawFlatSeparator(&rcButton,lpdis->hDC);
1501 }
1502
1503 /* draw text */
1504 if (btnPtr == NULL)
1505 { //new separator
1506 DrawTextA(lpdis->hDC,"Separator",-1,&rcText,DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1507 } else if (btnPtr->pszName != NULL)
1508 {
1509 DrawTextW(lpdis->hDC,btnPtr->pszName,-1,&rcText,DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1510 }
1511
1512 if (lpdis->itemState & ODS_FOCUS)
1513 {
1514 SetBkColor (lpdis->hDC, oldBk);
1515 SetTextColor (lpdis->hDC, oldText);
1516 }
1517
1518 SelectObject (lpdis->hDC, hOldBrush);
1519 SelectObject (lpdis->hDC, hOldPen);
1520
1521 return TRUE;
1522 }
1523
1524 return FALSE;
1525}
1526
1527static BOOL TBCUSTOMIZE_MeasureItem(HWND hwnd,WPARAM wParam,LPARAM lParam)
1528{
1529 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
1530 {
1531 TOOLBAR_INFO* infoPtr = (TOOLBAR_INFO*)GetWindowLongA(hwnd,DWL_USER);
1532 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
1533
1534 if (infoPtr)
1535 {
1536 DWORD dwStyle = GetWindowLongA(infoPtr->hwndToolbar,GWL_STYLE);
1537
1538 if (dwStyle & TBSTYLE_FLAT)
1539 lpmis->itemHeight = infoPtr->nBitmapHeight+4;
1540 else
1541 lpmis->itemHeight = infoPtr->nBitmapHeight+8;
1542 } else lpmis->itemHeight = 16+8;
1543
1544 return TRUE;
1545 }
1546
1547 return FALSE;
1548}
1549
1550/***********************************************************************
1551 * TOOLBAR_CustomizeDialogProc
1552 * This function implements the toolbar customization dialog.
1553 */
1554static BOOL WINAPI
1555TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1556{
1557 TOOLBAR_INFO *infoPtr;
1558
1559 switch (uMsg)
1560 {
1561 case WM_INITDIALOG:
1562 return TBCUSTOMIZE_InitDialog(hwnd,wParam,lParam);
1563
1564 case WM_CLOSE:
1565 return TBCUSTOMIZE_Close(hwnd,wParam,lParam);
1566
1567 case WM_COMMAND:
1568 return TBCUSTOMIZE_Command(hwnd,wParam,lParam);
1569
1570 case WM_DESTROY:
1571 return TBCUSTOMIZE_Destroy(hwnd,wParam,lParam);
1572
1573 case WM_DRAWITEM:
1574 return TBCUSTOMIZE_DrawItem(hwnd,wParam,lParam);
1575
1576 case WM_MEASUREITEM:
1577 return TBCUSTOMIZE_MeasureItem(hwnd,wParam,lParam);
1578
1579 default:
1580 return FALSE;
1581 }
1582}
1583
1584
1585/***********************************************************************
1586 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
1587 *
1588 */
1589static LRESULT
1590TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
1591{
1592 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1593 LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
1594 INT nIndex = 0,nButtons;
1595 HBITMAP hbmLoad;
1596
1597 if (!lpAddBmp)
1598 return -1;
1599
1600 if (lpAddBmp->hInst == HINST_COMMCTRL)
1601 {
1602 if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
1603 nButtons = 15;
1604 else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
1605 nButtons = 13;
1606 else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
1607 nButtons = 5;
1608 else
1609 return -1;
1610
1611// TRACE ("adding %d internal bitmaps!\n", nButtons);
1612
1613 /* Windows resize all the buttons to the size of a newly added standard Image*/
1614 if (lpAddBmp->nID & 1)
1615 {
1616 /* large icons */
1617 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1618 MAKELPARAM((WORD)26, (WORD)26));
1619 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1620 MAKELPARAM((WORD)33, (WORD)33));
1621 }
1622 else
1623 {
1624 /* small icons */
1625 SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
1626 MAKELPARAM((WORD)16, (WORD)16));
1627 SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
1628 MAKELPARAM((WORD)22, (WORD)22));
1629 }
1630
1631 TOOLBAR_CalcToolbar (hwnd);
1632 }
1633 else
1634 {
1635 nButtons = (INT)wParam;
1636 if (nButtons <= 0)
1637 return -1;
1638
1639// TRACE ("adding %d bitmaps!\n", nButtons);
1640 }
1641
1642 if (!(infoPtr->himlDef)) {
1643 /* create new default image list */
1644// TRACE ("creating default image list!\n");
1645
1646 infoPtr->himlDef =
1647 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
1648 ILC_COLOR | ILC_MASK, nButtons, 2);
1649 infoPtr->himlInt = infoPtr->himlDef;
1650 }
1651
1652 /* Add bitmaps to the default image list */
1653 if (lpAddBmp->hInst == (HINSTANCE)0)
1654 {
1655 nIndex =
1656 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
1657 CLR_DEFAULT);
1658 }
1659 else if (lpAddBmp->hInst == HINST_COMMCTRL)
1660 {
1661 /* Add system bitmaps */
1662 switch (lpAddBmp->nID)
1663 {
1664 case IDB_STD_SMALL_COLOR:
1665 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1666 MAKEINTRESOURCEA(IDB_STD_SMALL));
1667 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1668 hbmLoad, CLR_DEFAULT);
1669 DeleteObject (hbmLoad);
1670 break;
1671
1672 case IDB_STD_LARGE_COLOR:
1673 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1674 MAKEINTRESOURCEA(IDB_STD_LARGE));
1675 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1676 hbmLoad, CLR_DEFAULT);
1677 DeleteObject (hbmLoad);
1678 break;
1679
1680 case IDB_VIEW_SMALL_COLOR:
1681 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1682 MAKEINTRESOURCEA(IDB_VIEW_SMALL));
1683 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1684 hbmLoad, CLR_DEFAULT);
1685 DeleteObject (hbmLoad);
1686 break;
1687
1688 case IDB_VIEW_LARGE_COLOR:
1689 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1690 MAKEINTRESOURCEA(IDB_VIEW_LARGE));
1691 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1692 hbmLoad, CLR_DEFAULT);
1693 DeleteObject (hbmLoad);
1694 break;
1695
1696 case IDB_HIST_SMALL_COLOR:
1697 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1698 MAKEINTRESOURCEA(IDB_HIST_SMALL));
1699 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1700 hbmLoad, CLR_DEFAULT);
1701 DeleteObject (hbmLoad);
1702 break;
1703
1704 case IDB_HIST_LARGE_COLOR:
1705 hbmLoad = LoadBitmapA (COMCTL32_hModule,
1706 MAKEINTRESOURCEA(IDB_HIST_LARGE));
1707 nIndex = ImageList_AddMasked (infoPtr->himlDef,
1708 hbmLoad, CLR_DEFAULT);
1709 DeleteObject (hbmLoad);
1710 break;
1711
1712 default:
1713 nIndex = ImageList_GetImageCount (infoPtr->himlDef);
1714 //ERR ("invalid imagelist!\n");
1715 break;
1716 }
1717 }
1718 else
1719 {
1720 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
1721 nIndex = ImageList_AddMasked (infoPtr->himlDef, hbmLoad, CLR_DEFAULT);
1722 DeleteObject (hbmLoad);
1723 }
1724
1725 infoPtr->nNumBitmaps += nButtons;
1726
1727 return nIndex;
1728}
1729
1730
1731static LRESULT
1732TOOLBAR_AddButtonsA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1733{
1734 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1735 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
1736 INT nOldButtons, nNewButtons, nAddButtons, nCount;
1737
1738// TRACE (toolbar, "adding %d buttons!\n", wParam);
1739
1740 nAddButtons = (UINT)wParam;
1741 nOldButtons = infoPtr->nNumButtons;
1742 nNewButtons = nOldButtons+nAddButtons;
1743
1744 if (infoPtr->nNumButtons == 0)
1745 {
1746 infoPtr->buttons = COMCTL32_Alloc(sizeof(TBUTTON_INFO)*nNewButtons);
1747 } else
1748 {
1749 TBUTTON_INFO* oldButtons = infoPtr->buttons;
1750
1751 infoPtr->buttons = COMCTL32_Alloc(sizeof(TBUTTON_INFO)*nNewButtons);
1752 memcpy(&infoPtr->buttons[0], &oldButtons[0],nOldButtons * sizeof(TBUTTON_INFO));
1753 COMCTL32_Free(oldButtons);
1754 }
1755
1756 infoPtr->nNumButtons = nNewButtons;
1757
1758 /* insert new button data */
1759 for (nCount = 0; nCount < nAddButtons; nCount++)
1760 {
1761 TBUTTON_INFO* btnPtr = &infoPtr->buttons[nOldButtons+nCount];
1762
1763 btnPtr->iBitmap = lpTbb[nCount].iBitmap;
1764 btnPtr->idCommand = lpTbb[nCount].idCommand;
1765 btnPtr->fsState = lpTbb[nCount].fsState;
1766 btnPtr->fsStyle = lpTbb[nCount].fsStyle;
1767 btnPtr->dwData = lpTbb[nCount].dwData;
1768 btnPtr->iString = lpTbb[nCount].iString;
1769 btnPtr->bHot = FALSE;
1770 btnPtr->bDelete = FALSE; //only used in customize
1771 btnPtr->pszName = NULL;
1772
1773 if ((infoPtr->hwndToolTip) && !(btnPtr->fsStyle & TBSTYLE_SEP))
1774 {
1775 TTTOOLINFOA ti;
1776
1777 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1778 ti.cbSize = sizeof (TTTOOLINFOA);
1779 ti.hwnd = hwnd;
1780 ti.uId = btnPtr->idCommand;
1781 ti.hinst = 0;
1782 ti.lpszText = LPSTR_TEXTCALLBACKA;
1783
1784 SendMessageA (infoPtr->hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
1785 }
1786 }
1787
1788 TOOLBAR_CalcToolbar(hwnd);
1789
1790 InvalidateRect(hwnd,NULL,FALSE);
1791
1792 return TRUE;
1793}
1794
1795
1796static LRESULT TOOLBAR_AddButtonsW(HWND hwnd,WPARAM wParam,LPARAM lParam)
1797{
1798 //CB: just call AddButtonsA, no Unicode used?!?
1799
1800 return TOOLBAR_AddButtonsA(hwnd,wParam,lParam);
1801}
1802
1803/* << TOOLBAR_AddButtons32W >> */
1804
1805
1806static LRESULT
1807TOOLBAR_AddStringA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1808{
1809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1810 INT nIndex;
1811
1812 if ((wParam) && (HIWORD(lParam) == 0)) {
1813 char szString[256];
1814 INT len;
1815// TRACE (toolbar, "adding string from resource!\n");
1816
1817 len = LoadStringA ((HINSTANCE)wParam, (UINT)lParam,
1818 szString, 256);
1819
1820// TRACE (toolbar, "len=%d \"%s\"\n", len, szString);
1821 nIndex = infoPtr->nNumStrings;
1822 if (infoPtr->nNumStrings == 0) {
1823 infoPtr->strings =
1824 COMCTL32_Alloc (sizeof(LPWSTR));
1825 }
1826 else {
1827 LPWSTR *oldStrings = infoPtr->strings;
1828 infoPtr->strings =
1829 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1830 memcpy (&infoPtr->strings[0], &oldStrings[0],
1831 sizeof(LPWSTR) * infoPtr->nNumStrings);
1832 COMCTL32_Free (oldStrings);
1833 }
1834
1835 infoPtr->strings[infoPtr->nNumStrings] =
1836 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1837 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], szString);
1838 infoPtr->nNumStrings++;
1839 }
1840 else {
1841 LPSTR p = (LPSTR)lParam;
1842 INT len;
1843
1844 if (p == NULL)
1845 return -1;
1846// TRACE (toolbar, "adding string(s) from array!\n");
1847 nIndex = infoPtr->nNumStrings;
1848 while (*p) {
1849 len = lstrlenA (p);
1850// TRACE (toolbar, "len=%d \"%s\"\n", len, p);
1851
1852 if (infoPtr->nNumStrings == 0) {
1853 infoPtr->strings =
1854 COMCTL32_Alloc (sizeof(LPWSTR));
1855 }
1856 else {
1857 LPWSTR *oldStrings = infoPtr->strings;
1858 infoPtr->strings =
1859 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1860 memcpy (&infoPtr->strings[0], &oldStrings[0],
1861 sizeof(LPWSTR) * infoPtr->nNumStrings);
1862 COMCTL32_Free (oldStrings);
1863 }
1864
1865 infoPtr->strings[infoPtr->nNumStrings] =
1866 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1867 lstrcpyAtoW (infoPtr->strings[infoPtr->nNumStrings], p);
1868 infoPtr->nNumStrings++;
1869
1870 p += (len+1);
1871 }
1872 }
1873
1874 return nIndex;
1875}
1876
1877
1878static LRESULT
1879TOOLBAR_AddStringW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1880{
1881 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1882 INT nIndex;
1883
1884 if ((wParam) && (HIWORD(lParam) == 0)) {
1885 WCHAR szString[256];
1886 INT len;
1887// TRACE (toolbar, "adding string from resource!\n");
1888
1889 len = LoadStringW ((HINSTANCE)wParam, (UINT)lParam,
1890 szString, 256);
1891
1892// TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(szString));
1893 nIndex = infoPtr->nNumStrings;
1894 if (infoPtr->nNumStrings == 0) {
1895 infoPtr->strings =
1896 COMCTL32_Alloc (sizeof(LPWSTR));
1897 }
1898 else {
1899 LPWSTR *oldStrings = infoPtr->strings;
1900 infoPtr->strings =
1901 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1902 memcpy (&infoPtr->strings[0], &oldStrings[0],
1903 sizeof(LPWSTR) * infoPtr->nNumStrings);
1904 COMCTL32_Free (oldStrings);
1905 }
1906
1907 infoPtr->strings[infoPtr->nNumStrings] =
1908 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1909 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], szString);
1910 infoPtr->nNumStrings++;
1911 }
1912 else {
1913 LPWSTR p = (LPWSTR)lParam;
1914 INT len;
1915
1916 if (p == NULL)
1917 return -1;
1918// TRACE (toolbar, "adding string(s) from array!\n");
1919 nIndex = infoPtr->nNumStrings;
1920 while (*p) {
1921 len = lstrlenW (p);
1922// TRACE (toolbar, "len=%d \"%s\"\n", len, debugstr_w(p));
1923
1924 if (infoPtr->nNumStrings == 0) {
1925 infoPtr->strings =
1926 COMCTL32_Alloc (sizeof(LPWSTR));
1927 }
1928 else {
1929 LPWSTR *oldStrings = infoPtr->strings;
1930 infoPtr->strings =
1931 COMCTL32_Alloc (sizeof(LPWSTR) * (infoPtr->nNumStrings + 1));
1932 memcpy (&infoPtr->strings[0], &oldStrings[0],
1933 sizeof(LPWSTR) * infoPtr->nNumStrings);
1934 COMCTL32_Free (oldStrings);
1935 }
1936
1937 infoPtr->strings[infoPtr->nNumStrings] =
1938 COMCTL32_Alloc (sizeof(WCHAR)*(len+1));
1939 lstrcpyW (infoPtr->strings[infoPtr->nNumStrings], p);
1940 infoPtr->nNumStrings++;
1941
1942 p += (len+1);
1943 }
1944 }
1945
1946 return nIndex;
1947}
1948
1949
1950static LRESULT
1951TOOLBAR_AutoSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1952{
1953 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1954 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1955 RECT parent_rect;
1956 HWND parent;
1957 /* INT32 x, y; */
1958 INT cx, cy;
1959 UINT uPosFlags = 0;
1960
1961// TRACE (toolbar, "resize forced!\n");
1962
1963 parent = GetParent (hwnd);
1964 GetClientRect(parent, &parent_rect);
1965
1966 if (dwStyle & CCS_NORESIZE) {
1967 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
1968 cx = 0;
1969 cy = 0;
1970 }
1971 else {
1972 infoPtr->nWidth = parent_rect.right - parent_rect.left;
1973 TOOLBAR_CalcToolbar (hwnd);
1974 InvalidateRect( hwnd, NULL, TRUE );
1975 cy = infoPtr->nHeight;
1976 cx = infoPtr->nWidth;
1977 }
1978
1979 if (dwStyle & CCS_NOPARENTALIGN)
1980 uPosFlags |= SWP_NOMOVE;
1981
1982 if (!(dwStyle & CCS_NODIVIDER))
1983 cy += GetSystemMetrics(SM_CYEDGE);
1984
1985 infoPtr->bAutoSize = TRUE;
1986 SetWindowPos (hwnd, HWND_TOP, parent_rect.left, parent_rect.top,
1987 cx, cy, uPosFlags);
1988
1989 return 0;
1990}
1991
1992
1993static LRESULT
1994TOOLBAR_ButtonCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
1995{
1996 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
1997
1998 return infoPtr->nNumButtons;
1999}
2000
2001
2002static LRESULT
2003TOOLBAR_ButtonStructSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2004{
2005 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2006
2007 if (infoPtr == NULL) {
2008// ERR (toolbar, "(0x%x, 0x%x, 0x%lx)\n", hwnd, wParam, lParam);
2009// ERR (toolbar, "infoPtr == NULL!\n");
2010 return 0;
2011 }
2012
2013 infoPtr->dwStructSize = (DWORD)wParam;
2014
2015 return 0;
2016}
2017
2018
2019static LRESULT
2020TOOLBAR_ChangeBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2021{
2022 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2023 TBUTTON_INFO *btnPtr;
2024 HDC hdc;
2025 INT nIndex;
2026
2027 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2028 if (nIndex == -1)
2029 return FALSE;
2030
2031 btnPtr = &infoPtr->buttons[nIndex];
2032 btnPtr->iBitmap = LOWORD(lParam);
2033
2034 hdc = GetDC (hwnd);
2035 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2036 ReleaseDC (hwnd, hdc);
2037
2038 return TRUE;
2039}
2040
2041
2042static LRESULT
2043TOOLBAR_CheckButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2044{
2045 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2046 TBUTTON_INFO *btnPtr;
2047 HDC hdc;
2048 INT nIndex;
2049 INT nOldIndex = -1;
2050
2051 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2052 if (nIndex == -1)
2053 return FALSE;
2054
2055 btnPtr = &infoPtr->buttons[nIndex];
2056
2057 if (!(btnPtr->fsStyle & TBSTYLE_CHECK))
2058 return FALSE;
2059
2060 if (LOWORD(lParam) == FALSE)
2061 btnPtr->fsState &= ~TBSTATE_CHECKED;
2062 else {
2063 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
2064 nOldIndex =
2065 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
2066 if (nOldIndex == nIndex)
2067 return 0;
2068 if (nOldIndex != -1)
2069 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
2070 }
2071 btnPtr->fsState |= TBSTATE_CHECKED;
2072 }
2073
2074 hdc = GetDC (hwnd);
2075 if (nOldIndex != -1)
2076 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
2077 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2078 ReleaseDC (hwnd, hdc);
2079
2080 /* FIXME: Send a WM_NOTIFY?? */
2081
2082 return TRUE;
2083}
2084
2085
2086static LRESULT
2087TOOLBAR_CommandToIndex (HWND hwnd, WPARAM wParam, LPARAM lParam)
2088{
2089 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2090
2091 return TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2092}
2093
2094static LRESULT
2095TOOLBAR_Customize (HWND hwnd)
2096{
2097 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2098 LRESULT ret;
2099 LPCVOID template;
2100 HRSRC hRes;
2101 NMHDR nmhdr;
2102
2103 if (infoPtr->nNumButtons == 0) return 0;
2104
2105 /* send TBN_BEGINADJUST notification */
2106 nmhdr.hwndFrom = hwnd;
2107 nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
2108 nmhdr.code = TBN_BEGINADJUST;
2109
2110 SendMessageA (infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
2111
2112 if (!(hRes = FindResourceA (COMCTL32_hModule,
2113 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2114 RT_DIALOGA)))
2115 return FALSE;
2116
2117 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2118 return FALSE;
2119
2120 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2121 (LPDLGTEMPLATEA)template,
2122 hwnd,
2123 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2124 (LPARAM)infoPtr);
2125
2126 /* send TBN_ENDADJUST notification */
2127 nmhdr.code = TBN_ENDADJUST;
2128
2129 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
2130
2131 return ret;
2132}
2133
2134
2135static LRESULT
2136TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2137{
2138 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2139 INT nIndex = (INT)wParam;
2140
2141 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2142 return FALSE;
2143
2144 if ((infoPtr->hwndToolTip) &&
2145 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2146 TTTOOLINFOA ti;
2147
2148 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2149 ti.cbSize = sizeof (TTTOOLINFOA);
2150 ti.hwnd = hwnd;
2151 ti.uId = infoPtr->buttons[nIndex].idCommand;
2152
2153 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2154 }
2155
2156 COMCTL32_Free(infoPtr->buttons[nIndex].pszName);
2157
2158 if (infoPtr->nNumButtons == 1)
2159 {
2160// TRACE (toolbar, " simple delete!\n");
2161 COMCTL32_Free (infoPtr->buttons);
2162 infoPtr->buttons = NULL;
2163 infoPtr->nNumButtons = 0;
2164 } else
2165 {
2166 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2167// TRACE(toolbar, "complex delete! [nIndex=%d]\n", nIndex);
2168
2169 infoPtr->nNumButtons--;
2170 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2171 if (nIndex > 0) {
2172 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2173 nIndex * sizeof(TBUTTON_INFO));
2174 }
2175
2176 if (nIndex < infoPtr->nNumButtons) {
2177 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2178 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2179 }
2180
2181 COMCTL32_Free (oldButtons);
2182 }
2183
2184 TOOLBAR_CalcToolbar (hwnd);
2185
2186 InvalidateRect (hwnd, NULL, TRUE);
2187
2188 return TRUE;
2189}
2190
2191
2192static LRESULT
2193TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2194{
2195 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2196 TBUTTON_INFO *btnPtr;
2197 HDC hdc;
2198 INT nIndex;
2199
2200 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2201 if (nIndex == -1)
2202 return FALSE;
2203
2204 btnPtr = &infoPtr->buttons[nIndex];
2205 if (LOWORD(lParam) == FALSE)
2206 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2207 else
2208 btnPtr->fsState |= TBSTATE_ENABLED;
2209
2210 hdc = GetDC (hwnd);
2211 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2212 ReleaseDC (hwnd, hdc);
2213
2214 return TRUE;
2215}
2216
2217
2218/* << TOOLBAR_GetAnchorHighlight >> */
2219
2220
2221static LRESULT
2222TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2223{
2224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2225 INT nIndex;
2226
2227 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2228 if (nIndex == -1)
2229 return -1;
2230
2231 return infoPtr->buttons[nIndex].iBitmap;
2232}
2233
2234
2235static LRESULT
2236TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2237{
2238 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2239}
2240
2241
2242static LRESULT
2243TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2244{
2245 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2246 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2247 INT nIndex = (INT)wParam;
2248 TBUTTON_INFO *btnPtr;
2249
2250 if (infoPtr == NULL)
2251 return FALSE;
2252
2253 if (lpTbb == NULL)
2254 return FALSE;
2255
2256 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2257 return FALSE;
2258
2259 btnPtr = &infoPtr->buttons[nIndex];
2260 lpTbb->iBitmap = btnPtr->iBitmap;
2261 lpTbb->idCommand = btnPtr->idCommand;
2262 lpTbb->fsState = btnPtr->fsState;
2263 lpTbb->fsStyle = btnPtr->fsStyle;
2264 lpTbb->dwData = btnPtr->dwData;
2265 lpTbb->iString = btnPtr->iString;
2266
2267 return TRUE;
2268}
2269
2270
2271static LRESULT
2272TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2273{
2274 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2275 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2276 TBUTTON_INFO *btnPtr;
2277 INT nIndex;
2278
2279 if (infoPtr == NULL)
2280 return -1;
2281 if (lpTbInfo == NULL)
2282 return -1;
2283 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2284 return -1;
2285
2286 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2287 if (nIndex == -1)
2288 return -1;
2289
2290 btnPtr = &infoPtr->buttons[nIndex];
2291
2292 if (lpTbInfo->dwMask & TBIF_COMMAND)
2293 lpTbInfo->idCommand = btnPtr->idCommand;
2294 if (lpTbInfo->dwMask & TBIF_IMAGE)
2295 lpTbInfo->iImage = btnPtr->iBitmap;
2296 if (lpTbInfo->dwMask & TBIF_LPARAM)
2297 lpTbInfo->lParam = btnPtr->dwData;
2298 if (lpTbInfo->dwMask & TBIF_SIZE)
2299 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2300 if (lpTbInfo->dwMask & TBIF_STATE)
2301 lpTbInfo->fsState = btnPtr->fsState;
2302 if (lpTbInfo->dwMask & TBIF_STYLE)
2303 lpTbInfo->fsStyle = btnPtr->fsStyle;
2304 if (lpTbInfo->dwMask & TBIF_TEXT) {
2305 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2306 lstrcpynWtoA (lpTbInfo->pszText,
2307 infoPtr->strings[btnPtr->iString],
2308 lpTbInfo->cchText);
2309 }
2310
2311 return nIndex;
2312}
2313
2314static LRESULT TOOLBAR_GetButtonInfoW(HWND hwnd,WPARAM wParam,LPARAM lParam)
2315{
2316 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2317 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2318 TBUTTON_INFO *btnPtr;
2319 INT nIndex;
2320
2321 if (infoPtr == NULL)
2322 return -1;
2323 if (lpTbInfo == NULL)
2324 return -1;
2325 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2326 return -1;
2327
2328 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2329 if (nIndex == -1)
2330 return -1;
2331
2332 btnPtr = &infoPtr->buttons[nIndex];
2333
2334 if (lpTbInfo->dwMask & TBIF_COMMAND)
2335 lpTbInfo->idCommand = btnPtr->idCommand;
2336 if (lpTbInfo->dwMask & TBIF_IMAGE)
2337 lpTbInfo->iImage = btnPtr->iBitmap;
2338 if (lpTbInfo->dwMask & TBIF_LPARAM)
2339 lpTbInfo->lParam = btnPtr->dwData;
2340 if (lpTbInfo->dwMask & TBIF_SIZE)
2341 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2342 if (lpTbInfo->dwMask & TBIF_STATE)
2343 lpTbInfo->fsState = btnPtr->fsState;
2344 if (lpTbInfo->dwMask & TBIF_STYLE)
2345 lpTbInfo->fsStyle = btnPtr->fsStyle;
2346 if (lpTbInfo->dwMask & TBIF_TEXT) {
2347 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2348 lstrcpynW (lpTbInfo->pszText,
2349 infoPtr->strings[btnPtr->iString],
2350 lpTbInfo->cchText);
2351 }
2352
2353 return nIndex;
2354}
2355
2356/* << TOOLBAR_GetButtonInfo32W >> */
2357
2358
2359static LRESULT
2360TOOLBAR_GetButtonSize (HWND hwnd)
2361{
2362 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2363
2364 return MAKELONG((WORD)infoPtr->nButtonWidth,
2365 (WORD)infoPtr->nButtonHeight);
2366}
2367
2368
2369static LRESULT
2370TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2371{
2372 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2373 INT nIndex, nStringIndex;
2374
2375 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2376 if (nIndex == -1)
2377 return -1;
2378
2379 nStringIndex = infoPtr->buttons[nIndex].iString;
2380
2381// TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
2382
2383 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2384 return -1;
2385
2386 if (lParam == 0) return -1;
2387
2388 lstrcpyWtoA ((LPSTR)lParam, infoPtr->strings[nStringIndex]);
2389
2390 return lstrlenW (infoPtr->strings[nStringIndex]);
2391}
2392
2393static LRESULT TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2394{
2395 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2396 INT nIndex, nStringIndex;
2397
2398 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2399 if (nIndex == -1)
2400 return -1;
2401
2402 nStringIndex = infoPtr->buttons[nIndex].iString;
2403
2404// TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
2405
2406 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2407 return -1;
2408
2409 if (lParam == 0) return -1;
2410
2411 lstrcpyW ((LPWSTR)lParam, infoPtr->strings[nStringIndex]);
2412
2413 return lstrlenW (infoPtr->strings[nStringIndex]);
2414}
2415
2416/* << TOOLBAR_GetButtonText32W >> */
2417/* << TOOLBAR_GetColorScheme >> */
2418
2419
2420static LRESULT
2421TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2422{
2423 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2424
2425 return (LRESULT)infoPtr->himlDis;
2426}
2427
2428
2429static LRESULT
2430TOOLBAR_GetExtendedStyle (HWND hwnd)
2431{
2432 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2433
2434 return infoPtr->dwExStyle;
2435}
2436
2437
2438static LRESULT
2439TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2440{
2441 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2442
2443 return (LRESULT)infoPtr->himlHot;
2444}
2445
2446
2447/* << TOOLBAR_GetHotItem >> */
2448
2449
2450static LRESULT
2451TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2452{
2453 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2454
2455 return (LRESULT)infoPtr->himlDef;
2456}
2457
2458
2459/* << TOOLBAR_GetInsertMark >> */
2460/* << TOOLBAR_GetInsertMarkColor >> */
2461
2462
2463static LRESULT
2464TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2465{
2466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2467 TBUTTON_INFO *btnPtr;
2468 LPRECT lpRect;
2469 INT nIndex;
2470
2471 if (infoPtr == NULL)
2472 return FALSE;
2473 nIndex = (INT)wParam;
2474 btnPtr = &infoPtr->buttons[nIndex];
2475 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2476 return FALSE;
2477 lpRect = (LPRECT)lParam;
2478 if (lpRect == NULL)
2479 return FALSE;
2480 if (btnPtr->fsState & TBSTATE_HIDDEN)
2481 return FALSE;
2482
2483 TOOLBAR_CalcToolbar( hwnd );
2484
2485 lpRect->left = btnPtr->rect.left;
2486 lpRect->right = btnPtr->rect.right;
2487 lpRect->bottom = btnPtr->rect.bottom;
2488 lpRect->top = btnPtr->rect.top;
2489
2490 return TRUE;
2491}
2492
2493
2494static LRESULT
2495TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2496{
2497 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2498 LPSIZE lpSize = (LPSIZE)lParam;
2499
2500 if (lpSize == NULL)
2501 return FALSE;
2502
2503 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2504 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2505
2506// TRACE (toolbar, "maximum size %d x %d\n",
2507// infoPtr->rcBound.right - infoPtr->rcBound.left,
2508// infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2509
2510 return TRUE;
2511}
2512
2513
2514/* << TOOLBAR_GetObject >> */
2515/* << TOOLBAR_GetPadding >> */
2516
2517
2518static LRESULT
2519TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2520{
2521 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2522 TBUTTON_INFO *btnPtr;
2523 LPRECT lpRect;
2524 INT nIndex;
2525
2526 if (infoPtr == NULL)
2527 return FALSE;
2528 nIndex = (INT)wParam;
2529 btnPtr = &infoPtr->buttons[nIndex];
2530 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2531 return FALSE;
2532 lpRect = (LPRECT)lParam;
2533 if (lpRect == NULL)
2534 return FALSE;
2535
2536 lpRect->left = btnPtr->rect.left;
2537 lpRect->right = btnPtr->rect.right;
2538 lpRect->bottom = btnPtr->rect.bottom;
2539 lpRect->top = btnPtr->rect.top;
2540
2541 return TRUE;
2542}
2543
2544
2545static LRESULT
2546TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2547{
2548 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2549
2550 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2551 return infoPtr->nRows;
2552 else
2553 return 1;
2554}
2555
2556
2557static LRESULT
2558TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2559{
2560 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2561 INT nIndex;
2562
2563 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2564 if (nIndex == -1)
2565 return -1;
2566
2567 return infoPtr->buttons[nIndex].fsState;
2568}
2569
2570
2571static LRESULT
2572TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2573{
2574 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2575 INT nIndex;
2576
2577 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2578 if (nIndex == -1)
2579 return -1;
2580
2581 return infoPtr->buttons[nIndex].fsStyle;
2582}
2583
2584
2585static LRESULT
2586TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2587{
2588 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2589
2590 if (infoPtr == NULL)
2591 return 0;
2592
2593 return infoPtr->nMaxTextRows;
2594}
2595
2596
2597static LRESULT
2598TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
2599{
2600 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2601
2602 if (infoPtr == NULL) return 0;
2603 return infoPtr->hwndToolTip;
2604}
2605
2606
2607static LRESULT
2608TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2609{
2610 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2611
2612// TRACE (toolbar, "%s hwnd=0x%x stub!\n",
2613// infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
2614
2615 return infoPtr->bUnicode;
2616}
2617
2618
2619static LRESULT
2620TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2621{
2622 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2623 TBUTTON_INFO *btnPtr;
2624 INT nIndex;
2625
2626 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2627 if (nIndex == -1)
2628 return FALSE;
2629
2630 btnPtr = &infoPtr->buttons[nIndex];
2631 if (LOWORD(lParam) == FALSE)
2632 btnPtr->fsState &= ~TBSTATE_HIDDEN;
2633 else
2634 btnPtr->fsState |= TBSTATE_HIDDEN;
2635
2636 TOOLBAR_CalcToolbar (hwnd);
2637
2638 InvalidateRect (hwnd, NULL, TRUE);
2639
2640 return TRUE;
2641}
2642
2643
2644static LRESULT
2645TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2646{
2647 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
2648}
2649
2650
2651static LRESULT
2652TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2653{
2654 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2655 TBUTTON_INFO *btnPtr;
2656 HDC hdc;
2657 INT nIndex;
2658
2659 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2660 if (nIndex == -1)
2661 return FALSE;
2662
2663 btnPtr = &infoPtr->buttons[nIndex];
2664 if (LOWORD(lParam) == FALSE)
2665 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
2666 else
2667 btnPtr->fsState |= TBSTATE_INDETERMINATE;
2668
2669 hdc = GetDC (hwnd);
2670 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2671 ReleaseDC (hwnd, hdc);
2672
2673 return TRUE;
2674}
2675
2676
2677static LRESULT
2678TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2679{
2680 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2681 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2682 INT nIndex = (INT)wParam;
2683 TBUTTON_INFO *oldButtons;
2684
2685 if (lpTbb == NULL)
2686 return FALSE;
2687 if (nIndex < 0)
2688 return FALSE;
2689
2690// TRACE (toolbar, "inserting button index=%d\n", nIndex);
2691 if (nIndex > infoPtr->nNumButtons) {
2692 nIndex = infoPtr->nNumButtons;
2693// TRACE (toolbar, "adjust index=%d\n", nIndex);
2694 }
2695
2696 oldButtons = infoPtr->buttons;
2697 infoPtr->nNumButtons++;
2698 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2699 /* pre insert copy */
2700 if (nIndex > 0) {
2701 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2702 nIndex * sizeof(TBUTTON_INFO));
2703 }
2704
2705 /* insert new button */
2706 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
2707 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
2708 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
2709 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
2710 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
2711 infoPtr->buttons[nIndex].iString = lpTbb->iString;
2712
2713 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
2714 TTTOOLINFOA ti;
2715
2716 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2717 ti.cbSize = sizeof (TTTOOLINFOA);
2718 ti.hwnd = hwnd;
2719 ti.uId = lpTbb->idCommand;
2720 ti.hinst = 0;
2721 ti.lpszText = LPSTR_TEXTCALLBACKA;
2722
2723 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2724 0, (LPARAM)&ti);
2725 }
2726
2727 /* post insert copy */
2728 if (nIndex < infoPtr->nNumButtons - 1) {
2729 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
2730 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
2731 }
2732
2733 COMCTL32_Free (oldButtons);
2734
2735 TOOLBAR_CalcToolbar (hwnd);
2736
2737 InvalidateRect (hwnd, NULL, FALSE);
2738
2739 return TRUE;
2740}
2741
2742static LRESULT TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2743{
2744 //CB: just call InsertButtonA, no Unicode used?!?
2745
2746 return TOOLBAR_InsertButtonA(hwnd,wParam,lParam);
2747}
2748
2749/* << TOOLBAR_InsertButton32W >> */
2750/* << TOOLBAR_InsertMarkHitTest >> */
2751
2752
2753static LRESULT
2754TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
2755{
2756 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2757 INT nIndex;
2758
2759 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2760 if (nIndex == -1)
2761 return FALSE;
2762
2763 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
2764}
2765
2766
2767static LRESULT
2768TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
2769{
2770 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2771 INT nIndex;
2772
2773 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2774 if (nIndex == -1)
2775 return FALSE;
2776
2777 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
2778}
2779
2780
2781static LRESULT
2782TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
2783{
2784 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2785 INT nIndex;
2786
2787 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2788 if (nIndex == -1)
2789 return FALSE;
2790
2791 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
2792}
2793
2794
2795static LRESULT
2796TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
2797{
2798 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2799 INT nIndex;
2800
2801 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2802 if (nIndex == -1)
2803 return FALSE;
2804
2805 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
2806}
2807
2808
2809static LRESULT
2810TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2811{
2812 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2813 INT nIndex;
2814
2815 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2816 if (nIndex == -1)
2817 return FALSE;
2818
2819 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
2820}
2821
2822
2823static LRESULT
2824TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
2825{
2826 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2827 INT nIndex;
2828
2829 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2830 if (nIndex == -1)
2831 return FALSE;
2832
2833 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
2834}
2835
2836
2837/* << TOOLBAR_LoadImages >> */
2838/* << TOOLBAR_MapAccelerator >> */
2839/* << TOOLBAR_MarkButton >> */
2840/* << TOOLBAR_MoveButton >> */
2841
2842
2843static LRESULT
2844TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2845{
2846 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2847 TBUTTON_INFO *btnPtr;
2848 HDC hdc;
2849 INT nIndex;
2850
2851 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2852 if (nIndex == -1)
2853 return FALSE;
2854
2855 btnPtr = &infoPtr->buttons[nIndex];
2856 if (LOWORD(lParam) == FALSE)
2857 btnPtr->fsState &= ~TBSTATE_PRESSED;
2858 else
2859 btnPtr->fsState |= TBSTATE_PRESSED;
2860
2861 hdc = GetDC (hwnd);
2862 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2863 ReleaseDC (hwnd, hdc);
2864
2865 return TRUE;
2866}
2867
2868
2869/* << TOOLBAR_ReplaceBitmap >> */
2870
2871
2872static LRESULT
2873TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2874{
2875#if 0
2876 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2877 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
2878
2879 if (lpSave == NULL) return 0;
2880
2881 if ((BOOL)wParam) {
2882 /* save toolbar information */
2883// FIXME (toolbar, "save to \"%s\" \"%s\"\n",
2884// lpSave->pszSubKey, lpSave->pszValueName);
2885
2886
2887 }
2888 else {
2889 /* restore toolbar information */
2890
2891// FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
2892// lpSave->pszSubKey, lpSave->pszValueName);
2893
2894
2895 }
2896#endif
2897
2898 return 0;
2899}
2900
2901static LRESULT TOOLBAR_SaveRestoreW(HWND hwnd,WPARAM wParam,LPARAM lParam)
2902{
2903#if 0
2904 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2905 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
2906
2907 if (lpSave == NULL) return 0;
2908
2909 if ((BOOL)wParam) {
2910 /* save toolbar information */
2911// FIXME (toolbar, "save to \"%s\" \"%s\"\n",
2912// lpSave->pszSubKey, lpSave->pszValueName);
2913
2914
2915 }
2916 else {
2917 /* restore toolbar information */
2918
2919// FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
2920// lpSave->pszSubKey, lpSave->pszValueName);
2921
2922
2923 }
2924#endif
2925
2926 return 0;
2927}
2928
2929/* << TOOLBAR_SaveRestore32W >> */
2930/* << TOOLBAR_SetAnchorHighlight >> */
2931
2932
2933static LRESULT
2934TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2935{
2936 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2937
2938 if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
2939
2940 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
2941 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
2942
2943 return TRUE;
2944}
2945
2946
2947static LRESULT
2948TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2949{
2950 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2951 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
2952 TBUTTON_INFO *btnPtr;
2953 INT nIndex;
2954
2955 if (lptbbi == NULL)
2956 return FALSE;
2957 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
2958 return FALSE;
2959
2960 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2961 if (nIndex == -1)
2962 return FALSE;
2963
2964 btnPtr = &infoPtr->buttons[nIndex];
2965 if (lptbbi->dwMask & TBIF_COMMAND)
2966 btnPtr->idCommand = lptbbi->idCommand;
2967 if (lptbbi->dwMask & TBIF_IMAGE)
2968 btnPtr->iBitmap = lptbbi->iImage;
2969 if (lptbbi->dwMask & TBIF_LPARAM)
2970 btnPtr->dwData = lptbbi->lParam;
2971/* if (lptbbi->dwMask & TBIF_SIZE) */
2972/* btnPtr->cx = lptbbi->cx; */
2973 if (lptbbi->dwMask & TBIF_STATE)
2974 btnPtr->fsState = lptbbi->fsState;
2975 if (lptbbi->dwMask & TBIF_STYLE)
2976 btnPtr->fsStyle = lptbbi->fsStyle;
2977
2978 if (lptbbi->dwMask & TBIF_TEXT) {
2979 if ((btnPtr->iString >= 0) ||
2980 (btnPtr->iString < infoPtr->nNumStrings)) {
2981#if 0
2982 CHAR **lpString = &infoPtr->strings[btnPtr->iString]; //wrong, it's Unicode!!!
2983 INT len = lstrlenA (lptbbi->pszText);
2984 *lpString = COMCTL32_ReAlloc (lpString, sizeof(char)*(len+1));
2985#endif
2986
2987 /* this is the ultimate sollution */
2988/* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
2989 }
2990 }
2991
2992 return TRUE;
2993}
2994
2995static LRESULT TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2996{
2997 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2998 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
2999 TBUTTON_INFO *btnPtr;
3000 INT nIndex;
3001
3002 if (lptbbi == NULL)
3003 return FALSE;
3004 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3005 return FALSE;
3006
3007 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3008 if (nIndex == -1)
3009 return FALSE;
3010
3011 btnPtr = &infoPtr->buttons[nIndex];
3012 if (lptbbi->dwMask & TBIF_COMMAND)
3013 btnPtr->idCommand = lptbbi->idCommand;
3014 if (lptbbi->dwMask & TBIF_IMAGE)
3015 btnPtr->iBitmap = lptbbi->iImage;
3016 if (lptbbi->dwMask & TBIF_LPARAM)
3017 btnPtr->dwData = lptbbi->lParam;
3018/* if (lptbbi->dwMask & TBIF_SIZE) */
3019/* btnPtr->cx = lptbbi->cx; */
3020 if (lptbbi->dwMask & TBIF_STATE)
3021 btnPtr->fsState = lptbbi->fsState;
3022 if (lptbbi->dwMask & TBIF_STYLE)
3023 btnPtr->fsStyle = lptbbi->fsStyle;
3024
3025 if (lptbbi->dwMask & TBIF_TEXT) {
3026 if ((btnPtr->iString >= 0) ||
3027 (btnPtr->iString < infoPtr->nNumStrings)) {
3028#if 0
3029 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3030 INT len = lstrlenW (lptbbi->pszText);
3031 *lpString = COMCTL32_ReAlloc (lpString, sizeof(wchar)*(len+1));
3032#endif
3033
3034 /* this is the ultimate sollution */
3035/* Str_SetPtrW (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3036 }
3037 }
3038
3039 return TRUE;
3040}
3041
3042/* << TOOLBAR_SetButtonInfo32W >> */
3043
3044
3045static LRESULT
3046TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3047{
3048 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3049
3050 if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
3051
3052 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3053 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3054
3055 return TRUE;
3056}
3057
3058
3059static LRESULT
3060TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3061{
3062 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3063
3064 if (infoPtr == NULL)
3065 return FALSE;
3066
3067 infoPtr->cxMin = (INT)LOWORD(lParam);
3068 infoPtr->cxMax = (INT)HIWORD(lParam);
3069
3070 return TRUE;
3071}
3072
3073
3074static LRESULT
3075TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3076{
3077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3078 INT nIndex = (INT)wParam;
3079
3080 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3081 return FALSE;
3082
3083 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3084
3085 if (infoPtr->hwndToolTip) {
3086
3087// FIXME (toolbar, "change tool tip!\n");
3088
3089 }
3090
3091 return TRUE;
3092}
3093
3094
3095/* << TOOLBAR_SetColorScheme >> */
3096
3097
3098static LRESULT
3099TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3100{
3101 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3102 HIMAGELIST himlTemp;
3103
3104 himlTemp = infoPtr->himlDis;
3105 infoPtr->himlDis = (HIMAGELIST)lParam;
3106
3107 /* FIXME: redraw ? */
3108
3109 return (LRESULT)himlTemp;
3110}
3111
3112
3113static LRESULT
3114TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3115{
3116 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3117 DWORD dwTemp;
3118
3119 dwTemp = infoPtr->dwDTFlags;
3120 infoPtr->dwDTFlags =
3121 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3122
3123 return (LRESULT)dwTemp;
3124}
3125
3126
3127static LRESULT
3128TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3129{
3130 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3131 DWORD dwTemp;
3132
3133 dwTemp = infoPtr->dwExStyle;
3134 infoPtr->dwExStyle = (DWORD)lParam;
3135
3136 return (LRESULT)dwTemp;
3137}
3138
3139
3140static LRESULT
3141TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142{
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3144 HIMAGELIST himlTemp;
3145
3146 himlTemp = infoPtr->himlHot;
3147 infoPtr->himlHot = (HIMAGELIST)lParam;
3148
3149 /* FIXME: redraw ? */
3150
3151 return (LRESULT)himlTemp;
3152}
3153
3154
3155/* << TOOLBAR_SetHotItem >> */
3156
3157
3158static LRESULT
3159TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3160{
3161 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3162 HIMAGELIST himlTemp;
3163
3164 himlTemp = infoPtr->himlDef;
3165 infoPtr->himlDef = (HIMAGELIST)lParam;
3166
3167 /* FIXME: redraw ? */
3168
3169 return (LRESULT)himlTemp;
3170}
3171
3172
3173static LRESULT
3174TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3175{
3176 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3177
3178 infoPtr->nIndent = (INT)wParam;
3179
3180 TOOLBAR_CalcToolbar (hwnd);
3181
3182 InvalidateRect(hwnd, NULL, FALSE);
3183
3184 return TRUE;
3185}
3186
3187
3188/* << TOOLBAR_SetInsertMark >> */
3189
3190
3191static LRESULT
3192TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3193{
3194 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3195
3196 infoPtr->clrInsertMark = (COLORREF)lParam;
3197
3198 /* FIXME : redraw ??*/
3199
3200 return 0;
3201}
3202
3203
3204static LRESULT
3205TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3206{
3207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3208
3209 if (infoPtr == NULL)
3210 return FALSE;
3211
3212 infoPtr->nMaxTextRows = (INT)wParam;
3213
3214 return TRUE;
3215}
3216
3217
3218/* << TOOLBAR_SetPadding >> */
3219
3220
3221static LRESULT
3222TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3223{
3224 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3225 HWND hwndOldNotify;
3226
3227 if (infoPtr == NULL)
3228 return 0;
3229 hwndOldNotify = infoPtr->hwndNotify;
3230 infoPtr->hwndNotify = (HWND)wParam;
3231
3232 return hwndOldNotify;
3233}
3234
3235
3236static LRESULT
3237TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3238{
3239 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3240 LPRECT lprc = (LPRECT)lParam;
3241
3242 if (LOWORD(wParam) > 1) {
3243
3244// FIXME (toolbar, "multiple rows not supported!\n");
3245
3246 }
3247
3248 /* recalculate toolbar */
3249 TOOLBAR_CalcToolbar (hwnd);
3250
3251 /* return bounding rectangle */
3252 if (lprc) {
3253 lprc->left = infoPtr->rcBound.left;
3254 lprc->right = infoPtr->rcBound.right;
3255 lprc->top = infoPtr->rcBound.top;
3256 lprc->bottom = infoPtr->rcBound.bottom;
3257 }
3258
3259 /* repaint toolbar */
3260 InvalidateRect(hwnd, NULL, FALSE);
3261
3262 return 0;
3263}
3264
3265
3266static LRESULT
3267TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3268{
3269 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3270 TBUTTON_INFO *btnPtr;
3271 HDC hdc;
3272 INT nIndex;
3273
3274 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3275 if (nIndex == -1)
3276 return FALSE;
3277
3278 btnPtr = &infoPtr->buttons[nIndex];
3279 btnPtr->fsState = LOWORD(lParam);
3280
3281 hdc = GetDC (hwnd);
3282 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3283 ReleaseDC (hwnd, hdc);
3284
3285 return TRUE;
3286}
3287
3288
3289static LRESULT
3290TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3291{
3292 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3293 TBUTTON_INFO *btnPtr;
3294 HDC hdc;
3295 INT nIndex;
3296
3297 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3298 if (nIndex == -1)
3299 return FALSE;
3300
3301 btnPtr = &infoPtr->buttons[nIndex];
3302 btnPtr->fsStyle = LOWORD(lParam);
3303
3304 hdc = GetDC (hwnd);
3305 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3306 ReleaseDC (hwnd, hdc);
3307
3308 if (infoPtr->hwndToolTip) {
3309
3310// FIXME (toolbar, "change tool tip!\n");
3311
3312 }
3313
3314 return TRUE;
3315}
3316
3317
3318static LRESULT
3319TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3320{
3321 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3322
3323 if (infoPtr == NULL)
3324 return 0;
3325 infoPtr->hwndToolTip = (HWND)wParam;
3326 return 0;
3327}
3328
3329
3330static LRESULT
3331TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3332{
3333 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3334 BOOL bTemp;
3335
3336// TRACE (toolbar, "%s hwnd=0x%04x stub!\n",
3337// ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3338
3339 bTemp = infoPtr->bUnicode;
3340 infoPtr->bUnicode = (BOOL)wParam;
3341
3342 return bTemp;
3343}
3344
3345
3346static LRESULT
3347TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
3348{
3349 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3350 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3351 LOGFONTA logFont;
3352
3353 /* initialize info structure */
3354 infoPtr->nButtonHeight = 22;
3355 infoPtr->nButtonWidth = 23;
3356 infoPtr->nBitmapHeight = 15;
3357 infoPtr->nBitmapWidth = 16;
3358
3359 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
3360 infoPtr->nRows = 1;
3361 infoPtr->nMaxTextRows = 1;
3362 infoPtr->cxMin = -1;
3363 infoPtr->cxMax = -1;
3364
3365 infoPtr->bCaptured = FALSE;
3366 infoPtr->bUnicode = IsWindowUnicode(hwnd);
3367 infoPtr->nButtonDown = -1;
3368 infoPtr->nOldHit = -1;
3369 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
3370 infoPtr->hwndNotify = GetParent (hwnd);
3371 infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
3372 infoPtr->dwDTFlags = DT_CENTER;
3373
3374 infoPtr->hwndToolbar = hwnd;
3375 infoPtr->oldButtons = NULL;
3376 infoPtr->nNumOldButtons = 0;
3377
3378 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3379 infoPtr->hFont = CreateFontIndirectA (&logFont);
3380
3381 if (dwStyle & TBSTYLE_TOOLTIPS)
3382 {
3383 /* Create tooltip control */
3384 infoPtr->hwndToolTip =
3385 CreateWindowExA (WS_EX_TOOLWINDOW,TOOLTIPS_CLASSA,NULL,WS_POPUP,
3386 CW_USEDEFAULT,CW_USEDEFAULT,
3387 CW_USEDEFAULT,CW_USEDEFAULT,
3388 hwnd,0,0,0);
3389
3390 /* Send NM_TOOLTIPSCREATED notification */
3391 if (infoPtr->hwndToolTip)
3392 {
3393 NMTOOLTIPSCREATED nmttc;
3394
3395 nmttc.hdr.hwndFrom = hwnd;
3396 nmttc.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
3397 nmttc.hdr.code = NM_TOOLTIPSCREATED;
3398 nmttc.hwndToolTips = infoPtr->hwndToolTip;
3399
3400 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmttc.hdr.idFrom,(LPARAM)&nmttc);
3401 }
3402 }
3403
3404 return 0;
3405}
3406
3407
3408static LRESULT
3409TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
3410{
3411 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3412
3413 /* delete tooltip control */
3414 if (infoPtr->hwndToolTip)
3415 DestroyWindow (infoPtr->hwndToolTip);
3416
3417 /* delete button data */
3418 if (infoPtr->buttons)
3419 {
3420 INT x;
3421
3422 for (x = 0;x < infoPtr->nNumButtons;x++) COMCTL32_Free(infoPtr->buttons[x].pszName);
3423 COMCTL32_Free(infoPtr->buttons);
3424 }
3425
3426 /* delete strings */
3427 if (infoPtr->strings) {
3428 INT i;
3429 for (i = 0; i < infoPtr->nNumStrings; i++)
3430 if (infoPtr->strings[i])
3431 COMCTL32_Free (infoPtr->strings[i]);
3432
3433 COMCTL32_Free (infoPtr->strings);
3434 }
3435
3436 /* destroy internal image list */
3437 if (infoPtr->himlInt)
3438 ImageList_Destroy (infoPtr->himlInt);
3439
3440 /* delete default font */
3441 if (infoPtr->hFont)
3442 DeleteObject (infoPtr->hFont);
3443
3444 /* free toolbar info data */
3445 COMCTL32_Free (infoPtr);
3446
3447 return 0;
3448}
3449
3450
3451static LRESULT
3452TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
3453{
3454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3455
3456 //SvL: Check ptr
3457 if (infoPtr && infoPtr->bTransparent)
3458 return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
3459
3460 return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
3461}
3462
3463
3464static LRESULT
3465TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
3466{
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3468 TBUTTON_INFO *btnPtr;
3469 POINT pt;
3470 INT nHit;
3471 HDC hdc;
3472
3473 pt.x = (INT)LOWORD(lParam);
3474 pt.y = (INT)HIWORD(lParam);
3475 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3476
3477 if (nHit >= 0) {
3478 btnPtr = &infoPtr->buttons[nHit];
3479 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3480 return 0;
3481 SetCapture (hwnd);
3482 infoPtr->bCaptured = TRUE;
3483 infoPtr->nButtonDown = nHit;
3484
3485 btnPtr->fsState |= TBSTATE_PRESSED;
3486
3487 hdc = GetDC (hwnd);
3488 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3489 ReleaseDC (hwnd, hdc);
3490 }
3491 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
3492 TOOLBAR_Customize (hwnd);
3493
3494 return 0;
3495}
3496
3497
3498static LRESULT
3499TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
3500{
3501 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3502 TBUTTON_INFO *btnPtr;
3503 POINT pt;
3504 INT nHit;
3505 HDC hdc;
3506
3507 if (infoPtr->hwndToolTip)
3508 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3509 WM_LBUTTONDOWN, wParam, lParam);
3510
3511 pt.x = (INT)LOWORD(lParam);
3512 pt.y = (INT)HIWORD(lParam);
3513 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3514
3515 if (nHit >= 0) {
3516 btnPtr = &infoPtr->buttons[nHit];
3517 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3518 return 0;
3519
3520 SetCapture (hwnd);
3521 infoPtr->bCaptured = TRUE;
3522 infoPtr->nButtonDown = nHit;
3523 infoPtr->nOldHit = nHit;
3524
3525 btnPtr->fsState |= TBSTATE_PRESSED;
3526
3527 hdc = GetDC (hwnd);
3528 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3529 ReleaseDC (hwnd, hdc);
3530 }
3531
3532 return 0;
3533}
3534
3535
3536static LRESULT
3537TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
3538{
3539 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3540 TBUTTON_INFO *btnPtr;
3541 POINT pt;
3542 INT nHit;
3543 INT nOldIndex = -1;
3544 HDC hdc;
3545 BOOL bSendMessage = TRUE;
3546
3547 if (infoPtr->hwndToolTip)
3548 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3549 WM_LBUTTONUP, wParam, lParam);
3550
3551 pt.x = (INT)LOWORD(lParam);
3552 pt.y = (INT)HIWORD(lParam);
3553 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3554
3555 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
3556 infoPtr->bCaptured = FALSE;
3557 ReleaseCapture ();
3558 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3559 btnPtr->fsState &= ~TBSTATE_PRESSED;
3560
3561 if (nHit == infoPtr->nButtonDown) {
3562 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
3563 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
3564 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
3565 infoPtr->nButtonDown);
3566 if (nOldIndex == infoPtr->nButtonDown)
3567 bSendMessage = FALSE;
3568 if ((nOldIndex != infoPtr->nButtonDown) &&
3569 (nOldIndex != -1))
3570 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3571 btnPtr->fsState |= TBSTATE_CHECKED;
3572 }
3573 else {
3574 if (btnPtr->fsState & TBSTATE_CHECKED)
3575 btnPtr->fsState &= ~TBSTATE_CHECKED;
3576 else
3577 btnPtr->fsState |= TBSTATE_CHECKED;
3578 }
3579 }
3580 }
3581 else
3582 bSendMessage = FALSE;
3583
3584 hdc = GetDC (hwnd);
3585 if (nOldIndex != -1)
3586 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
3587 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3588 ReleaseDC (hwnd, hdc);
3589
3590 if (bSendMessage)
3591 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
3592 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
3593
3594 infoPtr->nButtonDown = -1;
3595 infoPtr->nOldHit = -1;
3596 }
3597
3598 return 0;
3599}
3600
3601
3602static LRESULT
3603TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
3604{
3605 TBUTTON_INFO *btnPtr, *oldBtnPtr;
3606 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3607 POINT pt;
3608 INT nHit;
3609 HDC hdc;
3610 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
3611
3612 if (infoPtr->hwndToolTip)
3613 TOOLBAR_RelayEvent (infoPtr->hwndToolTip,hwnd,
3614 WM_MOUSEMOVE,wParam,lParam);
3615
3616 pt.x = (INT)LOWORD(lParam);
3617 pt.y = (INT)HIWORD(lParam);
3618
3619 nHit = TOOLBAR_InternalHitTest(hwnd,&pt);
3620
3621 if (infoPtr->nOldHit != nHit)
3622 {
3623 /* Remove the effect of an old hot button */
3624 if(infoPtr->nOldHit == infoPtr->nHotItem)
3625 {
3626 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
3627 if (oldBtnPtr->bHot) //CB: dynamic buttons
3628 {
3629 oldBtnPtr->bHot = FALSE;
3630
3631 if (dwStyle & TBSTYLE_FLAT) InvalidateRect(hwnd,&oldBtnPtr->rect,TRUE);
3632 }
3633 }
3634
3635 /* It's not a separator or in nowhere. It's a hot button. */
3636 if (nHit >= 0)
3637 {
3638 btnPtr = &infoPtr->buttons[nHit];
3639 if (!btnPtr->bHot)
3640 {
3641 btnPtr->bHot = TRUE;
3642
3643 if (dwStyle & TBSTYLE_FLAT)
3644 {
3645 hdc = GetDC (hwnd);
3646 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3647 ReleaseDC (hwnd, hdc);
3648 }
3649
3650 infoPtr->nHotItem = nHit;
3651 }
3652 }
3653
3654 if (infoPtr->bCaptured)
3655 {
3656 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3657 if (infoPtr->nOldHit == infoPtr->nButtonDown)
3658 {
3659 btnPtr->fsState &= ~TBSTATE_PRESSED;
3660
3661 hdc = GetDC (hwnd);
3662 TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
3663 ReleaseDC(hwnd,hdc);
3664 } else if (nHit == infoPtr->nButtonDown)
3665 {
3666 btnPtr->fsState |= TBSTATE_PRESSED;
3667
3668 hdc = GetDC(hwnd);
3669 TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
3670 ReleaseDC(hwnd,hdc);
3671 }
3672 }
3673 infoPtr->nOldHit = nHit;
3674 }
3675 return 0;
3676}
3677
3678
3679static LRESULT
3680TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3681{
3682/* if (wndPtr->dwStyle & CCS_NODIVIDER) */
3683 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
3684/* else */
3685/* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
3686}
3687
3688
3689static LRESULT
3690TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3691{
3692 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
3693 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
3694
3695 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
3696}
3697
3698
3699static LRESULT
3700TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3701{
3702 TOOLBAR_INFO *infoPtr;
3703
3704 /* allocate memory for info structure */
3705 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
3706 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3707
3708 /* paranoid!! */
3709 infoPtr->dwStructSize = sizeof(TBBUTTON);
3710
3711 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
3712 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
3713 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
3714 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
3715 }
3716
3717 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
3718}
3719
3720
3721static LRESULT
3722TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
3723{
3724 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3725 RECT rcWindow;
3726 HDC hdc;
3727
3728 if (dwStyle & WS_MINIMIZE)
3729 return 0; /* Nothing to do */
3730
3731 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
3732
3733 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
3734 return 0;
3735
3736 if (!(dwStyle & CCS_NODIVIDER))
3737 {
3738 GetWindowRect (hwnd, &rcWindow);
3739 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3740 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
3741 }
3742
3743 ReleaseDC( hwnd, hdc );
3744
3745 return 0;
3746}
3747
3748
3749static LRESULT
3750TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
3751{
3752 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3753 LPNMHDR lpnmh = (LPNMHDR)lParam;
3754
3755// TRACE (toolbar, "passing WM_NOTIFY!\n");
3756
3757 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
3758 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
3759
3760#if 0
3761 if (lpnmh->code == TTN_GETDISPINFOA) {
3762 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
3763
3764// FIXME (toolbar, "retrieving ASCII string\n");
3765
3766 }
3767 else if (lpnmh->code == TTN_GETDISPINFOW) {
3768 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
3769
3770// FIXME (toolbar, "retrieving UNICODE string\n");
3771
3772 }
3773#endif
3774 }
3775
3776 return 0;
3777}
3778
3779
3780static LRESULT
3781TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
3782{
3783 HDC hdc;
3784 PAINTSTRUCT ps;
3785
3786 TOOLBAR_CalcToolbar(hwnd);
3787 hdc = wParam == 0 ? BeginPaint(hwnd,&ps) : (HDC)wParam;
3788 TOOLBAR_Refresh(hwnd,hdc);
3789 if (!wParam) EndPaint (hwnd, &ps);
3790 return 0;
3791}
3792
3793
3794static LRESULT
3795TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
3796{
3797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3798 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3799 RECT parent_rect;
3800 HWND parent;
3801 /* INT32 x, y; */
3802 INT cx, cy;
3803 INT flags;
3804 UINT uPosFlags = 0;
3805
3806 /* Resize deadlock check */
3807 if (infoPtr->bAutoSize) {
3808 infoPtr->bAutoSize = FALSE;
3809 return 0;
3810 }
3811
3812 flags = (INT) wParam;
3813
3814 /* FIXME for flags =
3815 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
3816 */
3817
3818// TRACE (toolbar, "sizing toolbar!\n");
3819
3820 if (flags == SIZE_RESTORED) {
3821 /* width and height don't apply */
3822 parent = GetParent (hwnd);
3823 GetClientRect(parent, &parent_rect);
3824
3825 if (dwStyle & CCS_NORESIZE) {
3826 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3827
3828 /* FIXME */
3829/* infoPtr->nWidth = parent_rect.right - parent_rect.left; */
3830 cy = infoPtr->nHeight;
3831 cx = infoPtr->nWidth;
3832 TOOLBAR_CalcToolbar (hwnd);
3833 infoPtr->nWidth = cx;
3834 infoPtr->nHeight = cy;
3835 }
3836 else {
3837 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3838 TOOLBAR_CalcToolbar (hwnd);
3839 cy = infoPtr->nHeight;
3840 cx = infoPtr->nWidth;
3841 }
3842
3843 if (dwStyle & CCS_NOPARENTALIGN) {
3844 uPosFlags |= SWP_NOMOVE;
3845 cy = infoPtr->nHeight;
3846 cx = infoPtr->nWidth;
3847 }
3848
3849 if (!(dwStyle & CCS_NODIVIDER))
3850 cy += GetSystemMetrics(SM_CYEDGE);
3851
3852 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
3853 cx, cy, uPosFlags | SWP_NOZORDER);
3854 }
3855 return 0;
3856}
3857
3858
3859static LRESULT
3860TOOLBAR_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
3861{
3862 TOOLBAR_AutoSize (hwnd, wParam, lParam);
3863
3864 InvalidateRect(hwnd, NULL, FALSE);
3865
3866 return 0;
3867}
3868
3869
3870
3871static LRESULT WINAPI
3872ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3873{
3874 switch (uMsg)
3875 {
3876 case TB_ADDBITMAP:
3877 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
3878
3879 case TB_ADDBUTTONSA:
3880 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
3881
3882 case TB_ADDBUTTONSW:
3883 return TOOLBAR_AddButtonsW(hwnd,wParam,lParam);
3884
3885 case TB_ADDSTRINGA:
3886 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
3887
3888 case TB_ADDSTRINGW:
3889 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
3890
3891 case TB_AUTOSIZE:
3892 return TOOLBAR_AutoSize (hwnd, wParam, lParam);
3893
3894 case TB_BUTTONCOUNT:
3895 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
3896
3897 case TB_BUTTONSTRUCTSIZE:
3898 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
3899
3900 case TB_CHANGEBITMAP:
3901 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
3902
3903 case TB_CHECKBUTTON:
3904 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
3905
3906 case TB_COMMANDTOINDEX:
3907 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
3908
3909 case TB_CUSTOMIZE:
3910 return TOOLBAR_Customize (hwnd);
3911
3912 case TB_DELETEBUTTON:
3913 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
3914
3915 case TB_ENABLEBUTTON:
3916 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
3917
3918/* case TB_GETANCHORHIGHLIGHT: */ /* 4.71 */
3919
3920 case TB_GETBITMAP:
3921 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
3922
3923 case TB_GETBITMAPFLAGS:
3924 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
3925
3926 case TB_GETBUTTON:
3927 return TOOLBAR_GetButton (hwnd, wParam, lParam);
3928
3929 case TB_GETBUTTONINFOA:
3930 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
3931
3932 case TB_GETBUTTONINFOW: /* 4.71 */
3933 return TOOLBAR_GetButtonInfoW(hwnd,wParam,lParam);
3934
3935 case TB_GETBUTTONSIZE:
3936 return TOOLBAR_GetButtonSize (hwnd);
3937
3938 case TB_GETBUTTONTEXTA:
3939 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
3940
3941 case TB_GETBUTTONTEXTW:
3942 return TOOLBAR_GetButtonTextW(hwnd,wParam,lParam);
3943
3944/* case TB_GETCOLORSCHEME: */ /* 4.71 */
3945
3946 case TB_GETDISABLEDIMAGELIST:
3947 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
3948
3949 case TB_GETEXTENDEDSTYLE:
3950 return TOOLBAR_GetExtendedStyle (hwnd);
3951
3952 case TB_GETHOTIMAGELIST:
3953 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
3954
3955/* case TB_GETHOTITEM: */ /* 4.71 */
3956
3957 case TB_GETIMAGELIST:
3958 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
3959
3960/* case TB_GETINSERTMARK: */ /* 4.71 */
3961/* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
3962
3963 case TB_GETITEMRECT:
3964 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
3965
3966 case TB_GETMAXSIZE:
3967 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
3968
3969/* case TB_GETOBJECT: */ /* 4.71 */
3970/* case TB_GETPADDING: */ /* 4.71 */
3971
3972 case TB_GETRECT:
3973 return TOOLBAR_GetRect (hwnd, wParam, lParam);
3974
3975 case TB_GETROWS:
3976 return TOOLBAR_GetRows (hwnd, wParam, lParam);
3977
3978 case TB_GETSTATE:
3979 return TOOLBAR_GetState (hwnd, wParam, lParam);
3980
3981 case TB_GETSTYLE:
3982 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
3983
3984 case TB_GETTEXTROWS:
3985 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
3986
3987 case TB_GETTOOLTIPS:
3988 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
3989
3990 case TB_GETUNICODEFORMAT:
3991 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
3992
3993 case TB_HIDEBUTTON:
3994 return TOOLBAR_HideButton (hwnd, wParam, lParam);
3995
3996 case TB_HITTEST:
3997 return TOOLBAR_HitTest (hwnd, wParam, lParam);
3998
3999 case TB_INDETERMINATE:
4000 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
4001
4002 case TB_INSERTBUTTONA:
4003 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
4004
4005 case TB_INSERTBUTTONW:
4006 return TOOLBAR_InsertButtonW(hwnd,wParam,lParam);
4007
4008/* case TB_INSERTMARKHITTEST: */ /* 4.71 */
4009
4010 case TB_ISBUTTONCHECKED:
4011 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
4012
4013 case TB_ISBUTTONENABLED:
4014 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
4015
4016 case TB_ISBUTTONHIDDEN:
4017 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
4018
4019 case TB_ISBUTTONHIGHLIGHTED:
4020 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
4021
4022 case TB_ISBUTTONINDETERMINATE:
4023 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
4024
4025 case TB_ISBUTTONPRESSED:
4026 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
4027
4028/* case TB_LOADIMAGES: */ /* 4.70 */
4029/* case TB_MAPACCELERATORA: */ /* 4.71 */
4030/* case TB_MAPACCELERATORW: */ /* 4.71 */
4031/* case TB_MARKBUTTON: */ /* 4.71 */
4032/* case TB_MOVEBUTTON: */ /* 4.71 */
4033
4034 case TB_PRESSBUTTON:
4035 return TOOLBAR_PressButton (hwnd, wParam, lParam);
4036
4037/* case TB_REPLACEBITMAP: */
4038
4039 case TB_SAVERESTOREA:
4040 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
4041
4042 case TB_SAVERESTOREW:
4043 return TOOLBAR_SaveRestoreW(hwnd,wParam,lParam);
4044
4045/* case TB_SETANCHORHIGHLIGHT: */ /* 4.71 */
4046
4047 case TB_SETBITMAPSIZE:
4048 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
4049
4050 case TB_SETBUTTONINFOA:
4051 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
4052
4053 case TB_SETBUTTONINFOW: /* 4.71 */
4054 return TOOLBAR_SetButtonInfoW(hwnd,wParam,lParam);
4055
4056 case TB_SETBUTTONSIZE:
4057 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
4058
4059 case TB_SETBUTTONWIDTH:
4060 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
4061
4062 case TB_SETCMDID:
4063 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
4064
4065/* case TB_SETCOLORSCHEME: */ /* 4.71 */
4066
4067 case TB_SETDISABLEDIMAGELIST:
4068 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
4069
4070 case TB_SETDRAWTEXTFLAGS:
4071 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
4072
4073 case TB_SETEXTENDEDSTYLE:
4074 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
4075
4076 case TB_SETHOTIMAGELIST:
4077 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
4078
4079/* case TB_SETHOTITEM: */ /* 4.71 */
4080
4081 case TB_SETIMAGELIST:
4082 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
4083
4084 case TB_SETINDENT:
4085 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
4086
4087/* case TB_SETINSERTMARK: */ /* 4.71 */
4088
4089 case TB_SETINSERTMARKCOLOR:
4090 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
4091
4092 case TB_SETMAXTEXTROWS:
4093 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
4094
4095/* case TB_SETPADDING: */ /* 4.71 */
4096
4097 case TB_SETPARENT:
4098 return TOOLBAR_SetParent (hwnd, wParam, lParam);
4099
4100 case TB_SETROWS:
4101 return TOOLBAR_SetRows (hwnd, wParam, lParam);
4102
4103 case TB_SETSTATE:
4104 return TOOLBAR_SetState (hwnd, wParam, lParam);
4105
4106 case TB_SETSTYLE:
4107 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
4108
4109 case TB_SETTOOLTIPS:
4110 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
4111
4112 case TB_SETUNICODEFORMAT:
4113 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
4114
4115
4116/* case WM_CHAR: */
4117
4118 case WM_CREATE:
4119 return TOOLBAR_Create (hwnd, wParam, lParam);
4120
4121 case WM_DESTROY:
4122 return TOOLBAR_Destroy (hwnd, wParam, lParam);
4123
4124 case WM_ERASEBKGND:
4125 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
4126
4127/* case WM_GETFONT: */
4128/* case WM_KEYDOWN: */
4129/* case WM_KILLFOCUS: */
4130
4131 case WM_LBUTTONDBLCLK:
4132 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
4133
4134 case WM_LBUTTONDOWN:
4135 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
4136
4137 case WM_LBUTTONUP:
4138 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
4139
4140 case WM_MOUSEMOVE:
4141 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
4142
4143 case WM_NCACTIVATE:
4144 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
4145
4146 case WM_NCCALCSIZE:
4147 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
4148
4149 case WM_NCCREATE:
4150 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
4151
4152 case WM_NCPAINT:
4153 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
4154
4155 case WM_NOTIFY:
4156 return TOOLBAR_Notify (hwnd, wParam, lParam);
4157
4158/* case WM_NOTIFYFORMAT: */
4159
4160 case WM_PAINT:
4161 return TOOLBAR_Paint (hwnd, wParam);
4162
4163 case WM_SIZE:
4164 return TOOLBAR_Size (hwnd, wParam, lParam);
4165
4166 case WM_STYLECHANGED:
4167 return TOOLBAR_StyleChanged (hwnd, wParam, lParam);
4168
4169/* case WM_SYSCOLORCHANGE: */
4170
4171/* case WM_WININICHANGE: */
4172
4173 case WM_CHARTOITEM:
4174 case WM_COMMAND:
4175 case WM_DRAWITEM:
4176 case WM_MEASUREITEM:
4177 case WM_VKEYTOITEM:
4178 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
4179
4180 default:
4181// if (uMsg >= WM_USER)
4182// ERR (toolbar, "unknown msg %04x wp=%08x lp=%08lx\n",
4183// uMsg, wParam, lParam);
4184 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4185 }
4186 return 0;
4187}
4188
4189
4190VOID
4191TOOLBAR_Register (VOID)
4192{
4193 WNDCLASSA wndClass;
4194
4195//SvL: Don't check this now
4196// if (GlobalFindAtomA (TOOLBARCLASSNAMEA)) return;
4197
4198 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4199 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4200 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
4201 wndClass.cbClsExtra = 0;
4202 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
4203 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
4204 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
4205 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
4206
4207 RegisterClassA (&wndClass);
4208}
4209
4210
4211VOID
4212TOOLBAR_Unregister (VOID)
4213{
4214 if (GlobalFindAtomA (TOOLBARCLASSNAMEA))
4215 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
4216}
4217
Note: See TracBrowser for help on using the repository browser.