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

Last change on this file since 496 was 496, checked in by cbratschi, 26 years ago

wine-990731 update

File size: 116.3 KB
Line 
1/* $Id: toolbar.c,v 1.12 1999-08-14 16:13:13 cbratschi 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 //load OS/2 dialog
2113
2114 ret = NativeDlgBoxIP(COMCTL32_hModule,
2115 GetWindowLongA(hwnd,GWL_HINSTANCE),
2116 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2117 hwnd,
2118 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2119 (LPARAM)infoPtr);
2120
2121 if (ret == (INT)-1) ret = 0;
2122
2123/* //original WINE code
2124 if (!(hRes = FindResourceA (COMCTL32_hModule,
2125 MAKEINTRESOURCEA(IDD_TBCUSTOMIZE),
2126 RT_DIALOGA)))
2127 return FALSE;
2128
2129 if(!(template = (LPVOID)LoadResource (COMCTL32_hModule, hRes)))
2130 return FALSE;
2131
2132 ret = DialogBoxIndirectParamA (GetWindowLongA (hwnd, GWL_HINSTANCE),
2133 (LPDLGTEMPLATEA)template,
2134 hwnd,
2135 (DLGPROC)TOOLBAR_CustomizeDialogProc,
2136 (LPARAM)infoPtr);
2137*/
2138
2139 /* send TBN_ENDADJUST notification */
2140 nmhdr.code = TBN_ENDADJUST;
2141
2142 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
2143
2144 return ret;
2145}
2146
2147
2148static LRESULT
2149TOOLBAR_DeleteButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2150{
2151 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2152 INT nIndex = (INT)wParam;
2153
2154 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2155 return FALSE;
2156
2157 if ((infoPtr->hwndToolTip) &&
2158 !(infoPtr->buttons[nIndex].fsStyle & TBSTYLE_SEP)) {
2159 TTTOOLINFOA ti;
2160
2161 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2162 ti.cbSize = sizeof (TTTOOLINFOA);
2163 ti.hwnd = hwnd;
2164 ti.uId = infoPtr->buttons[nIndex].idCommand;
2165
2166 SendMessageA (infoPtr->hwndToolTip, TTM_DELTOOLA, 0, (LPARAM)&ti);
2167 }
2168
2169 COMCTL32_Free(infoPtr->buttons[nIndex].pszName);
2170
2171 if (infoPtr->nNumButtons == 1)
2172 {
2173// TRACE (toolbar, " simple delete!\n");
2174 COMCTL32_Free (infoPtr->buttons);
2175 infoPtr->buttons = NULL;
2176 infoPtr->nNumButtons = 0;
2177 } else
2178 {
2179 TBUTTON_INFO *oldButtons = infoPtr->buttons;
2180// TRACE(toolbar, "complex delete! [nIndex=%d]\n", nIndex);
2181
2182 infoPtr->nNumButtons--;
2183 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2184 if (nIndex > 0) {
2185 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2186 nIndex * sizeof(TBUTTON_INFO));
2187 }
2188
2189 if (nIndex < infoPtr->nNumButtons) {
2190 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
2191 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
2192 }
2193
2194 COMCTL32_Free (oldButtons);
2195 }
2196
2197 TOOLBAR_CalcToolbar (hwnd);
2198
2199 InvalidateRect (hwnd, NULL, TRUE);
2200
2201 return TRUE;
2202}
2203
2204
2205static LRESULT
2206TOOLBAR_EnableButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2207{
2208 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2209 TBUTTON_INFO *btnPtr;
2210 HDC hdc;
2211 INT nIndex;
2212
2213 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2214 if (nIndex == -1)
2215 return FALSE;
2216
2217 btnPtr = &infoPtr->buttons[nIndex];
2218 if (LOWORD(lParam) == FALSE)
2219 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
2220 else
2221 btnPtr->fsState |= TBSTATE_ENABLED;
2222
2223 hdc = GetDC (hwnd);
2224 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2225 ReleaseDC (hwnd, hdc);
2226
2227 return TRUE;
2228}
2229
2230
2231/* << TOOLBAR_GetAnchorHighlight >> */
2232
2233
2234static LRESULT
2235TOOLBAR_GetBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
2236{
2237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2238 INT nIndex;
2239
2240 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2241 if (nIndex == -1)
2242 return -1;
2243
2244 return infoPtr->buttons[nIndex].iBitmap;
2245}
2246
2247
2248static LRESULT
2249TOOLBAR_GetBitmapFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
2250{
2251 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
2252}
2253
2254
2255static LRESULT
2256TOOLBAR_GetButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2257{
2258 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2259 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2260 INT nIndex = (INT)wParam;
2261 TBUTTON_INFO *btnPtr;
2262
2263 if (infoPtr == NULL)
2264 return FALSE;
2265
2266 if (lpTbb == NULL)
2267 return FALSE;
2268
2269 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2270 return FALSE;
2271
2272 btnPtr = &infoPtr->buttons[nIndex];
2273 lpTbb->iBitmap = btnPtr->iBitmap;
2274 lpTbb->idCommand = btnPtr->idCommand;
2275 lpTbb->fsState = btnPtr->fsState;
2276 lpTbb->fsStyle = btnPtr->fsStyle;
2277 lpTbb->dwData = btnPtr->dwData;
2278 lpTbb->iString = btnPtr->iString;
2279
2280 return TRUE;
2281}
2282
2283
2284static LRESULT
2285TOOLBAR_GetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2286{
2287 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2288 LPTBBUTTONINFOA lpTbInfo = (LPTBBUTTONINFOA)lParam;
2289 TBUTTON_INFO *btnPtr;
2290 INT nIndex;
2291
2292 if (infoPtr == NULL)
2293 return -1;
2294 if (lpTbInfo == NULL)
2295 return -1;
2296 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOA))
2297 return -1;
2298
2299 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2300 if (nIndex == -1)
2301 return -1;
2302
2303 btnPtr = &infoPtr->buttons[nIndex];
2304
2305 if (lpTbInfo->dwMask & TBIF_COMMAND)
2306 lpTbInfo->idCommand = btnPtr->idCommand;
2307 if (lpTbInfo->dwMask & TBIF_IMAGE)
2308 lpTbInfo->iImage = btnPtr->iBitmap;
2309 if (lpTbInfo->dwMask & TBIF_LPARAM)
2310 lpTbInfo->lParam = btnPtr->dwData;
2311 if (lpTbInfo->dwMask & TBIF_SIZE)
2312 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2313 if (lpTbInfo->dwMask & TBIF_STATE)
2314 lpTbInfo->fsState = btnPtr->fsState;
2315 if (lpTbInfo->dwMask & TBIF_STYLE)
2316 lpTbInfo->fsStyle = btnPtr->fsStyle;
2317 if (lpTbInfo->dwMask & TBIF_TEXT) {
2318 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2319 lstrcpynWtoA (lpTbInfo->pszText,
2320 infoPtr->strings[btnPtr->iString],
2321 lpTbInfo->cchText);
2322 }
2323
2324 return nIndex;
2325}
2326
2327static LRESULT TOOLBAR_GetButtonInfoW(HWND hwnd,WPARAM wParam,LPARAM lParam)
2328{
2329 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2330 LPTBBUTTONINFOW lpTbInfo = (LPTBBUTTONINFOW)lParam;
2331 TBUTTON_INFO *btnPtr;
2332 INT nIndex;
2333
2334 if (infoPtr == NULL)
2335 return -1;
2336 if (lpTbInfo == NULL)
2337 return -1;
2338 if (lpTbInfo->cbSize < sizeof(TBBUTTONINFOW))
2339 return -1;
2340
2341 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2342 if (nIndex == -1)
2343 return -1;
2344
2345 btnPtr = &infoPtr->buttons[nIndex];
2346
2347 if (lpTbInfo->dwMask & TBIF_COMMAND)
2348 lpTbInfo->idCommand = btnPtr->idCommand;
2349 if (lpTbInfo->dwMask & TBIF_IMAGE)
2350 lpTbInfo->iImage = btnPtr->iBitmap;
2351 if (lpTbInfo->dwMask & TBIF_LPARAM)
2352 lpTbInfo->lParam = btnPtr->dwData;
2353 if (lpTbInfo->dwMask & TBIF_SIZE)
2354 lpTbInfo->cx = (WORD)(btnPtr->rect.right - btnPtr->rect.left);
2355 if (lpTbInfo->dwMask & TBIF_STATE)
2356 lpTbInfo->fsState = btnPtr->fsState;
2357 if (lpTbInfo->dwMask & TBIF_STYLE)
2358 lpTbInfo->fsStyle = btnPtr->fsStyle;
2359 if (lpTbInfo->dwMask & TBIF_TEXT) {
2360 if ((btnPtr->iString >= 0) || (btnPtr->iString < infoPtr->nNumStrings))
2361 lstrcpynW (lpTbInfo->pszText,
2362 infoPtr->strings[btnPtr->iString],
2363 lpTbInfo->cchText);
2364 }
2365
2366 return nIndex;
2367}
2368
2369/* << TOOLBAR_GetButtonInfo32W >> */
2370
2371
2372static LRESULT
2373TOOLBAR_GetButtonSize (HWND hwnd)
2374{
2375 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2376
2377 return MAKELONG((WORD)infoPtr->nButtonWidth,
2378 (WORD)infoPtr->nButtonHeight);
2379}
2380
2381
2382static LRESULT
2383TOOLBAR_GetButtonTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2384{
2385 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2386 INT nIndex, nStringIndex;
2387
2388 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2389 if (nIndex == -1)
2390 return -1;
2391
2392 nStringIndex = infoPtr->buttons[nIndex].iString;
2393
2394// TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
2395
2396 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2397 return -1;
2398
2399 if (lParam == 0) return -1;
2400
2401 lstrcpyWtoA ((LPSTR)lParam, infoPtr->strings[nStringIndex]);
2402
2403 return lstrlenW (infoPtr->strings[nStringIndex]);
2404}
2405
2406static LRESULT TOOLBAR_GetButtonTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2407{
2408 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2409 INT nIndex, nStringIndex;
2410
2411 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2412 if (nIndex == -1)
2413 return -1;
2414
2415 nStringIndex = infoPtr->buttons[nIndex].iString;
2416
2417// TRACE (toolbar, "index=%d stringIndex=%d\n", nIndex, nStringIndex);
2418
2419 if ((nStringIndex < 0) || (nStringIndex >= infoPtr->nNumStrings))
2420 return -1;
2421
2422 if (lParam == 0) return -1;
2423
2424 lstrcpyW ((LPWSTR)lParam, infoPtr->strings[nStringIndex]);
2425
2426 return lstrlenW (infoPtr->strings[nStringIndex]);
2427}
2428
2429/* << TOOLBAR_GetButtonText32W >> */
2430/* << TOOLBAR_GetColorScheme >> */
2431
2432
2433static LRESULT
2434TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2435{
2436 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2437
2438 return (LRESULT)infoPtr->himlDis;
2439}
2440
2441
2442static LRESULT
2443TOOLBAR_GetExtendedStyle (HWND hwnd)
2444{
2445 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2446
2447 return infoPtr->dwExStyle;
2448}
2449
2450
2451static LRESULT
2452TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2453{
2454 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2455
2456 return (LRESULT)infoPtr->himlHot;
2457}
2458
2459
2460/* << TOOLBAR_GetHotItem >> */
2461
2462
2463static LRESULT
2464TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
2465{
2466 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2467
2468 return (LRESULT)infoPtr->himlDef;
2469}
2470
2471
2472/* << TOOLBAR_GetInsertMark >> */
2473/* << TOOLBAR_GetInsertMarkColor >> */
2474
2475
2476static LRESULT
2477TOOLBAR_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2478{
2479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2480 TBUTTON_INFO *btnPtr;
2481 LPRECT lpRect;
2482 INT nIndex;
2483
2484 if (infoPtr == NULL)
2485 return FALSE;
2486 nIndex = (INT)wParam;
2487 btnPtr = &infoPtr->buttons[nIndex];
2488 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2489 return FALSE;
2490 lpRect = (LPRECT)lParam;
2491 if (lpRect == NULL)
2492 return FALSE;
2493 if (btnPtr->fsState & TBSTATE_HIDDEN)
2494 return FALSE;
2495
2496 TOOLBAR_CalcToolbar( hwnd );
2497
2498 lpRect->left = btnPtr->rect.left;
2499 lpRect->right = btnPtr->rect.right;
2500 lpRect->bottom = btnPtr->rect.bottom;
2501 lpRect->top = btnPtr->rect.top;
2502
2503 return TRUE;
2504}
2505
2506
2507static LRESULT
2508TOOLBAR_GetMaxSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2509{
2510 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2511 LPSIZE lpSize = (LPSIZE)lParam;
2512
2513 if (lpSize == NULL)
2514 return FALSE;
2515
2516 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
2517 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
2518
2519// TRACE (toolbar, "maximum size %d x %d\n",
2520// infoPtr->rcBound.right - infoPtr->rcBound.left,
2521// infoPtr->rcBound.bottom - infoPtr->rcBound.top);
2522
2523 return TRUE;
2524}
2525
2526
2527/* << TOOLBAR_GetObject >> */
2528/* << TOOLBAR_GetPadding >> */
2529
2530
2531static LRESULT
2532TOOLBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
2533{
2534 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2535 TBUTTON_INFO *btnPtr;
2536 LPRECT lpRect;
2537 INT nIndex;
2538
2539 if (infoPtr == NULL)
2540 return FALSE;
2541 nIndex = (INT)wParam;
2542 btnPtr = &infoPtr->buttons[nIndex];
2543 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
2544 return FALSE;
2545 lpRect = (LPRECT)lParam;
2546 if (lpRect == NULL)
2547 return FALSE;
2548
2549 lpRect->left = btnPtr->rect.left;
2550 lpRect->right = btnPtr->rect.right;
2551 lpRect->bottom = btnPtr->rect.bottom;
2552 lpRect->top = btnPtr->rect.top;
2553
2554 return TRUE;
2555}
2556
2557
2558static LRESULT
2559TOOLBAR_GetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2560{
2561 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2562
2563 if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_WRAPABLE)
2564 return infoPtr->nRows;
2565 else
2566 return 1;
2567}
2568
2569
2570static LRESULT
2571TOOLBAR_GetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
2572{
2573 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2574 INT nIndex;
2575
2576 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2577 if (nIndex == -1)
2578 return -1;
2579
2580 return infoPtr->buttons[nIndex].fsState;
2581}
2582
2583
2584static LRESULT
2585TOOLBAR_GetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
2586{
2587 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2588 INT nIndex;
2589
2590 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2591 if (nIndex == -1)
2592 return -1;
2593
2594 return infoPtr->buttons[nIndex].fsStyle;
2595}
2596
2597
2598static LRESULT
2599TOOLBAR_GetTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
2600{
2601 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2602
2603 if (infoPtr == NULL)
2604 return 0;
2605
2606 return infoPtr->nMaxTextRows;
2607}
2608
2609
2610static LRESULT
2611TOOLBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
2612{
2613 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2614
2615 if (infoPtr == NULL) return 0;
2616 return infoPtr->hwndToolTip;
2617}
2618
2619
2620static LRESULT
2621TOOLBAR_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
2622{
2623 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2624
2625// TRACE (toolbar, "%s hwnd=0x%x stub!\n",
2626// infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
2627
2628 return infoPtr->bUnicode;
2629}
2630
2631
2632static LRESULT
2633TOOLBAR_HideButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2634{
2635 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2636 TBUTTON_INFO *btnPtr;
2637 INT nIndex;
2638
2639 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2640 if (nIndex == -1)
2641 return FALSE;
2642
2643 btnPtr = &infoPtr->buttons[nIndex];
2644 if (LOWORD(lParam) == FALSE)
2645 btnPtr->fsState &= ~TBSTATE_HIDDEN;
2646 else
2647 btnPtr->fsState |= TBSTATE_HIDDEN;
2648
2649 TOOLBAR_CalcToolbar (hwnd);
2650
2651 InvalidateRect (hwnd, NULL, TRUE);
2652
2653 return TRUE;
2654}
2655
2656
2657static LRESULT
2658TOOLBAR_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
2659{
2660 return TOOLBAR_InternalHitTest (hwnd, (LPPOINT)lParam);
2661}
2662
2663
2664static LRESULT
2665TOOLBAR_Indeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2666{
2667 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2668 TBUTTON_INFO *btnPtr;
2669 HDC hdc;
2670 INT nIndex;
2671
2672 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2673 if (nIndex == -1)
2674 return FALSE;
2675
2676 btnPtr = &infoPtr->buttons[nIndex];
2677 if (LOWORD(lParam) == FALSE)
2678 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
2679 else
2680 btnPtr->fsState |= TBSTATE_INDETERMINATE;
2681
2682 hdc = GetDC (hwnd);
2683 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2684 ReleaseDC (hwnd, hdc);
2685
2686 return TRUE;
2687}
2688
2689
2690static LRESULT
2691TOOLBAR_InsertButtonA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2692{
2693 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2694 LPTBBUTTON lpTbb = (LPTBBUTTON)lParam;
2695 INT nIndex = (INT)wParam;
2696 TBUTTON_INFO *oldButtons;
2697
2698 if (lpTbb == NULL)
2699 return FALSE;
2700 if (nIndex < 0)
2701 return FALSE;
2702
2703// TRACE (toolbar, "inserting button index=%d\n", nIndex);
2704 if (nIndex > infoPtr->nNumButtons) {
2705 nIndex = infoPtr->nNumButtons;
2706// TRACE (toolbar, "adjust index=%d\n", nIndex);
2707 }
2708
2709 oldButtons = infoPtr->buttons;
2710 infoPtr->nNumButtons++;
2711 infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
2712 /* pre insert copy */
2713 if (nIndex > 0) {
2714 memcpy (&infoPtr->buttons[0], &oldButtons[0],
2715 nIndex * sizeof(TBUTTON_INFO));
2716 }
2717
2718 /* insert new button */
2719 infoPtr->buttons[nIndex].iBitmap = lpTbb->iBitmap;
2720 infoPtr->buttons[nIndex].idCommand = lpTbb->idCommand;
2721 infoPtr->buttons[nIndex].fsState = lpTbb->fsState;
2722 infoPtr->buttons[nIndex].fsStyle = lpTbb->fsStyle;
2723 infoPtr->buttons[nIndex].dwData = lpTbb->dwData;
2724 infoPtr->buttons[nIndex].iString = lpTbb->iString;
2725
2726 if ((infoPtr->hwndToolTip) && !(lpTbb->fsStyle & TBSTYLE_SEP)) {
2727 TTTOOLINFOA ti;
2728
2729 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
2730 ti.cbSize = sizeof (TTTOOLINFOA);
2731 ti.hwnd = hwnd;
2732 ti.uId = lpTbb->idCommand;
2733 ti.hinst = 0;
2734 ti.lpszText = LPSTR_TEXTCALLBACKA;
2735
2736 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA,
2737 0, (LPARAM)&ti);
2738 }
2739
2740 /* post insert copy */
2741 if (nIndex < infoPtr->nNumButtons - 1) {
2742 memcpy (&infoPtr->buttons[nIndex+1], &oldButtons[nIndex],
2743 (infoPtr->nNumButtons - nIndex - 1) * sizeof(TBUTTON_INFO));
2744 }
2745
2746 COMCTL32_Free (oldButtons);
2747
2748 TOOLBAR_CalcToolbar (hwnd);
2749
2750 InvalidateRect (hwnd, NULL, FALSE);
2751
2752 return TRUE;
2753}
2754
2755static LRESULT TOOLBAR_InsertButtonW (HWND hwnd, WPARAM wParam, LPARAM lParam)
2756{
2757 //CB: just call InsertButtonA, no Unicode used?!?
2758
2759 return TOOLBAR_InsertButtonA(hwnd,wParam,lParam);
2760}
2761
2762/* << TOOLBAR_InsertButton32W >> */
2763/* << TOOLBAR_InsertMarkHitTest >> */
2764
2765
2766static LRESULT
2767TOOLBAR_IsButtonChecked (HWND hwnd, WPARAM wParam, LPARAM lParam)
2768{
2769 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2770 INT nIndex;
2771
2772 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2773 if (nIndex == -1)
2774 return FALSE;
2775
2776 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
2777}
2778
2779
2780static LRESULT
2781TOOLBAR_IsButtonEnabled (HWND hwnd, WPARAM wParam, LPARAM lParam)
2782{
2783 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2784 INT nIndex;
2785
2786 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2787 if (nIndex == -1)
2788 return FALSE;
2789
2790 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
2791}
2792
2793
2794static LRESULT
2795TOOLBAR_IsButtonHidden (HWND hwnd, WPARAM wParam, LPARAM lParam)
2796{
2797 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2798 INT nIndex;
2799
2800 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2801 if (nIndex == -1)
2802 return FALSE;
2803
2804 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
2805}
2806
2807
2808static LRESULT
2809TOOLBAR_IsButtonHighlighted (HWND hwnd, WPARAM wParam, LPARAM lParam)
2810{
2811 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2812 INT nIndex;
2813
2814 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2815 if (nIndex == -1)
2816 return FALSE;
2817
2818 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
2819}
2820
2821
2822static LRESULT
2823TOOLBAR_IsButtonIndeterminate (HWND hwnd, WPARAM wParam, LPARAM lParam)
2824{
2825 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2826 INT nIndex;
2827
2828 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2829 if (nIndex == -1)
2830 return FALSE;
2831
2832 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
2833}
2834
2835
2836static LRESULT
2837TOOLBAR_IsButtonPressed (HWND hwnd, WPARAM wParam, LPARAM lParam)
2838{
2839 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2840 INT nIndex;
2841
2842 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2843 if (nIndex == -1)
2844 return FALSE;
2845
2846 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
2847}
2848
2849
2850/* << TOOLBAR_LoadImages >> */
2851/* << TOOLBAR_MapAccelerator >> */
2852/* << TOOLBAR_MarkButton >> */
2853/* << TOOLBAR_MoveButton >> */
2854
2855
2856static LRESULT
2857TOOLBAR_PressButton (HWND hwnd, WPARAM wParam, LPARAM lParam)
2858{
2859 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2860 TBUTTON_INFO *btnPtr;
2861 HDC hdc;
2862 INT nIndex;
2863
2864 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2865 if (nIndex == -1)
2866 return FALSE;
2867
2868 btnPtr = &infoPtr->buttons[nIndex];
2869 if (LOWORD(lParam) == FALSE)
2870 btnPtr->fsState &= ~TBSTATE_PRESSED;
2871 else
2872 btnPtr->fsState |= TBSTATE_PRESSED;
2873
2874 hdc = GetDC (hwnd);
2875 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
2876 ReleaseDC (hwnd, hdc);
2877
2878 return TRUE;
2879}
2880
2881
2882/* << TOOLBAR_ReplaceBitmap >> */
2883
2884
2885static LRESULT
2886TOOLBAR_SaveRestoreA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2887{
2888#if 0
2889 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2890 LPTBSAVEPARAMSA lpSave = (LPTBSAVEPARAMSA)lParam;
2891
2892 if (lpSave == NULL) return 0;
2893
2894 if ((BOOL)wParam) {
2895 /* save toolbar information */
2896// FIXME (toolbar, "save to \"%s\" \"%s\"\n",
2897// lpSave->pszSubKey, lpSave->pszValueName);
2898
2899
2900 }
2901 else {
2902 /* restore toolbar information */
2903
2904// FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
2905// lpSave->pszSubKey, lpSave->pszValueName);
2906
2907
2908 }
2909#endif
2910
2911 return 0;
2912}
2913
2914static LRESULT TOOLBAR_SaveRestoreW(HWND hwnd,WPARAM wParam,LPARAM lParam)
2915{
2916#if 0
2917 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2918 LPTBSAVEPARAMSW lpSave = (LPTBSAVEPARAMSW)lParam;
2919
2920 if (lpSave == NULL) return 0;
2921
2922 if ((BOOL)wParam) {
2923 /* save toolbar information */
2924// FIXME (toolbar, "save to \"%s\" \"%s\"\n",
2925// lpSave->pszSubKey, lpSave->pszValueName);
2926
2927
2928 }
2929 else {
2930 /* restore toolbar information */
2931
2932// FIXME (toolbar, "restore from \"%s\" \"%s\"\n",
2933// lpSave->pszSubKey, lpSave->pszValueName);
2934
2935
2936 }
2937#endif
2938
2939 return 0;
2940}
2941
2942/* << TOOLBAR_SaveRestore32W >> */
2943/* << TOOLBAR_SetAnchorHighlight >> */
2944
2945
2946static LRESULT
2947TOOLBAR_SetBitmapSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
2948{
2949 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2950
2951 if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
2952
2953 infoPtr->nBitmapWidth = (INT)LOWORD(lParam);
2954 infoPtr->nBitmapHeight = (INT)HIWORD(lParam);
2955
2956 return TRUE;
2957}
2958
2959
2960static LRESULT
2961TOOLBAR_SetButtonInfoA (HWND hwnd, WPARAM wParam, LPARAM lParam)
2962{
2963 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
2964 LPTBBUTTONINFOA lptbbi = (LPTBBUTTONINFOA)lParam;
2965 TBUTTON_INFO *btnPtr;
2966 INT nIndex;
2967
2968 if (lptbbi == NULL)
2969 return FALSE;
2970 if (lptbbi->cbSize < sizeof(TBBUTTONINFOA))
2971 return FALSE;
2972
2973 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
2974 if (nIndex == -1)
2975 return FALSE;
2976
2977 btnPtr = &infoPtr->buttons[nIndex];
2978 if (lptbbi->dwMask & TBIF_COMMAND)
2979 btnPtr->idCommand = lptbbi->idCommand;
2980 if (lptbbi->dwMask & TBIF_IMAGE)
2981 btnPtr->iBitmap = lptbbi->iImage;
2982 if (lptbbi->dwMask & TBIF_LPARAM)
2983 btnPtr->dwData = lptbbi->lParam;
2984/* if (lptbbi->dwMask & TBIF_SIZE) */
2985/* btnPtr->cx = lptbbi->cx; */
2986 if (lptbbi->dwMask & TBIF_STATE)
2987 btnPtr->fsState = lptbbi->fsState;
2988 if (lptbbi->dwMask & TBIF_STYLE)
2989 btnPtr->fsStyle = lptbbi->fsStyle;
2990
2991 if (lptbbi->dwMask & TBIF_TEXT) {
2992 if ((btnPtr->iString >= 0) ||
2993 (btnPtr->iString < infoPtr->nNumStrings)) {
2994#if 0
2995 CHAR **lpString = &infoPtr->strings[btnPtr->iString]; //wrong, it's Unicode!!!
2996 INT len = lstrlenA (lptbbi->pszText);
2997 *lpString = COMCTL32_ReAlloc (lpString, sizeof(char)*(len+1));
2998#endif
2999
3000 /* this is the ultimate sollution */
3001/* Str_SetPtrA (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3002 }
3003 }
3004
3005 return TRUE;
3006}
3007
3008static LRESULT TOOLBAR_SetButtonInfoW (HWND hwnd, WPARAM wParam, LPARAM lParam)
3009{
3010 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3011 LPTBBUTTONINFOW lptbbi = (LPTBBUTTONINFOW)lParam;
3012 TBUTTON_INFO *btnPtr;
3013 INT nIndex;
3014
3015 if (lptbbi == NULL)
3016 return FALSE;
3017 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
3018 return FALSE;
3019
3020 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3021 if (nIndex == -1)
3022 return FALSE;
3023
3024 btnPtr = &infoPtr->buttons[nIndex];
3025 if (lptbbi->dwMask & TBIF_COMMAND)
3026 btnPtr->idCommand = lptbbi->idCommand;
3027 if (lptbbi->dwMask & TBIF_IMAGE)
3028 btnPtr->iBitmap = lptbbi->iImage;
3029 if (lptbbi->dwMask & TBIF_LPARAM)
3030 btnPtr->dwData = lptbbi->lParam;
3031/* if (lptbbi->dwMask & TBIF_SIZE) */
3032/* btnPtr->cx = lptbbi->cx; */
3033 if (lptbbi->dwMask & TBIF_STATE)
3034 btnPtr->fsState = lptbbi->fsState;
3035 if (lptbbi->dwMask & TBIF_STYLE)
3036 btnPtr->fsStyle = lptbbi->fsStyle;
3037
3038 if (lptbbi->dwMask & TBIF_TEXT) {
3039 if ((btnPtr->iString >= 0) ||
3040 (btnPtr->iString < infoPtr->nNumStrings)) {
3041#if 0
3042 WCHAR **lpString = &infoPtr->strings[btnPtr->iString];
3043 INT len = lstrlenW (lptbbi->pszText);
3044 *lpString = COMCTL32_ReAlloc (lpString, sizeof(wchar)*(len+1));
3045#endif
3046
3047 /* this is the ultimate sollution */
3048/* Str_SetPtrW (&infoPtr->strings[btnPtr->iString], lptbbi->pszText); */
3049 }
3050 }
3051
3052 return TRUE;
3053}
3054
3055/* << TOOLBAR_SetButtonInfo32W >> */
3056
3057
3058static LRESULT
3059TOOLBAR_SetButtonSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3060{
3061 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3062
3063 if (((INT)LOWORD(lParam) <= 0) || ((INT)HIWORD(lParam) <= 0)) return FALSE;
3064
3065 infoPtr->nButtonWidth = (INT)LOWORD(lParam);
3066 infoPtr->nButtonHeight = (INT)HIWORD(lParam);
3067
3068 return TRUE;
3069}
3070
3071
3072static LRESULT
3073TOOLBAR_SetButtonWidth (HWND hwnd, WPARAM wParam, LPARAM lParam)
3074{
3075 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3076
3077 if (infoPtr == NULL)
3078 return FALSE;
3079
3080 infoPtr->cxMin = (INT)LOWORD(lParam);
3081 infoPtr->cxMax = (INT)HIWORD(lParam);
3082
3083 return TRUE;
3084}
3085
3086
3087static LRESULT
3088TOOLBAR_SetCmdId (HWND hwnd, WPARAM wParam, LPARAM lParam)
3089{
3090 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3091 INT nIndex = (INT)wParam;
3092
3093 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3094 return FALSE;
3095
3096 infoPtr->buttons[nIndex].idCommand = (INT)lParam;
3097
3098 if (infoPtr->hwndToolTip) {
3099
3100// FIXME (toolbar, "change tool tip!\n");
3101
3102 }
3103
3104 return TRUE;
3105}
3106
3107
3108/* << TOOLBAR_SetColorScheme >> */
3109
3110
3111static LRESULT
3112TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3113{
3114 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3115 HIMAGELIST himlTemp;
3116
3117 himlTemp = infoPtr->himlDis;
3118 infoPtr->himlDis = (HIMAGELIST)lParam;
3119
3120 /* FIXME: redraw ? */
3121
3122 return (LRESULT)himlTemp;
3123}
3124
3125
3126static LRESULT
3127TOOLBAR_SetDrawTextFlags (HWND hwnd, WPARAM wParam, LPARAM lParam)
3128{
3129 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3130 DWORD dwTemp;
3131
3132 dwTemp = infoPtr->dwDTFlags;
3133 infoPtr->dwDTFlags =
3134 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
3135
3136 return (LRESULT)dwTemp;
3137}
3138
3139
3140static LRESULT
3141TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3142{
3143 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3144 DWORD dwTemp;
3145
3146 dwTemp = infoPtr->dwExStyle;
3147 infoPtr->dwExStyle = (DWORD)lParam;
3148
3149 return (LRESULT)dwTemp;
3150}
3151
3152
3153static LRESULT
3154TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3155{
3156 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
3157 HIMAGELIST himlTemp;
3158
3159 himlTemp = infoPtr->himlHot;
3160 infoPtr->himlHot = (HIMAGELIST)lParam;
3161
3162 /* FIXME: redraw ? */
3163
3164 return (LRESULT)himlTemp;
3165}
3166
3167
3168/* << TOOLBAR_SetHotItem >> */
3169
3170
3171static LRESULT
3172TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
3173{
3174 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3175 HIMAGELIST himlTemp;
3176
3177 himlTemp = infoPtr->himlDef;
3178 infoPtr->himlDef = (HIMAGELIST)lParam;
3179
3180 /* FIXME: redraw ? */
3181
3182 return (LRESULT)himlTemp;
3183}
3184
3185
3186static LRESULT
3187TOOLBAR_SetIndent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3188{
3189 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3190
3191 infoPtr->nIndent = (INT)wParam;
3192
3193 TOOLBAR_CalcToolbar (hwnd);
3194
3195 InvalidateRect(hwnd, NULL, FALSE);
3196
3197 return TRUE;
3198}
3199
3200
3201/* << TOOLBAR_SetInsertMark >> */
3202
3203
3204static LRESULT
3205TOOLBAR_SetInsertMarkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
3206{
3207 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3208
3209 infoPtr->clrInsertMark = (COLORREF)lParam;
3210
3211 /* FIXME : redraw ??*/
3212
3213 return 0;
3214}
3215
3216
3217static LRESULT
3218TOOLBAR_SetMaxTextRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3219{
3220 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3221
3222 if (infoPtr == NULL)
3223 return FALSE;
3224
3225 infoPtr->nMaxTextRows = (INT)wParam;
3226
3227 return TRUE;
3228}
3229
3230
3231/* << TOOLBAR_SetPadding >> */
3232
3233
3234static LRESULT
3235TOOLBAR_SetParent (HWND hwnd, WPARAM wParam, LPARAM lParam)
3236{
3237 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3238 HWND hwndOldNotify;
3239
3240 if (infoPtr == NULL)
3241 return 0;
3242 hwndOldNotify = infoPtr->hwndNotify;
3243 infoPtr->hwndNotify = (HWND)wParam;
3244
3245 return hwndOldNotify;
3246}
3247
3248
3249static LRESULT
3250TOOLBAR_SetRows (HWND hwnd, WPARAM wParam, LPARAM lParam)
3251{
3252 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3253 LPRECT lprc = (LPRECT)lParam;
3254
3255 if (LOWORD(wParam) > 1) {
3256
3257// FIXME (toolbar, "multiple rows not supported!\n");
3258
3259 }
3260
3261 /* recalculate toolbar */
3262 TOOLBAR_CalcToolbar (hwnd);
3263
3264 /* return bounding rectangle */
3265 if (lprc) {
3266 lprc->left = infoPtr->rcBound.left;
3267 lprc->right = infoPtr->rcBound.right;
3268 lprc->top = infoPtr->rcBound.top;
3269 lprc->bottom = infoPtr->rcBound.bottom;
3270 }
3271
3272 /* repaint toolbar */
3273 InvalidateRect(hwnd, NULL, FALSE);
3274
3275 return 0;
3276}
3277
3278
3279static LRESULT
3280TOOLBAR_SetState (HWND hwnd, WPARAM wParam, LPARAM lParam)
3281{
3282 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3283 TBUTTON_INFO *btnPtr;
3284 HDC hdc;
3285 INT nIndex;
3286
3287 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3288 if (nIndex == -1)
3289 return FALSE;
3290
3291 btnPtr = &infoPtr->buttons[nIndex];
3292 btnPtr->fsState = LOWORD(lParam);
3293
3294 hdc = GetDC (hwnd);
3295 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3296 ReleaseDC (hwnd, hdc);
3297
3298 return TRUE;
3299}
3300
3301
3302static LRESULT
3303TOOLBAR_SetStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
3304{
3305 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3306 TBUTTON_INFO *btnPtr;
3307 HDC hdc;
3308 INT nIndex;
3309
3310 nIndex = TOOLBAR_GetButtonIndex (infoPtr, (INT)wParam);
3311 if (nIndex == -1)
3312 return FALSE;
3313
3314 btnPtr = &infoPtr->buttons[nIndex];
3315 btnPtr->fsStyle = LOWORD(lParam);
3316
3317 hdc = GetDC (hwnd);
3318 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3319 ReleaseDC (hwnd, hdc);
3320
3321 if (infoPtr->hwndToolTip) {
3322
3323// FIXME (toolbar, "change tool tip!\n");
3324
3325 }
3326
3327 return TRUE;
3328}
3329
3330
3331static LRESULT
3332TOOLBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
3333{
3334 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3335
3336 if (infoPtr == NULL)
3337 return 0;
3338 infoPtr->hwndToolTip = (HWND)wParam;
3339 return 0;
3340}
3341
3342
3343static LRESULT
3344TOOLBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
3345{
3346 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3347 BOOL bTemp;
3348
3349// TRACE (toolbar, "%s hwnd=0x%04x stub!\n",
3350// ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
3351
3352 bTemp = infoPtr->bUnicode;
3353 infoPtr->bUnicode = (BOOL)wParam;
3354
3355 return bTemp;
3356}
3357
3358
3359static LRESULT
3360TOOLBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
3361{
3362 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3363 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3364 LOGFONTA logFont;
3365
3366 /* initialize info structure */
3367 infoPtr->nButtonHeight = 22;
3368 infoPtr->nButtonWidth = 23;
3369 infoPtr->nBitmapHeight = 15;
3370 infoPtr->nBitmapWidth = 16;
3371
3372 infoPtr->nHeight = infoPtr->nButtonHeight + TOP_BORDER + BOTTOM_BORDER;
3373 infoPtr->nRows = 1;
3374 infoPtr->nMaxTextRows = 1;
3375 infoPtr->cxMin = -1;
3376 infoPtr->cxMax = -1;
3377
3378 infoPtr->bCaptured = FALSE;
3379 infoPtr->bUnicode = IsWindowUnicode(hwnd);
3380 infoPtr->nButtonDown = -1;
3381 infoPtr->nOldHit = -1;
3382 infoPtr->nHotItem = -2; /* It has to be initially different from nOldHit */
3383 infoPtr->hwndNotify = GetParent (hwnd);
3384 infoPtr->bTransparent = (dwStyle & TBSTYLE_FLAT);
3385 infoPtr->dwDTFlags = DT_CENTER;
3386
3387 infoPtr->hwndToolbar = hwnd;
3388 infoPtr->oldButtons = NULL;
3389 infoPtr->nNumOldButtons = 0;
3390
3391 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3392 infoPtr->hFont = CreateFontIndirectA (&logFont);
3393
3394 if (dwStyle & TBSTYLE_TOOLTIPS)
3395 {
3396 /* Create tooltip control */
3397 infoPtr->hwndToolTip =
3398 CreateWindowExA (WS_EX_TOOLWINDOW,TOOLTIPS_CLASSA,NULL,WS_POPUP,
3399 CW_USEDEFAULT,CW_USEDEFAULT,
3400 CW_USEDEFAULT,CW_USEDEFAULT,
3401 hwnd,0,0,0);
3402
3403 /* Send NM_TOOLTIPSCREATED notification */
3404 if (infoPtr->hwndToolTip)
3405 {
3406 NMTOOLTIPSCREATED nmttc;
3407
3408 nmttc.hdr.hwndFrom = hwnd;
3409 nmttc.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
3410 nmttc.hdr.code = NM_TOOLTIPSCREATED;
3411 nmttc.hwndToolTips = infoPtr->hwndToolTip;
3412
3413 SendMessageA(infoPtr->hwndNotify,WM_NOTIFY,(WPARAM)nmttc.hdr.idFrom,(LPARAM)&nmttc);
3414 }
3415 }
3416
3417 return 0;
3418}
3419
3420
3421static LRESULT
3422TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
3423{
3424 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3425
3426 /* delete tooltip control */
3427 if (infoPtr->hwndToolTip)
3428 DestroyWindow (infoPtr->hwndToolTip);
3429
3430 /* delete button data */
3431 if (infoPtr->buttons)
3432 {
3433 INT x;
3434
3435 for (x = 0;x < infoPtr->nNumButtons;x++) COMCTL32_Free(infoPtr->buttons[x].pszName);
3436 COMCTL32_Free(infoPtr->buttons);
3437 }
3438
3439 /* delete strings */
3440 if (infoPtr->strings) {
3441 INT i;
3442 for (i = 0; i < infoPtr->nNumStrings; i++)
3443 if (infoPtr->strings[i])
3444 COMCTL32_Free (infoPtr->strings[i]);
3445
3446 COMCTL32_Free (infoPtr->strings);
3447 }
3448
3449 /* destroy internal image list */
3450 if (infoPtr->himlInt)
3451 ImageList_Destroy (infoPtr->himlInt);
3452
3453 /* delete default font */
3454 if (infoPtr->hFont)
3455 DeleteObject (infoPtr->hFont);
3456
3457 /* free toolbar info data */
3458 COMCTL32_Free (infoPtr);
3459
3460 return 0;
3461}
3462
3463
3464static LRESULT
3465TOOLBAR_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
3466{
3467 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3468
3469 if (infoPtr->bTransparent)
3470 return SendMessageA (GetParent (hwnd), WM_ERASEBKGND, wParam, lParam);
3471
3472 return DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
3473}
3474
3475
3476static LRESULT
3477TOOLBAR_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
3478{
3479 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3480 TBUTTON_INFO *btnPtr;
3481 POINT pt;
3482 INT nHit;
3483 HDC hdc;
3484
3485 pt.x = (INT)LOWORD(lParam);
3486 pt.y = (INT)HIWORD(lParam);
3487 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3488
3489 if (nHit >= 0) {
3490 btnPtr = &infoPtr->buttons[nHit];
3491 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3492 return 0;
3493 SetCapture (hwnd);
3494 infoPtr->bCaptured = TRUE;
3495 infoPtr->nButtonDown = nHit;
3496
3497 btnPtr->fsState |= TBSTATE_PRESSED;
3498
3499 hdc = GetDC (hwnd);
3500 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3501 ReleaseDC (hwnd, hdc);
3502 }
3503 else if (GetWindowLongA (hwnd, GWL_STYLE) & CCS_ADJUSTABLE)
3504 TOOLBAR_Customize (hwnd);
3505
3506 return 0;
3507}
3508
3509
3510static LRESULT
3511TOOLBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
3512{
3513 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3514 TBUTTON_INFO *btnPtr;
3515 POINT pt;
3516 INT nHit;
3517 HDC hdc;
3518
3519 if (infoPtr->hwndToolTip)
3520 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3521 WM_LBUTTONDOWN, wParam, lParam);
3522
3523 pt.x = (INT)LOWORD(lParam);
3524 pt.y = (INT)HIWORD(lParam);
3525 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3526
3527 if (nHit >= 0) {
3528 btnPtr = &infoPtr->buttons[nHit];
3529 if (!(btnPtr->fsState & TBSTATE_ENABLED))
3530 return 0;
3531
3532 SetCapture (hwnd);
3533 infoPtr->bCaptured = TRUE;
3534 infoPtr->nButtonDown = nHit;
3535 infoPtr->nOldHit = nHit;
3536
3537 btnPtr->fsState |= TBSTATE_PRESSED;
3538
3539 hdc = GetDC (hwnd);
3540 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3541 ReleaseDC (hwnd, hdc);
3542 }
3543
3544 return 0;
3545}
3546
3547
3548static LRESULT
3549TOOLBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
3550{
3551 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3552 TBUTTON_INFO *btnPtr;
3553 POINT pt;
3554 INT nHit;
3555 INT nOldIndex = -1;
3556 HDC hdc;
3557 BOOL bSendMessage = TRUE;
3558
3559 if (infoPtr->hwndToolTip)
3560 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
3561 WM_LBUTTONUP, wParam, lParam);
3562
3563 pt.x = (INT)LOWORD(lParam);
3564 pt.y = (INT)HIWORD(lParam);
3565 nHit = TOOLBAR_InternalHitTest (hwnd, &pt);
3566
3567 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
3568 infoPtr->bCaptured = FALSE;
3569 ReleaseCapture ();
3570 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3571 btnPtr->fsState &= ~TBSTATE_PRESSED;
3572
3573 if (nHit == infoPtr->nButtonDown) {
3574 if (btnPtr->fsStyle & TBSTYLE_CHECK) {
3575 if (btnPtr->fsStyle & TBSTYLE_GROUP) {
3576 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
3577 infoPtr->nButtonDown);
3578 if (nOldIndex == infoPtr->nButtonDown)
3579 bSendMessage = FALSE;
3580 if ((nOldIndex != infoPtr->nButtonDown) &&
3581 (nOldIndex != -1))
3582 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3583 btnPtr->fsState |= TBSTATE_CHECKED;
3584 }
3585 else {
3586 if (btnPtr->fsState & TBSTATE_CHECKED)
3587 btnPtr->fsState &= ~TBSTATE_CHECKED;
3588 else
3589 btnPtr->fsState |= TBSTATE_CHECKED;
3590 }
3591 }
3592 }
3593 else
3594 bSendMessage = FALSE;
3595
3596 hdc = GetDC (hwnd);
3597 if (nOldIndex != -1)
3598 TOOLBAR_DrawButton (hwnd, &infoPtr->buttons[nOldIndex], hdc);
3599 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3600 ReleaseDC (hwnd, hdc);
3601
3602 if (bSendMessage)
3603 SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
3604 MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
3605
3606 infoPtr->nButtonDown = -1;
3607 infoPtr->nOldHit = -1;
3608 }
3609
3610 return 0;
3611}
3612
3613
3614static LRESULT
3615TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
3616{
3617 TBUTTON_INFO *btnPtr, *oldBtnPtr;
3618 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3619 POINT pt;
3620 INT nHit;
3621 HDC hdc;
3622 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
3623
3624 if (infoPtr->hwndToolTip)
3625 TOOLBAR_RelayEvent (infoPtr->hwndToolTip,hwnd,
3626 WM_MOUSEMOVE,wParam,lParam);
3627
3628 pt.x = (INT)LOWORD(lParam);
3629 pt.y = (INT)HIWORD(lParam);
3630
3631 nHit = TOOLBAR_InternalHitTest(hwnd,&pt);
3632
3633 if (infoPtr->nOldHit != nHit)
3634 {
3635 /* Remove the effect of an old hot button */
3636 if(infoPtr->nOldHit == infoPtr->nHotItem)
3637 {
3638 oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
3639 if (oldBtnPtr->bHot) //CB: dynamic buttons
3640 {
3641 oldBtnPtr->bHot = FALSE;
3642
3643 if (dwStyle & TBSTYLE_FLAT) InvalidateRect(hwnd,&oldBtnPtr->rect,TRUE);
3644 }
3645 }
3646
3647 /* It's not a separator or in nowhere. It's a hot button. */
3648 if (nHit >= 0)
3649 {
3650 btnPtr = &infoPtr->buttons[nHit];
3651 if (!btnPtr->bHot)
3652 {
3653 btnPtr->bHot = TRUE;
3654
3655 if (dwStyle & TBSTYLE_FLAT)
3656 {
3657 hdc = GetDC (hwnd);
3658 TOOLBAR_DrawButton (hwnd, btnPtr, hdc);
3659 ReleaseDC (hwnd, hdc);
3660 }
3661
3662 infoPtr->nHotItem = nHit;
3663 }
3664 }
3665
3666 if (infoPtr->bCaptured)
3667 {
3668 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
3669 if (infoPtr->nOldHit == infoPtr->nButtonDown)
3670 {
3671 btnPtr->fsState &= ~TBSTATE_PRESSED;
3672
3673 hdc = GetDC (hwnd);
3674 TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
3675 ReleaseDC(hwnd,hdc);
3676 } else if (nHit == infoPtr->nButtonDown)
3677 {
3678 btnPtr->fsState |= TBSTATE_PRESSED;
3679
3680 hdc = GetDC(hwnd);
3681 TOOLBAR_DrawButton(hwnd,btnPtr,hdc);
3682 ReleaseDC(hwnd,hdc);
3683 }
3684 }
3685 infoPtr->nOldHit = nHit;
3686 }
3687 return 0;
3688}
3689
3690
3691static LRESULT
3692TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3693{
3694/* if (wndPtr->dwStyle & CCS_NODIVIDER) */
3695 return DefWindowProcA (hwnd, WM_NCACTIVATE, wParam, lParam);
3696/* else */
3697/* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
3698}
3699
3700
3701static LRESULT
3702TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
3703{
3704 if (!(GetWindowLongA (hwnd, GWL_STYLE) & CCS_NODIVIDER))
3705 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
3706
3707 return DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
3708}
3709
3710
3711static LRESULT
3712TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
3713{
3714 TOOLBAR_INFO *infoPtr;
3715
3716 /* allocate memory for info structure */
3717 infoPtr = (TOOLBAR_INFO *)COMCTL32_Alloc (sizeof(TOOLBAR_INFO));
3718 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
3719
3720 /* paranoid!! */
3721 infoPtr->dwStructSize = sizeof(TBBUTTON);
3722
3723 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
3724 if (!GetWindowLongA (hwnd, GWL_HINSTANCE)) {
3725 HINSTANCE hInst = (HINSTANCE)GetWindowLongA (GetParent (hwnd), GWL_HINSTANCE);
3726 SetWindowLongA (hwnd, GWL_HINSTANCE, (DWORD)hInst);
3727 }
3728
3729 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
3730}
3731
3732
3733static LRESULT
3734TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
3735{
3736 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3737 RECT rcWindow;
3738 HDC hdc;
3739
3740 if (dwStyle & WS_MINIMIZE)
3741 return 0; /* Nothing to do */
3742
3743 DefWindowProcA (hwnd, WM_NCPAINT, wParam, lParam);
3744
3745 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
3746 return 0;
3747
3748 if (!(dwStyle & CCS_NODIVIDER))
3749 {
3750 GetWindowRect (hwnd, &rcWindow);
3751 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3752 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
3753 }
3754
3755 ReleaseDC( hwnd, hdc );
3756
3757 return 0;
3758}
3759
3760
3761static LRESULT
3762TOOLBAR_Notify (HWND hwnd, WPARAM wParam, LPARAM lParam)
3763{
3764 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3765 LPNMHDR lpnmh = (LPNMHDR)lParam;
3766
3767// TRACE (toolbar, "passing WM_NOTIFY!\n");
3768
3769 if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
3770 SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
3771
3772#if 0
3773 if (lpnmh->code == TTN_GETDISPINFOA) {
3774 LPNMTTDISPINFOA lpdi = (LPNMTTDISPINFOA)lParam;
3775
3776// FIXME (toolbar, "retrieving ASCII string\n");
3777
3778 }
3779 else if (lpnmh->code == TTN_GETDISPINFOW) {
3780 LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam;
3781
3782// FIXME (toolbar, "retrieving UNICODE string\n");
3783
3784 }
3785#endif
3786 }
3787
3788 return 0;
3789}
3790
3791
3792static LRESULT
3793TOOLBAR_Paint (HWND hwnd, WPARAM wParam)
3794{
3795 HDC hdc;
3796 PAINTSTRUCT ps;
3797
3798 TOOLBAR_CalcToolbar(hwnd);
3799 hdc = wParam == 0 ? BeginPaint(hwnd,&ps) : (HDC)wParam;
3800 TOOLBAR_Refresh(hwnd,hdc);
3801 if (!wParam) EndPaint (hwnd, &ps);
3802 return 0;
3803}
3804
3805
3806static LRESULT
3807TOOLBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
3808{
3809 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
3810 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
3811 RECT parent_rect;
3812 HWND parent;
3813 /* INT32 x, y; */
3814 INT cx, cy;
3815 INT flags;
3816 UINT uPosFlags = 0;
3817
3818 /* Resize deadlock check */
3819 if (infoPtr->bAutoSize) {
3820 infoPtr->bAutoSize = FALSE;
3821 return 0;
3822 }
3823
3824 flags = (INT) wParam;
3825
3826 /* FIXME for flags =
3827 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED
3828 */
3829
3830// TRACE (toolbar, "sizing toolbar!\n");
3831
3832 if (flags == SIZE_RESTORED) {
3833 /* width and height don't apply */
3834 parent = GetParent (hwnd);
3835 GetClientRect(parent, &parent_rect);
3836
3837 if (dwStyle & CCS_NORESIZE) {
3838 uPosFlags |= (SWP_NOSIZE | SWP_NOMOVE);
3839
3840 /* FIXME */
3841/* infoPtr->nWidth = parent_rect.right - parent_rect.left; */
3842 cy = infoPtr->nHeight;
3843 cx = infoPtr->nWidth;
3844 TOOLBAR_CalcToolbar (hwnd);
3845 infoPtr->nWidth = cx;
3846 infoPtr->nHeight = cy;
3847 }
3848 else {
3849 infoPtr->nWidth = parent_rect.right - parent_rect.left;
3850 TOOLBAR_CalcToolbar (hwnd);
3851 cy = infoPtr->nHeight;
3852 cx = infoPtr->nWidth;
3853 }
3854
3855 if (dwStyle & CCS_NOPARENTALIGN) {
3856 uPosFlags |= SWP_NOMOVE;
3857 cy = infoPtr->nHeight;
3858 cx = infoPtr->nWidth;
3859 }
3860
3861 if (!(dwStyle & CCS_NODIVIDER))
3862 cy += GetSystemMetrics(SM_CYEDGE);
3863
3864 SetWindowPos (hwnd, 0, parent_rect.left, parent_rect.top,
3865 cx, cy, uPosFlags | SWP_NOZORDER);
3866 }
3867 return 0;
3868}
3869
3870
3871static LRESULT
3872TOOLBAR_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
3873{
3874 TOOLBAR_AutoSize (hwnd, wParam, lParam);
3875
3876 InvalidateRect(hwnd, NULL, FALSE);
3877
3878 return 0;
3879}
3880
3881
3882
3883static LRESULT WINAPI
3884ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3885{
3886 switch (uMsg)
3887 {
3888 case TB_ADDBITMAP:
3889 return TOOLBAR_AddBitmap (hwnd, wParam, lParam);
3890
3891 case TB_ADDBUTTONSA:
3892 return TOOLBAR_AddButtonsA (hwnd, wParam, lParam);
3893
3894 case TB_ADDBUTTONSW:
3895 return TOOLBAR_AddButtonsW(hwnd,wParam,lParam);
3896
3897 case TB_ADDSTRINGA:
3898 return TOOLBAR_AddStringA (hwnd, wParam, lParam);
3899
3900 case TB_ADDSTRINGW:
3901 return TOOLBAR_AddStringW (hwnd, wParam, lParam);
3902
3903 case TB_AUTOSIZE:
3904 return TOOLBAR_AutoSize (hwnd, wParam, lParam);
3905
3906 case TB_BUTTONCOUNT:
3907 return TOOLBAR_ButtonCount (hwnd, wParam, lParam);
3908
3909 case TB_BUTTONSTRUCTSIZE:
3910 return TOOLBAR_ButtonStructSize (hwnd, wParam, lParam);
3911
3912 case TB_CHANGEBITMAP:
3913 return TOOLBAR_ChangeBitmap (hwnd, wParam, lParam);
3914
3915 case TB_CHECKBUTTON:
3916 return TOOLBAR_CheckButton (hwnd, wParam, lParam);
3917
3918 case TB_COMMANDTOINDEX:
3919 return TOOLBAR_CommandToIndex (hwnd, wParam, lParam);
3920
3921 case TB_CUSTOMIZE:
3922 return TOOLBAR_Customize (hwnd);
3923
3924 case TB_DELETEBUTTON:
3925 return TOOLBAR_DeleteButton (hwnd, wParam, lParam);
3926
3927 case TB_ENABLEBUTTON:
3928 return TOOLBAR_EnableButton (hwnd, wParam, lParam);
3929
3930/* case TB_GETANCHORHIGHLIGHT: */ /* 4.71 */
3931
3932 case TB_GETBITMAP:
3933 return TOOLBAR_GetBitmap (hwnd, wParam, lParam);
3934
3935 case TB_GETBITMAPFLAGS:
3936 return TOOLBAR_GetBitmapFlags (hwnd, wParam, lParam);
3937
3938 case TB_GETBUTTON:
3939 return TOOLBAR_GetButton (hwnd, wParam, lParam);
3940
3941 case TB_GETBUTTONINFOA:
3942 return TOOLBAR_GetButtonInfoA (hwnd, wParam, lParam);
3943
3944 case TB_GETBUTTONINFOW: /* 4.71 */
3945 return TOOLBAR_GetButtonInfoW(hwnd,wParam,lParam);
3946
3947 case TB_GETBUTTONSIZE:
3948 return TOOLBAR_GetButtonSize (hwnd);
3949
3950 case TB_GETBUTTONTEXTA:
3951 return TOOLBAR_GetButtonTextA (hwnd, wParam, lParam);
3952
3953 case TB_GETBUTTONTEXTW:
3954 return TOOLBAR_GetButtonTextW(hwnd,wParam,lParam);
3955
3956/* case TB_GETCOLORSCHEME: */ /* 4.71 */
3957
3958 case TB_GETDISABLEDIMAGELIST:
3959 return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
3960
3961 case TB_GETEXTENDEDSTYLE:
3962 return TOOLBAR_GetExtendedStyle (hwnd);
3963
3964 case TB_GETHOTIMAGELIST:
3965 return TOOLBAR_GetHotImageList (hwnd, wParam, lParam);
3966
3967/* case TB_GETHOTITEM: */ /* 4.71 */
3968
3969 case TB_GETIMAGELIST:
3970 return TOOLBAR_GetImageList (hwnd, wParam, lParam);
3971
3972/* case TB_GETINSERTMARK: */ /* 4.71 */
3973/* case TB_GETINSERTMARKCOLOR: */ /* 4.71 */
3974
3975 case TB_GETITEMRECT:
3976 return TOOLBAR_GetItemRect (hwnd, wParam, lParam);
3977
3978 case TB_GETMAXSIZE:
3979 return TOOLBAR_GetMaxSize (hwnd, wParam, lParam);
3980
3981/* case TB_GETOBJECT: */ /* 4.71 */
3982/* case TB_GETPADDING: */ /* 4.71 */
3983
3984 case TB_GETRECT:
3985 return TOOLBAR_GetRect (hwnd, wParam, lParam);
3986
3987 case TB_GETROWS:
3988 return TOOLBAR_GetRows (hwnd, wParam, lParam);
3989
3990 case TB_GETSTATE:
3991 return TOOLBAR_GetState (hwnd, wParam, lParam);
3992
3993 case TB_GETSTYLE:
3994 return TOOLBAR_GetStyle (hwnd, wParam, lParam);
3995
3996 case TB_GETTEXTROWS:
3997 return TOOLBAR_GetTextRows (hwnd, wParam, lParam);
3998
3999 case TB_GETTOOLTIPS:
4000 return TOOLBAR_GetToolTips (hwnd, wParam, lParam);
4001
4002 case TB_GETUNICODEFORMAT:
4003 return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
4004
4005 case TB_HIDEBUTTON:
4006 return TOOLBAR_HideButton (hwnd, wParam, lParam);
4007
4008 case TB_HITTEST:
4009 return TOOLBAR_HitTest (hwnd, wParam, lParam);
4010
4011 case TB_INDETERMINATE:
4012 return TOOLBAR_Indeterminate (hwnd, wParam, lParam);
4013
4014 case TB_INSERTBUTTONA:
4015 return TOOLBAR_InsertButtonA (hwnd, wParam, lParam);
4016
4017 case TB_INSERTBUTTONW:
4018 return TOOLBAR_InsertButtonW(hwnd,wParam,lParam);
4019
4020/* case TB_INSERTMARKHITTEST: */ /* 4.71 */
4021
4022 case TB_ISBUTTONCHECKED:
4023 return TOOLBAR_IsButtonChecked (hwnd, wParam, lParam);
4024
4025 case TB_ISBUTTONENABLED:
4026 return TOOLBAR_IsButtonEnabled (hwnd, wParam, lParam);
4027
4028 case TB_ISBUTTONHIDDEN:
4029 return TOOLBAR_IsButtonHidden (hwnd, wParam, lParam);
4030
4031 case TB_ISBUTTONHIGHLIGHTED:
4032 return TOOLBAR_IsButtonHighlighted (hwnd, wParam, lParam);
4033
4034 case TB_ISBUTTONINDETERMINATE:
4035 return TOOLBAR_IsButtonIndeterminate (hwnd, wParam, lParam);
4036
4037 case TB_ISBUTTONPRESSED:
4038 return TOOLBAR_IsButtonPressed (hwnd, wParam, lParam);
4039
4040/* case TB_LOADIMAGES: */ /* 4.70 */
4041/* case TB_MAPACCELERATORA: */ /* 4.71 */
4042/* case TB_MAPACCELERATORW: */ /* 4.71 */
4043/* case TB_MARKBUTTON: */ /* 4.71 */
4044/* case TB_MOVEBUTTON: */ /* 4.71 */
4045
4046 case TB_PRESSBUTTON:
4047 return TOOLBAR_PressButton (hwnd, wParam, lParam);
4048
4049/* case TB_REPLACEBITMAP: */
4050
4051 case TB_SAVERESTOREA:
4052 return TOOLBAR_SaveRestoreA (hwnd, wParam, lParam);
4053
4054 case TB_SAVERESTOREW:
4055 return TOOLBAR_SaveRestoreW(hwnd,wParam,lParam);
4056
4057/* case TB_SETANCHORHIGHLIGHT: */ /* 4.71 */
4058
4059 case TB_SETBITMAPSIZE:
4060 return TOOLBAR_SetBitmapSize (hwnd, wParam, lParam);
4061
4062 case TB_SETBUTTONINFOA:
4063 return TOOLBAR_SetButtonInfoA (hwnd, wParam, lParam);
4064
4065 case TB_SETBUTTONINFOW: /* 4.71 */
4066 return TOOLBAR_SetButtonInfoW(hwnd,wParam,lParam);
4067
4068 case TB_SETBUTTONSIZE:
4069 return TOOLBAR_SetButtonSize (hwnd, wParam, lParam);
4070
4071 case TB_SETBUTTONWIDTH:
4072 return TOOLBAR_SetButtonWidth (hwnd, wParam, lParam);
4073
4074 case TB_SETCMDID:
4075 return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
4076
4077/* case TB_SETCOLORSCHEME: */ /* 4.71 */
4078
4079 case TB_SETDISABLEDIMAGELIST:
4080 return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
4081
4082 case TB_SETDRAWTEXTFLAGS:
4083 return TOOLBAR_SetDrawTextFlags (hwnd, wParam, lParam);
4084
4085 case TB_SETEXTENDEDSTYLE:
4086 return TOOLBAR_SetExtendedStyle (hwnd, wParam, lParam);
4087
4088 case TB_SETHOTIMAGELIST:
4089 return TOOLBAR_SetHotImageList (hwnd, wParam, lParam);
4090
4091/* case TB_SETHOTITEM: */ /* 4.71 */
4092
4093 case TB_SETIMAGELIST:
4094 return TOOLBAR_SetImageList (hwnd, wParam, lParam);
4095
4096 case TB_SETINDENT:
4097 return TOOLBAR_SetIndent (hwnd, wParam, lParam);
4098
4099/* case TB_SETINSERTMARK: */ /* 4.71 */
4100
4101 case TB_SETINSERTMARKCOLOR:
4102 return TOOLBAR_SetInsertMarkColor (hwnd, wParam, lParam);
4103
4104 case TB_SETMAXTEXTROWS:
4105 return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
4106
4107/* case TB_SETPADDING: */ /* 4.71 */
4108
4109 case TB_SETPARENT:
4110 return TOOLBAR_SetParent (hwnd, wParam, lParam);
4111
4112 case TB_SETROWS:
4113 return TOOLBAR_SetRows (hwnd, wParam, lParam);
4114
4115 case TB_SETSTATE:
4116 return TOOLBAR_SetState (hwnd, wParam, lParam);
4117
4118 case TB_SETSTYLE:
4119 return TOOLBAR_SetStyle (hwnd, wParam, lParam);
4120
4121 case TB_SETTOOLTIPS:
4122 return TOOLBAR_SetToolTips (hwnd, wParam, lParam);
4123
4124 case TB_SETUNICODEFORMAT:
4125 return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
4126
4127
4128/* case WM_CHAR: */
4129
4130 case WM_CREATE:
4131 return TOOLBAR_Create (hwnd, wParam, lParam);
4132
4133 case WM_DESTROY:
4134 return TOOLBAR_Destroy (hwnd, wParam, lParam);
4135
4136 case WM_ERASEBKGND:
4137 return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
4138
4139/* case WM_GETFONT: */
4140/* case WM_KEYDOWN: */
4141/* case WM_KILLFOCUS: */
4142
4143 case WM_LBUTTONDBLCLK:
4144 return TOOLBAR_LButtonDblClk (hwnd, wParam, lParam);
4145
4146 case WM_LBUTTONDOWN:
4147 return TOOLBAR_LButtonDown (hwnd, wParam, lParam);
4148
4149 case WM_LBUTTONUP:
4150 return TOOLBAR_LButtonUp (hwnd, wParam, lParam);
4151
4152 case WM_MOUSEMOVE:
4153 return TOOLBAR_MouseMove (hwnd, wParam, lParam);
4154
4155 case WM_NCACTIVATE:
4156 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
4157
4158 case WM_NCCALCSIZE:
4159 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
4160
4161 case WM_NCCREATE:
4162 return TOOLBAR_NCCreate (hwnd, wParam, lParam);
4163
4164 case WM_NCPAINT:
4165 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
4166
4167 case WM_NOTIFY:
4168 return TOOLBAR_Notify (hwnd, wParam, lParam);
4169
4170/* case WM_NOTIFYFORMAT: */
4171
4172 case WM_PAINT:
4173 return TOOLBAR_Paint (hwnd, wParam);
4174
4175 case WM_SIZE:
4176 return TOOLBAR_Size (hwnd, wParam, lParam);
4177
4178 case WM_STYLECHANGED:
4179 return TOOLBAR_StyleChanged (hwnd, wParam, lParam);
4180
4181/* case WM_SYSCOLORCHANGE: */
4182
4183/* case WM_WININICHANGE: */
4184
4185 case WM_CHARTOITEM:
4186 case WM_COMMAND:
4187 case WM_DRAWITEM:
4188 case WM_MEASUREITEM:
4189 case WM_VKEYTOITEM:
4190 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
4191
4192 default:
4193// if (uMsg >= WM_USER)
4194// ERR (toolbar, "unknown msg %04x wp=%08x lp=%08lx\n",
4195// uMsg, wParam, lParam);
4196 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4197 }
4198 return 0;
4199}
4200
4201
4202VOID
4203TOOLBAR_Register (VOID)
4204{
4205 WNDCLASSA wndClass;
4206
4207 if (GlobalFindAtomA (TOOLBARCLASSNAMEA)) return;
4208
4209 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4210 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
4211 wndClass.lpfnWndProc = (WNDPROC)ToolbarWindowProc;
4212 wndClass.cbClsExtra = 0;
4213 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
4214 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
4215 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
4216 wndClass.lpszClassName = TOOLBARCLASSNAMEA;
4217
4218 RegisterClassA (&wndClass);
4219}
4220
4221
4222VOID
4223TOOLBAR_Unregister (VOID)
4224{
4225 if (GlobalFindAtomA (TOOLBARCLASSNAMEA))
4226 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL);
4227}
4228
Note: See TracBrowser for help on using the repository browser.