98965f42b85e727d23a7ad8c23ed90bd3c67b9b1
[reactos.git] / dll / win32 / comctl32 / toolbar.c
1 /*
2 * Toolbar control
3 *
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 *
22 * NOTES
23 *
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
26 *
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
30 *
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETOBJECT
37 * - TB_INSERTMARKHITTEST
38 * - TB_SAVERESTORE
39 * - WM_WININICHANGE
40 * - Notifications:
41 * - NM_CHAR
42 * - TBN_GETOBJECT
43 * - TBN_SAVE
44 * - Button wrapping (under construction).
45 * - Fix TB_SETROWS and Separators.
46 * - iListGap custom draw support.
47 *
48 * Testing:
49 * - Run tests using Waite Group Windows95 API Bible Volume 2.
50 * The second cdrom contains executables addstr.exe, btncount.exe,
51 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
52 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
53 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
54 * setparnt.exe, setrows.exe, toolwnd.exe.
55 * - Microsoft's controlspy examples.
56 * - Charles Petzold's 'Programming Windows': gadgets.exe
57 *
58 * Differences between MSDN and actual native control operation:
59 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
60 * to the right of the bitmap. Otherwise, this style is
61 * identical to TBSTYLE_FLAT."
62 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
63 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
64 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
65 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
66 *
67 */
68
69 #include "comctl32.h"
70
71 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
72
73 static HCURSOR hCursorDrag = NULL;
74
75 typedef struct
76 {
77 INT iBitmap;
78 INT idCommand;
79 BYTE fsState;
80 BYTE fsStyle;
81 BOOL bHot;
82 BOOL bDropDownPressed;
83 DWORD_PTR dwData;
84 INT_PTR iString;
85 INT nRow;
86 RECT rect;
87 INT cx; /* manually set size */
88 } TBUTTON_INFO;
89
90 typedef struct
91 {
92 UINT nButtons;
93 HINSTANCE hInst;
94 UINT nID;
95 } TBITMAP_INFO;
96
97 typedef struct
98 {
99 HIMAGELIST himl;
100 INT id;
101 } IMLENTRY, *PIMLENTRY;
102
103 typedef struct
104 {
105 DWORD dwStructSize; /* size of TBBUTTON struct */
106 RECT client_rect;
107 RECT rcBound; /* bounding rectangle */
108 INT nButtonHeight;
109 INT nButtonWidth;
110 INT nBitmapHeight;
111 INT nBitmapWidth;
112 INT nIndent;
113 INT nRows; /* number of button rows */
114 INT nMaxTextRows; /* maximum number of text rows */
115 INT cxMin; /* minimum button width */
116 INT cxMax; /* maximum button width */
117 INT nNumButtons; /* number of buttons */
118 INT nNumBitmaps; /* number of bitmaps */
119 INT nNumStrings; /* number of strings */
120 INT nNumBitmapInfos;
121 INT nButtonDown; /* toolbar button being pressed or -1 if none */
122 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
123 INT nOldHit;
124 INT nHotItem; /* index of the "hot" item */
125 SIZE szPadding; /* padding values around button */
126 #ifdef __REACTOS__
127 SIZE szBarPadding; /* padding values around the toolbar (NOT USED BUT STORED) */
128 SIZE szSpacing; /* spacing values between buttons */
129 MARGINS themeMargins;
130 #endif
131 INT iTopMargin; /* the top margin */
132 INT iListGap; /* default gap between text and image for toolbar with list style */
133 HFONT hDefaultFont;
134 HFONT hFont; /* text font */
135 HIMAGELIST himlInt; /* image list created internally */
136 PIMLENTRY *himlDef; /* default image list array */
137 INT cimlDef; /* default image list array count */
138 PIMLENTRY *himlHot; /* hot image list array */
139 INT cimlHot; /* hot image list array count */
140 PIMLENTRY *himlDis; /* disabled image list array */
141 INT cimlDis; /* disabled image list array count */
142 HWND hwndToolTip; /* handle to tool tip control */
143 HWND hwndNotify; /* handle to the window that gets notifications */
144 HWND hwndSelf; /* my own handle */
145 BOOL bAnchor; /* anchor highlight enabled */
146 BOOL bDoRedraw; /* Redraw status */
147 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
148 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
149 BOOL bCaptured; /* mouse captured? */
150 DWORD dwStyle; /* regular toolbar style */
151 DWORD dwExStyle; /* extended toolbar style */
152 DWORD dwDTFlags; /* DrawText flags */
153
154 COLORREF clrInsertMark; /* insert mark color */
155 COLORREF clrBtnHighlight; /* color for Flat Separator */
156 COLORREF clrBtnShadow; /* color for Flag Separator */
157 INT iVersion;
158 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
159 * for TTN_GETDISPINFOW notification */
160 TBINSERTMARK tbim; /* info on insertion mark */
161 TBUTTON_INFO *buttons; /* pointer to button array */
162 LPWSTR *strings; /* pointer to string array */
163 TBITMAP_INFO *bitmaps;
164 } TOOLBAR_INFO, *PTOOLBAR_INFO;
165
166
167 /* used by customization dialog */
168 typedef struct
169 {
170 PTOOLBAR_INFO tbInfo;
171 HWND tbHwnd;
172 } CUSTDLG_INFO, *PCUSTDLG_INFO;
173
174 typedef struct
175 {
176 TBBUTTON btn;
177 BOOL bVirtual;
178 BOOL bRemovable;
179 WCHAR text[64];
180 } CUSTOMBUTTON, *PCUSTOMBUTTON;
181
182 typedef enum
183 {
184 IMAGE_LIST_DEFAULT,
185 IMAGE_LIST_HOT,
186 IMAGE_LIST_DISABLED
187 } IMAGE_LIST_TYPE;
188
189 #define SEPARATOR_WIDTH 8
190 #define TOP_BORDER 2
191 #define BOTTOM_BORDER 2
192 #define DDARROW_WIDTH 11
193 #define ARROW_HEIGHT 3
194 #define INSERTMARK_WIDTH 2
195
196 /* default padding inside a button */
197 #define DEFPAD_CX 7
198 #define DEFPAD_CY 6
199
200 #ifdef __REACTOS__
201 /* default space between buttons and between rows */
202 #define DEFSPACE_CX 7
203 #define DEFSPACE_CY 6
204 #endif
205
206 #define DEFLISTGAP 4
207
208 /* vertical padding used in list mode when image is present */
209 #ifdef __REACTOS__
210 #define LISTPAD_CY 2
211 #else
212 #define LISTPAD_CY 9
213 #endif
214
215 /* how wide to treat the bitmap if it isn't present */
216 #define NONLIST_NOTEXT_OFFSET 2
217
218 #define TOOLBAR_NOWHERE (-1)
219
220 /* Used to find undocumented extended styles */
221 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
222 TBSTYLE_EX_VERTICAL | \
223 TBSTYLE_EX_MIXEDBUTTONS | \
224 TBSTYLE_EX_DOUBLEBUFFER | \
225 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
226
227 /* all of the CCS_ styles */
228 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
229 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
230
231 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
232 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
233 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
234 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
235 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
236
237 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
238
239 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
240 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
241 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
242 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
243 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
244 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
245 static LRESULT TOOLBAR_LButtonDown(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
246 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
247 static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
248 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
249 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
250 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
251 static LRESULT TOOLBAR_SetButtonInfo(TOOLBAR_INFO *infoPtr, INT Id,
252 const TBBUTTONINFOW *lptbbi, BOOL isW);
253
254
255 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
256 {
257 #ifdef __REACTOS__
258 if (infoPtr->iVersion == 6)
259 return 0;
260 #endif
261 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
262 }
263
264 static inline BOOL TOOLBAR_HasDropDownArrows(DWORD exStyle)
265 {
266 return (exStyle & TBSTYLE_EX_DRAWDDARROWS) != 0;
267 }
268
269 static inline BOOL button_has_ddarrow(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
270 {
271 return (TOOLBAR_HasDropDownArrows( infoPtr->dwExStyle ) && (btnPtr->fsStyle & BTNS_DROPDOWN)) ||
272 (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
273 }
274
275 static LPWSTR
276 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
277 {
278 LPWSTR lpText = NULL;
279
280 /* NOTE: iString == -1 is undocumented */
281 if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1))
282 lpText = (LPWSTR)btnPtr->iString;
283 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
284 lpText = infoPtr->strings[btnPtr->iString];
285
286 return lpText;
287 }
288
289 static void
290 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
291 {
292 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
293 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
294 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
295 }
296
297 static void
298 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
299 {
300 if (TRACE_ON(toolbar)){
301 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
302 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
303 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
304 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
305 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
306 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
307 wine_dbgstr_rect(&bP->rect));
308 }
309 }
310
311
312 static void
313 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
314 {
315 if (TRACE_ON(toolbar)) {
316 INT i;
317
318 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
319 iP->hwndSelf, line,
320 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
321 iP->nNumStrings, iP->dwStyle);
322 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
323 iP->hwndSelf, line,
324 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
325 (iP->bDoRedraw) ? "TRUE" : "FALSE");
326 for(i=0; i<iP->nNumButtons; i++) {
327 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
328 }
329 }
330 }
331
332 static inline BOOL
333 TOOLBAR_ButtonHasString(const TBUTTON_INFO *btnPtr)
334 {
335 return HIWORD(btnPtr->iString) && btnPtr->iString != -1;
336 }
337
338 static void set_string_index( TBUTTON_INFO *btn, INT_PTR str, BOOL unicode )
339 {
340 if (!IS_INTRESOURCE( str ) && str != -1)
341 {
342 if (!TOOLBAR_ButtonHasString( btn )) btn->iString = 0;
343
344 if (unicode)
345 Str_SetPtrW( (WCHAR **)&btn->iString, (WCHAR *)str );
346 else
347 Str_SetPtrAtoW( (WCHAR **)&btn->iString, (char *)str );
348 }
349 else
350 {
351 if (TOOLBAR_ButtonHasString( btn )) Free( (WCHAR *)btn->iString );
352
353 btn->iString = str;
354 }
355 }
356
357 static void set_stringT( TBUTTON_INFO *btn, const WCHAR *str, BOOL unicode )
358 {
359 if (IS_INTRESOURCE( (DWORD_PTR)str ) || (DWORD_PTR)str == -1) return;
360 set_string_index( btn, (DWORD_PTR)str, unicode );
361 }
362
363 static void free_string( TBUTTON_INFO *btn )
364 {
365 set_string_index( btn, 0, TRUE );
366
367 }
368
369 /***********************************************************************
370 * TOOLBAR_CheckStyle
371 *
372 * This function validates that the styles set are implemented and
373 * issues FIXMEs warning of possible problems. In a perfect world this
374 * function should be null.
375 */
376 static void
377 TOOLBAR_CheckStyle (const TOOLBAR_INFO *infoPtr)
378 {
379 if (infoPtr->dwStyle & TBSTYLE_REGISTERDROP)
380 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr->hwndSelf);
381 }
382
383
384 static INT
385 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
386 {
387 if(!IsWindow(infoPtr->hwndSelf))
388 return 0; /* we have just been destroyed */
389
390 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
391 nmhdr->hwndFrom = infoPtr->hwndSelf;
392 nmhdr->code = code;
393
394 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
395 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
396
397 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
398 }
399
400 /***********************************************************************
401 * TOOLBAR_GetBitmapIndex
402 *
403 * This function returns the bitmap index associated with a button.
404 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
405 * is issued to retrieve the index.
406 */
407 static INT
408 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
409 {
410 INT ret = btnPtr->iBitmap;
411
412 if (ret == I_IMAGECALLBACK)
413 {
414 /* issue TBN_GETDISPINFO */
415 NMTBDISPINFOW nmgd;
416
417 memset(&nmgd, 0, sizeof(nmgd));
418 nmgd.idCommand = btnPtr->idCommand;
419 nmgd.lParam = btnPtr->dwData;
420 nmgd.dwMask = TBNF_IMAGE;
421 nmgd.iImage = -1;
422 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
423 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
424 if (nmgd.dwMask & TBNF_DI_SETITEM)
425 btnPtr->iBitmap = nmgd.iImage;
426 ret = nmgd.iImage;
427 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
428 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
429 }
430
431 if (ret != I_IMAGENONE)
432 ret = GETIBITMAP(infoPtr, ret);
433
434 return ret;
435 }
436
437
438 static BOOL
439 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
440 {
441 HIMAGELIST himl;
442 INT id = GETHIMLID(infoPtr, index);
443 INT iBitmap = GETIBITMAP(infoPtr, index);
444
445 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
446 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
447 (index == I_IMAGECALLBACK))
448 return TRUE;
449 else
450 return FALSE;
451 }
452
453
454 static inline BOOL
455 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
456 {
457 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
458 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
459 }
460
461
462 /***********************************************************************
463 * TOOLBAR_GetImageListForDrawing
464 *
465 * This function validates the bitmap index (including I_IMAGECALLBACK
466 * functionality) and returns the corresponding image list.
467 */
468 static HIMAGELIST
469 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
470 IMAGE_LIST_TYPE imagelist, INT * index)
471 {
472 HIMAGELIST himl;
473
474 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
475 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
476 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
477 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
478 return NULL;
479 }
480
481 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
482 if ((*index == I_IMAGECALLBACK) ||
483 (*index == I_IMAGENONE)) return NULL;
484 ERR("TBN_GETDISPINFO returned invalid index %d\n",
485 *index);
486 return NULL;
487 }
488
489 switch(imagelist)
490 {
491 case IMAGE_LIST_DEFAULT:
492 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
493 break;
494 case IMAGE_LIST_HOT:
495 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
496 break;
497 case IMAGE_LIST_DISABLED:
498 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
499 break;
500 default:
501 himl = NULL;
502 FIXME("Shouldn't reach here\n");
503 }
504
505 if (!himl)
506 TRACE("no image list\n");
507
508 return himl;
509 }
510
511
512 static void
513 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
514 {
515 RECT myrect;
516 COLORREF oldcolor, newcolor;
517
518 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
519 myrect.right = myrect.left + 1;
520 myrect.top = lpRect->top + 2;
521 myrect.bottom = lpRect->bottom - 2;
522
523 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
524 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
525 oldcolor = SetBkColor (hdc, newcolor);
526 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
527
528 myrect.left = myrect.right;
529 myrect.right = myrect.left + 1;
530
531 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
532 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
533 SetBkColor (hdc, newcolor);
534 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
535
536 SetBkColor (hdc, oldcolor);
537 }
538
539
540 /***********************************************************************
541 * TOOLBAR_DrawFlatHorizontalSeparator
542 *
543 * This function draws horizontal separator for toolbars having CCS_VERT style.
544 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
545 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
546 * are horizontal as opposed to the vertical separators for not dropdown
547 * type.
548 *
549 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
550 */
551 static void
552 TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
553 const TOOLBAR_INFO *infoPtr)
554 {
555 RECT myrect;
556 COLORREF oldcolor, newcolor;
557
558 myrect.left = lpRect->left;
559 myrect.right = lpRect->right;
560 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
561 myrect.bottom = myrect.top + 1;
562
563 InflateRect (&myrect, -2, 0);
564
565 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
566
567 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
568 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
569 oldcolor = SetBkColor (hdc, newcolor);
570 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
571
572 myrect.top = myrect.bottom;
573 myrect.bottom = myrect.top + 1;
574
575 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
576 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
577 SetBkColor (hdc, newcolor);
578 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
579
580 SetBkColor (hdc, oldcolor);
581 }
582
583
584 static void
585 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
586 {
587 INT x, y;
588 HPEN hPen, hOldPen;
589
590 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
591 hOldPen = SelectObject ( hdc, hPen );
592 x = left + 2;
593 y = top;
594 MoveToEx (hdc, x, y, NULL);
595 LineTo (hdc, x+5, y++); x++;
596 MoveToEx (hdc, x, y, NULL);
597 LineTo (hdc, x+3, y++); x++;
598 MoveToEx (hdc, x, y, NULL);
599 LineTo (hdc, x+1, y);
600 SelectObject( hdc, hOldPen );
601 DeleteObject( hPen );
602 }
603
604 /*
605 * Draw the text string for this button.
606 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
607 * is non-zero, so we can simply check himlDef to see if we have
608 * an image list
609 */
610 static void
611 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
612 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
613 {
614 HDC hdc = tbcd->nmcd.hdc;
615 HFONT hOldFont = 0;
616 COLORREF clrOld = 0;
617 COLORREF clrOldBk = 0;
618 int oldBkMode = 0;
619 UINT state = tbcd->nmcd.uItemState;
620 #ifdef __REACTOS__
621 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
622 #endif
623
624 /* draw text */
625 if (lpText && infoPtr->nMaxTextRows > 0) {
626 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
627 wine_dbgstr_rect(rcText));
628
629 hOldFont = SelectObject (hdc, infoPtr->hFont);
630 #ifdef __REACTOS__
631 if (theme)
632 {
633 DWORD dwDTFlags2 = 0;
634 int partId = TP_BUTTON;
635 int stateId = TS_NORMAL;
636
637 if (state & CDIS_DISABLED)
638 {
639 stateId = TS_DISABLED;
640 dwDTFlags2 = DTT_GRAYED;
641 }
642 else if (state & CDIS_SELECTED)
643 stateId = TS_PRESSED;
644 else if (state & CDIS_CHECKED)
645 stateId = (state & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
646 else if (state & CDIS_HOT)
647 stateId = TS_HOT;
648
649 DrawThemeText(theme, hdc, partId, stateId, lpText, -1, infoPtr->dwDTFlags, dwDTFlags2, rcText);
650 SelectObject (hdc, hOldFont);
651 return;
652 }
653 #endif
654
655 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
656 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
657 }
658 else if (state & CDIS_DISABLED) {
659 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
660 OffsetRect (rcText, 1, 1);
661 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
662 SetTextColor (hdc, comctl32_color.clr3dShadow);
663 OffsetRect (rcText, -1, -1);
664 }
665 else if (state & CDIS_INDETERMINATE) {
666 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
667 }
668 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
669 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
670 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
671 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
672 }
673 else {
674 clrOld = SetTextColor (hdc, tbcd->clrText);
675 }
676
677 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
678 SetTextColor (hdc, clrOld);
679 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
680 {
681 SetBkColor (hdc, clrOldBk);
682 SetBkMode (hdc, oldBkMode);
683 }
684 SelectObject (hdc, hOldFont);
685 }
686 }
687
688
689 static void
690 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
691 {
692 HDC hdc = tbcd->nmcd.hdc;
693 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
694 COLORREF clrTextOld;
695 COLORREF clrBkOld;
696 INT cx = lpRect->right - lpRect->left;
697 INT cy = lpRect->bottom - lpRect->top;
698 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
699 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
700 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
701 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
702 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
703 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
704 SetBkColor(hdc, clrBkOld);
705 SetTextColor(hdc, clrTextOld);
706 SelectObject (hdc, hbr);
707 }
708
709
710 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
711 {
712 INT cx, cy;
713 HBITMAP hbmMask, hbmImage;
714 HDC hdcMask, hdcImage;
715
716 ImageList_GetIconSize(himl, &cx, &cy);
717
718 /* Create src image */
719 hdcImage = CreateCompatibleDC(hdc);
720 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
721 SelectObject(hdcImage, hbmImage);
722 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
723 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
724
725 /* Create Mask */
726 hdcMask = CreateCompatibleDC(0);
727 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
728 SelectObject(hdcMask, hbmMask);
729
730 /* Remove the background and all white pixels */
731 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
732 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
733 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
734 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
735
736 /* draw the new mask 'etched' to hdc */
737 SetBkColor(hdc, RGB(255, 255, 255));
738 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
739 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
740 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
741 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
742 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
743
744 /* Cleanup */
745 DeleteObject(hbmImage);
746 DeleteDC(hdcImage);
747 DeleteObject (hbmMask);
748 DeleteDC(hdcMask);
749 }
750
751
752 static UINT
753 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
754 {
755 UINT retstate = 0;
756
757 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
758 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
759 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
760 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
761 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
762 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
763 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
764 return retstate;
765 }
766
767 /* draws the image on a toolbar button */
768 static void
769 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
770 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
771 {
772 HIMAGELIST himl = NULL;
773 BOOL draw_masked = FALSE, draw_desaturated = FALSE;
774 INT index;
775 INT offset = 0;
776 UINT draw_flags = ILD_TRANSPARENT;
777 #ifdef __REACTOS__
778 IMAGEINFO info = {0};
779 BITMAP bm = {0};
780 #endif
781
782 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
783 {
784 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
785 if (!himl)
786 {
787 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
788
789 #ifdef __REACTOS__
790 ImageList_GetImageInfo(himl, index, &info);
791 GetObjectW(info.hbmImage, sizeof(bm), &bm);
792
793 if (bm.bmBitsPixel == 32)
794 {
795 draw_desaturated = TRUE;
796 }
797 else
798 {
799 draw_masked = TRUE;
800 }
801 #else
802 draw_masked = TRUE;
803 #endif
804 }
805 }
806 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
807 ((tbcd->nmcd.uItemState & CDIS_HOT)
808 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
809 {
810 /* if hot, attempt to draw with hot image list, if fails,
811 use default image list */
812 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
813 if (!himl)
814 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
815 }
816 else
817 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
818
819 if (!himl)
820 return;
821
822 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
823 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
824 offset = 1;
825
826 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
827 (tbcd->nmcd.uItemState & CDIS_MARKED))
828 draw_flags |= ILD_BLEND50;
829
830 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
831 index, himl, left, top, offset);
832
833 if (draw_masked)
834 {
835 /* code path for drawing flat disabled icons without alpha channel */
836 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
837 }
838 else if (draw_desaturated)
839 {
840 /* code path for drawing disabled, alpha-blended (32bpp) icons */
841 IMAGELISTDRAWPARAMS imldp = {0};
842
843 imldp.cbSize = sizeof(imldp);
844 imldp.himl = himl;
845 imldp.i = index;
846 imldp.hdcDst = tbcd->nmcd.hdc,
847 imldp.x = offset + left;
848 imldp.y = offset + top;
849 imldp.rgbBk = CLR_NONE;
850 imldp.rgbFg = CLR_DEFAULT;
851 imldp.fStyle = ILD_TRANSPARENT;
852 imldp.fState = ILS_ALPHA | ILS_SATURATE;
853 imldp.Frame = 192;
854
855 ImageList_DrawIndirect (&imldp);
856 }
857 else
858 {
859 /* code path for drawing standard icons as-is */
860 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
861 }
862 }
863
864 /* draws a blank frame for a toolbar button */
865 static void
866 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, const RECT *rect, DWORD dwItemCDFlag)
867 {
868 HDC hdc = tbcd->nmcd.hdc;
869 RECT rc = *rect;
870 /* if the state is disabled or indeterminate then the button
871 * cannot have an interactive look like pressed or hot */
872 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
873 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
874 BOOL pressed_look = !non_interactive_state &&
875 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
876 (tbcd->nmcd.uItemState & CDIS_CHECKED));
877
878 /* app don't want us to draw any edges */
879 if (dwItemCDFlag & TBCDRF_NOEDGES)
880 return;
881
882 if (infoPtr->dwStyle & TBSTYLE_FLAT)
883 {
884 if (pressed_look)
885 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
886 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
887 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
888 }
889 else
890 {
891 if (pressed_look)
892 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
893 else
894 DrawEdge (hdc, &rc, EDGE_RAISED,
895 BF_SOFT | BF_RECT | BF_MIDDLE);
896 }
897 }
898
899 static void
900 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
901 {
902 HDC hdc = tbcd->nmcd.hdc;
903 int offset = 0;
904 BOOL pressed = bDropDownPressed ||
905 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
906
907 if (infoPtr->dwStyle & TBSTYLE_FLAT)
908 {
909 if (pressed)
910 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
911 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
912 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
913 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
914 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
915 }
916 else
917 {
918 if (pressed)
919 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
920 else
921 DrawEdge (hdc, rcArrow, EDGE_RAISED,
922 BF_SOFT | BF_RECT | BF_MIDDLE);
923 }
924
925 if (pressed)
926 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
927
928 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
929 {
930 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
931 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
932 }
933 else
934 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
935 }
936
937 /* draws a complete toolbar button */
938 static void
939 TOOLBAR_DrawButton (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
940 {
941 DWORD dwStyle = infoPtr->dwStyle;
942 BOOL hasDropDownArrow = button_has_ddarrow( infoPtr, btnPtr );
943 BOOL drawSepDropDownArrow = hasDropDownArrow &&
944 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
945 RECT rc, rcArrow, rcBitmap, rcText;
946 LPWSTR lpText = NULL;
947 NMTBCUSTOMDRAW tbcd;
948 DWORD ntfret;
949 INT offset;
950 INT oldBkMode;
951 DWORD dwItemCustDraw;
952 DWORD dwItemCDFlag;
953 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
954
955 rc = btnPtr->rect;
956 rcArrow = rc;
957
958 /* separator - doesn't send NM_CUSTOMDRAW */
959 if (btnPtr->fsStyle & BTNS_SEP) {
960 if (theme)
961 {
962 DrawThemeBackground (theme, hdc,
963 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
964 &rc, NULL);
965 }
966 else
967 /* with the FLAT style, iBitmap is the width and has already */
968 /* been taken into consideration in calculating the width */
969 /* so now we need to draw the vertical separator */
970 /* empirical tests show that iBitmap can/will be non-zero */
971 /* when drawing the vertical bar... */
972 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
973 if (dwStyle & CCS_VERT) {
974 RECT rcsep = rc;
975 InflateRect(&rcsep, -infoPtr->szPadding.cx, -infoPtr->szPadding.cy);
976 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep, hdc, infoPtr);
977 }
978 else {
979 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
980 }
981 }
982 else if (btnPtr->fsStyle != BTNS_SEP) {
983 FIXME("Draw some kind of separator: fsStyle=%x\n",
984 btnPtr->fsStyle);
985 }
986 return;
987 }
988
989 /* get a pointer to the text */
990 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
991
992 if (hasDropDownArrow)
993 {
994 int right;
995
996 if (dwStyle & TBSTYLE_FLAT)
997 right = max(rc.left, rc.right - DDARROW_WIDTH);
998 else
999 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
1000
1001 if (drawSepDropDownArrow)
1002 rc.right = right;
1003
1004 rcArrow.left = right;
1005 }
1006
1007 /* copy text & bitmap rects after adjusting for drop-down arrow
1008 * so that text & bitmap is centered in the rectangle not containing
1009 * the arrow */
1010 rcText = rc;
1011 rcBitmap = rc;
1012
1013 /* Center the bitmap horizontally and vertically */
1014 if (dwStyle & TBSTYLE_LIST)
1015 {
1016 if (lpText &&
1017 infoPtr->nMaxTextRows > 0 &&
1018 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1019 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1020 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
1021 else
1022 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
1023 }
1024 else
1025 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
1026
1027 rcBitmap.top += infoPtr->szPadding.cy / 2;
1028 #ifdef __REACTOS__
1029 rcBitmap.top += infoPtr->themeMargins.cyTopHeight;
1030 #endif
1031
1032 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
1033 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
1034 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1035 TRACE("Text=%s\n", debugstr_w(lpText));
1036 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
1037
1038 /* calculate text position */
1039 if (lpText)
1040 {
1041 InflateRect(&rcText, -GetSystemMetrics(SM_CXEDGE), 0);
1042 if (dwStyle & TBSTYLE_LIST)
1043 {
1044 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
1045 }
1046 else
1047 {
1048 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
1049 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
1050 else
1051 rcText.top += infoPtr->szPadding.cy/2 + 2;
1052 }
1053 }
1054
1055 /* Initialize fields in all cases, because we use these later
1056 * NOTE: applications can and do alter these to customize their
1057 * toolbars */
1058 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1059 tbcd.clrText = comctl32_color.clrBtnText;
1060 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
1061 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
1062 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
1063 tbcd.clrMark = comctl32_color.clrHighlight;
1064 tbcd.clrHighlightHotTrack = 0;
1065 tbcd.nStringBkMode = TRANSPARENT;
1066 tbcd.nHLStringBkMode = OPAQUE;
1067 tbcd.rcText.left = 0;
1068 tbcd.rcText.top = 0;
1069 tbcd.rcText.right = rcText.right - rc.left;
1070 tbcd.rcText.bottom = rcText.bottom - rc.top;
1071 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1072 tbcd.nmcd.hdc = hdc;
1073 tbcd.nmcd.rc = btnPtr->rect;
1074 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
1075
1076 /* FIXME: what are these used for? */
1077 tbcd.hbrLines = 0;
1078 tbcd.hpenLines = 0;
1079
1080 /* Issue Item Prepaint notify */
1081 dwItemCustDraw = 0;
1082 dwItemCDFlag = 0;
1083 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
1084 {
1085 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
1086 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1087 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1088 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1089 /* reset these fields so the user can't alter the behaviour like native */
1090 tbcd.nmcd.hdc = hdc;
1091 tbcd.nmcd.rc = btnPtr->rect;
1092
1093 dwItemCustDraw = ntfret & 0xffff;
1094 dwItemCDFlag = ntfret & 0xffff0000;
1095 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
1096 return;
1097 /* save the only part of the rect that the user can change */
1098 rcText.right = tbcd.rcText.right + rc.left;
1099 rcText.bottom = tbcd.rcText.bottom + rc.top;
1100 }
1101
1102 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
1103 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
1104 OffsetRect(&rcText, 1, 1);
1105
1106 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
1107 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
1108 TOOLBAR_DrawPattern (&rc, &tbcd);
1109
1110 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
1111 && (tbcd.nmcd.uItemState & CDIS_HOT))
1112 {
1113 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
1114 {
1115 COLORREF oldclr;
1116
1117 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1118 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1119 if (hasDropDownArrow)
1120 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1121 SetBkColor(hdc, oldclr);
1122 }
1123 }
1124
1125 #ifdef __REACTOS__
1126 if (theme && !(dwItemCDFlag & TBCDRF_NOBACKGROUND))
1127 #else
1128 if (theme)
1129 #endif
1130 {
1131 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1132 int stateId = TS_NORMAL;
1133
1134 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1135 stateId = TS_DISABLED;
1136 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1137 stateId = TS_PRESSED;
1138 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1139 #ifdef __REACTOS__
1140 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_CHECKED;
1141 #else
1142 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1143 #endif
1144 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1145 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1146 stateId = TS_HOT;
1147
1148 DrawThemeBackground (theme, hdc, partId, stateId, &rc, NULL);
1149 }
1150
1151 #ifdef __REACTOS__
1152 if (!theme)
1153 #else
1154 else
1155 #endif
1156 TOOLBAR_DrawFrame(infoPtr, &tbcd, &rc, dwItemCDFlag);
1157
1158 if (drawSepDropDownArrow)
1159 {
1160 if (theme)
1161 {
1162 int stateId = TS_NORMAL;
1163
1164 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1165 stateId = TS_DISABLED;
1166 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1167 stateId = TS_PRESSED;
1168 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1169 #ifdef __REACTOS__
1170 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_CHECKED;
1171 #else
1172 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1173 #endif
1174 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1175 stateId = TS_HOT;
1176
1177 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1178 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1179 }
1180 else
1181 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1182 }
1183
1184 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1185 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1186 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1187 SetBkMode (hdc, oldBkMode);
1188
1189 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1190
1191 if (hasDropDownArrow && !drawSepDropDownArrow)
1192 {
1193 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1194 {
1195 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1196 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1197 }
1198 #ifndef __REACTOS__
1199 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1200 {
1201 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1202 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1203 }
1204 else
1205 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1206 #else
1207 else
1208 {
1209 COLORREF clr = comctl32_color.clrBtnText;
1210 if (theme)
1211 GetThemeColor(theme, TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, &clr);
1212
1213 if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1214 {
1215 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1216 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, clr);
1217 }
1218 else
1219 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, clr);
1220 }
1221 #endif
1222 }
1223
1224 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1225 {
1226 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1227 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1228 }
1229
1230 }
1231
1232
1233 static void
1234 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1235 {
1236 TBUTTON_INFO *btnPtr;
1237 INT i;
1238 RECT rcTemp, rcClient;
1239 NMTBCUSTOMDRAW tbcd;
1240 DWORD ntfret;
1241 DWORD dwBaseCustDraw;
1242
1243 /* the app has told us not to redraw the toolbar */
1244 if (!infoPtr->bDoRedraw)
1245 return;
1246
1247 /* if imagelist belongs to the app, it can be changed
1248 by the app after setting it */
1249 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1250 {
1251 infoPtr->nNumBitmaps = 0;
1252 for (i = 0; i < infoPtr->cimlDef; i++)
1253 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1254 }
1255
1256 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1257
1258 /* change the imagelist icon size if we manage the list and it is necessary */
1259 TOOLBAR_CheckImageListIconSize(infoPtr);
1260
1261 /* Send initial notify */
1262 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1263 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1264 tbcd.nmcd.hdc = hdc;
1265 tbcd.nmcd.rc = ps->rcPaint;
1266 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1267 dwBaseCustDraw = ntfret & 0xffff;
1268
1269 GetClientRect(infoPtr->hwndSelf, &rcClient);
1270
1271 /* redraw necessary buttons */
1272 btnPtr = infoPtr->buttons;
1273 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1274 {
1275 BOOL bDraw;
1276 if (!RectVisible(hdc, &btnPtr->rect))
1277 continue;
1278 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1279 {
1280 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1281 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1282 }
1283 else
1284 bDraw = TRUE;
1285 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1286 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1287 if (bDraw)
1288 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1289 }
1290
1291 /* draw insert mark if required */
1292 if (infoPtr->tbim.iButton != -1)
1293 {
1294 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1295 RECT rcInsertMark;
1296 rcInsertMark.top = rcButton.top;
1297 rcInsertMark.bottom = rcButton.bottom;
1298 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1299 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1300 else
1301 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1302 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1303 }
1304
1305 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1306 {
1307 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1308 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1309 tbcd.nmcd.hdc = hdc;
1310 tbcd.nmcd.rc = ps->rcPaint;
1311 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1312 }
1313 }
1314
1315 /***********************************************************************
1316 * TOOLBAR_MeasureString
1317 *
1318 * This function gets the width and height of a string in pixels. This
1319 * is done first by using GetTextExtentPoint to get the basic width
1320 * and height. The DrawText is called with DT_CALCRECT to get the exact
1321 * width. The reason is because the text may have more than one "&" (or
1322 * prefix characters as M$ likes to call them). The prefix character
1323 * indicates where the underline goes, except for the string "&&" which
1324 * is reduced to a single "&". GetTextExtentPoint does not process these
1325 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1326 */
1327 static void
1328 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1329 HDC hdc, LPSIZE lpSize)
1330 {
1331 RECT myrect;
1332
1333 lpSize->cx = 0;
1334 lpSize->cy = 0;
1335
1336 if (infoPtr->nMaxTextRows > 0 &&
1337 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1338 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1339 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1340 {
1341 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1342
1343 if(lpText != NULL) {
1344 /* first get size of all the text */
1345 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1346
1347 /* feed above size into the rectangle for DrawText */
1348 SetRect(&myrect, 0, 0, lpSize->cx, lpSize->cy);
1349
1350 /* Use DrawText to get true size as drawn (less pesky "&") */
1351 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1352 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1353 DT_NOPREFIX : 0));
1354
1355 /* feed back to caller */
1356 lpSize->cx = myrect.right;
1357 lpSize->cy = myrect.bottom;
1358 }
1359 }
1360
1361 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1362 }
1363
1364 /***********************************************************************
1365 * TOOLBAR_CalcStrings
1366 *
1367 * This function walks through each string and measures it and returns
1368 * the largest height and width to caller.
1369 */
1370 static void
1371 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1372 {
1373 TBUTTON_INFO *btnPtr;
1374 INT i;
1375 SIZE sz;
1376 HDC hdc;
1377 HFONT hOldFont;
1378
1379 lpSize->cx = 0;
1380 lpSize->cy = 0;
1381
1382 if (infoPtr->nMaxTextRows == 0)
1383 return;
1384
1385 hdc = GetDC (infoPtr->hwndSelf);
1386 hOldFont = SelectObject (hdc, infoPtr->hFont);
1387
1388 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1389 {
1390 TEXTMETRICW tm;
1391
1392 GetTextMetricsW(hdc, &tm);
1393 lpSize->cy = tm.tmHeight;
1394 }
1395
1396 btnPtr = infoPtr->buttons;
1397 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1398 if(TOOLBAR_GetText(infoPtr, btnPtr))
1399 {
1400 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1401 if (sz.cx > lpSize->cx)
1402 lpSize->cx = sz.cx;
1403 if (sz.cy > lpSize->cy)
1404 lpSize->cy = sz.cy;
1405 }
1406 }
1407
1408 SelectObject (hdc, hOldFont);
1409 ReleaseDC (infoPtr->hwndSelf, hdc);
1410
1411 TRACE("max string size %d x %d\n", lpSize->cx, lpSize->cy);
1412 }
1413
1414 /***********************************************************************
1415 * TOOLBAR_WrapToolbar
1416 *
1417 * This function walks through the buttons and separators in the
1418 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1419 * wrapping should occur based on the width of the toolbar window.
1420 * It does *not* calculate button placement itself. That task
1421 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1422 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1423 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1424 *
1425 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1426 * vertical toolbar lists.
1427 */
1428
1429 static void
1430 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1431 {
1432 TBUTTON_INFO *btnPtr;
1433 INT x, cx, i, j, width;
1434 BOOL bButtonWrap;
1435
1436 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1437 /* no layout is necessary. Applications may use this style */
1438 /* to perform their own layout on the toolbar. */
1439 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1440 !(infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL) ) return;
1441
1442 btnPtr = infoPtr->buttons;
1443 x = infoPtr->nIndent;
1444 width = infoPtr->client_rect.right - infoPtr->client_rect.left;
1445
1446 bButtonWrap = FALSE;
1447
1448 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1449 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, width,
1450 infoPtr->nIndent);
1451
1452 for (i = 0; i < infoPtr->nNumButtons; i++ )
1453 {
1454 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1455
1456 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1457 continue;
1458
1459 if (btnPtr[i].cx > 0)
1460 cx = btnPtr[i].cx;
1461 /* horizontal separators are treated as buttons for width */
1462 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1463 !(infoPtr->dwStyle & CCS_VERT))
1464 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1465 else
1466 cx = infoPtr->nButtonWidth;
1467
1468 if (!btnPtr[i].cx && button_has_ddarrow( infoPtr, btnPtr + i ))
1469 cx += DDARROW_WIDTH;
1470
1471 /* Two or more adjacent separators form a separator group. */
1472 /* The first separator in a group should be wrapped to the */
1473 /* next row if the previous wrapping is on a button. */
1474 if( bButtonWrap &&
1475 (btnPtr[i].fsStyle & BTNS_SEP) &&
1476 (i + 1 < infoPtr->nNumButtons ) &&
1477 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1478 {
1479 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1480 btnPtr[i].fsState |= TBSTATE_WRAP;
1481 x = infoPtr->nIndent;
1482 i++;
1483 bButtonWrap = FALSE;
1484 continue;
1485 }
1486
1487 /* The layout makes sure the bitmap is visible, but not the button. */
1488 /* Test added to also wrap after a button that starts a row but */
1489 /* is bigger than the area. - GA 8/01 */
1490 if ((x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2 > width) ||
1491 ((x == infoPtr->nIndent) && (cx > width)))
1492 {
1493 BOOL bFound = FALSE;
1494
1495 /* If the current button is a separator and not hidden, */
1496 /* go to the next until it reaches a non separator. */
1497 /* Wrap the last separator if it is before a button. */
1498 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1499 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1500 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1501 i < infoPtr->nNumButtons )
1502 {
1503 i++;
1504 bFound = TRUE;
1505 }
1506
1507 if( bFound && i < infoPtr->nNumButtons )
1508 {
1509 i--;
1510 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1511 i, btnPtr[i].fsStyle, x, cx);
1512 btnPtr[i].fsState |= TBSTATE_WRAP;
1513 x = infoPtr->nIndent;
1514 bButtonWrap = FALSE;
1515 continue;
1516 }
1517 else if ( i >= infoPtr->nNumButtons)
1518 break;
1519
1520 /* If the current button is not a separator, find the last */
1521 /* separator and wrap it. */
1522 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1523 {
1524 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1525 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1526 {
1527 bFound = TRUE;
1528 i = j;
1529 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1530 i, btnPtr[i].fsStyle, x, cx);
1531 x = infoPtr->nIndent;
1532 btnPtr[j].fsState |= TBSTATE_WRAP;
1533 bButtonWrap = FALSE;
1534 break;
1535 }
1536 }
1537
1538 /* If no separator available for wrapping, wrap one of */
1539 /* non-hidden previous button. */
1540 if (!bFound)
1541 {
1542 for ( j = i - 1;
1543 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1544 {
1545 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1546 continue;
1547
1548 bFound = TRUE;
1549 i = j;
1550 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1551 i, btnPtr[i].fsStyle, x, cx);
1552 x = infoPtr->nIndent;
1553 btnPtr[j].fsState |= TBSTATE_WRAP;
1554 bButtonWrap = TRUE;
1555 break;
1556 }
1557 }
1558
1559 /* If all above failed, wrap the current button. */
1560 if (!bFound)
1561 {
1562 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1563 i, btnPtr[i].fsStyle, x, cx);
1564 btnPtr[i].fsState |= TBSTATE_WRAP;
1565 x = infoPtr->nIndent;
1566 if (btnPtr[i].fsStyle & BTNS_SEP )
1567 bButtonWrap = FALSE;
1568 else
1569 bButtonWrap = TRUE;
1570 }
1571 }
1572 else {
1573 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1574 i, btnPtr[i].fsStyle, x, cx);
1575 x += cx;
1576 }
1577 }
1578 }
1579
1580
1581 /***********************************************************************
1582 * TOOLBAR_MeasureButton
1583 *
1584 * Calculates the width and height required for a button. Used in
1585 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1586 * the width of buttons that are autosized.
1587 *
1588 * Note that it would have been rather elegant to use one piece of code for
1589 * both the laying out of the toolbar and for controlling where button parts
1590 * are drawn, but the native control has inconsistencies between the two that
1591 * prevent this from being effectively. These inconsistencies can be seen as
1592 * artefacts where parts of the button appear outside of the bounding button
1593 * rectangle.
1594 *
1595 * There are several cases for the calculation of the button dimensions and
1596 * button part positioning:
1597 *
1598 * List
1599 * ====
1600 *
1601 * With Bitmap:
1602 *
1603 * +--------------------------------------------------------+ ^
1604 * | ^ ^ | |
1605 * | | pad.cy / 2 | centered | |
1606 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1607 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1608 * | |<------------>| | | | |
1609 * | +--------------+ +------------+ | |
1610 * |<-------------------------------------->| | |
1611 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1612 * | szText.cx | |
1613 * +--------------------------------------------------------+ -
1614 * <-------------------------------------------------------->
1615 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1616 *
1617 * Without Bitmap (I_IMAGENONE):
1618 *
1619 * +-----------------------------------+ ^
1620 * | ^ | |
1621 * | | centered | | LISTPAD_CY +
1622 * | +------------+ | | szText.cy
1623 * | | Text | | |
1624 * | | | | |
1625 * | +------------+ | |
1626 * |<----------------->| | |
1627 * | cxedge |<-----------> | |
1628 * | szText.cx | |
1629 * +-----------------------------------+ -
1630 * <----------------------------------->
1631 * szText.cx + pad.cx
1632 *
1633 * Without text:
1634 *
1635 * +--------------------------------------+ ^
1636 * | ^ | |
1637 * | | padding.cy/2 | | DEFPAD_CY +
1638 * | +------------+ | | nBitmapHeight
1639 * | | Bitmap | | |
1640 * | | | | |
1641 * | +------------+ | |
1642 * |<------------------->| | |
1643 * | cxedge + iListGap/2 |<-----------> | |
1644 * | nBitmapWidth | |
1645 * +--------------------------------------+ -
1646 * <-------------------------------------->
1647 * 2*cxedge + nBitmapWidth + iListGap
1648 *
1649 * Non-List
1650 * ========
1651 *
1652 * With bitmap:
1653 *
1654 * +-----------------------------------+ ^
1655 * | ^ | |
1656 * | | pad.cy / 2 | | nBitmapHeight +
1657 * | - | | szText.cy +
1658 * | +------------+ | | DEFPAD_CY + 1
1659 * | centered | Bitmap | | |
1660 * |<----------------->| | | |
1661 * | +------------+ | |
1662 * | ^ | |
1663 * | 1 | | |
1664 * | - | |
1665 * | centered +---------------+ | |
1666 * |<--------------->| Text | | |
1667 * | +---------------+ | |
1668 * +-----------------------------------+ -
1669 * <----------------------------------->
1670 * pad.cx + max(nBitmapWidth, szText.cx)
1671 *
1672 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1673 *
1674 * +---------------------------------------+ ^
1675 * | ^ | |
1676 * | | 2 + pad.cy / 2 | |
1677 * | - | | szText.cy +
1678 * | centered +-----------------+ | | pad.cy + 2
1679 * |<--------------->| Text | | |
1680 * | +-----------------+ | |
1681 * | | |
1682 * +---------------------------------------+ -
1683 * <--------------------------------------->
1684 * 2*cxedge + pad.cx + szText.cx
1685 *
1686 * Without text:
1687 * As for with bitmaps, but with szText.cx zero.
1688 */
1689 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1690 BOOL bHasBitmap, BOOL bValidImageList)
1691 {
1692 SIZE sizeButton;
1693 if (infoPtr->dwStyle & TBSTYLE_LIST)
1694 {
1695 /* set button height from bitmap / text height... */
1696 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1697 sizeString.cy);
1698
1699 /* ... add on the necessary padding */
1700 if (bValidImageList)
1701 {
1702 #ifdef __REACTOS__
1703 sizeButton.cy += infoPtr->szPadding.cy;
1704 if (!bHasBitmap)
1705 #else
1706 if (bHasBitmap)
1707 sizeButton.cy += DEFPAD_CY;
1708 else
1709 #endif
1710 sizeButton.cy += LISTPAD_CY;
1711 }
1712 else
1713 sizeButton.cy += infoPtr->szPadding.cy;
1714
1715 /* calculate button width */
1716 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1717 infoPtr->nBitmapWidth + infoPtr->iListGap;
1718 if (sizeString.cx > 0)
1719 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1720
1721 }
1722 else
1723 {
1724 if (bHasBitmap)
1725 {
1726 #ifdef __REACTOS__
1727 sizeButton.cy = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1728 #else
1729 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1730 #endif
1731 if (sizeString.cy > 0)
1732 sizeButton.cy += 1 + sizeString.cy;
1733 sizeButton.cx = infoPtr->szPadding.cx +
1734 max(sizeString.cx, infoPtr->nBitmapWidth);
1735 }
1736 else
1737 {
1738 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1739 NONLIST_NOTEXT_OFFSET;
1740 sizeButton.cx = infoPtr->szPadding.cx +
1741 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1742 }
1743 }
1744
1745 #ifdef __REACTOS__
1746 sizeButton.cx += infoPtr->themeMargins.cxLeftWidth + infoPtr->themeMargins.cxRightWidth;
1747 sizeButton.cy += infoPtr->themeMargins.cyTopHeight + infoPtr->themeMargins.cyBottomHeight;
1748 #endif
1749
1750 return sizeButton;
1751 }
1752
1753
1754 /***********************************************************************
1755 * TOOLBAR_CalcToolbar
1756 *
1757 * This function calculates button and separator placement. It first
1758 * calculates the button sizes, gets the toolbar window width and then
1759 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1760 * on. It assigns a new location to each item and sends this location to
1761 * the tooltip window if appropriate. Finally, it updates the rcBound
1762 * rect and calculates the new required toolbar window height.
1763 */
1764 static void
1765 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1766 {
1767 SIZE sizeString, sizeButton;
1768 BOOL validImageList = FALSE;
1769
1770 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1771
1772 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1773
1774 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1775 validImageList = TRUE;
1776 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1777 infoPtr->nButtonWidth = sizeButton.cx;
1778 infoPtr->nButtonHeight = sizeButton.cy;
1779 infoPtr->iTopMargin = default_top_margin(infoPtr);
1780
1781 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1782 infoPtr->nButtonWidth = infoPtr->cxMin;
1783 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1784 infoPtr->nButtonWidth = infoPtr->cxMax;
1785
1786 TOOLBAR_LayoutToolbar(infoPtr);
1787 }
1788
1789 static void
1790 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1791 {
1792 TBUTTON_INFO *btnPtr;
1793 SIZE sizeButton;
1794 INT i, nRows, nSepRows;
1795 INT x, y, cx, cy;
1796 BOOL bWrap;
1797 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1798
1799 TOOLBAR_WrapToolbar(infoPtr);
1800
1801 x = infoPtr->nIndent;
1802 y = infoPtr->iTopMargin;
1803 cx = infoPtr->nButtonWidth;
1804 cy = infoPtr->nButtonHeight;
1805
1806 nRows = nSepRows = 0;
1807
1808 infoPtr->rcBound.top = y;
1809 infoPtr->rcBound.left = x;
1810 infoPtr->rcBound.bottom = y + cy;
1811 infoPtr->rcBound.right = x;
1812
1813 btnPtr = infoPtr->buttons;
1814
1815 TRACE("cy=%d\n", cy);
1816
1817 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1818 {
1819 bWrap = FALSE;
1820 if (btnPtr->fsState & TBSTATE_HIDDEN)
1821 {
1822 SetRectEmpty (&btnPtr->rect);
1823 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1824 continue;
1825 }
1826
1827 cy = infoPtr->nButtonHeight;
1828
1829 if (btnPtr->fsStyle & BTNS_SEP) {
1830 if (infoPtr->dwStyle & CCS_VERT) {
1831 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1832 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nButtonWidth;
1833 }
1834 else
1835 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1836 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1837 }
1838 else
1839 {
1840 if (btnPtr->cx)
1841 cx = btnPtr->cx;
1842 #ifdef __REACTOS__
1843 /* Revert Wine Commit 5b7b911 as it breaks Explorer Toolbar Buttons
1844 FIXME: Revisit this when the bug is fixed. CORE-9970 */
1845 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1846 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1847 #else
1848 else if (btnPtr->fsStyle & BTNS_AUTOSIZE)
1849 #endif
1850 {
1851 SIZE sz;
1852 HDC hdc;
1853 HFONT hOldFont;
1854
1855 hdc = GetDC (infoPtr->hwndSelf);
1856 hOldFont = SelectObject (hdc, infoPtr->hFont);
1857
1858 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1859
1860 SelectObject (hdc, hOldFont);
1861 ReleaseDC (infoPtr->hwndSelf, hdc);
1862
1863 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1864 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1865 validImageList);
1866 cx = sizeButton.cx;
1867 }
1868 else
1869 cx = infoPtr->nButtonWidth;
1870
1871 /* if size has been set manually then don't add on extra space
1872 * for the drop down arrow */
1873 if (!btnPtr->cx && button_has_ddarrow( infoPtr, btnPtr ))
1874 cx += DDARROW_WIDTH;
1875 }
1876 if (btnPtr->fsState & TBSTATE_WRAP)
1877 bWrap = TRUE;
1878
1879 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1880
1881 if (infoPtr->rcBound.left > x)
1882 infoPtr->rcBound.left = x;
1883 if (infoPtr->rcBound.right < x + cx)
1884 infoPtr->rcBound.right = x + cx;
1885 if (infoPtr->rcBound.bottom < y + cy)
1886 infoPtr->rcBound.bottom = y + cy;
1887
1888 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1889
1890 /* btnPtr->nRow is zero based. The space between the rows is */
1891 /* also considered as a row. */
1892 btnPtr->nRow = nRows + nSepRows;
1893
1894 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1895 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1896 x, y, x+cx, y+cy);
1897
1898 if( bWrap )
1899 {
1900 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1901 #ifdef __REACTOS__
1902 y += cy + infoPtr->szSpacing.cy;
1903 #else
1904 y += cy;
1905 #endif
1906 else
1907 {
1908 if ( !(infoPtr->dwStyle & CCS_VERT))
1909 y += cy + ( (btnPtr->cx > 0 ) ?
1910 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1911 else
1912 #ifdef __REACTOS__
1913 y += cy + infoPtr->szSpacing.cy;
1914 #else
1915 y += cy;
1916 #endif
1917
1918 /* nSepRows is used to calculate the extra height following */
1919 /* the last row. */
1920 nSepRows++;
1921 }
1922 x = infoPtr->nIndent;
1923
1924 /* Increment row number unless this is the last button */
1925 /* and it has Wrap set. */
1926 if (i != infoPtr->nNumButtons-1)
1927 nRows++;
1928 }
1929 else
1930 #ifdef __REACTOS__
1931 x += cx + infoPtr->szSpacing.cx;
1932 #else
1933 x += cx;
1934 #endif
1935 }
1936
1937 /* infoPtr->nRows is the number of rows on the toolbar */
1938 infoPtr->nRows = nRows + nSepRows + 1;
1939
1940 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1941 }
1942
1943
1944 static INT
1945 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
1946 {
1947 TBUTTON_INFO *btnPtr;
1948 INT i;
1949
1950 if (button)
1951 *button = FALSE;
1952
1953 btnPtr = infoPtr->buttons;
1954 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1955 if (btnPtr->fsState & TBSTATE_HIDDEN)
1956 continue;
1957
1958 if (btnPtr->fsStyle & BTNS_SEP) {
1959 if (PtInRect (&btnPtr->rect, *lpPt)) {
1960 TRACE(" ON SEPARATOR %d\n", i);
1961 return -i;
1962 }
1963 }
1964 else {
1965 if (PtInRect (&btnPtr->rect, *lpPt)) {
1966 TRACE(" ON BUTTON %d\n", i);
1967 if (button)
1968 *button = TRUE;
1969 return i;
1970 }
1971 }
1972 }
1973
1974 TRACE(" NOWHERE\n");
1975 return TOOLBAR_NOWHERE;
1976 }
1977
1978
1979 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1980 static BOOL
1981 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1982 {
1983 INT nOldButtons, nNewButtons, iButton;
1984 BOOL fHasString = FALSE;
1985
1986 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1987 iIndex = infoPtr->nNumButtons;
1988
1989 nOldButtons = infoPtr->nNumButtons;
1990 nNewButtons = nOldButtons + nAddButtons;
1991
1992 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1993 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1994 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1995 infoPtr->nNumButtons += nAddButtons;
1996
1997 /* insert new buttons data */
1998 for (iButton = 0; iButton < nAddButtons; iButton++) {
1999 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
2000 INT_PTR str;
2001
2002 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
2003
2004 ZeroMemory(btnPtr, sizeof(*btnPtr));
2005
2006 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
2007 btnPtr->idCommand = lpTbb[iButton].idCommand;
2008 btnPtr->fsState = lpTbb[iButton].fsState;
2009 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
2010 btnPtr->dwData = lpTbb[iButton].dwData;
2011
2012 if (btnPtr->fsStyle & BTNS_SEP)
2013 str = -1;
2014 else
2015 str = lpTbb[iButton].iString;
2016 set_string_index( btnPtr, str, fUnicode );
2017 fHasString |= TOOLBAR_ButtonHasString( btnPtr );
2018
2019 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
2020 }
2021
2022 if (infoPtr->nNumStrings > 0 || fHasString)
2023 TOOLBAR_CalcToolbar(infoPtr);
2024 else
2025 TOOLBAR_LayoutToolbar(infoPtr);
2026 TOOLBAR_AutoSize(infoPtr);
2027
2028 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
2029 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2030 return TRUE;
2031 }
2032
2033
2034 static INT
2035 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
2036 {
2037 TBUTTON_INFO *btnPtr;
2038 INT i;
2039
2040 if (CommandIsIndex) {
2041 TRACE("command is really index command=%d\n", idCommand);
2042 if (idCommand >= infoPtr->nNumButtons) return -1;
2043 return idCommand;
2044 }
2045 btnPtr = infoPtr->buttons;
2046 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
2047 if (btnPtr->idCommand == idCommand) {
2048 TRACE("command=%d index=%d\n", idCommand, i);
2049 return i;
2050 }
2051 }
2052 TRACE("no index found for command=%d\n", idCommand);
2053 return -1;
2054 }
2055
2056
2057 static INT
2058 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
2059 {
2060 TBUTTON_INFO *btnPtr;
2061 INT nRunIndex;
2062
2063 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
2064 return -1;
2065
2066 /* check index button */
2067 btnPtr = &infoPtr->buttons[nIndex];
2068 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
2069 if (btnPtr->fsState & TBSTATE_CHECKED)
2070 return nIndex;
2071 }
2072
2073 /* check previous buttons */
2074 nRunIndex = nIndex - 1;
2075 while (nRunIndex >= 0) {
2076 btnPtr = &infoPtr->buttons[nRunIndex];
2077 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2078 if (btnPtr->fsState & TBSTATE_CHECKED)
2079 return nRunIndex;
2080 }
2081 else
2082 break;
2083 nRunIndex--;
2084 }
2085
2086 /* check next buttons */
2087 nRunIndex = nIndex + 1;
2088 while (nRunIndex < infoPtr->nNumButtons) {
2089 btnPtr = &infoPtr->buttons[nRunIndex];
2090 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2091 if (btnPtr->fsState & TBSTATE_CHECKED)
2092 return nRunIndex;
2093 }
2094 else
2095 break;
2096 nRunIndex++;
2097 }
2098
2099 return -1;
2100 }
2101
2102
2103 static VOID
2104 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
2105 WPARAM wParam, LPARAM lParam)
2106 {
2107 MSG msg;
2108
2109 msg.hwnd = hwndMsg;
2110 msg.message = uMsg;
2111 msg.wParam = wParam;
2112 msg.lParam = lParam;
2113 msg.time = GetMessageTime ();
2114 msg.pt.x = (short)LOWORD(GetMessagePos ());
2115 msg.pt.y = (short)HIWORD(GetMessagePos ());
2116
2117 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
2118 }
2119
2120 static void
2121 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2122 {
2123 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
2124 TTTOOLINFOW ti;
2125
2126 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
2127 ti.cbSize = sizeof (TTTOOLINFOW);
2128 ti.hwnd = infoPtr->hwndSelf;
2129 ti.uId = button->idCommand;
2130 ti.hinst = 0;
2131 ti.lpszText = LPSTR_TEXTCALLBACKW;
2132 /* ti.lParam = random value from the stack? */
2133
2134 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
2135 0, (LPARAM)&ti);
2136 }
2137 }
2138
2139 static void
2140 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2141 {
2142 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
2143 TTTOOLINFOW ti;
2144
2145 ZeroMemory(&ti, sizeof(ti));
2146 ti.cbSize = sizeof(ti);
2147 ti.hwnd = infoPtr->hwndSelf;
2148 ti.uId = button->idCommand;
2149
2150 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
2151 }
2152 }
2153
2154 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2155 {
2156 /* Set the toolTip only for non-hidden, non-separator button */
2157 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
2158 {
2159 TTTOOLINFOW ti;
2160
2161 ZeroMemory(&ti, sizeof(ti));
2162 ti.cbSize = sizeof(ti);
2163 ti.hwnd = infoPtr->hwndSelf;
2164 ti.uId = button->idCommand;
2165 ti.rect = button->rect;
2166 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2167 }
2168 }
2169
2170 /* Creates the tooltip control */
2171 static void
2172 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2173 {
2174 int i;
2175 NMTOOLTIPSCREATED nmttc;
2176
2177 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2178 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2179 infoPtr->hwndSelf, 0, 0, 0);
2180
2181 if (!infoPtr->hwndToolTip)
2182 return;
2183
2184 /* Send NM_TOOLTIPSCREATED notification */
2185 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2186 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2187
2188 for (i = 0; i < infoPtr->nNumButtons; i++)
2189 {
2190 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2191 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2192 }
2193 }
2194
2195 /* keeps available button list box sorted by button id */
2196 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2197 {
2198 int i;
2199 int count;
2200 PCUSTOMBUTTON btnInfo;
2201 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2202
2203 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2204
2205 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2206
2207 /* position 0 is always separator */
2208 for (i = 1; i < count; i++)
2209 {
2210 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2211 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2212 {
2213 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2214 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2215 return;
2216 }
2217 }
2218 /* id higher than all others add to end */
2219 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2220 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2221 }
2222
2223 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2224 {
2225 NMTOOLBARW nmtb;
2226
2227 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2228
2229 if (nIndexFrom == nIndexTo)
2230 return;
2231
2232 /* MSDN states that iItem is the index of the button, rather than the
2233 * command ID as used by every other NMTOOLBAR notification */
2234 nmtb.iItem = nIndexFrom;
2235 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2236 {
2237 PCUSTOMBUTTON btnInfo;
2238 NMHDR hdr;
2239 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2240 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2241
2242 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2243
2244 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2245 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2246 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2247 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2248
2249 if (nIndexTo <= 0)
2250 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2251 else
2252 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2253
2254 /* last item is always separator, so -2 instead of -1 */
2255 if (nIndexTo >= (count - 2))
2256 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2257 else
2258 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2259
2260 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2261 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2262
2263 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2264 }
2265 }
2266
2267 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2268 {
2269 NMTOOLBARW nmtb;
2270
2271 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2272
2273 /* MSDN states that iItem is the index of the button, rather than the
2274 * command ID as used by every other NMTOOLBAR notification */
2275 nmtb.iItem = nIndexAvail;
2276 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2277 {
2278 PCUSTOMBUTTON btnInfo;
2279 NMHDR hdr;
2280 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2281 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2282 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2283
2284 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2285
2286 if (nIndexAvail != 0) /* index == 0 indicates separator */
2287 {
2288 /* remove from 'available buttons' list */
2289 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2290 if (nIndexAvail == count-1)
2291 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2292 else
2293 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2294 }
2295 else
2296 {
2297 PCUSTOMBUTTON btnNew;
2298
2299 /* duplicate 'separator' button */
2300 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2301 *btnNew = *btnInfo;
2302 btnInfo = btnNew;
2303 }
2304
2305 /* insert into 'toolbar button' list */
2306 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2307 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2308
2309 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2310
2311 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2312 }
2313 }
2314
2315 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2316 {
2317 PCUSTOMBUTTON btnInfo;
2318 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2319
2320 TRACE("Remove: index %d\n", index);
2321
2322 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2323
2324 /* send TBN_QUERYDELETE notification */
2325 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2326 {
2327 NMHDR hdr;
2328
2329 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2330 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2331
2332 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2333
2334 /* insert into 'available button' list */
2335 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2336 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2337 else
2338 Free(btnInfo);
2339
2340 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2341 }
2342 }
2343
2344 /* drag list notification function for toolbar buttons list box */
2345 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2346 const DRAGLISTINFO *pDLI)
2347 {
2348 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2349 switch (pDLI->uNotification)
2350 {
2351 case DL_BEGINDRAG:
2352 {
2353 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2354 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2355 /* no dragging for last item (separator) */
2356 if (nCurrentItem >= (nCount - 1)) return FALSE;
2357 return TRUE;
2358 }
2359 case DL_DRAGGING:
2360 {
2361 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2362 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2363 /* no dragging past last item (separator) */
2364 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2365 {
2366 DrawInsert(hwnd, hwndList, nCurrentItem);
2367 /* FIXME: native uses "move button" cursor */
2368 return DL_COPYCURSOR;
2369 }
2370
2371 /* not over toolbar buttons list */
2372 if (nCurrentItem < 0)
2373 {
2374 POINT ptWindow = pDLI->ptCursor;
2375 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2376 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2377 /* over available buttons list? */
2378 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2379 /* FIXME: native uses "move button" cursor */
2380 return DL_COPYCURSOR;
2381 }
2382 /* clear drag arrow */
2383 DrawInsert(hwnd, hwndList, -1);
2384 return DL_STOPCURSOR;
2385 }
2386 case DL_DROPPED:
2387 {
2388 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2389 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2390 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2391 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2392 {
2393 /* clear drag arrow */
2394 DrawInsert(hwnd, hwndList, -1);
2395 /* move item */
2396 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2397 }
2398 /* not over toolbar buttons list */
2399 if (nIndexTo < 0)
2400 {
2401 POINT ptWindow = pDLI->ptCursor;
2402 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2403 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2404 /* over available buttons list? */
2405 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2406 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2407 }
2408 break;
2409 }
2410 case DL_CANCELDRAG:
2411 /* Clear drag arrow */
2412 DrawInsert(hwnd, hwndList, -1);
2413 break;
2414 }
2415
2416 return 0;
2417 }
2418
2419 /* drag list notification function for available buttons list box */
2420 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2421 const DRAGLISTINFO *pDLI)
2422 {
2423 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2424 switch (pDLI->uNotification)
2425 {
2426 case DL_BEGINDRAG:
2427 return TRUE;
2428 case DL_DRAGGING:
2429 {
2430 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2431 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2432 /* no dragging past last item (separator) */
2433 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2434 {
2435 DrawInsert(hwnd, hwndList, nCurrentItem);
2436 /* FIXME: native uses "move button" cursor */
2437 return DL_COPYCURSOR;
2438 }
2439
2440 /* not over toolbar buttons list */
2441 if (nCurrentItem < 0)
2442 {
2443 POINT ptWindow = pDLI->ptCursor;
2444 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2445 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2446 /* over available buttons list? */
2447 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2448 /* FIXME: native uses "move button" cursor */
2449 return DL_COPYCURSOR;
2450 }
2451 /* clear drag arrow */
2452 DrawInsert(hwnd, hwndList, -1);
2453 return DL_STOPCURSOR;
2454 }
2455 case DL_DROPPED:
2456 {
2457 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2458 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2459 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2460 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2461 {
2462 /* clear drag arrow */
2463 DrawInsert(hwnd, hwndList, -1);
2464 /* add item */
2465 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2466 }
2467 }
2468 case DL_CANCELDRAG:
2469 /* Clear drag arrow */
2470 DrawInsert(hwnd, hwndList, -1);
2471 break;
2472 }
2473 return 0;
2474 }
2475
2476 extern UINT uDragListMessage DECLSPEC_HIDDEN;
2477
2478 /***********************************************************************
2479 * TOOLBAR_CustomizeDialogProc
2480 * This function implements the toolbar customization dialog.
2481 */
2482 static INT_PTR CALLBACK
2483 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2484 {
2485 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2486 PCUSTOMBUTTON btnInfo;
2487 NMTOOLBARA nmtb;
2488 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2489
2490 switch (uMsg)
2491 {
2492 case WM_INITDIALOG:
2493 custInfo = (PCUSTDLG_INFO)lParam;
2494 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2495
2496 if (custInfo)
2497 {
2498 WCHAR Buffer[256];
2499 int i = 0;
2500 int index;
2501 NMTBINITCUSTOMIZE nmtbic;
2502
2503 infoPtr = custInfo->tbInfo;
2504
2505 /* send TBN_QUERYINSERT notification */
2506 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2507
2508 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2509 return FALSE;
2510
2511 nmtbic.hwndDialog = hwnd;
2512 /* Send TBN_INITCUSTOMIZE notification */
2513 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2514 TBNRF_HIDEHELP)
2515 {
2516 TRACE("TBNRF_HIDEHELP requested\n");
2517 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2518 }
2519
2520 /* add items to 'toolbar buttons' list and check if removable */
2521 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2522 {
2523 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2524 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2525 btnInfo->btn.fsStyle = BTNS_SEP;
2526 btnInfo->bVirtual = FALSE;
2527 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2528
2529 /* send TBN_QUERYDELETE notification */
2530 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2531
2532 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2533 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2534 }
2535
2536 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2537
2538 /* insert separator button into 'available buttons' list */
2539 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2540 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2541 btnInfo->btn.fsStyle = BTNS_SEP;
2542 btnInfo->bVirtual = FALSE;
2543 btnInfo->bRemovable = TRUE;
2544 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2545 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2546 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2547
2548 /* insert all buttons into dsa */
2549 for (i = 0;; i++)
2550 {
2551 /* send TBN_GETBUTTONINFO notification */
2552 NMTOOLBARW nmtb;
2553 nmtb.iItem = i;
2554 nmtb.pszText = Buffer;
2555 nmtb.cchText = 256;
2556
2557 /* Clear previous button's text */
2558 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2559
2560 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2561 break;
2562
2563 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2564 nmtb.tbButton.fsStyle, i,
2565 nmtb.tbButton.idCommand,
2566 nmtb.tbButton.iString,
2567 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2568 : "");
2569
2570 /* insert button into the appropriate list */
2571 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2572 if (index == -1)
2573 {
2574 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2575 btnInfo->bVirtual = FALSE;
2576 btnInfo->bRemovable = TRUE;
2577 }
2578 else
2579 {
2580 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2581 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2582 }
2583
2584 btnInfo->btn = nmtb.tbButton;
2585 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2586 {
2587 if (lstrlenW(nmtb.pszText))
2588 lstrcpyW(btnInfo->text, nmtb.pszText);
2589 else if (nmtb.tbButton.iString >= 0 &&
2590 nmtb.tbButton.iString < infoPtr->nNumStrings)
2591 {
2592 lstrcpyW(btnInfo->text,
2593 infoPtr->strings[nmtb.tbButton.iString]);
2594 }
2595 }
2596
2597 if (index == -1)
2598 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2599 }
2600
2601 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2602
2603 /* select first item in the 'available' list */
2604 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2605
2606 /* append 'virtual' separator button to the 'toolbar buttons' list */
2607 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2608 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2609 btnInfo->btn.fsStyle = BTNS_SEP;
2610 btnInfo->bVirtual = TRUE;
2611 btnInfo->bRemovable = FALSE;
2612 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2613 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2614 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2615
2616 /* select last item in the 'toolbar' list */
2617 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2618 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2619
2620 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2621 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2622
2623 /* set focus and disable buttons */
2624 PostMessageW (hwnd, WM_USER, 0, 0);
2625 }
2626 return TRUE;
2627
2628 case WM_USER:
2629 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2630 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2631 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2632 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2633 return TRUE;
2634
2635 case WM_CLOSE:
2636 EndDialog(hwnd, FALSE);
2637 return TRUE;
2638
2639 case WM_COMMAND:
2640 switch (LOWORD(wParam))
2641 {
2642 case IDC_TOOLBARBTN_LBOX:
2643 if (HIWORD(wParam) == LBN_SELCHANGE)
2644 {
2645 PCUSTOMBUTTON btnInfo;
2646 NMTOOLBARA nmtb;
2647 int count;
2648 int index;
2649
2650 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2651 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2652
2653 /* send TBN_QUERYINSERT notification */
2654 nmtb.iItem = index;
2655 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2656
2657 /* get list box item */
2658 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2659
2660 if (index == (count - 1))
2661 {
2662 /* last item (virtual separator) */
2663 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2664 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2665 }
2666 else if (index == (count - 2))
2667 {
2668 /* second last item (last non-virtual item) */
2669 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2670 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2671 }
2672 else if (index == 0)
2673 {
2674 /* first item */
2675 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2676 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2677 }
2678 else
2679 {
2680 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2681 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2682 }
2683
2684 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2685 }
2686 break;
2687
2688 case IDC_MOVEUP_BTN:
2689 {
2690 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2691 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2692 }
2693 break;
2694
2695 case IDC_MOVEDN_BTN: /* move down */
2696 {
2697 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2698 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2699 }
2700 break;
2701
2702 case IDC_REMOVE_BTN: /* remove button */
2703 {
2704 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2705
2706 if (LB_ERR == index)
2707 break;
2708
2709 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2710 }
2711 break;
2712 case IDC_HELP_BTN:
2713 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2714 break;
2715 case IDC_RESET_BTN:
2716 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2717 break;
2718
2719 case IDOK: /* Add button */
2720 {
2721 int index;
2722 int indexto;
2723
2724 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2725 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2726
2727 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2728 }
2729 break;
2730
2731 case IDCANCEL:
2732 EndDialog(hwnd, FALSE);
2733 break;
2734 }
2735 return TRUE;
2736
2737 case WM_DESTROY:
2738 {
2739 int count;
2740 int i;
2741
2742 /* delete items from 'toolbar buttons' listbox*/
2743 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2744 for (i = 0; i < count; i++)
2745 {
2746 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2747 Free(btnInfo);
2748 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2749 }
2750 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2751
2752
2753 /* delete items from 'available buttons' listbox*/
2754 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2755 for (i = 0; i < count; i++)
2756 {
2757 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2758 Free(btnInfo);
2759 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2760 }
2761 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2762 }
2763 return TRUE;
2764
2765 case WM_DRAWITEM:
2766 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2767 {
2768 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2769 RECT rcButton;
2770 RECT rcText;
2771 HPEN hPen, hOldPen;
2772 HBRUSH hOldBrush;
2773 COLORREF oldText = 0;
2774 COLORREF oldBk = 0;
2775
2776 /* get item data */
2777 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, lpdis->itemID, 0);
2778 if (btnInfo == NULL)
2779 {
2780 FIXME("btnInfo invalid\n");
2781 return TRUE;
2782 }
2783
2784 /* set colors and select objects */
2785 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2786 if (btnInfo->bVirtual)
2787 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2788 else
2789 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2790 hPen = CreatePen( PS_SOLID, 1,
2791 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2792 hOldPen = SelectObject (lpdis->hDC, hPen );
2793 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2794
2795 /* fill background rectangle */
2796 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2797 lpdis->rcItem.right, lpdis->rcItem.bottom);
2798
2799 /* calculate button and text rectangles */
2800 rcButton = lpdis->rcItem;
2801 InflateRect (&rcButton, -1, -1);
2802 rcText = rcButton;
2803 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2804 rcText.left = rcButton.right + 2;
2805
2806 /* draw focus rectangle */
2807 if (lpdis->itemState & ODS_FOCUS)
2808 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2809
2810 /* draw button */
2811 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2812 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2813
2814 /* draw image and text */
2815 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2816 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2817 btnInfo->btn.iBitmap));
2818 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2819 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2820 }
2821 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2822 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2823
2824 /* delete objects and reset colors */
2825 SelectObject (lpdis->hDC, hOldBrush);
2826 SelectObject (lpdis->hDC, hOldPen);
2827 SetBkColor (lpdis->hDC, oldBk);
2828 SetTextColor (lpdis->hDC, oldText);
2829 DeleteObject( hPen );
2830 return TRUE;
2831 }
2832 return FALSE;
2833
2834 case WM_MEASUREITEM:
2835 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2836 {
2837 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2838
2839 lpmis->itemHeight = 15 + 8; /* default height */
2840
2841 return TRUE;
2842 }
2843 return FALSE;
2844
2845 default:
2846 if (uDragListMessage && (uMsg == uDragListMessage))
2847 {
2848 if (wParam == IDC_TOOLBARBTN_LBOX)
2849 {
2850 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2851 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2852 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2853 return TRUE;
2854 }
2855 else if (wParam == IDC_AVAILBTN_LBOX)
2856 {
2857 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2858 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2859 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2860 return TRUE;
2861 }
2862 }
2863 return FALSE;
2864 }
2865 }
2866
2867 static BOOL
2868 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2869 {
2870 HBITMAP hbmLoad;
2871 INT nCountBefore = ImageList_GetImageCount(himlDef);
2872 INT nCountAfter;
2873 INT cxIcon, cyIcon;
2874 INT nAdded;
2875 INT nIndex;
2876
2877 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2878 /* Add bitmaps to the default image list */
2879 if (bitmap->hInst == NULL) /* a handle was passed */
2880 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2881 else if (bitmap->hInst == COMCTL32_hModule)
2882 hbmLoad = LoadImageW( bitmap->hInst, MAKEINTRESOURCEW(bitmap->nID),
2883 IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
2884 else
2885 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2886
2887 /* enlarge the bitmap if needed */
2888 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2889 if (bitmap->hInst != COMCTL32_hModule)
2890 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2891
2892 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2893 DeleteObject(hbmLoad);
2894 if (nIndex == -1)
2895 return FALSE;
2896
2897 nCountAfter = ImageList_GetImageCount(himlDef);
2898 nAdded = nCountAfter - nCountBefore;
2899 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2900 {
2901 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2902 } else if (nAdded > (INT)bitmap->nButtons) {
2903 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2904 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2905 }
2906
2907 infoPtr->nNumBitmaps += nAdded;
2908 return TRUE;
2909 }
2910
2911 static void
2912 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2913 {
2914 HIMAGELIST himlDef;
2915 HIMAGELIST himlNew;
2916 INT cx, cy;
2917 INT i;
2918
2919 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2920 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2921 return;
2922 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2923 return;
2924 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2925 return;
2926
2927 TRACE("Update icon size: %dx%d -> %dx%d\n",
2928 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2929
2930 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2931 ILC_COLOR32|ILC_MASK, 8, 2);
2932 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2933 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2934 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2935 infoPtr->himlInt = himlNew;
2936
2937 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2938 ImageList_Destroy(himlDef);
2939 }
2940
2941 /***********************************************************************
2942 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2943 *
2944 */
2945 static LRESULT
2946 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2947 {
2948 TBITMAP_INFO info;
2949 INT iSumButtons, i;
2950 HIMAGELIST himlDef;
2951
2952 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2953 if (!lpAddBmp)
2954 return -1;
2955
2956 if (lpAddBmp->hInst == HINST_COMMCTRL)
2957 {
2958 info.hInst = COMCTL32_hModule;
2959 switch (lpAddBmp->nID)
2960 {
2961 case IDB_STD_SMALL_COLOR:
2962 case 2:
2963 info.nButtons = 15;
2964 info.nID = IDB_STD_SMALL;
2965 break;
2966 case IDB_STD_LARGE_COLOR:
2967 case 3:
2968 info.nButtons = 15;
2969 info.nID = IDB_STD_LARGE;
2970 break;
2971 case IDB_VIEW_SMALL_COLOR:
2972 case 6:
2973 info.nButtons = 12;
2974 info.nID = IDB_VIEW_SMALL;
2975 break;
2976 case IDB_VIEW_LARGE_COLOR:
2977 case 7:
2978 info.nButtons = 12;
2979 info.nID = IDB_VIEW_LARGE;
2980 break;
2981 case IDB_HIST_SMALL_COLOR:
2982 info.nButtons = 5;
2983 info.nID = IDB_HIST_SMALL;
2984 break;
2985 case IDB_HIST_LARGE_COLOR:
2986 info.nButtons = 5;
2987 info.nID = IDB_HIST_LARGE;
2988 break;
2989 default:
2990 WARN("unknown bitmap id, %ld\n", lpAddBmp->nID);
2991 return -1;
2992 }
2993
2994 TRACE ("adding %d internal bitmaps\n", info.nButtons);
2995
2996 /* Windows resize all the buttons to the size of a newly added standard image */
2997 if (lpAddBmp->nID & 1)
2998 {
2999 /* large icons: 24x24. Will make the button 31x30 */
3000 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
3001 }
3002 else
3003 {
3004 /* small icons: 16x16. Will make the buttons 23x22 */
3005 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
3006 }
3007
3008 TOOLBAR_CalcToolbar (infoPtr);
3009 }
3010 else
3011 {
3012 info.nButtons = count;
3013 info.hInst = lpAddBmp->hInst;
3014 info.nID = lpAddBmp->nID;
3015 TRACE("adding %d bitmaps\n", info.nButtons);
3016 }
3017
3018 /* check if the bitmap is already loaded and compute iSumButtons */
3019 iSumButtons = 0;
3020 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
3021 {
3022 if (infoPtr->bitmaps[i].hInst == info.hInst &&
3023 infoPtr->bitmaps[i].nID == info.nID)
3024 return iSumButtons;
3025 iSumButtons += infoPtr->bitmaps[i].nButtons;
3026 }
3027
3028 if (!infoPtr->cimlDef) {
3029 /* create new default image list */
3030 TRACE ("creating default image list\n");
3031
3032 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
3033 ILC_COLOR32 | ILC_MASK, info.nButtons, 2);
3034 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
3035 infoPtr->himlInt = himlDef;
3036 }
3037 else {
3038 himlDef = GETDEFIMAGELIST(infoPtr, 0);
3039 }
3040
3041 if (!himlDef) {
3042 WARN("No default image list available\n");
3043 return -1;
3044 }
3045
3046 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
3047 return -1;
3048
3049 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
3050 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
3051 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
3052 infoPtr->nNumBitmapInfos++;
3053 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
3054
3055 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3056 return iSumButtons;
3057 }
3058
3059
3060 static LRESULT
3061 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
3062 {
3063 TRACE("adding %d buttons (unicode=%d)\n", nAddButtons, fUnicode);
3064
3065 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
3066 }
3067
3068
3069 static LRESULT
3070 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
3071 {
3072 #define MAX_RESOURCE_STRING_LENGTH 512
3073 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3074 INT nIndex = infoPtr->nNumStrings;
3075
3076 TRACE("%p, %lx\n", hInstance, lParam);
3077
3078 if (IS_INTRESOURCE(lParam)) {
3079 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3080 WCHAR delimiter;
3081 WCHAR *next_delim;
3082 HRSRC hrsrc;
3083 WCHAR *p;
3084 INT len;
3085
3086 TRACE("adding string from resource\n");
3087
3088 if (!hInstance) return -1;
3089
3090 hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
3091 (LPWSTR)RT_STRING );
3092 if (!hrsrc)
3093 {
3094 TRACE("string not found in resources\n");
3095 return -1;
3096 }
3097
3098 len = LoadStringW (hInstance, (UINT)lParam,
3099 szString, MAX_RESOURCE_STRING_LENGTH);
3100
3101 TRACE("len=%d %s\n", len, debugstr_w(szString));
3102 if (len == 0 || len == 1)
3103 return nIndex;
3104
3105 TRACE("delimiter: 0x%x\n", *szString);
3106 delimiter = *szString;
3107 p = szString + 1;
3108
3109 while ((next_delim = strchrW(p, delimiter)) != NULL) {
3110 *next_delim = 0;
3111 if (next_delim + 1 >= szString + len)
3112 {
3113 /* this may happen if delimiter == '\0' or if the last char is a
3114 * delimiter (then it is ignored like the native does) */
3115 break;
3116 }
3117
3118 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3119 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
3120 infoPtr->nNumStrings++;
3121
3122 p = next_delim + 1;
3123 }
3124 }
3125 else {
3126 LPWSTR p = (LPWSTR)lParam;
3127 INT len;
3128
3129 if (p == NULL)
3130 return -1;
3131 TRACE("adding string(s) from array\n");
3132 while (*p) {
3133 len = strlenW (p);
3134
3135 TRACE("len=%d %s\n", len, debugstr_w(p));
3136 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3137 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3138 infoPtr->nNumStrings++;
3139
3140 p += (len+1);
3141 }
3142 }
3143
3144 if (fFirstString)
3145 TOOLBAR_CalcToolbar(infoPtr);
3146 return nIndex;
3147 }
3148
3149
3150 static LRESULT
3151 TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
3152 {
3153 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3154 LPSTR p;
3155 INT nIndex;
3156 INT len;
3157
3158 TRACE("%p, %lx\n", hInstance, lParam);
3159
3160 if (IS_INTRESOURCE(lParam)) /* load from resources */
3161 return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
3162
3163 p = (LPSTR)lParam;
3164 if (p == NULL)
3165 return -1;
3166
3167 TRACE("adding string(s) from array\n");
3168 nIndex = infoPtr->nNumStrings;
3169 while (*p) {
3170 len = strlen (p);
3171 TRACE("len=%d \"%s\"\n", len, p);
3172
3173 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3174 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3175 infoPtr->nNumStrings++;
3176
3177 p += (len+1);
3178 }
3179
3180 if (fFirstString)
3181 TOOLBAR_CalcToolbar(infoPtr);
3182 return nIndex;
3183 }
3184
3185
3186 static LRESULT
3187 TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
3188 {
3189 TRACE("auto sizing, style=%#x\n", infoPtr->dwStyle);
3190 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3191
3192 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3193 {
3194 RECT window_rect, parent_rect;
3195 UINT uPosFlags = SWP_NOZORDER | SWP_NOACTIVATE;
3196 HWND parent;
3197 INT x, y, cx, cy;
3198
3199 parent = GetParent (infoPtr->hwndSelf);
3200
3201 if (!parent || !infoPtr->bDoRedraw)
3202 return 0;
3203
3204 GetClientRect(parent, &parent_rect);
3205
3206 x = parent_rect.left;
3207 y = parent_rect.top;
3208
3209 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3210 cx = parent_rect.right - parent_rect.left;
3211
3212 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3213 {
3214 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3215 MapWindowPoints( 0, parent, (POINT *)&window_rect, 2 );
3216 y = window_rect.top;
3217 }
3218 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3219 {
3220 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3221 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3222 }
3223
3224 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3225 uPosFlags |= SWP_NOMOVE;
3226
3227 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3228 cy += GetSystemMetrics(SM_CYEDGE);
3229
3230 if (infoPtr->dwStyle & WS_BORDER)
3231 {
3232 cx += 2 * GetSystemMetrics(SM_CXBORDER);
3233 cy += 2 * GetSystemMetrics(SM_CYBORDER);
3234 }
3235
3236 SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
3237 }
3238
3239 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL))
3240 {
3241 TOOLBAR_LayoutToolbar(infoPtr);
3242 InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
3243 }
3244
3245 return 0;
3246 }
3247
3248
3249 static inline LRESULT
3250 TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
3251 {
3252 return infoPtr->nNumButtons;
3253 }
3254
3255
3256 static inline LRESULT
3257 TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
3258 {
3259 infoPtr->dwStructSize = Size;
3260
3261 return 0;
3262 }
3263
3264
3265 static LRESULT
3266 TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
3267 {
3268 TBUTTON_INFO *btnPtr;
3269 INT nIndex;
3270
3271 TRACE("button %d, iBitmap now %d\n", Id, Index);
3272
3273 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3274 if (nIndex == -1)
3275 return FALSE;
3276
3277 btnPtr = &infoPtr->buttons[nIndex];
3278 btnPtr->iBitmap = Index;
3279
3280 /* we HAVE to erase the background, the new bitmap could be */
3281 /* transparent */
3282 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3283
3284 return TRUE;
3285 }
3286
3287
3288 static LRESULT
3289 TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3290 {
3291 TBUTTON_INFO *btnPtr;
3292 INT nIndex;
3293 INT nOldIndex = -1;
3294 BOOL bChecked = FALSE;
3295
3296 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3297
3298 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
3299
3300 if (nIndex == -1)
3301 return FALSE;
3302
3303 btnPtr = &infoPtr->buttons[nIndex];
3304
3305 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) != 0;
3306
3307 if (!LOWORD(lParam))
3308 btnPtr->fsState &= ~TBSTATE_CHECKED;
3309 else {
3310 if (btnPtr->fsStyle & BTNS_GROUP) {
3311 nOldIndex =
3312 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3313 if (nOldIndex == nIndex)
3314 return 0;
3315 if (nOldIndex != -1)
3316 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3317 }
3318 btnPtr->fsState |= TBSTATE_CHECKED;
3319 }
3320
3321 if( bChecked != LOWORD(lParam) )
3322 {
3323 if (nOldIndex != -1)
3324 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
3325 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3326 }
3327
3328 /* FIXME: Send a WM_NOTIFY?? */
3329
3330 return TRUE;
3331 }
3332
3333
3334 static LRESULT
3335 TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
3336 {
3337 return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3338 }
3339
3340
3341 static LRESULT
3342 TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
3343 {
3344 CUSTDLG_INFO custInfo;
3345 LRESULT ret;
3346 NMHDR nmhdr;
3347
3348 custInfo.tbInfo = infoPtr;
3349 custInfo.tbHwnd = infoPtr->hwndSelf;
3350
3351 /* send TBN_BEGINADJUST notification */
3352 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3353
3354 ret = DialogBoxParamW (COMCTL32_hModule, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3355 infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc, (LPARAM)&custInfo);
3356
3357 /* send TBN_ENDADJUST notification */
3358 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3359
3360 return ret;
3361 }
3362
3363
3364 static LRESULT
3365 TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
3366 {
3367 NMTOOLBARW nmtb;
3368 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3369
3370 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3371 return FALSE;
3372
3373 memset(&nmtb, 0, sizeof(nmtb));
3374 nmtb.iItem = btnPtr->idCommand;
3375 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3376 nmtb.tbButton.idCommand = btnPtr->idCommand;
3377 nmtb.tbButton.fsState = btnPtr->fsState;
3378 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3379 nmtb.tbButton.dwData = btnPtr->dwData;
3380 nmtb.tbButton.iString = btnPtr->iString;
3381 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3382
3383 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3384
3385 if (infoPtr->nNumButtons == 1) {
3386 TRACE(" simple delete\n");
3387 free_string( infoPtr->buttons );
3388 Free (infoPtr->buttons);
3389 infoPtr->buttons = NULL;
3390 infoPtr->nNumButtons = 0;
3391 }
3392 else {
3393 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3394 TRACE("complex delete [nIndex=%d]\n", nIndex);
3395
3396 infoPtr->nNumButtons--;
3397 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3398 if (nIndex > 0) {
3399 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3400 nIndex * sizeof(TBUTTON_INFO));
3401 }
3402
3403 if (nIndex < infoPtr->nNumButtons) {
3404 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3405 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3406 }
3407
3408 free_string( oldButtons + nIndex );
3409 Free (oldButtons);
3410 }
3411
3412 TOOLBAR_LayoutToolbar(infoPtr);
3413
3414 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3415
3416 return TRUE;
3417 }
3418
3419
3420 static LRESULT
3421 TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3422 {
3423 TBUTTON_INFO *btnPtr;
3424 INT nIndex;
3425 DWORD bState;
3426
3427 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3428
3429 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
3430
3431 if (nIndex == -1)
3432 return FALSE;
3433
3434 btnPtr = &infoPtr->buttons[nIndex];
3435
3436 bState = btnPtr->fsState & TBSTATE_ENABLED;
3437
3438 /* update the toolbar button state */
3439 if(!LOWORD(lParam)) {
3440 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3441 } else {
3442 btnPtr->fsState |= TBSTATE_ENABLED;
3443 }
3444
3445 /* redraw the button only if the state of the button changed */
3446 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3447 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3448
3449 return TRUE;
3450 }
3451
3452
3453 static inline LRESULT
3454 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
3455 {
3456 return infoPtr->bAnchor;
3457 }
3458
3459
3460 static LRESULT
3461 TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
3462 {
3463 INT nIndex;
3464
3465 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3466 if (nIndex == -1)
3467 return -1;
3468
3469 return infoPtr->buttons[nIndex].iBitmap;
3470 }
3471
3472
3473 static inline LRESULT
3474 TOOLBAR_GetBitmapFlags (void)
3475 {
3476 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3477 }
3478
3479
3480 static LRESULT
3481 TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
3482 {
3483 TBUTTON_INFO *btnPtr;
3484
3485 if (lpTbb == NULL)
3486 return FALSE;
3487
3488 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3489 return FALSE;
3490
3491 btnPtr = &infoPtr->buttons[nIndex];
3492 lpTbb->iBitmap = btnPtr->iBitmap;
3493 lpTbb->idCommand = btnPtr->idCommand;
3494 lpTbb->fsState = btnPtr->fsState;
3495 lpTbb->fsStyle = btnPtr->fsStyle;
3496 lpTbb->bReserved[0] = 0;
3497 lpTbb->bReserved[1] = 0;
3498 lpTbb->dwData = btnPtr->dwData;
3499 lpTbb->iString = btnPtr->iString;
3500
3501 return TRUE;
3502 }
3503
3504
3505 static LRESULT
3506 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
3507 {
3508 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3509 TBUTTON_INFO *btnPtr;
3510 INT nIndex;
3511
3512 if (lpTbInfo == NULL)
3513 return -1;
3514
3515 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3516 * the headers and tests shows that even with comctl 6 Vista accepts only the
3517 * original TBBUTTONINFO size
3518 */
3519 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3520 {
3521 WARN("Invalid button size\n");
3522 return -1;
3523 }
3524
3525 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
3526 if (nIndex == -1)
3527 return -1;
3528
3529 btnPtr = &infoPtr->buttons[nIndex];
3530 if (lpTbInfo->dwMask & TBIF_COMMAND)
3531 lpTbInfo->idCommand = btnPtr->idCommand;
3532 if (lpTbInfo->dwMask & TBIF_IMAGE)
3533 lpTbInfo->iImage = btnPtr->iBitmap;
3534 if (lpTbInfo->dwMask & TBIF_LPARAM)
3535 lpTbInfo->lParam = btnPtr->dwData;
3536 if (lpTbInfo->dwMask & TBIF_SIZE)
3537 /* tests show that for separators TBIF_SIZE returns not calculated width,
3538 but cx property, that differs from 0 only if application have
3539 specifically set it */
3540 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3541 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3542 if (lpTbInfo->dwMask & TBIF_STATE)
3543 lpTbInfo->fsState = btnPtr->fsState;
3544 if (lpTbInfo->dwMask & TBIF_STYLE)
3545 lpTbInfo->fsStyle = btnPtr->fsStyle;
3546 if (lpTbInfo->dwMask & TBIF_TEXT) {
3547 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3548 can't use TOOLBAR_GetText here */
3549 if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1)) {
3550 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3551 if (bUnicode)
3552 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3553 else
3554 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3555 } else if (!bUnicode || lpTbInfo->pszText)
3556 lpTbInfo->pszText[0] = '\0';
3557 }
3558 return nIndex;
3559 }
3560
3561
3562 static inline LRESULT
3563 TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
3564 {
3565 return MAKELONG((WORD)infoPtr->nButtonWidth,
3566 (WORD)infoPtr->nButtonHeight);
3567 }
3568
3569
3570 static LRESULT
3571 TOOLBAR_GetButtonText (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr, BOOL isW)
3572 {
3573 INT nIndex;
3574 LPWSTR lpText;
3575 LRESULT ret = 0;
3576
3577 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3578 if (nIndex == -1)
3579 return -1;
3580
3581 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3582
3583 if (isW)
3584 {
3585 if (lpText)
3586 {
3587 ret = strlenW (lpText);
3588 if (lpStr) strcpyW (lpStr, lpText);
3589 }
3590 }
3591 else
3592 ret = WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3593 (LPSTR)lpStr, lpStr ? 0x7fffffff : 0, NULL, NULL ) - 1;
3594 return ret;
3595 }
3596
3597
3598 static LRESULT
3599 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3600 {
3601 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3602 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3603 return (LRESULT)GETDISIMAGELIST(infoPtr, wParam);
3604 }
3605
3606
3607 static inline LRESULT
3608 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO *infoPtr)
3609 {
3610 TRACE("\n");
3611
3612 return infoPtr->dwExStyle;