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

Last change on this file since 6644 was 6644, checked in by bird, 24 years ago

Added $Id:$ keyword.

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