[COMCTL32] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / 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 #endif
130 INT iTopMargin; /* the top margin */
131 INT iListGap; /* default gap between text and image for toolbar with list style */
132 HFONT hDefaultFont;
133 HFONT hFont; /* text font */
134 HIMAGELIST himlInt; /* image list created internally */
135 PIMLENTRY *himlDef; /* default image list array */
136 INT cimlDef; /* default image list array count */
137 PIMLENTRY *himlHot; /* hot image list array */
138 INT cimlHot; /* hot image list array count */
139 PIMLENTRY *himlDis; /* disabled image list array */
140 INT cimlDis; /* disabled image list array count */
141 HWND hwndToolTip; /* handle to tool tip control */
142 HWND hwndNotify; /* handle to the window that gets notifications */
143 HWND hwndSelf; /* my own handle */
144 BOOL bAnchor; /* anchor highlight enabled */
145 BOOL bDoRedraw; /* Redraw status */
146 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
147 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
148 BOOL bCaptured; /* mouse captured? */
149 DWORD dwStyle; /* regular toolbar style */
150 DWORD dwExStyle; /* extended toolbar style */
151 DWORD dwDTFlags; /* DrawText flags */
152
153 COLORREF clrInsertMark; /* insert mark color */
154 COLORREF clrBtnHighlight; /* color for Flat Separator */
155 COLORREF clrBtnShadow; /* color for Flag Separator */
156 INT iVersion;
157 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
158 * for TTN_GETDISPINFOW notification */
159 TBINSERTMARK tbim; /* info on insertion mark */
160 TBUTTON_INFO *buttons; /* pointer to button array */
161 LPWSTR *strings; /* pointer to string array */
162 TBITMAP_INFO *bitmaps;
163 } TOOLBAR_INFO, *PTOOLBAR_INFO;
164
165
166 /* used by customization dialog */
167 typedef struct
168 {
169 PTOOLBAR_INFO tbInfo;
170 HWND tbHwnd;
171 } CUSTDLG_INFO, *PCUSTDLG_INFO;
172
173 typedef struct
174 {
175 TBBUTTON btn;
176 BOOL bVirtual;
177 BOOL bRemovable;
178 WCHAR text[64];
179 } CUSTOMBUTTON, *PCUSTOMBUTTON;
180
181 typedef enum
182 {
183 IMAGE_LIST_DEFAULT,
184 IMAGE_LIST_HOT,
185 IMAGE_LIST_DISABLED
186 } IMAGE_LIST_TYPE;
187
188 #define SEPARATOR_WIDTH 8
189 #define TOP_BORDER 2
190 #define BOTTOM_BORDER 2
191 #define DDARROW_WIDTH 11
192 #define ARROW_HEIGHT 3
193 #define INSERTMARK_WIDTH 2
194
195 /* default padding inside a button */
196 #define DEFPAD_CX 7
197 #define DEFPAD_CY 6
198
199 #ifdef __REACTOS__
200 /* default space between buttons and between rows */
201 #define DEFSPACE_CX 7
202 #define DEFSPACE_CY 6
203 #endif
204
205 #define DEFLISTGAP 4
206
207 /* vertical padding used in list mode when image is present */
208 #ifdef __REACTOS__
209 #define LISTPAD_CY 2
210 #else
211 #define LISTPAD_CY 9
212 #endif
213
214 /* how wide to treat the bitmap if it isn't present */
215 #define NONLIST_NOTEXT_OFFSET 2
216
217 #define TOOLBAR_NOWHERE (-1)
218
219 /* Used to find undocumented extended styles */
220 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
221 TBSTYLE_EX_VERTICAL | \
222 TBSTYLE_EX_MIXEDBUTTONS | \
223 TBSTYLE_EX_DOUBLEBUFFER | \
224 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
225
226 /* all of the CCS_ styles */
227 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
228 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
229
230 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
231 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
232 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
233 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
234 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
235
236 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
237
238 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
239 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
240 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
241 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
242 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
243 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
244 static LRESULT TOOLBAR_LButtonDown(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
245 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
246 static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
247 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
248 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
249 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
250 static LRESULT TOOLBAR_SetButtonInfo(TOOLBAR_INFO *infoPtr, INT Id,
251 const TBBUTTONINFOW *lptbbi, BOOL isW);
252
253
254 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
255 {
256 #ifndef __REACTOS__
257 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
258 #else /* r65766 */
259 /* This is the behaviour in comctl32 v6 */
260 return 0;
261 #endif
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
621 /* draw text */
622 if (lpText && infoPtr->nMaxTextRows > 0) {
623 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
624 wine_dbgstr_rect(rcText));
625
626 hOldFont = SelectObject (hdc, infoPtr->hFont);
627 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
628 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
629 }
630 else if (state & CDIS_DISABLED) {
631 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
632 OffsetRect (rcText, 1, 1);
633 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
634 SetTextColor (hdc, comctl32_color.clr3dShadow);
635 OffsetRect (rcText, -1, -1);
636 }
637 else if (state & CDIS_INDETERMINATE) {
638 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
639 }
640 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
641 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
642 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
643 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
644 }
645 else {
646 clrOld = SetTextColor (hdc, tbcd->clrText);
647 }
648
649 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
650 SetTextColor (hdc, clrOld);
651 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
652 {
653 SetBkColor (hdc, clrOldBk);
654 SetBkMode (hdc, oldBkMode);
655 }
656 SelectObject (hdc, hOldFont);
657 }
658 }
659
660
661 static void
662 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
663 {
664 HDC hdc = tbcd->nmcd.hdc;
665 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
666 COLORREF clrTextOld;
667 COLORREF clrBkOld;
668 INT cx = lpRect->right - lpRect->left;
669 INT cy = lpRect->bottom - lpRect->top;
670 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
671 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
672 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
673 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
674 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
675 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
676 SetBkColor(hdc, clrBkOld);
677 SetTextColor(hdc, clrTextOld);
678 SelectObject (hdc, hbr);
679 }
680
681
682 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
683 {
684 INT cx, cy;
685 HBITMAP hbmMask, hbmImage;
686 HDC hdcMask, hdcImage;
687
688 ImageList_GetIconSize(himl, &cx, &cy);
689
690 /* Create src image */
691 hdcImage = CreateCompatibleDC(hdc);
692 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
693 SelectObject(hdcImage, hbmImage);
694 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
695 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
696
697 /* Create Mask */
698 hdcMask = CreateCompatibleDC(0);
699 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
700 SelectObject(hdcMask, hbmMask);
701
702 /* Remove the background and all white pixels */
703 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
704 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
705 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
706 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
707
708 /* draw the new mask 'etched' to hdc */
709 SetBkColor(hdc, RGB(255, 255, 255));
710 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
711 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
712 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
713 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
714 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
715
716 /* Cleanup */
717 DeleteObject(hbmImage);
718 DeleteDC(hdcImage);
719 DeleteObject (hbmMask);
720 DeleteDC(hdcMask);
721 }
722
723
724 static UINT
725 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
726 {
727 UINT retstate = 0;
728
729 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
730 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
731 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
732 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
733 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
734 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
735 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
736 return retstate;
737 }
738
739 /* draws the image on a toolbar button */
740 static void
741 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
742 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
743 {
744 HIMAGELIST himl = NULL;
745 BOOL draw_masked = FALSE, draw_desaturated = FALSE;
746 INT index;
747 INT offset = 0;
748 UINT draw_flags = ILD_TRANSPARENT;
749 #ifdef __REACTOS__
750 IMAGEINFO info = {0};
751 BITMAP bm = {0};
752 #endif
753
754 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
755 {
756 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
757 if (!himl)
758 {
759 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
760
761 #ifdef __REACTOS__
762 ImageList_GetImageInfo(himl, index, &info);
763 GetObjectW(info.hbmImage, sizeof(bm), &bm);
764
765 if (bm.bmBitsPixel == 32)
766 {
767 draw_desaturated = TRUE;
768 }
769 else
770 {
771 draw_masked = TRUE;
772 }
773 #else
774 draw_masked = TRUE;
775 #endif
776 }
777 }
778 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
779 ((tbcd->nmcd.uItemState & CDIS_HOT)
780 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
781 {
782 /* if hot, attempt to draw with hot image list, if fails,
783 use default image list */
784 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
785 if (!himl)
786 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
787 }
788 else
789 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
790
791 if (!himl)
792 return;
793
794 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
795 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
796 offset = 1;
797
798 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
799 (tbcd->nmcd.uItemState & CDIS_MARKED))
800 draw_flags |= ILD_BLEND50;
801
802 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
803 index, himl, left, top, offset);
804
805 if (draw_masked)
806 {
807 /* code path for drawing flat disabled icons without alpha channel */
808 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
809 }
810 else if (draw_desaturated)
811 {
812 /* code path for drawing disabled, alpha-blended (32bpp) icons */
813 IMAGELISTDRAWPARAMS imldp = {0};
814
815 imldp.cbSize = sizeof(imldp);
816 imldp.himl = himl;
817 imldp.i = index;
818 imldp.hdcDst = tbcd->nmcd.hdc,
819 imldp.x = offset + left;
820 imldp.y = offset + top;
821 imldp.rgbBk = CLR_NONE;
822 imldp.rgbFg = CLR_DEFAULT;
823 imldp.fStyle = ILD_TRANSPARENT;
824 imldp.fState = ILS_ALPHA | ILS_SATURATE;
825 imldp.Frame = 192;
826
827 ImageList_DrawIndirect (&imldp);
828 }
829 else
830 {
831 /* code path for drawing standard icons as-is */
832 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
833 }
834 }
835
836 /* draws a blank frame for a toolbar button */
837 static void
838 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, const RECT *rect, DWORD dwItemCDFlag)
839 {
840 HDC hdc = tbcd->nmcd.hdc;
841 RECT rc = *rect;
842 /* if the state is disabled or indeterminate then the button
843 * cannot have an interactive look like pressed or hot */
844 BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
845 (tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
846 BOOL pressed_look = !non_interactive_state &&
847 ((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
848 (tbcd->nmcd.uItemState & CDIS_CHECKED));
849
850 /* app don't want us to draw any edges */
851 if (dwItemCDFlag & TBCDRF_NOEDGES)
852 return;
853
854 if (infoPtr->dwStyle & TBSTYLE_FLAT)
855 {
856 if (pressed_look)
857 DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
858 else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
859 DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
860 }
861 else
862 {
863 if (pressed_look)
864 DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
865 else
866 DrawEdge (hdc, &rc, EDGE_RAISED,
867 BF_SOFT | BF_RECT | BF_MIDDLE);
868 }
869 }
870
871 static void
872 TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
873 {
874 HDC hdc = tbcd->nmcd.hdc;
875 int offset = 0;
876 BOOL pressed = bDropDownPressed ||
877 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
878
879 if (infoPtr->dwStyle & TBSTYLE_FLAT)
880 {
881 if (pressed)
882 DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
883 else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
884 !(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
885 !(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
886 DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
887 }
888 else
889 {
890 if (pressed)
891 DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
892 else
893 DrawEdge (hdc, rcArrow, EDGE_RAISED,
894 BF_SOFT | BF_RECT | BF_MIDDLE);
895 }
896
897 if (pressed)
898 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
899
900 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
901 {
902 TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
903 TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
904 }
905 else
906 TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
907 }
908
909 /* draws a complete toolbar button */
910 static void
911 TOOLBAR_DrawButton (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
912 {
913 DWORD dwStyle = infoPtr->dwStyle;
914 BOOL hasDropDownArrow = button_has_ddarrow( infoPtr, btnPtr );
915 BOOL drawSepDropDownArrow = hasDropDownArrow &&
916 (~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
917 RECT rc, rcArrow, rcBitmap, rcText;
918 LPWSTR lpText = NULL;
919 NMTBCUSTOMDRAW tbcd;
920 DWORD ntfret;
921 INT offset;
922 INT oldBkMode;
923 DWORD dwItemCustDraw;
924 DWORD dwItemCDFlag;
925 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
926
927 rc = btnPtr->rect;
928 CopyRect (&rcArrow, &rc);
929
930 /* separator - doesn't send NM_CUSTOMDRAW */
931 if (btnPtr->fsStyle & BTNS_SEP) {
932 if (theme)
933 {
934 DrawThemeBackground (theme, hdc,
935 (dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
936 &rc, NULL);
937 }
938 else
939 /* with the FLAT style, iBitmap is the width and has already */
940 /* been taken into consideration in calculating the width */
941 /* so now we need to draw the vertical separator */
942 /* empirical tests show that iBitmap can/will be non-zero */
943 /* when drawing the vertical bar... */
944 if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
945 if (dwStyle & CCS_VERT) {
946 RECT rcsep = rc;
947 InflateRect(&rcsep, -infoPtr->szPadding.cx, -infoPtr->szPadding.cy);
948 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep, hdc, infoPtr);
949 }
950 else {
951 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
952 }
953 }
954 else if (btnPtr->fsStyle != BTNS_SEP) {
955 FIXME("Draw some kind of separator: fsStyle=%x\n",
956 btnPtr->fsStyle);
957 }
958 return;
959 }
960
961 /* get a pointer to the text */
962 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
963
964 if (hasDropDownArrow)
965 {
966 int right;
967
968 if (dwStyle & TBSTYLE_FLAT)
969 right = max(rc.left, rc.right - DDARROW_WIDTH);
970 else
971 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
972
973 if (drawSepDropDownArrow)
974 rc.right = right;
975
976 rcArrow.left = right;
977 }
978
979 /* copy text & bitmap rects after adjusting for drop-down arrow
980 * so that text & bitmap is centered in the rectangle not containing
981 * the arrow */
982 CopyRect(&rcText, &rc);
983 CopyRect(&rcBitmap, &rc);
984
985 /* Center the bitmap horizontally and vertically */
986 if (dwStyle & TBSTYLE_LIST)
987 {
988 if (lpText &&
989 infoPtr->nMaxTextRows > 0 &&
990 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
991 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
992 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
993 else
994 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
995 }
996 else
997 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
998
999 rcBitmap.top += infoPtr->szPadding.cy / 2;
1000
1001 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
1002 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
1003 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
1004 TRACE("Text=%s\n", debugstr_w(lpText));
1005 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
1006
1007 /* calculate text position */
1008 if (lpText)
1009 {
1010 rcText.left += GetSystemMetrics(SM_CXEDGE);
1011 rcText.right -= GetSystemMetrics(SM_CXEDGE);
1012 if (dwStyle & TBSTYLE_LIST)
1013 {
1014 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
1015 }
1016 else
1017 {
1018 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
1019 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
1020 else
1021 rcText.top += infoPtr->szPadding.cy/2 + 2;
1022 }
1023 }
1024
1025 /* Initialize fields in all cases, because we use these later
1026 * NOTE: applications can and do alter these to customize their
1027 * toolbars */
1028 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1029 tbcd.clrText = comctl32_color.clrBtnText;
1030 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
1031 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
1032 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
1033 tbcd.clrMark = comctl32_color.clrHighlight;
1034 tbcd.clrHighlightHotTrack = 0;
1035 tbcd.nStringBkMode = TRANSPARENT;
1036 tbcd.nHLStringBkMode = OPAQUE;
1037 tbcd.rcText.left = 0;
1038 tbcd.rcText.top = 0;
1039 tbcd.rcText.right = rcText.right - rc.left;
1040 tbcd.rcText.bottom = rcText.bottom - rc.top;
1041 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1042 tbcd.nmcd.hdc = hdc;
1043 tbcd.nmcd.rc = btnPtr->rect;
1044 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
1045
1046 /* FIXME: what are these used for? */
1047 tbcd.hbrLines = 0;
1048 tbcd.hpenLines = 0;
1049
1050 /* Issue Item Prepaint notify */
1051 dwItemCustDraw = 0;
1052 dwItemCDFlag = 0;
1053 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
1054 {
1055 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
1056 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1057 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1058 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1059 /* reset these fields so the user can't alter the behaviour like native */
1060 tbcd.nmcd.hdc = hdc;
1061 tbcd.nmcd.rc = btnPtr->rect;
1062
1063 dwItemCustDraw = ntfret & 0xffff;
1064 dwItemCDFlag = ntfret & 0xffff0000;
1065 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
1066 return;
1067 /* save the only part of the rect that the user can change */
1068 rcText.right = tbcd.rcText.right + rc.left;
1069 rcText.bottom = tbcd.rcText.bottom + rc.top;
1070 }
1071
1072 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
1073 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
1074 OffsetRect(&rcText, 1, 1);
1075
1076 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
1077 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
1078 TOOLBAR_DrawPattern (&rc, &tbcd);
1079
1080 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
1081 && (tbcd.nmcd.uItemState & CDIS_HOT))
1082 {
1083 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
1084 {
1085 COLORREF oldclr;
1086
1087 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1088 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1089 if (hasDropDownArrow)
1090 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1091 SetBkColor(hdc, oldclr);
1092 }
1093 }
1094
1095 #ifdef __REACTOS__
1096 if (theme && !(dwItemCDFlag & TBCDRF_NOBACKGROUND))
1097 #else
1098 if (theme)
1099 #endif
1100 {
1101 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1102 int stateId = TS_NORMAL;
1103
1104 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1105 stateId = TS_DISABLED;
1106 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1107 stateId = TS_PRESSED;
1108 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1109 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1110 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1111 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1112 stateId = TS_HOT;
1113
1114 DrawThemeBackground (theme, hdc, partId, stateId, &rc, NULL);
1115 }
1116
1117 #ifdef __REACTOS__
1118 if (!theme)
1119 #else
1120 else
1121 #endif
1122 TOOLBAR_DrawFrame(infoPtr, &tbcd, &rc, dwItemCDFlag);
1123
1124 if (drawSepDropDownArrow)
1125 {
1126 if (theme)
1127 {
1128 int stateId = TS_NORMAL;
1129
1130 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1131 stateId = TS_DISABLED;
1132 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1133 stateId = TS_PRESSED;
1134 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1135 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1136 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1137 stateId = TS_HOT;
1138
1139 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1140 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1141 }
1142 else
1143 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1144 }
1145
1146 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1147 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1148 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1149 SetBkMode (hdc, oldBkMode);
1150
1151 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1152
1153 if (hasDropDownArrow && !drawSepDropDownArrow)
1154 {
1155 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1156 {
1157 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1158 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1159 }
1160 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1161 {
1162 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1163 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1164 }
1165 else
1166 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1167 }
1168
1169 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1170 {
1171 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1172 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1173 }
1174
1175 }
1176
1177
1178 static void
1179 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1180 {
1181 TBUTTON_INFO *btnPtr;
1182 INT i;
1183 RECT rcTemp, rcClient;
1184 NMTBCUSTOMDRAW tbcd;
1185 DWORD ntfret;
1186 DWORD dwBaseCustDraw;
1187
1188 /* the app has told us not to redraw the toolbar */
1189 if (!infoPtr->bDoRedraw)
1190 return;
1191
1192 /* if imagelist belongs to the app, it can be changed
1193 by the app after setting it */
1194 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1195 {
1196 infoPtr->nNumBitmaps = 0;
1197 for (i = 0; i < infoPtr->cimlDef; i++)
1198 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1199 }
1200
1201 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1202
1203 /* change the imagelist icon size if we manage the list and it is necessary */
1204 TOOLBAR_CheckImageListIconSize(infoPtr);
1205
1206 /* Send initial notify */
1207 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1208 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1209 tbcd.nmcd.hdc = hdc;
1210 tbcd.nmcd.rc = ps->rcPaint;
1211 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1212 dwBaseCustDraw = ntfret & 0xffff;
1213
1214 GetClientRect(infoPtr->hwndSelf, &rcClient);
1215
1216 /* redraw necessary buttons */
1217 btnPtr = infoPtr->buttons;
1218 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1219 {
1220 BOOL bDraw;
1221 if (!RectVisible(hdc, &btnPtr->rect))
1222 continue;
1223 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1224 {
1225 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1226 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1227 }
1228 else
1229 bDraw = TRUE;
1230 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1231 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1232 if (bDraw)
1233 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1234 }
1235
1236 /* draw insert mark if required */
1237 if (infoPtr->tbim.iButton != -1)
1238 {
1239 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1240 RECT rcInsertMark;
1241 rcInsertMark.top = rcButton.top;
1242 rcInsertMark.bottom = rcButton.bottom;
1243 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1244 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1245 else
1246 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1247 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1248 }
1249
1250 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1251 {
1252 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1253 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1254 tbcd.nmcd.hdc = hdc;
1255 tbcd.nmcd.rc = ps->rcPaint;
1256 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1257 }
1258 }
1259
1260 /***********************************************************************
1261 * TOOLBAR_MeasureString
1262 *
1263 * This function gets the width and height of a string in pixels. This
1264 * is done first by using GetTextExtentPoint to get the basic width
1265 * and height. The DrawText is called with DT_CALCRECT to get the exact
1266 * width. The reason is because the text may have more than one "&" (or
1267 * prefix characters as M$ likes to call them). The prefix character
1268 * indicates where the underline goes, except for the string "&&" which
1269 * is reduced to a single "&". GetTextExtentPoint does not process these
1270 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1271 */
1272 static void
1273 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1274 HDC hdc, LPSIZE lpSize)
1275 {
1276 RECT myrect;
1277
1278 lpSize->cx = 0;
1279 lpSize->cy = 0;
1280
1281 if (infoPtr->nMaxTextRows > 0 &&
1282 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1283 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1284 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1285 {
1286 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1287
1288 if(lpText != NULL) {
1289 /* first get size of all the text */
1290 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1291
1292 /* feed above size into the rectangle for DrawText */
1293 myrect.left = myrect.top = 0;
1294 myrect.right = lpSize->cx;
1295 myrect.bottom = lpSize->cy;
1296
1297 /* Use DrawText to get true size as drawn (less pesky "&") */
1298 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1299 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1300 DT_NOPREFIX : 0));
1301
1302 /* feed back to caller */
1303 lpSize->cx = myrect.right;
1304 lpSize->cy = myrect.bottom;
1305 }
1306 }
1307
1308 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1309 }
1310
1311 /***********************************************************************
1312 * TOOLBAR_CalcStrings
1313 *
1314 * This function walks through each string and measures it and returns
1315 * the largest height and width to caller.
1316 */
1317 static void
1318 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1319 {
1320 TBUTTON_INFO *btnPtr;
1321 INT i;
1322 SIZE sz;
1323 HDC hdc;
1324 HFONT hOldFont;
1325
1326 lpSize->cx = 0;
1327 lpSize->cy = 0;
1328
1329 if (infoPtr->nMaxTextRows == 0)
1330 return;
1331
1332 hdc = GetDC (infoPtr->hwndSelf);
1333 hOldFont = SelectObject (hdc, infoPtr->hFont);
1334
1335 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1336 {
1337 TEXTMETRICW tm;
1338
1339 GetTextMetricsW(hdc, &tm);
1340 lpSize->cy = tm.tmHeight;
1341 }
1342
1343 btnPtr = infoPtr->buttons;
1344 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1345 if(TOOLBAR_GetText(infoPtr, btnPtr))
1346 {
1347 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1348 if (sz.cx > lpSize->cx)
1349 lpSize->cx = sz.cx;
1350 if (sz.cy > lpSize->cy)
1351 lpSize->cy = sz.cy;
1352 }
1353 }
1354
1355 SelectObject (hdc, hOldFont);
1356 ReleaseDC (infoPtr->hwndSelf, hdc);
1357
1358 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1359 }
1360
1361 /***********************************************************************
1362 * TOOLBAR_WrapToolbar
1363 *
1364 * This function walks through the buttons and separators in the
1365 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1366 * wrapping should occur based on the width of the toolbar window.
1367 * It does *not* calculate button placement itself. That task
1368 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1369 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1370 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1371 *
1372 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1373 * vertical toolbar lists.
1374 */
1375
1376 static void
1377 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1378 {
1379 TBUTTON_INFO *btnPtr;
1380 INT x, cx, i, j, width;
1381 BOOL bButtonWrap;
1382
1383 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1384 /* no layout is necessary. Applications may use this style */
1385 /* to perform their own layout on the toolbar. */
1386 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1387 !(infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL) ) return;
1388
1389 btnPtr = infoPtr->buttons;
1390 x = infoPtr->nIndent;
1391 width = infoPtr->client_rect.right - infoPtr->client_rect.left;
1392
1393 bButtonWrap = FALSE;
1394
1395 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1396 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, width,
1397 infoPtr->nIndent);
1398
1399 for (i = 0; i < infoPtr->nNumButtons; i++ )
1400 {
1401 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1402
1403 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1404 continue;
1405
1406 if (btnPtr[i].cx > 0)
1407 cx = btnPtr[i].cx;
1408 /* horizontal separators are treated as buttons for width */
1409 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1410 !(infoPtr->dwStyle & CCS_VERT))
1411 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1412 else
1413 cx = infoPtr->nButtonWidth;
1414
1415 if (!btnPtr[i].cx && button_has_ddarrow( infoPtr, btnPtr + i ))
1416 cx += DDARROW_WIDTH;
1417
1418 /* Two or more adjacent separators form a separator group. */
1419 /* The first separator in a group should be wrapped to the */
1420 /* next row if the previous wrapping is on a button. */
1421 if( bButtonWrap &&
1422 (btnPtr[i].fsStyle & BTNS_SEP) &&
1423 (i + 1 < infoPtr->nNumButtons ) &&
1424 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1425 {
1426 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1427 btnPtr[i].fsState |= TBSTATE_WRAP;
1428 x = infoPtr->nIndent;
1429 i++;
1430 bButtonWrap = FALSE;
1431 continue;
1432 }
1433
1434 /* The layout makes sure the bitmap is visible, but not the button. */
1435 /* Test added to also wrap after a button that starts a row but */
1436 /* is bigger than the area. - GA 8/01 */
1437 if ((x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2 > width) ||
1438 ((x == infoPtr->nIndent) && (cx > width)))
1439 {
1440 BOOL bFound = FALSE;
1441
1442 /* If the current button is a separator and not hidden, */
1443 /* go to the next until it reaches a non separator. */
1444 /* Wrap the last separator if it is before a button. */
1445 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1446 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1447 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1448 i < infoPtr->nNumButtons )
1449 {
1450 i++;
1451 bFound = TRUE;
1452 }
1453
1454 if( bFound && i < infoPtr->nNumButtons )
1455 {
1456 i--;
1457 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1458 i, btnPtr[i].fsStyle, x, cx);
1459 btnPtr[i].fsState |= TBSTATE_WRAP;
1460 x = infoPtr->nIndent;
1461 bButtonWrap = FALSE;
1462 continue;
1463 }
1464 else if ( i >= infoPtr->nNumButtons)
1465 break;
1466
1467 /* If the current button is not a separator, find the last */
1468 /* separator and wrap it. */
1469 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1470 {
1471 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1472 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1473 {
1474 bFound = TRUE;
1475 i = j;
1476 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1477 i, btnPtr[i].fsStyle, x, cx);
1478 x = infoPtr->nIndent;
1479 btnPtr[j].fsState |= TBSTATE_WRAP;
1480 bButtonWrap = FALSE;
1481 break;
1482 }
1483 }
1484
1485 /* If no separator available for wrapping, wrap one of */
1486 /* non-hidden previous button. */
1487 if (!bFound)
1488 {
1489 for ( j = i - 1;
1490 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1491 {
1492 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1493 continue;
1494
1495 bFound = TRUE;
1496 i = j;
1497 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1498 i, btnPtr[i].fsStyle, x, cx);
1499 x = infoPtr->nIndent;
1500 btnPtr[j].fsState |= TBSTATE_WRAP;
1501 bButtonWrap = TRUE;
1502 break;
1503 }
1504 }
1505
1506 /* If all above failed, wrap the current button. */
1507 if (!bFound)
1508 {
1509 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1510 i, btnPtr[i].fsStyle, x, cx);
1511 btnPtr[i].fsState |= TBSTATE_WRAP;
1512 x = infoPtr->nIndent;
1513 if (btnPtr[i].fsStyle & BTNS_SEP )
1514 bButtonWrap = FALSE;
1515 else
1516 bButtonWrap = TRUE;
1517 }
1518 }
1519 else {
1520 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1521 i, btnPtr[i].fsStyle, x, cx);
1522 x += cx;
1523 }
1524 }
1525 }
1526
1527
1528 /***********************************************************************
1529 * TOOLBAR_MeasureButton
1530 *
1531 * Calculates the width and height required for a button. Used in
1532 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1533 * the width of buttons that are autosized.
1534 *
1535 * Note that it would have been rather elegant to use one piece of code for
1536 * both the laying out of the toolbar and for controlling where button parts
1537 * are drawn, but the native control has inconsistencies between the two that
1538 * prevent this from being effectively. These inconsistencies can be seen as
1539 * artefacts where parts of the button appear outside of the bounding button
1540 * rectangle.
1541 *
1542 * There are several cases for the calculation of the button dimensions and
1543 * button part positioning:
1544 *
1545 * List
1546 * ====
1547 *
1548 * With Bitmap:
1549 *
1550 * +--------------------------------------------------------+ ^
1551 * | ^ ^ | |
1552 * | | pad.cy / 2 | centered | |
1553 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1554 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1555 * | |<------------>| | | | |
1556 * | +--------------+ +------------+ | |
1557 * |<-------------------------------------->| | |
1558 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1559 * | szText.cx | |
1560 * +--------------------------------------------------------+ -
1561 * <-------------------------------------------------------->
1562 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1563 *
1564 * Without Bitmap (I_IMAGENONE):
1565 *
1566 * +-----------------------------------+ ^
1567 * | ^ | |
1568 * | | centered | | LISTPAD_CY +
1569 * | +------------+ | | szText.cy
1570 * | | Text | | |
1571 * | | | | |
1572 * | +------------+ | |
1573 * |<----------------->| | |
1574 * | cxedge |<-----------> | |
1575 * | szText.cx | |
1576 * +-----------------------------------+ -
1577 * <----------------------------------->
1578 * szText.cx + pad.cx
1579 *
1580 * Without text:
1581 *
1582 * +--------------------------------------+ ^
1583 * | ^ | |
1584 * | | padding.cy/2 | | DEFPAD_CY +
1585 * | +------------+ | | nBitmapHeight
1586 * | | Bitmap | | |
1587 * | | | | |
1588 * | +------------+ | |
1589 * |<------------------->| | |
1590 * | cxedge + iListGap/2 |<-----------> | |
1591 * | nBitmapWidth | |
1592 * +--------------------------------------+ -
1593 * <-------------------------------------->
1594 * 2*cxedge + nBitmapWidth + iListGap
1595 *
1596 * Non-List
1597 * ========
1598 *
1599 * With bitmap:
1600 *
1601 * +-----------------------------------+ ^
1602 * | ^ | |
1603 * | | pad.cy / 2 | | nBitmapHeight +
1604 * | - | | szText.cy +
1605 * | +------------+ | | DEFPAD_CY + 1
1606 * | centered | Bitmap | | |
1607 * |<----------------->| | | |
1608 * | +------------+ | |
1609 * | ^ | |
1610 * | 1 | | |
1611 * | - | |
1612 * | centered +---------------+ | |
1613 * |<--------------->| Text | | |
1614 * | +---------------+ | |
1615 * +-----------------------------------+ -
1616 * <----------------------------------->
1617 * pad.cx + max(nBitmapWidth, szText.cx)
1618 *
1619 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1620 *
1621 * +---------------------------------------+ ^
1622 * | ^ | |
1623 * | | 2 + pad.cy / 2 | |
1624 * | - | | szText.cy +
1625 * | centered +-----------------+ | | pad.cy + 2
1626 * |<--------------->| Text | | |
1627 * | +-----------------+ | |
1628 * | | |
1629 * +---------------------------------------+ -
1630 * <--------------------------------------->
1631 * 2*cxedge + pad.cx + szText.cx
1632 *
1633 * Without text:
1634 * As for with bitmaps, but with szText.cx zero.
1635 */
1636 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1637 BOOL bHasBitmap, BOOL bValidImageList)
1638 {
1639 SIZE sizeButton;
1640 if (infoPtr->dwStyle & TBSTYLE_LIST)
1641 {
1642 /* set button height from bitmap / text height... */
1643 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1644 sizeString.cy);
1645
1646 /* ... add on the necessary padding */
1647 if (bValidImageList)
1648 {
1649 #ifdef __REACTOS__
1650 sizeButton.cy += infoPtr->szPadding.cy;
1651 if (!bHasBitmap)
1652 #else
1653 if (bHasBitmap)
1654 sizeButton.cy += DEFPAD_CY;
1655 else
1656 #endif
1657 sizeButton.cy += LISTPAD_CY;
1658 }
1659 else
1660 sizeButton.cy += infoPtr->szPadding.cy;
1661
1662 /* calculate button width */
1663 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1664 infoPtr->nBitmapWidth + infoPtr->iListGap;
1665 if (sizeString.cx > 0)
1666 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1667
1668 }
1669 else
1670 {
1671 if (bHasBitmap)
1672 {
1673 #ifdef __REACTOS__
1674 sizeButton.cy = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1675 #else
1676 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1677 #endif
1678 if (sizeString.cy > 0)
1679 sizeButton.cy += 1 + sizeString.cy;
1680 sizeButton.cx = infoPtr->szPadding.cx +
1681 max(sizeString.cx, infoPtr->nBitmapWidth);
1682 }
1683 else
1684 {
1685 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1686 NONLIST_NOTEXT_OFFSET;
1687 sizeButton.cx = infoPtr->szPadding.cx +
1688 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1689 }
1690 }
1691 return sizeButton;
1692 }
1693
1694
1695 /***********************************************************************
1696 * TOOLBAR_CalcToolbar
1697 *
1698 * This function calculates button and separator placement. It first
1699 * calculates the button sizes, gets the toolbar window width and then
1700 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1701 * on. It assigns a new location to each item and sends this location to
1702 * the tooltip window if appropriate. Finally, it updates the rcBound
1703 * rect and calculates the new required toolbar window height.
1704 */
1705 static void
1706 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1707 {
1708 SIZE sizeString, sizeButton;
1709 BOOL validImageList = FALSE;
1710
1711 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1712
1713 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1714
1715 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1716 validImageList = TRUE;
1717 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1718 infoPtr->nButtonWidth = sizeButton.cx;
1719 infoPtr->nButtonHeight = sizeButton.cy;
1720 infoPtr->iTopMargin = default_top_margin(infoPtr);
1721
1722 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1723 infoPtr->nButtonWidth = infoPtr->cxMin;
1724 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1725 infoPtr->nButtonWidth = infoPtr->cxMax;
1726
1727 TOOLBAR_LayoutToolbar(infoPtr);
1728 }
1729
1730 static void
1731 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1732 {
1733 TBUTTON_INFO *btnPtr;
1734 SIZE sizeButton;
1735 INT i, nRows, nSepRows;
1736 INT x, y, cx, cy;
1737 BOOL bWrap;
1738 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1739
1740 TOOLBAR_WrapToolbar(infoPtr);
1741
1742 x = infoPtr->nIndent;
1743 y = infoPtr->iTopMargin;
1744 cx = infoPtr->nButtonWidth;
1745 cy = infoPtr->nButtonHeight;
1746
1747 nRows = nSepRows = 0;
1748
1749 infoPtr->rcBound.top = y;
1750 infoPtr->rcBound.left = x;
1751 infoPtr->rcBound.bottom = y + cy;
1752 infoPtr->rcBound.right = x;
1753
1754 btnPtr = infoPtr->buttons;
1755
1756 TRACE("cy=%d\n", cy);
1757
1758 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1759 {
1760 bWrap = FALSE;
1761 if (btnPtr->fsState & TBSTATE_HIDDEN)
1762 {
1763 SetRectEmpty (&btnPtr->rect);
1764 continue;
1765 }
1766
1767 cy = infoPtr->nButtonHeight;
1768
1769 if (btnPtr->fsStyle & BTNS_SEP) {
1770 if (infoPtr->dwStyle & CCS_VERT) {
1771 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1772 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nButtonWidth;
1773 }
1774 else
1775 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1776 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1777 }
1778 else
1779 {
1780 if (btnPtr->cx)
1781 cx = btnPtr->cx;
1782 #ifdef __REACTOS__
1783 /* Revert Wine Commit 5b7b911 as it breaks Explorer Toolbar Buttons
1784 FIXME: Revisit this when the bug is fixed. CORE-9970 */
1785 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1786 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1787 #else
1788 else if (btnPtr->fsStyle & BTNS_AUTOSIZE)
1789 #endif
1790 {
1791 SIZE sz;
1792 HDC hdc;
1793 HFONT hOldFont;
1794
1795 hdc = GetDC (infoPtr->hwndSelf);
1796 hOldFont = SelectObject (hdc, infoPtr->hFont);
1797
1798 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1799
1800 SelectObject (hdc, hOldFont);
1801 ReleaseDC (infoPtr->hwndSelf, hdc);
1802
1803 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1804 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1805 validImageList);
1806 cx = sizeButton.cx;
1807 }
1808 else
1809 cx = infoPtr->nButtonWidth;
1810
1811 /* if size has been set manually then don't add on extra space
1812 * for the drop down arrow */
1813 if (!btnPtr->cx && button_has_ddarrow( infoPtr, btnPtr ))
1814 cx += DDARROW_WIDTH;
1815 }
1816 if (btnPtr->fsState & TBSTATE_WRAP)
1817 bWrap = TRUE;
1818
1819 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1820
1821 if (infoPtr->rcBound.left > x)
1822 infoPtr->rcBound.left = x;
1823 if (infoPtr->rcBound.right < x + cx)
1824 infoPtr->rcBound.right = x + cx;
1825 if (infoPtr->rcBound.bottom < y + cy)
1826 infoPtr->rcBound.bottom = y + cy;
1827
1828 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1829
1830 /* btnPtr->nRow is zero based. The space between the rows is */
1831 /* also considered as a row. */
1832 btnPtr->nRow = nRows + nSepRows;
1833
1834 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1835 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1836 x, y, x+cx, y+cy);
1837
1838 if( bWrap )
1839 {
1840 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1841 y += cy;
1842 else
1843 {
1844 if ( !(infoPtr->dwStyle & CCS_VERT))
1845 y += cy + ( (btnPtr->cx > 0 ) ?
1846 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1847 else
1848 y += cy;
1849
1850 /* nSepRows is used to calculate the extra height following */
1851 /* the last row. */
1852 nSepRows++;
1853 }
1854 x = infoPtr->nIndent;
1855
1856 /* Increment row number unless this is the last button */
1857 /* and it has Wrap set. */
1858 if (i != infoPtr->nNumButtons-1)
1859 nRows++;
1860 }
1861 else
1862 x += cx;
1863 }
1864
1865 /* infoPtr->nRows is the number of rows on the toolbar */
1866 infoPtr->nRows = nRows + nSepRows + 1;
1867
1868 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1869 }
1870
1871
1872 static INT
1873 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
1874 {
1875 TBUTTON_INFO *btnPtr;
1876 INT i;
1877
1878 if (button)
1879 *button = FALSE;
1880
1881 btnPtr = infoPtr->buttons;
1882 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1883 if (btnPtr->fsState & TBSTATE_HIDDEN)
1884 continue;
1885
1886 if (btnPtr->fsStyle & BTNS_SEP) {
1887 if (PtInRect (&btnPtr->rect, *lpPt)) {
1888 TRACE(" ON SEPARATOR %d!\n", i);
1889 return -i;
1890 }
1891 }
1892 else {
1893 if (PtInRect (&btnPtr->rect, *lpPt)) {
1894 TRACE(" ON BUTTON %d!\n", i);
1895 if (button)
1896 *button = TRUE;
1897 return i;
1898 }
1899 }
1900 }
1901
1902 TRACE(" NOWHERE!\n");
1903 return TOOLBAR_NOWHERE;
1904 }
1905
1906
1907 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1908 static BOOL
1909 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1910 {
1911 INT nOldButtons, nNewButtons, iButton;
1912 BOOL fHasString = FALSE;
1913
1914 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1915 iIndex = infoPtr->nNumButtons;
1916
1917 nOldButtons = infoPtr->nNumButtons;
1918 nNewButtons = nOldButtons + nAddButtons;
1919
1920 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1921 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1922 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1923 infoPtr->nNumButtons += nAddButtons;
1924
1925 /* insert new buttons data */
1926 for (iButton = 0; iButton < nAddButtons; iButton++) {
1927 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1928 INT_PTR str;
1929
1930 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1931
1932 ZeroMemory(btnPtr, sizeof(*btnPtr));
1933
1934 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1935 btnPtr->idCommand = lpTbb[iButton].idCommand;
1936 btnPtr->fsState = lpTbb[iButton].fsState;
1937 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1938 btnPtr->dwData = lpTbb[iButton].dwData;
1939
1940 if (btnPtr->fsStyle & BTNS_SEP)
1941 str = -1;
1942 else
1943 str = lpTbb[iButton].iString;
1944 set_string_index( btnPtr, str, fUnicode );
1945 fHasString |= TOOLBAR_ButtonHasString( btnPtr );
1946
1947 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1948 }
1949
1950 if (infoPtr->nNumStrings > 0 || fHasString)
1951 TOOLBAR_CalcToolbar(infoPtr);
1952 else
1953 TOOLBAR_LayoutToolbar(infoPtr);
1954 TOOLBAR_AutoSize(infoPtr);
1955
1956 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1957 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1958 return TRUE;
1959 }
1960
1961
1962 static INT
1963 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1964 {
1965 TBUTTON_INFO *btnPtr;
1966 INT i;
1967
1968 if (CommandIsIndex) {
1969 TRACE("command is really index command=%d\n", idCommand);
1970 if (idCommand >= infoPtr->nNumButtons) return -1;
1971 return idCommand;
1972 }
1973 btnPtr = infoPtr->buttons;
1974 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1975 if (btnPtr->idCommand == idCommand) {
1976 TRACE("command=%d index=%d\n", idCommand, i);
1977 return i;
1978 }
1979 }
1980 TRACE("no index found for command=%d\n", idCommand);
1981 return -1;
1982 }
1983
1984
1985 static INT
1986 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1987 {
1988 TBUTTON_INFO *btnPtr;
1989 INT nRunIndex;
1990
1991 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1992 return -1;
1993
1994 /* check index button */
1995 btnPtr = &infoPtr->buttons[nIndex];
1996 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1997 if (btnPtr->fsState & TBSTATE_CHECKED)
1998 return nIndex;
1999 }
2000
2001 /* check previous buttons */
2002 nRunIndex = nIndex - 1;
2003 while (nRunIndex >= 0) {
2004 btnPtr = &infoPtr->buttons[nRunIndex];
2005 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2006 if (btnPtr->fsState & TBSTATE_CHECKED)
2007 return nRunIndex;
2008 }
2009 else
2010 break;
2011 nRunIndex--;
2012 }
2013
2014 /* check next buttons */
2015 nRunIndex = nIndex + 1;
2016 while (nRunIndex < infoPtr->nNumButtons) {
2017 btnPtr = &infoPtr->buttons[nRunIndex];
2018 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2019 if (btnPtr->fsState & TBSTATE_CHECKED)
2020 return nRunIndex;
2021 }
2022 else
2023 break;
2024 nRunIndex++;
2025 }
2026
2027 return -1;
2028 }
2029
2030
2031 static VOID
2032 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
2033 WPARAM wParam, LPARAM lParam)
2034 {
2035 MSG msg;
2036
2037 msg.hwnd = hwndMsg;
2038 msg.message = uMsg;
2039 msg.wParam = wParam;
2040 msg.lParam = lParam;
2041 msg.time = GetMessageTime ();
2042 msg.pt.x = (short)LOWORD(GetMessagePos ());
2043 msg.pt.y = (short)HIWORD(GetMessagePos ());
2044
2045 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
2046 }
2047
2048 #ifdef __REACTOS__
2049 static LRESULT
2050 TOOLBAR_ThemeChanged(HWND hwnd)
2051 {
2052 HTHEME theme = GetWindowTheme(hwnd);
2053 CloseThemeData(theme);
2054 OpenThemeData(hwnd, themeClass);
2055 return 0;
2056 }
2057 #endif
2058
2059 static void
2060 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2061 {
2062 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
2063 TTTOOLINFOW ti;
2064
2065 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
2066 ti.cbSize = sizeof (TTTOOLINFOW);
2067 ti.hwnd = infoPtr->hwndSelf;
2068 ti.uId = button->idCommand;
2069 ti.hinst = 0;
2070 ti.lpszText = LPSTR_TEXTCALLBACKW;
2071 /* ti.lParam = random value from the stack? */
2072
2073 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
2074 0, (LPARAM)&ti);
2075 }
2076 }
2077
2078 static void
2079 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2080 {
2081 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
2082 TTTOOLINFOW ti;
2083
2084 ZeroMemory(&ti, sizeof(ti));
2085 ti.cbSize = sizeof(ti);
2086 ti.hwnd = infoPtr->hwndSelf;
2087 ti.uId = button->idCommand;
2088
2089 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
2090 }
2091 }
2092
2093 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2094 {
2095 /* Set the toolTip only for non-hidden, non-separator button */
2096 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
2097 {
2098 TTTOOLINFOW ti;
2099
2100 ZeroMemory(&ti, sizeof(ti));
2101 ti.cbSize = sizeof(ti);
2102 ti.hwnd = infoPtr->hwndSelf;
2103 ti.uId = button->idCommand;
2104 ti.rect = button->rect;
2105 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2106 }
2107 }
2108
2109 /* Creates the tooltip control */
2110 static void
2111 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2112 {
2113 int i;
2114 NMTOOLTIPSCREATED nmttc;
2115
2116 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2117 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2118 infoPtr->hwndSelf, 0, 0, 0);
2119
2120 if (!infoPtr->hwndToolTip)
2121 return;
2122
2123 /* Send NM_TOOLTIPSCREATED notification */
2124 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2125 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2126
2127 for (i = 0; i < infoPtr->nNumButtons; i++)
2128 {
2129 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2130 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2131 }
2132 }
2133
2134 /* keeps available button list box sorted by button id */
2135 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2136 {
2137 int i;
2138 int count;
2139 PCUSTOMBUTTON btnInfo;
2140 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2141
2142 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2143
2144 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2145
2146 /* position 0 is always separator */
2147 for (i = 1; i < count; i++)
2148 {
2149 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2150 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2151 {
2152 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2153 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2154 return;
2155 }
2156 }
2157 /* id higher than all others add to end */
2158 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2159 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2160 }
2161
2162 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2163 {
2164 NMTOOLBARW nmtb;
2165
2166 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2167
2168 if (nIndexFrom == nIndexTo)
2169 return;
2170
2171 /* MSDN states that iItem is the index of the button, rather than the
2172 * command ID as used by every other NMTOOLBAR notification */
2173 nmtb.iItem = nIndexFrom;
2174 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2175 {
2176 PCUSTOMBUTTON btnInfo;
2177 NMHDR hdr;
2178 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2179 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2180
2181 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2182
2183 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2184 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2185 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2186 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2187
2188 if (nIndexTo <= 0)
2189 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2190 else
2191 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2192
2193 /* last item is always separator, so -2 instead of -1 */
2194 if (nIndexTo >= (count - 2))
2195 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2196 else
2197 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2198
2199 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2200 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2201
2202 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2203 }
2204 }
2205
2206 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2207 {
2208 NMTOOLBARW nmtb;
2209
2210 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2211
2212 /* MSDN states that iItem is the index of the button, rather than the
2213 * command ID as used by every other NMTOOLBAR notification */
2214 nmtb.iItem = nIndexAvail;
2215 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2216 {
2217 PCUSTOMBUTTON btnInfo;
2218 NMHDR hdr;
2219 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2220 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2221 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2222
2223 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2224
2225 if (nIndexAvail != 0) /* index == 0 indicates separator */
2226 {
2227 /* remove from 'available buttons' list */
2228 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2229 if (nIndexAvail == count-1)
2230 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2231 else
2232 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2233 }
2234 else
2235 {
2236 PCUSTOMBUTTON btnNew;
2237
2238 /* duplicate 'separator' button */
2239 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2240 *btnNew = *btnInfo;
2241 btnInfo = btnNew;
2242 }
2243
2244 /* insert into 'toolbar button' list */
2245 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2246 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2247
2248 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2249
2250 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2251 }
2252 }
2253
2254 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2255 {
2256 PCUSTOMBUTTON btnInfo;
2257 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2258
2259 TRACE("Remove: index %d\n", index);
2260
2261 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2262
2263 /* send TBN_QUERYDELETE notification */
2264 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2265 {
2266 NMHDR hdr;
2267
2268 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2269 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2270
2271 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2272
2273 /* insert into 'available button' list */
2274 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2275 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2276 else
2277 Free(btnInfo);
2278
2279 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2280 }
2281 }
2282
2283 /* drag list notification function for toolbar buttons list box */
2284 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2285 const DRAGLISTINFO *pDLI)
2286 {
2287 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2288 switch (pDLI->uNotification)
2289 {
2290 case DL_BEGINDRAG:
2291 {
2292 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2293 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2294 /* no dragging for last item (separator) */
2295 if (nCurrentItem >= (nCount - 1)) return FALSE;
2296 return TRUE;
2297 }
2298 case DL_DRAGGING:
2299 {
2300 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2301 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2302 /* no dragging past last item (separator) */
2303 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2304 {
2305 DrawInsert(hwnd, hwndList, nCurrentItem);
2306 /* FIXME: native uses "move button" cursor */
2307 return DL_COPYCURSOR;
2308 }
2309
2310 /* not over toolbar buttons list */
2311 if (nCurrentItem < 0)
2312 {
2313 POINT ptWindow = pDLI->ptCursor;
2314 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2315 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2316 /* over available buttons list? */
2317 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2318 /* FIXME: native uses "move button" cursor */
2319 return DL_COPYCURSOR;
2320 }
2321 /* clear drag arrow */
2322 DrawInsert(hwnd, hwndList, -1);
2323 return DL_STOPCURSOR;
2324 }
2325 case DL_DROPPED:
2326 {
2327 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2328 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2329 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2330 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2331 {
2332 /* clear drag arrow */
2333 DrawInsert(hwnd, hwndList, -1);
2334 /* move item */
2335 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2336 }
2337 /* not over toolbar buttons list */
2338 if (nIndexTo < 0)
2339 {
2340 POINT ptWindow = pDLI->ptCursor;
2341 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2342 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2343 /* over available buttons list? */
2344 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2345 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2346 }
2347 break;
2348 }
2349 case DL_CANCELDRAG:
2350 /* Clear drag arrow */
2351 DrawInsert(hwnd, hwndList, -1);
2352 break;
2353 }
2354
2355 return 0;
2356 }
2357
2358 /* drag list notification function for available buttons list box */
2359 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2360 const DRAGLISTINFO *pDLI)
2361 {
2362 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2363 switch (pDLI->uNotification)
2364 {
2365 case DL_BEGINDRAG:
2366 return TRUE;
2367 case DL_DRAGGING:
2368 {
2369 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2370 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2371 /* no dragging past last item (separator) */
2372 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2373 {
2374 DrawInsert(hwnd, hwndList, nCurrentItem);
2375 /* FIXME: native uses "move button" cursor */
2376 return DL_COPYCURSOR;
2377 }
2378
2379 /* not over toolbar buttons list */
2380 if (nCurrentItem < 0)
2381 {
2382 POINT ptWindow = pDLI->ptCursor;
2383 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2384 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2385 /* over available buttons list? */
2386 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2387 /* FIXME: native uses "move button" cursor */
2388 return DL_COPYCURSOR;
2389 }
2390 /* clear drag arrow */
2391 DrawInsert(hwnd, hwndList, -1);
2392 return DL_STOPCURSOR;
2393 }
2394 case DL_DROPPED:
2395 {
2396 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2397 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2398 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2399 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2400 {
2401 /* clear drag arrow */
2402 DrawInsert(hwnd, hwndList, -1);
2403 /* add item */
2404 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2405 }
2406 }
2407 case DL_CANCELDRAG:
2408 /* Clear drag arrow */
2409 DrawInsert(hwnd, hwndList, -1);
2410 break;
2411 }
2412 return 0;
2413 }
2414
2415 extern UINT uDragListMessage DECLSPEC_HIDDEN;
2416
2417 /***********************************************************************
2418 * TOOLBAR_CustomizeDialogProc
2419 * This function implements the toolbar customization dialog.
2420 */
2421 static INT_PTR CALLBACK
2422 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2423 {
2424 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2425 PCUSTOMBUTTON btnInfo;
2426 NMTOOLBARA nmtb;
2427 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2428
2429 switch (uMsg)
2430 {
2431 case WM_INITDIALOG:
2432 custInfo = (PCUSTDLG_INFO)lParam;
2433 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2434
2435 if (custInfo)
2436 {
2437 WCHAR Buffer[256];
2438 int i = 0;
2439 int index;
2440 NMTBINITCUSTOMIZE nmtbic;
2441
2442 infoPtr = custInfo->tbInfo;
2443
2444 /* send TBN_QUERYINSERT notification */
2445 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2446
2447 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2448 return FALSE;
2449
2450 nmtbic.hwndDialog = hwnd;
2451 /* Send TBN_INITCUSTOMIZE notification */
2452 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2453 TBNRF_HIDEHELP)
2454 {
2455 TRACE("TBNRF_HIDEHELP requested\n");
2456 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2457 }
2458
2459 /* add items to 'toolbar buttons' list and check if removable */
2460 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2461 {
2462 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2463 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2464 btnInfo->btn.fsStyle = BTNS_SEP;
2465 btnInfo->bVirtual = FALSE;
2466 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2467
2468 /* send TBN_QUERYDELETE notification */
2469 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2470
2471 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2472 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2473 }
2474
2475 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2476
2477 /* insert separator button into 'available buttons' list */
2478 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2479 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2480 btnInfo->btn.fsStyle = BTNS_SEP;
2481 btnInfo->bVirtual = FALSE;
2482 btnInfo->bRemovable = TRUE;
2483 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2484 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2485 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2486
2487 /* insert all buttons into dsa */
2488 for (i = 0;; i++)
2489 {
2490 /* send TBN_GETBUTTONINFO notification */
2491 NMTOOLBARW nmtb;
2492 nmtb.iItem = i;
2493 nmtb.pszText = Buffer;
2494 nmtb.cchText = 256;
2495
2496 /* Clear previous button's text */
2497 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2498
2499 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2500 break;
2501
2502 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2503 nmtb.tbButton.fsStyle, i,
2504 nmtb.tbButton.idCommand,
2505 nmtb.tbButton.iString,
2506 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2507 : "");
2508
2509 /* insert button into the appropriate list */
2510 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2511 if (index == -1)
2512 {
2513 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2514 btnInfo->bVirtual = FALSE;
2515 btnInfo->bRemovable = TRUE;
2516 }
2517 else
2518 {
2519 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2520 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2521 }
2522
2523 btnInfo->btn = nmtb.tbButton;
2524 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2525 {
2526 if (lstrlenW(nmtb.pszText))
2527 lstrcpyW(btnInfo->text, nmtb.pszText);
2528 else if (nmtb.tbButton.iString >= 0 &&
2529 nmtb.tbButton.iString < infoPtr->nNumStrings)
2530 {
2531 lstrcpyW(btnInfo->text,
2532 infoPtr->strings[nmtb.tbButton.iString]);
2533 }
2534 }
2535
2536 if (index == -1)
2537 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2538 }
2539
2540 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2541
2542 /* select first item in the 'available' list */
2543 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2544
2545 /* append 'virtual' separator button to the 'toolbar buttons' list */
2546 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2547 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2548 btnInfo->btn.fsStyle = BTNS_SEP;
2549 btnInfo->bVirtual = TRUE;
2550 btnInfo->bRemovable = FALSE;
2551 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2552 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2553 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2554
2555 /* select last item in the 'toolbar' list */
2556 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2557 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2558
2559 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2560 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2561
2562 /* set focus and disable buttons */
2563 PostMessageW (hwnd, WM_USER, 0, 0);
2564 }
2565 return TRUE;
2566
2567 case WM_USER:
2568 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2569 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2570 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2571 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2572 return TRUE;
2573
2574 case WM_CLOSE:
2575 EndDialog(hwnd, FALSE);
2576 return TRUE;
2577
2578 case WM_COMMAND:
2579 switch (LOWORD(wParam))
2580 {
2581 case IDC_TOOLBARBTN_LBOX:
2582 if (HIWORD(wParam) == LBN_SELCHANGE)
2583 {
2584 PCUSTOMBUTTON btnInfo;
2585 NMTOOLBARA nmtb;
2586 int count;
2587 int index;
2588
2589 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2590 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2591
2592 /* send TBN_QUERYINSERT notification */
2593 nmtb.iItem = index;
2594 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2595
2596 /* get list box item */
2597 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2598
2599 if (index == (count - 1))
2600 {
2601 /* last item (virtual separator) */
2602 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2603 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2604 }
2605 else if (index == (count - 2))
2606 {
2607 /* second last item (last non-virtual item) */
2608 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2609 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2610 }
2611 else if (index == 0)
2612 {
2613 /* first item */
2614 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2615 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2616 }
2617 else
2618 {
2619 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2620 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2621 }
2622
2623 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2624 }
2625 break;
2626
2627 case IDC_MOVEUP_BTN:
2628 {
2629 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2630 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2631 }
2632 break;
2633
2634 case IDC_MOVEDN_BTN: /* move down */
2635 {
2636 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2637 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2638 }
2639 break;
2640
2641 case IDC_REMOVE_BTN: /* remove button */
2642 {
2643 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2644
2645 if (LB_ERR == index)
2646 break;
2647
2648 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2649 }
2650 break;
2651 case IDC_HELP_BTN:
2652 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2653 break;
2654 case IDC_RESET_BTN:
2655 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2656 break;
2657
2658 case IDOK: /* Add button */
2659 {
2660 int index;
2661 int indexto;
2662
2663 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2664 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2665
2666 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2667 }
2668 break;
2669
2670 case IDCANCEL:
2671 EndDialog(hwnd, FALSE);
2672 break;
2673 }
2674 return TRUE;
2675
2676 case WM_DESTROY:
2677 {
2678 int count;
2679 int i;
2680
2681 /* delete items from 'toolbar buttons' listbox*/
2682 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2683 for (i = 0; i < count; i++)
2684 {
2685 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2686 Free(btnInfo);
2687 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2688 }
2689 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2690
2691
2692 /* delete items from 'available buttons' listbox*/
2693 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2694 for (i = 0; i < count; i++)
2695 {
2696 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2697 Free(btnInfo);
2698 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2699 }
2700 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2701 }
2702 return TRUE;
2703
2704 case WM_DRAWITEM:
2705 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2706 {
2707 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2708 RECT rcButton;
2709 RECT rcText;
2710 HPEN hPen, hOldPen;
2711 HBRUSH hOldBrush;
2712 COLORREF oldText = 0;
2713 COLORREF oldBk = 0;
2714
2715 /* get item data */
2716 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, lpdis->itemID, 0);
2717 if (btnInfo == NULL)
2718 {
2719 FIXME("btnInfo invalid!\n");
2720 return TRUE;
2721 }
2722
2723 /* set colors and select objects */
2724 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2725 if (btnInfo->bVirtual)
2726 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2727 else
2728 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2729 hPen = CreatePen( PS_SOLID, 1,
2730 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2731 hOldPen = SelectObject (lpdis->hDC, hPen );
2732 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2733
2734 /* fill background rectangle */
2735 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2736 lpdis->rcItem.right, lpdis->rcItem.bottom);
2737
2738 /* calculate button and text rectangles */
2739 CopyRect (&rcButton, &lpdis->rcItem);
2740 InflateRect (&rcButton, -1, -1);
2741 CopyRect (&rcText, &rcButton);
2742 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2743 rcText.left = rcButton.right + 2;
2744
2745 /* draw focus rectangle */
2746 if (lpdis->itemState & ODS_FOCUS)
2747 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2748
2749 /* draw button */
2750 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2751 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2752
2753 /* draw image and text */
2754 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2755 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2756 btnInfo->btn.iBitmap));
2757 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2758 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2759 }
2760 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2761 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2762
2763 /* delete objects and reset colors */
2764 SelectObject (lpdis->hDC, hOldBrush);
2765 SelectObject (lpdis->hDC, hOldPen);
2766 SetBkColor (lpdis->hDC, oldBk);
2767 SetTextColor (lpdis->hDC, oldText);
2768 DeleteObject( hPen );
2769 return TRUE;
2770 }
2771 return FALSE;
2772
2773 case WM_MEASUREITEM:
2774 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2775 {
2776 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2777
2778 lpmis->itemHeight = 15 + 8; /* default height */
2779
2780 return TRUE;
2781 }
2782 return FALSE;
2783
2784 default:
2785 if (uDragListMessage && (uMsg == uDragListMessage))
2786 {
2787 if (wParam == IDC_TOOLBARBTN_LBOX)
2788 {
2789 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2790 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2791 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2792 return TRUE;
2793 }
2794 else if (wParam == IDC_AVAILBTN_LBOX)
2795 {
2796 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2797 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2798 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2799 return TRUE;
2800 }
2801 }
2802 return FALSE;
2803 }
2804 }
2805
2806 static BOOL
2807 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2808 {
2809 HBITMAP hbmLoad;
2810 INT nCountBefore = ImageList_GetImageCount(himlDef);
2811 INT nCountAfter;
2812 INT cxIcon, cyIcon;
2813 INT nAdded;
2814 INT nIndex;
2815
2816 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2817 /* Add bitmaps to the default image list */
2818 if (bitmap->hInst == NULL) /* a handle was passed */
2819 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2820 else if (bitmap->hInst == COMCTL32_hModule)
2821 hbmLoad = LoadImageW( bitmap->hInst, MAKEINTRESOURCEW(bitmap->nID),
2822 IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
2823 else
2824 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2825
2826 /* enlarge the bitmap if needed */
2827 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2828 if (bitmap->hInst != COMCTL32_hModule)
2829 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2830
2831 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2832 DeleteObject(hbmLoad);
2833 if (nIndex == -1)
2834 return FALSE;
2835
2836 nCountAfter = ImageList_GetImageCount(himlDef);
2837 nAdded = nCountAfter - nCountBefore;
2838 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2839 {
2840 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2841 } else if (nAdded > (INT)bitmap->nButtons) {
2842 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2843 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2844 }
2845
2846 infoPtr->nNumBitmaps += nAdded;
2847 return TRUE;
2848 }
2849
2850 static void
2851 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2852 {
2853 HIMAGELIST himlDef;
2854 HIMAGELIST himlNew;
2855 INT cx, cy;
2856 INT i;
2857
2858 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2859 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2860 return;
2861 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2862 return;
2863 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2864 return;
2865
2866 TRACE("Update icon size: %dx%d -> %dx%d\n",
2867 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2868
2869 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2870 ILC_COLOR32|ILC_MASK, 8, 2);
2871 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2872 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2873 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2874 infoPtr->himlInt = himlNew;
2875
2876 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2877 ImageList_Destroy(himlDef);
2878 }
2879
2880 /***********************************************************************
2881 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2882 *
2883 */
2884 static LRESULT
2885 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2886 {
2887 TBITMAP_INFO info;
2888 INT iSumButtons, i;
2889 HIMAGELIST himlDef;
2890
2891 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2892 if (!lpAddBmp)
2893 return -1;
2894
2895 if (lpAddBmp->hInst == HINST_COMMCTRL)
2896 {
2897 info.hInst = COMCTL32_hModule;
2898 switch (lpAddBmp->nID)
2899 {
2900 case IDB_STD_SMALL_COLOR:
2901 info.nButtons = 15;
2902 info.nID = IDB_STD_SMALL;
2903 break;
2904 case IDB_STD_LARGE_COLOR:
2905 info.nButtons = 15;
2906 info.nID = IDB_STD_LARGE;
2907 break;
2908 case IDB_VIEW_SMALL_COLOR:
2909 info.nButtons = 12;
2910 info.nID = IDB_VIEW_SMALL;
2911 break;
2912 case IDB_VIEW_LARGE_COLOR:
2913 info.nButtons = 12;
2914 info.nID = IDB_VIEW_LARGE;
2915 break;
2916 case IDB_HIST_SMALL_COLOR:
2917 info.nButtons = 5;
2918 info.nID = IDB_HIST_SMALL;
2919 break;
2920 case IDB_HIST_LARGE_COLOR:
2921 info.nButtons = 5;
2922 info.nID = IDB_HIST_LARGE;
2923 break;
2924 default:
2925 return -1;
2926 }
2927
2928 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2929
2930 /* Windows resize all the buttons to the size of a newly added standard image */
2931 if (lpAddBmp->nID & 1)
2932 {
2933 /* large icons: 24x24. Will make the button 31x30 */
2934 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2935 }
2936 else
2937 {
2938 /* small icons: 16x16. Will make the buttons 23x22 */
2939 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2940 }
2941
2942 TOOLBAR_CalcToolbar (infoPtr);
2943 }
2944 else
2945 {
2946 info.nButtons = count;
2947 info.hInst = lpAddBmp->hInst;
2948 info.nID = lpAddBmp->nID;
2949 TRACE("adding %d bitmaps!\n", info.nButtons);
2950 }
2951
2952 /* check if the bitmap is already loaded and compute iSumButtons */
2953 iSumButtons = 0;
2954 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2955 {
2956 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2957 infoPtr->bitmaps[i].nID == info.nID)
2958 return iSumButtons;
2959 iSumButtons += infoPtr->bitmaps[i].nButtons;
2960 }
2961
2962 if (!infoPtr->cimlDef) {
2963 /* create new default image list */
2964 TRACE ("creating default image list!\n");
2965
2966 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2967 ILC_COLOR32 | ILC_MASK, info.nButtons, 2);
2968 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2969 infoPtr->himlInt = himlDef;
2970 }
2971 else {
2972 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2973 }
2974
2975 if (!himlDef) {
2976 WARN("No default image list available\n");
2977 return -1;
2978 }
2979
2980 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2981 return -1;
2982
2983 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2984 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2985 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2986 infoPtr->nNumBitmapInfos++;
2987 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2988
2989 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2990 return iSumButtons;
2991 }
2992
2993
2994 static LRESULT
2995 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
2996 {
2997 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
2998
2999 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
3000 }
3001
3002
3003 static LRESULT
3004 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
3005 {
3006 #define MAX_RESOURCE_STRING_LENGTH 512
3007 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3008 INT nIndex = infoPtr->nNumStrings;
3009
3010 TRACE("%p, %lx\n", hInstance, lParam);
3011
3012 if (IS_INTRESOURCE(lParam)) {
3013 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3014 WCHAR delimiter;
3015 WCHAR *next_delim;
3016 HRSRC hrsrc;
3017 WCHAR *p;
3018 INT len;
3019
3020 TRACE("adding string from resource\n");
3021
3022 if (!hInstance) return -1;
3023
3024 hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
3025 (LPWSTR)RT_STRING );
3026 if (!hrsrc)
3027 {
3028 TRACE("string not found in resources\n");
3029 return -1;
3030 }
3031
3032 len = LoadStringW (hInstance, (UINT)lParam,
3033 szString, MAX_RESOURCE_STRING_LENGTH);
3034
3035 TRACE("len=%d %s\n", len, debugstr_w(szString));
3036 if (len == 0 || len == 1)
3037 return nIndex;
3038
3039 TRACE("delimiter: 0x%x\n", *szString);
3040 delimiter = *szString;
3041 p = szString + 1;