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

Last change on this file since 6502 was 6380, checked in by sandervl, 24 years ago

wine resync

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