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

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

font delete bugs removed

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